packServer/backend/database/migrations/20261021180000-create-subject-plans.js
liufumingren 3030f50cd3 续期改为选套餐下单,支付回调确认后才续期
数据库
- 新增 subject_plans(天数 + 定价):迁移内置三档
  30 天 ¥99 / 180 天 ¥499(推荐,划线 594)/ 365 天 ¥899(最划算,划线 1204)
- subject_orders 增加 plan_id / plan_code / plan_name 快照

后端
- GET /api/web/subject-plans:上架套餐(含 pricePerDay)
- POST /api/web/subjects/:id/orders 改为 { planId }:金额只认套餐价,
  前端传的 amount/days 一律忽略;套餐不存在/下架/未配价格 → 422
- 新增 GET /api/web/subjects/:id/orders/:orderNo(轮询支付状态)、
  POST .../orders/:orderNo/close(关闭待支付订单)
- 下单仍然只建单不动期限;续期只发生在 POST /api/pay/notify(渠道回调)成功之后

前端
- 续期不再 prompt 输入天数:弹窗展示套餐卡片(天数/价格/划线价/角标/折合每天),
  点「生成订单(¥xxx)」→ 显示订单号、金额、状态(待支付)
- 每 2s 轮询订单状态,回调确认后自动刷新主体列表并提示新到期时间;
  待支付时可「关闭订单」,避免留下悬挂单

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-21 17:43:18 +08:00

84 lines
3.1 KiB
JavaScript
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.

'use strict';
/**
* 续期套餐(subject_plans)+ 默认三档套餐
*
* 之前续期是「自己输入天数」,改成**选择套餐**:套餐把天数与定价绑在一起,价格由服务端算,
* 前端只传 `planId`(不信任前端传来的金额)。
*
* 默认三档(价格可在库/接口里改,不用发版):
* 30 天 ¥ 99
* 180 天 ¥ 499
* 365 天 ¥ 899
*/
module.exports = {
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, TINYINT, INTEGER, DECIMAL, DATE } = Sequelize;
await queryInterface.createTable('subject_plans', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false },
code: { type: STRING(32), allowNull: false, unique: true, comment: '套餐编码(month/半年/年 等,稳定标识)' },
name: { type: STRING(64), allowNull: false, comment: '套餐名称(展示用)' },
days: { type: INTEGER.UNSIGNED, allowNull: false, comment: '续期天数' },
price: { type: DECIMAL(10, 2), allowNull: false, defaultValue: 0, comment: '售价(元)' },
original_price: { type: DECIMAL(10, 2), allowNull: true, comment: '划线原价(可选)' },
tag: { type: STRING(16), allowNull: true, comment: '角标文案(如「推荐」「最划算」)' },
description: { type: STRING(255), allowNull: true, comment: '副标题说明' },
sort: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '排序(小的在前)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1 上架 0 下架' },
created_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
updated_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
deleted_at: { type: DATE, allowNull: true },
}, { comment: '主体续期套餐表' });
await queryInterface.addIndex('subject_plans', [ 'status', 'sort' ], { name: 'idx_subject_plans_status_sort' });
const now = new Date();
await queryInterface.bulkInsert('subject_plans', [
{
code: 'p30',
name: '30 天',
days: 30,
price: 99,
original_price: null,
tag: null,
description: '短期试用 / 临时项目',
sort: 10,
status: 1,
created_at: now,
updated_at: now,
},
{
code: 'p180',
name: '180 天',
days: 180,
price: 499,
original_price: 594,
tag: '推荐',
description: '半年,折合 ¥2.77 / 天',
sort: 20,
status: 1,
created_at: now,
updated_at: now,
},
{
code: 'p365',
name: '365 天',
days: 365,
price: 899,
original_price: 1204,
tag: '最划算',
description: '一年,折合 ¥2.46 / 天',
sort: 30,
status: 1,
created_at: now,
updated_at: now,
},
]);
},
async down(queryInterface) {
await queryInterface.dropTable('subject_plans');
},
};