diff --git a/json/sub_distributors.json b/json/sub_distributors.json new file mode 100644 index 0000000..068eb24 --- /dev/null +++ b/json/sub_distributors.json @@ -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"] + } + } +} diff --git a/wwwroot/api/add_sub_reseller.dspy b/wwwroot/api/add_sub_reseller.dspy new file mode 100644 index 0000000..0fdb802 --- /dev/null +++ b/wwwroot/api/add_sub_reseller.dspy @@ -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 diff --git a/wwwroot/sub_distributors_list/add_sub_distributors.dspy b/wwwroot/sub_distributors_list/add_sub_distributors.dspy index 1727a15..0fdb802 100644 --- a/wwwroot/sub_distributors_list/add_sub_distributors.dspy +++ b/wwwroot/sub_distributors_list/add_sub_distributors.dspy @@ -1,65 +1,7 @@ - ns = params_kw.copy() for k,v in ns.items(): - if v == 'NaN' or v == 'null': - ns[k] = None -id = params_kw.id -if not id or len(id) > 32: - id = uuid() -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" - } -} + if v == 'NaN' or v == 'null': + ns[k] = None +env = request._run_ns +r = await env.create_sub_reseller(request, ns) +return r