32 lines
1.3 KiB
Plaintext
32 lines
1.3 KiB
Plaintext
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 json.dumps(result, ensure_ascii=False)
|