-- =============================================
|
-- 销售报价模块数据库表
|
-- =============================================
|
|
-- 1. 报价单主表
|
CREATE TABLE IF NOT EXISTS `crm_sale_quotation` (
|
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
|
`no` varchar(32) NOT NULL COMMENT '报价单号',
|
`name` varchar(128) NOT NULL COMMENT '报价单名称',
|
`customer_id` bigint NOT NULL COMMENT '客户编号',
|
`business_id` bigint DEFAULT NULL COMMENT '商机编号',
|
`contact_id` bigint DEFAULT NULL COMMENT '联系人编号',
|
`owner_user_id` bigint NOT NULL COMMENT '负责人编号',
|
`status` int NOT NULL DEFAULT 0 COMMENT '状态(0草稿 10审批中 20已通过 30已拒绝 40已取消 50已转合同)',
|
`process_instance_id` varchar(64) DEFAULT NULL COMMENT '工作流编号',
|
`quotation_time` datetime DEFAULT NULL COMMENT '报价日期',
|
`valid_until` datetime DEFAULT NULL COMMENT '有效期至',
|
`total_product_price` decimal(24,6) DEFAULT NULL COMMENT '产品总金额',
|
`discount_percent` decimal(10,2) DEFAULT 0 COMMENT '整单折扣(%)',
|
`discount_price` decimal(24,6) DEFAULT 0 COMMENT '优惠金额',
|
`total_price` decimal(24,6) DEFAULT NULL COMMENT '报价总金额',
|
`tax_rate` decimal(10,2) DEFAULT NULL COMMENT '税率(%)',
|
`tax_price` decimal(24,6) DEFAULT NULL COMMENT '税额',
|
`contract_id` bigint DEFAULT NULL COMMENT '关联合同编号',
|
`contract_no` varchar(32) DEFAULT NULL COMMENT '关联合同单号',
|
`file_url` varchar(512) DEFAULT NULL COMMENT '附件地址',
|
`remark` varchar(1024) DEFAULT NULL COMMENT '备注',
|
`creator` varchar(64) DEFAULT NULL COMMENT '创建者',
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
`updater` varchar(64) DEFAULT NULL COMMENT '更新者',
|
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
|
PRIMARY KEY (`id`),
|
UNIQUE KEY `uk_no` (`no`),
|
KEY `idx_customer_id` (`customer_id`),
|
KEY `idx_business_id` (`business_id`),
|
KEY `idx_owner_user_id` (`owner_user_id`)
|
) ENGINE=InnoDB COMMENT='CRM 销售报价单';
|
|
-- 2. 报价单产品明细表
|
CREATE TABLE IF NOT EXISTS `crm_sale_quotation_product` (
|
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
|
`quotation_id` bigint NOT NULL COMMENT '报价单编号',
|
`item_id` bigint NOT NULL COMMENT 'MDM物料编号',
|
`item_unit_id` bigint DEFAULT NULL COMMENT '计量单位编号',
|
`item_price` decimal(24,6) NOT NULL COMMENT '物料原价(冗余)',
|
`quotation_price` decimal(24,6) NOT NULL COMMENT '报价单价',
|
`count` decimal(24,6) NOT NULL COMMENT '数量',
|
`total_price` decimal(24,6) NOT NULL COMMENT '小计金额',
|
`tax_percent` decimal(10,2) DEFAULT NULL COMMENT '税率(%)',
|
`tax_price` decimal(24,6) DEFAULT NULL COMMENT '税额',
|
`remark` varchar(256) DEFAULT NULL COMMENT '备注',
|
`creator` varchar(64) DEFAULT NULL COMMENT '创建者',
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
`updater` varchar(64) DEFAULT NULL COMMENT '更新者',
|
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
|
PRIMARY KEY (`id`),
|
KEY `idx_quotation_id` (`quotation_id`)
|
) ENGINE=InnoDB COMMENT='CRM 销售报价单产品明细';
|
|
-- =============================================
|
-- 合同产品表修改(使用 MDM 物料)
|
-- =============================================
|
|
-- 3. 修改合同产品表结构
|
-- 注意:如果已有数据,需要先处理数据迁移
|
-- ALTER TABLE `crm_contract_product` DROP COLUMN `product_id`;
|
-- ALTER TABLE `crm_contract_product` DROP COLUMN `product_price`;
|
|
ALTER TABLE `crm_contract_product`
|
ADD COLUMN `item_id` bigint DEFAULT NULL COMMENT 'MDM物料编号' AFTER `contract_id`,
|
ADD COLUMN `item_unit_id` bigint DEFAULT NULL COMMENT '计量单位编号' AFTER `item_id`,
|
ADD COLUMN `item_price` decimal(24,6) DEFAULT NULL COMMENT '物料原价(冗余)' AFTER `item_unit_id`;
|
|
-- 数据迁移:将 product_id 重命名为 item_id(如果需要保留原有数据)
|
-- UPDATE `crm_contract_product` SET `item_id` = `product_id`, `item_price` = `product_price`;
|
|
-- =============================================
|
-- BPM 分类(需要在 BPM 管理后台创建,这里提供 SQL 参考)
|
-- =============================================
|
|
-- INSERT INTO `bpm_category` (`name`, `code`, `description`, `status`, `sort`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
|
-- VALUES ('销售报价审批', 'sale_quotation_approve', '销售报价单审批流程分类', 0, 0, '1', NOW(), '1', NOW(), b'0');
|