/*
 2.0 MysqlTable in OperatingCenter System DDL、DML
*/
-- ----------------------------
-- Table structure for op_merchant_list
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_merchant_list`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `merchant_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '商户编号',
    `merchant_name` varchar(64)  NOT NULL DEFAULT '' COMMENT '商户名称',
    `login_name` varchar(32)  NOT NULL DEFAULT '' COMMENT '登录名',
    `merchant_short_name` varchar(64) NOT NULL DEFAULT '' COMMENT '商户简称',
    `contact_name` varchar(64) NOT NULL DEFAULT ''  COMMENT '联系人姓名',
    `contact_email` varchar(64) NULL DEFAULT NULL COMMENT '联系人邮箱',
    `contact_phone` TINYINT(11) DEFAULT 0 COMMENT '联系人手机号',
    `merchant_level` TINYINT(1) DEFAULT 0 COMMENT '商户级别(0:简单模式|M0-页面简洁，仅基础收款功能, 1:高级模式|M1-支持api调用， 支持配置应用及分账、转账功能)',
    `refund_method` TINYINT(1) DEFAULT 0 COMMENT '退款方式(0:平台退款, 1:接口退款)',
    `merchant_type` TINYINT(1) DEFAULT 0 COMMENT '商户类型(0:特约商户, 1:普通商户)',
    `agent_id` varchar(64) NULL DEFAULT '' COMMENT '代理商ID',
    `service_id` varchar(64) NULL DEFAULT '' COMMENT '服务商ID',
    `notes` varchar(256) NULL DEFAULT NULL COMMENT '备注',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `reserved_field3` varchar(64) NULL DEFAULT NULL COMMENT '预留字段3',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_merchant_number (merchant_number) -- 商户编号创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商户列表';

-- ----------------------------
-- Table structure for op_store_management
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_store_management`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `merchant_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '商户编号',
    `enter_piece_id` varchar(32)  NOT NULL DEFAULT '' COMMENT '进件Id',
    `store_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '门店编号',
    `store_name` varchar(64)  NOT NULL DEFAULT '' COMMENT '门店名称',
    `contact_phone` TINYINT(11) DEFAULT 0 COMMENT '联系人电话',
    `logo_photo` varchar(64) NULL DEFAULT '' COMMENT '门店logo',
    `indoor_scene_photo` varchar(64) NULL DEFAULT '' COMMENT '门店内景照片',
    `environment_photo` varchar(64) NULL DEFAULT '' COMMENT '门店环境照片',
    `door_sign_photo` varchar(64) NULL DEFAULT '' COMMENT '门头照片',
    `province` varchar(64) NULL DEFAULT '' COMMENT '省份',
    `city` varchar(64) NULL DEFAULT '' COMMENT '城市',
    `urban_area` varchar(64) NULL DEFAULT '' COMMENT '城区',
    `specific_location` varchar(64) NULL DEFAULT '' COMMENT '具体位置',
    `latitude_longitude` varchar(32) NULL DEFAULT '' COMMENT '经纬度',
    `customer_service_phone` varchar(256) NULL DEFAULT NULL COMMENT '客服电话',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `reserved_field3` varchar(64) NULL DEFAULT NULL COMMENT '预留字段3',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_merchant_number (merchant_number) -- 商户编号创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '门店管理';

-- ----------------------------
-- Table structure for op_enter_piece_management
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_enter_piece_management`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `merchant_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '商户编号',
    `apply_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '申请单号',
    `channel` TINYINT(1) DEFAULT 0 COMMENT '渠道（TODO：暂定0-汇付天下，完善渠道后，补充对应的注释）',
    `product_name` varchar(64) NULL DEFAULT '' COMMENT '进件商户名',
    `merchant_type` TINYINT(1) DEFAULT 0 COMMENT '商户类型(0:个体工商户, 1:企业)',
    `submit_status` varchar(64) NULL DEFAULT '' COMMENT '提交状态(0-拟稿，1-审核中，2-进件成功)',
    `source` TINYINT(1) DEFAULT 0  COMMENT '来源(0-运营中心，1-商户系统)',
    `submit_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '' COMMENT '提交时间',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `reserved_field3` varchar(64) NULL DEFAULT NULL COMMENT '预留字段3',
    `reserved_field4` varchar(64) NULL DEFAULT NULL COMMENT '预留字段4',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_merchant_number (merchant_number) -- 商户编号创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '进件管理';

-- ----------------------------
-- Table structure for op_merchant_info
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_merchant_info`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `enter_piece_id` varchar(32)  NOT NULL DEFAULT '' COMMENT '进件ID',
    `license_photo` varchar(32)  NOT NULL DEFAULT '' COMMENT '营业执照照片',
    `license_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '营业执照编号',
    `merchant_full_name` varchar(32)  NOT NULL DEFAULT '' COMMENT '商户名称全称',
    `registered_address` varchar(64)  NOT NULL DEFAULT '' COMMENT '营业执照注册地址',
    `issue_date` DATE COMMENT '营业执照有效期开始时间',
    `expiry_date` DATE COMMENT '营业执照有效期截止时间',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_enter_piece_id (enter_piece_id) -- 进件Id创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商户信息';



-- ----------------------------
-- Table structure for op_legal_entity_id_card_info
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_legal_entity_id_card_info`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `enter_piece_id` varchar(32)  NOT NULL DEFAULT '' COMMENT '进件ID',
    `card_front_photo` varchar(32)  NOT NULL DEFAULT '' COMMENT '法人身份证人像面照片',
    `card_reverse_photo` varchar(32)  NOT NULL DEFAULT '' COMMENT '法人身份证国徽面照片',
    `card_name` varchar(32)  NOT NULL DEFAULT '' COMMENT '法人身份证姓名',
    `card_number` varchar(32)  NOT NULL DEFAULT '' COMMENT '法人身份证号',
    `start_date` varchar(32)  NOT NULL DEFAULT '' COMMENT '法人身份证起始有效时间',
    `end_date` varchar(32)  NOT NULL DEFAULT '' COMMENT '法人身份证结束有效时间',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_enter_piece_id (enter_piece_id) -- 进件Id创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '法人身份证信息';

