'use strict'; /** * 售后进度步骤表 Model,基于 `wms_after_sale_detail` 表。 * @param {import('egg').Application} app Egg 应用实例 * @return {import('sequelize').ModelCtor} 售后进度步骤 Model(含常量挂载) */ module.exports = app => { const { STRING, BIGINT, TEXT, DATE } = app.Sequelize; // ============================ // 枚举常量定义 // ============================ /** * 步骤状态枚举(与 wms_after_sale.status 一致)。 */ const STEP_STATUS = { pending: '待处理', processing: '处理中', pending_feedback: '等待外部反馈', completed: '已完成', closed: '已关闭', cancelled: '已取消', }; // ============================ // Model 定义 // ============================ const AfterSaleDetail = app.model.define('after_sale_detail', { /** 主键 */ id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键', }, /** 关联售后主表ID */ after_sale_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '关联售后主表ID(wms_after_sale.id)', }, /** 步骤记录时售后主表的状态 */ step_status: { type: STRING(20), allowNull: false, defaultValue: 'processing', comment: '步骤记录时售后主表的状态,与 wms_after_sale.status 一致: pending | processing | pending_feedback | completed | closed | cancelled', }, /** 操作人账户ID */ operator_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '操作人账户ID(关联 accounts 表);外部系统回调/自动触发的步骤可为空', }, /** 操作人信息快照 */ operator_snapshot: { type: TEXT, allowNull: true, comment: '操作人信息快照(JSON),如 {"name":"张三","role":"客服"},防止账户删除后历史丢失', }, /** 操作动作描述 */ action: { type: STRING(100), allowNull: true, comment: '操作动作描述,如"确认收货"、"审核驳回"、"发起退款"', }, /** 处理备注 */ remark: { type: TEXT, allowNull: true, comment: '处理备注', }, /** 步骤开始时间 */ started_at: { type: DATE, allowNull: true, comment: '步骤开始时间', }, /** 步骤完成时间 */ completed_at: { type: DATE, allowNull: true, comment: '步骤完成时间', }, /** 创建时间 */ created_at: { type: DATE, allowNull: true, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, /** 更新时间 */ updated_at: { type: DATE, allowNull: true, comment: '更新时间', }, /** 软删除时间 */ deleted_at: { type: DATE, allowNull: true, comment: '软删除时间', }, }, { tableName: 'wms_after_sale_detail', comment: '售后进度步骤表', timestamps: false, indexes: [ { name: 'idx_after_sale_id', fields: [ 'after_sale_id' ], }, { name: 'idx_operator_id', fields: [ 'operator_id' ], }, ], }); // ============================ // 关联关系 // ============================ AfterSaleDetail.associate = function() { const { AfterSale, AfterSaleDetail } = app.model; // 关联售后主表(多对一) AfterSaleDetail.belongsTo(AfterSale, { foreignKey: 'after_sale_id', as: 'afterSale', }); }; // ============================ // 常量挂载到 Model // ============================ AfterSaleDetail.STEP_STATUS = STEP_STATUS; return AfterSaleDetail; };