fix: add_sub_distributors calls create_sub_reseller for org+account creation
This commit is contained in:
parent
160bc36fb1
commit
da5fd85984
12
json/sub_distributors.json
Normal file
12
json/sub_distributors.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"tblname": "sub_distributors",
|
||||||
|
"alias": "sub_distributors_list",
|
||||||
|
"title": "二级分销商管理",
|
||||||
|
"params": {
|
||||||
|
"sortby": ["created_at desc"],
|
||||||
|
"on_add": "create_sub_reseller",
|
||||||
|
"browserfields": {
|
||||||
|
"exclouded": ["id", "resellerid", "orgid", "created_by", "created_at", "updated_at"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
wwwroot/api/add_sub_reseller.dspy
Normal file
7
wwwroot/api/add_sub_reseller.dspy
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
ns = params_kw.copy()
|
||||||
|
for k,v in ns.items():
|
||||||
|
if v == 'NaN' or v == 'null':
|
||||||
|
ns[k] = None
|
||||||
|
env = request._run_ns
|
||||||
|
r = await env.create_sub_reseller(request, ns)
|
||||||
|
return r
|
||||||
@ -1,65 +1,7 @@
|
|||||||
|
|
||||||
ns = params_kw.copy()
|
ns = params_kw.copy()
|
||||||
for k,v in ns.items():
|
for k,v in ns.items():
|
||||||
if v == 'NaN' or v == 'null':
|
if v == 'NaN' or v == 'null':
|
||||||
ns[k] = None
|
ns[k] = None
|
||||||
id = params_kw.id
|
env = request._run_ns
|
||||||
if not id or len(id) > 32:
|
r = await env.create_sub_reseller(request, ns)
|
||||||
id = uuid()
|
return r
|
||||||
ns['id'] = id
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
userorgid = await get_userorgid()
|
|
||||||
if not userorgid:
|
|
||||||
return {
|
|
||||||
"widgettype":"Error",
|
|
||||||
"options":{
|
|
||||||
"title":"Authorization Error",
|
|
||||||
"timeout":3,
|
|
||||||
"cwidth":16,
|
|
||||||
"cheight":9,
|
|
||||||
"message":"Please login"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ns['resellerid'] = userorgid
|
|
||||||
|
|
||||||
# Auto-generate sub_dist_code if not provided
|
|
||||||
if not ns.get('sub_dist_code'):
|
|
||||||
from datetime import datetime as _dt
|
|
||||||
_prefix = f"SD-{_dt.now().strftime('%Y%m%d')}"
|
|
||||||
async with DBPools().sqlorContext(get_module_dbname('supplychain')) as _sor:
|
|
||||||
_recs = await _sor.sqlExe(
|
|
||||||
"SELECT COUNT(*) as cnt FROM sub_distributors WHERE resellerid = ${rid}$ AND sub_dist_code LIKE ${p}$",
|
|
||||||
{"rid": userorgid, "p": _prefix + "%"}
|
|
||||||
)
|
|
||||||
_seq = (_recs[0].cnt if _recs else 0) + 1
|
|
||||||
ns['sub_dist_code'] = f"{_prefix}-{_seq:04d}"
|
|
||||||
ns['created_by'] = userorgid
|
|
||||||
ns['created_at'] = timestampstr()
|
|
||||||
|
|
||||||
db = DBPools()
|
|
||||||
dbname = get_module_dbname('supplychain')
|
|
||||||
async with db.sqlorContext(dbname) as sor:
|
|
||||||
r = await sor.C('sub_distributors', ns.copy())
|
|
||||||
return {
|
|
||||||
"widgettype":"Message",
|
|
||||||
"options":{
|
|
||||||
"cwidth":16,
|
|
||||||
"cheight":9,
|
|
||||||
"title":"Add Success",
|
|
||||||
"timeout":3,
|
|
||||||
"message":"ok"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"widgettype":"Error",
|
|
||||||
"options":{
|
|
||||||
"title":"Add Error",
|
|
||||||
"cwidth":16,
|
|
||||||
"cheight":9,
|
|
||||||
"timeout":3,
|
|
||||||
"message":"failed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user