WMS_MAIN/app/model/user_oauth.js

163 lines
3.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';
/**
* 用户第三方授权表模型。
* 保存用户通过第三方厂商(微信等)OAuth 登录后的授权信息与令牌信息。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, TINYINT, DATE } = app.Sequelize;
const UserOauth = app.model.define('userOauth', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
user_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '用户ID(关联 account.id)',
},
app_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '微信应用ID(关联 wms_wechat_app.id),用于取对应应用 token 处理',
},
provider: {
type: STRING(50),
allowNull: false,
comment: '厂商,如 wechat/mini_program',
},
platform: {
type: STRING(50),
allowNull: true,
comment: '平台,如 h5/app/mp',
},
unionid: {
type: STRING(50),
allowNull: true,
comment: '厂商统一ID(同一厂商跨应用唯一,部分平台无)',
},
openid: {
type: STRING(50),
allowNull: false,
comment: '平台内唯一ID',
},
nickname: {
type: STRING(255),
allowNull: true,
comment: '昵称',
},
sex: {
type: TINYINT(1),
allowNull: false,
defaultValue: 0,
comment: '性别:0=未知,1=男,2=女',
},
country: {
type: STRING(50),
allowNull: true,
comment: '国家',
},
province: {
type: STRING(50),
allowNull: true,
comment: '省',
},
city: {
type: STRING(50),
allowNull: true,
comment: '市',
},
headimgurl: {
type: STRING(500),
allowNull: true,
comment: '头像URL',
},
login_time: {
type: INTEGER(11),
allowNull: true,
comment: '最近登录时间(unix秒级时间戳)',
},
login_count: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '累计登录次数',
},
expire_in: {
type: INTEGER(11),
allowNull: true,
comment: '令牌过期周期(秒)',
},
expire_time: {
type: INTEGER(11),
allowNull: true,
comment: '令牌过期时间(unix秒级时间戳)',
},
session_key: {
type: STRING(45),
allowNull: true,
comment: '会话密钥(微信小程序登录态)',
},
refresh_token: {
type: STRING(110),
allowNull: true,
comment: '刷新令牌',
},
access_token: {
type: STRING(110),
allowNull: true,
comment: '访问令牌',
},
login_code: {
type: STRING(128),
allowNull: true,
comment: '登录码({uuid,id_6} JSON 的 base64,一次性消费)',
},
agreement_version_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
defaultValue: null,
comment: '协议版本ID(关联 wms_wechat_agreement_version.id,loginByCode 时自动更新到最新)',
},
created_at: {
type: DATE,
comment: '创建时间',
},
updated_at: {
type: DATE,
comment: '更新时间',
},
}, {
tableName: 'wms_user_oauth',
underscored: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
comment: '用户第三方授权表',
indexes: [
{
unique: true,
fields: [ 'app_id', 'provider', 'openid' ],
name: 'uk_app_provider_openid',
},
{
unique: true,
fields: [ 'login_code' ],
name: 'uk_login_code',
},
{
fields: [ 'user_id' ],
name: 'idx_user_id',
},
],
});
return UserOauth;
};