'use strict'; /** * 微信开放平台授权小程序表模型。 * 记录仓库(主体)授权的小程序信息与令牌,供业务按小程序维度调用微信接口。 * @param {import('egg').Application} app Egg 应用实例。 * @return {import('sequelize').ModelCtor} Sequelize 模型。 */ module.exports = app => { const { BIGINT, STRING, INTEGER, TINYINT, TEXT, DATE } = app.Sequelize; const WechatApp = app.model.define('wechatApp', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '仓库ID(绑定关系,NULL=已授权待绑定仓库)', }, appid: { type: STRING(64), allowNull: false, comment: '小程序AppID', }, nickname: { type: STRING(100), allowNull: true, comment: '小程序名称', }, user_name: { type: STRING(100), allowNull: true, comment: '小程序原始ID(gh_xxx)', }, head_img: { type: STRING(500), allowNull: true, comment: '小程序头像URL', }, authorizer_refresh_token: { type: STRING(255), allowNull: true, comment: '授权方刷新令牌(长期有效,防 Redis 丢失)', }, auth_time: { type: INTEGER(11), allowNull: true, comment: '授权时间(unix秒级时间戳)', }, func_info: { type: TEXT, allowNull: true, comment: '授权权限集合(JSON 字符串,来自 api_query_auth)', }, template_id: { type: BIGINT(20).UNSIGNED, allowNull: true, defaultValue: null, comment: '当前上传的代码模板ID(wxa/commit 成功后记录)', }, user_version: { type: STRING(64), allowNull: true, defaultValue: null, comment: '当前上传的代码版本号(wxa/commit 成功后记录)', }, audit_status: { type: TINYINT(1), allowNull: false, defaultValue: 0, comment: '代码审核状态:0=未提交,1=审核中,2=审核通过,3=审核驳回', }, audit_id: { type: BIGINT(20).UNSIGNED, allowNull: true, defaultValue: null, comment: '微信审核单ID(wxa/submit_audit 返回的 auditid)', }, audit_reason: { type: STRING(500), allowNull: true, defaultValue: null, comment: '代码审核驳回原因', }, principal_name: { type: STRING(100), allowNull: true, defaultValue: null, comment: '主体名称', }, signature: { type: STRING(500), allowNull: true, defaultValue: null, comment: '小程序账号介绍', }, alias: { type: STRING(100), allowNull: true, defaultValue: null, comment: '微信号(可能为空)', }, qrcode_url: { type: STRING(500), allowNull: true, defaultValue: null, comment: '二维码图片URL', }, service_type_id: { type: TINYINT, allowNull: true, defaultValue: null, comment: '账号类型id(0 普通小程序等)', }, verify_type_id: { type: TINYINT, allowNull: true, defaultValue: null, comment: '认证类型id(-1 未认证,0 微信认证,1 新浪微博认证,3 资质通过未名称认证,4 同3+微博)', }, account_status: { type: TINYINT, allowNull: true, defaultValue: null, comment: '账号状态(1 正常,14 已注销,16 已封禁,18 已告警,19 已冻结)', }, register_type: { type: TINYINT, allowNull: true, defaultValue: null, comment: '小程序注册方式(0 普通,6 法人扫脸创建企业小程序等)', }, business_info: { type: STRING(500), allowNull: true, defaultValue: null, comment: '功能开通状况 JSON', }, mini_program_info: { type: TEXT, allowNull: true, defaultValue: null, comment: '小程序配置信息 JSON(network/categories/visit_status)', }, auth_task_id: { type: STRING(64), allowNull: true, defaultValue: null, comment: '微信认证任务ID(发起认证接口返回)', }, auth_task_status: { type: TINYINT, allowNull: true, defaultValue: null, comment: '认证任务流程状态(task_status 0-15)', }, auth_apply_status: { type: TINYINT, allowNull: true, defaultValue: null, comment: '认证审核单状态(apply_status 0-5)', }, is_enabled: { type: TINYINT(1), allowNull: false, defaultValue: 1, comment: '是否启用:1=启用,0=停用', }, created_at: { type: DATE, comment: '创建时间', }, updated_at: { type: DATE, comment: '更新时间', }, }, { tableName: 'wms_wechat_app', underscored: true, timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: false, comment: '微信开放平台授权小程序表(仓库绑定)', indexes: [ { unique: true, fields: [ 'appid' ], name: 'uk_appid', }, { fields: [ 'warehouse_id' ], name: 'idx_warehouse_id', }, ], }); return WechatApp; };