diff --git a/app/service/inbox/functions.js b/app/service/inbox/functions.js index 64ee1cc..5fac707 100644 --- a/app/service/inbox/functions.js +++ b/app/service/inbox/functions.js @@ -1032,6 +1032,23 @@ class InboxFunctionsService extends Service { { is_intercept: 'Y' }, { 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( `[inbox functions] 设置拦截状态: ${interceptOrderIds.length} 个订单` ); @@ -1367,6 +1384,23 @@ class InboxFunctionsService extends Service { { is_intercept: 'Y' }, { 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} 个订单`); } } diff --git a/app/service/openapiMethods/order.js b/app/service/openapiMethods/order.js index 50c55e4..9fd9b6a 100644 --- a/app/service/openapiMethods/order.js +++ b/app/service/openapiMethods/order.js @@ -79,6 +79,27 @@ class OpenapiOrderService extends MainService { 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 { const { ctx } = this; diff --git a/app/service/qimenMethods/order.js b/app/service/qimenMethods/order.js index a390248..dc40180 100644 --- a/app/service/qimenMethods/order.js +++ b/app/service/qimenMethods/order.js @@ -208,6 +208,26 @@ class orderServer extends MainService { 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 { await ctx.service.systems.afterSale.createInterceptWorkOrdersAndNotify({