Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_address():
"""添加地址
"""
data = request.get_json()
address = AddressSchema().load(data)
session.add(address)
session.commit()
return json_response(address=AddressSchema().dump(address))
User.wallet_money: payer.wallet_money - wallet_transaction.amount
})
if count == 0:
session.rollback()
return json_response(ResponseCode.TRANSACTION_FAILURE)
count = User.query.filter(
and_(User.id == payee.id, User.wallet_money == payee.wallet_money)
).update({
User.wallet_money: payee.wallet_money + wallet_transaction.amount
})
if count == 0:
session.rollback()
return json_response(ResponseCode.TRANSACTION_FAILURE)
session.add(wallet_transaction)
session.commit()
return json_response(wallet_transaction=WalletTransactionSchema().dump(wallet_transaction))
CartProduct.user_id == cart_product.user_id).all()
# 商品是否已在购物车
existed = None
for v in cart_products:
if v.product_id == cart_product.product_id:
existed = v
break
# 购物车商品数量不能超过限制
if len(cart_products) >= current_app.config['CART_PRODUCT_LIMIT'] and existed is None:
return json_response(ResponseCode.QUANTITY_EXCEEDS_LIMIT)
# 商品已在购物车则更新数量,否则添加一条新纪录
if existed is None:
session.add(cart_product)
else:
existed.amount += cart_product.amount
session.commit()
return json_response(cart_product=CartProductSchema().dump(cart_product if existed is None else existed))
def create_product():
"""创建商品
"""
data = request.get_json()
product = ProductSchema().load(data)
session.add(product)
session.commit()
return json_response(product=ProductSchema().dump(product))
def create_shop():
"""创建店铺
"""
data = request.get_json()
shop = ShopSchema().load(data)
session.add(shop)
session.commit()
return json_response(shop=ShopSchema().dump(shop))
def create_favorite_product():
"""收藏商品
"""
data = request.get_json()
favorite_product = FavoriteProductSchema().load(data)
session.add(favorite_product)
session.commit()
return json_response(favorite_product=FavoriteProductSchema().dump(favorite_product))