- 主体状态缓存(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>
38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 协议(agreements)
|
||
*
|
||
* 一行 = 一种协议(用户协议 / 隐私政策……),版本正文在 `agreement_versions`,
|
||
* `current_version_id` 指向当前生效版本(不设外键,避免与版本表互相依赖)。
|
||
*/
|
||
module.exports = (app) => {
|
||
const { BIGINT, STRING, TINYINT, INTEGER, DATE } = app.Sequelize;
|
||
|
||
const Agreement = app.model.define('agreement', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
code: { type: STRING(64), allowNull: false, unique: true, comment: '协议标识(user_agreement 等)' },
|
||
name: { type: STRING(128), allowNull: false, comment: '协议名称(展示用)' },
|
||
description: { type: STRING(255), allowNull: true, comment: '简介' },
|
||
required: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '登录是否必须同意:1是 0否' },
|
||
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1启用 0停用' },
|
||
sortNo: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '展示排序(小的在前)' },
|
||
currentVersionId: { type: BIGINT.UNSIGNED, allowNull: true, comment: '当前生效版本 agreement_versions.id' },
|
||
}, {
|
||
tableName: 'agreements',
|
||
paranoid: true,
|
||
comment: '协议定义表',
|
||
});
|
||
|
||
Agreement.associate = function() {
|
||
app.model.Agreement.hasMany(app.model.AgreementVersion, { foreignKey: 'agreement_id', as: 'versions' });
|
||
app.model.Agreement.belongsTo(app.model.AgreementVersion, {
|
||
foreignKey: 'current_version_id',
|
||
as: 'currentVersion',
|
||
constraints: false,
|
||
});
|
||
};
|
||
|
||
return Agreement;
|
||
};
|