feat: init_free_customers.dspy + button in free_customer_assign
This commit is contained in:
parent
1e99ad2cc8
commit
9d3c4e0adf
42
wwwroot/api/init_free_customers.dspy
Normal file
42
wwwroot/api/init_free_customers.dspy
Normal file
@ -0,0 +1,42 @@
|
||||
"""Initialize discount_customer_bind for all users in current org.
|
||||
Users without a bind record get bind_type='3' (domain registration), sale_id=NULL."""
|
||||
userorgid = await get_userorgid()
|
||||
if not userorgid or userorgid == '0':
|
||||
return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': '仅机构用户可执行', 'timeout': 3}}
|
||||
|
||||
count = 0
|
||||
async with DBPools().sqlorContext('sage') as sor:
|
||||
# Get all users in this org
|
||||
users = await sor.sqlExe(
|
||||
'SELECT id, orgid FROM users WHERE orgid = ${oid}$',
|
||||
{'oid': userorgid}
|
||||
)
|
||||
if not users:
|
||||
return {'widgettype': 'Message', 'options': {'title': '提示', 'message': '该机构下无用户', 'type': 'warning', 'timeout': 3}}
|
||||
|
||||
async with DBPools().sqlorContext('discount') as disc_sor:
|
||||
for u in users:
|
||||
existing = await disc_sor.sqlExe(
|
||||
'SELECT id FROM discount_customer_bind WHERE customerid = ${cid}$',
|
||||
{'cid': u.id}
|
||||
)
|
||||
if not existing:
|
||||
await disc_sor.C('discount_customer_bind', {
|
||||
'id': getID(),
|
||||
'customerid': u.id,
|
||||
'resellerid': userorgid,
|
||||
'sale_id': None,
|
||||
'promo_code_id': None,
|
||||
'bind_type': '3',
|
||||
})
|
||||
count += 1
|
||||
|
||||
return {
|
||||
'widgettype': 'Message',
|
||||
'options': {
|
||||
'title': '初始化完成',
|
||||
'message': f'共 {len(users)} 个用户,新增 {count} 条自由客户记录',
|
||||
'type': 'success',
|
||||
'timeout': 0
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,22 @@
|
||||
"fontSize": "16px", "fontWeight": "600", "color": "#F1F5F9", "padding": "8px 12px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {"padding": "4px 12px", "alignItems": "center"},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {"label": "初始化自由客户", "css": "primary", "fontSize": "12px", "padding": "4px 12px", "borderRadius": "4px"},
|
||||
"binds": [{
|
||||
"wid": "self", "event": "click",
|
||||
"actiontype": "urlwidget", "target": "app.sage_main_content",
|
||||
"mode": "replace",
|
||||
"options": {"url": "{{entire_url('/discount/api/init_free_customers.dspy')}}", "method": "POST"}
|
||||
}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {"bgcolor": "#0F172A", "padding": "8px 0", "borderRadius": "6px 6px 0 0", "alignItems": "center", "width": "100%"},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user