'use strict'; /** * 操作日志模型,对应 operation_logs 表。 * * 三类对象(店铺商品 / 系统商品 / 组合商品)共用一张日志表, * 通过 target_type + target_id 定位,页面按对象查历史操作记录。 * @param {Egg.Application} app egg application * @return {object} operationLog model */ module.exports = app => { const { BIGINT, STRING, JSON: JsonType, DATE } = app.Sequelize; const OperationLog = app.model.define('operation_log', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, target_type: { type: STRING(32), allowNull: false, comment: '对象类型:shop_product / product / combo_product' }, target_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '对象ID' }, action: { type: STRING(32), allowNull: false, comment: '动作码:create / update / bind / unbind / remove / offline / delete' }, title: { type: STRING(255), allowNull: false, comment: '操作说明' }, detail: { type: JsonType, comment: '操作明细(前后值等)' }, source: { type: STRING(20), allowNull: false, defaultValue: 'ui', comment: '来源:ui / sync / system' }, operator_id: { type: BIGINT.UNSIGNED, comment: '操作人用户ID' }, operator_name: { type: STRING(50), comment: '操作人名称' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }); OperationLog.associate = () => { app.model.OperationLog.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' }); }; return OperationLog; };