
-- 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);

