'use strict'; /** * 微信绑定模型,对应 user_wechat_binds 表。 * 一个微信身份(openid)只绑定一个系统账号;一个系统账号只保留最近一次绑定的微信。 * 网关侧的 openid 只在服务端保存,前端只展示脱敏值。 * @param {Egg.Application} app egg application * @return {object} user_wechat_bind model */ module.exports = app => { const { BIGINT, STRING, DATE } = app.Sequelize; const UserWechatBind = app.model.define('user_wechat_bind', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, user_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '系统用户ID' }, app_key: { type: STRING(64), comment: '所属网关应用 appKey(区分开发/生产环境)' }, gateway_uid: { type: BIGINT.UNSIGNED, comment: '网关用户ID(通知里的 userId)' }, openid: { type: STRING(64), allowNull: false, comment: '公众号 openid,全局唯一' }, unionid: { type: STRING(64), comment: '开放平台 unionid(公众号已绑定开放平台时才有)' }, bind_scene: { type: STRING(16), allowNull: false, defaultValue: 'bind', comment: '绑定来源:bind 主动绑定 / login 扫码登录自动绑定' }, last_login_at: { type: DATE, comment: '最近一次微信登录时间' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }); UserWechatBind.associate = () => { app.model.UserWechatBind.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' }); }; return UserWechatBind; };