feat: 支持同卡种续卡叠加并修复过期登录态

支付成功后将次数或有效期叠加到已有会员卡,首页与详情页引导续卡;接口 401 时同步清掉本地登录态。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
richarjiang
2026-09-07 14:04:11 +08:00
parent 801e2f47da
commit 88cd8419c8
22 changed files with 1370 additions and 123 deletions

View File

@@ -0,0 +1,20 @@
-- AlterTable
ALTER TABLE `memberships` ADD COLUMN `total_times` INTEGER NULL;
-- AlterTable
ALTER TABLE `orders` ADD COLUMN `membership_id` VARCHAR(191) NULL;
-- CreateIndex
CREATE INDEX `memberships_user_id_card_type_id_idx` ON `memberships`(`user_id`, `card_type_id`);
-- CreateIndex
CREATE INDEX `orders_membership_id_idx` ON `orders`(`membership_id`);
-- AddForeignKey
ALTER TABLE `orders` ADD CONSTRAINT `orders_membership_id_fkey` FOREIGN KEY (`membership_id`) REFERENCES `memberships`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- Backfill purchased-times snapshot for existing times/trial cards
UPDATE `memberships` `m`
INNER JOIN `card_types` `ct` ON `ct`.`id` = `m`.`card_type_id`
SET `m`.`total_times` = `ct`.`total_times`
WHERE `ct`.`total_times` IS NOT NULL AND `m`.`total_times` IS NULL;