def __init__(self): from LoveBreakfast.services.SCarts import SCarts self.scart = SCarts() from LoveBreakfast.services.SProduct import SProduct self.spro = SProduct() from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() from LoveBreakfast.services.SProduct import SProduct self.sproduct = SProduct() from LoveBreakfast.services.SAddress import SAddress self.sadd = SAddress() from LoveBreakfast.services.SMachinery import SMachinery self.smach = SMachinery() self.title = '============{0}============'
def __init__(self): self.service_product = SProduct() self.service_review = SReview() self.control_order = COrders() self.service_user = SUsers() self.service_order = SOrders() self.title = '============{0}============'
def __init__(self): self.title = "=========={0}==========" from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() from LoveBreakfast.services.SProduct import SProduct self.sproduct = SProduct() from LoveBreakfast.services.SOrders import SOrders self.sorders = SOrders() from LoveBreakfast.services.SAddress import SAddress self.sadd = SAddress() from LoveBreakfast.services.SCoupons import SCoupons self.scoupons = SCoupons() from LoveBreakfast.services.SMachinery import SMachinery self.smach = SMachinery() from LoveBreakfast.services.SCarts import SCarts self.scart = SCarts() global OMstatus_list OMstatus_list = ("已取消", "未支付", "已支付", "已接单", "已配送", "已装箱", "已完成", "已评价")
class COrders(): def __init__(self): self.title = "=========={0}==========" from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() from LoveBreakfast.services.SProduct import SProduct self.sproduct = SProduct() from LoveBreakfast.services.SOrders import SOrders self.sorders = SOrders() from LoveBreakfast.services.SAddress import SAddress self.sadd = SAddress() from LoveBreakfast.services.SCoupons import SCoupons self.scoupons = SCoupons() from LoveBreakfast.services.SMachinery import SMachinery self.smach = SMachinery() from LoveBreakfast.services.SCarts import SCarts self.scart = SCarts() global OMstatus_list OMstatus_list = ("已取消", "未支付", "已支付", "已接单", "已配送", "已装箱", "已完成", "已评价") def get_order_list(self): args = request.args.to_dict() if "token" not in args: return PARAMS_MISS print(self.title.format("args")) print(args) print(self.title.format("args")) token = args.get("token") Uid = token_to_usid(token) # 暂时不处理过滤 order_list = get_model_return_list( self.sorders.get_all_order_by_uid(Uid)) print(self.title.format("order_list")) print(order_list) print(self.title.format("order_list")) data = [] if order_list: for row in order_list: status = row.get("OMstatus") row["OMtime"] = timeformate.get_web_time_str( str(row.get("OMtime"))) if status > 21 or status == 0 or self.checktime(): row["is_index"] = 702 else: row["is_index"] = 701 row["OMstatus"] = self.get_status_name_by_status(status) row["Orderitems"] = [] order_items = get_model_return_list( self.sorders.get_order_item_by_oid(row.get("OMid"))) print(self.title.format("order_items")) print(order_items) print(self.title.format("order_items")) for raw in order_items: Pid = raw.get("PRid") PRnumber = raw.get("PRnumber") product = get_model_return_dict( self.sproduct.get_product_all_by_pid(Pid)) product["PRid"] = Pid product["PRnumber"] = PRnumber print(self.title.format("product")) print(product) print(self.title.format("product")) row["Orderitems"].append(product) data.append(row) response_make_main_order = import_status("messages_get_item_ok", "OK") from LoveBreakfast.config.urlconfig import product_url_list response_make_main_order["sowing"] = product_url_list response_make_main_order["data"] = data return response_make_main_order def get_order_abo(self): args = request.args.to_dict() if "token" not in args or "OMid" not in args: return PARAMS_MISS print(self.title.format("args")) print(args) print(self.title.format("args")) Oid = args["OMid"] token = args.get("token") Uid = token_to_usid(token) order_abo = get_model_return_dict( self.sorders.get_order_abo_by_oid(Oid)) print(self.title.format("order_abo")) print(order_abo) print(self.title.format("order_abo")) order_abo["OMtime"] = timeformate.get_web_time_str( order_abo.get("OMtime")) order_abo["is_index"] = 701 if self.checktime() or order_abo.get("OMstatus") > 21 or order_abo.get( "OMstatus") == 0: order_abo["is_index"] = 702 order_abo["OMstatus"] = self.get_status_name_by_status( order_abo.get("OMstatus")) order_abo["OMdate"] = timeformate.get_web_time_str( order_abo.get("OMdate")) users = get_model_return_dict(self.susers.get_uname_utel_by_uid(Uid)) print(self.title.format("users")) print(users) print(self.title.format("users")) order_abo.update(users) order_items = get_model_return_list( self.sorders.get_order_item_by_oid(Oid)) print(self.title.format("order_items")) print(order_items) print(self.title.format("order_items")) order_abo["Orderitems"] = order_items addabo = get_model_return_dict( self.sadd.get_addabo_by_addid(order_abo.get("AAid"))) print(self.title.format("addabo")) print(addabo) print(self.title.format("addabo")) order_abo.update(addabo) for row in order_items: product = get_model_return_dict( self.sproduct.get_product_all_by_pid(row.get("PRid"))) print(self.title.format("product")) print(product) print(self.title.format("product")) row.update(product) response_make_main_order = import_status("messages_get_item_ok", "OK") response_make_main_order["data"] = order_abo return response_make_main_order def make_main_order(self): return TIME_ERROR args = request.args.to_dict() data = request.data data = json.loads(data) print(self.title.format("args")) print(args) print(self.title.format("args")) print(self.title.format("data")) print(data) print(self.title.format("data")) if "token" not in args: return PARAMS_MISS params_list = ["Order_items", "OMtime", "OMdate", "OMtotal", "AAid"] for params in params_list: if params not in data: return PARAMS_MISS token = args.get("token") Uid = token_to_usid(token) OMtime = timeformate.get_db_time_str(data["OMtime"]) if self.checktime(): return import_status("error_make_ordermain_time", "LOVEBREAKFAST_ERROR", "error_make_ordermain_time") OMdate = timeformate.get_db_time_str(data["OMdate"]) if not self.check_order_date(OMdate): return import_status("") order_item = data["Order_items"] OMcode = self.make_code() import uuid aaid = get_str(data, "AAid") OMid = str(uuid.uuid1()) try: for op in order_item: prostatus = self.sproduct.get_product_status_by_prid( op.get("PRid")) print(self.title.format("prostatus")) print(prostatus.PRstatus) print(self.title.format("prostatus")) if prostatus.PRstatus != 1: return import_status("error_no_pro", "LOVEBREAKFAST_ERROR", "error_no_pro") mach = self.smach.get_maid_by_aaid_prid( get_str(data, "AAid"), op.get("PRid")) print(self.title.format("mach")) print(mach) print(self.title.format("mach")) if not mach: return SYSTEM_ERROR self.sorders.add_model( "Orderpart", **{ "OPid": str(uuid.uuid1()), "OMid": OMid, "PRid": op.get("PRid"), "PRnumber": op.get("PRnumber") }) cart = get_model_return_dict( self.scart.get_cart_by_uid_pid(Uid, get_str(op, "PRid"))) print(self.title.format("cartt")) print(cart) print(self.title.format("cartt")) self.scart.del_carts(cart.get("CAid")) print(self.title.format("success add orderpart")) self.sorders.add_model( "Ordermain", **{ "OMid": OMid, "OMtime": OMtime, "OMdate": OMdate, "OMstatus": 7, "USid": Uid, "AAid": aaid, "OMcode": OMcode, "OMabo": get_str(data, "OMabo"), "OMtotal": data.get("OMtotal") }) self.scoupons.update_carbackage(get_str(data, "CAid")) response_make_main_order = import_status( "messages_add_main_order_success", "OK") response_make_main_order["data"] = {} response_make_main_order["data"]["OMid"] = OMid return response_make_main_order except Exception as e: print(self.title.format("error")) print(e.message) print(self.title.format("error")) return SYSTEM_ERROR def update_order_info(self): pass def update_order_status(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) data = request.data data = json.loads(data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "token" not in args: return PARAMS_MISS if "OMstatus" not in data or "OMid" not in data: return PARAMS_MISS # 处理token过程,这里未设计 OMstatus = get_str(data, "OMstatus") if OMstatus not in OMstatus_list: return import_status("messages_error_wrong_status_code", "LOVEBREAKFAST_ERROR", "error_wrong_status_code") OMid = data["OMid"] update_OMstatus = {} update_OMstatus["OMstatus"] = self.get_status_by_status_name(OMstatus) response_update_order_status = self.sorders.update_status_by_oid( OMid, update_OMstatus) if not response_update_order_status: return SYSTEM_ERROR return import_status("messages_update_order_status_ok", "OK") def get_order_user(self): args = request.args.to_dict() if "token" not in args: return PARAMS_MISS print(self.title.format("args")) print(args) print(self.title.format("args")) token = args.get("token") Uid = token_to_usid(token) users_info = self.susers.get_all_users_info(Uid) if not users_info: return SYSTEM_ERROR response_user_info = {} Utel = users_info.UStelphone response_user_info["Utel"] = Utel if users_info.USname not in ["", None]: Uname = users_info.USname response_user_info["Uname"] = Uname else: response_user_info["Uname"] = None if users_info.USsex not in ["", None]: Usex = users_info.USsex response_user_info["Usex"] = Usex else: response_user_info["Usex"] = None response_of_get_all = import_status("messages_get_item_ok", "OK") response_of_get_all["data"] = response_user_info return response_of_get_all def get_status_name_by_status(self, status): return OMstatus_list[status / 7] def get_status_by_status_name(self, status_name): i = 0 while i < 7: if status_name == OMstatus_list[i]: return i * 7 i = i + 1 return -99 def checktime(self): """ check now is between 6:00 and 22:00 :return: """ timenow = datetime.datetime.now() if 6 < timenow.hour < 22: return False return True def make_code(self): import random while True: randomcode = random.randint(100000, 999999) order = self.sorders.get_order_main_by_code(randomcode) if not order: return randomcode def get_order_price(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "token" not in args: return PARAMS_MISS data = json.loads(request.data) print(self.title.format("data")) print(data) print(self.title.format("data")) products_list = data.get("productlist") # OMcointype = "¥" order_list = [] OMprice = 0 try: for product in products_list: prnumber = product.get("PRnumber") product = get_model_return_dict( self.sproduct.get_pro_info_by_pid(product.get("PRid"))) # if product.get("PBunit") != OMcointype: # TODO 增加换算过程 # pass OMprice += (product.get("PRprice") * prnumber) order_list.append(product) if "COid" in data and get_str(data, "COid"): coupon = get_model_return_dict( self.scoupons.get_coupons_by_couid(get_str(data, "COid"))) print(self.title.format(coupon)) print(coupon) print(self.title.format(coupon)) OMprice = self.compute_om_price_by_coupons(coupon, OMprice) if not isinstance(OMprice, float): return OMprice print(self.title.format("OMprice")) print(OMprice) print(self.title.format("OMprice")) data = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") data["data"] = {"OMprice": OMprice, "productlist": order_list} return data except Exception as e: print(self.title.format("get order error")) print(e.message) print(self.title.format("get order error")) def compute_om_price_by_coupons(self, coupon, omprice): from decimal import Decimal time_now = timeformate.get_db_time_str() omprice = Decimal(str(omprice)) print(self.title.format("timenow")) print(time_now) print(self.title.format("timenow")) print(self.title.format("coutime")) print("endtime:", coupon.get("COend", ""), "\n starttime:", coupon.get("COstart", "")) print(self.title.format("coutime")) if coupon.get("COend") and time_now > coupon.get("COend"): return import_status("ERROR_MESSAGE_COUPONS_TIMEEND", "SHARPGOODS_ERROR", "ERROR_TIMR") if coupon.get("COstart") and time_now < coupon.get("COstart"): return import_status("ERROR_MESSAGE_COUPONS_TIMESTART", "SHARPGOODS_ERROR", "ERROR_TIMR") if omprice > coupon.get("COfilter", 0): if coupon.get("COamount"): omprice = omprice - Decimal(str(coupon.get("COamount", 0))) elif isinstance(coupon.get("COdiscount"), float): omprice = omprice * Decimal(str(coupon.get("COdiscount"))) else: # 优惠券不打折扣也不满减,要他干嘛 pass print(self.title.format("限定两位小数前的omproce")) print(omprice) print(self.title.format("限定两位小数前的omproce")) omprice = omprice.quantize(Decimal("0.00")) return float(omprice) if omprice >= 0 else 0.00 def check_order_date(self, order_date): print(self.title.format("order_date")) print(order_date) timenow = datetime.datetime.now().date() time_order = datetime.datetime.strptime( order_date, timeformate.format_for_db).date() if timenow >= time_order: return False return True
class CCarts(): def __init__(self): from LoveBreakfast.services.SCarts import SCarts self.scart = SCarts() from LoveBreakfast.services.SProduct import SProduct self.spro = SProduct() from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() from LoveBreakfast.services.SProduct import SProduct self.sproduct = SProduct() from LoveBreakfast.services.SAddress import SAddress self.sadd = SAddress() from LoveBreakfast.services.SMachinery import SMachinery self.smach = SMachinery() self.title = '============{0}============' def get_carts_by_uid(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "token" not in args or "AAid" not in args: return PARAMS_MISS token = args.get("token") uid = token_to_usid(token) ASid = args.get("ASid") is_user = self.susers.get_user_by_usid(uid) print(self.title.format("is_user")) print(is_user) print(self.title.format("is_user")) if not is_user: return import_status("ERROR_MESSAGE_NONE_USER", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_USER") cart_info_list = [] cart_list = self.scart.get_carts_by_Uid(uid) print(self.title.format("cartlist")) print(cart_list) print(self.title.format("cartlist")) aaid_list = self.sadd.get_addabo_by_asid(ASid) for cart in cart_list: if cart.CAstatus != 1: continue PRid = cart.PRid address_list = [i.AAid for i in self.smach.get_aaid_by_prid(PRid)] print(self.title.format("address_list")) print(address_list) print(self.title.format("address_list")) if not address_list: return SYSTEM_ERROR if not set(address_list).intersection(aaid_list): continue cart_service_info = self.spro.get_all_pro_fro_carts(PRid) print(self.title.format("cart_service_info")) print(cart_service_info) print(self.title.format("cart_service_info")) if not cart_service_info: return SYSTEM_ERROR cart_info = {} cart_info["PRid"] = cart_service_info.PRid cart_info["PRimage"] = cart_service_info.PRimage cart_info["PRname"] = cart_service_info.PRname cart_info["PRstatus"] = cart_service_info.PRstatus cart_info["PRsalesvolume"] = cart_service_info.PRsalesvolume cart_info["PRprice"] = cart_service_info.PRprice cart_info["PRscore"] = cart_service_info.PRscore cart_info["CAnumber"] = cart.CAnumber cart_info_list.append(cart_info) back_response = import_status("SUCCESS_GET_MESSAGE", "OK") back_response["data"] = cart_info_list return back_response def add_or_update_cart(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) data = json.loads(request.data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "token" not in args: return PARAMS_MISS token = args.get("token") uid = token_to_usid(token) pid = data.get("PRid") CAnumber = data.get("CAnumber") if CAnumber <= 0: PBnumber = self.scart.get_pbnumber_by_pbid_and_usid(pid, uid) pnum = int(CAnumber) + int(PBnumber) if pnum <= 0: return self.del_cart(uid, pid) try: if not self.sproduct.get_pro_info_by_pid(pid): return import_status("ERROR_MESSAGE_NONE_PRODUCT", "SHARPGOODS_ERROR", "ERROR_NONE_PRODUCT") cart = self.scart.get_cart_by_uid_pid(uid, pid) print(self.title.format("cart")) print(cart) print(self.title.format("cart")) if cart: PBnumber = self.scart.get_pbnumber_by_pbid_and_usid(pid, uid) pnum = int(CAnumber) + int(PBnumber) self.scart.update_num_cart(pnum, cart.CAid) else: add_model( "Cart", **{ "CAid": str(uuid.uuid1()), "CAnumber": CAnumber, "USid": uid, "CAstatus": 1, "PRid": pid }) except dberror: return SYSTEM_ERROR except Exception as e: print(e.message) return SYSTEM_ERROR return import_status("SUCCESS_MESSAGE_UPDATE_CART", "OK") def del_cart(self, uid, pid): try: cart = self.scart.get_cart_by_uid_pid(uid, pid) print(self.title.format("cart")) print(cart) print(self.title.format("cart")) if not cart: return import_status("ERROR_MESSAGE_NONE_PRODUCT", "LOVEBREAKFAST_ERROR", "ERROR_NONE_PRODUCT") self.scart.del_carts(cart.CAid) return import_status("SUCCESS_MESSAGE_DEL_CART", "OK") except Exception as e: print(e.message) return SYSTEM_ERROR def del_product(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "token" not in args: return PARAMS_MISS data = json.loads(request.data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "PRid" not in data: return PARAMS_MISS token = args.get("token") uid = token_to_usid(token) return self.del_cart(uid, data.get("PRid")) def get_carts_by_uid_caid(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "token" not in args: return PARAMS_MISS caid_list = [] if request.environ.get("REQUEST_METHOD") == "POST": data = json.loads(request.data) print(self.title.format("data")) print(data) print(self.title.format("data")) caid_list = data.get("CAid") token = args.get("token") uid = token_to_usid(token) ASid = args.get("ASid") is_user = self.susers.get_user_by_usid(uid) print(self.title.format("is_user")) print(is_user) print(self.title.format("is_user")) if not is_user: return import_status("ERROR_MESSAGE_NONE_USER", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_USER") aaid_list = [i.AAid for i in self.sadd.get_addabo_by_asid(ASid)] cart_info_list = [] cart_list = self.scart.get_carts_by_Uid(uid) print(self.title.format("cartlist")) print(cart_list) print(self.title.format("cartlist")) for cart in cart_list: if cart.CAstatus != 1: continue if caid_list and cart.CAid not in caid_list: continue PRid = cart.PRid address_list = [i.AAid for i in self.smach.get_aaid_by_prid(PRid)] print(self.title.format("address_list")) print(address_list) print(self.title.format("address_list")) if not address_list: return SYSTEM_ERROR if not set(address_list).intersection(aaid_list): continue cart_service_info = self.spro.get_all_pro_fro_carts(PRid) print(self.title.format("cart_service_info")) print(cart_service_info) print(self.title.format("cart_service_info")) if not cart_service_info: return SYSTEM_ERROR cart_info = {} cart_info["PRid"] = cart_service_info.PRid cart_info["PRimage"] = cart_service_info.PRimage cart_info["PRname"] = cart_service_info.PRname cart_info["PRstatus"] = cart_service_info.PRstatus cart_info["PRsalesvolume"] = cart_service_info.PRsalesvolume cart_info["PRprice"] = cart_service_info.PRprice cart_info["PRscore"] = cart_service_info.PRscore cart_info["CAnumber"] = cart.CAnumber cart_info["CAid"] = cart.CAid cart_info_list.append(cart_info) back_response = import_status("SUCCESS_GET_MESSAGE", "OK") back_response["data"] = cart_info_list return back_response
def __init__(self): from LoveBreakfast.services.SUsers import SUsers self.users = SUsers() from LoveBreakfast.services.SCoupons import SCoupons self.scoupons = SCoupons()
def __init__(self): from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() self.title = '============{0}============'
class CUsers(): def __init__(self): from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() self.title = '============{0}============' def register(self): return TIME_ERROR data = request.data data = json.loads(data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "UStelphone" not in data or "USpassword" not in data or "UScode" not in data: return PARAMS_MISS user = self.susers.get_user_by_utel(data["UStelphone"]) print(self.title.format("user")) print(user) print(self.title.format("user")) if user: return import_status("messages_repeat_tel", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_TELPHONE") UScode_dict = self.susers.get_code_by_utel(data["UStelphone"]) print(self.title.format("UScode")) print(UScode_dict) print(self.title.format("UScode")) if not UScode_dict: return import_status("ERROR_MESSAGE_NONE_ICCODE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_ICCODE") UScode = UScode_dict.ICcode if UScode != data["UScode"]: return import_status("ERROR_MESSAGE_WRONG_ICCODE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_ICCODE") if "USinvatecode" in data: Uinvate = data["USinvatecode"] # TODO 创建优惠券 USinvatecode = self.make_invate_code() is_register = self.susers.login_users(data["UStelphone"], data["USpassword"], USinvatecode) print(self.title.format("is_register")) print(is_register) print(self.title.format("is_register")) if not is_register: return SYSTEM_ERROR back_response = import_status("SUCCESS_MESSAGE_REGISTER_OK", "OK") return back_response def make_invate_code(self): USinvate = self.susers.get_all_invate_code() while True: invate_code = self.make_random_code() if invate_code not in USinvate: break return invate_code def make_random_code(self): import random random_code = "" while len(random_code) < 2: a = random.randint(97, 122) a = chr(a) random_code = random_code + a while len(random_code) < 6: a = random.randint(0, 9) random_code = random_code + str(a) return random_code def login(self): data = request.data data = json.loads(data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "UStelphone" not in data or "USpassword" not in data: return PARAMS_MISS Utel = data["UStelphone"] usid = get_model_return_dict(self.susers.get_user_by_utel(Utel)) print(self.title.format("usid")) print(usid) print(self.title.format("usid")) if not usid: return import_status("ERROR_MESSAGE_NONE_TELPHONE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_TELPHONE") upwd = self.susers.get_upwd_by_utel(Utel) if upwd != data["USpassword"]: return import_status("ERROR_MESSAGE_WRONG_PASSWORD", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_PASSWORD") back_response = import_status("SUCCESS_MESSAGE_LOGIN", "OK") from LoveBreakfast.common.MakeToken import usid_to_token token = usid_to_token(usid.get("USid")) back_response["data"] = {} back_response["data"]["token"] = token return back_response def update_info(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "token" not in args: return PARAMS_MISS token = args.get("token") Uid = token_to_usid(token) is_user = self.susers.get_user_by_usid(Uid) print(self.title.format("is_user")) print(is_user) print(self.title.format("is_user")) if not is_user: return import_status("ERROR_MESSAGE_NONE_USER", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_USER") data = request.data data = json.loads(data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "USname" not in data and "USsex" not in data: return PARAMS_MISS users = {} if "USname" in data: users["USname"] = data["USname"] if "USsex" in data: Usex = data["USsex"] if Usex == "男": Usex = 101 else: Usex = 102 users["USsex"] = Usex update_info = self.susers.update_users_by_uid(Uid, users) print(self.title.format("update_info")) print(update_info) print(self.title.format("update_info")) if not update_info: return SYSTEM_ERROR back_response = import_status("SUCCESS_MESSAGE_UPDATE_INFO", "OK") return back_response def update_pwd(self): data = request.data data = json.loads(data) print self.title.format("data") print data print self.title.format("data") if "USpasswordold" not in data or "USpasswordnew" not in data or "UStelphone" not in data: return SYSTEM_ERROR Utel = data["UStelphone"] list_utel = self.susers.get_all_user_tel() print self.title.format("list_utel") print list_utel print self.title.format("list_utel") if list_utel == False: return SYSTEM_ERROR if Utel not in list_utel: return import_status("ERROR_MESSAGE_NONE_TELPHONE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_TELPHONE") upwd = self.susers.get_upwd_by_utel(Utel) print self.title.format("USpassword") print upwd print self.title.format("USpassword") if upwd != data["USpasswordold"]: return import_status("ERROR_MESSAGE_WRONG_PASSWORD", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_PASSWORD") users = {} Upwd = data["USpasswordnew"] users["USpassword"] = Upwd Uid = self.susers.get_uid_by_utel(Utel) update_info = self.susers.update_users_by_uid(Uid, users) print self.title.format("update_info") print update_info print self.title.format("update_info") if not update_info: return SYSTEM_ERROR response_of_update_users = import_status("SUCCESS_MESSAGE_UPDATE_PASSWORD", "OK") return response_of_update_users def all_info(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "token" not in args: return PARAMS_MISS token = args.get("token") Uid = token_to_usid(token) users_info = get_model_return_dict(self.susers.get_all_users_info(Uid)) print(self.title.format("users_info")) print(users_info) print(self.title.format("users_info")) if not users_info: return SYSTEM_ERROR if users_info.get("USsex") not in["", None]: Usex = users_info.get("USsex") if Usex == 101: users_info["USsex"] = "男" elif Usex == 102: users_info["USsex"] = "女" else: users_info["USsex"] = "未知性别" else: users_info["USsex"] = None back_response = import_status("SUCCESS_GET_MESSAGE", "OK") back_response["data"] = users_info return back_response def get_inforcode(self): return TIME_ERROR data = request.data data = json.loads(data) print(self.title.format("data")) print(data) print(self.title.format("data")) if "UStelphone" not in data: return PARAMS_MISS Utel = data["UStelphone"] # 拼接验证码字符串(6位) code = "" while len(code) < 6: import random item = random.randint(1, 9) code = code + str(item) # 获取当前时间,与上一次获取的时间进行比较,小于60秒的获取直接报错 import datetime from LoveBreakfast.common.timeformate import format_for_db time_time = datetime.datetime.now() time_str = datetime.datetime.strftime(time_time, format_for_db) """ utel_list = self.susers.get_user_by_utel(Utel) print(self.title.format("utel_list")) print(utel_list) print(self.title.format("utel_list")) if utel_list: return import_status("ERROR_MESSAGE_REPEAT_TELPHONE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_REPEAT_TELPHONE") """ # 根据电话号码获取时间 time_up = self.susers.get_uptime_by_utel(Utel) print(self.title.format("time_up")) print time_up print(self.title.format("time_up")) if time_up: time_up_time = datetime.datetime.strptime(time_up.ICtime, format_for_db) delta = time_time - time_up_time if delta.seconds < 60: return import_status("ERROR_MESSAGE_GET_CODE_FAST", "LOVEBREAKFAST_ERROR", "ERROR_CODE_GET_CODE_FAST") new_inforcode = self.susers.add_inforcode(Utel, code, time_str) print(self.title.format("new_inforcode")) print(new_inforcode) print(self.title.format("new_inforcode")) if not new_inforcode: return SYSTEM_ERROR from LoveBreakfast.config.Inforcode import SignName, TemplateCode from LoveBreakfast.common.Inforsend import send_sms params = '{\"code\":\"' + code + '\",\"product\":\"etech\"}' # params = u'{"name":"wqb","code":"12345678","address":"bz","phone":"13000000000"}' __business_id = uuid.uuid1() response_send_message = send_sms(__business_id, Utel, SignName, TemplateCode, params) response_send_message = json.loads(response_send_message) print(self.title.format("response_send_message")) print(response_send_message) print(self.title.format("response_send_message")) if response_send_message["Code"] == "OK": status = 200 else: status = 405 response_ok = {} response_ok["status"] = status response_ok["messages"] = response_send_message["Message"] return response_ok def forget_pwd(self): data = request.data data = json.loads(data) print self.title.format("data") print data print self.title.format("data") if "USpasswordnew" not in data or "USpasswordnewrepeat" not in data or "UStelphone" not in data or "UScode" not in data: return SYSTEM_ERROR Utel = data["UStelphone"] list_utel = self.susers.get_all_user_tel() print self.title.format("list_utel") print list_utel print self.title.format("list_utel") if not list_utel: return SYSTEM_ERROR if Utel not in list_utel: return import_status("ERROR_MESSAGE_NONE_TELPHONE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_NONE_TELPHONE") code_in_db = self.susers.get_code_by_utel(data["UStelphone"]) print self.title.format("code_in_db") print code_in_db print self.title.format("code_in_db") if not code_in_db: return import_status("ERROR_MESSAGE_WRONG_TELCODE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_TELCODE") if code_in_db.ICcode != data["UScode"]: return import_status("ERROR_MESSAGE_WRONG_TELCODE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_TELCODE") if data["USpasswordnew"] != data["USpasswordnewrepeat"]: return import_status("ERROR_MESSAGE_WRONG_REPEAT_PASSWORD", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_REPEAT_PASSWORD") users = {} Upwd = data["USpasswordnew"] users["USpassword"] = Upwd Uid = self.susers.get_uid_by_utel(Utel) update_info = self.susers.update_users_by_uid(Uid, users) print self.title.format("update_info") print update_info print self.title.format("update_info") if not update_info: return SYSTEM_ERROR response_of_update_users = import_status("SUCCESS_MESSAGE_UPDATE_PASSWORD", "OK") return response_of_update_users
class CVotes: conversion_VOunit = {1300: "站"} conversion_VOtype = {1001: "单选题", 1002: '多选题', 1003: '填空题'} conversion_VOunit_reverse = {k: v for v, k in conversion_VOunit.items()} conversion_VOtype_reverse = {k: v for v, k in conversion_VOtype.items()} def __init__(self): from LoveBreakfast.services.SVotes import SVotes self.svotes = SVotes() from LoveBreakfast.services.SUsers import SUsers self.susers = SUsers() self.title = '============{0}============' # def get_all(self): # args = request.args.to_dict() # if "VSid" not in args: # return PARAMS_MISS # all_vote = self.svotes.get_all_vote() # print(self.title.format("all_vote")) # print(all_vote) # print(self.title.format("all_vote")) # if not all_vote: # return SYSTEM_ERROR # vote_list = [] # for row in all_vote: # vote_item = {} # VOid = row.VOid # VOno = row.VOno # VOtext = row.VOtext # VOchoice = row.VOchoice # VOisnull = row.VOisnull # if VOchoice == 1001: # choice = "[单选题]" # elif VOchoice == 1002: # choice = "[多选题]" # elif VOchoice == 1003: # choice = "[填空题]" # else: # choice = None # vote_item["VOid"] = VOid # vote_item["VOno"] = VOno # vote_item["VOtext"] = VOtext # vote_item["VOisnull"] = VOisnull # vote_item["VOchoice"] = choice # if VOchoice == 1001 or VOchoice == 1002: # vote_item["choice_items"] = [] # all_vote_items = self.svotes.get_voteitem_by_void(VOid) # print(self.title.format("all_vote_items")) # print(all_vote_items) # print(self.title.format("all_vote_items")) # for item in all_vote_items: # vote_choice_item = {} # VItext = item.VItext # VIno = item.VIno # vote_choice_item["VItext"] = VItext # vote_choice_item["VIno"] = VIno # vote_item["choice_items"].append(vote_choice_item) # vote_list.append(vote_item) # response = import_status("SUCCESS_MESSAGE_GET_VOTE", "OK") # response["data"] = vote_list # return response def get_vote(self): args = request.args.to_dict() print(self.title.format('args')) print(args) print(self.title.format('args')) if "VSid" not in args: return PARAMS_MISS vono = args.get("VOno") if args.get("VOno") else 1 vsid = args.get("VSid") try: votes = self.svotes.get_votes(vsid) print(self.title.format('votes')) print(votes) print(self.title.format('votes')) count = self.svotes.get_count(vsid) print(self.title.format('count')) print(count) print(self.title.format('count')) time_now = get_db_time_str() # 答题时间判断 if votes.VSstartTime and votes.VSstartTime > time_now: return import_status("error_vote_time", "LOVEBREAKFAST_ERROR", "error_vote_time_start") if votes.VSendTime and votes.VSendTime < time_now: return import_status("error_vote_time", "LOVEBREAKFAST_ERROR", "error_vote_time_end") vote = todict(self.svotes.get_vote(vsid, vono)) print(self.title.format("vote")) print(vote) print(self.title.format("vote")) # 获取下一题no if int(vote.get("VOno")) < count: if vote.get("VOtype") < 1003: votechoice_list = tolist( self.svotes.get_votechoisce(vote.get("VOid"))) if vote.get("VOtype") < 1002: for votechoice in votechoice_list: if not votechoice.get("VCnext"): votechoice["VCnext"] = int( vote.get("VOno")) + 1 else: vote["VCnext"] = int(vote.get("VOno")) + 1 vote["votechoice"] = votechoice_list else: vote["VCnext"] = int(vote.get("VOno")) + 1 else: vote["VCnext"] = "" vote["VOunit"] = self.conversion_VOunit.get(vote.get("VOunit")) vote["VOtype"] = self.conversion_VOtype.get( vote.get('VOtype', 1001)) response = import_status("SUCCESS_MESSAGE_GET_VOTE", "OK") vote["progress"] = int( float(vote.get("VOno")) / float(count) * 100) response["data"] = vote return response except Exception as e: print(self.title.format("get vote")) print(e.message) print(self.title.format("get vote")) return SYSTEM_ERROR def get_host(self): args = request.args.to_dict() print(self.title.format('args')) print(args) print(self.title.format('args')) if "VSid" not in args: return PARAMS_MISS vsid = args.get("VSid") votes = todict(self.svotes.get_votes(vsid)) print(self.title.format('votes')) print(votes) print(self.title.format('votes')) # votes.pop("VSstartTime") # votes.pop("VSendTime") time_now = get_db_time_str() time_status = "时间没问题" time_status_code = 200 if votes.get("VSstartTime") and time_now < votes.get("VSstartTime"): time_status_code = 405601 time_status = "答题时间未到" if votes.get("VSendTime") and time_now > votes.get("VSendTime"): time_status_code = 405602 time_status = "答题时间已超" votes["VSstartTime"] = get_web_time_str(votes.get("VSstartTime"), format_forweb_no_HMS) votes["VSendTime"] = get_web_time_str(votes.get("VSendTime"), format_forweb_no_HMS) votes["VStime"] = "2018-08-10" votes["TimeStatus"] = time_status votes["TimeStatusCode"] = time_status_code response = import_status("SUCCESS_MESSAGE_GET_VOTE", "OK") response["data"] = votes return response # def make_vote(self): # data = json.loads(request.data) # print(self.title.format("data")) # print(data) # print(self.title.format("data")) # if "UStelphone" not in data or "USname" not in data or "USchoose" not in data: # return PARAMS_MISS # UStelphone = data["UStelphone"] # if len(UStelphone) != 11: # return import_status("ERROR_MESSAGE_WRONG_TELPHONE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_WRONG_TELPHONE") # user = self.susers.get_user_by_utel(UStelphone) # if user: # return import_status("ERROR_MESSAGE_REPEAT_VOTE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_REPEAT_VOTE") # USname = data["USname"] # USchoose = data["USchoose"] # for row in USchoose: # add_model("Votenotes", # **{ # "VNid": str(uuid.uuid1()), # "VOno": row["VOno"], # "VNtext": row["VNtext"], # "VNtelphone": UStelphone # }) # # # 注册+免单优惠券 # USinvate = self.make_invate_code() # USpassword = self.make_password() # add_model("Users", # **{ # "USid": str(uuid.uuid1()), # "UStelphone": UStelphone, # "USpassword": USpassword, # "USname": USname, # "UScoin": 999.99, # "USinvatecode": USinvate # }) # # TODO 设计优惠券,利用当前999.99积分后期创建 # response = {} # response["USpassword"] = USpassword # response["UScode"] = USinvate # response_of_add = import_status("SUCCESS_MESSAGE_NEW_VOTE","OK") # response_of_add["data"] = response # return response_of_add def make_password(self): return self.make_random_code(3, 8) def make_invate_code(self): USinvate = self.susers.get_all_invate_code() while True: invate_code = self.make_random_code(3, 7) if invate_code not in USinvate: break return invate_code def make_random_code(self, m, n): import random random_code = "" while len(random_code) < m: a = random.randint(97, 122) a = chr(a) random_code = random_code + a while len(random_code) < n: a = random.randint(0, 9) random_code = random_code + str(a) return random_code def make_vote(self): data = json.loads(request.data) print(self.title.format('data')) print(data) print(self.title.format('data')) usertel = data.get("UStelphone") username = data.get("USname") user = self.susers.get_uid_by_utel(usertel) print(self.title.format('data')) print(data) print(self.title.format('data')) if not user: # 注册+免单优惠券 USinvate = self.make_invate_code() print(self.title.format('USinvate')) print(USinvate) print(self.title.format('USinvate')) USpassword = self.make_password() print(self.title.format('USpassword')) print(USpassword) print(self.title.format('USpassword')) user = str(uuid.uuid1()) self.susers.add_model( "Users", **{ "USid": user, "UStelphone": usertel, "USpassword": USpassword, "USname": username, "UScoin": 999.99, "USinvatecode": USinvate }) vn = self.svotes.get_Votenotes(data.get("VSid"), user) if vn: return import_status("ERROR_MESSAGE_REPEAT_VOTE", "LOVEBREAKFAST_ERROR", "ERROR_CODE_REPEAT_VOTE") vntime = get_db_time_str() vnid = str(uuid.uuid1()) self.svotes.add_model( "Votenotes", **{ "VNid": vnid, "VSid": data.get("VSid"), "USid": user, "VNtime": vntime }) VoteResult = data.get("USchoose") for vr in VoteResult: if not isinstance(vr.get("VRchoice"), basestring): vr["VRchoice"] = json.dumps(vr.get("VRchoice")) self.svotes.add_model( "VoteResult", **{ "VRid": str(uuid.uuid1()), "VNid": vnid, "VOid": vr.get("VOid"), "VRchoice": vr.get("VRchoice"), "VRabo": vr.get("VRabo") }) self.susers.add_model( "Cardpackage", **{ "CAid": str(uuid.uuid1()), "USid": user, "CAstatus": 2, "CAstart": get_db_time_str(), "CAend": "20181231235959", "COid": "123", }) response = import_status("SUCCESS_MESSAGE_NEW_VOTE", "OK") response["data"] = { "UStelphone": usertel, "USpassword": self.susers.get_upwd_by_utel(usertel), } return response