kboss/b/zj/product_salemode_search - 副本 - 副本.dspy
2025-07-16 14:27:17 +08:00

68 lines
3.0 KiB
Plaintext

async def product_salemode_search(ns={}):
"""
产品价格不落地
查找sale_protocol以后 具体产品配置查找
:param ns:
:return:
"""
db = DBPools()
async with db.sqlorContext('kboss') as sor:
try:
if ns.get('salemode') == '0':
res_list = []
ns_search = {
'protocolid': ns.get('protocolid'),
'del_flg': '0'
}
res = await sor.R('product_salemode', ns_search)
# 首先查找不是*的产品 加到产品列表
# 已经存在的id列表
prd_singles = [item.get('productid') for item in res if item.get('productid') != '*']
# 已经存在的id列表 包含对应折扣
prd_single_ids = [(item.get('productid'), item.get('discount')) for item in res if item.get('productid') != '*']
for prd_single in prd_single_ids:
single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
between effect_date and expire_date;""" % prd_single[0]
single_res_li = await sor.sqlExe(single_sql, {})
single_res = single_res_li[0] if single_res_li else {}
single_res['discount'] = prd_single[1]
res_list.append(single_res)
# 查找*的所有产品id 通过prd_single筛选
nss = {
'productid': '*',
'protocolid': ns.get('protocolid'),
'del_flg': '0'
}
res_star = await sor.R('product_salemode', nss)
if res_star:
# 针对产品设置的统一折扣
start_discount = res_star[0].get('discount')
provider_star = res_star[0].get('providerid')
res_product_sql = """select * from product where providerid = '%s' and del_flg = '0' and CURRENT_DATE
between effect_date and expire_date;""" % provider_star
res_product_li = await sor.sqlExe(res_product_sql, {})
for res_product in res_product_li:
res_product_id = res_product.get('id')
if res_product_id not in prd_singles:
res_product['discount'] = start_discount
res_list.append(res_product)
return {
"status": True,
"msg": "product_salemode search success",
"data": res_list
}
except Exception as e:
return {
"status": False,
"msg": "product_salemode search failed",
'data': e
}
return {
"status": False,
"msg": "product_salemode search failed",
"data": 111,
}
ret = await product_salemode_search(params_kw)
return ret