Esempio n. 1
0
    def new_meal(self):
        args = request.args.to_dict()
        print(self.title.format("args"))
        print(args)
        print(self.title.format("args"))
        if "token" not in args and "MSid" not in args:
            return PARAMS_MISS
        USid = token_to_usid(args["token"])
        MSid = args["MSid"]
        user = self.susers.get_user_by_usid(USid)
        if not user:
            return import_status("ERROR_NONE_USER", "GROUPMEAL_ERROR",
                                 "ERROR_NONE_USER")
        mess = self.smess.get_mess_by_msid(MSid)
        if not mess:
            return SYSTEM_ERROR
        # TODO 用户改为管理员
        data = request.data
        print(self.title.format("data"))
        print(data)
        print(self.title.format("data"))
        data = json.loads(data)

        meal_not_null_keys = ["MEname", "MEimage", "MEprice", "MEtype"]
        meal_null_keys = [
            "MEinfo", "MEdprice", "MEweight", "MEinventory", "MEprotein",
            "MEfat", "MEcarbohydrate", "MEcalorie", "MEinorganic", "MEcalcium",
            "MEphosphorus", "MEiron"
        ]

        for row in data.keys():
            if row not in meal_not_null_keys and row not in meal_null_keys:
                return PARAMS_REDUNDANCY

        data["MEvolume"] = 0
        data["MEfraction"] = 0
        data["MEstatus"] = 281
        data["MEtag"] = 296
        data["MSid"] = args["MSid"]
        data["MEid"] = str(uuid.uuid1())
        MEtype = data["MEtype"]
        data["MEtype"] = self.num_word_change(word=MEtype)

        print data
        new_meal = add_model("Meals", **data)
        print(self.title.format("new_meal"))
        print(new_meal)
        print(self.title.format("new_meal"))
        if not new_meal:
            return SYSTEM_ERROR

        return import_status("SUCCESS_ADD_MEAL", "OK")
Esempio n. 2
0
    def register(self):
        data = request.data
        data = json.loads(data)
        print(self.title.format("data"))
        print(data)
        print(self.title.format("data"))

        if "UStelphone" not in data or "USpassword" not in data or "UScode" not in data:
            return PARAMS_MISS

        user = self.susers.get_user_by_utel(data["UStelphone"])
        print(self.title.format("user"))
        print(user)
        print(self.title.format("user"))
        if user:
            return import_status("MESSAGE_ERROR_REPAET_TELPHONE", "GROUPMEAL_ERROR", "ERROR_CODE_NONE_TELPHONE")

        UScode_dict = self.susers.get_code_by_utel(data["UStelphone"])
        print(self.title.format("UScode"))
        print(UScode_dict)
        print(self.title.format("UScode"))
        if not UScode_dict:
            return import_status("ERROR_MESSAGE_NONE_ICCODE", "GROUPMEAL_ERROR", "ERROR_CODE_NONE_ICCODE")
        UScode = UScode_dict.ICcode
        if UScode != data["UScode"]:
            return import_status("ERROR_MESSAGE_WRONG_ICCODE", "GROUPMEAL_ERROR", "ERROR_CODE_WRONG_ICCODE")

        if "USinvatecode" in data:
            Uinvate = data["USinvatecode"]
            # TODO 创建优惠券

        UStelphone = "昵称" + str(data["UStelphone"])
        USinvatecode = self.make_invate_code()
        new_user = add_model("Users",
                  **{
                      "USid": str(uuid.uuid1()),
                      "USname": UStelphone,
                      "UStelphone": data["UStelphone"],
                      "USpassword": data["USpassword"],
                      "USlevel": 1,
                      "UScoin": 0,
                      "USinvatecode": USinvatecode
                  })
        if not new_user:
            return SYSTEM_ERROR

        back_response = import_status("SUCCESS_MESSAGE_REGISTER_OK", "OK")
        return back_response
