Пример #1
0
 def post(self):
     self.parser.add_argument("email", type=inputs.regex(r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'),
                              required=True, location="json",
                              help='email format is incorrect')
     self.parser.add_argument("totalPrice", type=int, required=True, location="json", help='totalPrice format is incorrect')
     self.parser.add_argument("username", type=str, required=True, location="json",
                              help='username format is incorrect')
     self.parser.add_argument("phone", type=str, required=True, location="json",
                              help='phone format is incorrect')
     self.parser.add_argument("payType", type=str, required=True, location="json",
                              help='payType format is incorrect')
     self.parser.add_argument("productList", type=list, required=True, location="json",
                              help='productList format is incorrect')
     self.parser.add_argument("addressId", type=str, required=True, location="json",
                              help='addressId format is incorrect')
     args = self.parser.parse_args()
     mallUsersInfo = MallUsersModel.query.filter_by(email=args.email).first()
     if mallUsersInfo.balance < args.totalPrice:
         return pretty_result(code.ERROR, msg="create order failed, balance ont enough!")
     else:
         for i in args.productList:
             proudctInfo = ProductsModel.query.filter_by(id=i).first()
             proudctInfo.status = "solded"
             ProductsModel.update(proudctInfo)
         mallUsersInfo.balance = mallUsersInfo.balance - args.totalPrice
         MallUsersModel.update(mallUsersInfo)
     order = OrdersModel(email=args.email,no=get_order_code(), username=args.username, totalPrice=args.totalPrice, phone=args.phone.replace("-", ""),
                             couponPrice=0, payType=args.payType, status="noDelivery", productList=','.join([str(x) for x in args.productList]),
                             addressId=args.addressId)
     OrdersModel.add(OrdersModel, order)
     return pretty_result(code.OK, msg="create order info successful!")
Пример #2
0
    def put(self, token):
        try:
            data = self.parser.parse_args()
            validateObj = ProductsModel.validateData(data, request)
            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            product_id = decodeID(token)
            product = ProductsModel.find_by_id(product_id)
            if not product or product.token != token:
                return {"success": False, 'message': 'Record Not Found'}, 404

            product.product_name = data['product_name']
            product.logo = data['logo']
            product.brand_id = data['brand_id']
            product.category_id = data['category_id']
            product.modified_on = datetime.now()
            product.modified_by = 1
            name = data['product_name']
            if name.strip():
                product.save_to_db()
            else:
                return {
                    "success": False,
                    "message": "String Should not be empty"
                }

            return {
                "success": True,
                "message": "Record updated successfully."
            }, 200
        except Exception as e:
            return {"success": False, "message": str(e)}
Пример #3
0
 def get(self, product_name):
     product = ProductsModel.find_by_name(product_name)
     try :
         if product:
             return product.json()
     except Exception as e:
         return {"message": "Record not found'{}'".format(e)}, 404
Пример #4
0
 def get(cls, token):
     try:
         product_id = decodeID(token)
         product = ProductsModel.find_by_id(product_id)
         if not product or product.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         return product.json(), 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Пример #5
0
    def post(self, product_name):
        db.create_all()
        db.session.commit()
        if ProductsModel.find_by_name(product_name):
            return {'message': "An Record with name '{}' already exists.".format(product_name)}, 400

        data = self.parser.parse_args()
        
        
        product = ProductsModel(product_name,**data,)
        product.created_by = 1
        product.created_on = datetime.now()
        product.modified_by = 0
        product.deleted_by = 0
        try:
            
            product.save_to_db()
        except Exception as e:
            return {"message": "An error occurred while inserting the Record.'{}'".format(e)}
            
        return product.json(), 201
Пример #6
0
 def delete(cls, product_name):
     product = ProductsModel.find_by_name(product_name)
     if product:
         product.deleted_by =1
         product.deleted_on = datetime.now()
         product.save_to_db()
         #product.delete_from_db()
         return {'message': 'Record deleted'}
         
         
     else :
         return {"Message":"Record Not FOUND"}
Пример #7
0
 def put(self, product_name):
     data = self.parser.parse_args()
     product=ProductsModel.find_by_name(product_name)
     if product:
         product.modified_on = datetime.now()
         product.modified_by = 1
         product.logo = data['logo']
         product.brand_id = data['brand_id']
         product.category_id = data['category_id']
         
     else :
         return {"Message":"Record Not FOUND"}
     product.save_to_db()
     return product.json()
Пример #8
0
    def delete(cls, token):
        try:
            product_id = decodeID(token)
            product = ProductsModel.find_by_id(product_id)
            if not product or product.token != token:
                return {"success": False, 'message': 'Record Not Found'}, 404

            product.deleted_by = 1
            product.deleted_on = datetime.now()
            product.save_to_db()
            #product.delete_from_db()
            return {"success": True, 'message': 'Record deleted.'}, 200
        except Exception as e:
            return {"success": False, "message": str(e)}
Пример #9
0
    def delete(self):
        self.parser.add_argument("ids",
                                 type=list,
                                 required=True,
                                 location="json",
                                 help='ids is required')
        self.parser.add_argument("updateUser",
                                 type=str,
                                 required=True,
                                 location="json",
                                 help='updateUser is required')
        self.parser.add_argument("content",
                                 type=list,
                                 required=True,
                                 location="json",
                                 help='content is required')
        args = self.parser.parse_args()
        for item in args.ids:
            productInfo = ProductsModel.query.filter_by(id=item).first()
            productPictureList = productInfo.picture.split(",")
            for j in productPictureList:
                old_fname = filePath + str(j) + '.png'
                if os.path.exists(old_fname):
                    os.remove(old_fname)
                else:
                    print(str(j) + " the file does not exist")

        ProductsModel.delete(ProductsModel, args.ids)
        content = str(args.content)
        if len(str(args.content)) > 500:
            content = str(args.ids)
        log = LogsModel(username=args.updateUser,
                        model="product",
                        action="delete",
                        content=content)
        LogsModel.add(LogsModel, log)
        return pretty_result(code.OK, msg='商品信息删除成功!')
Пример #10
0
 def get(self):
     """
     获取商品列表信息
     :return: json
     """
     self.parser.add_argument("type",
                              type=str,
                              required=True,
                              location="args",
                              help='ids is required')
     args = self.parser.parse_args()
     id = ProductsModel.get_id(ProductsModel)
     no = ""
     if not id[0][0]:
         no = args.type + "%012d" % 1
     else:
         no = args.type + "%012d" % (id[0][0] + 1)
     return pretty_result(code.OK, data=no, msg='获取商品No信息删除成功!')
Пример #11
0
 def get(self):
     """
     获取商品列表信息
     :return: json
     """
     self.parser.add_argument("pageNo",
                              type=int,
                              required=True,
                              location="args",
                              help='pageNo is required')
     self.parser.add_argument("pageSize",
                              type=int,
                              required=True,
                              location="args",
                              help='pageSize is required')
     self.parser.add_argument("no",
                              type=str,
                              required=True,
                              location="args",
                              help='no is required')
     self.parser.add_argument("Pclass",
                              type=str,
                              required=True,
                              location="args",
                              help='Pclass is required')
     args = self.parser.parse_args()
     product_list = ProductsModel.paginate(ProductsModel, args.pageNo,
                                           args.pageSize)
     items = []
     totalCount = product_list.total
     product_list = product_list.items
     if args.no or args.Pclass:
         product_list = ProductsModel.filter_by_no_Pclass(
             ProductsModel, args.no, args.Pclass)
         totalCount = len(product_list)
     for product in product_list:
         fileList = []
         pictures = product.picture.split(",")
         for i in pictures:
             url = config.domain + "/api/v1/pictureManagement/get?type=product&id=" + i
             fileList.append({"name": i, "url": url})
         items.append({
             'id':
             product.id,
             'no':
             product.no,
             'name':
             product.name,
             'description':
             product.description,
             'position':
             product.position,
             'picture':
             fileList,
             'gender':
             product.gender,
             'size':
             product.size,
             'age':
             product.age,
             'Pclass':
             product.Pclass,
             'type':
             product.type,
             'status':
             product.status,
             'inPrice':
             product.inPrice,
             'outPrice':
             product.outPrice,
             'price':
             product.price,
             'level':
             product.level,
             'showTimes':
             product.showTimes,
             'remark':
             product.remark,
             'updateUser':
             product.updateUser,
             'updateTime':
             product.update_time.strftime("%m/%d/%Y %H:%M:%S")
         })
     data = {
         'pageNo': args.pageNo,
         'pageSize': args.pageSize,
         'totalCount': totalCount,
         'items': items
     }
     return pretty_result(code.OK, data=data, msg='商品信息获取成功!')
Пример #12
0
 def put(self):
     self.parser.add_argument("id",
                              type=int,
                              required=True,
                              location="form",
                              help='id is required')
     self.parser.add_argument("no",
                              type=str,
                              required=True,
                              location="form",
                              help='no is required')
     self.parser.add_argument("name",
                              type=str,
                              required=True,
                              location="form",
                              help='name is required')
     self.parser.add_argument("description",
                              type=str,
                              required=True,
                              location="form",
                              help='description is required')
     self.parser.add_argument("position",
                              type=str,
                              required=True,
                              location="form",
                              help='position is required')
     self.parser.add_argument("picture",
                              type=FileStorage,
                              location='files',
                              action='append',
                              help='picture is file')
     self.parser.add_argument("gender",
                              type=str,
                              required=True,
                              location="form",
                              help='gender is required')
     self.parser.add_argument("size",
                              type=str,
                              required=True,
                              location="form",
                              help='size is required')
     self.parser.add_argument("age",
                              type=str,
                              required=True,
                              location="form",
                              help='age is required')
     self.parser.add_argument("Pclass",
                              type=str,
                              required=True,
                              location="form",
                              help='Pclass is required')
     self.parser.add_argument("type",
                              type=str,
                              required=True,
                              location="form",
                              help='type is required')
     self.parser.add_argument("status",
                              type=str,
                              required=True,
                              location="form",
                              help='status is required')
     self.parser.add_argument("inPrice",
                              type=str,
                              required=True,
                              location="form",
                              help='inprice is required')
     self.parser.add_argument("outPrice",
                              type=str,
                              required=True,
                              location="form",
                              help='outprice is required')
     self.parser.add_argument("price",
                              type=int,
                              required=True,
                              location="form",
                              help='price is required')
     self.parser.add_argument("level",
                              type=int,
                              required=True,
                              location="form",
                              help='level is required')
     self.parser.add_argument("showTimes",
                              type=str,
                              required=True,
                              location="form",
                              help='showTimes is required')
     self.parser.add_argument("remark",
                              type=str,
                              location="form",
                              help='remark is not required')
     self.parser.add_argument("updateUser",
                              type=str,
                              required=True,
                              location="form",
                              help='updateUser is required')
     self.parser.add_argument("removeList",
                              type=str,
                              required=True,
                              location="form",
                              help='removelist is required')
     args = self.parser.parse_args()
     productNoInfo = ProductsModel.query.filter_by(no=args.no).all()
     for item in productNoInfo:
         if item.id != args.id:
             return pretty_result(code.ERROR, msg='该商品编号已存在,不可以编辑!')
     productInfo = ProductsModel.query.filter_by(no=args.no).first()
     productPictureList = productInfo.picture.split(",")
     removeList = args.removeList.split(",")
     pictureList = ''
     for j in removeList:
         if j in productPictureList:
             productPictureList.remove(j)
             old_fname = filePath + str(j) + '.png'
             if os.path.exists(old_fname):
                 os.remove(old_fname)
             else:
                 print(str(j) + " the file does not exist")
     if args.picture:
         for item in args.picture:
             if item.filename in removeList:
                 continue
             new_fname = filePath + str(item.filename) + '.png'
             item.save(new_fname)
             productPictureList.append(str(item.filename))
     pictureList = ','.join(productPictureList)
     productInfo.no = args.no
     productInfo.name = args.name
     productInfo.description = args.description
     productInfo.position = args.position
     productInfo.picture = pictureList
     productInfo.gender = args.gender
     productInfo.size = args.size
     productInfo.age = args.age
     productInfo.Pclass = args.Pclass
     productInfo.type = args.type
     productInfo.status = args.status
     productInfo.inPrice = args.inPrice
     productInfo.outPrice = args.outPrice
     productInfo.price = args.price
     productInfo.level = args.level
     productInfo.showTimes = args.showTimes
     productInfo.remark = args.remark
     productInfo.updateUser = args.updateUser
     ProductsModel.update(productInfo)
     content = str({
         "no": args.no,
         "name": args.name,
         "description": args.description,
         "position": args.position,
         "picture": pictureList,
         "gender": args.gender,
         "size": args.size,
         "age": args.age,
         "Pclass": args.Pclass,
         "type": args.type,
         "status": args.status,
         "inPrice": args.inPrice,
         "outPrice": args.outPrice,
         "price": args.price,
         "level": args.level,
         "remark": args.remark,
         "showTimes": args.showTimes,
         "updateUser": args.updateUser
     })
     log = LogsModel(username=args.updateUser,
                     model="product",
                     action="edit",
                     content=content)
     LogsModel.add(LogsModel, log)
     return pretty_result(code.OK, msg='商品信息修改成功!')
Пример #13
0
 def post(self):
     self.parser.add_argument("no",
                              type=str,
                              required=True,
                              location="form",
                              help='no is required')
     self.parser.add_argument("name",
                              type=str,
                              required=True,
                              location="form",
                              help='name is required')
     self.parser.add_argument("description",
                              type=str,
                              required=True,
                              location="form",
                              help='description is required')
     self.parser.add_argument("position",
                              type=str,
                              required=True,
                              location="form",
                              help='position is required')
     self.parser.add_argument("picture",
                              type=FileStorage,
                              required=True,
                              location='files',
                              action='append',
                              help='picture is required')
     self.parser.add_argument("gender",
                              type=str,
                              required=True,
                              location="form",
                              help='gender is required')
     self.parser.add_argument("size",
                              type=str,
                              required=True,
                              location="form",
                              help='size is required')
     self.parser.add_argument("age",
                              type=str,
                              required=True,
                              location="form",
                              help='age is required')
     self.parser.add_argument("Pclass",
                              type=str,
                              required=True,
                              location="form",
                              help='Pclass is required')
     self.parser.add_argument("type",
                              type=str,
                              required=True,
                              location="form",
                              help='type is required')
     self.parser.add_argument("status",
                              type=str,
                              required=True,
                              location="form",
                              help='status is required')
     self.parser.add_argument("inPrice",
                              type=int,
                              required=True,
                              location="form",
                              help='inPrice is required')
     self.parser.add_argument("outPrice",
                              type=int,
                              required=True,
                              location="form",
                              help='outPrice is required')
     self.parser.add_argument("price",
                              type=int,
                              required=True,
                              location="form",
                              help='price is required')
     self.parser.add_argument("level",
                              type=int,
                              required=True,
                              location="form",
                              help='level is required')
     self.parser.add_argument("showTimes",
                              type=int,
                              default=0,
                              location="form",
                              help='showTimes is required')
     self.parser.add_argument("remark",
                              type=str,
                              location="form",
                              help='remark is not required')
     self.parser.add_argument("updateUser",
                              type=str,
                              required=True,
                              location="form",
                              help='updateUser is required')
     self.parser.add_argument("removeList",
                              type=str,
                              required=True,
                              location="form",
                              help='removelist is required')
     args = self.parser.parse_args()
     productNoInfo = ProductsModel.query.filter_by(no=args.no).all()
     if productNoInfo:
         return pretty_result(code.ERROR, msg='该商品已经被录入!')
     removeList = args.removeList.split(",")
     pictureList = ''
     for item in args.picture:
         if item.filename in removeList:
             continue
         new_fname = filePath + str(item.filename) + '.png'
         item.save(new_fname)
         pictureList = pictureList + str(item.filename) + ","
     pictureList = pictureList[:-1]
     product = ProductsModel(no=args.no,
                             position=args.position,
                             picture=pictureList,
                             gender=args.gender,
                             size=args.size,
                             age=args.age,
                             Pclass=args.Pclass,
                             type=args.type,
                             name=args.name,
                             description=args.description,
                             status=args.status,
                             inPrice=args.inPrice,
                             outPrice=args.outPrice,
                             price=args.price,
                             level=args.level,
                             remark=args.remark,
                             showTimes=args.showTimes,
                             updateUser=args.updateUser)
     ProductsModel.add(ProductsModel, product)
     if product.id:
         content = str({
             "no": args.no,
             "name": args.name,
             "description": args.description,
             "position": args.position,
             "picture": pictureList,
             "gender": args.gender,
             "size": args.size,
             "age": args.age,
             "Pclass": args.Pclass,
             "type": args.type,
             "status": args.status,
             "inPrice": args.inPrice,
             "outPrice": args.outPrice,
             "price": args.price,
             "level": args.level,
             "remark": args.remark,
             "showTimes": args.showTimes,
             "updateUser": args.updateUser
         })
         log = LogsModel(username=args.updateUser,
                         model="product",
                         action="add",
                         content=content)
         LogsModel.add(LogsModel, log)
         return pretty_result(code.OK, msg='商品信息创建成功!')
     else:
         return pretty_result(code.Error, msg='商品信息创建失败!')
Пример #14
0
 def post(self):
     """
     抽奖信息
     :return: json
     """
     self.parser.add_argument("gender", type=str, required=True, location="json",
                              help='gender is required')
     self.parser.add_argument("size", type=str, required=True, location="json",
                              help='size is required')
     self.parser.add_argument("age", type=str, required=True, location="json",
                              help='age is required')
     self.parser.add_argument("Pclass", type=str, required=True, location="json",
                              help='Pclass is required')
     self.parser.add_argument("count", type=int, required=True, location="json",
                              help='count is required')
     self.parser.add_argument("point", type=int, required=True, location="json",
                              help='point is required')
     self.parser.add_argument("email", type=inputs.regex(r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'),
                              required=True, location="json",
                              help='email format is incorrect')
     args = self.parser.parse_args()
     products = ProductsModel.filter_by_gender_size_age_Pclass(ProductsModel, args.gender, args.size, args.age, args.Pclass)
     i = 0
     showData = []
     data=[]
     for item in products:
         print(item)
         if i >= args.count:
             break
         if item.status == "unsold":
             i = i + 1
             showData.append(item)
     if i < args.count:
         for item in products:
             if i >= args.count:
                 break
             if item.status == "online":
                 if (datetime.datetime.now() - item.update_time).total_seconds() > config.countDown:
                     i = i + 1
                     showData.append(item)
     if i < args.count:
         return pretty_result(code.ERROR, data=[], msg='Get award info failed, Product not enough!')
     else:
         for j in showData:
             # 更新次数和状态
             productsInfo = ProductsModel.query.filter_by(id=j.id).first()
             productsInfo.status = 'online'
             productsInfo.showTimes = productsInfo.showTimes + 1
             ProductsModel.update(productsInfo)
             url = ''
             pictures = productsInfo.picture.split(",")
             for i in pictures:
                 url = config.domain + "/api/v1/pictureManagement/get?type=product&id=" + i
                 break
             data.append(
                 {
                     'id': productsInfo.id,
                     'no': productsInfo.no,
                     'position': productsInfo.position,
                     'picture': url,
                     'gender': productsInfo.gender,
                     'size': productsInfo.size,
                     'age': productsInfo.age,
                     'Pclass': productsInfo.Pclass,
                     'type': productsInfo.type,
                     'status': productsInfo.status,
                     'inPrice': productsInfo.inPrice,
                     'outPrice': productsInfo.outPrice,
                     'price': productsInfo.price,
                     'level': productsInfo.level,
                     'showTimes': productsInfo.showTimes,
                     'remark': productsInfo.remark,
                     'updateUser': productsInfo.updateUser,
                     'updateTime': productsInfo.update_time.strftime("%m/%d/%Y %H:%M:%S")
                 }
             )
             Cart = CartsModel(email=args.email, no=productsInfo.no)
             CartsModel.add(CartsModel, Cart)
         mallUserInfo = MallUsersModel.query.filter_by(email=args.email).first()
         mallUserInfo.point = mallUserInfo.point - args.point
         MallUsersModel.update(mallUserInfo)
         return pretty_result(code.OK, data=data, msg='Get award info successful!')
Пример #15
0
 def put(self):
     self.parser.add_argument("cartItemIds",
                              type=list,
                              location="json",
                              help='cartItemIds format is incorrect')
     args = self.parser.parse_args()
     if args.cartItemIds:
         productInfo = ProductsModel.get_ids(ProductsModel,
                                             args.cartItemIds)
         data = []
         for product in productInfo:
             url = ''
             countDown = (datetime.datetime.now() -
                          product.update_time).total_seconds()
             pictures = product.picture.split(",")
             for i in pictures:
                 url = config.domain + "/api/v1/pictureManagement/get?type=product&id=" + i
                 break
             data.append({
                 'id':
                 product.id,
                 'no':
                 product.no,
                 'name':
                 product.name,
                 'description':
                 product.description,
                 'position':
                 product.position,
                 'picture':
                 url,
                 'gender':
                 product.gender,
                 'size':
                 product.size,
                 'age':
                 product.age,
                 'Pclass':
                 product.Pclass,
                 'type':
                 product.type,
                 'status':
                 product.status,
                 'inPrice':
                 product.inPrice,
                 'outPrice':
                 product.outPrice,
                 'price':
                 product.price,
                 'level':
                 product.level,
                 'showTimes':
                 product.showTimes,
                 'remark':
                 product.remark,
                 'time': (config.countDown - countDown) * 1000,
                 'updateUser':
                 product.updateUser,
                 'updateTime':
                 product.update_time.strftime("%m/%d/%Y %H:%M:%S")
             })
         return pretty_result(code.OK,
                              data=data,
                              msg="get create order info successful!")
     else:
         return pretty_result(code.OK,
                              data=[],
                              msg="get create order info successful!")
Пример #16
0
    def post(self):
        data = self.parser.parse_args()
        product = ProductsModel(**data)
        product.created_by = 1
        product.created_on = datetime.now()
        product.modified_by = 0
        product.deleted_by = 0
        product.modified_on = None
        product.deleted_on = None

        try:
            validateObj = ProductsModel.validateData(data, request)

            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            if ProductsModel.find_by_name(data['product_name']):
                return {
                    "success": False,
                    "message": "A product with that Record Name already exists"
                }, 400
            name = data['product_name']
            if name.strip():
                product.save_to_db()
                product.token = encodeID(product.product_id)
                product.save_to_db()
            else:
                return {
                    "success": False,
                    "message": "String Should not be empty"
                }
        except Exception as e:
            return {
                "message":
                "An error occurred creating the Record.'{}'".format(e)
            }, 500
        return product.json(), 201