This commit is contained in:
2025-12-02 19:57:10 +08:00
parent 3440744179
commit 08ff223ff8
188 changed files with 12337 additions and 7212 deletions

View File

@@ -0,0 +1,47 @@
-- ============================================
-- 代理短链表
-- 说明:存储推广链接和邀请链接的短链映射关系
--
-- 功能说明:
-- 1. 支持两种类型promotion推广报告和 invite邀请好友
-- 2. 为每个链接生成一个短链标识6位随机字符串
-- 3. 短链格式https://推广域名/s/{short_code}
-- 4. 短链重定向到前端传入的target_path
--
-- 执行步骤:
-- 1. 执行此 SQL 创建表
-- 2. 使用 goctl 生成 Modelagent_short_link -> AgentShortLinkModel
-- 3. 在 servicecontext.go 中添加 AgentShortLinkModel
-- ============================================
CREATE TABLE `agent_short_link` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`type` tinyint NOT NULL COMMENT '类型1=推广报告(promotion)2=邀请好友(invite)',
`link_id` bigint DEFAULT NULL COMMENT '推广链接ID关联agent_link表仅推广报告类型使用',
`invite_code_id` bigint DEFAULT NULL COMMENT '邀请码ID关联agent_invite_code表仅邀请好友类型使用',
`link_identifier` varchar(200) DEFAULT NULL COMMENT '推广链接标识(加密,仅推广报告类型使用)',
`invite_code` varchar(50) DEFAULT NULL COMMENT '邀请码(仅邀请好友类型使用)',
`short_code` varchar(20) NOT NULL COMMENT '短链标识6位随机字符串',
`target_path` varchar(500) NOT NULL COMMENT '目标地址(前端传入,如:/agent/promotionInquire/xxx 或 /register?invite_code=xxx',
`promotion_domain` varchar(200) NOT NULL COMMENT '推广域名(生成短链时使用的域名)',
`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 '删除时间',
`del_state` tinyint NOT NULL DEFAULT 0 COMMENT '删除状态0=未删除1=已删除',
`version` bigint NOT NULL DEFAULT 0 COMMENT '版本号(乐观锁)',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_short_code` (`short_code`, `del_state`) COMMENT '短链标识唯一索引',
UNIQUE KEY `uk_link_id_type` (
`link_id`,
`type`,
`del_state`
) COMMENT '同一推广链接同一类型只能有一个有效短链',
UNIQUE KEY `uk_invite_code_id_type` (
`invite_code_id`,
`type`,
`del_state`
) COMMENT '同一邀请码同一类型只能有一个有效短链',
KEY `idx_link_identifier` (`link_identifier`) COMMENT '推广链接标识索引',
KEY `idx_invite_code` (`invite_code`) COMMENT '邀请码索引',
KEY `idx_type` (`type`) COMMENT '类型索引',
KEY `idx_create_time` (`create_time`) COMMENT '创建时间索引'
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '代理短链表';

View File

@@ -0,0 +1,46 @@
-- ============================================
-- 邀请码使用历史表
-- 说明:记录每次邀请码的使用情况,支持统计和查询
--
-- 功能说明:
-- 1. 记录每个邀请码每次使用的详细信息
-- 2. 支持统计每个邀请码邀请了多少代理
-- 3. 支持查询某个代理是通过哪个邀请码成为代理的
-- 4. 保留完整的使用历史记录
--
-- 执行步骤:
-- 1. 执行此 SQL 创建表和添加字段
-- 2. 使用 goctl 生成 Modelagent_invite_code_usage -> AgentInviteCodeUsageModel
-- 3. 在 servicecontext.go 中添加 AgentInviteCodeUsageModel
-- ============================================
CREATE TABLE `agent_invite_code_usage` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`invite_code_id` bigint NOT NULL COMMENT '邀请码ID关联agent_invite_code表',
`code` varchar(50) NOT NULL COMMENT '邀请码(冗余字段,便于查询)',
`user_id` bigint NOT NULL COMMENT '使用用户ID',
`agent_id` bigint NOT NULL COMMENT '成为的代理ID',
`agent_level` tinyint NOT NULL COMMENT '代理等级1=普通2=黄金3=钻石',
`used_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '使用时间',
`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 '删除时间',
`del_state` tinyint NOT NULL DEFAULT 0 COMMENT '删除状态0=未删除1=已删除',
`version` bigint NOT NULL DEFAULT 0 COMMENT '版本号(乐观锁)',
PRIMARY KEY (`id`),
KEY `idx_invite_code_id` (`invite_code_id`) COMMENT '关联邀请码ID',
KEY `idx_code` (`code`) COMMENT '邀请码索引',
KEY `idx_user_id` (`user_id`) COMMENT '用户ID索引',
KEY `idx_agent_id` (`agent_id`) COMMENT '代理ID索引',
KEY `idx_used_time` (`used_time`) COMMENT '使用时间索引',
KEY `idx_create_time` (`create_time`) COMMENT '创建时间索引',
KEY `idx_code_time` (`code`, `used_time`) COMMENT '邀请码和使用时间复合索引'
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '邀请码使用历史表';
-- ============================================
-- 在agent表中添加invite_code_id字段可选便于直接查询代理是通过哪个邀请码成为的
-- ============================================
ALTER TABLE `agent`
ADD COLUMN `invite_code_id` bigint DEFAULT NULL COMMENT '通过哪个邀请码成为代理关联agent_invite_code表' AFTER `team_leader_id`;
ALTER TABLE `agent`
ADD KEY `idx_invite_code_id` (`invite_code_id`) COMMENT '邀请码ID索引';

