Files
yunzerwebsiteallinone/go/docs/sql/create_backend_crm_payback.sql
T
2026-09-15 10:44:31 +08:00

63 lines
4.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================================
-- CRM回款相关表:回款计划 / 回款记录(回款进度流水)
-- yz_backend_crm_payback 回款计划
-- yz_backend_crm_payback_record 回款记录(每次「新建回款」追加一条,
-- 以回款计划 payback_id 为先导条件)
-- 可重复执行(CREATE TABLE IF NOT EXISTS)。
-- 运行:mysql -h<host> -P<port> -u<user> -p <db> < create_backend_crm_payback.sql
-- =============================================================
CREATE TABLE IF NOT EXISTS `yz_backend_crm_payback` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',
`tenant_id` varchar(64) NOT NULL COMMENT '租户ID',
`contract_id` bigint(20) DEFAULT NULL COMMENT '关联合同ID(yz_backend_crm_contract.id)',
`contract_no` varchar(50) NOT NULL DEFAULT '' COMMENT '合同编号',
`contract_name` varchar(100) NOT NULL DEFAULT '' COMMENT '合同名称',
`customer_id` bigint(20) DEFAULT NULL COMMENT '客户ID',
`customer_name` varchar(128) NOT NULL DEFAULT '' COMMENT '客户名称',
`plan_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '回款周期:1月度/2季度/3年度/4进度/5自定义',
`pay_method` tinyint(4) NOT NULL DEFAULT '1' COMMENT '回款方式:1对公转账/2网银转账/3现金/4支票/5支付宝/6微信/7其他',
`remind_days` int(11) NOT NULL DEFAULT '0' COMMENT '提前几天提醒',
`owner_user_id` varchar(64) NOT NULL DEFAULT '' COMMENT '负责人用户ID',
`owner_user_name` varchar(128) NOT NULL DEFAULT '' COMMENT '负责人姓名',
`contract_amount` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '合同总金额',
`total_amount` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '计划回款总额',
`received_amount` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '已回款金额',
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态:1进行中/2已完成',
`items` text COMMENT '计划明细JSON数组',
`remark` text COMMENT '备注',
`create_user_id` varchar(64) NOT NULL DEFAULT '' COMMENT '创建人用户ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间(软删除)',
PRIMARY KEY (`id`),
KEY `idx_tenant_id` (`tenant_id`),
KEY `idx_contract` (`tenant_id`,`contract_id`),
KEY `idx_customer` (`tenant_id`,`customer_id`),
KEY `idx_status` (`tenant_id`,`status`),
KEY `idx_delete_time` (`delete_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='租户CRM回款计划表';
CREATE TABLE IF NOT EXISTS `yz_backend_crm_payback_record` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',
`tenant_id` varchar(64) NOT NULL COMMENT '租户ID',
`contract_id` bigint(20) DEFAULT NULL COMMENT '关联合同ID(yz_backend_crm_contract.id)',
`payback_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '关联回款计划ID(yz_backend_crm_payback.id)',
`amount` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '本次回款金额',
`received_date` varchar(20) NOT NULL DEFAULT '' COMMENT '回款日期 YYYY-MM-DD',
`pay_method` tinyint(4) NOT NULL DEFAULT '1' COMMENT '回款方式:1对公/2网银/3现金/4支票/5支付宝/6微信/7其他',
`receipt_url` varchar(512) DEFAULT NULL COMMENT '流水回执文件地址',
`receipt_name` varchar(255) DEFAULT NULL COMMENT '流水回执文件名',
`remark` text COMMENT '备注',
`owner_user_id` varchar(64) NOT NULL DEFAULT '' COMMENT '负责人用户ID',
`owner_user_name` varchar(128) NOT NULL DEFAULT '' COMMENT '负责人姓名',
`create_user_id` varchar(64) NOT NULL DEFAULT '' COMMENT '创建人用户ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间(软删除)',
PRIMARY KEY (`id`),
KEY `idx_tenant_contract` (`tenant_id`,`contract_id`),
KEY `idx_payback` (`tenant_id`,`payback_id`),
KEY `idx_delete_time` (`delete_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='租户CRM回款记录表(回款进度流水)';