- 主体状态缓存(Redis 优先、进程内兜底):设备心跳与上报判断不再查库,续期/停用后主动失效 - 上报写接口按缓存校验期限:过期 403 subject_expired、停用 subject_disabled、主体缺失 subject_missing - 心跳与 /api/scanner/me 返回 subject 状态,桌面端据此暂停推送并在续期后自动补传积压 - 新增续期订单(subject_orders)与接口,支付回调 POST /api/pay/notify 幂等、支持 HMAC 签名, 另提供内部令牌模拟支付用于联调 - 顺带提交工作区中已完成的「登录协议」后端改动(agreement):与本次改动共用 router.js / config.default.js Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
40 lines
2.2 KiB
JavaScript
40 lines
2.2 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 主体续期订单
|
||
*
|
||
* 真实支付渠道还没接:先把「下单 → 渠道回调 → 主体续期」的链路落库,
|
||
* 回调格式见 `app/controller/pay/notify.js`(模拟回调见 README)。
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
const { BIGINT, STRING, TINYINT, INTEGER, DECIMAL, DATE } = Sequelize;
|
||
|
||
await queryInterface.createTable('subject_orders', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false },
|
||
order_no: { type: STRING(32), allowNull: false, unique: true, comment: '订单号(对外唯一)' },
|
||
subject_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '主体 subjects.id' },
|
||
user_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '下单用户 users.id' },
|
||
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 等)' },
|
||
transaction_id: { type: STRING(64), allowNull: true, comment: '渠道流水号' },
|
||
paid_at: { type: DATE, allowNull: true, comment: '支付时间' },
|
||
expire_before: { type: DATE, allowNull: true, comment: '续期前的到期时间' },
|
||
expire_after: { type: DATE, allowNull: true, comment: '续期后的到期时间' },
|
||
remark: { type: STRING(255), allowNull: true, comment: '备注' },
|
||
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_orders', [ 'subject_id' ], { name: 'idx_subject_orders_subject' });
|
||
await queryInterface.addIndex('subject_orders', [ 'status' ], { name: 'idx_subject_orders_status' });
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.dropTable('subject_orders');
|
||
},
|
||
};
|