View File

@@ -0,0 +1,56 @@
-- ============================================
-- 代理配置表重构 SQL 脚本
-- 执行顺序:按照下面的顺序依次执行
-- ============================================
-- ============================================
-- 步骤1删除价格相关配置项
-- 说明价格配置已改为在产品配置表agent_product_config中按产品配置
-- ============================================
DELETE FROM `agent_config` WHERE `config_key` IN (
'base_price',
'system_max_price',
'price_threshold',
'price_fee_rate'
);
-- ============================================
-- 步骤2统一配置键命名
-- 说明:修改配置键名称,使其与代码逻辑一致
-- ============================================
-- 修改等级加成配置键
UPDATE `agent_config` SET `config_key` = 'level_1_bonus' WHERE `config_key` = 'level_bonus_normal';
UPDATE `agent_config` SET `config_key` = 'level_2_bonus' WHERE `config_key` = 'level_bonus_gold';
UPDATE `agent_config` SET `config_key` = 'level_3_bonus' WHERE `config_key` = 'level_bonus_diamond';
-- 修改升级费用配置键
UPDATE `agent_config` SET `config_key` = 'upgrade_to_gold_fee' WHERE `config_key` = 'upgrade_fee_normal_to_gold';
UPDATE `agent_config` SET `config_key` = 'upgrade_to_diamond_fee' WHERE `config_key` = 'upgrade_fee_to_diamond';
-- 修改升级返佣配置键
UPDATE `agent_config` SET `config_key` = 'upgrade_to_gold_rebate' WHERE `config_key` = 'upgrade_rebate_normal_to_gold';
UPDATE `agent_config` SET `config_key` = 'upgrade_to_diamond_rebate' WHERE `config_key` = 'upgrade_rebate_to_diamond';
-- ============================================
-- 步骤3添加缺失的配置项
-- 说明:添加免税额度配置项(如果不存在)
-- ============================================
INSERT INTO `agent_config` (`config_key`, `config_value`, `config_type`, `description`)
SELECT 'tax_exemption_amount', '0.00', 'tax', '提现免税额度默认0'
WHERE NOT EXISTS (
SELECT 1 FROM `agent_config` WHERE `config_key` = 'tax_exemption_amount'
);
-- ============================================
-- 验证查询:检查配置项是否正确
-- ============================================
SELECT `config_key`, `config_value`, `config_type`, `description`
FROM `agent_config`
WHERE `del_state` = 0
ORDER BY `config_type`, `config_key`;
-- ============================================
-- 执行完成后,请重新生成 agent_config 相关的 Model 代码
-- ============================================

View File

