def remove_cart(): id = request.args["id"] if id: ShoppingCart.remove_cart(id) return Success(msg="移除成功") else: return ParameterException(msg="请传入商品id")
def address_delete(): id = request.args["id"] if id: Address.delete_address(id=id) return Success(msg="删除成功") else: return ParameterException(msg="请传入地址id")
def append_cart(): data = eval(str(request.data, encoding='utf-8')) form = Append_Cart(ImmutableMultiDict(data)) if form.validate(): ShoppingCart.append_cart(form) return Success(msg="加入购物成功") else: return ParameterException(msg=form.errors)
def amend(): data = eval(str(request.data, encoding='utf-8')) form = AddressAmend(ImmutableMultiDict(data)) if form.validate(): Address.amend_default_address(form) return Success(msg="更改地址成功") else: return ParameterException(msg=form.errors)
def clear_cart(cls): cart = ShoppingCart.query.filter_by(delete_time=None).all() if cart: date = datetime.now() for item in cart: item.update(delete_time=date, commit=True) return Success(msg="清空成功") else: return NotFound(msg="空空如已")
def add_comm(): """ 添加商品信息 :return: """ data = eval(str(request.data, encoding='utf-8')) form = CommForm(ImmutableMultiDict(data)) if form.validate(): Commodity.insert_comm(data) # 添加商品到数据库 return Success(msg="添加商品成功") else: return Failed(msg=form.errors)
def put_comm(): """ 更新商品信息 :return: """ data = eval(str(request.data, encoding='utf-8')) form = PutCommForm(ImmutableMultiDict(data)) if form.validate(): if Commodity.update_comm(data): return Success(msg="更新商品成功") else: return Failed(msg=form.errors)
def del_comm(): """ 删除商品信息 :return: """ id = request.args["id"] if id: comm = Commodity.del_comm(id) if comm: return Success(msg="删除商品成功") else: return Failed(msg="此商品不存在") else: return Failed(msg="请传入商品id")