WMS_MAIN/app/model/number_sequence.js
liufumingren 38b29be776 feat: 新增退回拆包模块(returnUnpack)与序列表原子取号
- 新增 wms_return_unpack 主表/明细/视频 与 wms_return_query_log 表(model + 迁移)
- 新增序列表 wms_number_sequence,单号取号改为 INSERT...ON DUPLICATE KEY 原子递增(含历史 seed 对齐)
- 补齐 wms_order_delivery 基表缺失 25 列(修复 Unknown column)
- 权限固定 ID 540-549 + 角色授权迁移
- 修复 returnReceived.create 出参 record 包装;修复 afterSale 发件人查询列名(name→company_name)
- detail 接口按设计走 548 权限校验
2026-08-13 21:40:50 +08:00

56 lines
1.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';
/**
* 业务单号序列表模型。
* 按「仓库 + 业务类型 + 日期」维度原子分配序号,
* 取号使用 INSERT ... ON DUPLICATE KEY UPDATE current_seq = LAST_INSERT_ID(current_seq + 1),
* 避免「查当日最大序号+1」在并发下的撞号问题。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, CHAR } = app.Sequelize;
const NumberSequence = app.model.define('wms_number_sequence', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(序号隔离维度)',
},
biz_type: {
type: STRING(30),
allowNull: false,
comment: '业务类型,如 return_unpack(退回拆包单号)',
},
date_part: {
type: CHAR(8),
allowNull: false,
comment: '日期片段 YYYYMMDD',
},
current_seq: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '当前已分配序号(原子递增)',
},
}, {
tableName: 'wms_number_sequence',
comment: '业务单号序列表(原子取号)',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{ name: 'uk_warehouse_biz_date', unique: true, fields: [ 'warehouse_id', 'biz_type', 'date_part' ] },
],
});
return NumberSequence;
};