@@ -0,0 +1,32 @@
-- ============================================
-- 代理佣金冻结任务表
-- 说明:用于记录需要解冻的佣金冻结任务,保证异步任务的一致性和持久化
-- ============================================
CREATE TABLE `agent_freeze_task` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`agent_id` bigint NOT NULL COMMENT '代理ID',
`order_id` bigint NOT NULL COMMENT '订单ID',
`commission_id` bigint NOT NULL COMMENT '佣金记录ID',
`freeze_amount` decimal(10, 2) NOT NULL COMMENT '冻结金额',
`order_price` decimal(10, 2) NOT NULL COMMENT '订单单价',
`freeze_ratio` decimal(5, 4) NOT NULL DEFAULT 0.1000 COMMENT '冻结比例例如0.1000表示10%',
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态1=待解冻2=已解冻3=已取消',
`freeze_time` datetime NOT NULL COMMENT '冻结时间',
`unfreeze_time` datetime NOT NULL COMMENT '解冻时间(冻结时间+1个月',
`actual_unfreeze_time` datetime DEFAULT NULL COMMENT '实际解冻时间',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`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 '删除时间',
`del_state` tinyint NOT NULL DEFAULT 0 COMMENT '删除状态0=未删除1=已删除',
`version` bigint NOT NULL DEFAULT 0 COMMENT '版本号(乐观锁)',
PRIMARY KEY (`id`),
KEY `idx_agent_id` (`agent_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_commission_id` (`commission_id`),
KEY `idx_status` (`status`),
KEY `idx_unfreeze_time` (`unfreeze_time`),
KEY `idx_agent_status` (`agent_id`, `status`),
KEY `idx_create_time` (`create_time`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '代理佣金冻结任务表';

View File

@@ -0,0 +1,25 @@
-- ============================================
-- 移除代理产品配置表中的 product_name 字段
-- 说明:改为通过 product_id 关联查询 product 表获取产品名称
-- 执行时间2025-01-XX
-- ============================================
-- 删除 product_name 字段
ALTER TABLE `agent_product_config` DROP COLUMN `product_name`;
-- ============================================
-- 验证查询:检查字段是否已删除
-- ============================================
DESC `agent_product_config`;
-- ============================================
-- 验证查询:通过关联查询获取产品名称
-- ============================================
SELECT apc.id, apc.product_id, p.product_name, apc.base_price, apc.system_max_price, apc.price_threshold, apc.price_fee_rate, apc.del_state, apc.create_time
FROM
`agent_product_config` apc
LEFT JOIN `product` p ON apc.product_id = p.id
AND p.del_state = 0
WHERE
apc.del_state = 0
ORDER BY apc.product_id;

View File

@@ -0,0 +1,112 @@
-- ============================================
-- 同步产品表数据到代理产品配置表
-- 说明:为现有产品创建对应的代理产品配置记录
-- 执行时间2025-01-XX
-- ============================================
-- 方式1使用 INSERT IGNORE如果记录已存在则忽略
-- 注意product_name 字段已移除,改为通过 product_id 关联查询 product 表获取
INSERT IGNORE INTO
`agent_product_config` (
`product_id`,
`base_price`,
`system_max_price`,
`price_threshold`,
`price_fee_rate`,
`del_state`,
`version`
)
VALUES (
1,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
2,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
3,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
4,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
5,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
6,
0.00,
9999.99,
NULL,
NULL,
0,
0
),
(
7,
0.00,
9999.99,
NULL,
NULL,
0,
0
);
-- ============================================
-- 方式2使用 INSERT ... ON DUPLICATE KEY UPDATE如果记录已存在则忽略
-- 注意product_name 字段已移除,不再需要更新
-- ============================================
/*
INSERT INTO `agent_product_config`
(`product_id`, `base_price`, `system_max_price`, `price_threshold`, `price_fee_rate`, `del_state`, `version`)
VALUES
(1, 0.00, 9999.99, NULL, NULL, 0, 0),
(2, 0.00, 9999.99, NULL, NULL, 0, 0),
(3, 0.00, 9999.99, NULL, NULL, 0, 0),
(4, 0.00, 9999.99, NULL, NULL, 0, 0),
(5, 0.00, 9999.99, NULL, NULL, 0, 0),
(6, 0.00, 9999.99, NULL, NULL, 0, 0),
(7, 0.00, 9999.99, NULL, NULL, 0, 0)
ON DUPLICATE KEY UPDATE
`product_id` = VALUES(`product_id`);
*/
-- ============================================
-- 验证查询:检查同步结果
-- ============================================
SELECT apc.id, apc.product_id, p.product_name, apc.base_price, apc.system_max_price, apc.price_threshold, apc.price_fee_rate, apc.del_state, apc.create_time
FROM
`agent_product_config` apc
LEFT JOIN `product` p ON apc.product_id = p.id
AND p.del_state = 0
WHERE
apc.del_state = 0
ORDER BY apc.product_id;