fix: sub_reseller_code → sub_resellerid (存org_id,修复多层分销链遍历)

- sub_resellers.json 模型: sub_reseller_code(varchar 64) → sub_resellerid(varchar 32)
- 唯一索引: idx_sr_code → idx_sr_sub_resellerid
- codes 关联: sub_resellerid 关联 organization.orgname
- init.py create_sub_reseller: 写入 sub_resellers 表(非 sub_distributors),字段 sub_resellerid
- init.py get_distribution_chain: SQL SELECT sub_resellerid(非 orgid)
- JSON/UI/dspy 字段引用同步更新
- DDL 重新生成
This commit is contained in:
yumoqing 2026-07-20 15:25:38 +08:00
parent e6d5998c15
commit 1303b48685
5 changed files with 94 additions and 113 deletions

View File

@ -15,7 +15,7 @@
"sub_reseller_name": "二级分销商名称", "sub_reseller_name": "二级分销商名称",
"status": "状态" "status": "状态"
}, },
"editexclouded": ["id", "resellerid", "sub_reseller_code", "created_by", "created_at", "updated_at"], "editexclouded": ["id", "resellerid", "sub_resellerid", "created_by", "created_at", "updated_at"],
"browserfields": { "browserfields": {
"exclouded": ["id"], "exclouded": ["id"],
"alters": { "alters": {

View File

@ -1,19 +1,59 @@
-- ./supplier_resource_price.json
drop table if exists supplier_resource_price;
CREATE TABLE supplier_resource_price
(
`id` VARCHAR(32) NOT NULL comment '主键ID',
`supplier_org_id` VARCHAR(32) NOT NULL comment '供应商机构ID',
`resource_type` VARCHAR(32) NOT NULL comment '资源类型',
`resource_ref_id` VARCHAR(32) NOT NULL comment '资源引用ID',
`resource_ref_name` VARCHAR(255) comment '资源名称',
`unit_price` double(15,8) DEFAULT '0' comment '统一单价',
`price_unit` VARCHAR(32) NOT NULL comment '价格单位',
`input_price` double(15,8) comment '输入单价(LLM专用)',
`output_price` double(15,8) comment '输出单价(LLM专用)',
`currency` CHAR(8) DEFAULT 'CNY' comment '货币',
`effective_date` date NOT NULL comment '生效日期',
`expiry_date` date comment '失效日期',
`status` CHAR(1) DEFAULT '1' comment '状态',
`created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间'
,primary key(id)
)
engine=innodb
default charset=utf8
comment '供应商资源定价表'
;
CREATE INDEX supplier_resource_price_idx_srp_supplier ON supplier_resource_price(supplier_org_id);
CREATE INDEX supplier_resource_price_idx_srp_resource ON supplier_resource_price(resource_type,resource_ref_id);
CREATE INDEX supplier_resource_price_idx_srp_dates ON supplier_resource_price(effective_date,expiry_date);
CREATE INDEX supplier_resource_price_idx_srp_status ON supplier_resource_price(status);
CREATE UNIQUE INDEX supplier_resource_price_idx_srp_unique ON supplier_resource_price(supplier_org_id,resource_type,resource_ref_id,effective_date);
-- ./sub_resellers.json -- ./sub_resellers.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists sub_resellers; drop table if exists sub_resellers;
CREATE TABLE sub_resellers CREATE TABLE sub_resellers
( (
`id` VARCHAR(32) NOT NULL comment '主键ID', `id` VARCHAR(32) NOT NULL comment '主键ID',
`resellerid` VARCHAR(32) NOT NULL comment '所属分销商机构ID', `resellerid` VARCHAR(32) NOT NULL comment '所属分销商机构ID',
`sub_reseller_code` VARCHAR(64) NOT NULL comment '二级分销商编号', `sub_resellerid` VARCHAR(32) NOT NULL comment '二级分销商机构ID',
`sub_reseller_name` VARCHAR(255) NOT NULL comment '二级分销商名称', `sub_reseller_name` VARCHAR(255) NOT NULL comment '二级分销商名称',
`contact_person` VARCHAR(100) comment '联系人', `contact_person` VARCHAR(100) comment '联系人',
`contact_phone` VARCHAR(50) comment '联系电话', `contact_phone` VARCHAR(50) comment '联系电话',
@ -23,7 +63,7 @@ CREATE TABLE sub_resellers
`bank_name` VARCHAR(255) comment '开户银行', `bank_name` VARCHAR(255) comment '开户银行',
`bank_account` VARCHAR(64) comment '银行账号', `bank_account` VARCHAR(64) comment '银行账号',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -33,14 +73,13 @@ CREATE TABLE sub_resellers
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '二级分销商表' comment '二级分销商表'
; ;
CREATE INDEX sub_resellers_idx_sr_reseller ON sub_resellers(resellerid); CREATE INDEX sub_resellers_idx_sr_reseller ON sub_resellers(resellerid);
CREATE UNIQUE INDEX sub_resellers_idx_sr_code ON sub_resellers(resellerid,sub_reseller_code); CREATE UNIQUE INDEX sub_resellers_idx_sr_sub_resellerid ON sub_resellers(resellerid,sub_resellerid);
-- ./distribution_agreements.json -- ./distribution_agreements.json
@ -48,8 +87,6 @@ CREATE UNIQUE INDEX sub_resellers_idx_sr_code ON sub_resellers(resellerid,sub_re
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists distribution_agreements; drop table if exists distribution_agreements;
CREATE TABLE distribution_agreements CREATE TABLE distribution_agreements
( (
@ -64,7 +101,7 @@ CREATE TABLE distribution_agreements
`end_date` date comment '到期日期', `end_date` date comment '到期日期',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`default_discount` double(5,4) DEFAULT '1.0000' comment '默认分销折扣', `default_discount` double(5,4) DEFAULT '1.0000' comment '默认分销折扣',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -74,9 +111,8 @@ CREATE TABLE distribution_agreements
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '分销协议表' comment '分销协议表'
; ;
@ -90,8 +126,6 @@ CREATE UNIQUE INDEX distribution_agreements_idx_da_code ON distribution_agreemen
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists sales_ledger; drop table if exists sales_ledger;
CREATE TABLE sales_ledger CREATE TABLE sales_ledger
( (
@ -113,7 +147,7 @@ CREATE TABLE sales_ledger
`distribution_amount` double(15,2) comment '分销金额', `distribution_amount` double(15,2) comment '分销金额',
`profit_amount` double(15,2) comment '利润金额', `profit_amount` double(15,2) comment '利润金额',
`settlement_status` CHAR(1) NOT NULL DEFAULT '0' comment '结算状态', `settlement_status` CHAR(1) NOT NULL DEFAULT '0' comment '结算状态',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -123,9 +157,8 @@ CREATE TABLE sales_ledger
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '销售记账表' comment '销售记账表'
; ;
@ -141,8 +174,6 @@ CREATE INDEX sales_ledger_idx_sl_supplier ON sales_ledger(supplier_id);
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists supply_contract_items; drop table if exists supply_contract_items;
CREATE TABLE supply_contract_items CREATE TABLE supply_contract_items
( (
@ -154,7 +185,7 @@ CREATE TABLE supply_contract_items
`productid` VARCHAR(32) comment '产品ID', `productid` VARCHAR(32) comment '产品ID',
`discount` double(5,4) NOT NULL DEFAULT '1.0000' comment '进货折扣', `discount` double(5,4) NOT NULL DEFAULT '1.0000' comment '进货折扣',
`settlement_price` double(15,4) comment '结算单价', `settlement_price` double(15,4) comment '结算单价',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_at` datetime NOT NULL comment '创建时间' `created_at` datetime NOT NULL comment '创建时间'
@ -162,9 +193,8 @@ CREATE TABLE supply_contract_items
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '供销合同产品折扣明细表' comment '供销合同产品折扣明细表'
; ;
@ -177,8 +207,6 @@ CREATE INDEX supply_contract_items_idx_sci_product ON supply_contract_items(con
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists supplychain_accounting; drop table if exists supplychain_accounting;
CREATE TABLE supplychain_accounting CREATE TABLE supplychain_accounting
( (
@ -203,7 +231,7 @@ CREATE TABLE supplychain_accounting
`sale_date` date NOT NULL comment '销售日期', `sale_date` date NOT NULL comment '销售日期',
`source_type` CHAR(1) DEFAULT '1' comment '来源类型', `source_type` CHAR(1) DEFAULT '1' comment '来源类型',
`source_id` VARCHAR(32) comment '来源记录ID', `source_id` VARCHAR(32) comment '来源记录ID',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间' `created_at` datetime NOT NULL comment '创建时间'
@ -212,9 +240,8 @@ CREATE TABLE supplychain_accounting
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '供销记账表' comment '供销记账表'
; ;
@ -231,8 +258,6 @@ CREATE INDEX supplychain_accounting_idx_sa_source ON supplychain_accounting(sou
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists platform_supply_products; drop table if exists platform_supply_products;
CREATE TABLE platform_supply_products CREATE TABLE platform_supply_products
( (
@ -248,7 +273,7 @@ CREATE TABLE platform_supply_products
`commission_rate` double(5,4) DEFAULT '0.0000' comment '佣金率', `commission_rate` double(5,4) DEFAULT '0.0000' comment '佣金率',
`min_order_qty` int comment '最小订货量', `min_order_qty` int comment '最小订货量',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -257,9 +282,8 @@ CREATE TABLE platform_supply_products
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '平台供销产品明细表' comment '平台供销产品明细表'
; ;
@ -274,15 +298,12 @@ CREATE UNIQUE INDEX platform_supply_products_idx_psp_unique ON platform_supply_p
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists sub_distributors; drop table if exists sub_distributors;
CREATE TABLE sub_distributors CREATE TABLE sub_distributors
( (
`id` VARCHAR(32) NOT NULL comment '主键ID', `id` VARCHAR(32) NOT NULL comment '主键ID',
`resellerid` VARCHAR(32) NOT NULL comment '所属主分销商机构ID', `resellerid` VARCHAR(32) NOT NULL comment '所属主分销商机构ID',
`sub_dist_code` VARCHAR(64) NOT NULL comment '二级分销商编号',
`sub_dist_name` VARCHAR(255) NOT NULL comment '二级分销商名称', `sub_dist_name` VARCHAR(255) NOT NULL comment '二级分销商名称',
`contact_person` VARCHAR(100) comment '联系人', `contact_person` VARCHAR(100) comment '联系人',
`contact_phone` VARCHAR(50) comment '联系电话', `contact_phone` VARCHAR(50) comment '联系电话',
@ -293,24 +314,22 @@ CREATE TABLE sub_distributors
`bank_account` VARCHAR(64) comment '银行账号', `bank_account` VARCHAR(64) comment '银行账号',
`managed_by` VARCHAR(32) comment '负责销售ID', `managed_by` VARCHAR(32) comment '负责销售ID',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL DEFAULT 'CURRENT_TIMESTAMP' comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime DEFAULT 'CURRENT_TIMESTAMP' comment '更新时间'
,primary key(id) ,primary key(id)
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '二级分销商表' comment '二级分销商表'
; ;
CREATE INDEX sub_distributors_idx_sd_reseller ON sub_distributors(resellerid); CREATE INDEX sub_distributors_idx_sd_reseller ON sub_distributors(resellerid);
CREATE UNIQUE INDEX sub_distributors_idx_sd_code ON sub_distributors(resellerid,sub_dist_code);
CREATE INDEX sub_distributors_idx_sd_manager ON sub_distributors(managed_by); CREATE INDEX sub_distributors_idx_sd_manager ON sub_distributors(managed_by);
-- ./platform_supply_relations.json -- ./platform_supply_relations.json
@ -319,8 +338,6 @@ CREATE INDEX sub_distributors_idx_sd_manager ON sub_distributors(managed_by);
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists platform_supply_relations; drop table if exists platform_supply_relations;
CREATE TABLE platform_supply_relations CREATE TABLE platform_supply_relations
( (
@ -338,7 +355,7 @@ CREATE TABLE platform_supply_relations
`start_date` date NOT NULL comment '生效日期', `start_date` date NOT NULL comment '生效日期',
`end_date` date comment '到期日期', `end_date` date comment '到期日期',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -348,9 +365,8 @@ CREATE TABLE platform_supply_relations
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '平台内供销关系表' comment '平台内供销关系表'
; ;
@ -366,8 +382,6 @@ CREATE INDEX platform_supply_relations_idx_psr_status ON platform_supply_relati
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists suppliers; drop table if exists suppliers;
CREATE TABLE suppliers CREATE TABLE suppliers
( (
@ -383,8 +397,13 @@ CREATE TABLE suppliers
`tax_number` VARCHAR(64) comment '税号', `tax_number` VARCHAR(64) comment '税号',
`bank_name` VARCHAR(255) comment '开户银行', `bank_name` VARCHAR(255) comment '开户银行',
`bank_account` VARCHAR(64) comment '银行账号', `bank_account` VARCHAR(64) comment '银行账号',
`orgid` VARCHAR(32) NOT NULL comment '机构ID',
`is_external` CHAR(1) NOT NULL DEFAULT '1' comment '是否外部供应商',
`settlement_cycle` VARCHAR(20) comment '结算周期',
`settlement_day` int comment '结算日',
`payment_type` VARCHAR(20) comment '付款方式',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -394,13 +413,13 @@ CREATE TABLE suppliers
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '供应商表' comment '供应商表'
; ;
CREATE INDEX suppliers_idx_suppliers_reseller ON suppliers(resellerid); CREATE INDEX suppliers_idx_suppliers_reseller ON suppliers(resellerid);
CREATE INDEX suppliers_idx_suppliers_orgid ON suppliers(orgid);
CREATE UNIQUE INDEX suppliers_idx_suppliers_code ON suppliers(resellerid,supplier_code); CREATE UNIQUE INDEX suppliers_idx_suppliers_code ON suppliers(resellerid,supplier_code);
-- ./product_supplier_mapping.json -- ./product_supplier_mapping.json
@ -409,8 +428,6 @@ CREATE UNIQUE INDEX suppliers_idx_suppliers_code ON suppliers(resellerid,supplie
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists product_supplier_mapping; drop table if exists product_supplier_mapping;
CREATE TABLE product_supplier_mapping CREATE TABLE product_supplier_mapping
( (
@ -438,9 +455,8 @@ CREATE TABLE product_supplier_mapping
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '产品供应映射表' comment '产品供应映射表'
; ;
@ -456,8 +472,6 @@ CREATE UNIQUE INDEX product_supplier_mapping_idx_psm_unique ON product_supplier_
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists distribution_agreement_items; drop table if exists distribution_agreement_items;
CREATE TABLE distribution_agreement_items CREATE TABLE distribution_agreement_items
( (
@ -470,7 +484,7 @@ CREATE TABLE distribution_agreement_items
`discount` double(5,4) NOT NULL DEFAULT '1.0000' comment '分销折扣', `discount` double(5,4) NOT NULL DEFAULT '1.0000' comment '分销折扣',
`min_order_qty` int comment '最小订购量', `min_order_qty` int comment '最小订购量',
`sale_price` double(15,4) comment '分销指导价', `sale_price` double(15,4) comment '分销指导价',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_at` datetime NOT NULL comment '创建时间' `created_at` datetime NOT NULL comment '创建时间'
@ -478,9 +492,8 @@ CREATE TABLE distribution_agreement_items
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '分销协议产品折扣明细表' comment '分销协议产品折扣明细表'
; ;
@ -493,8 +506,6 @@ CREATE INDEX distribution_agreement_items_idx_dai_product ON distribution_agree
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists supply_contracts; drop table if exists supply_contracts;
CREATE TABLE supply_contracts CREATE TABLE supply_contracts
( (
@ -509,7 +520,7 @@ CREATE TABLE supply_contracts
`end_date` date comment '到期日期', `end_date` date comment '到期日期',
`status` CHAR(1) NOT NULL DEFAULT '1' comment '状态', `status` CHAR(1) NOT NULL DEFAULT '1' comment '状态',
`default_discount` double(5,4) DEFAULT '1.0000' comment '默认折扣', `default_discount` double(5,4) DEFAULT '1.0000' comment '默认折扣',
`remark` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '备注', `remark` longtext comment '备注',
`created_by` VARCHAR(32) comment '创建人', `created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间', `created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间' `updated_at` datetime comment '更新时间'
@ -519,9 +530,8 @@ CREATE TABLE supply_contracts
) )
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb engine=innodb
default charset=utf8
comment '供销合同表' comment '供销合同表'
; ;
@ -529,37 +539,3 @@ CREATE INDEX supply_contracts_idx_sc_reseller ON supply_contracts(resellerid);
CREATE INDEX supply_contracts_idx_sc_supplier ON supply_contracts(supplier_id); CREATE INDEX supply_contracts_idx_sc_supplier ON supply_contracts(supplier_id);
CREATE UNIQUE INDEX supply_contracts_idx_sc_code ON supply_contracts(resellerid,contract_code); CREATE UNIQUE INDEX supply_contracts_idx_sc_code ON supply_contracts(resellerid,contract_code);
-- ./supplier_resource_price.json
drop table if exists supplier_resource_price;
CREATE TABLE supplier_resource_price
(
`id` VARCHAR(32) NOT NULL comment '主键ID',
`supplier_org_id` VARCHAR(32) NOT NULL comment '供应商机构ID',
`resource_type` VARCHAR(32) NOT NULL comment '资源类型',
`resource_ref_id` VARCHAR(32) NOT NULL comment '资源引用ID',
`resource_ref_name` VARCHAR(255) comment '资源名称',
`unit_price` double(15,8) DEFAULT '0' comment '统一单价',
`price_unit` VARCHAR(32) NOT NULL comment '价格单位',
`input_price` double(15,8) comment '输入单价(LLM专用)',
`output_price` double(15,8) comment '输出单价(LLM专用)',
`currency` CHAR(8) DEFAULT 'CNY' comment '货币',
`effective_date` date NOT NULL comment '生效日期',
`expiry_date` date comment '失效日期',
`status` CHAR(1) DEFAULT '1' comment '状态',
`created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime comment '更新时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '供应商资源定价表'
;
CREATE INDEX supplier_resource_price_idx_srp_supplier ON supplier_resource_price(supplier_org_id);
CREATE INDEX supplier_resource_price_idx_srp_resource ON supplier_resource_price(resource_type,resource_ref_id);
CREATE INDEX supplier_resource_price_idx_srp_dates ON supplier_resource_price(effective_date,expiry_date);
CREATE INDEX supplier_resource_price_idx_srp_status ON supplier_resource_price(status);
CREATE UNIQUE INDEX supplier_resource_price_idx_srp_unique ON supplier_resource_price(supplier_org_id,resource_type,resource_ref_id,effective_date);

View File

@ -23,10 +23,10 @@
"nullable": "no" "nullable": "no"
}, },
{ {
"name": "sub_reseller_code", "name": "sub_resellerid",
"title": "二级分销商编号", "title": "二级分销商机构ID",
"type": "str", "type": "str",
"length": 64, "length": 32,
"nullable": "no" "nullable": "no"
}, },
{ {
@ -116,9 +116,9 @@
"idxfields": ["resellerid"] "idxfields": ["resellerid"]
}, },
{ {
"name": "idx_sr_code", "name": "idx_sr_sub_resellerid",
"idxtype": "unique", "idxtype": "unique",
"idxfields": ["resellerid", "sub_reseller_code"] "idxfields": ["resellerid", "sub_resellerid"]
} }
], ],
"codes": [ "codes": [
@ -127,6 +127,12 @@
"table": "organization", "table": "organization",
"valuefield": "id", "valuefield": "id",
"textfield": "orgname" "textfield": "orgname"
},
{
"field": "sub_resellerid",
"table": "organization",
"valuefield": "id",
"textfield": "orgname"
} }
] ]
} }

View File

@ -306,7 +306,7 @@ async def delete_supply_contract_item(request, params_kw):
# ============================================================ # ============================================================
async def create_sub_reseller(request, params_kw): async def create_sub_reseller(request, params_kw):
"""Create a new sub-reseller with orgid for discount/accounting.""" """Create a new sub-reseller with sub_resellerid (org_id) for discount/accounting."""
env = request._run_ns env = request._run_ns
user_id = await env.get_user() user_id = await env.get_user()
resellerid = await env.get_userorgid() resellerid = await env.get_userorgid()
@ -319,7 +319,7 @@ async def create_sub_reseller(request, params_kw):
new_orgid = getID() new_orgid = getID()
org_rec = { org_rec = {
"id": new_orgid, "id": new_orgid,
"orgname": data.get("sub_dist_name"), "orgname": data.get("sub_reseller_name"),
"orgtype": "sub_reseller", "orgtype": "sub_reseller",
"status": "1", "status": "1",
"created_by": user_id, "created_by": user_id,
@ -332,8 +332,8 @@ async def create_sub_reseller(request, params_kw):
rec = { rec = {
"id": getID(), "id": getID(),
"resellerid": resellerid, "resellerid": resellerid,
"orgid": new_orgid, "sub_resellerid": new_orgid,
"sub_dist_name": data.get("sub_dist_name"), "sub_reseller_name": data.get("sub_reseller_name"),
"contact_person": data.get("contact_person"), "contact_person": data.get("contact_person"),
"contact_phone": data.get("contact_phone"), "contact_phone": data.get("contact_phone"),
"contact_email": data.get("contact_email"), "contact_email": data.get("contact_email"),
@ -343,12 +343,11 @@ async def create_sub_reseller(request, params_kw):
"bank_account": data.get("bank_account"), "bank_account": data.get("bank_account"),
"status": data.get("status", "1"), "status": data.get("status", "1"),
"remark": data.get("remark"), "remark": data.get("remark"),
"managed_by": user_id,
"created_by": user_id, "created_by": user_id,
"created_at": now, "created_at": now,
"updated_at": now, "updated_at": now,
} }
await sor.C("sub_distributors", rec) await sor.C("sub_resellers", rec)
return json.dumps({"status": "ok", "data": rec, "message": "创建成功"}) return json.dumps({"status": "ok", "data": rec, "message": "创建成功"})
@ -595,13 +594,13 @@ async def get_distribution_chain(product_ownerid, seller_orgid):
current = product_ownerid current = product_ownerid
visited = {product_ownerid} visited = {product_ownerid}
while current != seller_orgid: while current != seller_orgid:
sql = """SELECT orgid FROM sub_resellers sql = """SELECT sub_resellerid FROM sub_resellers
WHERE resellerid = ${resellerid}$ AND status = '1' WHERE resellerid = ${resellerid}$ AND status = '1'
LIMIT 100""" LIMIT 100"""
recs = await sor.sqlExe(sql, {'resellerid': current}) recs = await sor.sqlExe(sql, {'resellerid': current})
found = False found = False
for r in (recs or []): for r in (recs or []):
orgid = r.get('orgid') if hasattr(r, 'get') else getattr(r, 'orgid', None) orgid = r.get('sub_resellerid') if hasattr(r, 'get') else getattr(r, 'sub_resellerid', None)
if orgid and orgid == seller_orgid: if orgid and orgid == seller_orgid:
chain.append(orgid) chain.append(orgid)
return chain return chain