예제 #1
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}============'
예제 #2
0
 def __init__(self):
     try:
         self.title = "========{0}========="
         self.sproduct = SProduct()
         self.service_category = SCategory()
         self.smach = SMachinery()
         self.sadd = SAddress()
     except Exception as e:
         print(self.title.format("error"))
         print(e.message)
         print(self.title.format("error"))
예제 #3
0
 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}============'
예제 #4
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 = ("已取消", "未支付", "已支付", "已接单", "已配送", "已装箱", "已完成",
                      "已评价")
예제 #5
0
 def __init__(self):
     self.service_product = SProduct()
     self.service_category = SCategory()
예제 #6
0
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
예제 #7
0
class CReview():
    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 create_review(self):
        args = request.args.to_dict()
        print(self.title.format("args"))
        print(args)
        print(self.title.format("args"))
        if "token" not in args.keys() or "OMid" not in args.keys():
            return PARAMS_MISS

        token = args.get("token")
        USid = token_to_usid(token)
        OMid = get_str(args, "OMid")
        OMstatus = self.service_order.get_omstatus_by_omid(OMid)
        if OMstatus >= 49:
            return import_status("ERROR_MESSAGE_WRONG_OMSTATUS",
                                 "LOVEBREAKFAST_ERROR",
                                 "ERROR_CODE_WRONG_OMSTATUS")

        data = request.data
        data = json.loads(data)
        print(self.title.format("data"))
        print(data)
        print(self.title.format("data"))

        for row in data:
            print(self.title.format("data_item"))
            print(row)
            print(self.title.format("data_item"))
            if "PRid" not in row or "REscore" not in row:
                return PARAMS_MISS
            if "REcontent" in row:
                REcontent = row["REcontent"]
            else:
                REcontent = None
            PRid = row["PRid"]
            REscore = row["REscore"]
            print(self.title.format("REscore"))
            print(REscore)
            print(self.title.format("REscore"))
            try:
                add_model(
                    "Review", **{
                        "REid": str(uuid.uuid1()),
                        "OMid": OMid,
                        "PRid": PRid,
                        "USid": USid,
                        "REscore": REscore,
                        "REcontent": REcontent,
                        "REstatus": 1
                    })
            except Exception as e:
                print(self.title.format("add_review"))
                print(e.message)
                print(self.title.format("add_review"))
                return SYSTEM_ERROR

            product_volue = self.service_product.get_product_volume_by_prid(
                PRid)
            product_score = self.service_product.get_product_score_by_prid(
                PRid)

            score = (product_score * product_volue + REscore) / product_volue
            product = {"PRscore": score}
            update_product = self.service_product.update_product_by_prid(
                PRid, product)
            print(self.title.format("update_product"))
            print(update_product)
            print(self.title.format("update_product"))
            if not update_product:
                return SYSTEM_ERROR

            order = {"OMstatus": 49}
            update_order = self.service_order.update_ordermain_by_omid(
                OMid, order)
            print(self.title.format("update_order"))
            print(update_order)
            print(self.title.format("update_order"))
            if not update_order:
                return SYSTEM_ERROR

        back_response = import_status("SUCCESS_MESSAGE_ADD_REVIEW", "OK")
        return back_response

    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 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(result)
        return {
            "message": "delete review success !",
            "status": 200,
        }
예제 #8
0
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
예제 #9
0
class CProduct():
    def __init__(self):
        try:
            self.title = "========{0}========="
            self.sproduct = SProduct()
            self.service_category = SCategory()
            self.smach = SMachinery()
            self.sadd = SAddress()
        except Exception as e:
            print(self.title.format("error"))
            print(e.message)
            print(self.title.format("error"))

    def get_all(self):
        args = request.args.to_dict()
        if "VNtelphone" in args:
            pass
        try:
            pro_list_of_product = get_model_return_list(
                self.sproduct.get_all())
            print(self.title.format("pro_list_of_product"))
            print(pro_list_of_product)
            print(self.title.format("pro_list_of_product"))
            if "PRhost" in args and args.get("PRhost") == "host":
                prolist = pro_list_of_product[:]
            elif "ASid" in args and args.get("ASid"):
                aaid_list = get_model_return_list(
                    self.sadd.get_addabo_by_asid(get_str(args, "ASid")))
                print(self.title.format("aaid_list"))
                print(aaid_list)
                print(self.title.format("aaid_list"))
                pro_list_of_addabo = []
                for aaid in aaid_list:
                    pro_list_of_addabo.extend([
                        i.PRid
                        for i in self.smach.get_pro_by_aaid(aaid.get("AAid"))
                    ])

                pro_list_of_addabo = {}.fromkeys(pro_list_of_addabo).keys()
                print(self.title.format("pro_list_of_addabo"))
                print(pro_list_of_addabo)
                print(self.title.format("pro_list_of_addabo"))

                prolist = [
                    pro for pro in pro_list_of_product
                    if pro.get("PRid") in pro_list_of_addabo
                ]
            elif "ASid" not in args:
                return PARAMS_MISS
            else:
                return SYSTEM_ERROR

            print(self.title.format("prolist"))
            print(prolist)
            print(self.title.format("prolist"))
            pro_list_of_control = []
            if prolist:
                pro_list_of_control = prolist

            data = import_status("get_product_list_success", "OK")
            data["data"] = pro_list_of_control
            return data
        except Exception as e:
            print(self.title.format("error"))
            print(e.message)
            print(self.title.format("error"))
            return SYSTEM_ERROR

    # 根据商品id获取商品详情
    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
