admin/sql/migrate_coupon_grant_system.sql
zzh f972a28d79
All checks were successful
Build and Deploy / deploy (push) Successful in 3m50s
feat: 落地滚动会员、券发放与邀请分成奖励
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-06 17:40:24 +08:00

110 lines
4.5 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.

-- 优惠券发放体系:未解锁状态、到期提醒标记、新人/裂变券模板(可重复执行)
SET @db := DATABASE();
SET @col := (
SELECT COUNT(1)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_coupon_instance'
AND COLUMN_NAME = 'ExpiryNoticeSent'
);
SET @sql := IF(
@col = 0,
'ALTER TABLE `t_coupon_instance`
ADD COLUMN `ExpiryNoticeSent` TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''到期前3天已提醒'' AFTER `LockExpireTime`',
'SELECT ''ExpiryNoticeSent already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 新人首单券 15 元,领取后 15 天
INSERT INTO `t_coupon_template` (
`TemplateCode`, `TemplateName`, `CouponType`, `FaceValue`, `DiscountRate`, `MaxDiscountAmount`,
`MinOrderAmount`, `TotalQuantity`, `IssuedQuantity`, `PerCustomerLimit`,
`ValidType`, `ValidStartTime`, `ValidEndTime`, `ValidDaysAfterReceive`,
`ApplyScopeJson`, `GrantChannel`, `Status`, `Remark`,
`IsDeleted`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
)
SELECT
'NEWCOMER_FIRST', '新人首单券', 'fixed_off', 15.00, NULL, NULL,
0, 0, 0, 1,
2, NULL, NULL, 15,
NULL, 'newcomer', 1, '注册自动下发,仅抵基础运费,退款不退回',
0, 0, NOW(), 0, NOW()
WHERE NOT EXISTS (
SELECT 1 FROM `t_coupon_template` x WHERE x.`IsDeleted` = 0 AND x.`TemplateCode` = 'NEWCOMER_FIRST'
);
-- 新人第二单券 15 元,满 150 基础运费,解锁后 30 天
INSERT INTO `t_coupon_template` (
`TemplateCode`, `TemplateName`, `CouponType`, `FaceValue`, `DiscountRate`, `MaxDiscountAmount`,
`MinOrderAmount`, `TotalQuantity`, `IssuedQuantity`, `PerCustomerLimit`,
`ValidType`, `ValidStartTime`, `ValidEndTime`, `ValidDaysAfterReceive`,
`ApplyScopeJson`, `GrantChannel`, `Status`, `Remark`,
`IsDeleted`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
)
SELECT
'NEWCOMER_SECOND', '新人第二单券', 'fixed_off', 15.00, NULL, NULL,
150, 0, 0, 1,
3, NULL, NULL, 30,
NULL, 'newcomer', 1, '首单派送成功后解锁,实付基础运费满 150',
0, 0, NOW(), 0, NOW()
WHERE NOT EXISTS (
SELECT 1 FROM `t_coupon_template` x WHERE x.`IsDeleted` = 0 AND x.`TemplateCode` = 'NEWCOMER_SECOND'
);
-- 新人备货券 20 元,满 200,注册后 60 天
INSERT INTO `t_coupon_template` (
`TemplateCode`, `TemplateName`, `CouponType`, `FaceValue`, `DiscountRate`, `MaxDiscountAmount`,
`MinOrderAmount`, `TotalQuantity`, `IssuedQuantity`, `PerCustomerLimit`,
`ValidType`, `ValidStartTime`, `ValidEndTime`, `ValidDaysAfterReceive`,
`ApplyScopeJson`, `GrantChannel`, `Status`, `Remark`,
`IsDeleted`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
)
SELECT
'NEWCOMER_STOCK', '新人备货券', 'fixed_off', 20.00, NULL, NULL,
200, 0, 0, 1,
2, NULL, NULL, 60,
NULL, 'newcomer', 1, '注册自动下发,实付基础运费满 200',
0, 0, NOW(), 0, NOW()
WHERE NOT EXISTS (
SELECT 1 FROM `t_coupon_template` x WHERE x.`IsDeleted` = 0 AND x.`TemplateCode` = 'NEWCOMER_STOCK'
);
-- 裂变:老客 20 元无门槛
INSERT INTO `t_coupon_template` (
`TemplateCode`, `TemplateName`, `CouponType`, `FaceValue`, `DiscountRate`, `MaxDiscountAmount`,
`MinOrderAmount`, `TotalQuantity`, `IssuedQuantity`, `PerCustomerLimit`,
`ValidType`, `ValidStartTime`, `ValidEndTime`, `ValidDaysAfterReceive`,
`ApplyScopeJson`, `GrantChannel`, `Status`, `Remark`,
`IsDeleted`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
)
SELECT
'REFERRAL_INVITER', '邀请有礼券', 'fixed_off', 20.00, NULL, NULL,
0, 0, 0, 1,
2, NULL, NULL, 30,
NULL, 'referral', 1, '被邀请人首单派送成功后发给邀请人',
0, 0, NOW(), 0, NOW()
WHERE NOT EXISTS (
SELECT 1 FROM `t_coupon_template` x WHERE x.`IsDeleted` = 0 AND x.`TemplateCode` = 'REFERRAL_INVITER'
);
-- 裂变:新客额外 5 元
INSERT INTO `t_coupon_template` (
`TemplateCode`, `TemplateName`, `CouponType`, `FaceValue`, `DiscountRate`, `MaxDiscountAmount`,
`MinOrderAmount`, `TotalQuantity`, `IssuedQuantity`, `PerCustomerLimit`,
`ValidType`, `ValidStartTime`, `ValidEndTime`, `ValidDaysAfterReceive`,
`ApplyScopeJson`, `GrantChannel`, `Status`, `Remark`,
`IsDeleted`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
)
SELECT
'REFERRAL_INVITEE', '邀请注册加赠券', 'fixed_off', 5.00, NULL, NULL,
0, 0, 0, 1,
2, NULL, NULL, 30,
NULL, 'referral', 1, '被邀请人注册即发 5 元券',
0, 0, NOW(), 0, NOW()
WHERE NOT EXISTS (
SELECT 1 FROM `t_coupon_template` x WHERE x.`IsDeleted` = 0 AND x.`TemplateCode` = 'REFERRAL_INVITEE'
);