Compare commits
8 Commits
b436b6dd9e
...
1ea2bc48f7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ea2bc48f7 | ||
|
|
793dca8375 | ||
|
|
64c24f963d | ||
|
|
9974cfab89 | ||
|
|
61467756e2 | ||
|
|
6c5e69c7d9 | ||
|
|
2795ae0758 | ||
|
|
a024a20356 |
@ -269,19 +269,7 @@ module.exports = app => {
|
|||||||
order_id: {
|
order_id: {
|
||||||
type: BIGINT(20).UNSIGNED,
|
type: BIGINT(20).UNSIGNED,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
comment: '订单ID(关联 wms_order.id),快递反馈建单时从 wms_order_express.order_id 填入',
|
comment: '订单ID(关联 wms_order_delivery.id)',
|
||||||
},
|
|
||||||
/** 发货订单ID */
|
|
||||||
order_delivery_id: {
|
|
||||||
type: BIGINT(20).UNSIGNED,
|
|
||||||
allowNull: true,
|
|
||||||
comment: '发货订单ID(关联 wms_order_delivery.id)',
|
|
||||||
},
|
|
||||||
/** 发货订单号(冗余) */
|
|
||||||
order_delivery_no: {
|
|
||||||
type: STRING(50),
|
|
||||||
allowNull: true,
|
|
||||||
comment: '发货订单号(冗余字段)',
|
|
||||||
},
|
},
|
||||||
/** 入库单ID */
|
/** 入库单ID */
|
||||||
entry_order_id: {
|
entry_order_id: {
|
||||||
@ -381,8 +369,8 @@ module.exports = app => {
|
|||||||
fields: [ 'waybill_id' ],
|
fields: [ 'waybill_id' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'idx_order_delivery_id',
|
name: 'idx_order_id',
|
||||||
fields: [ 'order_delivery_id' ],
|
fields: [ 'order_id' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'idx_entry_order_id',
|
name: 'idx_entry_order_id',
|
||||||
|
|||||||
@ -969,6 +969,23 @@ class InboxFunctionsService extends Service {
|
|||||||
const interceptOrderIds = [];
|
const interceptOrderIds = [];
|
||||||
const kickOutOrderIds = [];
|
const kickOutOrderIds = [];
|
||||||
|
|
||||||
|
// 批量查询散单的称重状态(wms_order_express.weighing_weight)
|
||||||
|
let weighingMap = {};
|
||||||
|
const scatterOrderIds = orders
|
||||||
|
.filter(o => o.wave_id > 0 && waveMap[o.wave_id] && waveMap[o.wave_id].wave_type === 2)
|
||||||
|
.map(o => o.id);
|
||||||
|
if (scatterOrderIds.length > 0) {
|
||||||
|
const expressRows = await ctx.model.OrderExpress.findAll({
|
||||||
|
attributes: [ 'order_id', 'weighing_weight' ],
|
||||||
|
where: { order_id: { [ctx.app.Sequelize.Op.in]: scatterOrderIds }, warehouse_id: warehouseId },
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
weighingMap = Object.fromEntries(
|
||||||
|
(Array.isArray(expressRows) ? expressRows : [])
|
||||||
|
.map(r => [ r.order_id, Number(r.weighing_weight || 0) ])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (const order of orders) {
|
for (const order of orders) {
|
||||||
const wave = waveMap[order.wave_id];
|
const wave = waveMap[order.wave_id];
|
||||||
const orderId = order.id;
|
const orderId = order.id;
|
||||||
@ -980,8 +997,9 @@ class InboxFunctionsService extends Service {
|
|||||||
// 团购波次:未复核 → 拦截
|
// 团购波次:未复核 → 拦截
|
||||||
needIntercept = order.inspection_status !== 'fin';
|
needIntercept = order.inspection_status !== 'fin';
|
||||||
} else if (wave.wave_type === 2) {
|
} else if (wave.wave_type === 2) {
|
||||||
// 散单波次:未称重视同可拦截(订单表无称重状态,默认拦截)
|
// 散单波次:未称重 → 拦截(weighing_weight = 0 表示未称重)
|
||||||
needIntercept = true;
|
const weight = weighingMap[orderId] ?? 0;
|
||||||
|
needIntercept = weight <= 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 无波次订单:直接拦截
|
// 无波次订单:直接拦截
|
||||||
@ -1014,6 +1032,23 @@ class InboxFunctionsService extends Service {
|
|||||||
{ is_intercept: 'Y' },
|
{ is_intercept: 'Y' },
|
||||||
{ where: { order_id: { [ctx.app.Sequelize.Op.in]: interceptOrderIds }, warehouse_id: warehouseId } }
|
{ where: { order_id: { [ctx.app.Sequelize.Op.in]: interceptOrderIds }, warehouse_id: warehouseId } }
|
||||||
);
|
);
|
||||||
|
// 写入操作日志(失败不影响主流程)
|
||||||
|
try {
|
||||||
|
const logService = ctx.service?.systems?.operationLog;
|
||||||
|
if (logService && typeof logService.createOperationLogs === 'function') {
|
||||||
|
await logService.createOperationLogs(
|
||||||
|
interceptOrderIds.map(oid => ({
|
||||||
|
businessType: 'order',
|
||||||
|
businessId: String(warehouseId),
|
||||||
|
operationCode: 'ORDER_INTERCEPT_REQUEST',
|
||||||
|
operator: { id: '0', name: groupName || 'AI系统' },
|
||||||
|
extras: { warehouseId, orderId: oid, newInterceptStatus: 'requested' },
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (logErr) {
|
||||||
|
ctx.logger.warn(`[inbox functions] 写入拦截操作日志失败: ${logErr.message}`);
|
||||||
|
}
|
||||||
ctx.logger.info(
|
ctx.logger.info(
|
||||||
`[inbox functions] 设置拦截状态: ${interceptOrderIds.length} 个订单`
|
`[inbox functions] 设置拦截状态: ${interceptOrderIds.length} 个订单`
|
||||||
);
|
);
|
||||||
@ -1311,11 +1346,30 @@ class InboxFunctionsService extends Service {
|
|||||||
waveMap = Object.fromEntries(waves.map(w => [ w.wave_id, w ]));
|
waveMap = Object.fromEntries(waves.map(w => [ w.wave_id, w ]));
|
||||||
}
|
}
|
||||||
const interceptOrderIds = [];
|
const interceptOrderIds = [];
|
||||||
|
// 批量查询散单的称重状态
|
||||||
|
const scatterIds = orders
|
||||||
|
.filter(o => o.wave_id > 0 && waveMap[o.wave_id] && waveMap[o.wave_id].wave_type === 2)
|
||||||
|
.map(o => o.id);
|
||||||
|
const wMap = {};
|
||||||
|
if (scatterIds.length > 0) {
|
||||||
|
const er = await ctx.model.OrderExpress.findAll({
|
||||||
|
attributes: [ 'order_id', 'weighing_weight' ],
|
||||||
|
where: { order_id: { [ctx.app.Sequelize.Op.in]: scatterIds }, warehouse_id: warehouseId },
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
for (const r of (Array.isArray(er) ? er : [])) {
|
||||||
|
wMap[r.order_id] = Number(r.weighing_weight || 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const order of orders) {
|
for (const order of orders) {
|
||||||
const wave = waveMap[order.wave_id];
|
const wave = waveMap[order.wave_id];
|
||||||
let needIntercept = false;
|
let needIntercept = false;
|
||||||
if (order.wave_id > 0 && wave) {
|
if (order.wave_id > 0 && wave) {
|
||||||
needIntercept = wave.wave_type === 1 ? order.inspection_status !== 'fin' : true;
|
if (wave.wave_type === 1) {
|
||||||
|
needIntercept = order.inspection_status !== 'fin';
|
||||||
|
} else {
|
||||||
|
needIntercept = (wMap[order.id] ?? 0) <= 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
needIntercept = true;
|
needIntercept = true;
|
||||||
}
|
}
|
||||||
@ -1330,6 +1384,23 @@ class InboxFunctionsService extends Service {
|
|||||||
{ is_intercept: 'Y' },
|
{ is_intercept: 'Y' },
|
||||||
{ where: { order_id: { [ctx.app.Sequelize.Op.in]: interceptOrderIds }, warehouse_id: warehouseId } }
|
{ where: { order_id: { [ctx.app.Sequelize.Op.in]: interceptOrderIds }, warehouse_id: warehouseId } }
|
||||||
);
|
);
|
||||||
|
// 写入操作日志(失败不影响主流程)
|
||||||
|
try {
|
||||||
|
const logSvc = ctx.service?.systems?.operationLog;
|
||||||
|
if (logSvc && typeof logSvc.createOperationLogs === 'function') {
|
||||||
|
await logSvc.createOperationLogs(
|
||||||
|
interceptOrderIds.map(oid => ({
|
||||||
|
businessType: 'order',
|
||||||
|
businessId: String(warehouseId),
|
||||||
|
operationCode: 'ORDER_INTERCEPT_REQUEST',
|
||||||
|
operator: { id: '0', name: groupName || 'AI系统' },
|
||||||
|
extras: { warehouseId, orderId: oid, newInterceptStatus: 'requested' },
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (logErr) {
|
||||||
|
ctx.logger.warn(`[inbox functions] 取消拦截-写入操作日志失败: ${logErr.message}`);
|
||||||
|
}
|
||||||
ctx.logger.info(`[inbox functions] 取消拦截-设置拦截状态: ${interceptOrderIds.length} 个订单`);
|
ctx.logger.info(`[inbox functions] 取消拦截-设置拦截状态: ${interceptOrderIds.length} 个订单`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,27 @@ class OpenapiOrderService extends MainService {
|
|||||||
|
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
|
|
||||||
|
// 写入拦截操作日志(失败不影响主流程)
|
||||||
|
try {
|
||||||
|
const { ctx: ctx2 } = this;
|
||||||
|
if (ctx2.model && ctx2.model.OperationLog) {
|
||||||
|
const whId2 = ctx2.user && ctx2.user.store_id ? Number(ctx2.user.store_id) : 0;
|
||||||
|
await ctx2.model.OperationLog.create({
|
||||||
|
business_type: 'order',
|
||||||
|
business_id: String(existingOrder.id),
|
||||||
|
operation_code: 'ORDER_INTERCEPT_REQUEST',
|
||||||
|
operator_id: ctx2.user?.employees_id || ctx2.user?.id || null,
|
||||||
|
operator_name: ctx2.user?.employees_name || 'OpenAPI',
|
||||||
|
external_log_type: 'NONE',
|
||||||
|
warehouse_id: whId2 || null,
|
||||||
|
platform_code: 'OPENAPI',
|
||||||
|
message: 'OpenAPI取消订单-触发拦截',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (logErr) {
|
||||||
|
this.ctx.logger.warn('[OpenAPIOrderCancel] 写入拦截操作日志失败,不影响主流程', logErr);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建售后工单 + 通知快递群(失败不影响主流程)
|
// 创建售后工单 + 通知快递群(失败不影响主流程)
|
||||||
try {
|
try {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
|
|||||||
@ -208,6 +208,26 @@ class orderServer extends MainService {
|
|||||||
|
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
|
|
||||||
|
// 写入拦截操作日志(失败不影响主流程)
|
||||||
|
try {
|
||||||
|
if (ctx.model && ctx.model.OperationLog) {
|
||||||
|
const customerId2 = String(info.customerId || '').trim();
|
||||||
|
await ctx.model.OperationLog.create({
|
||||||
|
business_type: 'order',
|
||||||
|
business_id: String(existingOrder.id),
|
||||||
|
operation_code: 'ORDER_INTERCEPT_REQUEST',
|
||||||
|
operator_id: null,
|
||||||
|
operator_name: customerId2 ? `qimen:${customerId2}` : 'qimen',
|
||||||
|
external_log_type: 'NONE',
|
||||||
|
warehouse_id: info.warehouseId || null,
|
||||||
|
platform_code: customerId2 || 'SYSTEM',
|
||||||
|
message: '奇门取消订单-触发拦截',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (logErr) {
|
||||||
|
ctx.logger.warn('[QimenOrderCancel] 写入拦截操作日志失败,不影响主流程', logErr);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建售后工单 + 通知快递群(失败不影响主流程)
|
// 创建售后工单 + 通知快递群(失败不影响主流程)
|
||||||
try {
|
try {
|
||||||
await ctx.service.systems.afterSale.createInterceptWorkOrdersAndNotify({
|
await ctx.service.systems.afterSale.createInterceptWorkOrdersAndNotify({
|
||||||
@ -239,6 +259,18 @@ class orderServer extends MainService {
|
|||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 同步更新运单表拦截标记
|
||||||
|
try {
|
||||||
|
await ctx.model.OrderExpress.update(
|
||||||
|
{ is_intercept: 'Y' },
|
||||||
|
{ where: { order_id: existingOrder.id, warehouse_id: info.warehouseId }, transaction }
|
||||||
|
);
|
||||||
|
} catch (expressErr) {
|
||||||
|
ctx.logger.warn(
|
||||||
|
`[qimen order cancel] 更新运单拦截标记失败(sync), orderId=${existingOrder.id}, error=${expressErr.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
await this.sendCancelInterceptNotice({
|
await this.sendCancelInterceptNotice({
|
||||||
orderCode,
|
orderCode,
|
||||||
|
|||||||
@ -314,8 +314,8 @@ class AfterSaleMethodService extends MainService {
|
|||||||
status: 'pending',
|
status: 'pending',
|
||||||
waybill_id: waybillId || null,
|
waybill_id: waybillId || null,
|
||||||
waybill_no: redundantFields.waybill_no || null,
|
waybill_no: redundantFields.waybill_no || null,
|
||||||
order_delivery_id: orderDeliveryId || null,
|
order_id: orderDeliveryId || null,
|
||||||
order_delivery_no: redundantFields.order_delivery_no || null,
|
order_no: redundantFields.order_no || null,
|
||||||
entry_order_id: entryOrderId || null,
|
entry_order_id: entryOrderId || null,
|
||||||
entry_order_no: redundantFields.entry_order_no || null,
|
entry_order_no: redundantFields.entry_order_no || null,
|
||||||
order_stockout_id: orderStockoutId || null,
|
order_stockout_id: orderStockoutId || null,
|
||||||
@ -373,7 +373,7 @@ class AfterSaleMethodService extends MainService {
|
|||||||
attributes: [ 'delivery_order_code' ],
|
attributes: [ 'delivery_order_code' ],
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
redundant.order_delivery_no = order ? order.delivery_order_code || null : null;
|
redundant.order_no = order ? order.delivery_order_code || null : null;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.logger.warn(`[afterSale._resolveRedundantFields] 查询发货订单号失败: ${err.message}`);
|
ctx.logger.warn(`[afterSale._resolveRedundantFields] 查询发货订单号失败: ${err.message}`);
|
||||||
|
|||||||
@ -2294,6 +2294,18 @@ class PendingOrderService extends OrderBaseService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// 同步更新运单表拦截标记
|
||||||
|
try {
|
||||||
|
const { Op: cancelOp } = this.app.Sequelize;
|
||||||
|
await this.ctx.model.OrderExpress.update(
|
||||||
|
{ is_intercept: 'Y' },
|
||||||
|
{ where: { order_id: { [cancelOp.in]: syncedOrderIds }, warehouse_id: warehouseId } }
|
||||||
|
);
|
||||||
|
} catch (expressErr) {
|
||||||
|
this.ctx.logger.warn(
|
||||||
|
`[PendingOrderService.cancelOrder] 更新运单拦截标记失败, count=${syncedOrderIds.length}, error=${expressErr.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
this.ctx.logger.info(
|
this.ctx.logger.info(
|
||||||
`[PendingOrderService.cancelOrder] 订单已同步,不可取消,已转为拦截处理,订单ID: ${syncedOrderIds.join(',')}`
|
`[PendingOrderService.cancelOrder] 订单已同步,不可取消,已转为拦截处理,订单ID: ${syncedOrderIds.join(',')}`
|
||||||
);
|
);
|
||||||
|
|||||||
@ -3611,15 +3611,15 @@ class RecheckOrderService extends OrderBaseService {
|
|||||||
throw new Error('拦截状态更新失败,请稍后重试');
|
throw new Error('拦截状态更新失败,请稍后重试');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步更新运单表:仅对已标记拦截的运单设置退回标记
|
// 同步更新运单表:标记拦截 + 退回
|
||||||
try {
|
try {
|
||||||
await ctx.model.OrderExpress.update(
|
await ctx.model.OrderExpress.update(
|
||||||
{ is_back: 'Y' },
|
{ is_intercept: 'Y', is_back: 'Y' },
|
||||||
{ where: { order_id: orderId, warehouse_id: warehouseId, is_intercept: 'Y' } }
|
{ where: { order_id: orderId, warehouse_id: warehouseId } }
|
||||||
);
|
);
|
||||||
} catch (expressErr) {
|
} catch (expressErr) {
|
||||||
ctx.logger.warn(
|
ctx.logger.warn(
|
||||||
`[recheckOrder.confirmIntercept] 更新运单退回标记失败, orderId=${orderId}, error=${expressErr.message}`
|
`[recheckOrder.confirmIntercept] 更新运单拦截/退回标记失败, orderId=${orderId}, error=${expressErr.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -341,14 +341,16 @@ class AfterSaleService extends Service {
|
|||||||
const related = {};
|
const related = {};
|
||||||
|
|
||||||
// ======= 1. 关联订单详情 =======
|
// ======= 1. 关联订单详情 =======
|
||||||
if (afterSale.order_delivery_id) {
|
// 统一使用 order_id
|
||||||
|
const resolvedOrderId = afterSale.order_id;
|
||||||
|
if (resolvedOrderId) {
|
||||||
try {
|
try {
|
||||||
related.order = await this._resolveOrderDetail(
|
related.order = await this._resolveOrderDetail(
|
||||||
afterSale.order_delivery_id,
|
resolvedOrderId,
|
||||||
afterSale.warehouse_id
|
afterSale.warehouse_id
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.logger.warn(`[_enrichAfterSaleDetail] 解析订单详情失败 id=${afterSale.order_delivery_id}: ${err.message}`);
|
ctx.logger.warn(`[_enrichAfterSaleDetail] 解析订单详情失败 id=${resolvedOrderId}: ${err.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,6 +608,9 @@ class AfterSaleService extends Service {
|
|||||||
// 数量
|
// 数量
|
||||||
items_count: order.items_count,
|
items_count: order.items_count,
|
||||||
items_total: order.items_total,
|
items_total: order.items_total,
|
||||||
|
// 金额
|
||||||
|
total_amount: order.total_amount,
|
||||||
|
item_amount: order.item_amount,
|
||||||
// 收件人 / 发件人 / 明细 / 打包视频
|
// 收件人 / 发件人 / 明细 / 打包视频
|
||||||
recipient,
|
recipient,
|
||||||
sender,
|
sender,
|
||||||
|
|||||||
@ -0,0 +1,40 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
const { STRING, BIGINT } = Sequelize;
|
||||||
|
const tableName = 'wms_after_sale';
|
||||||
|
|
||||||
|
// 检查列是否存在
|
||||||
|
const [columns] = await queryInterface.sequelize.query(
|
||||||
|
`SHOW COLUMNS FROM \`${tableName}\` LIKE 'order_delivery_id'`
|
||||||
|
);
|
||||||
|
if (Array.isArray(columns) && columns.length > 0) {
|
||||||
|
await queryInterface.removeColumn(tableName, 'order_delivery_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
const [columns2] = await queryInterface.sequelize.query(
|
||||||
|
`SHOW COLUMNS FROM \`${tableName}\` LIKE 'order_delivery_no'`
|
||||||
|
);
|
||||||
|
if (Array.isArray(columns2) && columns2.length > 0) {
|
||||||
|
await queryInterface.removeColumn(tableName, 'order_delivery_no');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
const { STRING, BIGINT } = Sequelize;
|
||||||
|
const tableName = 'wms_after_sale';
|
||||||
|
|
||||||
|
await queryInterface.addColumn(tableName, 'order_delivery_id', {
|
||||||
|
type: BIGINT(20).UNSIGNED,
|
||||||
|
allowNull: true,
|
||||||
|
comment: '发货订单ID(关联 wms_order_delivery.id)',
|
||||||
|
});
|
||||||
|
|
||||||
|
await queryInterface.addColumn(tableName, 'order_delivery_no', {
|
||||||
|
type: STRING(50),
|
||||||
|
allowNull: true,
|
||||||
|
comment: '发货订单号(冗余字段)',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user