packServer/backend/app/model/user_agreement.js
liufumingren 7b11f7052d feat(subject): 主体到期暂停设备上报,新增续期订单与支付回调
- 主体状态缓存(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>
2026-10-20 18:55:57 +08:00

36 lines
1.7 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';
/**
* 用户协议同意记录(user_agreements)
*
* 一行 = 某个用户同意过某个协议的某个版本(同一版本重复登录只更新时间,不重复插入)。
* 版本号同时冗余一列 `version`,方便协议版本被改名/归档后仍能审计当时同意的是哪一版。
*/
module.exports = (app) => {
const { BIGINT, STRING, DATE } = app.Sequelize;
const UserAgreement = app.model.define('user_agreement', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
userId: { type: BIGINT.UNSIGNED, allowNull: false, comment: 'users.id' },
agreementId: { type: BIGINT.UNSIGNED, allowNull: false, comment: 'agreements.id' },
versionId: { type: BIGINT.UNSIGNED, allowNull: false, comment: 'agreement_versions.id' },
version: { type: STRING(32), allowNull: false, comment: '同意时的版本号快照' },
source: { type: STRING(32), allowNull: true, comment: '来源:mini_program / web / h5' },
ip: { type: STRING(64), allowNull: true, comment: '同意时的客户端 IP' },
userAgent: { type: STRING(255), allowNull: true, comment: '同意时的 User-Agent' },
agreedAt: { type: DATE, allowNull: false, comment: '同意时间' },
}, {
tableName: 'user_agreements',
paranoid: true,
comment: '用户协议同意记录表',
});
UserAgreement.associate = function() {
app.model.UserAgreement.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
app.model.UserAgreement.belongsTo(app.model.Agreement, { foreignKey: 'agreement_id', as: 'agreement' });
app.model.UserAgreement.belongsTo(app.model.AgreementVersion, { foreignKey: 'version_id', as: 'versionInfo' });
};
return UserAgreement;
};