fix: 删除折扣产品明细菜单; create校验customerid并从默认方案复制detail
This commit is contained in:
parent
02f00c6739
commit
d08f6fb289
@ -1,19 +1,50 @@
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error', 'timeout': 3}}
|
||||
|
||||
try:
|
||||
user_orgid = (await get_userorgid()) or '0'
|
||||
dbname = get_module_dbname('discount')
|
||||
customerid = params_kw.get('customerid')
|
||||
|
||||
if not customerid:
|
||||
result = {'widgettype': 'Error', 'options': {'title': '参数错误', 'message': '请选择客户后再创建折扣方案', 'timeout': 5}}
|
||||
return result
|
||||
|
||||
dbname = get_module_dbname('discount')
|
||||
data = dict(params_kw)
|
||||
data['id'] = uuid()
|
||||
discountid = getID()
|
||||
data['id'] = discountid
|
||||
data['resellerid'] = user_orgid
|
||||
data['customerid'] = customerid
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
await sor.C('discount', data)
|
||||
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣方案创建成功', 'type': 'success'}}
|
||||
# Copy default discount details (customerid=NULL) to this customer's plan
|
||||
default_sql = """
|
||||
SELECT id FROM discount
|
||||
WHERE resellerid = ${resellerid}$ AND customerid IS NULL
|
||||
ORDER BY enabled_date DESC LIMIT 1
|
||||
"""
|
||||
default_recs = await sor.sqlExe(default_sql, {'resellerid': user_orgid})
|
||||
|
||||
if default_recs:
|
||||
default_discountid = default_recs[0].id
|
||||
detail_sql = "SELECT * FROM discount_detail WHERE discountid = ${did}$"
|
||||
details = await sor.sqlExe(detail_sql, {'did': default_discountid})
|
||||
|
||||
for d in details or []:
|
||||
await sor.C('discount_detail', {
|
||||
'id': getID(),
|
||||
'discountid': discountid,
|
||||
'resellerid': user_orgid,
|
||||
'prodtypeid': d.prodtypeid,
|
||||
'productid': d.productid,
|
||||
'discount': d.discount,
|
||||
})
|
||||
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣方案创建成功,已复制默认产品折扣', 'type': 'success', 'timeout': 3}}
|
||||
|
||||
except Exception as e:
|
||||
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
||||
debug(f'discount_create error: {format_exc()}')
|
||||
result['options'] = {'title': 'Error', 'message': f'创建失败: {str(e)}', 'type': 'error', 'timeout': 5}
|
||||
|
||||
return json.dumps(result, ensure_ascii=False)
|
||||
return result
|
||||
|
||||
@ -10,11 +10,6 @@
|
||||
"label": "折扣管理",
|
||||
"url": "{{entire_url('discount_list/index.ui')}}"
|
||||
},
|
||||
{
|
||||
"name":"discount_detail_list",
|
||||
"label": "折扣产品明细",
|
||||
"url": "{{entire_url('discount_detail_list/index.ui')}}"
|
||||
},
|
||||
{
|
||||
"name":"discount_marketing_list",
|
||||
"label": "营销方案",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user