58 lines
2.0 KiB
Plaintext
58 lines
2.0 KiB
Plaintext
async def shoppingCartUpdate(ns={}):
|
|
"""
|
|
update cart *为必填项
|
|
`cartid` 购物车id和用户id相同 *
|
|
`productid` '产品id' *
|
|
`spec_id` '规格id' *
|
|
`quantity` '数量' * int
|
|
`list_price` '原价' * double
|
|
`discount` '折扣' * double
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
# get search origin data to update amount and quantity
|
|
cart_org_data = await sor.R('cart_goods', {'id': ns.get('id')})
|
|
cart_data = cart_org_data[0] if cart_org_data else {}
|
|
if not cart_data:
|
|
return {
|
|
"status": False,
|
|
"msg": "cart_goods update failed, can not get id",
|
|
}
|
|
ns['cartid'] = cart_data.get('cartid')
|
|
ns['amount'] = cart_data.get('price') * int(ns.get('quantity'))
|
|
await sor.U('cart_goods', ns)
|
|
|
|
# update customer_cart after update cart_goods
|
|
ns_sort = {
|
|
'cartid': ns.get('cartid'),
|
|
'del_flg': '0'
|
|
}
|
|
cart_goods = await sor.R('cart_goods', ns_sort)
|
|
price_amount = 0
|
|
for goods in cart_goods:
|
|
price_amount += goods.get('amount')
|
|
customer_cart = {
|
|
# 购物车id, 用户id相同
|
|
'id': ns.get('cartid'),
|
|
'last_date': time.strftime('%Y-%m-%d'),
|
|
'customerid': ns.get('cartid'),
|
|
'goods_cnt': len(cart_goods),
|
|
'amount': price_amount
|
|
}
|
|
await sor.U('customer_cart', customer_cart)
|
|
return {
|
|
"status": True,
|
|
"msg": "cart_goods update success"
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
"status": False,
|
|
"msg": "cart_goods update failed",
|
|
}
|
|
|
|
|
|
ret = await shoppingCartUpdate(params_kw)
|
|
return ret |