-- C端 相关表结构
-- -------------------------------------
-- Table structure for customer_user 用户表
-- --------------------------------------
DROP TABLE IF EXISTS `customer_user`;
CREATE TABLE `customer_user`
(
    `id`            bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `identifier_no` varchar(32)  DEFAULT '' UNIQUE COMMENT '账号ID',
    `nickname`      varchar(50)  DEFAULT NULL UNIQUE COMMENT '昵称/会员名称',
    `password`      varchar(100) DEFAULT '' COMMENT '密码',
    `phone_number`  char(11)     DEFAULT '' COMMENT '手机号（大陆）',
    `email`         varchar(100) DEFAULT '' COMMENT '电子邮箱',
    `gmt_create`    TIMESTAMP    DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`  TIMESTAMP    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='用户表';

DROP TABLE IF EXISTS `customer_operation_log`;
CREATE TABLE `customer_operation_log`
(
    `id`               bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `customer_user_id` BIGINT UNSIGNED DEFAULT 0 COMMENT '客户id',
    `module`           varchar(64)   default '' comment '业务模块(菜单)',
    `type`             varchar(64)   default '' comment '业务类型(新增、修改)',
    `ipaddr`           varchar(128)  default '' comment '登录IP地址',
    `content`          varchar(2048) DEFAULT '' COMMENT '操作内容',
    `login_location`   varchar(255)  default '' comment '登录地点',
    `gmt_create`       TIMESTAMP     DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`     TIMESTAMP     DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    INDEX              idx_cui (`customer_user_id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='用户操作日志表';

DROP TABLE IF EXISTS `c_credit_quota_logic`;
CREATE TABLE `c_credit_quota_logic`
(
    `id`               bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `dimension`        VARCHAR(64) DEFAULT '' COMMENT '维度',
    `standard_setting` VARCHAR(64) DEFAULT '' comment '标准设定',
    `weight`           DOUBLE(2, 2
) DEFAULT 0 COMMENT '权重',
    `standard_score`   DOUBLE(5,2)     DEFAULT 0 COMMENT '标准分值',
    `estimate_score`   DOUBLE(5,2)     DEFAULT 0 COMMENT '评估分值',
    `remark`           VARCHAR(256) DEFAULT '' COMMENT '标准设定备注',
    `gmt_create`       TIMESTAMP    DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`     TIMESTAMP    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='用户授信额度逻辑表';

DROP TABLE IF EXISTS `c_credit_score_quota`;
CREATE TABLE `c_credit_score_quota`
(
    `id`            bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `currency_code` CHAR(3)     DEFAULT '' COMMENT '币种代码',
    `quota`         varchar(64) DEFAULT '' comment '额度',
    `start_score`   DOUBLE(5, 2
) DEFAULT 0 COMMENT '分数区间开始',
    `end_score`     DOUBLE(5,2)     DEFAULT 0 COMMENT '分数区间结束',
    `gmt_create`    TIMESTAMP   DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`  TIMESTAMP   DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='用户授信分数额度表';

-- C端 初始化数据
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('1', '1', 0.30, 100.00, 30.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('1', '2', 0.30, 80.00, 24.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('1', '3', 0.30, 60.00, 18.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('1', '4', 0.30, 40.00, 12.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('1', '5', 0.00, 0.00, 0.00);

INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('2', '1', 0.10, 100.00, 10.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('2', '2', 0.10, 40.00, 4.00);

INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('3', '1', 0.20, 100.00, 20.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('3', '2', 0.20, 80.00, 16.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('3', '3', 0.20, 60.00, 12.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('3', '4', 0.20, 50.00, 10.00);

INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('4', '4', 0.20, 100.00, 20.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('4', '2', 0.20, 80.00, 16.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('4', '3', 0.20, 60.00, 12.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('4', '1', 0.20, 0.00, 0.00);

INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('5', '5', 0.20, 0.00, 0.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('5', '4', 0.20, 60.00, 12.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('5', '3', 0.20, 80.00, 16.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('5', '2', 0.20, 100.00, 20.00);
INSERT INTO `c_credit_quota_logic` (`dimension`, `standard_setting`, `weight`, `standard_score`, `estimate_score`)
VALUES ('5', '1', 0.20, 0.00, 0.00);

INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '1500000', 90.00, 100.00);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '1200000', 80.00, 89.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '1000000', 70.00, 79.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '800000', 60.00, 60.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '500000', 50.00, 50.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '400000', 40.00, 40.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '300000', 30.00, 30.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '200000', 20.00, 20.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '100000', 10.00, 10.99);
INSERT INTO `c_credit_score_quota` (`currency_code`, `quota`, `start_score`, `end_score`)
VALUES ('USD', '50000', 0.00, 9.99);

-- 销售合同基础表
DROP TABLE IF EXISTS `sales_contract`;
CREATE TABLE `sales_contract`
(
    `id`                       bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `customer_user_id`         BIGINT UNSIGNED DEFAULT 0 COMMENT '客户id',
    `contract_no`              varchar(64)     default '' comment '合同编号',
    `contract_name`            varchar(300)    default '' comment '合同名称',
    `importer_cert_no`         VARCHAR(32)     DEFAULT '' COMMENT '进口商统一社会信用代码/注册号',
    `importer_enterprise_name` VARCHAR(300)    DEFAULT NULL COMMENT '进口商企业名称',
    `agency_cert_no`           VARCHAR(32)     DEFAULT '' COMMENT '代理公司统一社会信用代码/注册号',
    `agency_enterprise_name`   VARCHAR(300)    DEFAULT NULL COMMENT '代理公司企业名称',
    `trade_terms`              varchar(4)      DEFAULT '' COMMENT '贸易术语',
    `port_departure`           varchar(255)    DEFAULT '' comment '起运港',
    `port_destination`         varchar(255)    DEFAULT '' comment '目的港',
    `template_type`            TINYINT(2) DEFAULT null COMMENT '模板类型1长银0自有',
    `sign_date`                DATETIME        DEFAULT null COMMENT '签署日期',
    `exchange_rate`            DECIMAL(17, 10) DEFAULT 0 COMMENT '汇率',
    `submit_status`            varchar(4)      DEFAULT '' COMMENT '提交状态1草稿2正式',
    `contract_status`          varchar(4)      DEFAULT '' COMMENT '合同状态1草稿2生效3待上传6已完成',
    `audit_status`             varchar(4)      DEFAULT '' COMMENT '审核状态1待审核2风控审核通过3法务审核通过4风控审核不通过5法务审核不通过',
    `deleted`                  TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    `create_by`                varchar(64)     default '' comment '创建者',
    `update_by`                varchar(64)     default '' comment '更新者',
    `gmt_create`               TIMESTAMP       DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`             TIMESTAMP       DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    UNIQUE INDEX uk_contract_No (`contract_No`),
    INDEX                      idx_cui (`customer_user_id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='销售合同表基础表';

-- 销售商品
DROP TABLE IF EXISTS `sales_commodity`;
CREATE TABLE `sales_commodity`
(
    `id`                     bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `sales_contract_id`      BIGINT UNSIGNED DEFAULT 0 COMMENT '销售合同主键',
    `entity_no`              VARCHAR(16)    DEFAULT '' COMMENT '供应商编号',
    `entity_name`            VARCHAR(64)    DEFAULT '' COMMENT '供应商名称',
    `hs_code`                VARCHAR(32)    DEFAULT '' COMMENT '商品编码',
    `name`                   VARCHAR(300)   DEFAULT NULL COMMENT '商品名称',
    `pack_spec`              VARCHAR(300)   DEFAULT NULL COMMENT '包装规格',
    `measurement_unit`       VARCHAR(300)   DEFAULT NULL COMMENT '计量单位',
    `export_tax_rebate_rate` VARCHAR(10)    DEFAULT '' COMMENT '出口退税税率',
    `added_tax_rate`         VARCHAR(10)    DEFAULT '' COMMENT '增值税率/增值税征税率',
    `number`                 INT            DEFAULT 0 comment '数量',
    `price_unit`             DECIMAL(17, 4) DEFAULT 0 comment '单价',
    `currency`               VARCHAR(3)     DEFAULT 'USD' COMMENT '币种',
    `amount`                 DECIMAL(17, 4) DEFAULT 0 COMMENT '金额',
    `model`                  VARCHAR(64)    DEFAULT '' COMMENT '型号',
    `deleted`                TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    -- `submit_status`          varchar(4)   DEFAULT '' COMMENT '提交状态1草稿2正式',
    `gmt_create`             TIMESTAMP      DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`           TIMESTAMP      DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    INDEX                    idx_sales_contract_id (`sales_contract_id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='销售商品表';

-- 合同条款
DROP TABLE IF EXISTS `contract_terms`;
CREATE TABLE `contract_terms`
(
    `id`               bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `contract_id`      BIGINT UNSIGNED DEFAULT 0 COMMENT '合同条款主键',
    `contractType`     VARCHAR(6)   DEFAULT '' COMMENT '合同类型',
    `contract_no`      varchar(64)  default '' comment '合同编号',
    `payment_way`      VARCHAR(6)   DEFAULT '' COMMENT '付款方式',
    `payment_currency` VARCHAR(3)   DEFAULT '' COMMENT '付款币种',
    `invoice_type`     VARCHAR(2)   DEFAULT '' COMMENT '发票类型1增值税专用发票2增值税普通发票',
    `settlement_cycle` INT          DEFAULT NULL COMMENT '结算周期单位天',
    `account_name`     VARCHAR(50)  DEFAULT '' COMMENT '账户名称',
    `account_number`   VARCHAR(50)  DEFAULT '' COMMENT '账号',
    `opening_bank`     VARCHAR(300) DEFAULT '' COMMENT '开户行名称',
    `swift_code`       VARCHAR(100) DEFAULT '' COMMENT '香港开户行',
    `deleted`          TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    -- `submit_status`    varchar(4)   DEFAULT '' COMMENT '提交状态1草稿2正式',
    `remark`           varchar(512) DEFAULT '' COMMENT '备注',
    `gmt_create`       TIMESTAMP    DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`     TIMESTAMP    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    UNIQUE INDEX uk_contract_No (`contract_No`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='合同条款表';

-- 合同条款扩展
DROP TABLE IF EXISTS `contract_terms_extend`;
CREATE TABLE `contract_terms_extend`
(
    `id`                bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `contract_terms_id` BIGINT UNSIGNED DEFAULT 0 COMMENT '合同条款主键',
    `type`              VARCHAR(3)   DEFAULT '' COMMENT '扩展类型1付款2条款',
    `payment_time`      VARCHAR(3)   DEFAULT '' COMMENT '付款时点，枚举',
    `term_title`        VARCHAR(512) DEFAULT '' COMMENT '条款标题',
    `content`           TEXT         DEFAULT NULL COMMENT '内容',
    `deleted`           TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    -- `submit_status`     varchar(4)   DEFAULT '' COMMENT '提交状态1草稿2正式',
    `gmt_create`        TIMESTAMP    DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`      TIMESTAMP    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    INDEX               idx_contract_terms_id (`contract_terms_id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='合同条款扩展表';

DROP TABLE IF EXISTS `contract_file`;
CREATE TABLE `contract_file`
(
    `id`                     BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `contract_no`            VARCHAR(64) DEFAULT '' COMMENT '合同编号',
    `sign_flow_id`           VARCHAR(50) DEFAULT '' COMMENT '签署流程ID',
    `sign_file_id`           VARCHAR(50) DEFAULT '' COMMENT '签署文件ID',
    `sign_file_type`         VARCHAR(50) DEFAULT '' COMMENT '签署文件类型',
    `unsign_file_storage_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '（未签署的）合同附件ID',
    `signed_file_storage_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '（签署完的）合同附件ID',
    `operator_name`          VARCHAR(50) DEFAULT '' COMMENT '操作人姓名',
    `generation_time`        DATETIME    DEFAULT NULL COMMENT '生成时间',
    `deleted`                TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    `gmt_create`             TIMESTAMP   DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`           TIMESTAMP   DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='合同文件';

-- 采购订单
DROP TABLE IF EXISTS `purchase_order`;
CREATE TABLE `purchase_order`
(
    `id`                   bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `customer_user_id`     BIGINT UNSIGNED DEFAULT 0 COMMENT '客户id',
    `sales_order_id`       BIGINT UNSIGNED DEFAULT 0 COMMENT '销售订单主键',
    `order_no`             VARCHAR(64)    DEFAULT '' COMMENT '订单编号',
    `entity_no`            VARCHAR(64)    DEFAULT '' COMMENT '供应商编号',
    `agency_cert_no`       VARCHAR(32)    DEFAULT '' COMMENT '代理公司统一社会信用代码/注册号',
    `purchase_contract_no` VARCHAR(64)    DEFAULT '' COMMENT '采购合同编号',
    `invoice_type`         VARCHAR(2)     DEFAULT '' COMMENT '发票类型1增值税专用发票2增值税普通发票',
    `currency`             VARCHAR(3)     DEFAULT 'CNY' COMMENT '币种',
    `amount_total`         DECIMAL(17, 4) DEFAULT '0' COMMENT '订单总额',
    `tax_amount_total`     DECIMAL(17, 4) DEFAULT '0' COMMENT '订单税额',
    `settlement_cycle`     INT            DEFAULT NULL COMMENT '结算周期单位天',
    `deleted`              TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    `gmt_create`           TIMESTAMP      DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`         TIMESTAMP      DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`),
    INDEX                  idx_sales_order_id (`sales_order_id`)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET utf8mb4
  COLLATE utf8mb4_bin COMMENT ='采购订单表';


-- 采购订单-关联商品
DROP TABLE IF EXISTS `purchase_order_commodity`;
CREATE TABLE `purchase_order_commodity`
(
    `id`                 BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `purchase_order_id`  BIGINT(20) UNSIGNED NOT NULL COMMENT '采购订单id',
    `sales_commodity_id` BIGINT(20) UNSIGNED NOT NULL COMMENT '销售商品id',
    `hs_code`            VARCHAR(32)        DEFAULT '' COMMENT '商品编码',
    `name`               VARCHAR(32)        DEFAULT '' COMMENT '商品名称',
    `measurement_unit`   VARCHAR(32)        DEFAULT '' COMMENT '计量单位',
    `pack_spec`          VARCHAR(300)       DEFAULT '' COMMENT '包装规格',
    `number`             INT                DEFAULT 0 comment '数量',
    `price_unit`         DECIMAL(17, 2)     DEFAULT '0' COMMENT '采购单价 (不含税) ',
    `tax_refund_rate`    DECIMAL(8, 6)      DEFAULT '0' COMMENT '增值税税率',
    `currency`           VARCHAR(3)         DEFAULT 'CNY' COMMENT '币种',
    `amount`             DECIMAL(17, 4)     DEFAULT '0' COMMENT '商品金额',
    `model`              VARCHAR(64)        DEFAULT '' COMMENT '型号',
    `deleted`            TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    `gmt_create`         TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`       TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='采购订单-关联商品';

DROP TABLE IF EXISTS `purchase_order_logistics`;
CREATE TABLE `purchase_order_logistics`
(
    `id`                     BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `purchase_order_id`      BIGINT(20) UNSIGNED NOT NULL COMMENT '采购订单id',
    `company_name`           VARCHAR(300)       DEFAULT '' COMMENT '物流公司名称',
    `logistics_order_number` VARCHAR(32)        DEFAULT '' COMMENT '物流单号',
    `delivery_time`          DATETIME           DEFAULT NULL COMMENT '发货时间',
    `arrive_time`            DATETIME           DEFAULT NULL COMMENT '送达时间',
    -- `transport_certificate_file_id` BIGINT(20) UNSIGNED NOT NULL COMMENT '运输证明文件id',
    `remark`                 varchar(512)       DEFAULT '' COMMENT '备注',
    `deleted`                TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    `gmt_create`             TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`           TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='采购订单-关联商品';

-- 采购订单-发票信息
DROP TABLE IF EXISTS `purchase_order_invoice`;
CREATE TABLE `purchase_order_invoice`
(
    `id`           BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `order_id`     BIGINT(20) UNSIGNED NOT NULL COMMENT '采购订单id',
    `invoice_no`   VARCHAR(32)        DEFAULT '' COMMENT '发票号码',
    `amount`       DECIMAL(17, 2)     DEFAULT '0' COMMENT '发票金额',
    `file_id`      BIGINT(20) UNSIGNED NOT NULL COMMENT '发票文件id',
    `deleted`      TINYINT(1) DEFAULT 0 COMMENT '删除标识',
    `gmt_create`   TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='采购订单-发票信息';

