This commit is contained in:
liufumingren 2026-05-16 23:00:49 +08:00
parent 9845a239e2
commit adb1a16599
16 changed files with 886 additions and 113 deletions

View File

@ -128,6 +128,17 @@ module.exports = app => {
allowNull: true,
comment: '寄件人街道',
},
ispickup: {
type: TINYINT(1),
allowNull: true,
defaultValue: 0,
comment: '是否上门取件',
},
shipperno: {
type: STRING(255),
allowNull: true,
comment: '寄件网点编码',
},
}, {
tableName: 'wms_express_interface',
freezeTableName: true,
@ -146,14 +157,14 @@ module.exports = app => {
/**
* 定义快递接口与系统快递的关联关系。
*
* 说明:`wms_express_interface.express_code` 对应 `wms_express.code`。
* 说明:`wms_express_interface.sys_express_code` 对应 `wms_express.code`。
*/
ExpressInterface.associate = function() {
const { Express } = app.model;
if (Express && typeof ExpressInterface.belongsTo === 'function') {
ExpressInterface.belongsTo(Express, {
foreignKey: 'express_code',
foreignKey: 'sys_express_code',
targetKey: 'code',
as: 'express',
constraints: false,

View File

@ -0,0 +1,154 @@
'use strict';
/**
* 库位维度出入库流水模型。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { STRING, INTEGER, BIGINT, ENUM, DATE, TEXT } = app.Sequelize;
const StorageTransaction = app.model.define('storage_transaction', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
transaction_type: {
type: ENUM('INBOUND', 'OUTBOUND', 'TRANSFER_OUT', 'TRANSFER_IN'),
allowNull: false,
comment: '出入库类型',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '货主ID',
},
stock_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '商品库存ID,关联 wms_stock_warehouse.id',
},
storage_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位库存ID,关联 wms_storage.id',
},
space_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位ID',
},
quantity: {
type: INTEGER(12),
allowNull: false,
comment: '变动数量(正数)',
},
before_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更前总库存数量',
},
after_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更后总库存数量',
},
before_locked_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更前锁定数量',
},
after_locked_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更后锁定数量',
},
batch_no: {
type: STRING(100),
allowNull: true,
comment: '批次号',
},
inventory_type: {
type: ENUM('ZP', 'CC', 'JS', 'XS', 'ZT', 'DJ', 'FP'),
defaultValue: 'ZP',
comment: '库存类型',
},
order_type: {
type: STRING(50),
allowNull: true,
comment: '关联单据类型',
},
order_no: {
type: TEXT,
allowNull: true,
comment: '关联单据号',
},
order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '关联单据ID',
},
source_order_codes: {
type: TEXT,
allowNull: true,
comment: '来源订单号集合',
},
operator_id: {
type: STRING(100),
allowNull: true,
comment: '操作人ID',
},
operator_name: {
type: STRING(100),
allowNull: true,
comment: '操作人名称',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
}, {
tableName: 'wms_storage_transaction',
freezeTableName: true,
timestamps: false,
comment: '库位维度出入库流水记录表',
indexes: [
{
name: 'idx_storage_id',
fields: [ 'storage_id' ],
},
{
name: 'idx_stock_id',
fields: [ 'stock_id' ],
},
{
name: 'idx_warehouse_time',
fields: [ 'warehouse_id', 'created_at' ],
},
{
name: 'idx_order',
fields: [ 'order_type', 'order_id' ],
},
{
name: 'idx_created_at',
fields: [ 'created_at' ],
},
],
});
return StorageTransaction;
};

View File

@ -5,6 +5,7 @@ const OrderBaseService = require('./base');
const PENDING_OUTBOUND_STATUS = 'padding';
const PENDING_CANCEL_STATUS = 'cancel';
const PENDING_CANCEL_STEP = 9;
const PENDING_OUTBOUND_STEP = 4;
const PENDING_CANCEL_ALLOWED_STEPS = new Set([ 0, 1, 2, 3 ]);
const PENDING_CANCEL_PENDING_STEPS = new Set([ 1, 2 ]);
const ALLOCATE_STORAGE_TASK_CACHE_KEY_PREFIX = 'order:pending:allocate_storage:request:';
@ -828,6 +829,7 @@ class PendingOrderService extends OrderBaseService {
const now = new Date();
const updateValues = {
outbound_status: PENDING_OUTBOUND_STATUS,
step: PENDING_OUTBOUND_STEP,
updated_at: now,
};

View File

@ -140,9 +140,19 @@ class expressInterfaceService extends MainService {
name,
express_code: expressCode,
expressCode: camelExpressCode,
sys_express_code: sysExpressCode,
sysExpressCode: camelSysExpressCode,
platform_code: platformCode,
platformCode: camelPlatformCode,
expressPlatformId: camelExpressPlatformId,
weight_type: weightType,
weightType: camelWeightType,
address,
town_name: townName,
townName: camelTownName,
ispickup: isPickup,
isPickup: camelIsPickup,
shipperno: shipperNo,
shipperNo: camelShipperNo,
...rest
} = data || {};
@ -159,6 +169,24 @@ class expressInterfaceService extends MainService {
if (platformCode !== undefined || camelPlatformCode !== undefined) {
payload.platform_code = platformCode !== undefined ? platformCode : camelPlatformCode;
}
if (sysExpressCode !== undefined || camelSysExpressCode !== undefined) {
payload.sys_express_code = sysExpressCode !== undefined ? sysExpressCode : camelSysExpressCode;
}
if (weightType !== undefined || camelWeightType !== undefined) {
payload.weight_type = weightType !== undefined ? weightType : camelWeightType;
}
if (address !== undefined) {
payload.address = address;
}
if (townName !== undefined || camelTownName !== undefined) {
payload.town_name = townName !== undefined ? townName : camelTownName;
}
if (isPickup !== undefined || camelIsPickup !== undefined) {
payload.ispickup = isPickup !== undefined ? isPickup : camelIsPickup;
}
if (shipperNo !== undefined || camelShipperNo !== undefined) {
payload.shipperno = shipperNo !== undefined ? shipperNo : camelShipperNo;
}
return await this.callSystemExpressInterface('create', payload, '创建快递接口失败');
}
@ -177,9 +205,19 @@ class expressInterfaceService extends MainService {
name,
express_code: expressCode,
expressCode: camelExpressCode,
sys_express_code: sysExpressCode,
sysExpressCode: camelSysExpressCode,
platform_code: platformCode,
platformCode: camelPlatformCode,
expressPlatformId: camelExpressPlatformId,
weight_type: weightType,
weightType: camelWeightType,
address,
town_name: townName,
townName: camelTownName,
ispickup: isPickup,
isPickup: camelIsPickup,
shipperno: shipperNo,
shipperNo: camelShipperNo,
...rest
} = data || {};
@ -197,6 +235,24 @@ class expressInterfaceService extends MainService {
if (platformCode !== undefined || camelPlatformCode !== undefined) {
payload.platform_code = platformCode !== undefined ? platformCode : camelPlatformCode;
}
if (sysExpressCode !== undefined || camelSysExpressCode !== undefined) {
payload.sys_express_code = sysExpressCode !== undefined ? sysExpressCode : camelSysExpressCode;
}
if (weightType !== undefined || camelWeightType !== undefined) {
payload.weight_type = weightType !== undefined ? weightType : camelWeightType;
}
if (address !== undefined) {
payload.address = address;
}
if (townName !== undefined || camelTownName !== undefined) {
payload.town_name = townName !== undefined ? townName : camelTownName;
}
if (isPickup !== undefined || camelIsPickup !== undefined) {
payload.ispickup = isPickup !== undefined ? isPickup : camelIsPickup;
}
if (shipperNo !== undefined || camelShipperNo !== undefined) {
payload.shipperno = shipperNo !== undefined ? shipperNo : camelShipperNo;
}
return await this.callSystemExpressInterface('update', payload, '更新快递接口失败');
}

View File

@ -1939,7 +1939,7 @@ class UserService extends Service {
await this.app.setCacheAsync(cacheKey, null, 1);
} else {
// 清除用户所有平台的缓存
const platforms = [ 'web', 'pda', 'mini', 'app' ];
const platforms = [ 'web', 'pda', 'mini', 'app', 'workerstation', 'workstation' ];
for (const platform of platforms) {
const cacheKey = `user:info:${userId}:${platform}`;
await this.app.setCacheAsync(cacheKey, null, 1);

View File

@ -265,7 +265,6 @@ class OrderDeliveryMigrationService extends MainService {
const { Op } = this.ctx.app.Sequelize;
const updateValues = {
outbound_status: OUTBOUND_STATUS_TIMEOUT,
step: OUTBOUND_STEP,
updated_at: new Date(),
};
const updateResult = await sourceOrderModel.update(updateValues, {

View File

@ -236,6 +236,9 @@ class SettingExpressInterfaceService extends Service {
express_code: {
field: 'express_code',
},
sys_express_code: {
field: 'sys_express_code',
},
platform_code: {
field: 'platform_code',
},
@ -378,11 +381,100 @@ class SettingExpressInterfaceService extends Service {
return {
code: this.normalizeOptionalText(row.code, 'express.code', 50),
name: this.normalizeOptionalText(row.name, 'express.name', 255),
polyapi_code: this.normalizeOptionalText(row.polyapi_code, 'express.polyapi_code', 255),
polyapi_extra_info: row.polyapi_extra_info === undefined ? null : row.polyapi_extra_info,
pdd_code: this.normalizeOptionalText(row.pdd_code, 'express.pdd_code', 255),
pdd_code: this.normalizeOptionalText(row.PDD !== undefined ? row.PDD : row.pdd_code, 'express.pdd_code', 255),
ks_code: this.normalizeOptionalText(row.KS !== undefined ? row.KS : row.ks_code, 'express.ks_code', 255),
dyxd_code: this.normalizeOptionalText(row.DYXD !== undefined ? row.DYXD : row.dyxd_code, 'express.dyxd_code', 255),
};
}
/**
* 获取平台自建快递编码字段名。
*
* @param {string} platformCode 平台编码
* @return {string|null} 平台字段名
*/
getPlatformExpressColumn(platformCode) {
const normalizedPlatformCode = this.normalizePlatformCode(platformCode, 'platform_code', 20);
const fieldMap = {
KS: 'KS',
KSAPP: 'KS',
PDD: 'PDD',
DYXD: 'DYXD',
DY: 'DYXD',
DOUYIN: 'DYXD',
};
return fieldMap[normalizedPlatformCode] || null;
}
/**
* 校验系统快递编码是否存在。
*
* @param {string} sysExpressCode 系统快递编码
* @return {Promise<string>} 系统快递编码
*/
async ensureSystemExpressCodeExists(sysExpressCode) {
const normalizedSysExpressCode = this.normalizeText(sysExpressCode, 'sys_express_code', 50).toUpperCase();
const express = await this.ctx.model.Express.findOne({
where: {
code: normalizedSysExpressCode,
},
attributes: [ 'code' ],
});
if (!express) {
throw this.createError('sys_express_code 未匹配到系统快递编码', 400);
}
return normalizedSysExpressCode;
}
/**
* 根据外部快递编码解析系统快递编码。
*
* @param {Object} data 输入参数
* @param {string} data.expressCode 外部快递编码
* @param {string} data.platformCode 平台编码
* @param {string} [data.sysExpressCode] 显式系统快递编码
* @return {Promise<string>} 系统快递编码
*/
async resolveSysExpressCode(data = {}) {
const expressCode = this.normalizeText(data.expressCode, 'express_code', 255).toUpperCase();
const platformCode = this.normalizePlatformCode(data.platformCode, 'platform_code', 20);
const inputSysExpressCode = data.sysExpressCode;
if (inputSysExpressCode !== undefined && inputSysExpressCode !== null && String(inputSysExpressCode).trim() !== '') {
return await this.ensureSystemExpressCodeExists(inputSysExpressCode);
}
const matchedBySystemCode = await this.ctx.model.Express.findOne({
where: {
code: expressCode,
},
attributes: [ 'code' ],
});
if (matchedBySystemCode) {
return this.normalizeText(matchedBySystemCode.code, 'sys_express_code', 50).toUpperCase();
}
const platformColumn = this.getPlatformExpressColumn(platformCode);
if (platformColumn) {
const matchedByPlatformCode = await this.ctx.model.Express.findOne({
where: {
[platformColumn]: expressCode,
},
attributes: [ 'code' ],
});
if (matchedByPlatformCode) {
return this.normalizeText(matchedByPlatformCode.code, 'sys_express_code', 50).toUpperCase();
}
}
throw this.createError('express_code 未匹配到系统快递编码', 400);
}
/**
* 规范化快递接口记录。
*
@ -400,20 +492,26 @@ class SettingExpressInterfaceService extends Service {
id: row.id === undefined || row.id === null ? null : Number(row.id),
name: this.normalizeOptionalText(row.name, 'name', 255),
express_code: this.normalizeOptionalText(row.express_code, 'express_code', 255),
sys_express_code: this.normalizeOptionalText(row.sys_express_code, 'sys_express_code', 50),
warehouse_id: row.warehouse_id === undefined || row.warehouse_id === null ? null : Number(row.warehouse_id),
platform_code: this.normalizeOptionalText(row.platform_code, 'platform_code', 20),
sender_name: this.normalizeOptionalText(row.sender_name, 'sender_name', 50),
sender_tel: this.normalizeOptionalText(row.sender_tel, 'sender_tel', 11),
weight: row.weight === undefined || row.weight === null ? null : Number(row.weight),
weight_type: row.weight_type === undefined || row.weight_type === null ? null : Number(row.weight_type),
token: this.normalizeOptionalText(row.token, 'token', 500),
viewer: this.normalizeOptionalText(row.viewer, 'viewer', 50),
client_id: this.normalizeOptionalText(row.client_id, 'client_id', 50),
is_share: row.is_share === undefined || row.is_share === null ? null : Number(row.is_share),
ispickup: row.ispickup === undefined || row.ispickup === null ? null : Number(row.ispickup),
share_id: row.share_id === undefined || row.share_id === null ? null : Number(row.share_id),
shipperno: this.normalizeOptionalText(row.shipperno, 'shipperno', 255),
can_use_count: row.can_use_count === undefined || row.can_use_count === null ? null : Number(row.can_use_count),
province_name: this.normalizeOptionalText(row.province_name, 'province_name', 255),
city_name: this.normalizeOptionalText(row.city_name, 'city_name', 255),
district_name: this.normalizeOptionalText(row.district_name, 'district_name', 255),
address: this.normalizeOptionalText(row.address, 'address', 255),
town_name: this.normalizeOptionalText(row.town_name, 'town_name', 255),
site_code: this.normalizeOptionalText(row.site_code, 'site_code', 255),
product_type: this.normalizeOptionalText(row.product_type, 'product_type', 50),
shop_name: this.normalizeOptionalText(row.shop_name, 'shop_name', 255),
@ -695,9 +793,10 @@ class SettingExpressInterfaceService extends Service {
include: this.getInterfaceInclude(),
attributes: [
'id', 'name', 'express_code', 'warehouse_id', 'platform_code',
'sys_express_code',
'sender_name', 'sender_tel', 'weight', 'token', 'viewer', 'client_id', 'is_share',
'share_id', 'can_use_count', 'province_name', 'city_name', 'district_name', 'site_code',
'product_type', 'shop_name',
'product_type', 'weight_type', 'shop_name', 'address', 'town_name', 'ispickup', 'shipperno',
],
order: [[ 'id', 'DESC' ]],
offset,
@ -812,27 +911,37 @@ class SettingExpressInterfaceService extends Service {
if (!platformCode) {
throw this.createError('platform_code 参数不能为空', 400);
}
await this.ensureCodeAvailable(expressCode);
await this.ensureInterfaceAvailable(platformCode);
const sysExpressCode = await this.resolveSysExpressCode({
expressCode,
platformCode,
sysExpressCode: data.sys_express_code !== undefined ? data.sys_express_code : data.sysExpressCode,
});
const payload = {
warehouse_id: currentStoreId,
name,
express_code: expressCode,
platform_code: platformCode,
sys_express_code: sysExpressCode,
sender_name: this.normalizeOptionalText(data.sender_name || data.senderName, 'sender_name', 50),
sender_tel: this.normalizeOptionalText(data.sender_tel || data.senderTel, 'sender_tel', 11),
weight: this.normalizeInteger(data.weight, 'weight', {
allowEmpty: true,
}),
weight_type: this.normalizeInteger(data.weight_type !== undefined ? data.weight_type : data.weightType, 'weight_type', {
allowEmpty: true,
}),
token: this.normalizeOptionalText(data.token, 'token', 500),
viewer: this.normalizeOptionalText(data.viewer, 'viewer', 50),
client_id: this.normalizeOptionalText(data.client_id || data.clientId, 'client_id', 50),
is_share: this.normalizeFlag(data.is_share !== undefined ? data.is_share : data.isShare, 'is_share', 0),
ispickup: this.normalizeFlag(data.ispickup !== undefined ? data.ispickup : data.isPickup, 'ispickup', 0),
share_id: this.normalizeInteger(data.share_id || data.shareId, 'share_id', {
allowEmpty: true,
min: 1,
}),
shipperno: this.normalizeOptionalText(data.shipperno !== undefined ? data.shipperno : data.shipperNo, 'shipperno', 255),
can_use_count: this.normalizeInteger(data.can_use_count !== undefined ? data.can_use_count : data.canUseCount, 'can_use_count', {
allowEmpty: true,
min: 0,
@ -840,6 +949,8 @@ class SettingExpressInterfaceService extends Service {
province_name: this.normalizeOptionalText(data.province_name || data.provinceName, 'province_name', 255),
city_name: this.normalizeOptionalText(data.city_name || data.cityName, 'city_name', 255),
district_name: this.normalizeOptionalText(data.district_name || data.districtName, 'district_name', 255),
address: this.normalizeOptionalText(data.address, 'address', 255),
town_name: this.normalizeOptionalText(data.town_name || data.townName, 'town_name', 255),
site_code: this.normalizeOptionalText(data.site_code || data.siteCode, 'site_code', 255),
product_type: this.normalizeOptionalText(data.product_type || data.productType, 'product_type', 50),
shop_name: this.normalizeOptionalText(data.shop_name || data.shopName, 'shop_name', 255),
@ -880,11 +991,15 @@ class SettingExpressInterfaceService extends Service {
|| Object.prototype.hasOwnProperty.call(data, 'expressCode');
const hasPlatformCode = Object.prototype.hasOwnProperty.call(data, 'platform_code')
|| Object.prototype.hasOwnProperty.call(data, 'platformCode');
const hasSysExpressCode = Object.prototype.hasOwnProperty.call(data, 'sys_express_code')
|| Object.prototype.hasOwnProperty.call(data, 'sysExpressCode');
const hasSenderName = Object.prototype.hasOwnProperty.call(data, 'sender_name')
|| Object.prototype.hasOwnProperty.call(data, 'senderName');
const hasSenderTel = Object.prototype.hasOwnProperty.call(data, 'sender_tel')
|| Object.prototype.hasOwnProperty.call(data, 'senderTel');
const hasWeight = Object.prototype.hasOwnProperty.call(data, 'weight');
const hasWeightType = Object.prototype.hasOwnProperty.call(data, 'weight_type')
|| Object.prototype.hasOwnProperty.call(data, 'weightType');
const hasToken = Object.prototype.hasOwnProperty.call(data, 'token');
const hasViewer = Object.prototype.hasOwnProperty.call(data, 'viewer');
const hasClientId = Object.prototype.hasOwnProperty.call(data, 'client_id')
@ -893,6 +1008,10 @@ class SettingExpressInterfaceService extends Service {
|| Object.prototype.hasOwnProperty.call(data, 'isShare');
const hasShareId = Object.prototype.hasOwnProperty.call(data, 'share_id')
|| Object.prototype.hasOwnProperty.call(data, 'shareId');
const hasIsPickup = Object.prototype.hasOwnProperty.call(data, 'ispickup')
|| Object.prototype.hasOwnProperty.call(data, 'isPickup');
const hasShipperNo = Object.prototype.hasOwnProperty.call(data, 'shipperno')
|| Object.prototype.hasOwnProperty.call(data, 'shipperNo');
const hasCanUseCount = Object.prototype.hasOwnProperty.call(data, 'can_use_count')
|| Object.prototype.hasOwnProperty.call(data, 'canUseCount');
const hasProvinceName = Object.prototype.hasOwnProperty.call(data, 'province_name')
@ -901,6 +1020,9 @@ class SettingExpressInterfaceService extends Service {
|| Object.prototype.hasOwnProperty.call(data, 'cityName');
const hasDistrictName = Object.prototype.hasOwnProperty.call(data, 'district_name')
|| Object.prototype.hasOwnProperty.call(data, 'districtName');
const hasAddress = Object.prototype.hasOwnProperty.call(data, 'address');
const hasTownName = Object.prototype.hasOwnProperty.call(data, 'town_name')
|| Object.prototype.hasOwnProperty.call(data, 'townName');
const hasSiteCode = Object.prototype.hasOwnProperty.call(data, 'site_code')
|| Object.prototype.hasOwnProperty.call(data, 'siteCode');
const hasProductType = Object.prototype.hasOwnProperty.call(data, 'product_type')
@ -908,10 +1030,12 @@ class SettingExpressInterfaceService extends Service {
const hasShopName = Object.prototype.hasOwnProperty.call(data, 'shop_name')
|| Object.prototype.hasOwnProperty.call(data, 'shopName');
if (!hasName && !hasExpressCode && !hasPlatformCode && !hasSenderName
&& !hasSenderTel && !hasWeight && !hasToken && !hasViewer && !hasClientId && !hasIsShare
&& !hasShareId && !hasCanUseCount && !hasProvinceName && !hasCityName && !hasDistrictName
&& !hasSiteCode && !hasProductType && !hasShopName) {
if (!hasName && !hasExpressCode && !hasPlatformCode && !hasSysExpressCode
&& !hasSenderName && !hasSenderTel && !hasWeight && !hasWeightType && !hasToken
&& !hasViewer && !hasClientId && !hasIsShare && !hasShareId && !hasIsPickup
&& !hasShipperNo && !hasCanUseCount && !hasProvinceName && !hasCityName
&& !hasDistrictName && !hasAddress && !hasTownName && !hasSiteCode
&& !hasProductType && !hasShopName) {
throw this.createError('至少需要提供一个可更新字段', 400);
}
@ -959,6 +1083,12 @@ class SettingExpressInterfaceService extends Service {
});
}
if (hasWeightType) {
updates.weight_type = this.normalizeInteger(data.weight_type !== undefined ? data.weight_type : data.weightType, 'weight_type', {
allowEmpty: true,
});
}
if (hasToken) {
updates.token = this.normalizeOptionalText(data.token, 'token', 500);
}
@ -982,6 +1112,14 @@ class SettingExpressInterfaceService extends Service {
});
}
if (hasIsPickup) {
updates.ispickup = this.normalizeFlag(data.ispickup !== undefined ? data.ispickup : data.isPickup, 'ispickup', 0);
}
if (hasShipperNo) {
updates.shipperno = this.normalizeOptionalText(data.shipperno !== undefined ? data.shipperno : data.shipperNo, 'shipperno', 255);
}
if (hasCanUseCount) {
updates.can_use_count = this.normalizeInteger(data.can_use_count !== undefined ? data.can_use_count : data.canUseCount, 'can_use_count', {
allowEmpty: true,
@ -1001,6 +1139,14 @@ class SettingExpressInterfaceService extends Service {
updates.district_name = this.normalizeOptionalText(data.district_name || data.districtName, 'district_name', 255);
}
if (hasAddress) {
updates.address = this.normalizeOptionalText(data.address, 'address', 255);
}
if (hasTownName) {
updates.town_name = this.normalizeOptionalText(data.town_name || data.townName, 'town_name', 255);
}
if (hasSiteCode) {
updates.site_code = this.normalizeOptionalText(data.site_code || data.siteCode, 'site_code', 255);
}
@ -1013,8 +1159,14 @@ class SettingExpressInterfaceService extends Service {
updates.shop_name = this.normalizeOptionalText(data.shop_name || data.shopName, 'shop_name', 255);
}
if (Object.prototype.hasOwnProperty.call(updates, 'express_code')) {
await this.ensureCodeAvailable(nextExpressCode, id);
if (hasExpressCode || hasPlatformCode || hasSysExpressCode) {
updates.sys_express_code = await this.resolveSysExpressCode({
expressCode: nextExpressCode,
platformCode: nextPlatformCode,
sysExpressCode: hasSysExpressCode
? (data.sys_express_code !== undefined ? data.sys_express_code : data.sysExpressCode)
: undefined,
});
}
const previousWarehouseId = Number(setting.warehouse_id || this.getCurrentStoreId());

View File

@ -780,6 +780,32 @@ class stockStoreService extends Service {
transaction: currentTransaction,
});
await ctx.model.StorageTransaction.create({
transaction_type: 'INBOUND',
warehouse_id: updatedRecord.warehouse_id || ctx.user.store_id,
store_id: ctx.user.store_id,
stock_id: storage.id,
storage_id: null,
space_id: null,
quantity: inboundQty,
before_quantity: beforeQuantity,
after_quantity: afterQuantity,
before_locked_quantity: beforeLockedQuantity,
after_locked_quantity: afterLockedQuantity,
batch_no: null,
inventory_type: 'ZP',
order_type: 'STOCK_STORE_INBOUND',
order_no: null,
order_id: null,
source_order_codes: null,
operator_id: String(ctx.user?.employees_id || ctx.user?.id || ''),
operator_name: ctx.user?.employees_name || '',
remark: '商品入库',
created_at: new Date(),
}, {
transaction: currentTransaction,
});
app.logger.info('[入库] 更新现有库存', {
itemId,
stockId: storage.id,

View File

@ -58,4 +58,4 @@ module.exports = {
comment: '关联单据号',
});
},
};
};

View File

@ -0,0 +1,187 @@
'use strict';
/**
* 获取当前数据库已存在的表名集合。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<Set<string>>} 表名集合。
*/
const getExistingTableSet = async queryInterface => {
const tables = await queryInterface.showAllTables();
return new Set(
tables.map(table => (typeof table === 'string' ? table : table.tableName))
);
};
/**
* 创建库位维度出入库流水表。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 实例。
* @return {Promise<void>} 无返回值。
*/
const createStorageTransactionTable = async (queryInterface, Sequelize) => {
await queryInterface.createTable('wms_storage_transaction', {
id: {
type: Sequelize.BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
transaction_type: {
type: Sequelize.ENUM('INBOUND', 'OUTBOUND', 'TRANSFER_OUT', 'TRANSFER_IN'),
allowNull: false,
comment: '出入库类型',
},
warehouse_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
store_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: false,
comment: '货主ID',
},
stock_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: false,
comment: '商品库存ID,关联 wms_stock_warehouse.id',
},
storage_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位库存ID,关联 wms_storage.id',
},
space_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位ID',
},
quantity: {
type: Sequelize.INTEGER(12),
allowNull: false,
comment: '变动数量(正数)',
},
before_quantity: {
type: Sequelize.INTEGER(12),
allowNull: true,
comment: '变更前总库存数量',
},
after_quantity: {
type: Sequelize.INTEGER(12),
allowNull: true,
comment: '变更后总库存数量',
},
before_locked_quantity: {
type: Sequelize.INTEGER(12),
allowNull: true,
comment: '变更前锁定数量',
},
after_locked_quantity: {
type: Sequelize.INTEGER(12),
allowNull: true,
comment: '变更后锁定数量',
},
batch_no: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '批次号',
},
inventory_type: {
type: Sequelize.ENUM('ZP', 'CC', 'JS', 'XS', 'ZT', 'DJ', 'FP'),
allowNull: true,
defaultValue: 'ZP',
comment: '库存类型',
},
order_type: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '关联单据类型',
},
order_no: {
type: Sequelize.TEXT,
allowNull: true,
comment: '关联单据号',
},
order_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: true,
comment: '关联单据ID',
},
source_order_codes: {
type: Sequelize.TEXT,
allowNull: true,
comment: '来源订单号集合',
},
operator_id: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '操作人ID',
},
operator_name: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '操作人名称',
},
remark: {
type: Sequelize.STRING(500),
allowNull: true,
comment: '备注',
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
}, {
charset: 'utf8mb4',
collate: 'utf8mb4_general_ci',
comment: '库位维度出入库流水记录表',
});
await queryInterface.addIndex('wms_storage_transaction', [ 'storage_id' ], {
name: 'idx_storage_id',
});
await queryInterface.addIndex('wms_storage_transaction', [ 'stock_id' ], {
name: 'idx_stock_id',
});
await queryInterface.addIndex('wms_storage_transaction', [ 'warehouse_id', 'created_at' ], {
name: 'idx_warehouse_time',
});
await queryInterface.addIndex('wms_storage_transaction', [ 'order_type', 'order_id' ], {
name: 'idx_order',
});
await queryInterface.addIndex('wms_storage_transaction', [ 'created_at' ], {
name: 'idx_created_at',
});
};
/**
* 新增库位维度出入库流水表。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 实例。
* @return {Promise<void>} 无返回值。
*/
module.exports.up = async (queryInterface, Sequelize) => {
const tableSet = await getExistingTableSet(queryInterface);
if (tableSet.has('wms_storage_transaction')) {
return;
}
await createStorageTransactionTable(queryInterface, Sequelize);
};
/**
* 回滚删除库位维度出入库流水表。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
module.exports.down = async queryInterface => {
const tableSet = await getExistingTableSet(queryInterface);
if (!tableSet.has('wms_storage_transaction')) {
return;
}
await queryInterface.dropTable('wms_storage_transaction');
};

View File

@ -1,4 +1,16 @@
[
{
"version": "2026.05.16-system-01",
"date": "2026-05-16",
"summary": "同步 setting.expressInterface.create 文档入参:移除未使用的 express_platform_id,标注必填字段",
"methods": [
"setting.expressInterface.create"
],
"notes": [
"移除文档中 express_platform_id(服务端实现未使用);确认必填字段 name/express_code/platform_code;仓库由系统自动填充,禁止传入 warehouse_id/warehouseId。"
],
"type": "updated"
},
{
"version": "2026.05.12-system-01",
"date": "2026-05-12",
@ -1758,5 +1770,20 @@
"任务状态值补充:submitted/running/success/failed/not_found。"
],
"type": "updated"
},
{
"version": "2026.05.16-system-03",
"date": "2026.05.16",
"summary": "同步 setting.expressInterface.create/update 入参与系统快递编码映射规则",
"methods": [
"setting.expressInterface.create",
"setting.expressInterface.update"
],
"notes": [
"补充入参:sys_express_code、weight_type、address、town_name、ispickup、shipperno,并保留既有字段。",
"在参数说明补充 camelCase 别名支持:sysExpressCode、weightType、townName、isPickup、shipperNo 等。",
"同步约束变化:不再因同仓快递编码重复或平台重复直接返回 409;当 express_code 无法匹配系统快递编码时返回 400,文案为 express_code 未匹配到系统快递编码。"
],
"type": "updated"
}
]

View File

@ -1,7 +1,7 @@
{
"module": "system",
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
"version": "2026.05.16-system-02",
"version": "2026.05.16-system-03",
"updatedAt": "2026-05-16",
"headers": [
{
@ -9096,7 +9096,7 @@
},
{
"method": "setting.expressInterface.create",
"description": "在当前仓库范围内创建快递接口,仅写入已实现字段(见 params),仓库由系统自动填充,禁止传入 warehouse_id/warehouseId。",
"description": "在当前仓库范围内创建快递接口。支持 snake_case 与 camelCase 别名入参;sys_express_code 可选显式传入,不传时服务端按 express_code + platform_code 自动解析系统快递编码;同仓快递编码或平台重复不再直接返回 409。",
"isNeedAuth": false,
"isNeedLogin": true,
"headers": [
@ -9120,126 +9120,161 @@
"type": "string",
"required": true,
"source": "body",
"description": "快递编码(不区分大小写,会在服务端转为大写)"
"description": "外部快递 code(支持 expressCode),不区分大小写,服务端会转为大写"
},
{
"name": "platform_code",
"type": "string",
"required": true,
"source": "body",
"description": "平台代码(不区分大小写,会在服务端转为大写)"
"description": "平台代码(支持 platformCode),不区分大小写,服务端会转为大写"
},
{
"name": "express_platform_id",
"type": "number",
"required": true,
"name": "sys_express_code",
"type": "string",
"required": false,
"source": "body",
"description": "平台接口 ID"
"description": "系统快递编码(支持 sysExpressCode)可选显式传入;未传时服务端按 express_code + platform_code 自动解析"
},
{
"name": "sender_name",
"type": "string",
"required": false,
"source": "body",
"description": "发件人姓名"
"description": "发件人姓名(支持 senderName,可选,最长 50 字符)"
},
{
"name": "sender_tel",
"type": "string",
"required": false,
"source": "body",
"description": "发件人电话"
"description": "发件人电话(支持 senderTel,可选,最长 11 字符)"
},
{
"name": "weight",
"type": "number",
"required": false,
"source": "body",
"description": "默认重量(可选)"
"description": "默认重量(可选,整数)"
},
{
"name": "weight_type",
"type": "number",
"required": false,
"source": "body",
"description": "重量类型(支持 weightType,可选,整数)"
},
{
"name": "token",
"type": "string",
"required": false,
"source": "body",
"description": "接口密钥或 token"
"description": "接口密钥或 token(可选,最长 500 字符)"
},
{
"name": "viewer",
"type": "string",
"required": false,
"source": "body",
"description": "查看者标识"
"description": "查看者标识(可选,最长 50 字符)"
},
{
"name": "client_id",
"type": "string",
"required": false,
"source": "body",
"description": "客户端 ID"
"description": "客户端 ID(支持 clientId,可选,最长 50 字符)"
},
{
"name": "is_share",
"type": "number",
"required": false,
"source": "body",
"description": "是否共享(0/1)"
"description": "是否共享(支持 isShare;0/1,可选,默认 0)"
},
{
"name": "share_id",
"type": "number",
"required": false,
"source": "body",
"description": "共享记录 ID"
"description": "共享记录 ID(支持 shareId,可选,整数)"
},
{
"name": "ispickup",
"type": "number",
"required": false,
"source": "body",
"description": "是否上门取件(支持 isPickup;0/1,可选,默认 0)"
},
{
"name": "shipperno",
"type": "string",
"required": false,
"source": "body",
"description": "电子面单客户号(支持 shipperNo,可选,最长 255 字符)"
},
{
"name": "can_use_count",
"type": "number",
"required": false,
"source": "body",
"description": "可用次数/配额"
"description": "可用次数/配额(支持 canUseCount,可选,整数,最小 0)"
},
{
"name": "province_name",
"type": "string",
"required": false,
"source": "body",
"description": "省"
"description": "省(支持 provinceName,可选,最长 255 字符)"
},
{
"name": "city_name",
"type": "string",
"required": false,
"source": "body",
"description": "市"
"description": "市(支持 cityName,可选,最长 255 字符)"
},
{
"name": "district_name",
"type": "string",
"required": false,
"source": "body",
"description": "区/县"
"description": "区/县(支持 districtName,可选,最长 255 字符)"
},
{
"name": "address",
"type": "string",
"required": false,
"source": "body",
"description": "详细地址(可选,最长 255 字符)"
},
{
"name": "town_name",
"type": "string",
"required": false,
"source": "body",
"description": "乡镇/街道(支持 townName,可选,最长 255 字符)"
},
{
"name": "site_code",
"type": "string",
"required": false,
"source": "body",
"description": "站点编码"
"description": "站点编码(支持 siteCode,可选,最长 255 字符)"
},
{
"name": "product_type",
"type": "string",
"required": false,
"source": "body",
"description": "快递产品类型"
"description": "快递产品类型(支持 productType,可选,最长 50 字符)"
},
{
"name": "shop_name",
"type": "string",
"required": false,
"source": "body",
"description": "店铺名称/分组标识"
"description": "店铺名称/分组标识(支持 shopName,可选,最长 255 字符)"
}
],
"response": [
@ -9252,18 +9287,22 @@
],
"errors": [
{
"code": "400",
"description": "必填参数缺失或参数格式错误"
"code": 400,
"message": "必填参数缺失或参数格式错误"
},
{
"code": "409",
"description": "快递编码或平台接口组合已存在(冲突)"
"code": 400,
"message": "express_code 未匹配到系统快递编码"
},
{
"code": 400,
"message": "sys_express_code 未匹配到系统快递编码"
}
]
},
{
"method": "setting.expressInterface.update",
"description": "更新快递接口,支持局部字段更新;支持 id 别名 interface_id / interfaceId;禁止通过接口修改 warehouse_id。",
"description": "更新快递接口,支持局部字段更新与 snake_case/camelCase 别名;支持 id 别名 interface_id / interfaceId;当 express_code/platform_code/sys_express_code 变更时会重算系统快递编码;同仓快递编码或平台重复不再直接返回 409。",
"isNeedAuth": false,
"isNeedLogin": true,
"headers": [
@ -9280,7 +9319,7 @@
"type": "number",
"required": true,
"source": "body",
"description": "快递接口ID;兼容 interface_id / interfaceId"
"description": "快递接口 ID;兼容 interface_id / interfaceId"
},
{
"name": "name",
@ -9294,35 +9333,35 @@
"type": "string",
"required": false,
"source": "body",
"description": "快递编码(更新时会被转为大写)"
"description": "外部快递 code(支持 expressCode),更新时会转为大写"
},
{
"name": "platform_code",
"type": "string",
"required": false,
"source": "body",
"description": "平台代码(更新时会被转为大写)"
"description": "平台代码(支持 platformCode),更新时会转为大写"
},
{
"name": "express_platform_id",
"type": "number",
"name": "sys_express_code",
"type": "string",
"required": false,
"source": "body",
"description": "平台接口 ID"
"description": "系统快递编码(支持 sysExpressCode)可选显式传入;不传时服务端按 express_code + platform_code 自动解析"
},
{
"name": "sender_name",
"type": "string",
"required": false,
"source": "body",
"description": "发件人姓名"
"description": "发件人姓名(支持 senderName)"
},
{
"name": "sender_tel",
"type": "string",
"required": false,
"source": "body",
"description": "发件人电话"
"description": "发件人电话(支持 senderTel)"
},
{
"name": "weight",
@ -9331,6 +9370,13 @@
"source": "body",
"description": "默认重量"
},
{
"name": "weight_type",
"type": "number",
"required": false,
"source": "body",
"description": "重量类型(支持 weightType)"
},
{
"name": "token",
"type": "string",
@ -9350,96 +9396,134 @@
"type": "string",
"required": false,
"source": "body",
"description": "客户端 ID"
"description": "客户端 ID(支持 clientId)"
},
{
"name": "is_share",
"type": "number",
"required": false,
"source": "body",
"description": "是否共享(0/1)"
"description": "是否共享(支持 isShare;0/1)"
},
{
"name": "share_id",
"type": "number",
"required": false,
"source": "body",
"description": "共享记录 ID"
"description": "共享记录 ID(支持 shareId)"
},
{
"name": "ispickup",
"type": "number",
"required": false,
"source": "body",
"description": "是否上门取件(支持 isPickup;0/1)"
},
{
"name": "shipperno",
"type": "string",
"required": false,
"source": "body",
"description": "电子面单客户号(支持 shipperNo)"
},
{
"name": "can_use_count",
"type": "number",
"required": false,
"source": "body",
"description": "可用次数/配额"
"description": "可用次数/配额(支持 canUseCount)"
},
{
"name": "province_name",
"type": "string",
"required": false,
"source": "body",
"description": "省"
"description": "省(支持 provinceName)"
},
{
"name": "city_name",
"type": "string",
"required": false,
"source": "body",
"description": "市"
"description": "市(支持 cityName)"
},
{
"name": "district_name",
"type": "string",
"required": false,
"source": "body",
"description": "区/县"
"description": "区/县(支持 districtName)"
},
{
"name": "address",
"type": "string",
"required": false,
"source": "body",
"description": "详细地址"
},
{
"name": "town_name",
"type": "string",
"required": false,
"source": "body",
"description": "乡镇/街道(支持 townName)"
},
{
"name": "site_code",
"type": "string",
"required": false,
"source": "body",
"description": "站点编码"
"description": "站点编码(支持 siteCode)"
},
{
"name": "product_type",
"type": "string",
"required": false,
"source": "body",
"description": "快递产品类型"
"description": "快递产品类型(支持 productType)"
},
{
"name": "shop_name",
"type": "string",
"required": false,
"source": "body",
"description": "店铺名称/分组标识"
"description": "店铺名称/分组标识(支持 shopName)"
}
],
"response": [
{
"name": "id",
"type": "number",
"required": true,
"description": "首条更新记录 ID"
},
{
"name": "name",
"type": "string",
"required": false,
"description": "更新后的接口名称"
}
],
"errors": [
{
"code": "400",
"description": "id 为空或无可更新字段"
"code": 400,
"message": "id 参数不能为空"
},
{
"code": "404",
"description": "快递接口不存在或无权限操作"
"code": 400,
"message": "至少需要提供一个可更新字段"
},
{
"code": "409",
"description": "快递编码或平台接口组合冲突"
"code": 400,
"message": "express_code 未匹配到系统快递编码"
},
{
"code": 400,
"message": "sys_express_code 未匹配到系统快递编码"
},
{
"code": 404,
"message": "快递接口不存在或无权限操作"
}
]
},

View File

@ -174,7 +174,12 @@ describe('test/app/service/systemMethods/setting/expressInterface.test.js', () =
name: '顺丰接口',
express_code: 'SF',
platform_code: 'TB',
express_platform_id: 1,
sysExpressCode: 'SF',
weightType: 2,
address: '上海市浦东新区',
townName: '张江镇',
isPickup: 1,
shipperNo: 'SHIP-001',
extra: {
keep: true,
},
@ -183,6 +188,12 @@ describe('test/app/service/systemMethods/setting/expressInterface.test.js', () =
id: 11,
name: '顺丰接口-更新',
token: 'token-2',
sys_express_code: 'SF',
weight_type: 3,
address: '深圳市南山区',
town_name: '粤海街道',
ispickup: 0,
shipperno: 'SHIP-002',
});
const deleteResult = await service.delete({
id: 11,
@ -198,7 +209,12 @@ describe('test/app/service/systemMethods/setting/expressInterface.test.js', () =
name: '顺丰接口',
express_code: 'SF',
platform_code: 'TB',
express_platform_id: 1,
sys_express_code: 'SF',
weight_type: 2,
address: '上海市浦东新区',
town_name: '张江镇',
ispickup: 1,
shipperno: 'SHIP-001',
extra: {
keep: true,
},
@ -208,6 +224,12 @@ describe('test/app/service/systemMethods/setting/expressInterface.test.js', () =
id: 11,
name: '顺丰接口-更新',
token: 'token-2',
sys_express_code: 'SF',
weight_type: 3,
address: '深圳市南山区',
town_name: '粤海街道',
ispickup: 0,
shipperno: 'SHIP-002',
touched: true,
});
assert.deepEqual(calls.delete[0], {

View File

@ -653,8 +653,10 @@ describe('test/app/service/systems/order_delivery_migration.test.js', () => {
assert.equal(targetItemModel.rows.length, 0);
});
it('should mark source orders as timeout when normal migration hits retryable lock errors', async () => {
const sourceRows = buildOrderRows(1);
it('should mark source orders as timeout without changing step when normal migration hits retryable lock errors', async () => {
const sourceRows = buildOrderRows(1, {
step: 9,
});
const { service, capture, transactionCalls, sourceOrderModel, targetOrderModel, sourceItemModel, targetItemModel } = createHarness({
sourceRows,
sourceItemRows: buildItemRows(sourceRows),
@ -679,8 +681,10 @@ describe('test/app/service/systems/order_delivery_migration.test.js', () => {
assert.equal(transactionCalls[0].rolledBack, true);
assert.equal(capture.updateOptions.length, 1);
assert.equal(capture.updateOptions[0].values.outbound_status, 'timeout');
assert.equal('step' in capture.updateOptions[0].values, false);
assert.equal(sourceOrderModel.rows.length, 1);
assert.equal(sourceOrderModel.rows[0].outbound_status, 'timeout');
assert.equal(sourceOrderModel.rows[0].step, 9);
assert.equal(targetOrderModel.rows.length, 0);
assert.equal(sourceItemModel.rows.length, 1);
assert.equal(targetItemModel.rows.length, 0);

View File

@ -33,6 +33,7 @@ function createHarness(options = {}) {
findAndCountAllCalls: 0,
findOneCalls: [],
findAllCalls: 0,
expressFindOneCalls: [],
createPayload: null,
updatePayload: null,
destroyPayload: null,
@ -85,6 +86,10 @@ function createHarness(options = {}) {
site_code: 'SITE-01',
product_type: 'STD',
shop_name: '旗舰店',
address: '广东省深圳市南山区科技园',
town_name: '粤海街道',
ispickup: 1,
shipperno: 'SHIPPER-001',
},
{
id: 12,
@ -151,8 +156,18 @@ function createHarness(options = {}) {
product_type: {},
weight_type: {},
shop_name: {},
address: {},
town_name: {},
ispickup: {},
shipperno: {},
};
const expressRows = options.expressRows || [
{ code: 'SF', name: '顺丰', PDD: 'SF-PDD', KS: 'SF-KS', DYXD: 'SF-DYXD' },
{ code: 'JD', name: '京东', PDD: 'JD-PDD', KS: 'JD-KS', DYXD: 'JD-DYXD' },
{ code: 'ZTO', name: '中通', PDD: 'ZTO-PDD', KS: 'ZTO-KS', DYXD: 'ZTO-DYXD' },
];
const ctx = {
user: {
store_id: options.storeId || 100000,
@ -184,6 +199,16 @@ function createHarness(options = {}) {
},
},
model: {
Express: {
async findOne(query) {
calls.expressFindOneCalls.push(query);
const where = query.where || {};
const [ key ] = Object.keys(where);
const value = where[key];
const found = expressRows.find(row => String(row[key] || '') === String(value || ''));
return found ? { ...found } : null;
},
},
ExpressInterface: {
rawAttributes,
async findAndCountAll(query) {
@ -279,6 +304,7 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
warehouse_id: 100000,
name: '顺丰接口',
express_code: 'SF',
sys_express_code: 'SF',
platform_code: 'TB',
express_platform_id: 1,
express: {
@ -338,7 +364,7 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
assert.equal(result.data.page_size, 1);
assert.equal(result.data.list[0].name, '顺丰接口');
assert.equal(result.data.list[0].platform_code, 'TB');
assert.equal(result.data.list[0].express_platform_id, 1);
assert.equal(result.data.list[0].sys_express_code, 'SF');
assert.equal(Array.isArray(calls.findAndCountAllQuery.include), true);
assert.equal(calls.findAndCountAllQuery.include.length, 1);
assert.equal(result.data.list[0].express.name, '顺丰');
@ -490,25 +516,11 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
assert.equal(result.data[0].express.polyapi_code, 'SF_API');
});
it('should load context for conflict lookups and keep old fields intact', async () => {
const { ctx, calls } = createHarness();
const service = new SettingExpressInterfaceService(ctx);
const codeConflict = await service.findCodeConflict('SF');
const interfaceConflict = await service.findInterfaceConflict('TB', 1);
assert.equal(calls.findOneCalls[0].include.length, 1);
assert.equal(calls.findOneCalls[1].include.length, 1);
assert.equal(codeConflict.express.name, '顺丰');
assert.equal(codeConflict.express_code, 'SF');
assert.equal(interfaceConflict.express.name, '顺丰');
});
it('should create a new express interface and normalize codes', async () => {
const { ctx, calls } = createHarness({
createdRowFactory: payload => ({
express: {
code: payload.express_code,
code: payload.sys_express_code,
name: '京东快递',
polyapi_code: 'JD_API',
polyapi_extra_info: { source: 'polyapi' },
@ -533,53 +545,74 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
name: '京东接口',
express_code: 'jd',
platform_code: 'tb',
express_platform_id: 3,
sender_name: '李四',
sender_tel: '13900000000',
token: ' token-2 ',
is_share: 1,
can_use_count: 5,
weight_type: 2,
address: '朝阳区望京',
town_name: '望京街道',
ispickup: 1,
shipperno: 'SNO-001',
});
assert.equal(calls.createPayload.warehouse_id, 100000);
assert.equal(calls.createPayload.express_code, 'JD');
assert.equal(calls.createPayload.sys_express_code, 'JD');
assert.equal(calls.createPayload.platform_code, 'TB');
assert.equal(calls.createPayload.express_platform_id, 3);
assert.equal(result.data.express_code, 'JD');
assert.equal(result.data.sys_express_code, 'JD');
assert.equal(result.data.platform_code, 'TB');
assert.equal(result.data.sender_name, '李四');
assert.equal(result.data.token, 'token-2');
assert.equal(result.data.weight_type, 2);
assert.equal(result.data.address, '朝阳区望京');
assert.equal(result.data.town_name, '望京街道');
assert.equal(result.data.ispickup, 1);
assert.equal(result.data.shipperno, 'SNO-001');
assert.equal(result.data.express.name, '京东快递');
assert.equal(Object.prototype.hasOwnProperty.call(result.data, 'express_platform'), false);
assert.equal(calls.cacheDeletes.includes('express_interface:warehouse:100000:platform:TB'), true);
});
it('should reject create when express code conflicts inside the current warehouse', async () => {
const { ctx } = createHarness();
it('should allow duplicate rows with same warehouse platform and express_code', async () => {
const { ctx, calls } = createHarness();
const service = new SettingExpressInterfaceService(ctx);
await assert.rejects(async () => {
await service.create({
name: '重复编码接口',
express_code: 'SF',
platform_code: 'WX',
express_platform_id: 4,
});
}, /快递编码已被当前仓库使用/);
const result = await service.create({
name: '重复编码接口',
express_code: 'SF',
platform_code: 'TB',
weight_type: 1,
weight: 100,
});
assert.equal(result.code, 200);
assert.equal(calls.createPayload.express_code, 'SF');
assert.equal(calls.createPayload.platform_code, 'TB');
assert.equal(calls.createPayload.weight_type, 1);
assert.equal(calls.findOneCalls.some(item => item.where && item.where.express_code === 'SF' && item.where.warehouse_id === 100000), false);
});
it('should reject create when platform and interface combination conflicts', async () => {
const { ctx } = createHarness();
it('should resolve sys_express_code by platform custom code', async () => {
const { ctx, calls } = createHarness({
expressRows: [
{ code: 'SF', name: '顺丰', PDD: 'SF-PDD', KS: 'KS-SF', DYXD: 'DY-SF' },
],
});
const service = new SettingExpressInterfaceService(ctx);
await assert.rejects(async () => {
await service.create({
name: '重复接口',
express_code: 'ZTO',
platform_code: 'TB',
express_platform_id: 1,
});
}, /当前平台和快递接口组合已被使用/);
const result = await service.create({
name: '拼多多顺丰接口',
express_code: 'sf-pdd',
platform_code: 'PDD',
});
assert.equal(result.code, 200);
assert.equal(calls.createPayload.express_code, 'SF-PDD');
assert.equal(calls.createPayload.sys_express_code, 'SF');
assert.equal(calls.expressFindOneCalls.length >= 2, true);
});
it('should update a record with boundary checks and partial fields', async () => {
@ -589,19 +622,35 @@ describe('test/app/service/systems/setting/expressInterface.test.js', () => {
const result = await service.update({
id: 11,
name: '顺丰接口-更新',
express_code: 'sf-pdd',
platform_code: 'pdd',
token: ' token-updated ',
can_use_count: 0,
weight_type: 3,
address: '上海市浦东新区',
town_name: '张江镇',
ispickup: 0,
shipperno: 'SHIPPER-NEW',
});
assert.equal(calls.findOneCalls.length >= 1, true);
assert.equal(calls.updatePayload.id, 11);
assert.equal(calls.updatePayload.updates.name, '顺丰接口-更新');
assert.equal(calls.updatePayload.updates.express_code, 'SF-PDD');
assert.equal(calls.updatePayload.updates.platform_code, 'PDD');
assert.equal(calls.updatePayload.updates.sys_express_code, 'SF');
assert.equal(calls.updatePayload.updates.token, 'token-updated');
assert.equal(calls.updatePayload.updates.can_use_count, 0);
assert.equal(calls.updatePayload.updates.weight_type, 3);
assert.equal(calls.updatePayload.updates.address, '上海市浦东新区');
assert.equal(calls.updatePayload.updates.town_name, '张江镇');
assert.equal(calls.updatePayload.updates.ispickup, 0);
assert.equal(calls.updatePayload.updates.shipperno, 'SHIPPER-NEW');
assert.equal(result.data.name, '顺丰接口-更新');
assert.equal(result.data.express.name, '顺丰');
assert.equal(Object.prototype.hasOwnProperty.call(result.data, 'express_platform'), false);
assert.equal(calls.cacheDeletes.includes('express_interface:warehouse:100000:platform:TB'), true);
assert.equal(calls.cacheDeletes.includes('express_interface:warehouse:100000:platform:PDD'), true);
});
it('should clear old and new cache keys when platform code changes on update', async () => {

View File

@ -348,8 +348,8 @@ describe('test/app/service/systems/storage.inventory.transfer.test.js', () => {
assert.equal(calls.rollbackCount, 0);
assert.equal(calls.stockTransactions.length, 4);
const transferOutTransactions = calls.stockTransactions.filter((item) => item.payload.transaction_type === 'TRANSFER_OUT');
const transferInTransactions = calls.stockTransactions.filter((item) => item.payload.transaction_type === 'TRANSFER_IN');
const transferOutTransactions = calls.stockTransactions.filter(item => item.payload.transaction_type === 'TRANSFER_OUT');
const transferInTransactions = calls.stockTransactions.filter(item => item.payload.transaction_type === 'TRANSFER_IN');
assert.equal(transferOutTransactions.length, 2);
assert.equal(transferInTransactions.length, 2);