数据库
- 新增 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>
45 lines
2.4 KiB
JavaScript
45 lines
2.4 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 主体续期订单(subject_orders)
|
||
*
|
||
* 一行 = 一次「续期 N 天」的下单记录:
|
||
* - `status`:0 待支付 / 1 已支付 / 2 已关闭
|
||
* - `amount` 为空表示不校验金额(内部续期 / 免费赠送)
|
||
* - 支付成功后由 `service/subject_order.js#payNotify` 把主体期限顺延,
|
||
* 并记录续期前后的到期时间(`expireBefore` / `expireAfter`)方便对账
|
||
*/
|
||
module.exports = (app) => {
|
||
const { BIGINT, STRING, TINYINT, INTEGER, DECIMAL, DATE } = app.Sequelize;
|
||
|
||
const SubjectOrder = app.model.define('subject_order', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
orderNo: { type: STRING(32), allowNull: false, unique: true, comment: '订单号(对外唯一)' },
|
||
subjectId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '主体 subjects.id' },
|
||
userId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '下单用户 users.id' },
|
||
planId: { type: BIGINT.UNSIGNED, allowNull: true, comment: '续期套餐 subject_plans.id(内部单可为空)' },
|
||
planCode: { type: STRING(32), allowNull: true, comment: '套餐编码快照' },
|
||
planName: { type: STRING(64), allowNull: true, comment: '套餐名称快照' },
|
||
days: { type: INTEGER.UNSIGNED, allowNull: false, comment: '续期天数' },
|
||
amount: { type: DECIMAL(10, 2), allowNull: true, comment: '应付金额(为空表示不校验)' },
|
||
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '状态:0待支付 1已支付 2已关闭' },
|
||
channel: { type: STRING(16), allowNull: true, comment: '支付渠道(mock 等)' },
|
||
transactionId: { type: STRING(64), allowNull: true, comment: '渠道流水号' },
|
||
paidAt: { type: DATE, allowNull: true, comment: '支付时间' },
|
||
expireBefore: { type: DATE, allowNull: true, comment: '续期前的到期时间' },
|
||
expireAfter: { type: DATE, allowNull: true, comment: '续期后的到期时间' },
|
||
remark: { type: STRING(255), allowNull: true, comment: '备注' },
|
||
}, {
|
||
tableName: 'subject_orders',
|
||
paranoid: true,
|
||
comment: '主体续期订单表',
|
||
});
|
||
|
||
SubjectOrder.associate = function() {
|
||
app.model.SubjectOrder.belongsTo(app.model.Subject, { foreignKey: 'subject_id', as: 'subject' });
|
||
app.model.SubjectOrder.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
|
||
};
|
||
|
||
return SubjectOrder;
|
||
};
|