Esempio n. 3
0
    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")
        USid = token_to_usid(token)
        MEid = data["MEid"]
        CAnumber = data["CAnumber"]
        if CAnumber <= 0:
            PBnumber = self.scart.get_canumber_by_meid_and_usid(MEid, USid)
            if not PBnumber:
                return SYSTEM_ERROR
            pnum = int(CAnumber) + int(PBnumber)
            if pnum <= 0:
                return self.del_cart(USid, MEid)
            else:
                cart = self.scart.get_cart_by_usid_meid(USid, MEid)
                print(self.title.format("cart"))
                print(cart)
                print(self.title.format("cart"))
                if not cart:
                    return SYSTEM_ERROR
                self.scart.update_num_cart(pnum, cart.CAid)
        else:
            try:
                if not self.smeal.get_meal_by_meid(MEid):
                    return import_status("ERROR_MESSAGE_NONE_PRODUCT",
                                         "GROUPMEAL_ERROR",
                                         "ERROR_NONE_PRODUCT")
                cart = self.scart.get_cart_by_usid_meid(USid, MEid)
                print(self.title.format("cart"))
                print(cart)
                print(self.title.format("cart"))
                if cart:
                    PBnumber = self.scart.get_canumber_by_meid_and_usid(
                        MEid, USid)
                    pnum = int(CAnumber) + int(PBnumber)
                    self.scart.update_num_cart(pnum, cart.CAid)
                else:
                    add_model(
                        "Cart", **{
                            "CAid": str(uuid.uuid1()),
                            "CAnumber": CAnumber,
                            "USid": USid,
                            "MEid": MEid
                        })
            except dberror:
                return SYSTEM_ERROR
            except Exception as e:
                print(e.message)
                return SYSTEM_ERROR

        return import_status("SUCCESS_MESSAGE_UPDATE_CART", "OK")
Esempio n. 4
0
    def make_main_order(self):
        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 or "MSid" not in args:
            return PARAMS_MISS

        params_list = ["Order_items", "OMtotal", "OMtime"]
        for params in params_list:
            if params not in data:
                return PARAMS_MISS
        null_params = ["OMabo", "CPid"]
        for params in data.keys():
            if params not in null_params and params not in params_list:
                return PARAMS_REDUNDANCY

        token = args.get("token")
        Uid = token_to_usid(token)
        user = self.susers.get_user_by_usid(Uid)
        if not user:
            return SYSTEM_ERROR
        MSid = args["MSid"]
        OMtime = timeformate.get_db_time_str(data["OMtime"])

        order_item = data["Order_items"]
        OMcode = self.make_code()
        import uuid
        OMid = str(uuid.uuid1())
        try:
            for op in order_item:
                MEstatus = self.smeal.get_mestatus_by_meid(op["MEid"])
                print(self.title.format("MEstatus"))
                print(MEstatus)
                print(self.title.format("MEstatus"))
                if MEstatus != 281:
                    return import_status("error_no_pro", "GROUPMEAL_ERROR",
                                         "error_no_pro")
                msid = self.smeal.get_msid_by_meid(op["MEid"])
                if msid != MSid:
                    return import_status("ERROR_MEAL_IN_MESS",
                                         "GROUPMEAL_ERROR",
                                         "ERROR_MEAL_IN_MESS")
                add_model(
                    "OrderPart", **{
                        "OPid": str(uuid.uuid1()),
                        "OMid": OMid,
                        "MEid": op["MEid"],
                        "MEnumber": op["MEnumber"]
                    })
                volume = self.smeal.get_mevolume_by_meid(op["MEid"])
                volume = volume + 1
                update_meal = self.smeal.update_meal(op["MEid"],
                                                     {"MEvolume": volume})
                if not update_meal:
                    return SYSTEM_ERROR

                cart = get_model_return_dict(
                    self.scart.get_cart_by_usid_meid(Uid, op["MEid"]))
                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"))
            # TODO 增加优惠券id
            self.sorders.add_model(
                "OrderMain", **{
                    "OMid": OMid,
                    "OMtime": OMtime,
                    "OMstatus": 301,
                    "USid": Uid,
                    "OMcode": OMcode,
                    "OMabo": data["OMabo"],
                    "OMtotal": data["OMtotal"]
                })

            # self.scoupons.update_carbackage(get_str(data, "CAid"))
            response_make_main_order = import_status("SUCCESS_MAKE_ORDER",
                                                     "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
Esempio n. 5
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 != 305:
            return import_status("ERROR_MESSAGE_WRONG_OMSTATUS",
                                 "GROUPMEAL_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 "MEid" not in row or "REscore" not in row or "REfscore" not in row:
                return PARAMS_MISS
            if "REcontent" in row:
                REcontent = row["REcontent"]
            else:
                REcontent = None
            PRid = row["MEid"]
            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,
                        "MEid": PRid,
                        "REscore": REscore,
                        "REcontent": REcontent,
                        "REfscore": row["REfscore"]
                    })
            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.smeal.get_mevolume_by_meid(PRid)
            product_score = self.smeal.get_mefrac_by_meid(PRid)

            score = (product_score * product_volue + REscore) / product_volue
            product = {"MEfraction": score}
            update_product = self.smeal.update_meal(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": 306}
            update_order = self.service_order.update_order_by_oid(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