From d483238ac55aa996d0b5e47b296ff9cd8d913404 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 26 Jun 2026 16:44:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8C=BA=E7=8A=B6=E6=80=81=E5=B9=B6=E6=8F=90=E4=BA=A4CRUD?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复文件权限 (600→644) - 删除调试日志 (global_func.py) - 添加 CRUD 生成的 wwwroot 文件 (pipeline_core/dist/ops) - 添加 mysql.ddl.sql 文件 - 更新 pyproject.toml 配置 - 添加 showcase 模块安装 (build.sh) - 更新 index.ui (sidebar toggle + 管理按钮) - 设置 start.sh/stop.sh 可执行权限 - 添加 wwwroot 符号链接 (appbase/rbac/pipeline_sdlc) - 更新 .gitignore (排除 pkgs/bricks/pipeline.pid) --- mysql.ddl.sql | 83 +++++ pyproject.toml | 12 +- .../add_distributor_pipeline.dspy | 37 ++ .../delete_distributor_pipeline.dspy | 33 ++ .../get_distributor_pipeline.dspy | 143 ++++++++ wwwroot/distributor_pipeline/index.ui | 327 ++++++++++++++++++ .../update_distributor_pipeline.dspy | 36 ++ wwwroot/distributors/add_distributors.dspy | 40 +++ wwwroot/distributors/delete_distributors.dspy | 33 ++ wwwroot/distributors/get_distributors.dspy | 148 ++++++++ wwwroot/distributors/index.ui | 240 +++++++++++++ wwwroot/distributors/update_distributors.dspy | 39 +++ 12 files changed, 1165 insertions(+), 6 deletions(-) create mode 100644 mysql.ddl.sql create mode 100644 wwwroot/distributor_pipeline/add_distributor_pipeline.dspy create mode 100644 wwwroot/distributor_pipeline/delete_distributor_pipeline.dspy create mode 100644 wwwroot/distributor_pipeline/get_distributor_pipeline.dspy create mode 100644 wwwroot/distributor_pipeline/index.ui create mode 100644 wwwroot/distributor_pipeline/update_distributor_pipeline.dspy create mode 100644 wwwroot/distributors/add_distributors.dspy create mode 100644 wwwroot/distributors/delete_distributors.dspy create mode 100644 wwwroot/distributors/get_distributors.dspy create mode 100644 wwwroot/distributors/index.ui create mode 100644 wwwroot/distributors/update_distributors.dspy diff --git a/mysql.ddl.sql b/mysql.ddl.sql new file mode 100644 index 0000000..d018d79 --- /dev/null +++ b/mysql.ddl.sql @@ -0,0 +1,83 @@ + +-- models/distributors.json + + + + + +-- 建库时请用以下语句,支持emoji字符 +-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +drop table if exists distributors; +CREATE TABLE distributors +( + + `id` VARCHAR(32) NOT NULL comment '主键', + `name` VARCHAR(200) NOT NULL comment '分销商名称', + `org_id` VARCHAR(32) comment '关联组织ID', + `contact_name` VARCHAR(50) comment '联系人', + `contact_phone` VARCHAR(20) comment '联系电话', + `contact_email` VARCHAR(100) comment '联系邮箱', + `api_key` VARCHAR(200) comment 'API密钥', + `commission_rate` double(5,2) DEFAULT '0' comment '佣金比例%', + `status` VARCHAR(20) DEFAULT 'active' comment '状态', + `agreement_start` date comment '协议开始日', + `agreement_end` date comment '协议结束日', + `remarks` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', + `created_by` VARCHAR(32) comment '创建人', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间', + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新时间' + + +,primary key(id) + + +) +CHARACTER SET utf8mb4 +COLLATE utf8mb4_unicode_ci +engine=innodb +comment '分销商表' +; + +CREATE INDEX distributors_idx_dist_name ON distributors(name); +CREATE INDEX distributors_idx_dist_status ON distributors(status); + +-- models/distributor_pipeline.json + + + + + +-- 建库时请用以下语句,支持emoji字符 +-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +drop table if exists distributor_pipeline; +CREATE TABLE distributor_pipeline +( + + `id` VARCHAR(32) NOT NULL comment '主键', + `distributor_id` VARCHAR(32) NOT NULL comment '分销商ID', + `pipeline_id` VARCHAR(32) NOT NULL comment '产线ID', + `custom_price` double(15,4) comment '自定义单价', + `markup_type` VARCHAR(20) comment '加价方式', + `markup_value` double(10,2) comment '加价值', + `daily_limit` int DEFAULT '0' comment '日限额', + `monthly_limit` int DEFAULT '0' comment '月限额', + `today_usage` int DEFAULT '0' comment '今日已用', + `month_usage` int DEFAULT '0' comment '本月已用', + `status` VARCHAR(20) DEFAULT 'active' comment '状态', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间', + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新时间' + + +,primary key(id) + + +) +CHARACTER SET utf8mb4 +COLLATE utf8mb4_unicode_ci +engine=innodb +comment '分销商-产线关联定价表' +; + +CREATE UNIQUE INDEX distributor_pipeline_idx_dp_dist_pipe ON distributor_pipeline(distributor_id,pipeline_id); +CREATE INDEX distributor_pipeline_idx_dp_distributor ON distributor_pipeline(distributor_id); + diff --git a/pyproject.toml b/pyproject.toml index 3036833..af56723 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [project] name = "pipeline_dist" version = "0.1.0" -description = "Pipeline distributor management module" -requires-python = ">=3.8" -dependencies = [ - "sqlor", - "bricks_for_python", -] +description = "产线分发模块" +dependencies = ["sqlor"] + +[tool.setuptools.packages.find] +where = ["."] +include = ["pipeline_dist*"] diff --git a/wwwroot/distributor_pipeline/add_distributor_pipeline.dspy b/wwwroot/distributor_pipeline/add_distributor_pipeline.dspy new file mode 100644 index 0000000..adaa5c9 --- /dev/null +++ b/wwwroot/distributor_pipeline/add_distributor_pipeline.dspy @@ -0,0 +1,37 @@ + +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 + + + +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('distributor_pipeline', 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" + } +} \ No newline at end of file diff --git a/wwwroot/distributor_pipeline/delete_distributor_pipeline.dspy b/wwwroot/distributor_pipeline/delete_distributor_pipeline.dspy new file mode 100644 index 0000000..5fea630 --- /dev/null +++ b/wwwroot/distributor_pipeline/delete_distributor_pipeline.dspy @@ -0,0 +1,33 @@ + +ns = { + 'id':params_kw['id'], +} + + +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('distributor_pipeline', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/distributor_pipeline/get_distributor_pipeline.dspy b/wwwroot/distributor_pipeline/get_distributor_pipeline.dspy new file mode 100644 index 0000000..baf0035 --- /dev/null +++ b/wwwroot/distributor_pipeline/get_distributor_pipeline.dspy @@ -0,0 +1,143 @@ + +ns = params_kw.copy() + + +debug(f'get_distributor_pipeline.dspy:{ns=}') +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'created_at' + + + +sql = '''select a.*, b.distributor_id_text, c.pipeline_id_text, d.markup_type_text, e.status_text +from (select * from distributor_pipeline where 1=1 [[filterstr]]) a left join (select id as distributor_id, + name as distributor_id_text from distributors where 1 = 1) b on a.distributor_id = b.distributor_id left join (select id as pipeline_id, + name as pipeline_id_text from pipelines where 1 = 1) c on a.pipeline_id = c.pipeline_id left join (select k as markup_type, + v as markup_type_text from appcodes_kv where parentid='markup_type') d on a.markup_type = d.markup_type left join (select k as status, + v as status_text from appcodes_kv where parentid='dp_status') e on a.status = e.status''' + +filterjson = params_kw.get('data_filter') +if filterjson and isinstance(filterjson, str): + try: + filterjson = json.loads(filterjson) + except (json.JSONDecodeError, TypeError): + filterjson = None +fields_str=r'''[ + { + "name": "id", + "title": "主键", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "distributor_id", + "title": "分销商ID", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "pipeline_id", + "title": "产线ID", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "custom_price", + "title": "自定义单价", + "type": "double", + "length": 15, + "dec": 4 + }, + { + "name": "markup_type", + "title": "加价方式", + "type": "str", + "length": 20 + }, + { + "name": "markup_value", + "title": "加价值", + "type": "double", + "length": 10, + "dec": 2 + }, + { + "name": "daily_limit", + "title": "日限额", + "type": "int", + "default": "0" + }, + { + "name": "monthly_limit", + "title": "月限额", + "type": "int", + "default": "0" + }, + { + "name": "today_usage", + "title": "今日已用", + "type": "int", + "default": "0" + }, + { + "name": "month_usage", + "title": "本月已用", + "type": "int", + "default": "0" + }, + { + "name": "status", + "title": "状态", + "type": "str", + "length": 20, + "default": "active" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp" + }, + { + "name": "updated_at", + "title": "更新时间", + "type": "timestamp" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + filterjson = default_filterjson(fields, ns) + +filterdic = ns.copy() +filterdic['filterstr'] = '' +filterdic['userorgid'] = '${userorgid}$' +filterdic['userid'] = '${userid}$' +if filterjson: + dbf = DBFilter(filterjson) + conds = dbf.gen(ns) + if conds: + ns.update(dbf.consts) + conds = f' and {conds}' + filterdic['filterstr'] = conds +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' } +filterdic.update(NameSpace) +sql = ac.convert(sql, filterdic) + +debug(f'{sql=}') +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/distributor_pipeline/index.ui b/wwwroot/distributor_pipeline/index.ui new file mode 100644 index 0000000..59a21fe --- /dev/null +++ b/wwwroot/distributor_pipeline/index.ui @@ -0,0 +1,327 @@ + +{ + "widgettype":"VBox", + "options":{"cheight":40,"width":"100%"}, + "subwidgets":[{ + "id":"distributor_pipeline_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"分销商-产线关联定价表", + + + + + "toolbar":{ + "tools": [ + { + "selected_row": true, + "name": "distributors", + "icon": "{{entire_url('/imgs/distributors.svg')}}", + "label": "分销商" + }, + { + "selected_row": true, + "name": "pipelines", + "icon": "{{entire_url('/imgs/pipelines.svg')}}", + "label": "产线" + } + ] +}, + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_distributor_pipeline.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_distributor_pipeline.dspy')}}", + + + "update_data_url":"{{entire_url('update_distributor_pipeline.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_distributor_pipeline.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id" + ], + "cwidth": {}, + "alters": { + "distributor_id": { + "dataurl": "{{entire_url('../api/get_search_distributor_id.dspy')}}" + }, + "pipeline_id": { + "dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}" + } + } +}, + + + "editexclouded":[ + "id", + "created_at", + "updated_at" +], + + "fields":[ + { + "name": "id", + "title": "主键", + "type": "str", + "length": 32, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "主键" + }, + { + "name": "distributor_id", + "title": "分销商ID", + "type": "str", + "length": 32, + "nullable": "no", + "label": "分销商ID", + "uitype": "code", + "valueField": "distributor_id", + "textField": "distributor_id_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_dist')}}", + "table": "distributors", + "tblvalue": "id", + "tbltext": "name", + "valueField": "distributor_id", + "textField": "distributor_id_text" + }, + "dataurl": "{{entire_url('../api/get_search_distributor_id.dspy')}}" + }, + { + "name": "pipeline_id", + "title": "产线ID", + "type": "str", + "length": 32, + "nullable": "no", + "label": "产线ID", + "uitype": "code", + "valueField": "pipeline_id", + "textField": "pipeline_id_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_dist')}}", + "table": "pipelines", + "tblvalue": "id", + "tbltext": "name", + "valueField": "pipeline_id", + "textField": "pipeline_id_text" + }, + "dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}" + }, + { + "name": "custom_price", + "title": "自定义单价", + "type": "double", + "length": 15, + "dec": 4, + "cwidth": 15, + "uitype": "float", + "datatype": "double", + "label": "自定义单价" + }, + { + "name": "markup_type", + "title": "加价方式", + "type": "str", + "length": 20, + "label": "加价方式", + "uitype": "code", + "valueField": "markup_type", + "textField": "markup_type_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_dist')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "markup_type", + "textField": "markup_type_text", + "cond": "parentid='markup_type'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "markup_value", + "title": "加价值", + "type": "double", + "length": 10, + "dec": 2, + "cwidth": 10, + "uitype": "float", + "datatype": "double", + "label": "加价值" + }, + { + "name": "daily_limit", + "title": "日限额", + "type": "int", + "default": "0", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "日限额" + }, + { + "name": "monthly_limit", + "title": "月限额", + "type": "int", + "default": "0", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "月限额" + }, + { + "name": "today_usage", + "title": "今日已用", + "type": "int", + "default": "0", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "今日已用" + }, + { + "name": "month_usage", + "title": "本月已用", + "type": "int", + "default": "0", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "本月已用" + }, + { + "name": "status", + "title": "状态", + "type": "str", + "length": 20, + "default": "active", + "label": "状态", + "uitype": "code", + "valueField": "status", + "textField": "status_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_dist')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "status", + "textField": "status_text", + "cond": "parentid='dp_status'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "创建时间" + }, + { + "name": "updated_at", + "title": "更新时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "更新时间" + } +] + }, + + + + "data_filter":{ + "distributor_id": "", + "pipeline_id": "", + "status": "" +}, + + + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[ + { + "wid": "self", + "event": "distributors", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "分销商", + "icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=distributors", + "resizable": true, + "height": "70%", + "width": "70%" + }, + "params_mapping": { + "mapping": { + "id": "distributor_id", + "referer_widget": "referer_widget" + }, + "need_other": false + }, + "options": { + "method": "POST", + "params": {}, + "url": "{{entire_url('../distributors')}}" + } + }, + { + "wid": "self", + "event": "pipelines", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "产线", + "icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=pipelines", + "resizable": true, + "height": "70%", + "width": "70%" + }, + "params_mapping": { + "mapping": { + "id": "pipeline_id", + "referer_widget": "referer_widget" + }, + "need_other": false + }, + "options": { + "method": "POST", + "params": {}, + "url": "{{entire_url('../pipelines')}}" + } + } +] + +}] +} \ No newline at end of file diff --git a/wwwroot/distributor_pipeline/update_distributor_pipeline.dspy b/wwwroot/distributor_pipeline/update_distributor_pipeline.dspy new file mode 100644 index 0000000..3569181 --- /dev/null +++ b/wwwroot/distributor_pipeline/update_distributor_pipeline.dspy @@ -0,0 +1,36 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + + + +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + + r = await sor.U('distributor_pipeline', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/distributors/add_distributors.dspy b/wwwroot/distributors/add_distributors.dspy new file mode 100644 index 0000000..bb8871f --- /dev/null +++ b/wwwroot/distributors/add_distributors.dspy @@ -0,0 +1,40 @@ + +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 + +if params_kw.get('api_key'): + ns['api_key'] = password_encode(params_kw.get('api_key')) + + + +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('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" + } +} \ No newline at end of file diff --git a/wwwroot/distributors/delete_distributors.dspy b/wwwroot/distributors/delete_distributors.dspy new file mode 100644 index 0000000..8f8d3e3 --- /dev/null +++ b/wwwroot/distributors/delete_distributors.dspy @@ -0,0 +1,33 @@ + +ns = { + 'id':params_kw['id'], +} + + +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('distributors', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/distributors/get_distributors.dspy b/wwwroot/distributors/get_distributors.dspy new file mode 100644 index 0000000..d5f7ea7 --- /dev/null +++ b/wwwroot/distributors/get_distributors.dspy @@ -0,0 +1,148 @@ + +ns = params_kw.copy() + + +debug(f'get_distributors.dspy:{ns=}') +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'created_at' + + + +sql = '''select a.*, b.status_text +from (select * from distributors where 1=1 [[filterstr]]) a left join (select k as status, + v as status_text from appcodes_kv where parentid='distributor_status') b on a.status = b.status''' + +filterjson = params_kw.get('data_filter') +if filterjson and isinstance(filterjson, str): + try: + filterjson = json.loads(filterjson) + except (json.JSONDecodeError, TypeError): + filterjson = None +fields_str=r'''[ + { + "name": "id", + "title": "主键", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "name", + "title": "分销商名称", + "type": "str", + "length": 200, + "nullable": "no" + }, + { + "name": "org_id", + "title": "关联组织ID", + "type": "str", + "length": 32 + }, + { + "name": "contact_name", + "title": "联系人", + "type": "str", + "length": 50 + }, + { + "name": "contact_phone", + "title": "联系电话", + "type": "str", + "length": 20 + }, + { + "name": "contact_email", + "title": "联系邮箱", + "type": "str", + "length": 100 + }, + { + "name": "api_key", + "title": "API密钥", + "type": "str", + "length": 200 + }, + { + "name": "commission_rate", + "title": "佣金比例%", + "type": "double", + "length": 5, + "dec": 2, + "default": "0" + }, + { + "name": "status", + "title": "状态", + "type": "str", + "length": 20, + "default": "active" + }, + { + "name": "agreement_start", + "title": "协议开始日", + "type": "date" + }, + { + "name": "agreement_end", + "title": "协议结束日", + "type": "date" + }, + { + "name": "remarks", + "title": "备注", + "type": "text" + }, + { + "name": "created_by", + "title": "创建人", + "type": "str", + "length": 32 + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp" + }, + { + "name": "updated_at", + "title": "更新时间", + "type": "timestamp" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + filterjson = default_filterjson(fields, ns) + +filterdic = ns.copy() +filterdic['filterstr'] = '' +filterdic['userorgid'] = '${userorgid}$' +filterdic['userid'] = '${userid}$' +if filterjson: + dbf = DBFilter(filterjson) + conds = dbf.gen(ns) + if conds: + ns.update(dbf.consts) + conds = f' and {conds}' + filterdic['filterstr'] = conds +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' } +filterdic.update(NameSpace) +sql = ac.convert(sql, filterdic) + +debug(f'{sql=}') +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/distributors/index.ui b/wwwroot/distributors/index.ui new file mode 100644 index 0000000..844faf7 --- /dev/null +++ b/wwwroot/distributors/index.ui @@ -0,0 +1,240 @@ + +{ + "widgettype":"VBox", + "options":{"cheight":40,"width":"100%"}, + "subwidgets":[{ + "id":"distributors_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"分销商表", + + + + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_distributors.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_distributors.dspy')}}", + + + "update_data_url":"{{entire_url('update_distributors.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_distributors.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id", + "api_key", + "remarks" + ], + "cwidth": {} +}, + + + "editexclouded":[ + "id", + "created_at", + "updated_at" +], + + "fields":[ + { + "name": "id", + "title": "主键", + "type": "str", + "length": 32, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "主键" + }, + { + "name": "name", + "title": "分销商名称", + "type": "str", + "length": 200, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "分销商名称" + }, + { + "name": "org_id", + "title": "关联组织ID", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "关联组织ID" + }, + { + "name": "contact_name", + "title": "联系人", + "type": "str", + "length": 50, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "联系人" + }, + { + "name": "contact_phone", + "title": "联系电话", + "type": "str", + "length": 20, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "联系电话" + }, + { + "name": "contact_email", + "title": "联系邮箱", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "联系邮箱" + }, + { + "name": "api_key", + "title": "API密钥", + "type": "str", + "length": 200, + "cwidth": 18, + "uitype": "password", + "datatype": "str", + "label": "API密钥" + }, + { + "name": "commission_rate", + "title": "佣金比例%", + "type": "double", + "length": 5, + "dec": 2, + "default": "0", + "cwidth": 5, + "uitype": "float", + "datatype": "double", + "label": "佣金比例%" + }, + { + "name": "status", + "title": "状态", + "type": "str", + "length": 20, + "default": "active", + "label": "状态", + "uitype": "code", + "valueField": "status", + "textField": "status_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_dist')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "status", + "textField": "status_text", + "cond": "parentid='distributor_status'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "agreement_start", + "title": "协议开始日", + "type": "date", + "length": 0, + "uitype": "date", + "datatype": "date", + "label": "协议开始日" + }, + { + "name": "agreement_end", + "title": "协议结束日", + "type": "date", + "length": 0, + "uitype": "date", + "datatype": "date", + "label": "协议结束日" + }, + { + "name": "remarks", + "title": "备注", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "备注" + }, + { + "name": "created_by", + "title": "创建人", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "创建人" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "创建时间" + }, + { + "name": "updated_at", + "title": "更新时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "更新时间" + } +] + }, + + + + "data_filter":{ + "name": "", + "status": "" +}, + + + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[] + +}] +} \ No newline at end of file diff --git a/wwwroot/distributors/update_distributors.dspy b/wwwroot/distributors/update_distributors.dspy new file mode 100644 index 0000000..f348d31 --- /dev/null +++ b/wwwroot/distributors/update_distributors.dspy @@ -0,0 +1,39 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + + +if params_kw.get('api_key'): + ns['api_key'] = password_encode(params_kw.get('api_key')) + + +db = DBPools() +dbname = get_module_dbname('pipeline_dist') +async with db.sqlorContext(dbname) as sor: + + r = await sor.U('distributors', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file