def del_cart(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" data = json.loads(request.data) print "=================data=================" print data print "=================data=================" if "token" not in args: return PARAMS_MISS uid = args.get("token") user = self.suser.get_usname_by_usid(get_str(args, "token")) if not user: return TOKEN_ERROR pbid = data.get("PBid") try: cart = self.scarts.get_cart_by_uid_pid(uid, pbid) print "=================cart=================" print cart print "=================cart=================" if not cart: return import_status("ERROR_MESSAGE_NONE_PRODUCT", "SHARPGOODS_ERROR", "ERROR_NONE_PRODUCT") self.scarts.del_carts(cart.CAid) return import_status("SUCCESS_MESSAGE_DEL_CART", "OK") except Exception as e: print(e.message) return SYSTEM_ERROR
def forget_pwd(self): data = request.data data = json.loads(data) print "=================data=================" print data print "=================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 "=================list_utel=================" print list_utel print "=================list_utel=================" if list_utel == False: return SYSTEM_ERROR if Utel not in list_utel: return import_status("ERROR_MESSAGE_NONE_TELPHONE", "SHARPGOODS_ERROR", "ERROR_NONE_TELPHONE") code_in_db = self.susers.get_code_by_utel(data["UStelphone"]) print "=================code_in_db=================" print code_in_db print "=================code_in_db=================" if not code_in_db: return import_status("ERROR_MESSAGE_WRONG_TELCODE", "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE") if code_in_db.ICcode != data["UScode"]: return import_status("ERROR_MESSAGE_WRONG_TELCODE", "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE") if data["USpasswordnew"] != data["USpasswordnewrepeat"]: return import_status("ERROR_MESSAGE_WRONG_REPEAT_PASSWORD", "SHARPGOODS_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 "=================update_info=================" print update_info print "=================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 add_or_update_cart(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" data = json.loads(request.data) print "=================data=================" print data print "=================data=================" if "token" not in args: return PARAMS_MISS uid = args.get("token") pbid = data.get("PBid") CAnumber = data.get("CAnumber") if CAnumber <= 0: PBnumber = self.scarts.get_pbnumber_by_pbid_and_usid(pbid, uid) pnum = int(CAnumber) + int(PBnumber) if pnum <= 0: return self.del_cart() try: if not self.sproduct.get_product_by_pbid(pbid): return import_status("ERROR_MESSAGE_NONE_PRODUCT", "SHARPGOODS_ERROR", "ERROR_NONE_PRODUCT") cart = self.scarts.get_cart_by_uid_pid(uid, pbid) print "=================cart=================" print cart print "=================cart=================" if cart: PBnumber = self.scarts.get_pbnumber_by_pbid_and_usid(pbid, uid) pnum = int(CAnumber) + int(PBnumber) self.scarts.update_num_cart(pnum, cart.CAid) else: self.scarts.add_model( "Cart", **{ "CAid": str(uuid.uuid4()), "CAnumber": CAnumber, "USid": uid, "CAstatus": 1, "PBid": pbid }) except dberror: return SYSTEM_ERROR except Exception as e: print(e.message) return SYSTEM_ERROR add_update_cart_ok = import_status("SUCCESS_MESSAGE_ADD_UPDATE_CART", "OK") return add_update_cart_ok
def get_review(self): args = request.args.to_dict() # 捕获前端的URL参数,以字典形式呈现 print "=================args=================" print args print "=================args=================" # 判断url参数是否异常 if "PRid" not in args: return PARAMS_MISS PRid = args["PRid"] PBid_list = self.sproduct.get_pbid_by_prid(PRid) review_list = [] all_review = self.service_review.get_review_by_pbid(PRid) print "=================all_review=================" print all_review print "=================all_review=================" if all_review: for review in all_review: reviews = {} REid = review.REid REtime = review.REtime REtime = get_web_time_str(REtime) USid = review.USid REcontent = review.REcontent USname = self.suser.get_usname_by_usid(USid) print "=================USname=================" print USname print "=================USname=================" reviews["REid"] = REid reviews["REtime"] = REtime reviews["USname"] = USname reviews["REcontent"] = REcontent review_list.append(reviews) response = import_status("SUCCESS_MESSAGE_GET_REVIEW", "OK") response["data"] = review_list return response
def register(self): data = request.data data = json.loads(data) print "=================data=================" print data print "=================data=================" if "UStelphone" not in data or "USpassword" not in data or "UScode" not in data: return PARAMS_MISS list_utel = self.susers.get_all_user_tel() print "=================list_utel=================" print list_utel print "=================list_utel=================" if list_utel == False: return SYSTEM_ERROR if data["UStelphone"] in list_utel: return import_status("ERROR_MESSAGE_REPEAT_TELPHONE", "SHARPGOODS_ERROR", "ERROR_REPEAT_TELPHONE") code_in_db = self.susers.get_code_by_utel(data["UStelphone"]) print "=================code_in_db=================" print code_in_db print "=================code_in_db=================" if not code_in_db: return import_status("ERROR_MESSAGE_WRONG_TELCODE", "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE") if code_in_db.ICcode != data["UScode"]: return import_status("ERROR_MESSAGE_WRONG_TELCODE", "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE") if "USinvate" in data: USinvate = data["USinvate"] #TODO 优惠券发放 USinvatecode = self.make_invate_code() is_register = self.susers.login_users(data["UStelphone"], data["USpassword"], USinvatecode) print "=================is_register=================" print is_register print "=================is_register=================" if is_register: return import_status("SUCCESS_MESSAGE_REGISTER", "OK") else: return SYSTEM_ERROR
def update_pwd(self): data = request.data data = json.loads(data) print "=================data=================" print data print "=================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 "=================list_utel=================" print list_utel print "=================list_utel=================" if list_utel == False: return SYSTEM_ERROR if Utel not in list_utel: return import_status("ERROR_MESSAGE_NONE_TELPHONE", "SHARPGOODS_ERROR", "ERROR_NONE_TELPHONE") upwd = self.susers.get_upwd_by_utel(Utel) print "=================USpassword=================" print upwd print "=================USpassword=================" if upwd != data["USpasswordold"]: return import_status("ERROR_MESSAGE_WRONG_PASSWORD", "SHARPGOODS_ERROR", "ERROR_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 "=================update_info=================" print update_info print "=================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 login(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" data = request.data data = json.loads(data) print "=================data=================" print data print "=================data=================" if "UStelphone" not in data or "USpassword" not in data: return PARAMS_MISS Utel = data["UStelphone"] list_utel = self.susers.get_all_user_tel() print "=================list_utel=================" print list_utel print "=================list_utel=================" if list_utel == False: return SYSTEM_ERROR if Utel not in list_utel: return import_status("ERROR_MESSAGE_NONE_TELPHONE", "SHARPGOODS_ERROR", "ERROR_NONE_TELPHONE") upwd = self.susers.get_upwd_by_utel(Utel) print "=================USpassword=================" print upwd print "=================USpassword=================" if upwd != data["USpassword"]: return import_status("ERROR_MESSAGE_WRONG_PASSWORD", "SHARPGOODS_ERROR", "ERROR_WRONG_PASSWORD") Uid = self.susers.get_uid_by_utel(Utel) print "=================USid=================" print Uid print "=================USid=================" login_success = import_status("SUCCESS_MESSAGE_LOGIN", "OK") login_success["data"] = {} login_success["data"]["token"] = Uid return login_success
def del_location(self): args = request.args.to_dict() print(self.title.format("args dict")) print(args) print(self.title.format("args dict")) if "token" not in args or "LOid" not in args: return PARAMS_MISS try: location = get_model_return_dict( self.slocation.get_location_by_loid(get_str(args, "LOid"))) if location.get("LOisedit") != "301": return import_status("ERROR_MESSAGE_NO_ROLE_UPDATE_LOCATION", "SHARPGOODS_ERROR", "ERROR_ROLE") self.slocation.update_locations_by_loid(args.get("LOid"), {"LOisedit": 303}) return import_status("SUCCESS_MESSAGE_DELETE_LOCATION", "OK") except Exception as e: print(self.title.format("del location error")) print(e.message) print(self.title.format("del location error")) return SYSTEM_ERROR
def delete_user_review(self): args = request.args.to_dict() # 捕获前端的URL参数,以字典形式呈现 # 判断url参数是否异常 if len(args) != 1 or "Uid" not in args.keys( ) or "Rid" not in args.keys(): message, status, statuscode = import_status( "URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG") return { "message": message, "status": status, "statuscode": statuscode, } uid_to_str = get_str(args, "Uid") uid_list = [] if uid_to_str not in uid_list: message, status, statuscode = import_status( "URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG") return { "message": message, "status": status, "statuscode": statuscode, } rid_to_str = get_str(args, "Rid") rid_list = self.service_review.get_rid_by_uid(uid_to_str) if rid_to_str not in rid_list: message, status, statuscode = import_status( "NO_THIS_REVIEW", "response_error", "NO_THIS_REVIEW") return { "message": message, "status": status, "statuscode": statuscode, } result = self.service_review.delete_user_review(rid_to_str) print(request) return { "message": "delete review success !", "status": 200, }
def update_location(self): args = request.args.to_dict() print(self.title.format("args dict")) print(args) print(self.title.format("args dict")) print(self.title.format("data dict")) data = request.data data = json.loads(data) print(data) print(self.title.format("data dict")) if "token" not in args or "LOid" not in data: return PARAMS_MISS if not set(self.params_list).issuperset(data.keys()): print("the params is contains key out of {0}".format( self.params_list)) return import_status("ERROR_MESSAGE_UPDATE_LOCATION_URL", "SHARPGOODS_ERROR", "ERROR_PARAMS") try: location = get_model_return_dict( self.slocation.get_location_by_loid(get_str(data, "LOid"))) if location.get("LOisedit") != 301: return import_status("ERROR_MESSAGE_NO_ROLE_UPDATE_LOCATION", "SHARPGOODS_ERROR", "ERROR_ROLE") for key in data: location[key] = get_str(data, key) self.slocation.update_locations_by_loid(get_str(data, "LOid"), location) return import_status("SUCCESS_MESSAGE_UPDSTE_LOCATION", "OK") except Exception as e: print(self.title.format("update location error")) print(e.message) print(self.title.format("update location error")) return SYSTEM_ERROR
def get_all_location(self): args = request.args.to_dict() print(self.title.format("args dict")) print(args) print(self.title.format("args dict")) if "token" not in args or not args.get("token"): return PARAMS_MISS data = import_status("SUCCESS_MESSAGE_GET_LOCATIONS", "OK") print(self.title.format("Location list")) print(get_model_return_list(self.slocation.get_all(args.get("token")))) data["data"] = get_model_return_list( self.slocation.get_all(args.get("token"))) print(self.title.format("Location list")) return data
def all_info(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" if "token" not in args: return PARAMS_MISS Uid = args["token"] users_info = self.susers.get_all_users_info(Uid) print "=================users_info=================" print users_info print "=================users_info=================" if not users_info: return SYSTEM_ERROR response_user_info = {} Utel = users_info.UStelphone response_user_info["UStelphone"] = Utel if users_info.USname not in ["", None]: Uname = users_info.USname response_user_info["USname"] = Uname else: response_user_info["USname"] = None if users_info.USsex not in ["", None]: Usex = users_info.USsex if Usex == 101: response_user_info["USsex"] = "男" elif Usex == 102: response_user_info["USsex"] = "女" else: response_user_info["USsex"] = "未知性别" else: response_user_info["USsex"] = None response_user_info["UScoin"] = users_info.UScoin response_user_info["USinvate"] = users_info.USinvate response_of_get_all = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") response_of_get_all["data"] = response_user_info return response_of_get_all
def update_info(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" data = request.data data = json.loads(data) print "=================data=================" print data print "=================data=================" if "token" not in args or data in ["", "{}"]: return PARAMS_MISS users = {} if "USname" in data: Uname = data["USname"] users["USname"] = Uname if "USsex" in data: Usex = data["USsex"] if Usex == "男".decode("UTF-8"): Usex = 101 elif Usex == "女".decode("UTF-8"): Usex = 102 users["USsex"] = Usex if users == {}: return PARAMS_MISS Uid = args["token"] update_info = self.susers.update_users_by_uid(Uid, users) print "=================update_info=================" print update_info print "=================update_info=================" if not update_info: return SYSTEM_ERROR response_of_update_users = import_status( "SUCCESS_MESSAGE_UPDATE_PERSONAL", "OK") return response_of_update_users
def new_location(self): args = request.args.to_dict() print(self.title.format("args dict")) print(args) print(self.title.format("args dict")) print(self.title.format("data dict")) data = request.data data = json.loads(data) print(data) print(self.title.format("data dict")) if "token" not in args: return PARAMS_MISS location = {} for key in self.params_list2: if key not in data: return PARAMS_MISS location[key] = get_str(data, key) try: location["LOisedit"] = 301 import uuid location["LOid"] = str(uuid.uuid4()) location["USid"] = get_str(args, "token") result = self.slocation.add_model("Locations", **location) print(self.title.format("result boolean")) print(result) print(self.title.format("result boolean")) if result: return import_status("SUCCESS_MESSAGE_ADD_LOCATION", "OK") return SYSTEM_ERROR except Exception as e: print(self.title.format("add location error")) print(e.message) print(self.title.format("add location error")) return SYSTEM_ERROR
def get_carts_by_uid_caid(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" if "token" not in args: return PARAMS_MISS data = json.loads(request.data, encoding="utf8") caidlist = data.get("CAid") # todo uid 验证未实现 uid = args["token"] # res_get_all = {} cart_info_list = [] cart_list = self.scarts.get_carts_by_Uid(uid) print "=================cart_list=================" print cart_list print "=================cart_list=================" for cart in cart_list: if cart.CAstatus != 1: continue if caidlist and cart.CAid not in caidlist: continue cart_service_info = self.sproduct.get_product_by_pbid(cart.PBid) print "=================cart_service_info=================" print cart_service_info print "=================cart_service_info=================" if not cart_service_info: return SYSTEM_ERROR PRid = cart_service_info.PRid BRid = cart_service_info.BRid product = self.sproduct.get_product_by_prid(PRid) print "=================product=================" print product print "=================product=================" if not product: return SYSTEM_ERROR cart_info = {} cart_info["PRquality"] = {} quality_list = self.sproduct.get_all_brand_by_brid_last(BRid) for key in quality_list.keys(): cart_info["PRquality"][key] = {} cart_info["PRquality"][key]["name"] = self.choose_key(key) cart_info["PRquality"][key]["choice"] = [] cart_info["PRquality"][key]["choice"].append(quality_list[key]) cart_info["PBid"] = cart.PBid cart_info["PBimage"] = cart_service_info.PBimage cart_info["PBsalesvolume"] = cart_service_info.PBsalesvolume cart_info["PBprice"] = cart_service_info.PBprice PBunit = cart_service_info.PBunit if PBunit == 401: cart_info["PBunit"] = "$" elif PBunit == 402: cart_info["PBunit"] = "¥" elif PBunit == 403: cart_info["PBunit"] = "欧元" elif PBunit == 404: cart_info["PBunit"] = "英镑" else: cart_info["PBunit"] = "其他币种" cart_info["PBscore"] = cart_service_info.PBscore cart_info["CAnumber"] = cart.CAnumber cart_info["PRname"] = product.PRname cart_info["PRinfo"] = product.PRinfo PRbrand = product.PRbrand if PRbrand == 601: cart_info["PRbrand"] = "美妆类" elif PRbrand == 602: cart_info["PRbrand"] = "3C类" else: cart_info["PRbrand"] = "其他" cart_info["PRvideo"] = product.PRvideo PRtype = product.PRtype if PRtype == 501: cart_info["PRtype"] = "自营" elif PRtype == 502: cart_info["PRtype"] = "非自营" else: cart_info["PRtype"] = "未知商品" cart_info_list.append(cart_info) res_get_all = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") res_get_all["data"] = cart_info_list return res_get_all
def get_cart_pkg(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" if "token" not in args: return PARAMS_MISS uid = args.get("token") try: cart_list = [] cart_pkgs = self.scoupons.get_cardpackage_by_uid(uid) print "=================cart_pkgs=================" print cart_pkgs print "=================cart_pkgs=================" for cart_pkg in cart_pkgs: if cart_pkg.CAstatus == 2: continue coupon = self.scoupons.get_coupons_by_couid(cart_pkg.COid) print "=================coupon=================" print coupon print "=================coupon=================" cart = {} COtype = coupon.COtype print "=================COtype=================" print COtype print "=================COtype=================" cart["CAid"] = cart_pkg.CAid if COtype == 801: COfilter = coupon.COfilter cart["COuse"] = "满{0}元可用".format(COfilter) cart["COcut"] = coupon.COamount COstart = coupon.COstart cart["COstart"] = get_web_time_str(COstart, format_forweb_no_HMS) COend = coupon.COend cart["COend"] = get_web_time_str(COend, format_forweb_no_HMS) elif COtype == 802: COfilter = coupon.COfilter cart["COuse"] = "满{0}元可用".format(COfilter) cart["COcut"] = str(coupon.COdiscount * 100) + "%" COstart = coupon.COstart cart["COstart"] = get_web_time_str(COstart, format_forweb_no_HMS) COend = coupon.COend cart["COend"] = get_web_time_str(COend, format_forweb_no_HMS) elif COtype == 803: CObrand = coupon.CObrand.encode("utf8") cart["COuse"] = "限{0}商品可用".format(str(CObrand)) cart["COcut"] = coupon.COamount COstart = coupon.COstart cart["COstart"] = get_web_time_str(COstart, format_forweb_no_HMS) COend = coupon.COend cart["COend"] = get_web_time_str(COend, format_forweb_no_HMS) elif COtype == 804: cart["COuse"] = "无限制" cart["COcut"] = coupon.COamount COstart = coupon.COstart cart["COstart"] = get_web_time_str(COstart, format_forweb_no_HMS) COend = coupon.COend cart["COend"] = get_web_time_str(COend, format_forweb_no_HMS) else: return cart_list.append(cart) except Exception as e: print("ERROR: " + e.message) return SYSTEM_ERROR response = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = cart_list return response
def get_inforcode(self): data = request.data data = json.loads(data) print("=====================data=================") print(data) print("=====================data=================") if "UStelphone" not in data: return SYSTEM_ERROR Utel = data["UStelphone"] # 拼接验证码字符串(6位) code = "" while len(code) < 6: import random item = random.randint(1, 9) code = code + str(item) print("=====================code=================") print code print("=====================code=================") # 获取当前时间,与上一次获取的时间进行比较,小于60秒的获取直接报错 import datetime time_time = datetime.datetime.now() time_str = datetime.datetime.strftime(time_time, "%Y%m%d%H%M%S") # 根据电话号码获取时间 # utel_list = self.susers.get_all_user_tel() # print("=====================utel_list=================") # print utel_list # print("=====================utel_list=================") # if Utel in utel_list: # return import_status("ERROR_MESSAGE_REGISTED_TELPHONE", "SHARPGOODS_ERROR", "ERROR_REGISTED_TELPHONE") time_up = self.susers.get_uptime_by_utel(Utel) print("=====================time_up=================") print time_up print("=====================time_up=================") if time_up: time_up_time = datetime.datetime.strptime(time_up.ICtime, "%Y%m%d%H%M%S") delta = time_time - time_up_time if delta.seconds < 60: return import_status("ERROR_MESSAGE_FAST_GET", "SHARPGOODS_ERROR", "ERROR_FAST_GET") new_inforcode = self.susers.add_inforcode(Utel, code, time_str) print("=====================new_inforcode=================") print new_inforcode print("=====================new_inforcode=================") if not new_inforcode: return SYSTEM_ERROR from SharpGoods.config.Inforcode import SignName, TemplateCode from SharpGoods.common.Inforsend import send_sms params = '{\"code\":\"' + code + '\",\"product\":\"etech\"}' # params = u'{"name":"wqb","code":"12345678","address":"bz","phone":"13000000000"}' import uuid __business_id = uuid.uuid1() response_send_message = send_sms(__business_id, Utel, SignName, TemplateCode, params) print("=====================response_send_message=================") print response_send_message print("=====================response_send_message=================") response_send_message = json.loads(response_send_message) if response_send_message["Code"] == "OK": status = 200 message = "获取成功" else: status = 405 message = "获取验证码失败" response_ok = {} response_ok["status"] = status response_ok["message"] = message return response_ok
def get_pbid_by_all_brand(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" data = request.data data = json.loads(data) print "=================data=================" print data print "=================data=================" if "token" not in args or "PRid" not in args: return PARAMS_MISS if data == {}: return PARAMS_MISS BRid = self.sproduct.get_brid_by_prid(args["PRid"]) print "=================BRid=================" print BRid print "=================BRid=================" if not BRid: return SYSTEM_ERROR key_list = [] brid = BRid[0] while brid != "0": Brand = self.sproduct.get_brand_by_brid(brid) brid, BRkey, BRvalue = Brand.BRfromid, Brand.BRkey, Brand.BRvalue key_list.append(BRkey) print "=================key_list=================" print key_list print "=================key_list=================" BRid_list = self.sproduct.get_brid_by_key_value(key_list[0], data[key_list[0]]) print "=================BRid_list=================" print BRid_list print "=================BRid_list=================" i = len(BRid_list) while i > 0: row = BRid_list[i - 1] raw = row while row != "0": brand = self.sproduct.get_brand_by_brid(row) print "=================brand=================" print brand print "=================brand=================" row, BRkey, BRvalue = brand.BRfromid, brand.BRkey, brand.BRvalue if data[BRkey] != BRvalue: BRid_list.remove(raw) i = i - 1 print "=================BRid_list=================" print BRid_list print "=================BRid_list=================" if len(BRid_list) != 1: return SYSTEM_ERROR BRid = BRid_list[0] pball = self.sproduct.get_pball_by_brid(BRid) print "=================pball=================" print pball print "=================pball=================" data = {} data["PBid"] = pball.PBid data["PBimage"] = pball.PBimage PBunit = pball.PBunit if PBunit == 401: data["PBunit"] = "$" elif PBunit == 402: data["PBunit"] = "¥" elif PBunit == 403: data["PBunit"] = "欧元" elif PBunit == 404: data["PBunit"] = "英镑" else: data["PBunit"] = "其他币种" data["PBprice"] = pball.PBprice data["PBsalesvolume"] = pball.PBsalesvolume data["PBscore"] = pball.PBscore response = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = data return response
def get(self, other): if other == "getdata": print("=======================api===================") print("接口名称是{0},接口方法是get".format("getdata")) print("=======================api===================") data = request.data print(data) import json data = json.loads(data) if "return_code" not in data: return PARAMS_MISS return { "return_code": "SUCCESS", "return_msg": "OK" } if other == "disclaimer": return """欢迎您使用网上购物。请您务必先仔细阅读本用户协议(包括隐私权条款及法律条款),我们将按以下的方式和条件为您提供我们的服务。如果您使用我们的服务,即表示您完全同意并接受本用户协议。 尊敬的买家朋友,请在购买本店产品之前,一定要花几分钟认真阅读以下内容以避免我们的交易发生一些不必要的误会。 为了节省您宝贵的时间,请一次性问完或者多问一些您需要咨询的问题,因为同时在线咨询客户较多,我们是先来先回复,再接待下一个客户可能得好几分钟或者几十分钟才能再回复您的第二条消息,所以您一次性问完或者问多一点,方便您快速地购买到心仪的宝贝。 ◆发货时间◆ 购买时间以买家付款时间为准,正常情况下,每天16点前的订单我们会安排当天发出,如果遇到特殊情况,我们会及时与买家联系,亲们在购买时也可以咨询客服。 ◆签收提醒◆ 买家签收时需本人签收或者委托第三方签收,请买家签收时务必查看外包装是否完整,如有破损,明显挤压变形等,检查所购买商品数量和外观问题,如有问题请立刻联系我们或者拒绝签收,一旦签收了就是默认收到的东西是完好无缺的,如有损失只能由买家自己承担! 当面检查签收,请买家朋友收快件的时候,一定要当着派送员的面检查货物,首先检查外包装是否完好,然后打开包裹,检查内件是否和您购买的产品和数量一致,如有任何异常,请不要签字收货,更不要让派送员离开,马上拿起电话,拨打我们运单上面的发件电话,告知实际情况,在经过我们电话确认可以签收的情况下,方可签字收货,让派送员离开,然后尽快上线联系我们售后客服确认,以便尽快解决;如果快递员要求必须先签字,那么签完字后请当着他的面拆包,确认配件完好,如有不对的地方请告知我们来联系快递解决!让派件员离开而没有经过我们确认,货物数量或者外观上面有问题,我们拒绝承担损失~请谅解。 对于不能自己亲自签收的客户,我们建议购买的时候通过给我们客服留言的方式,告知我们您什么时间段方便自己签收,我们给您备注在快递单上面,让派送员在指定时间内派送!一定要做到亲自检查签收,所有由于门卫保安家人朋友等代收的快件一律视为本人签收。 由于物流的原因,在您签收之前,出现破损或者丢失,我们会在物流确认三天之内给您重新补发 ◆退换问题◆ 所有产品支持七天无理由退换货,购买产品,自签收之时开始(快递官网签收时间为准),七天内,对产品不满意,不喜欢等,在不影响第二次销售的情况下,都可以退换货,你没有确认配件是完好无损、全新原装、一切功能完好之前请不要拆封!请一定记得,如若不然,本店概不退货; 由于产品本身存在的问题或者我们的失误造成的退换货,我们承担来回邮费,但需要说明的是,不管客户发回来的邮费是多少,我们给买家承担的返回来的邮费都不超过客户购买时实际收取的邮费金额(例如,买家购买一件产品50元和邮费10元,共计60元,如果由于产品原因,导致退换货,不管买家发回来产生了多少运费,我们最高只承担买家发回来10元邮费,如果购买时折扣优惠了,只算了8元邮费,我们最高也只承担买家发回来8元邮费) 由于买家自己的原因不喜欢,买错等等产生的邮费,全部由买家自己承担,发回来以后,请上线联系补差价和邮费,我们收到后第一时间换好发出; 所有退换货交易,请买家朋友一定要在包裹里面留一张字条,清晰的写清楚:微信号,姓名,地址,联系电话,订单编号,退换货原因,由于买家发回来的快件,在包裹里面找不到留言字条或者字条模糊看不清楚,我们无法在后台查询到买家交易信息,而造成的换货退款延误,我们不承担责任,请谅解。 敬请顾客朋友一定在购买前仔细阅读我们的以上条款。一旦购买本店商品我们就视为接受以上条款,买家事后不能以任何方式拒绝履行以上条款,不能以买前没看见为借口拒绝履行条款。因为您购买商品,仔细阅读购买条款是您应尽的职责,您和我们都必须遵守交易规则。如果您对本店以上观点并不赞同,我们并不建议您购买本店商品! 由于商品问题所发回来的快递,由买家先行垫付邮费,到付件全部拒绝签收,等换好或者退货以后,我们按照您购买时支付给我们的邮费金额,打款到支付宝账户或者直接来联系我们申请邮费退款,谢谢您的理解与配合! ◆快递选择◆ 由于每天订单较多,我们不会对客户的每一个地址去查询是否到达,只要拍下快递,就是默认接受中通申通快递,由于中通或者申通不到造成的时间等损失,本店概不负责! 我们同时支持顺丰快递的发送,如需发送顺丰快递,请在订单内备注,感谢您的配合。 """ if other == "payconfig": print("=======================api===================") print("接口名称是{0},接口方法是get".format("payconfig")) print("=======================api===================") args = request.args.to_dict() if "code" not in args or "OMid" not in args: return PARAMS_MISS print("=======================args===================") print(args) print("=======================args===================") code = args["code"] APP_ID = "wx284751ea4c889568" APP_SECRET_KEY = "051c81977efa8175e43686565265bb4f" request_url = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type={3}" \ .format(APP_ID, APP_SECRET_KEY, code, "authorization_code") print("=======================request_url===================") print str(request_url) print("=======================request_url===================") strResult = None try: import urllib2 req = urllib2.Request(request_url) response = urllib2.urlopen(req) strResult = response.read() response.close() print strResult except Exception as e: print e.message if "openid" not in strResult or "session_key" not in strResult: return import json strResult = json.loads(strResult) print("=======================strResult===================") print(strResult) print("=======================strResult===================") openid = strResult["openid"] OMid = args["OMid"] response = {} response["appid"] = "wx284751ea4c889568" response["openid"] = openid import time response["timeStamp"] = int(time.time()) import uuid response["nonceStr"] = str(uuid.uuid1()).replace("-", "") data = {} body = {} body["appid"] = "wx284751ea4c889568" body["mch_id"] = "1504082901" body["device_info"] = "WEB" body["nonce_str"] = str(uuid.uuid1()).replace("-", "") body["body"] = "Beauty mirror" body["out_trade_no"] = OMid.replace("-", "") OMprice = self.sorders.get_omprice_by_omid(OMid) print("============OMprice=========") print OMprice print("============OMprice=========") body["total_fee"] = int(OMprice * 100) body["spbill_create_ip"] = "120.79.182.43" import datetime body["time_start"] = datetime.datetime.now().strftime("%Y%m%d%H%M%S") body["time_expire"] = (datetime.datetime.now() + datetime.timedelta(hours=2)).strftime("%Y%m%d%H%M%S") body["notify_url"] = "https://h878.cn/sharp/goods/other/getdata" body["trade_type"] = "JSAPI" body["openid"] = openid key_sign = "appid={0}&body={1}&device_info={2}&mch_id={3}&nonce_str={4}¬ify_url={5}&openid={6}" \ "&out_trade_no={7}&time_expire={8}&time_start={9}&total_fee={10}&trade_type={11}".format( body["appid"], "Beauty mirror", body["device_info"], body["mch_id"], body["nonce_str"], body["notify_url"], body["openid"], body["out_trade_no"], body["time_expire"], body["time_start"], body["total_fee"], body["trade_type"] ) key_sign = key_sign + "&key={0}".format("HangZhouZhenLangHangZhouZhenLang") import hashlib s = hashlib.md5() s.update(key_sign) body["sign"] = s.hexdigest().upper() xml_body = """<xml>\n\t <appid><![CDATA[{0}]]></appid>\n\t <body><![CDATA[{1}]]></body>\n\t <device_info><![CDATA[{2}]]></device_info>\n\t <mch_id><![CDATA[{3}]]></mch_id>\n\t <nonce_str><![CDATA[{4}]]></nonce_str>\n\t <notify_url><![CDATA[{5}]]></notify_url>\n\t <openid><![CDATA[{6}]]></openid>\n\t <out_trade_no><![CDATA[{7}]]></out_trade_no>\n\t <time_expire><![CDATA[{8}]]></time_expire>\n\t <time_start><![CDATA[{9}]]></time_start>\n\t <total_fee><![CDATA[{10}]]></total_fee>\n\t <trade_type><![CDATA[{11}]]></trade_type>\n\t <sign>{12}</sign>\n </xml>\n""".format(body["appid"], "Beauty mirror", body["device_info"], body["mch_id"], body["nonce_str"], body["notify_url"], body["openid"], body["out_trade_no"], body["time_expire"], body["time_start"], body["total_fee"], body["trade_type"], body["sign"]) print("=======================body===================") print(body) print("=======================body===================") data["xml"] = body strResult = None try: import urllib2 url = "https://api.mch.weixin.qq.com/pay/unifiedorder" headers = {'Content-Type': 'application/xml'} # import xmltodict # xml_body = xmltodict.unparse(data) print("=======================xml_body===================") print xml_body print("=======================xml_body===================") req = urllib2.Request(url, headers=headers, data=xml_body) url_response = urllib2.urlopen(req) strResult = url_response.read() print 1 except Exception as e: print e.message print("=======================strResult===================") print(str(strResult)) print("=======================strResult===================") if not strResult: return import xmltodict json_strResult = xmltodict.parse(strResult) import json json_strResult = json.loads(json.dumps(json_strResult)) json_result = json_strResult["xml"] print("=======================json_result===================") print(str(json_result)) print("=======================json_result===================") if not json_strResult: return if "prepay_id" not in json_result: return prepay_id = json_result["prepay_id"] print("=======================prepay_id===================") print(str(prepay_id)) print("=======================prepay_id===================") response["package"] = "prepay_id=" + str(prepay_id) response["signType"] = "MD5" key_sign = "appId={0}&nonceStr={1}&package={2}&signType={3}&timeStamp={4}&key={5}".format( response["appid"], response["nonceStr"], response["package"], response["signType"], response["timeStamp"], "HangZhouZhenLangHangZhouZhenLang" ) s = hashlib.md5() s.update(key_sign) response["paySign"] = s.hexdigest().upper() return response if other == "prepayconfig": print("=======================api===================") print("接口名称是{0},接口方法是get".format("prepayconfig")) print("=======================api===================") args = request.args.to_dict() if "openid" not in args or "OMid" not in args: return PARAMS_MISS print("=======================args===================") print(args) print("=======================args===================") openid = args["openid"] OMid = args["OMid"] response = {} response["appid"] = "wx284751ea4c889568" response["openid"] = openid import time response["timeStamp"] = int(time.time()) import uuid response["nonceStr"] = str(uuid.uuid1()).replace("-", "") data = {} body = {} body["appid"] = "wx284751ea4c889568" body["mch_id"] = "1504082901" body["device_info"] = "WEB" body["nonce_str"] = str(uuid.uuid1()).replace("-", "") body["body"] = "Beauty mirror" body["out_trade_no"] = OMid.replace("-", "") body["total_fee"] = 1 body["spbill_create_ip"] = "120.79.182.43" import datetime body["time_start"] = datetime.datetime.now().strftime("%Y%m%d%H%M%S") body["time_expire"] = (datetime.datetime.now() + datetime.timedelta(hours=2)).strftime("%Y%m%d%H%M%S") body["notify_url"] = "https://h878.cn/sharp/goods/other/getdata" body["trade_type"] = "JSAPI" body["openid"] = openid key_sign = "appid={0}&body={1}&device_info={2}&mch_id={3}&nonce_str={4}¬ify_url={5}&openid={6}" \ "&out_trade_no={7}&time_expire={8}&time_start={9}&total_fee={10}&trade_type={11}".format( body["appid"], "Beauty mirror", body["device_info"], body["mch_id"], body["nonce_str"], body["notify_url"], body["openid"], body["out_trade_no"], body["time_expire"], body["time_start"], body["total_fee"], body["trade_type"] ) key_sign = key_sign + "&key={0}".format("HangZhouZhenLangHangZhouZhenLang") import hashlib s = hashlib.md5() s.update(key_sign) body["sign"] = s.hexdigest().upper() xml_body = """<xml>\n\t <appid><![CDATA[{0}]]></appid>\n\t <body><![CDATA[{1}]]></body>\n\t <device_info><![CDATA[{2}]]></device_info>\n\t <mch_id><![CDATA[{3}]]></mch_id>\n\t <nonce_str><![CDATA[{4}]]></nonce_str>\n\t <notify_url><![CDATA[{5}]]></notify_url>\n\t <openid><![CDATA[{6}]]></openid>\n\t <out_trade_no><![CDATA[{7}]]></out_trade_no>\n\t <time_expire><![CDATA[{8}]]></time_expire>\n\t <time_start><![CDATA[{9}]]></time_start>\n\t <total_fee><![CDATA[{10}]]></total_fee>\n\t <trade_type><![CDATA[{11}]]></trade_type>\n\t <sign>{12}</sign>\n </xml>\n""".format(body["appid"], "Beauty mirror", body["device_info"], body["mch_id"], body["nonce_str"], body["notify_url"], body["openid"], body["out_trade_no"], body["time_expire"], body["time_start"], body["total_fee"], body["trade_type"], body["sign"]) print("=======================body===================") print(body) print("=======================body===================") data["xml"] = body strResult = None try: import urllib2 url = "https://api.mch.weixin.qq.com/pay/unifiedorder" headers = {'Content-Type': 'application/xml'} #import xmltodict #xml_body = xmltodict.unparse(data) print("=======================xml_body===================") print xml_body print("=======================xml_body===================") req = urllib2.Request(url, headers=headers, data=xml_body) url_response = urllib2.urlopen(req) strResult = url_response.read() print 1 except Exception as e: print e.message print("=======================strResult===================") print(str(strResult)) print("=======================strResult===================") if not strResult: return import xmltodict json_strResult = xmltodict.parse(strResult) import json json_strResult = json.loads(json.dumps(json_strResult)) json_result = json_strResult["xml"] print("=======================json_result===================") print(str(json_result)) print("=======================json_result===================") if not json_strResult: return if "prepay_id" not in json_result: return prepay_id = json_result["prepay_id"] print("=======================prepay_id===================") print(str(prepay_id)) print("=======================prepay_id===================") response["package"] = "prepay_id=" + str(prepay_id) response["signType"] = "MD5" key_sign = "appId={0}&nonceStr={1}&package={2}&signType={3}&timeStamp={4}&key={5}".format( response["appid"], response["nonceStr"], response["package"], response["signType"], response["timeStamp"], "HangZhouZhenLangHangZhouZhenLang" ) s = hashlib.md5() s.update(key_sign) response["paySign"] = s.hexdigest().upper() return response if other == "logistics": from SharpGoods.config.logistics import LIST_LOGISTICS data = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") data["data"] = LIST_LOGISTICS return data
def get_control_brand_by_prid(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" data = request.data data = json.loads(data) print "=================data=================" print data print "=================data=================" if "token" not in args or "PRid" not in args: return PARAMS_MISS if data == {}: return PARAMS_MISS BRid = self.sproduct.get_brid_by_prid(args["PRid"]) print "=================BRid=================" print BRid print "=================BRid=================" if not BRid: return SYSTEM_ERROR key_list = [] brid = BRid[0] while brid != "0": Brand = self.sproduct.get_brand_by_brid(brid) brid, BRkey, BRvalue = Brand.BRfromid, Brand.BRkey, Brand.BRvalue key_list.append(BRkey) print "=================key_list=================" print key_list print "=================key_list=================" BRid_list = self.sproduct.get_brid_by_prid(args["PRid"]) brid_list = self.sproduct.get_brid_by_prid(args["PRid"]) print "=================BRid_list=================" print BRid_list print "=================BRid_list=================" i = len(BRid_list) while i > 0: raw = BRid_list[i - 1] row = BRid_list[i - 1] print "=================raw=================" print raw print "=================raw=================" while row != "0": brand = self.sproduct.get_brand_by_brid(row) print "=================brand=================" print brand print "=================brand=================" row, BRkey, BRvalue = brand.BRfromid, brand.BRkey, brand.BRvalue if BRkey in data.keys() and data[BRkey] != BRvalue: BRid_list.remove(raw) print "=================BRid_list_remove=================" print BRid_list print "=================BRid_list_remove=================" break i = i - 1 print "=================BRid_list=================" print BRid_list print "=================BRid_list=================" back_data = {} for key in key_list: back_data.keys().append(key) back_data[key] = [] for BRid in BRid_list: brand = self.sproduct.get_brand_by_brid(BRid) BRkey, BRvalue = brand.BRkey, brand.BRvalue if BRkey == key and BRvalue not in back_data[key]: back_data[key].append(BRvalue) else: while BRid != "0": brand_parent = self.sproduct.get_brand_by_brid(BRid) BRid, BRkey, BRvalue = brand_parent.BRfromid, brand_parent.BRkey, brand_parent.BRvalue if BRvalue not in back_data[key] and BRkey == key: back_data[key].append(BRvalue) key_list_control = data.keys() i = len(key_list_control) j = 0 control = [] while i > 0: control.append(self.get_m_by_n(key_list_control[i - 1], key_list_control, data, brid_list, i - 1)) back_data[key_list_control[i - 1]] = control[j] #print key_list_control[i - 1] i = i - 1 j = j + 1 response = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = back_data return response
def get_info_by_id(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" if "PRid" not in args: return PARAMS_MISS PRid = args["PRid"] product = self.sproduct.get_product_by_prid(PRid) print "=================product=================" print product print "=================product=================" if not product: return SYSTEM_ERROR product_price = [9999999, -1] product_volue = 0 product_price_list = self.sproduct.get_pbprice_by_prid(PRid) print "=================product_price_list=================" print product_price_list print "=================product_price_list=================" if not product_price_list: return SYSTEM_ERROR for row in product_price_list: if row < product_price[0]: product_price[0] = row if row > product_price[1]: product_price[1] = row product_volue_list = self.sproduct.get_pbvolume_by_prid(PRid) print "=================product_volue_list=================" print product_volue_list print "=================product_volue_list=================" if not product_volue_list: return SYSTEM_ERROR for row in product_volue_list: product_volue = product_volue + row product_info = {} product_info["PRid"] = PRid product_info["PRprice"] = str(product_price[0]) + "-" + str(product_price[1]) product_info["PRsalevolume"] = product_volue product_info["PRname"] = product.PRname product_info["PRvideo"] = product.PRvideo product_info["PRinfo"] = product.PRinfo product_info["PRvideostart"] = product.PRvideostart product_info["PRimage"] = product.PRimage product_info["PRaboimage"] = list(PRABOIMAGE.get(PRid)) PRbrand = product.PRbrand PRtype = product.PRtype if PRbrand == 601: product_info["PRbrand"] = "美妆类" elif PRbrand == 602: product_info["PRbrand"] = "3C类" else: product_info["PRbrand"] = "其他" if PRtype == 501: product_info["PRtype"] = "自营" elif PRtype == 502: product_info["PRtype"] = "非自营" else: product_info["PRtype"] = "未知商品" # PBimage = self.sproduct.get_pbimg_by_prid(PRid) # print "=================PBimage=================" # print PBimage # print "=================PBimage=================" # product_info["PBimage"] = [] # for img in PBimage: # product_info["PBimage"].append(img) product_info["PBimage"] = list(PRSWINGIMAGE.get(PRid)) product_info["PRquality"] = {} BRid = self.sproduct.get_brid_by_prid(PRid) print "=================BRid=================" print BRid print "=================BRid=================" for brid in BRid: while brid != "0": brand = self.sproduct.get_brand_by_brid(brid) print "=================brand=================" print brand print "=================brand=================" brid, BRkey, BRvalue = brand.BRfromid, brand.BRkey, brand.BRvalue if BRkey in product_info["PRquality"].keys(): if BRvalue not in product_info["PRquality"][BRkey]["choice"]: product_info["PRquality"][BRkey]["choice"].append(BRvalue) else: product_info["PRquality"].keys().append(BRkey) product_info["PRquality"][BRkey] = {} product_info["PRquality"][BRkey]["name"] = self.choose_key(BRkey) product_info["PRquality"][BRkey]["choice"] = [BRvalue] response_of_product = import_status("SUCCESS_MESSAGE_GET_PRODUCT", "OK") response_of_product["data"] = product_info return response_of_product
def get_all(self): PRid_list = self.sproduct.get_all_prid() print "=================PRid_list=================" print PRid_list print "=================PRid_list=================" args = request.args.to_dict() if "htv" not in args: return PARAMS_MISS htv = float(args.get("htv")) from SharpGoods.common.Gethdp import get_hdp hdp = get_hdp(htv) product_infos = [] for PRid in PRid_list: product = self.sproduct.get_product_by_prid(PRid) print "=================product=================" print product print "=================product=================" if not product: return SYSTEM_ERROR product_info = {} product_info["PRid"] = PRid product_info["PRimage"] = product.PRimage.format(hdp) product_infos.append(product_info) ''' product_price = [9999999, -1] product_volue = 0 product_price_list = self.sproduct.get_pbprice_by_prid(PRid) print "=================product_price_list=================" print product_price_list print "=================product_price_list=================" if not product_price_list: return SYSTEM_ERROR for row in product_price_list: if row < product_price[0]: product_price[0] = row if row > product_price[1]: product_price[1] = row product_volue_list = self.sproduct.get_pbvolume_by_prid(PRid) print "=================product_volue_list=================" print product_volue_list print "=================product_volue_list=================" if not product_volue_list: return SYSTEM_ERROR for row in product_volue_list: product_volue = product_volue + row product_info = {} product_info["PRid"] = PRid if product_price[0] == product_price[1]: product_info["PRprice"] = product_price[0] else: product_info["PRprice"] = str(product_price[0]) + "-" + str(product_price[1]) product_info["PRsalevolume"] = product_volue product_info["PRname"] = product.PRname product_info["PRvideo"] = product.PRvideo product_info["PRinfo"] = product.PRinfo product_info["PRimage"] = product.PRimage product_info["PRaboimage"] = product.PRaboimage PRbrand = product.PRbrand PRtype = product.PRtype if PRbrand == 601: product_info["PRbrand"] = "美妆类" elif PRbrand == 602: product_info["PRbrand"] = "3C类" else: product_info["PRbrand"] = "其他" if PRtype == 501: product_info["PRtype"] = "自营" elif PRtype == 502: product_info["PRtype"] = "非自营" else: product_info["PRtype"] = "未知商品" PBimage = self.sproduct.get_pbimg_by_prid(PRid) print "=================PBimage=================" print PBimage print "=================PBimage=================" product_info["PBimage"] = [] for img in PBimage: product_info["PBimage"].append(img) product_info["PRquality"] = {} BRid = self.sproduct.get_brid_by_prid(PRid) print "=================BRid=================" print BRid print "=================BRid=================" for brid in BRid: while brid != "0": brand = self.sproduct.get_brand_by_brid(brid) print "=================brand=================" print brand print "=================brand=================" brid, BRkey, BRvalue = brand.BRfromid, brand.BRkey, brand.BRvalue if BRkey in product_info["PRquality"].keys(): if BRvalue not in product_info["PRquality"][BRkey]["choice"]: product_info["PRquality"][BRkey]["choice"].append(BRvalue) else: product_info["PRquality"].keys().append(BRkey) product_info["PRquality"][BRkey] = {} product_info["PRquality"][BRkey]["name"] = self.choose_key(BRkey) product_info["PRquality"][BRkey]["choice"] = [] product_info["PRquality"][BRkey]["choice"].append(BRvalue) product_infos.append(product_info) ''' response_of_product = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") response_of_product["data"] = product_infos print(self.title.format("response")) print(response_of_product) print(self.title.format("response")) return response_of_product
def get_cart_pkg_by_pblst(self): args = request.args.to_dict() print "=================args=================" print args print "=================args=================" if "token" not in args: return PARAMS_MISS uid = args["token"] data = json.loads(request.data) print "=================data=================" print data print "=================data=================" if "PBid" not in data and "OMprice" not in data: return PARAMS_MISS try: cart_list = [] cart_pkgs = get_model_return_list( self.scoupons.get_cardpackage_by_uid(uid)) print "=================cart_pkgs=================" print cart_pkgs print "=================cart_pkgs=================" for cart_pkg in cart_pkgs: if cart_pkg.get("CAstatus") == 2: continue coupon = self.scoupons.get_coupons_by_couid( cart_pkg.get("COid")) print "=================coupon=================" print coupon print "=================coupon=================" cart = {} cart["CAid"] = cart_pkg.CAid COtype = coupon.COtype cart["COtype"] = COtype if COtype == 801: cart["COuse"] = "满{0}元可用".format(coupon.COfilter) cart["COcut"] = coupon.COamount cart["COstart"] = get_web_time_str(coupon.COstart, format_forweb_no_HMS) cart["COend"] = get_web_time_str(coupon.COend, format_forweb_no_HMS) elif COtype == 802: cart["COuse"] = "满{0}元可用".format(coupon.COfilter) cart["COcut"] = str(coupon.COdiscount * 100) + "%" cart["COstart"] = get_web_time_str(coupon.COstart, format_forweb_no_HMS) cart["COend"] = get_web_time_str(coupon.COend, format_forweb_no_HMS) elif COtype == 803: cart["COuse"] = "限{0}商品可用".format(coupon.CObrand) cart["COcut"] = coupon.COamount cart["COstart"] = get_web_time_str(coupon.COstart, format_forweb_no_HMS) cart["COend"] = get_web_time_str(coupon.COend, format_forweb_no_HMS) elif COtype == 804: cart["COuse"] = "无限制" cart["COcut"] = coupon.COamount cart["COstart"] = get_web_time_str(coupon.COstart, format_forweb_no_HMS) cart["COend"] = get_web_time_str(coupon.COend, format_forweb_no_HMS) cart_list.append(cart_pkg) except Exception as e: print("ERROR: " + e.message) return SYSTEM_ERROR for pbid in data: pass response = import_status("SUCCESS_MESSAGE_GET_INFO", "OK") response["data"] = cart_list return response
def create_review(self): args = request.args.to_dict() # 捕获前端的URL参数,以字典形式呈现 print "=================args=================" print args print "=================args=================" # 判断url参数是否异常 if "token" not in args and "OMid" not in args: return PARAMS_MISS Uid = args["token"] OMid = args["OMid"] uid = self.sorder.get_uid_by_omid(OMid) print "=================uid=================" print uid print "=================uid=================" omstatus = self.sorder.get_omstatus_by_omid(OMid) print "=================omstatus=================" print omstatus print "=================omstatus=================" if uid != Uid: return import_status("ERROR_MESSAGE_NONE_PERMISSION", "SHARPGOODS_ERROR", "ERROR_NONE_PERMISSION") if omstatus != 42: return import_status("ERROR_MESSAGE_WRONG_STATUS", "SHARPGOODS_ERROR", "ERROR_WRONG_STATUS") data = json.loads(request.data) print "=================data=================" print data print "=================data=================" if data == []: return PARAMS_MISS for review in data: if "PBid" not in review or "REcontent" not in review or "REscore" not in review: return PARAMS_MISS PRid = self.sproduct.get_prid_by_pbid(review["PBid"]) print "=================PRid=================" print PRid print "=================PRid=================" REcontent = review["REcontent"] add_review = self.service_review.new_review(PRid, uid, REcontent) if not add_review: return SYSTEM_ERROR product = self.sproduct.get_volue_score_by_pbid(review["PBid"]) print "=================product=================" print product print "=================product=================" PBscore, PBvolue = product.PBscore, product.PBsalesvolume score = (review["REscore"] + PBscore * PBvolue) / PBvolue product_brand = {} product_brand["PBid"] = review["PBid"] product_brand["PBscore"] = score update_product = self.sproduct.update_score_by_pbid( review["PBid"], product_brand) if not update_product: return SYSTEM_ERROR order_main = {} order_main["OMstatus"] = 49 update_order_status = self.sorder.update_omstatus_by_omid( OMid, order_main) if not update_order_status: return SYSTEM_ERROR return import_status("SUCCESS_MESSAGE_NEW_REVIEW", "OK")