-- ----------------------------
-- Table structure for op_Settlement_rules
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_settlement_rules`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `enter_piece_id` varchar(32)  NOT NULL DEFAULT '' COMMENT '进件ID',
    `settlement_info` varchar(32)  NOT NULL DEFAULT '' COMMENT '结算规则信息（todo 目前结算规则业务不完善，待产品确认规则再指定，占坑）',
    `industry` varchar(32)  NOT NULL DEFAULT '' COMMENT '选择行业',
    `special_qualifications_photo` varchar(32)  NOT NULL DEFAULT '' COMMENT '特殊资质',
    `rate_activity` TINYINT(1) DEFAULT 0 COMMENT '优惠费率活动(0-不参与，1-参与)',
    `server_bid_price` varchar(32)  NOT NULL DEFAULT '' COMMENT '服务商底价',
    `agent_rate` varchar(32)  NOT NULL DEFAULT '' COMMENT '代理商费率',
    `enter_piece_rate` varchar(64) NULL DEFAULT NULL COMMENT '进件费率',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_enter_piece_id (enter_piece_id) -- 进件Id创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '结算规则';

-- ----------------------------
-- Table structure for op_settlement_account
-- ----------------------------

CREATE TABLE IF NOT EXISTS `op_settlement_account`  (
    `id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
    `enter_piece_id` varchar(32)  NOT NULL DEFAULT '' COMMENT '进件ID',
    `account_type` TINYINT(1) DEFAULT 0 COMMENT '账户类型(0:对私, 1:对公)',
    `open_account_name` varchar(32)  NOT NULL DEFAULT '' COMMENT '开户名称',
    `bank_account` varchar(32)  NOT NULL DEFAULT '' COMMENT '银行账号',
    `open_account_bank` varchar(32)  NOT NULL DEFAULT '' COMMENT '开户行',
    `bank_address` varchar(32)  NOT NULL DEFAULT '' COMMENT '开户行地址',
    `reserved_field1` varchar(64) NULL DEFAULT NULL COMMENT '预留字段1',
    `reserved_field2` varchar(64) NULL DEFAULT NULL COMMENT '预留字段2',
    `created_user` VARCHAR(64) NOT NULL COMMENT '创建人',
    `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_user` VARCHAR(64) NOT NULL COMMENT '更新人',
    `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL COMMENT '逻辑删除标识 (0:未删除, 1:已删除)',
    `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
    INDEX idx_is_deleted (is_deleted), -- 为逻辑删除字段创建索引，提高查询性能
    INDEX idx_enter_piece_id (enter_piece_id) -- 进件Id创建索引、提高查询性能
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '结算账户';

