78 lines
3.5 KiB
Plaintext
78 lines
3.5 KiB
Plaintext
async def DiscontProductSearch(ns={}):
|
||
"""
|
||
search discount product
|
||
if ns is None, return all product
|
||
Can be queried using separate fields
|
||
:param ns:
|
||
:return:
|
||
"""
|
||
db = DBPools()
|
||
async with db.sqlorContext('kboss') as sor:
|
||
try:
|
||
ns['del_flg'] = '0'
|
||
ns['sort'] = 'create_at'
|
||
ns['order'] = 'desc'
|
||
ns['page'] = ns.get('page')
|
||
if not ns.get('page'):
|
||
return {
|
||
'status': False,
|
||
'msg': 'page is null'
|
||
}
|
||
orgid_find = await sor.R('users', {'id': await get_user(), 'del_flg': '0'})
|
||
if orgid_find:
|
||
orgid = orgid_find[0].get('orgid')
|
||
else:
|
||
return {
|
||
'status': False,
|
||
'msg': 'can not find orgid'
|
||
}
|
||
# <20><><EFBFBD>ҵ<D2B5>
|
||
floor_sql = """select fl.offer_orgid, fl.bid_orgid, fl.productid, fl.price, p.id, p.providerid, p.providerpid, p.name, p.description, p.ptype, p.state,
|
||
p.effect_date, p.expire_date, p.salemode, p.product_code,
|
||
p.spec_note, p.product_area, p.specific_pattern, p.reseller_orgid FROM floorprice as fl
|
||
LEFT JOIN product as p on fl.productid=p.id where fl.offer_orgid='%s' and fl.bid_orgid=''
|
||
and fl.del_flg='0';""" % orgid
|
||
floor_sql_res_li = await sor.sqlExe(floor_sql, {})
|
||
|
||
# filter discount and rebate
|
||
ns.pop('userid')
|
||
# product_res_list = await sor.R('product', ns)
|
||
cp_discount_sql = """select cp.customerid, cp.productid, cp.discount, p.id, p.providerid, p.providerpid,
|
||
p.name, p.description, p.ptype, p.state, p.effect_date, p.expire_date, p.salemode,
|
||
p.product_code, p.spec_note, p.product_area, p.specific_pattern, p.reseller_orgid from
|
||
cp_discount as cp left join product as p on cp.productid=p.id where
|
||
customerid = '%s' and cp.del_flg = '0' and CURRENT_DATE between
|
||
cp.start_date and cp.end_date;""" % orgid
|
||
cp_discount_list = await sor.sqlExe(cp_discount_sql, {'customerid': orgid})
|
||
# cp_dict = {}
|
||
# result = []
|
||
# for cp in cp_discount_list:
|
||
# cp_dict[cp.get('productid')] = cp.get('discount')
|
||
# keys_list = list(cp_dict.keys())
|
||
# for product in product_res_list.get('rows'):
|
||
# productid = product.get('id')
|
||
# if productid in keys_list:
|
||
# product['discount'] = cp_dict[productid]
|
||
# # product['discount_price'] = round(product['price'] * cp_dict[productid], 2)
|
||
# result.append(product)
|
||
if cp_discount_list:
|
||
# result = sorted(cp_discount_list, key=lambda x: x['start_date'], reverse=True)
|
||
result = cp_discount_list
|
||
else:
|
||
result = []
|
||
result.extend(floor_sql_res_li)
|
||
return {
|
||
"status": True,
|
||
"msg": "product search success ",
|
||
"data": result
|
||
}
|
||
except Exception as e:
|
||
return {
|
||
"status": False,
|
||
"msg": "product search failed",
|
||
'err_msg': e
|
||
}
|
||
|
||
|
||
ret = await DiscontProductSearch(params_kw)
|
||
return ret |