def add_cardpackage(self): args = request.args.to_dict() data = json.loads(request.data) if "token" not in args: return PARAMS_MISS token = args.get("token") uid = token_to_usid(token) couid = data.get("COid") try: cart_pkg = self.scoupons.get_card_by_uid_couid(uid, couid) cend = get_db_time_str() # 后期补充优惠券截止日期计算方法 if cart_pkg: if cart_pkg.CAstatus == 2: return import_status("error_coupons_used", "LOVEBREAKFAST_ERROR", "error_coupons_used") self.scoupons.update_carbackage(cart_pkg.CAid) else: self.scoupons.add_cardpackage(**{ "CAid": str(uuid.uuid4()), "USid": uid, "CAstatus": 1, "CAstart": get_db_time_str(), "CAend": cend, "COid": couid }) except dberror: return SYSTEM_ERROR except Exception as e: print(e.message) return SYSTEM_ERROR return import_status("messages_add_coupons_success", "OK")
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 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_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 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 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