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 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 get_info_by_id(self): args = request.args.to_dict() # 捕获前端的URL参数,以字典形式呈现 # 判断url参数是否异常 if len(args) != 1 or "PRid" not in args.keys(): return import_status("URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG") pid_to_str = get_str(args, "PRid") print(self.title.format("pid_to_str")) print(pid_to_str) print(self.title.format("pid_to_str")) # 返回商品详情 try: proabo_of_service = get_model_return_dict( self.sproduct.get_pro_info_by_pid(pid_to_str)) if not proabo_of_service: # 判断是否存在此pid return import_status("NO_THIS_PRODUCT", "response_error", "NO_THIS_PRODUCT") print("proabo_of_service") print(proabo_of_service) print("proabo_of_service") proabo_of_service["Pnum"] = 0 data = import_status("get_product_info_success", "OK") data["data"] = proabo_of_service return data except Exception as e: print(self.title.format("error")) print(e.message) print(self.title.format("error")) return SYSTEM_ERROR
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 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_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_addfirst(self): """ 通过城市名称和类型获取区域名称或者所有线路 :return: """ args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "ACname" not in args or "AFtype" not in args: return PARAMS_MISS try: acname = args.get("ACname") city = get_model_return_dict(self.sadd.get_city_by_name(acname)) if not city: return import_status("error_no_city", "LOVEBREAKFAST_ERROR", "error_no_city") print(self.title.format("city")) print(city) print(self.title.format("city")) af_type = get_str(args, "AFtype") list_first = get_model_return_list( self.sadd.get_addfirst_by_acid_astype(city.get("ACid"), AFTYPE.index(af_type))) print(self.title.format("list_first")) print(list_first) print(self.title.format("list_first")) return_data = import_status("messages_get_area_success", "OK") return_data["data"] = list_first return return_data except Exception as e: print(self.title.format("error")) print(e.message) print(self.title.format("error")) return SYSTEM_ERROR
def get_review(self): args = request.args.to_dict() print(self.title.format("args")) print(args) print(self.title.format("args")) if "OMid" not in args.keys() or "token" not in args.keys(): return PARAMS_MISS token = args.get("token") USid = token_to_usid(token) # TODO USid的作用? OMid = get_str(args, "OMid") all_review = get_model_return_list( self.service_review.get_review(OMid)) print(self.title.format("all_review")) print(all_review) print(self.title.format("all_review")) if not all_review: return SYSTEM_ERROR for row in all_review: product = get_model_return_dict( self.service_product.get_product_all_by_pid(row.get("PRid"))) print(self.title.format("product")) print(product) print(self.title.format("product")) if not product: return SYSTEM_ERROR row.update(product) back_response = import_status("SUCCESS_MESSAGE_ADD_REVIEW", "OK") back_response["data"] = all_review return back_response
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