Esempio n. 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!")
Esempio n. 2
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='商品信息修改成功!')
Esempio n. 3
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!')