'use strict'; /** * 外部打单账号模型,对应 external_print_accounts 表。 * 一个主体在同一平台上可配置多个账号,账号密码供服务端调用外部打单平台使用; * 密码不通过接口下发(列表/详情只返回 has_password),避免泄露。 * @param {Egg.Application} app egg application * @return {object} externalPrintAccount model */ module.exports = app => { const { BIGINT, STRING, TEXT, TINYINT, DATE } = app.Sequelize; const ExternalPrintAccount = app.model.define('external_print_account', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, platform_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属外部打单平台ID' }, account: { type: STRING(100), allowNull: false, comment: '外部打单平台登录账号' }, password: { type: STRING(255), allowNull: false, comment: '外部打单平台登录密码(服务端调用平台时使用,接口不回显)' }, cookie: { type: TEXT, comment: '外部打单平台会话 cookie(服务端登录后写回,接口不回显)' }, token: { type: STRING(255), comment: '外部打单平台登录 Token(服务端登录后写回,接口不回显)' }, login_status: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '登录状态:1已登录 0未登录/已失效' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }); ExternalPrintAccount.associate = () => { app.model.ExternalPrintAccount.belongsTo(app.model.ExternalPrintPlatform, { foreignKey: 'platform_id', as: 'platform' }); app.model.ExternalPrintAccount.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' }); app.model.ExternalPrintAccount.hasMany(app.model.ExternalPrintExpressInterface, { foreignKey: 'account_id', as: 'expressInterfaces', }); }; return ExternalPrintAccount; };