Example #1
0
    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
Example #2
0
    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
Example #3
0
 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,
     }
Example #4
0
    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
Example #5
0
    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