Compare commits
2 Commits
f14eb4f704
...
7e3af2d9b8
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e3af2d9b8 | |||
| 34843b6634 |
@ -1,7 +1,7 @@
|
||||
# Upsert折扣明细:对比old_discount和discount,不同才更新
|
||||
# 参数: discountid, productid, discount, old_discount, detail_id(可选)
|
||||
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error', 'timeout': 3}}
|
||||
|
||||
try:
|
||||
discountid = params_kw.get('discountid')
|
||||
@ -13,11 +13,22 @@ try:
|
||||
if not discountid or not productid:
|
||||
raise Exception('缺少必要参数: discountid, productid')
|
||||
|
||||
# 过滤 NaN 和空值
|
||||
if discount_val is not None:
|
||||
s = str(discount_val).strip().lower()
|
||||
if s in ('', 'nan', 'none', 'null'):
|
||||
discount_val = None
|
||||
|
||||
if old_discount is not None:
|
||||
s = str(old_discount).strip().lower()
|
||||
if s in ('', 'nan', 'none', 'null'):
|
||||
old_discount = None
|
||||
|
||||
# 对比新旧值,相同则跳过
|
||||
if discount_val is not None and old_discount is not None:
|
||||
try:
|
||||
if float(discount_val) == float(old_discount):
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣未变化', 'type': 'success'}}
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣未变化', 'type': 'success', 'timeout': 3}}
|
||||
return result
|
||||
except:
|
||||
pass
|
||||
@ -30,9 +41,9 @@ try:
|
||||
if detail_id:
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
await sor.D('discount_detail', {'id': detail_id})
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣已清除', 'type': 'success'}}
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣已清除', 'type': 'success', 'timeout': 3}}
|
||||
else:
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'ok', 'type': 'success'}}
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'ok', 'type': 'success', 'timeout': 3}}
|
||||
return result
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
@ -51,10 +62,10 @@ try:
|
||||
'discount': float(discount_val)
|
||||
})
|
||||
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣保存成功', 'type': 'success'}}
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣保存成功', 'type': 'success', 'timeout': 3}}
|
||||
|
||||
except Exception as e:
|
||||
debug(f'save_discount error: {format_exc()}')
|
||||
result['options'] = {'title': 'Error', 'message': f'保存失败: {str(e)}', 'type': 'error'}
|
||||
result['options'] = {'title': 'Error', 'message': f'保存失败: {str(e)}', 'type': 'error', 'timeout': 5}
|
||||
|
||||
return result
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user