WMS_MAIN/app/model/after_sale_detail.js
liufumingren 296536c83e feat: 售后模块V2全面落地
数据库:

- 创建 wms_after_sale 主表 (36字段/16索引)

- 创建 wms_after_sale_detail 步骤表 (11字段/3索引)

- 插入售后权限 16条 (ID 508-523)

- 绑定6个角色权限 (客服/仓库/生产主管/拣货组长)

代码:

- Model: after_sale.js + after_sale_detail.js (含常量枚举)

- Service: systemMethods/afterSale.js + systems/afterSale.js (19方法)

文档:

- API定义: methods/system.json (+9 methods)

- 设计文档: database/designs/after-sale-v2-design.md

- 开发/生产环境均已执行迁移,权限ID完全一致
2026-08-09 21:17:34 +08:00

144 lines
3.6 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';
/**
* 售后进度步骤表 Model,基于 `wms_after_sale_detail` 表。
* @param {import('egg').Application} app Egg 应用实例
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} 售后进度步骤 Model(含常量挂载)
*/
module.exports = app => {
const { STRING, BIGINT, TEXT, TINYINT, DATE } = app.Sequelize;
// ============================
// 枚举常量定义
// ============================
/**
* 步骤状态枚举。
* @type {{0: string, 1: string, 2: string, 3: string}}
*/
const STEP_STATUS = {
0: '待开始',
1: '进行中',
2: '已完成',
3: '已跳过',
};
// ============================
// 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: TINYINT(3).UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '步骤状态:0=待开始,1=进行中,2=已完成,3=已跳过',
},
/** 操作人账户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;
};