packServer/backend/app/model/wechat_oauth.js
liufumingren bd2363bf00 chore: 初始化仓库(backend / frontend / extension 三块)
- backend/:Egg 3 纯 JSON 接口服务(MySQL 8 + Redis),全部走 header 令牌鉴权;
  已彻底去掉服务端渲染(删除 page 控制器 / app/view / nunjucks / session / CSRF),
  开发时把页面请求反代到前端 dev server,生产托管 frontend/dist(SPA 回退)。
  单测 91 个通过(不需要本机数据库)。
- frontend/:Vite + Vue3 + TypeScript 的 SPA(登录 / 注册 / 找回密码 / 扫码登录与确认 /
  首页统计 / 设备管理 / 扫码记录 / 个人中心 / 测试页),vue-tsc 类型检查与构建通过。
- extension/:MV3 浏览器扩展(零构建),注入第三方 WMS 页面识别运单号并打开溯源页。
- 忽略规则统一放根 .gitignore:node_modules、dist、logs / logs-*、run、typings、
  .env*、config.local.js(含本机数据库与 Redis 密码,绝不入库)。
2026-10-17 08:50:32 +08:00

41 lines
1.9 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';
/**
* 微信授权表模型(wechat_oauth)
*
* 一条记录 = 某个用户在某个 appid 下的一次微信授权,
* 因此一个用户可绑定多个微信(公众号 / 小程序 / 开放平台)。
* 关联:WechatOauth.belongsTo(User, { as: 'user' }),
* 可通过 { include: [{ model: app.model.User, as: 'user' }] } 取出对应用户。
*/
module.exports = (app) => {
const { BIGINT, STRING, DATE } = app.Sequelize;
const WechatOauth = app.model.define('wechatOauth', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
// 下划线映射由 config.sequelize.define.underscored 统一处理(userId -> user_id)
userId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '关联 users.id' },
appid: { type: STRING(64), allowNull: false, comment: '微信 appid' },
openid: { type: STRING(64), allowNull: false, comment: '用户在该 appid 下的 openid' },
unionid: { type: STRING(64), comment: '开放平台 unionid' },
nickname: { type: STRING(64), allowNull: false, defaultValue: '', comment: '授权时微信昵称' },
avatar: { type: STRING(255), allowNull: false, defaultValue: '', comment: '授权时微信头像' },
sessionKey: { type: STRING(128), comment: '小程序 session_key' },
accessToken: { type: STRING(512), comment: '网页授权 access_token' },
refreshToken: { type: STRING(512), comment: '刷新令牌' },
scope: { type: STRING(64), comment: '授权 scope' },
tokenExpiresAt: { type: DATE, comment: 'access_token 过期时间' },
lastAuthAt: { type: DATE, comment: '最近授权时间' },
}, {
tableName: 'wechat_oauth',
paranoid: true,
comment: '微信授权表',
});
WechatOauth.associate = function() {
app.model.WechatOauth.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
};
return WechatOauth;
};