1
This commit is contained in:
parent
eb100b056d
commit
c2b5ffc319
@ -452,7 +452,7 @@ class HomeController extends Controller {
|
||||
status: 1,
|
||||
};
|
||||
|
||||
if (oauthData && oauthData.taobao_user_nick !== undefined) {
|
||||
if (oauthData && oauthData.taobao_user_nick != null) {
|
||||
updatePayload.shop_name = this.decodeTbShopName(oauthData.taobao_user_nick);
|
||||
}
|
||||
|
||||
@ -503,6 +503,38 @@ class HomeController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找与待更新店铺存在唯一约束冲突的店铺记录(不限授权状态)。
|
||||
* 用于乐观重试场景:当前预授权店铺 save 触发 uk_warehouse_platform_shop_name
|
||||
* 冲突时,回退到此方法查找冲突记录并尝试合并。
|
||||
* @param {import('sequelize').Model} shop 当前预申请店铺记录。
|
||||
* @param {object} updatePayload 待回写的字段对象,需包含 shop_name。
|
||||
* @param {import('sequelize').Transaction} transaction 当前事务对象。
|
||||
* @return {Promise<import('sequelize').Model|null>} 冲突的店铺记录,未找到返回 null。
|
||||
*/
|
||||
async findConflictShopForOauth(shop, updatePayload, transaction) {
|
||||
const { Op } = this.app.Sequelize;
|
||||
const normalizedShopName = updatePayload.shop_name != null
|
||||
? String(updatePayload.shop_name).trim()
|
||||
: '';
|
||||
|
||||
if (!normalizedShopName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return await this.ctx.model.Shop.findOne({
|
||||
where: {
|
||||
warehouse_id: shop.warehouse_id,
|
||||
platform_code: shop.platform_code,
|
||||
shop_name: normalizedShopName,
|
||||
id: {
|
||||
[Op.ne]: shop.id,
|
||||
},
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 按仓库、平台与授权标识查找已授权的旧店铺记录。
|
||||
* @param {import('sequelize').Model} shop 当前预申请店铺记录。
|
||||
@ -585,37 +617,111 @@ class HomeController extends Controller {
|
||||
'status',
|
||||
];
|
||||
|
||||
return await this.ctx.model.transaction(async transaction => {
|
||||
const authorizedShop = await this.findAuthorizedOauthShop(
|
||||
shop,
|
||||
updatePayload.owner_id,
|
||||
updatePayload.shop_name,
|
||||
transaction
|
||||
);
|
||||
// 兜底:若 OAuth 响应未返回 shop_name,沿用数据库已有值,避免 save 时触发 allowNull 校验
|
||||
if (!('shop_name' in updatePayload) || updatePayload.shop_name == null) {
|
||||
updatePayload.shop_name = shop.shop_name;
|
||||
}
|
||||
|
||||
if (authorizedShop) {
|
||||
authorizedShop.set(updatePayload);
|
||||
await authorizedShop.save({
|
||||
try {
|
||||
return await this.ctx.model.transaction(async transaction => {
|
||||
const authorizedShop = await this.findAuthorizedOauthShop(
|
||||
shop,
|
||||
updatePayload.owner_id,
|
||||
updatePayload.shop_name,
|
||||
transaction
|
||||
);
|
||||
|
||||
if (authorizedShop) {
|
||||
authorizedShop.set(updatePayload);
|
||||
await authorizedShop.save({
|
||||
fields: saveFields,
|
||||
transaction,
|
||||
});
|
||||
await shop.destroy({ transaction });
|
||||
|
||||
return authorizedShop;
|
||||
}
|
||||
|
||||
shop.set(updatePayload);
|
||||
await shop.save({
|
||||
fields: saveFields,
|
||||
transaction,
|
||||
});
|
||||
await shop.destroy({ transaction });
|
||||
|
||||
return authorizedShop;
|
||||
return shop;
|
||||
});
|
||||
} catch (error) {
|
||||
// 记录 Sequelize 验证错误的详细信息,包括每个字段的失败原因
|
||||
if (error.name === 'SequelizeValidationError' && Array.isArray(error.errors)) {
|
||||
const fieldErrors = error.errors.map(e => `${e.path}: ${e.message}`).join('; ');
|
||||
this.ctx.logger.error(
|
||||
'[platform-oauth][CAINIAO] 店铺保存校验失败,shop_id=%s,字段详情:%s',
|
||||
shop && shop.id,
|
||||
fieldErrors
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
shop.set(updatePayload);
|
||||
await shop.save({
|
||||
fields: saveFields,
|
||||
transaction,
|
||||
});
|
||||
// 唯一约束冲突:尝试乐观重试,查找冲突记录并合并
|
||||
if (error.name === 'SequelizeUniqueConstraintError') {
|
||||
const conflictFields = error.fields ? Object.keys(error.fields).join(', ') : 'unknown';
|
||||
const conflictValues = error.fields ? JSON.stringify(error.fields) : 'unknown';
|
||||
this.ctx.logger.error(
|
||||
'[platform-oauth][CAINIAO] 店铺保存唯一约束冲突,shop_id=%s,冲突字段:%s,冲突值:%s',
|
||||
shop && shop.id,
|
||||
conflictFields,
|
||||
conflictValues
|
||||
);
|
||||
|
||||
return shop;
|
||||
});
|
||||
// 乐观重试:在新事务中查找冲突记录并尝试合并
|
||||
try {
|
||||
return await this.ctx.model.transaction(async transaction => {
|
||||
const conflictShop = await this.findConflictShopForOauth(
|
||||
shop,
|
||||
updatePayload,
|
||||
transaction
|
||||
);
|
||||
|
||||
if (conflictShop) {
|
||||
conflictShop.set(updatePayload);
|
||||
await conflictShop.save({
|
||||
fields: saveFields,
|
||||
transaction,
|
||||
});
|
||||
await shop.destroy({ transaction });
|
||||
this.ctx.logger.info(
|
||||
'[platform-oauth][CAINIAO] 乐观重试成功,冲突店铺已合并,conflict_shop_id=%s,pre_auth_shop_id=%s',
|
||||
conflictShop.id,
|
||||
shop.id
|
||||
);
|
||||
return conflictShop;
|
||||
}
|
||||
|
||||
// 未找到冲突记录则返回 null,由上层展示友好提示
|
||||
this.ctx.logger.warn(
|
||||
'[platform-oauth][CAINIAO] 乐观重试未找到冲突记录,shop_id=%s,shop_name=%s',
|
||||
shop && shop.id,
|
||||
updatePayload.shop_name
|
||||
);
|
||||
return null;
|
||||
});
|
||||
} catch (retryError) {
|
||||
this.ctx.logger.error(
|
||||
'[platform-oauth][CAINIAO] 乐观重试失败,shop_id=%s,错误:%s',
|
||||
shop && shop.id,
|
||||
retryError.message || retryError
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理平台授权回调请求,解析 query 中的 code 与 state。
|
||||
* 内部使用 try-catch 兜底,确保即使处理过程中抛出未捕获异常也能渲染错误页面而非 500。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async platformOauthCallback() {
|
||||
@ -630,20 +736,47 @@ class HomeController extends Controller {
|
||||
let errorMessage = '';
|
||||
let shop = null;
|
||||
|
||||
if (!code) {
|
||||
errorMessage = 'code不能为空';
|
||||
} else if (!state) {
|
||||
errorMessage = 'state不能为空';
|
||||
} else if (!parsedState) {
|
||||
errorMessage = 'state解析失败';
|
||||
} else {
|
||||
switch (parsedState.platformCode) {
|
||||
case 'PDD':
|
||||
{
|
||||
const pddResult = await this.pdd(code);
|
||||
try {
|
||||
if (!code) {
|
||||
errorMessage = 'code不能为空';
|
||||
} else if (!state) {
|
||||
errorMessage = 'state不能为空';
|
||||
} else if (!parsedState) {
|
||||
errorMessage = 'state解析失败';
|
||||
} else {
|
||||
switch (parsedState.platformCode) {
|
||||
case 'PDD':
|
||||
{
|
||||
const pddResult = await this.pdd(code);
|
||||
|
||||
if (pddResult.success === false) {
|
||||
errorMessage = pddResult.message;
|
||||
if (pddResult.success === false) {
|
||||
errorMessage = pddResult.message;
|
||||
break;
|
||||
}
|
||||
|
||||
shop = await ctx.model.Shop.findOne({
|
||||
where: {
|
||||
auth_random_code: parsedState.authRandomCode,
|
||||
},
|
||||
});
|
||||
|
||||
if (shop && this.isMatchedShopPlatform(shop, parsedState.platformCode)) {
|
||||
const oauthData = pddResult.result && pddResult.result.data
|
||||
? pddResult.result.data
|
||||
: pddResult.result;
|
||||
|
||||
shop = await this.updatePddOauthShop(shop, oauthData);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'CAINIAO':
|
||||
{
|
||||
const cainiaoOauthResult = await this.cainiao(code);
|
||||
|
||||
if (!cainiaoOauthResult || cainiaoOauthResult.success === false) {
|
||||
errorMessage = cainiaoOauthResult && cainiaoOauthResult.message
|
||||
? cainiaoOauthResult.message
|
||||
: '菜鸟授权失败:未知错误';
|
||||
break;
|
||||
}
|
||||
|
||||
@ -654,45 +787,28 @@ class HomeController extends Controller {
|
||||
});
|
||||
|
||||
if (shop && this.isMatchedShopPlatform(shop, parsedState.platformCode)) {
|
||||
const oauthData = pddResult.result && pddResult.result.data
|
||||
? pddResult.result.data
|
||||
: pddResult.result;
|
||||
const oauthData = cainiaoOauthResult.result && cainiaoOauthResult.result.data
|
||||
? cainiaoOauthResult.result.data
|
||||
: cainiaoOauthResult.result;
|
||||
|
||||
shop = await this.updatePddOauthShop(shop, oauthData);
|
||||
shop = await this.updateCainiaoOauthShop(shop, oauthData);
|
||||
if (!shop) {
|
||||
errorMessage = '店铺名称已存在,请先在系统中解绑同名店铺后重试';
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'CAINIAO':
|
||||
{
|
||||
const cainiaoOauthResult = await this.cainiao(code);
|
||||
|
||||
if (!cainiaoOauthResult || cainiaoOauthResult.success === false) {
|
||||
errorMessage = cainiaoOauthResult && cainiaoOauthResult.message
|
||||
? cainiaoOauthResult.message
|
||||
: '菜鸟授权失败:未知错误';
|
||||
break;
|
||||
}
|
||||
|
||||
shop = await ctx.model.Shop.findOne({
|
||||
where: {
|
||||
auth_random_code: parsedState.authRandomCode,
|
||||
},
|
||||
});
|
||||
|
||||
if (shop && this.isMatchedShopPlatform(shop, parsedState.platformCode)) {
|
||||
const oauthData = cainiaoOauthResult.result && cainiaoOauthResult.result.data
|
||||
? cainiaoOauthResult.result.data
|
||||
: cainiaoOauthResult.result;
|
||||
|
||||
shop = await this.updateCainiaoOauthShop(shop, oauthData);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
errorMessage = '暂未接入该平台授权回调处理';
|
||||
break;
|
||||
}
|
||||
default:
|
||||
errorMessage = '暂未接入该平台授权回调处理';
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
ctx.logger.error('[platform-oauth] 回调处理异常: %s', error.stack || error.message || error);
|
||||
errorMessage = `系统内部错误:${error.message || '未知异常'}`;
|
||||
// 发生异常后不再信任 shop 状态,置空以避免渲染误导信息
|
||||
shop = null;
|
||||
}
|
||||
|
||||
const viewData = this.buildPlatformOauthCallbackViewData({
|
||||
|
||||
@ -157,6 +157,21 @@ module.exports = app => {
|
||||
allowNull: true,
|
||||
comment: '店铺名称',
|
||||
},
|
||||
buyer_message: {
|
||||
type: STRING(500),
|
||||
allowNull: true,
|
||||
comment: '买家留言',
|
||||
},
|
||||
seller_message: {
|
||||
type: STRING(500),
|
||||
allowNull: true,
|
||||
comment: '卖家留言',
|
||||
},
|
||||
remark: {
|
||||
type: STRING(500),
|
||||
allowNull: true,
|
||||
comment: '备注',
|
||||
},
|
||||
seller_nick: {
|
||||
type: STRING(200),
|
||||
allowNull: true,
|
||||
|
||||
@ -122,7 +122,7 @@ module.exports = app => {
|
||||
},
|
||||
{
|
||||
name: 'uk_warehouse_platform_shop_name',
|
||||
unique: true,
|
||||
unique: false,
|
||||
fields: [ 'warehouse_id', 'platform_code', 'shop_name' ],
|
||||
},
|
||||
{
|
||||
|
||||
@ -19,7 +19,7 @@ const REVIEW_STATUS_STEP_MAP = Object.freeze({
|
||||
const REVIEW_ORDER_ALLOWED_FIELDS = Object.freeze([ 'ids' ]);
|
||||
const BADGE_COUNT_OVER_LIMIT_VALUE = '99+';
|
||||
|
||||
const ORDER_LIST_BASE_ATTRIBUTES = Object.freeze([
|
||||
const ORDER_LIST_BASE_ATTRIBUTES = [
|
||||
'id', 'delivery_order_code', 'pre_delivery_order_code', 'pre_delivery_order_id',
|
||||
'order_type', 'order_flag', 'source_order_codes',
|
||||
'sys_platform_code', 'sys_platform_name',
|
||||
@ -27,6 +27,7 @@ const ORDER_LIST_BASE_ATTRIBUTES = Object.freeze([
|
||||
'place_order_time', 'pay_time', 'pay_no', 'service_code',
|
||||
'operator_name', 'operate_time', 'delivery_time',
|
||||
'shop_nick', 'seller_nick', 'buyer_nick',
|
||||
'buyer_message', 'seller_message', 'remark',
|
||||
'total_amount', 'item_amount', 'discount_amount', 'freight',
|
||||
'ar_amount', 'got_amount', 'service_fee',
|
||||
'logistics_name',
|
||||
@ -44,7 +45,7 @@ const ORDER_LIST_BASE_ATTRIBUTES = Object.freeze([
|
||||
'post_status', 'storage_status', 'pick_status', 'pack_status',
|
||||
'inspection_status', 'print_status', 'claim_status',
|
||||
'outbound_status', 'lock_status', 'intercept_status', 'basket_number', 'recheck_status',
|
||||
]);
|
||||
];
|
||||
|
||||
const ORDER_WEIGHT_TYPE_LABELS = Object.freeze({
|
||||
0: '常规',
|
||||
@ -1416,6 +1417,7 @@ class OrderBaseService extends MainService {
|
||||
const updateValues = {
|
||||
inspection_status: 'fin',
|
||||
step: 1,
|
||||
status: 'created',
|
||||
updated_at: now,
|
||||
};
|
||||
|
||||
|
||||
@ -28,9 +28,9 @@ class PendingOrderService extends OrderBaseService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress';
|
||||
const _noNeedRight = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,updateAddress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress';
|
||||
const _noNeedLog = 'list,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,parseAddress';
|
||||
const _noNeedAuth = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress';
|
||||
const _noNeedAuth = 'list,pendingOrder,reverseReviewOrder,markPendingOutboundOrder,cancelOrder,allocateExpressCode,allocateStorage,allocateStorageProgress,cancelAllocateStorage,syncOrderIds,updateOrderPlatform,updateOrderExpress,updateAddress,cloneOrder,createOrder,downloadCreateTemplate,parseAddress';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
}
|
||||
|
||||
@ -1468,7 +1468,10 @@ class PendingOrderService extends OrderBaseService {
|
||||
}
|
||||
|
||||
const model = await this.getOrderModel('order', warehouseId);
|
||||
const where = this.buildOrderWhere(orderIds, warehouseId);
|
||||
const where = {
|
||||
...this.buildOrderWhere(orderIds, warehouseId),
|
||||
post_status: 'none',
|
||||
};
|
||||
|
||||
const [ affectedRows ] = await model.update({
|
||||
sys_platform_code: platform.code,
|
||||
@ -1578,7 +1581,10 @@ class PendingOrderService extends OrderBaseService {
|
||||
}
|
||||
|
||||
const model = await this.getOrderModel('order', warehouseId);
|
||||
const where = this.buildOrderWhere(orderIds, warehouseId);
|
||||
const where = {
|
||||
...this.buildOrderWhere(orderIds, warehouseId),
|
||||
post_status: 'none',
|
||||
};
|
||||
|
||||
const [ affectedRows ] = await model.update({
|
||||
sys_logistics_code: sysLogisticsCode,
|
||||
@ -1623,6 +1629,92 @@ class PendingOrderService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改待处理订单的收件地址信息。
|
||||
*
|
||||
* 仅允许在未分配快递(post_status = 'none')时修改,至少提供一个地址字段。
|
||||
* 支持批量操作,返回更新数量和受影响的订单 ID 列表。
|
||||
*
|
||||
* @param {Object} data 请求体。
|
||||
* @param {number[]} data.ids 订单 ID 数组(必填)。
|
||||
* @param {string} [data.name] 收件人姓名。
|
||||
* @param {string} [data.mobile] 手机号。
|
||||
* @param {string} [data.tel] 电话。
|
||||
* @param {string} [data.zip_code] 邮编。
|
||||
* @param {string} [data.province] 省份。
|
||||
* @param {string} [data.city] 城市。
|
||||
* @param {string} [data.area] 区/县。
|
||||
* @param {string} [data.town] 镇/街道。
|
||||
* @param {string} [data.detail_address] 详细地址。
|
||||
* @return {Promise<Object>} 统一 success 包装的更新结果,含 updated_count 与 ids。
|
||||
*/
|
||||
async updateAddress(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const warehouseId = this.getWarehouseId();
|
||||
const operator = this.getOrderLogOperator();
|
||||
const logWarehouseId = this.getOrderLogWarehouseId(warehouseId);
|
||||
|
||||
// 解析订单 ID
|
||||
const orderIds = this.normalizeOrderIds(requestData);
|
||||
if (orderIds.length === 0) {
|
||||
throw new Error('ids 不能为空');
|
||||
}
|
||||
|
||||
// 收集可更新的地址字段
|
||||
const addressFields = [
|
||||
'name', 'mobile', 'tel', 'zip_code',
|
||||
'province', 'city', 'area', 'town', 'detail_address',
|
||||
];
|
||||
const updates = {};
|
||||
for (const field of addressFields) {
|
||||
const value = requestData[field];
|
||||
if (value !== undefined && value !== null && String(value).trim() !== '') {
|
||||
updates[field] = String(value).trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(updates).length === 0) {
|
||||
throw new Error('至少需要提供一个地址字段进行修改');
|
||||
}
|
||||
|
||||
updates.updated_at = new Date();
|
||||
|
||||
const model = await this.getOrderModel('order', warehouseId);
|
||||
const where = {
|
||||
...this.buildOrderWhere(orderIds, warehouseId),
|
||||
post_status: 'none',
|
||||
};
|
||||
|
||||
const [ affectedRows ] = await model.update(updates, { where });
|
||||
const count = Number(affectedRows || 0);
|
||||
|
||||
// 记录操作日志
|
||||
try {
|
||||
const updatedFieldNames = Object.keys(updates).filter(k => k !== 'updated_at');
|
||||
await this.ctx.service.systems.operationLog.createOperationLog({
|
||||
businessType: 'order',
|
||||
businessId: logWarehouseId,
|
||||
operationCode: 'ORDER_UPDATE_ADDRESS',
|
||||
operator,
|
||||
extras: {
|
||||
warehouseId: logWarehouseId,
|
||||
orderIds,
|
||||
updated_fields: updatedFieldNames,
|
||||
updated_count: count,
|
||||
message: `批量修改订单收件地址:订单ID [${orderIds.join(', ')}],更新字段 [${updatedFieldNames.join(', ')}],共更新 ${count} 条`,
|
||||
},
|
||||
beforeChanges: null,
|
||||
});
|
||||
} catch (logErr) {
|
||||
this.ctx.logger.warn('[PendingOrderService.updateAddress] 写入操作日志失败,不影响业务', logErr);
|
||||
}
|
||||
|
||||
return this.success('ok', {
|
||||
updated_count: count,
|
||||
ids: orderIds,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 克隆待处理订单。
|
||||
*
|
||||
|
||||
@ -183,6 +183,9 @@ class RecheckOrderService extends OrderBaseService {
|
||||
}
|
||||
);
|
||||
|
||||
// 更新波次拣货任务订单复核状态,并判断是否需要解绑车任务
|
||||
await this.updateTaskOrderReviewAndTryUnbindCart(orderId, warehouseId, operator, now);
|
||||
|
||||
return {
|
||||
order_id: orderId,
|
||||
waybill_no: waybillNo,
|
||||
@ -192,6 +195,162 @@ class RecheckOrderService extends OrderBaseService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新波次拣货任务订单的复核状态,若任务下所有订单均已复核完成则自动解绑车任务。
|
||||
* @param {number} orderId 订单ID。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @param {{ id: string|null, name: string }} operator 操作人信息。
|
||||
* @param {Date} now 当前时间。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async updateTaskOrderReviewAndTryUnbindCart(orderId, warehouseId, operator, now) {
|
||||
const { ctx } = this;
|
||||
const taskOrderColumnSet = await this.getTableColumnSet('wms_wave_pick_task_order');
|
||||
const hasReviewStatus = taskOrderColumnSet.has('review_status');
|
||||
const hasReviewUserId = taskOrderColumnSet.has('review_user_id');
|
||||
const hasReviewResult = taskOrderColumnSet.has('review_result');
|
||||
const hasReviewTime = taskOrderColumnSet.has('review_time');
|
||||
|
||||
// 若 review_status 列不存在,跳过后续所有逻辑
|
||||
if (!hasReviewStatus) {
|
||||
return;
|
||||
}
|
||||
|
||||
const operatorUserId = Number(operator.id) || 0;
|
||||
const reviewSetClauses = [];
|
||||
|
||||
reviewSetClauses.push('review_status = 1');
|
||||
if (hasReviewUserId) reviewSetClauses.push('review_user_id = :operatorUserId');
|
||||
if (hasReviewResult) reviewSetClauses.push('review_result = 1');
|
||||
if (hasReviewTime) reviewSetClauses.push('review_time = :now');
|
||||
reviewSetClauses.push('update_time = NOW()');
|
||||
|
||||
await ctx.model.query(
|
||||
`UPDATE wms_wave_pick_task_order
|
||||
SET ${reviewSetClauses.join(',\n ')}
|
||||
WHERE order_id = :orderId
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: {
|
||||
orderId,
|
||||
warehouseId,
|
||||
operatorUserId,
|
||||
now,
|
||||
},
|
||||
type: ctx.model.QueryTypes.UPDATE,
|
||||
}
|
||||
);
|
||||
|
||||
// 查询当前订单所属的波次拣货任务ID
|
||||
const taskRows = await ctx.model.query(
|
||||
`SELECT DISTINCT task_id
|
||||
FROM wms_wave_pick_task_order
|
||||
WHERE order_id = :orderId
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: { orderId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const taskId = Number(
|
||||
(Array.isArray(taskRows) && taskRows.length > 0 ? taskRows[0]?.task_id : 0)
|
||||
);
|
||||
|
||||
if (taskId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查该任务下是否所有订单都已复核完成
|
||||
const unreviewedRows = await ctx.model.query(
|
||||
`SELECT COUNT(*) AS cnt
|
||||
FROM wms_wave_pick_task_order
|
||||
WHERE task_id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
AND review_status != 1`,
|
||||
{
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
|
||||
const unreviewedCount = Number(
|
||||
(Array.isArray(unreviewedRows) && unreviewedRows.length > 0 ? unreviewedRows[0]?.cnt : 0)
|
||||
);
|
||||
|
||||
if (unreviewedCount > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 任务下所有订单均已复核完成,解绑车任务(失败不影响主流程)
|
||||
try {
|
||||
await this.unbindCartForTask(taskId, warehouseId, operatorUserId);
|
||||
ctx.logger.info(
|
||||
`[confirmRecheck] 车任务解绑成功, taskId=${taskId}, orderId=${orderId}, operatorUserId=${operatorUserId}`
|
||||
);
|
||||
} catch (unbindError) {
|
||||
ctx.logger.warn(
|
||||
`[confirmRecheck] 解绑车任务失败(复核已成功), taskId=${taskId}, orderId=${orderId}, error=${unbindError.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑车任务:清空波次拣货任务的车绑定、停用拣货车绑定记录、释放拣货车。
|
||||
* @param {number} taskId 波次拣货任务ID。
|
||||
* @param {number} warehouseId 仓库ID。
|
||||
* @param {number} operatorUserId 操作员用户ID。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async unbindCartForTask(taskId, warehouseId, operatorUserId) {
|
||||
const { ctx } = this;
|
||||
|
||||
// 1. 清空波次拣货任务的车绑定信息
|
||||
await ctx.model.query(
|
||||
`UPDATE wms_wave_pick_task
|
||||
SET current_cart_id = NULL,
|
||||
current_cart_code_snapshot = NULL,
|
||||
update_time = NOW()
|
||||
WHERE id = :taskId
|
||||
AND warehouse_id = :warehouseId`,
|
||||
{
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.UPDATE,
|
||||
}
|
||||
);
|
||||
|
||||
// 2. 停用拣货车绑定记录
|
||||
await ctx.model.query(
|
||||
`UPDATE wms_pick_task_cart_binding
|
||||
SET is_active = 0,
|
||||
unbind_user_id = :operatorUserId,
|
||||
unbind_time = NOW(),
|
||||
update_time = NOW()
|
||||
WHERE task_id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
AND is_active = 1`,
|
||||
{
|
||||
replacements: { taskId, warehouseId, operatorUserId },
|
||||
type: ctx.model.QueryTypes.UPDATE,
|
||||
}
|
||||
);
|
||||
|
||||
// 3. 释放拣货车(清空当前任务和绑定用户)
|
||||
await ctx.model.query(
|
||||
`UPDATE wms_pick_cart
|
||||
SET current_task_id = NULL,
|
||||
bind_user_id = NULL,
|
||||
last_seen_time = NOW(),
|
||||
update_time = NOW()
|
||||
WHERE warehouse_id = :warehouseId
|
||||
AND current_task_id = :taskId`,
|
||||
{
|
||||
replacements: { taskId, warehouseId },
|
||||
type: ctx.model.QueryTypes.UPDATE,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从多种兼容字段中解析订单ID。
|
||||
* @param {Object} data 请求体。
|
||||
|
||||
@ -10,7 +10,6 @@ const MAX_PAGE_SIZE = 200;
|
||||
const BATCH_LIST_MAX_PAGE_SIZE = 500;
|
||||
const DEFAULT_MAX_WAVE_QUANTITY = 500;
|
||||
const DEFAULT_MIN_GROUP_ORDER_FETCH_QUANTITY = 13;
|
||||
const WAVE_MANUAL_FETCH_FLAG = 'wave_manual_fetch';
|
||||
const FETCH_TASK_CACHE_KEY_PREFIX = 'wave:fetch:task:';
|
||||
const FETCH_TASK_CACHE_TTL_SECONDS = 60 * 60 * 2;
|
||||
const BATCH_CANCEL_TASK_CACHE_KEY_PREFIX = 'wave:batch-cancel:';
|
||||
@ -82,6 +81,17 @@ const BATCH_LIST_ASSIGNMENT_FILTER_SCHEMAS = Object.freeze({
|
||||
statsColumnPrefix: 'print',
|
||||
withErrorStatus: false,
|
||||
}),
|
||||
review: Object.freeze({
|
||||
fieldName: 'review_assignment_status',
|
||||
enumMap: Object.freeze({
|
||||
unreviewed: 'none',
|
||||
partially_reviewed: 'partial',
|
||||
reviewed: 'finished',
|
||||
}),
|
||||
caseInsensitive: true,
|
||||
statsColumnPrefix: 'review',
|
||||
withErrorStatus: true,
|
||||
}),
|
||||
});
|
||||
|
||||
class WaveService extends OrderBaseService {
|
||||
@ -936,16 +946,9 @@ class WaveService extends OrderBaseService {
|
||||
source: normalizedSource,
|
||||
transaction,
|
||||
});
|
||||
const orderFlagExpression = this.app.Sequelize.literal(`CASE
|
||||
WHEN order_flag IS NULL OR order_flag = '' THEN '${WAVE_MANUAL_FETCH_FLAG}'
|
||||
WHEN order_flag LIKE '%${WAVE_MANUAL_FETCH_FLAG}%' THEN order_flag
|
||||
ELSE CONCAT(order_flag, ',${WAVE_MANUAL_FETCH_FLAG}')
|
||||
END`);
|
||||
|
||||
await model.update({
|
||||
wave_id: waveId,
|
||||
wave_no: waveNo,
|
||||
order_flag: orderFlagExpression,
|
||||
}, {
|
||||
where: {
|
||||
id: { [Op.in]: candidateOrderIds },
|
||||
@ -1042,8 +1045,6 @@ class WaveService extends OrderBaseService {
|
||||
wave_id: allWaveIds.length > 0 ? allWaveIds[0] : 0,
|
||||
wave_ids: allWaveIds,
|
||||
order_ids: mergedOrderIds,
|
||||
auto_fetch_disabled: true,
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
...(reason ? { reason } : {}),
|
||||
};
|
||||
} catch (error) {
|
||||
@ -1235,6 +1236,16 @@ class WaveService extends OrderBaseService {
|
||||
return this.normalizeBatchListAssignmentStatusFilterByType(value, 'print');
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化波次列表复核状态筛选值(英文枚举)。
|
||||
*
|
||||
* @param {string} value 入参筛选值。
|
||||
* @return {string} 规范化后的筛选值,未传时返回空字符串。
|
||||
*/
|
||||
normalizeBatchListReviewAssignmentStatusFilter(value) {
|
||||
return this.normalizeBatchListAssignmentStatusFilterByType(value, 'review');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型获取波次分配状态筛选配置。
|
||||
*
|
||||
@ -1362,6 +1373,16 @@ class WaveService extends OrderBaseService {
|
||||
return this.buildBatchListAssignmentStatusFilterClauseByType(statusFilter, 'print');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建波次列表复核状态筛选 SQL 条件。
|
||||
*
|
||||
* @param {string} statusFilter 复核状态筛选值(none/partial/finished)。
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildBatchListReviewAssignmentFilterClause(statusFilter = '') {
|
||||
return this.buildBatchListAssignmentStatusFilterClauseByType(statusFilter, 'review');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按类型构建波次列表分配状态筛选 SQL 条件。
|
||||
*
|
||||
@ -1467,6 +1488,7 @@ class WaveService extends OrderBaseService {
|
||||
'storage_assignment_status',
|
||||
'express_assignment_status',
|
||||
'print_assignment_status',
|
||||
'review_assignment_status',
|
||||
];
|
||||
|
||||
const invalidFields = whereKeys.filter(key => !allowedFields.includes(key));
|
||||
@ -1600,6 +1622,9 @@ class WaveService extends OrderBaseService {
|
||||
const printAssignmentStatus = this.normalizeBatchListPrintAssignmentStatusFilter(
|
||||
normalizedWhere.print_assignment_status
|
||||
);
|
||||
const reviewAssignmentStatus = this.normalizeBatchListReviewAssignmentStatusFilter(
|
||||
normalizedWhere.review_assignment_status
|
||||
);
|
||||
|
||||
return {
|
||||
sql: conditions.length > 0 ? `\n AND ${conditions.join('\n AND ')}` : '',
|
||||
@ -1607,6 +1632,7 @@ class WaveService extends OrderBaseService {
|
||||
storageAssignmentStatus,
|
||||
expressAssignmentStatus,
|
||||
printAssignmentStatus,
|
||||
reviewAssignmentStatus,
|
||||
};
|
||||
}
|
||||
|
||||
@ -4005,6 +4031,8 @@ class WaveService extends OrderBaseService {
|
||||
const storageAssignmentFilterClause = this.buildBatchListStorageAssignmentFilterClause(whereClause.storageAssignmentStatus);
|
||||
const expressAssignmentFilterClause = this.buildBatchListExpressAssignmentFilterClause(whereClause.expressAssignmentStatus);
|
||||
const printAssignmentFilterClause = this.buildBatchListPrintAssignmentFilterClause(whereClause.printAssignmentStatus);
|
||||
const reviewAssignmentFilterClause = this.buildBatchListReviewAssignmentFilterClause(whereClause.reviewAssignmentStatus);
|
||||
const onlyTodo = Number(requestData.only_todo || 0);
|
||||
const baseBatchWhereSql = `
|
||||
warehouse_id = :warehouseId
|
||||
AND wave_status IN (:waveStatusList)
|
||||
@ -4041,7 +4069,10 @@ class WaveService extends OrderBaseService {
|
||||
SUM(CASE WHEN od.post_status = 'fin' THEN 1 ELSE 0 END) AS post_fin_count,
|
||||
SUM(CASE WHEN od.post_status = 'error' THEN 1 ELSE 0 END) AS post_error_count,
|
||||
SUM(CASE WHEN od.print_status = 'none' THEN 1 ELSE 0 END) AS print_none_count,
|
||||
SUM(CASE WHEN od.print_status = 'fin' THEN 1 ELSE 0 END) AS print_fin_count
|
||||
SUM(CASE WHEN od.print_status = 'fin' THEN 1 ELSE 0 END) AS print_fin_count,
|
||||
SUM(CASE WHEN od.inspection_status = 'fin' THEN 1 ELSE 0 END) AS review_fin_count,
|
||||
SUM(CASE WHEN od.inspection_status = 'error' THEN 1 ELSE 0 END) AS review_error_count,
|
||||
SUM(CASE WHEN od.inspection_status NOT IN ('fin', 'error') THEN 1 ELSE 0 END) AS review_none_count
|
||||
FROM (
|
||||
SELECT wave_id
|
||||
FROM wms_wave_batch
|
||||
@ -4054,6 +4085,8 @@ class WaveService extends OrderBaseService {
|
||||
${storageAssignmentFilterClause.sql}
|
||||
${expressAssignmentFilterClause.sql}
|
||||
${printAssignmentFilterClause.sql}
|
||||
${reviewAssignmentFilterClause.sql}
|
||||
${onlyTodo === 1 ? `\n AND COALESCE(wave_order_stats.order_total, 0) - COALESCE(wave_order_stats.review_fin_count, 0) > 0` : ''}
|
||||
`;
|
||||
|
||||
const listSql = `
|
||||
@ -4080,7 +4113,10 @@ class WaveService extends OrderBaseService {
|
||||
COALESCE(wave_order_stats.post_fin_count, 0) AS post_fin_count,
|
||||
COALESCE(wave_order_stats.post_error_count, 0) AS post_error_count,
|
||||
COALESCE(wave_order_stats.print_none_count, 0) AS print_none_count,
|
||||
COALESCE(wave_order_stats.print_fin_count, 0) AS print_fin_count
|
||||
COALESCE(wave_order_stats.print_fin_count, 0) AS print_fin_count,
|
||||
COALESCE(wave_order_stats.review_fin_count, 0) AS review_fin_count,
|
||||
COALESCE(wave_order_stats.review_error_count, 0) AS review_error_count,
|
||||
COALESCE(wave_order_stats.review_none_count, 0) AS review_none_count
|
||||
${batchListFromSql}
|
||||
ORDER BY wb.total_orders DESC, wb.wave_id DESC
|
||||
LIMIT :limit OFFSET :offset
|
||||
@ -4100,6 +4136,7 @@ class WaveService extends OrderBaseService {
|
||||
...storageAssignmentFilterClause.replacements,
|
||||
...expressAssignmentFilterClause.replacements,
|
||||
...printAssignmentFilterClause.replacements,
|
||||
...reviewAssignmentFilterClause.replacements,
|
||||
limit: pageSize,
|
||||
offset,
|
||||
},
|
||||
@ -4112,6 +4149,7 @@ class WaveService extends OrderBaseService {
|
||||
...storageAssignmentFilterClause.replacements,
|
||||
...expressAssignmentFilterClause.replacements,
|
||||
...printAssignmentFilterClause.replacements,
|
||||
...reviewAssignmentFilterClause.replacements,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
@ -4146,6 +4184,19 @@ class WaveService extends OrderBaseService {
|
||||
const expressErrorCount = Number(batch && batch.post_error_count || 0);
|
||||
const printNoneCount = Number(batch && batch.print_none_count || 0);
|
||||
const printFinCount = Number(batch && batch.print_fin_count || 0);
|
||||
const reviewFinCount = Number(batch && batch.review_fin_count || 0);
|
||||
const reviewErrorCount = Number(batch && batch.review_error_count || 0);
|
||||
const unreviewedOrderCount = orderCount - reviewFinCount;
|
||||
|
||||
// 复核状态判定:error 统一归入未复核
|
||||
let reviewAssignmentStatus;
|
||||
if (reviewErrorCount > 0 || orderCount === 0 || reviewFinCount === 0) {
|
||||
reviewAssignmentStatus = 'unreviewed';
|
||||
} else if (reviewFinCount === orderCount) {
|
||||
reviewAssignmentStatus = 'reviewed';
|
||||
} else {
|
||||
reviewAssignmentStatus = 'partially_reviewed';
|
||||
}
|
||||
|
||||
return {
|
||||
wave_id: waveId,
|
||||
@ -4173,6 +4224,8 @@ class WaveService extends OrderBaseService {
|
||||
partial: '部分打印',
|
||||
finished: '已打印',
|
||||
}),
|
||||
review_assignment_status: reviewAssignmentStatus,
|
||||
unreviewed_order_count: unreviewedOrderCount,
|
||||
};
|
||||
});
|
||||
|
||||
@ -4227,6 +4280,7 @@ class WaveService extends OrderBaseService {
|
||||
t.review_user_name,
|
||||
t.current_cart_id,
|
||||
t.current_cart_code_snapshot,
|
||||
c.cart_name AS cart_name,
|
||||
t.batch_no,
|
||||
t.device_id,
|
||||
t.start_time,
|
||||
@ -4236,6 +4290,7 @@ class WaveService extends OrderBaseService {
|
||||
t.create_time,
|
||||
t.update_time
|
||||
FROM wms_wave_pick_task t
|
||||
LEFT JOIN wms_pick_cart c ON c.id = t.current_cart_id AND c.warehouse_id = t.warehouse_id
|
||||
WHERE t.warehouse_id = :warehouseId
|
||||
${whereClause.sql}
|
||||
ORDER BY t.create_time DESC
|
||||
@ -4290,6 +4345,7 @@ class WaveService extends OrderBaseService {
|
||||
review_user_name: String(item && item.review_user_name || '').trim(),
|
||||
current_cart_id: Number(item && item.current_cart_id || 0),
|
||||
current_cart_code_snapshot: String(item && item.current_cart_code_snapshot || '').trim(),
|
||||
cart_name: String(item && item.cart_name || '').trim(),
|
||||
batch_no: String(item && item.batch_no || '').trim(),
|
||||
device_id: String(item && item.device_id || '').trim(),
|
||||
start_time: item && item.start_time || null,
|
||||
@ -6437,16 +6493,9 @@ class WaveService extends OrderBaseService {
|
||||
transaction,
|
||||
});
|
||||
|
||||
const orderFlagExpression = this.app.Sequelize.literal(`CASE
|
||||
WHEN order_flag IS NULL OR order_flag = '' THEN '${WAVE_MANUAL_FETCH_FLAG}'
|
||||
WHEN order_flag LIKE '%${WAVE_MANUAL_FETCH_FLAG}%' THEN order_flag
|
||||
ELSE CONCAT(order_flag, ',${WAVE_MANUAL_FETCH_FLAG}')
|
||||
END`);
|
||||
|
||||
await orderModel.update({
|
||||
wave_id: waveId,
|
||||
wave_no: waveNo,
|
||||
order_flag: orderFlagExpression,
|
||||
}, {
|
||||
where: {
|
||||
id: { [Op.in]: fetchableOrderIds },
|
||||
@ -9019,7 +9068,6 @@ class WaveService extends OrderBaseService {
|
||||
defaultQuantity: Number(defaultQuantity || 0),
|
||||
fetchMode: normalizedFetchMode,
|
||||
maxFetchQuantity: normalizedMaxFetchQuantity,
|
||||
autoFetchDisabledMarker: WAVE_MANUAL_FETCH_FLAG,
|
||||
});
|
||||
|
||||
const startedAt = Date.now();
|
||||
@ -9032,7 +9080,6 @@ class WaveService extends OrderBaseService {
|
||||
default_quantity: Number(defaultQuantity || 0),
|
||||
fetch_mode: normalizedFetchMode,
|
||||
...(normalizedFetchMode === 'single' ? { max_fetch_quantity: normalizedMaxFetchQuantity } : {}),
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
started_at: startedAt,
|
||||
});
|
||||
|
||||
@ -9087,7 +9134,6 @@ class WaveService extends OrderBaseService {
|
||||
fetch_mode: normalizedFetchMode,
|
||||
...(normalizedFetchMode === 'single' ? { max_fetch_quantity: normalizedMaxFetchQuantity } : {}),
|
||||
...(normalizedFetchMode === 'single' ? { limit_reached: reachedLimit } : {}),
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
started_at: startedAt,
|
||||
});
|
||||
}
|
||||
@ -9112,7 +9158,6 @@ class WaveService extends OrderBaseService {
|
||||
...(normalizedFetchMode === 'single' ? { max_fetch_quantity: normalizedMaxFetchQuantity } : {}),
|
||||
...(normalizedFetchMode === 'single' ? { limit_reached: reachedLimit } : {}),
|
||||
...(normalizedFetchMode === 'single' && reachedLimit ? { stop_reason: '达到最大抓取上限' } : {}),
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
started_at: startedAt,
|
||||
duration_ms: durationMs,
|
||||
});
|
||||
@ -9125,7 +9170,6 @@ class WaveService extends OrderBaseService {
|
||||
fetchMode: normalizedFetchMode,
|
||||
maxFetchQuantity: normalizedMaxFetchQuantity,
|
||||
reachedLimit,
|
||||
autoFetchDisabledMarker: WAVE_MANUAL_FETCH_FLAG,
|
||||
totalRequestQuantity,
|
||||
totalFetchedQuantity,
|
||||
durationMs,
|
||||
@ -9138,7 +9182,6 @@ class WaveService extends OrderBaseService {
|
||||
default_quantity: Number(defaultQuantity || 0),
|
||||
fetch_mode: normalizedFetchMode,
|
||||
...(normalizedFetchMode === 'single' ? { max_fetch_quantity: normalizedMaxFetchQuantity } : {}),
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
started_at: startedAt,
|
||||
duration_ms: Date.now() - startedAt,
|
||||
error: error && error.message ? error.message : `${error}`,
|
||||
@ -9174,7 +9217,6 @@ class WaveService extends OrderBaseService {
|
||||
default_quantity: defaultQuantity,
|
||||
fetch_mode: normalizedFetchMode,
|
||||
...(normalizedFetchMode === 'single' ? { max_fetch_quantity: normalizedMaxFetchQuantity } : {}),
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
submitted_at: Date.now(),
|
||||
});
|
||||
|
||||
@ -9185,7 +9227,6 @@ class WaveService extends OrderBaseService {
|
||||
defaultQuantity,
|
||||
fetchMode: normalizedFetchMode,
|
||||
maxFetchQuantity: normalizedMaxFetchQuantity,
|
||||
autoFetchDisabledMarker: WAVE_MANUAL_FETCH_FLAG,
|
||||
});
|
||||
|
||||
setImmediate(() => {
|
||||
@ -9204,7 +9245,6 @@ class WaveService extends OrderBaseService {
|
||||
defaultQuantity,
|
||||
fetchMode: normalizedFetchMode,
|
||||
maxFetchQuantity: normalizedMaxFetchQuantity,
|
||||
autoFetchDisabledMarker: WAVE_MANUAL_FETCH_FLAG,
|
||||
error: error && error.message ? error.message : error,
|
||||
stack: error && error.stack ? error.stack : '',
|
||||
});
|
||||
@ -9218,7 +9258,6 @@ class WaveService extends OrderBaseService {
|
||||
default_quantity: defaultQuantity,
|
||||
fetch_mode: normalizedFetchMode,
|
||||
...(normalizedFetchMode === 'single' ? { max_fetch_quantity: normalizedMaxFetchQuantity } : {}),
|
||||
auto_fetch_disabled_marker: WAVE_MANUAL_FETCH_FLAG,
|
||||
message: '任务已提交,后端异步处理中',
|
||||
});
|
||||
}
|
||||
@ -9925,16 +9964,9 @@ class WaveService extends OrderBaseService {
|
||||
transaction,
|
||||
});
|
||||
|
||||
const orderFlagExpression = this.app.Sequelize.literal(`CASE
|
||||
WHEN order_flag IS NULL OR order_flag = '' THEN '${WAVE_MANUAL_FETCH_FLAG}'
|
||||
WHEN order_flag LIKE '%${WAVE_MANUAL_FETCH_FLAG}%' THEN order_flag
|
||||
ELSE CONCAT(order_flag, ',${WAVE_MANUAL_FETCH_FLAG}')
|
||||
END`);
|
||||
|
||||
await orderModel.update({
|
||||
wave_id: waveId,
|
||||
wave_no: waveNo,
|
||||
order_flag: orderFlagExpression,
|
||||
}, {
|
||||
where: {
|
||||
id: { [Op.in]: fetchableOrderIds },
|
||||
@ -11420,8 +11452,11 @@ class WaveService extends OrderBaseService {
|
||||
/**
|
||||
* 公共拣货任务取消流程。
|
||||
*
|
||||
* 仅允许取消状态为 0/1/2 的任务。取消后会回收拣货车绑定、
|
||||
* 仅允许取消状态为 0/1/2/3 的任务。取消后会回收拣货车绑定、
|
||||
* 删除任务关联波次并将订单 wave_id 清空,使订单可重新参与后续策略抓取。
|
||||
* 当任务状态为 2(待复核)或 3(已完成)时,还会回退已拣货订单的
|
||||
* wms_wave_pick_task_order.pick_status 和 order_delivery.pick_status,
|
||||
* 使订单恢复为未拣货状态。
|
||||
*
|
||||
* @param {Object} [params={}] 取消参数。
|
||||
* @param {Array<number>} params.taskIds 任务ID列表。
|
||||
@ -11545,7 +11580,7 @@ class WaveService extends OrderBaseService {
|
||||
}
|
||||
|
||||
const taskStatus = Number(taskRow.status || 0);
|
||||
if (![ 0, 1, 2 ].includes(taskStatus)) {
|
||||
if (![ 0, 1, 2, 3 ].includes(taskStatus)) {
|
||||
const error = new Error('当前任务状态不允许取消');
|
||||
error.statusCode = 400;
|
||||
error.data = {
|
||||
@ -11646,6 +11681,46 @@ class WaveService extends OrderBaseService {
|
||||
});
|
||||
}
|
||||
|
||||
// 当任务状态为待复核(2)或已完成(3)时,回退订单拣货状态
|
||||
if ([ 2, 3 ].includes(taskStatus)) {
|
||||
await this.ctx.model.query(`
|
||||
UPDATE wms_wave_pick_task_order
|
||||
SET pick_status = 0,
|
||||
picked_time = NULL,
|
||||
update_time = NOW()
|
||||
WHERE task_id = :taskId
|
||||
AND warehouse_id = :warehouseId
|
||||
AND pick_status = 1
|
||||
`, {
|
||||
replacements: {
|
||||
taskId,
|
||||
warehouseId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
|
||||
const pickedOrderIds = [ ...new Set((Array.isArray(taskOrderRows) ? taskOrderRows : [])
|
||||
.map(row => Number(row && row.order_id || 0))
|
||||
.filter(orderId => Number.isInteger(orderId) && orderId > 0)) ];
|
||||
|
||||
if (pickedOrderIds.length > 0) {
|
||||
await orderModel.update({
|
||||
pick_status: 'padding',
|
||||
}, {
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
id: {
|
||||
[Op.in]: pickedOrderIds,
|
||||
},
|
||||
pick_status: 'fin',
|
||||
},
|
||||
transaction,
|
||||
validate: false,
|
||||
hooks: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.ctx.model.query(`
|
||||
UPDATE wms_wave_pick_task
|
||||
SET
|
||||
@ -11768,8 +11843,9 @@ class WaveService extends OrderBaseService {
|
||||
/**
|
||||
* 取消拣货任务并释放关联波次。
|
||||
*
|
||||
* 仅允许取消状态为 0/1/2 的任务。取消后会回收拣货车绑定、
|
||||
* 仅允许取消状态为 0/1/2/3 的任务。取消后会回收拣货车绑定、
|
||||
* 删除任务关联波次并将订单 wave_id 清空,使订单可重新参与后续策略抓取。
|
||||
* 当任务状态为 2(待复核)或 3(已完成)时,还会回退已拣货订单的拣货状态。
|
||||
*
|
||||
* @param {Object} [data={}] 请求参数。
|
||||
* @param {Array<number|string>} data.task_ids 任务ID数组。
|
||||
|
||||
@ -93,6 +93,7 @@ class PickService extends MainService {
|
||||
* @param {string} params.operatorName 操作人名称。
|
||||
* @param {Array<number>} params.orderIds 波次订单ID集合。
|
||||
* @param {string} [params.remark=''] 备注。
|
||||
* @param {number} [params.source=2] 任务来源:1-PDA扫码补任务,2-后台抓取,默认为2。
|
||||
* @return {Promise<{task_id: number, task_no: string}>} 创建结果。
|
||||
*/
|
||||
async createWavePickTask(params = {}) {
|
||||
@ -103,6 +104,7 @@ class PickService extends MainService {
|
||||
const pickMode = Number(params && params.pickMode || 2);
|
||||
const operatorId = Number(params && params.operatorId || 0);
|
||||
const operatorName = String(params && params.operatorName || '').trim() || 'system';
|
||||
const source = Number(params && params.source !== undefined ? params.source : 2);
|
||||
const remark = String(params && params.remark || '').trim();
|
||||
const normalizedOrderIds = [ ...new Set((Array.isArray(params && params.orderIds) ? params.orderIds : [])
|
||||
.map(id => Number(id || 0))
|
||||
@ -161,7 +163,7 @@ class PickService extends MainService {
|
||||
:waveId,
|
||||
:pickMode,
|
||||
0,
|
||||
2,
|
||||
:source,
|
||||
1,
|
||||
:orderCount,
|
||||
0,
|
||||
@ -178,6 +180,7 @@ class PickService extends MainService {
|
||||
warehouseId,
|
||||
waveId,
|
||||
pickMode,
|
||||
source,
|
||||
orderCount: normalizedOrderIds.length,
|
||||
operatorId,
|
||||
operatorName,
|
||||
@ -648,6 +651,7 @@ class PickService extends MainService {
|
||||
operatorName,
|
||||
orderIds: selectedOrderIds,
|
||||
remark: `pick.query keyword=${normalizedKeyword}`,
|
||||
source: 1,
|
||||
});
|
||||
|
||||
return this.success('ok', {
|
||||
|
||||
@ -974,6 +974,9 @@ class DeliveryOrderService extends Service {
|
||||
shopNick,
|
||||
sellerNick,
|
||||
buyerNick,
|
||||
buyerMessage,
|
||||
sellerMessage,
|
||||
remark,
|
||||
operatorName,
|
||||
operateTime,
|
||||
totalAmount,
|
||||
@ -1026,6 +1029,9 @@ class DeliveryOrderService extends Service {
|
||||
shop_nick: shopNick,
|
||||
seller_nick: sellerNick,
|
||||
buyer_nick: buyerNick,
|
||||
buyer_message: buyerMessage || '',
|
||||
seller_message: sellerMessage || '',
|
||||
remark: remark || '',
|
||||
operator_name: resolvedOperatorName,
|
||||
operate_time: operateTime ? new Date(operateTime) : null,
|
||||
total_amount: totalAmount ? parseFloat(totalAmount) : 0,
|
||||
@ -1042,7 +1048,7 @@ class DeliveryOrderService extends Service {
|
||||
logistics_area_code: logisticsAreaCode || '',
|
||||
is_urgency: isUrgency || 'N',
|
||||
invoice_flag: invoiceFlag || 'N',
|
||||
status: 'pedding',
|
||||
status: Number(step) >= DELIVERY_ORDER_STEP.APPROVED ? 'created' : 'pedding',
|
||||
step: Number.isInteger(Number(step)) ? Number(step) : DELIVERY_ORDER_STEP.PENDING_REVIEW,
|
||||
// 收件人信息
|
||||
name: receiverInfo?.name || '',
|
||||
|
||||
@ -1490,7 +1490,9 @@ class PickSystemService extends Service {
|
||||
t.warehouse_id,
|
||||
t.start_time,
|
||||
t.finish_time,
|
||||
t.ext_json
|
||||
t.ext_json,
|
||||
t.source,
|
||||
t.current_cart_id
|
||||
FROM wms_wave_pick_task t
|
||||
WHERE t.id = :taskId
|
||||
LIMIT 1
|
||||
@ -1504,7 +1506,8 @@ class PickSystemService extends Service {
|
||||
}
|
||||
|
||||
const taskPickUserId = Number(taskRow.pick_user_id || 0);
|
||||
if (!Number.isInteger(taskPickUserId) || taskPickUserId !== operatorId) {
|
||||
// source=2 后台抓取创建的任务 pick_user_id 可能为 0,此时跳过归属校验
|
||||
if (taskPickUserId !== 0 && (!Number.isInteger(taskPickUserId) || taskPickUserId !== operatorId)) {
|
||||
throw this.createBusinessError('当前操作人与任务创建人不一致,无权操作', 403);
|
||||
}
|
||||
|
||||
@ -1679,6 +1682,13 @@ class PickSystemService extends Service {
|
||||
throw this.createBusinessError('任务已完成或已取消,无法再次提交', 400);
|
||||
}
|
||||
|
||||
// source=2 表示后台抓取创建的任务,必须先绑定拣货车才能提交
|
||||
const taskSource = Number(taskRow && taskRow.source || 0);
|
||||
const taskCartId = Number(taskRow && taskRow.current_cart_id || 0);
|
||||
if (taskSource === 2 && taskCartId <= 0) {
|
||||
throw this.createBusinessError('后台抓取任务必须先绑定拣货车才能提交', 400);
|
||||
}
|
||||
|
||||
const transaction = await ctx.model.transaction();
|
||||
try {
|
||||
const taskOrderRows = await ctx.model.query(`
|
||||
|
||||
@ -313,6 +313,7 @@ class ShopsService extends Service {
|
||||
custom_name: shopRow.custom_name,
|
||||
status: shopRow.status,
|
||||
auth_expire_at: shopRow.auth_expire_at,
|
||||
access_token: shopRow.access_token,
|
||||
created_at: shopRow.created_at,
|
||||
updated_at: shopRow.updated_at,
|
||||
};
|
||||
@ -471,16 +472,18 @@ class ShopsService extends Service {
|
||||
const shopId = data.id !== undefined ? data.id : (data.shop_id !== undefined ? data.shop_id : data.shopId);
|
||||
const shop = await this.findShopById(shopId);
|
||||
const normalizedShopId = Number(shop.id);
|
||||
const referencedInterface = await ctx.model.ExpressInterface.findOne({
|
||||
const expressInterfaceCount = await ctx.model.ExpressInterface.count({
|
||||
where: {
|
||||
warehouse_id: this.getCurrentWarehouseId(),
|
||||
shop_id: normalizedShopId,
|
||||
},
|
||||
attributes: [ 'id' ],
|
||||
});
|
||||
|
||||
if (referencedInterface) {
|
||||
throw this.createError('店铺存在快递接口引用,无法删除', 409);
|
||||
if (expressInterfaceCount > 0) {
|
||||
throw this.createError(
|
||||
`该店铺已被 ${expressInterfaceCount} 个快递接口引用,请先解除绑定后再删除`,
|
||||
409
|
||||
);
|
||||
}
|
||||
|
||||
const deletedSuffix = `${Date.now()}_${crypto.randomBytes(4).toString('hex')}`;
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
const TABLE_NAME = 'wms_shops';
|
||||
const UNIQUE_INDEX_NAME = 'uk_warehouse_platform_shop_name';
|
||||
const PLAIN_INDEX_NAME = 'idx_warehouse_platform_shop_name';
|
||||
|
||||
/**
|
||||
* 检查指定表中是否存在指定名称的索引(通过 SHOW INDEX 做幂等判断)。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @param {string} tableName 表名。
|
||||
* @param {string} indexName 索引名。
|
||||
* @returns {Promise<boolean>} 索引是否存在。
|
||||
*/
|
||||
const hasIndex = async (queryInterface, tableName, indexName) => {
|
||||
const [rows] = await queryInterface.sequelize.query(
|
||||
`SHOW INDEX FROM \`${tableName}\` WHERE Key_name = :indexName`,
|
||||
{ replacements: { indexName } }
|
||||
);
|
||||
return rows && rows.length > 0;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 正向迁移:删除唯一约束,改为普通索引。
|
||||
* 原因:菜鸟 OAuth 授权回调时,预授权记录(status=0)与已授权记录(status=1)因同名店铺
|
||||
* 触发 UNIQUE KEY `uk_warehouse_platform_shop_name` 约束冲突,导致 MySQL UPDATE 失败。
|
||||
* 故将此唯一约束降为普通索引,仅保留查询性能。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @returns {Promise<void>} 无返回值。
|
||||
*/
|
||||
async up(queryInterface) {
|
||||
// 1. 删除唯一索引
|
||||
if (await hasIndex(queryInterface, TABLE_NAME, UNIQUE_INDEX_NAME)) {
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE \`${TABLE_NAME}\` DROP INDEX \`${UNIQUE_INDEX_NAME}\`;`
|
||||
);
|
||||
}
|
||||
|
||||
// 2. 添加普通索引(仅用于查询性能)
|
||||
if (!(await hasIndex(queryInterface, TABLE_NAME, PLAIN_INDEX_NAME))) {
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE \`${TABLE_NAME}\` ADD INDEX \`${PLAIN_INDEX_NAME}\` (warehouse_id, platform_code, shop_name);`
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 回滚迁移:恢复唯一约束。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @returns {Promise<void>} 无返回值。
|
||||
*/
|
||||
async down(queryInterface) {
|
||||
// 1. 删除普通索引
|
||||
if (await hasIndex(queryInterface, TABLE_NAME, PLAIN_INDEX_NAME)) {
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE \`${TABLE_NAME}\` DROP INDEX \`${PLAIN_INDEX_NAME}\`;`
|
||||
);
|
||||
}
|
||||
|
||||
// 2. 恢复唯一索引(幂等:已存在则跳过)
|
||||
if (!(await hasIndex(queryInterface, TABLE_NAME, UNIQUE_INDEX_NAME))) {
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE \`${TABLE_NAME}\` ADD UNIQUE INDEX \`${UNIQUE_INDEX_NAME}\` (warehouse_id, platform_code, shop_name);`
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -2888,5 +2888,105 @@
|
||||
"响应文档中新增 shop_nick 字段说明。"
|
||||
],
|
||||
"type": "updated"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-03",
|
||||
"date": "2026-06-07",
|
||||
"summary": "新增 order.pendingOrder.updateAddress:批量修改待处理订单收件地址,限制未分配快递时可用",
|
||||
"methods": [
|
||||
"order.pendingOrder.updateAddress"
|
||||
],
|
||||
"notes": [
|
||||
"新增 method:order.pendingOrder.updateAddress,免权限(isNeedAuth=false),需登录",
|
||||
"功能:批量修改待处理订单收件地址(name/mobile/tel/zip_code/province/city/area/town/detail_address)",
|
||||
"约束:仅 post_status='none'(未分配快递)的订单可修改;至少提供一个有效地址字段",
|
||||
"响应:返回 updated_count(实际更新行数)和 ids(请求订单ID数组)"
|
||||
],
|
||||
"type": "added"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-04",
|
||||
"date": "2026-06-07",
|
||||
"summary": "order.wave.wavePickTaskCancel 扩展可取消状态至 status=3,并新增拣货状态回退",
|
||||
"methods": [
|
||||
"order.wave.wavePickTaskCancel"
|
||||
],
|
||||
"notes": [
|
||||
"可取消状态从 [0,1,2] 扩展为 [0,1,2,3](status=3 已完成现在也可取消)",
|
||||
"取消 status=2(待复核)或 status=3(已完成)任务时,自动回退 wms_wave_pick_task_order.pick_status(1→0)和 order_delivery.pick_status(fin→padding)",
|
||||
"错误码 400 描述同步更新,补充 403 错误码说明"
|
||||
],
|
||||
"type": "updated"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-05",
|
||||
"date": "2026-06-07",
|
||||
"summary": "order.wave.wavePickTaskList 响应新增 cart_name 字段(拣货车名称)",
|
||||
"methods": [
|
||||
"order.wave.wavePickTaskList"
|
||||
],
|
||||
"notes": [
|
||||
"响应 list 子项新增 cart_name(string):通过 current_cart_id LEFT JOIN wms_pick_cart 表获取,未绑定拣货车时为空字符串。"
|
||||
],
|
||||
"type": "updated"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-06",
|
||||
"date": "2026-06-07",
|
||||
"summary": "pick.wavePickTaskComplete 新增后台抓取任务(source=2)拣货车绑定校验,未绑定拣货车时拒绝提交",
|
||||
"methods": [
|
||||
"pick.wavePickTaskComplete"
|
||||
],
|
||||
"notes": [
|
||||
"description 补充说明:后台抓取创建的任务(source=2)必须先绑定拣货车才能提交,否则返回 400。",
|
||||
"errors 中 400 错误补充:后台抓取任务(source=2)未绑定拣货车时拒绝提交,错误消息为\"后台抓取任务必须先绑定拣货车才能提交\"。"
|
||||
],
|
||||
"type": "updated"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-07",
|
||||
"date": "2026-06-07",
|
||||
"summary": "order.wave.batchList 文档修正:移除代码中不存在的 sync_assignment_status 引用",
|
||||
"methods": [
|
||||
"order.wave.batchList"
|
||||
],
|
||||
"notes": [
|
||||
"从 where 描述中移除 sync_assignment_status(代码 buildBatchListWhereClause allowedFields 中不存在该字段,BATCH_LIST_ASSIGNMENT_FILTER_SCHEMAS 中也无 review 之外的同步类型)。",
|
||||
"从 response list 描述中移除 sync_assignment_status(代码响应映射中仅返回 storage/express/print/review 四种 assignment_status,无 sync_assignment_status)。",
|
||||
"v2026.06.03-system-03 变更记录中声称新增的 sync_assignment_status 实际从未在代码中实现,本次仅为文档修正,不涉及代码变更。"
|
||||
],
|
||||
"type": "updated",
|
||||
"module": "order.wave"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-08",
|
||||
"date": "2026-06-07",
|
||||
"summary": "order.recheckOrder.confirmRecheck 补充后置行为说明:波次任务全部复核完成后自动解绑车任务",
|
||||
"methods": [
|
||||
"order.recheckOrder.confirmRecheck"
|
||||
],
|
||||
"notes": [
|
||||
"在 description 中补充:确认复核后,若该订单所属波次拣货任务下所有订单均已复核完成,则自动解绑车任务。解绑操作包括:清空 wms_wave_pick_task 的 current_cart_id/current_cart_code_snapshot、停用 wms_pick_task_cart_binding(is_active=0 并记录解绑人和时间)、释放 wms_pick_cart(清空 current_task_id/bind_user_id)。",
|
||||
"解绑失败仅记录 warn 日志,不影响复核主流程。",
|
||||
"入参和返回结构未变,仅补充行为说明。"
|
||||
],
|
||||
"type": "updated"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.07-system-10",
|
||||
"date": "2026-06-07",
|
||||
"summary": "移除 order.wave.groupFetch / singleFetch / fetch 响应中已废弃的 auto_fetch_disabled_marker 字段",
|
||||
"methods": [
|
||||
"order.wave.groupFetch",
|
||||
"order.wave.singleFetch",
|
||||
"order.wave.fetch"
|
||||
],
|
||||
"notes": [
|
||||
"auto_fetch_disabled_marker 字段已从代码 submitFetchTask 响应中移除,文档同步删除该字段的描述。",
|
||||
"auto_fetch_disabled 字段同样已从代码中移除,且原文档中不存在此字段(仅有 auto_fetch_disabled_marker),无需额外处理。",
|
||||
"涉及 method:order.wave.groupFetch、order.wave.singleFetch、order.wave.fetch,均移除 response 中的 auto_fetch_disabled_marker 字段。"
|
||||
],
|
||||
"type": "updated",
|
||||
"module": "order.wave"
|
||||
}
|
||||
]
|
||||
|
||||
@ -3850,6 +3850,120 @@
|
||||
"解析结果可直接回填到 createOrder 的收件人信息字段",
|
||||
"未识别到的字段返回空字符串"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.pendingOrder.updateAddress",
|
||||
"description": "批量修改待处理订单的收件地址信息。仅允许修改 post_status='none'(未分配快递)的订单;至少需要提供一个地址字段(name/mobile/tel/zip_code/province/city/area/town/detail_address),空值和纯空白会被忽略。更新成功后写入操作日志。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Bearer token"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "ids",
|
||||
"type": "number[]",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "订单ID 正整数数组,不能为空"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "收件人姓名"
|
||||
},
|
||||
{
|
||||
"name": "mobile",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "收件人手机号"
|
||||
},
|
||||
{
|
||||
"name": "tel",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "收件人电话"
|
||||
},
|
||||
{
|
||||
"name": "zip_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "邮编"
|
||||
},
|
||||
{
|
||||
"name": "province",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "省份"
|
||||
},
|
||||
{
|
||||
"name": "city",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "城市"
|
||||
},
|
||||
{
|
||||
"name": "area",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "区/县"
|
||||
},
|
||||
{
|
||||
"name": "town",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "镇/街道"
|
||||
},
|
||||
{
|
||||
"name": "detail_address",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "详细地址"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
{
|
||||
"name": "updated_count",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "实际更新的订单行数"
|
||||
},
|
||||
{
|
||||
"name": "ids",
|
||||
"type": "number[]",
|
||||
"required": true,
|
||||
"description": "请求的订单ID数组(原样返回)"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": 400,
|
||||
"message": "ids 不能为空"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"message": "至少需要提供一个地址字段进行修改"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"message": "仅允许修改 post_status='none'(未分配快递)的订单;若订单已分配快递则更新行数为 0,不会报错但实际无更新"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -3997,7 +4111,7 @@
|
||||
},
|
||||
{
|
||||
"method": "order.recheckOrder.confirmRecheck",
|
||||
"description": "按订单 ID 确认复核并记录复核任务到 wms_recheck_task(入参兼容 id/orderId)",
|
||||
"description": "按订单 ID 确认复核并记录复核任务到 wms_recheck_task(入参兼容 id/orderId)。确认复核后,若该订单所属波次拣货任务下所有订单均已复核完成,则自动解绑车任务:清空 wms_wave_pick_task 的车绑定信息(current_cart_id、current_cart_code_snapshot)、停用 wms_pick_task_cart_binding 绑定记录(is_active=0 并记录解绑人和时间)并释放 wms_pick_cart(清空 current_task_id、bind_user_id)。解绑失败仅记录 warn 日志,不影响复核主流程。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -4021,40 +4135,48 @@
|
||||
{
|
||||
"name": "order_id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "订单 ID"
|
||||
},
|
||||
{
|
||||
"name": "waybill_no",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "运单号"
|
||||
},
|
||||
{
|
||||
"name": "recheck_status",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "复核结果状态"
|
||||
},
|
||||
{
|
||||
"name": "recheck_time",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "复核时间(ISO 字符串)"
|
||||
},
|
||||
{
|
||||
"name": "review_no",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "复核任务编号"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单ID不能为空",
|
||||
"description": "订单ID不能为空"
|
||||
},
|
||||
{
|
||||
"code": "404",
|
||||
"message": "未找到对应订单",
|
||||
"description": "未找到对应订单"
|
||||
},
|
||||
{
|
||||
"code": "400",
|
||||
"message": "订单未拣货,不允许复核。",
|
||||
"description": "订单未拣货,不允许复核。"
|
||||
}
|
||||
]
|
||||
@ -5798,6 +5920,11 @@
|
||||
"type": "string",
|
||||
"description": "拣货人名称(兼容字段,旧客户端可能使用)"
|
||||
},
|
||||
{
|
||||
"name": "cart_name",
|
||||
"type": "string",
|
||||
"description": "拣货车名称(通过 current_cart_id 关联 wms_pick_cart 表获取,未绑定拣货车时为空字符串)"
|
||||
},
|
||||
{
|
||||
"name": "start_at",
|
||||
"type": "string",
|
||||
@ -5833,33 +5960,36 @@
|
||||
{
|
||||
"name": "total",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "总记录数"
|
||||
},
|
||||
{
|
||||
"name": "page",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "当前页码"
|
||||
},
|
||||
{
|
||||
"name": "page_size",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "每页大小"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"description": "缺少仓库上下文或参数格式错误"
|
||||
"message": "缺少仓库上下文或参数格式错误"
|
||||
},
|
||||
{
|
||||
"code": "500",
|
||||
"description": "查询失败"
|
||||
"message": "查询失败"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "order.wave.wavePickTaskCancel",
|
||||
"description": "取消拣货任务(批量),同时释放关联波次(物理删除波次记录,订单回池)、解绑拣货车、写操作日志。入参仅支持 task_ids(数组,必填),不再支持单个 task_id。操作人与仓库从请求上下文获取(例如当前登录用户上下文 ctx.user),若上下文缺失接口将返回错误。",
|
||||
"description": "取消拣货任务(批量)。可取消的状态:0=待开始、1=拣货中、2=待复核(拣货完成)、3=已完成,状态9(已取消)或其他状态不允许取消。同时释放关联波次(物理删除波次记录,订单回池)、解绑拣货车、写操作日志。对于status=2或3的任务,取消时会自动回退订单拣货状态:wms_wave_pick_task_order.pick_status(1→0)、order_delivery.pick_status(fin→padding)。入参仅支持 task_ids(数组,必填),不再支持单个 task_id。操作人与仓库从请求上下文获取(例如当前登录用户上下文 ctx.user),若上下文缺失接口将返回错误。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -5883,41 +6013,50 @@
|
||||
{
|
||||
"name": "cancelled_count",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "成功取消的任务数量"
|
||||
},
|
||||
{
|
||||
"name": "task_ids",
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"description": "处理的任务ID数组(若后端返回)"
|
||||
},
|
||||
{
|
||||
"name": "task_nos",
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"description": "处理的任务编号数组(若后端返回)"
|
||||
},
|
||||
{
|
||||
"name": "task_id",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "任务ID(历史兼容,若后端仍返回)"
|
||||
},
|
||||
{
|
||||
"name": "task_no",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "任务编号(历史兼容,若后端仍返回)"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"description": "任务状态不允许取消或入参缺失"
|
||||
"message": "任务状态不允许取消(仅允许status=0/1/2/3)或入参缺失"
|
||||
},
|
||||
{
|
||||
"code": "403",
|
||||
"message": "仅允许取消本人创建的任务(wavePickTaskCancelSelf 接口)"
|
||||
},
|
||||
{
|
||||
"code": "404",
|
||||
"description": "任务不存在"
|
||||
"message": "任务不存在"
|
||||
},
|
||||
{
|
||||
"code": "500",
|
||||
"description": "内部错误或事务回滚失败"
|
||||
"message": "内部错误或事务回滚失败"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -6736,12 +6875,6 @@
|
||||
"required": true,
|
||||
"description": "仓库默认抓取数量或全局默认值"
|
||||
},
|
||||
{
|
||||
"name": "auto_fetch_disabled_marker",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "手动抓取标记;值为 'wave_manual_fetch' 表示手动抓取"
|
||||
},
|
||||
{
|
||||
"name": "fetch_mode",
|
||||
"type": "string",
|
||||
@ -6813,12 +6946,6 @@
|
||||
"required": true,
|
||||
"description": "仓库默认抓取数量或全局默认值"
|
||||
},
|
||||
{
|
||||
"name": "auto_fetch_disabled_marker",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "手动抓取标记;值为 'wave_manual_fetch' 表示手动抓取"
|
||||
},
|
||||
{
|
||||
"name": "fetch_mode",
|
||||
"type": "string",
|
||||
@ -6896,12 +7023,6 @@
|
||||
"required": true,
|
||||
"description": "仓库默认抓取数量或全局默认值"
|
||||
},
|
||||
{
|
||||
"name": "auto_fetch_disabled_marker",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "手动抓取标记;值为 'wave_manual_fetch' 表示手动抓取"
|
||||
},
|
||||
{
|
||||
"name": "fetch_mode",
|
||||
"type": "string",
|
||||
@ -14210,7 +14331,7 @@
|
||||
},
|
||||
{
|
||||
"method": "pick.wavePickTaskComplete",
|
||||
"description": "完全提交拣货任务。支持 mode=1 全部确认,mode=2 部分确认(需传 order_ids)。提交后根据是否全部完成自动推进任务状态。",
|
||||
"description": "完全提交拣货任务。支持 mode=1 全部确认,mode=2 部分确认(需传 order_ids)。提交后根据是否全部完成自动推进任务状态。后台抓取创建的任务(source=2)必须先绑定拣货车才能提交,否则返回 400。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"isNeedRight": false,
|
||||
@ -14300,7 +14421,7 @@
|
||||
"errors": [
|
||||
{
|
||||
"code": 400,
|
||||
"message": "参数或业务状态不满足提交条件(如 task_id 不合法、mode 非 1/2、部分确认未传 order_ids、任务下无可确认订单等)。"
|
||||
"message": "参数或业务状态不满足提交条件(如 task_id 不合法、mode 非 1/2、部分确认未传 order_ids、任务下无可确认订单等)。后台抓取任务(source=2)未绑定拣货车时拒绝提交:\"后台抓取任务必须先绑定拣货车才能提交\"。"
|
||||
},
|
||||
{
|
||||
"code": 401,
|
||||
@ -19978,7 +20099,7 @@
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "筛选白名单字段(object,可选)。仅支持下列字段过滤,且禁止传入 warehouse_id / warehouseId:\n- wave_id(等值)\n- wave_no(模糊)\n- wave_type(等值)\n- wave_status(等值,接口固定叠加状态 0/1)\n- creator(模糊)\n- logistics_name(模糊)\n- item_part_type(等值)\n- item_part(模糊)\n- item_snapshot_key(模糊)\n- item_detail_machine(模糊)\n- distinguish_express(等值)\n- total_orders_min / total_orders_max(范围)\n- processed_orders_min / processed_orders_max(范围)\n- express_assignment_status(等值,string,可选,英文枚举,取值:unassigned、partially_assigned、assigned;语义:按快递分配聚合判断,assigned 表示聚合后全部 fin,partially_assigned 表示部分已分配且不含 error,unassigned 表示全 none 或包含 error(异常并入未分配集合))。\n- print_assignment_status(等值,string,可选,英文枚举,取值:unprinted、partially_printed、printed;语义:按打印分配聚合判断,printed 表示聚合后全部已打印)。\n- storage_assignment_status(等值,string,可选,取值:未分配、部分分配、已分配;默认不传不做限制)。过滤语义:已分配=聚合后全部 fin;部分分配=不含 error,且既不是全 none,也不是全 fin;未分配=全 none 或包含 error(异常并入未分配筛选集合)。说明:返回字段 storage_assignment_status 的展示值保持不变,包含 error 时仍可显示“分配异常”;此处 where 的过滤语义会把异常计入“未分配”,以避免把过滤语义与展示值混淆。\n- source(可选,number)来源过滤:0=普通波次(正常后台操作),1=管理后台策略任务,2=PDA策略任务;不传则不过滤。\n说明:express_assignment_status 与 print_assignment_status 要求使用英文枚举值;storage_assignment_status 仍向后兼容中文展示值。若传入的枚举值不在允许集合内,接口会返回 400(参数校验失败),并在 message 中说明错误字段与允许取值。\n- sync_assignment_status(等值,string,可选,英文枚举,取值:unsynced、partially_synced、synced;语义:按同步状态聚合判断,synced 表示全部 fin,partially_synced 表示部分已同步且不含 error,unsynced 表示全 padding 或包含 error(异常并入未同步集合))。\n- review_assignment_status(等值,string,可选,英文枚举:unreviewed、partially_reviewed、reviewed;分别表示未复核、部分复核、已复核)。"
|
||||
"description": "筛选白名单字段(object,可选)。仅支持下列字段过滤,且禁止传入 warehouse_id / warehouseId:\n- wave_id(等值)\n- wave_no(模糊)\n- wave_type(等值)\n- wave_status(等值,接口固定叠加状态 0/1)\n- creator(模糊)\n- logistics_name(模糊)\n- item_part_type(等值)\n- item_part(模糊)\n- item_snapshot_key(模糊)\n- item_detail_machine(模糊)\n- distinguish_express(等值)\n- total_orders_min / total_orders_max(范围)\n- processed_orders_min / processed_orders_max(范围)\n- express_assignment_status(等值,string,可选,英文枚举,取值:unassigned、partially_assigned、assigned;语义:按快递分配聚合判断,assigned 表示聚合后全部 fin,partially_assigned 表示部分已分配且不含 error,unassigned 表示全 none 或包含 error(异常并入未分配集合))。\n- print_assignment_status(等值,string,可选,英文枚举,取值:unprinted、partially_printed、printed;语义:按打印分配聚合判断,printed 表示聚合后全部已打印)。\n- storage_assignment_status(等值,string,可选,取值:未分配、部分分配、已分配;默认不传不做限制)。过滤语义:已分配=聚合后全部 fin;部分分配=不含 error,且既不是全 none,也不是全 fin;未分配=全 none 或包含 error(异常并入未分配筛选集合)。说明:返回字段 storage_assignment_status 的展示值保持不变,包含 error 时仍可显示“分配异常”;此处 where 的过滤语义会把异常计入“未分配”,以避免把过滤语义与展示值混淆。\n- source(可选,number)来源过滤:0=普通波次(正常后台操作),1=管理后台策略任务,2=PDA策略任务;不传则不过滤。\n说明:express_assignment_status 与 print_assignment_status 要求使用英文枚举值;storage_assignment_status 仍向后兼容中文展示值。若传入的枚举值不在允许集合内,接口会返回 400(参数校验失败),并在 message 中说明错误字段与允许取值。\n- review_assignment_status(等值,string,可选,英文枚举:unreviewed、partially_reviewed、reviewed;分别表示未复核、部分复核、已复核)。"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
@ -19986,7 +20107,7 @@
|
||||
"name": "list",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "波次列表,包含波次基础信息与状态汇总(order_count / storage_assignment_status / express_assignment_status / print_assignment_status / sync_assignment_status / review_assignment_status / unreviewed_order_count)。每条记录新增字段 source(number):来源标识,0=普通波次(正常后台操作),1=管理后台策略任务,2=PDA策略任务。"
|
||||
"description": "波次列表,包含波次基础信息与状态汇总(order_count / storage_assignment_status / express_assignment_status / print_assignment_status / review_assignment_status / unreviewed_order_count)。每条记录新增字段 source(number):来源标识,0=普通波次(正常后台操作),1=管理后台策略任务,2=PDA策略任务。"
|
||||
},
|
||||
{
|
||||
"name": "pagination",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user