예제 #10
0
 def __init__(self):
     self.service_product = SProduct()
     self.service_shop = SShop()
예제 #11
0
class CShop:
    def __init__(self):
        self.service_product = SProduct()
        self.service_shop = SShop()

    # 获取所有商店的信息
    def get_all_shops(self):
        # 返回商品详情
        list = []
        shopsdetail_of_service = self.service_shop.get_all_shops()
        for i in range(shopsdetail_of_service.__len__() / 10):
            shopdetail_of_controller = {}
            dic2 = {}
            shopdetail_of_controller["Sname"] = shopsdetail_of_service[i].Sname
            dic2["Simage"] = shopsdetail_of_service[i].Simage
            dic2["Sreview"] = shopsdetail_of_service[i].Sreview
            dic2["Sdetail"] = shopsdetail_of_service[i].Sdetail.encode("utf-8")
            shopdetail_of_controller["data"] = dic2
            list.append(shopdetail_of_controller)
        return {
            "status": 200,
            "message": "get homepage_shops success !",
            "data": list,
        }

    # 根据商品id获取商店详情
    def get_shop_detail(self):
        args = request.args.to_dict()  # 捕获前端的URL参数,以字典形式呈现
        # 判断url参数是否异常
        if len(args) != 1 or "Sid" not in args.keys():
            message, status, statuscode = import_status("URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }

        sid_to_str = get_str(args, "Sid")
        # 判断是否存在此pid
        print(type(sid_to_str))
        all_shop_id = self.service_shop.get_all_sid()
        print(type(all_shop_id))
        print(all_shop_id)
        if str(args["Sid"]) not in all_shop_id:
            message, status, statuscode = import_status("NO_THIS_Shop", "response_error", "NO_THIS_Shop")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }

        shopdetail = {}
        shopdetail_from_service = self.service_shop.get_shop_detail(sid_to_str)
        shopdetail["Sname"] = shopdetail_from_service.Sname
        shopdetail["Simage"] = shopdetail_from_service.Simage
        shopdetail["Stel"] = shopdetail_from_service.Stel
        shopdetail["Sdetail"] = shopdetail_from_service.Sdetail
        return {
            "status": 200,
            "message": "get shop_detail success !",
            "data": shopdetail
        }

    # 根据店铺id获取所有的分类与商品信息
    def get_category_and_product(self):
        args = request.args.to_dict()  # 捕获前端的URL参数,以字典形式呈现
        # 判断url参数是否异常
        if len(args) != 1 or "Sid" not in args.keys():
            message, status, statuscode = import_status("URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }

        sid_to_str = get_str(args, "Sid")
        # 判断是否存在此sid
        print(type(sid_to_str))
        all_shop_id = self.service_shop.get_all_sid()
        print(type(all_shop_id))
        print(all_shop_id)

        if str(args["Sid"]) not in all_shop_id:
            message, status, statuscode = import_status("NO_THIS_Shop", "response_error", "NO_THIS_Shop")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }

        # 获取所有的分类信息
        dic_for_cate_and_pro = []
        cate_list = self.service_shop.get_all_cid_cname(str(args["Sid"]))
        for i in range(cate_list.__len__()):
            dict1 = {}
            dict1["name"] = cate_list[i].Pcatgoryname
            Pcategoryid = cate_list[i].Pcategoryid
            pro_dic = None
            pro_dic = self.service_product.get_pro_id_by_cid(Pcategoryid)  # 根据分类id获取商品信息
            pro_dic_of_control = None
            pro_dic_of_control["Pname"] = pro_dic.Pname
            pro_dic_of_control["Pprice"] = pro_dic.Pprice
            pro_dic_of_control["Pimage"] = pro_dic.Pimage
            dict1["data"] = pro_dic_of_control
            dic_for_cate_and_pro.append(dict1)
        return {
            "status": 200,
            "message": "get get_category_and_product success !",
            "data": dic_for_cate_and_pro
        }