- 主体状态缓存(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>
37 lines
1.8 KiB
JavaScript
37 lines
1.8 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 协议版本(agreement_versions)
|
||
*
|
||
* 正文存 `content`(默认纯文本,`content_type='text'`;后续要富文本可改 'html'),
|
||
* `status`:0 草稿 / 1 已发布 / 2 已归档。只有「已发布」且被 `agreements.current_version_id`
|
||
* 指向的版本才会下发给客户端。
|
||
*/
|
||
module.exports = (app) => {
|
||
const { BIGINT, STRING, TINYINT, TEXT, DATE } = app.Sequelize;
|
||
|
||
const AgreementVersion = app.model.define('agreement_version', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
agreementId: { type: BIGINT.UNSIGNED, allowNull: false, comment: 'agreements.id' },
|
||
version: { type: STRING(32), allowNull: false, comment: '版本号(1.0.0)' },
|
||
title: { type: STRING(128), allowNull: false, comment: '版本标题' },
|
||
summary: { type: STRING(255), allowNull: true, comment: '变更摘要' },
|
||
content: { type: TEXT('long'), allowNull: false, comment: '协议正文' },
|
||
contentType: { type: STRING(16), allowNull: false, defaultValue: 'text', comment: '正文类型:text / html' },
|
||
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:0草稿 1已发布 2已归档' },
|
||
publishedAt: { type: DATE, allowNull: true, comment: '发布时间' },
|
||
effectiveAt: { type: DATE, allowNull: true, comment: '生效时间' },
|
||
}, {
|
||
tableName: 'agreement_versions',
|
||
paranoid: true,
|
||
comment: '协议版本表',
|
||
});
|
||
|
||
AgreementVersion.associate = function() {
|
||
app.model.AgreementVersion.belongsTo(app.model.Agreement, { foreignKey: 'agreement_id', as: 'agreement' });
|
||
app.model.AgreementVersion.hasMany(app.model.UserAgreement, { foreignKey: 'version_id', as: 'userAgreements' });
|
||
};
|
||
|
||
return AgreementVersion;
|
||
};
|