discount/wwwroot/api/discount_detail_create.dspy

32 lines
1.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
user_orgid = (await get_userorgid()) or '0'
dbname = get_module_dbname('discount')
data = dict(params_kw)
data['id'] = uuid()
data['resellerid'] = user_orgid
# discountid从多处获取(子表场景): params_kw > request.query > Referer头
if not data.get('discountid'):
data['discountid'] = request.query.get('discountid', '')
if not data.get('discountid'):
referer = request.headers.get('Referer', '')
if 'discountid=' in referer:
for part in referer.split('?')[-1].split('&'):
if part.startswith('discountid='):
data['discountid'] = part.split('=', 1)[1]
break
if not data.get('discountid'):
raise Exception('discountid不能为空请从折扣方案进入')
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('discount_detail', data)
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣明细创建成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
return result