73 lines
2.8 KiB
Plaintext
73 lines
2.8 KiB
Plaintext
async def shoppingCartSearch(ns={}):
|
|
"""
|
|
search cart *为必填项
|
|
id *
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
if not ns:
|
|
return {
|
|
"status": False,
|
|
"msg": "customer_cart search failed, id is empty",
|
|
"data": ""
|
|
}
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
# find orgid info from users
|
|
org_info = await sor.R('users', {'id': await get_user(), 'del_flg': '0'})
|
|
if org_info:
|
|
orgid = org_info[0].get('orgid')
|
|
else:
|
|
return {
|
|
'status': False,
|
|
'msg': 'can not find orgid from users, userid: %s' % await get_user()
|
|
}
|
|
|
|
result = {}
|
|
ns['del_flg'] = '0'
|
|
# ns['sort'] = 'create_at'
|
|
# ns['order'] = 'desc'
|
|
ns['page'] = ns.get('page') if ns.get('page') else 1
|
|
cart_sql = """select * from cart_goods where cartid = '%s' and del_flg=0""" % orgid
|
|
cart_result = await sor.sqlExe(cart_sql, {})
|
|
origin_price_amount = 0
|
|
product_detail_list = []
|
|
for cart in cart_result:
|
|
product_id = cart['productid']
|
|
product_info_li = await sor.R('product', {'id': product_id, 'del_flg': '0'})
|
|
product_info = product_info_li[0] if product_info_li else {}
|
|
if product_info:
|
|
product_info.pop('id')
|
|
# product_info.pop('price')
|
|
cart.update(product_info)
|
|
# 查找配置
|
|
config_spec_li = await sor.R('specificdata', {'id': cart['spec_id'], 'del_flg': '0'})
|
|
if config_spec_li:
|
|
cart['spec_data'] = config_spec_li[0]['spec_data']
|
|
|
|
product_detail_list.append(cart)
|
|
origin_price_amount += cart['list_price'] * cart['quantity']
|
|
ns['customerid'] = orgid
|
|
customer_cart = await sor.R('customer_cart', ns)
|
|
# add cartid to apply on buy button
|
|
result['cartid'] = customer_cart.get('rows')[0].get('customerid')
|
|
result['goods_cnt'] = customer_cart.get('rows')[0].get('goods_cnt')
|
|
result['discount_amount'] = customer_cart.get('rows')[0].get('amount')
|
|
result['origin_amount'] = round(origin_price_amount, 2)
|
|
result['cart_list'] = product_detail_list
|
|
return {
|
|
"status": True,
|
|
"msg": "customer_cart search success",
|
|
"data": result
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
"status": False,
|
|
"msg": "customer_cart search failed"
|
|
}
|
|
|
|
|
|
ret = await shoppingCartSearch(params_kw)
|
|
return ret |