From fbd9ac2326650c9bb2f6f77f32066f11eb854c30 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Wed, 26 Aug 2026 17:22:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(receiving):=20=E6=94=B6=E8=B4=A7=E5=8D=95?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=A8=A1=E6=9D=BF=E8=B0=83=E6=95=B4=EF=BC=88?= =?UTF-8?q?=E8=BD=A6=E7=89=8C/=E5=BF=AB=E9=80=92=E5=8D=95=E5=8F=B7?= =?UTF-8?q?=E6=9C=AA=E7=99=BB=E8=AE=B0=E6=98=BE=E7=A4=BA=E6=97=A0=EF=BC=89?= =?UTF-8?q?=E5=B9=B6=E6=96=B0=E5=A2=9E=E5=AE=8C=E6=88=90=E6=97=B6=E6=9C=AA?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=95=86=E5=93=81=E8=B4=A7=E4=B8=BB=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/notification_webhook.js | 3 +- app/service/systems/notice/index.js | 10 ++ app/service/systems/storage/receiving.js | 115 ++++++++++++++++++++--- methods/changes/warehouse.json | 31 ++++++ 4 files changed, 146 insertions(+), 13 deletions(-) diff --git a/app/model/notification_webhook.js b/app/model/notification_webhook.js index 86f6c8d..ce94b33 100644 --- a/app/model/notification_webhook.js +++ b/app/model/notification_webhook.js @@ -41,7 +41,8 @@ module.exports = app => { Object.freeze({ code: 'receiving_completed', name: '收货完成', business: 'receiving', description: '收货单完成后的通知' }), Object.freeze({ code: 'receiving_rejected', name: '收货驳回', business: 'receiving', description: '收货单被驳回并恢复为收货中后的通知' }), Object.freeze({ code: 'receiving_reviewed', name: '收货审核完成', business: 'receiving', description: '收货单批量审核通过后的通知' }), - Object.freeze({ code: 'receiving_store_bound', name: '收货单创建/绑定货主', business: 'receiving', description: '收货单创建或首次绑定货主时提醒货主填写车牌号/快递号的通知' }), + Object.freeze({ code: 'receiving_store_bound', name: '收货单创建/绑定货主', business: 'receiving', description: '收货单创建或首次绑定货主时的通知(展示车牌号/快递单号登记状态,未登记显示无)' }), + Object.freeze({ code: 'receiving_store_unmatched', name: '收货完成未匹配商品提醒', business: 'receiving', description: '收货单完成时存在未匹配商品明细,通知货主核实商品资料' }), Object.freeze({ code: 'order_sync_completed', name: '订单同步完成', business: 'order', description: '本地创建入口同步完成后的通知' }), Object.freeze({ code: 'order_cancel_intercepted', name: '订单取消拦截', business: 'order', description: '订单取消失败并触发拦截执行后的通知' }), Object.freeze({ code: 'wave_strategy_quick_scan_failed', name: '波次策略兜底扫描失败', business: 'order', description: '定时兜底扫描任务在仓库维度触发失败时通知' }), diff --git a/app/service/systems/notice/index.js b/app/service/systems/notice/index.js index 269d58f..0f30e6f 100644 --- a/app/service/systems/notice/index.js +++ b/app/service/systems/notice/index.js @@ -27,6 +27,7 @@ const DEFAULT_REGISTERED_EVENT_CODES = Object.freeze([ 'receiving_rejected', 'receiving_reviewed', 'receiving_store_bound', + 'receiving_store_unmatched', 'order_cancel_intercepted', 'wave_strategy_quick_scan_failed', 'store_warehouse_print_quantity_adjusted', @@ -63,6 +64,15 @@ const FIXED_GROUP_SUBSCRIPTIONS = Object.freeze({ ]), }), ]), + receiving_store_unmatched: Object.freeze([ + Object.freeze({ + groupType: 'store', + subType: 'receiving', + fallbackTargets: Object.freeze([ + Object.freeze({ groupType: 'store', subType: 'after_sales' }), + ]), + }), + ]), order_cancel_intercepted: Object.freeze([ Object.freeze({ groupType: 'warehouse', subType: 'exception' }), ]), diff --git a/app/service/systems/storage/receiving.js b/app/service/systems/storage/receiving.js index 56a4c9f..5af09f4 100644 --- a/app/service/systems/storage/receiving.js +++ b/app/service/systems/storage/receiving.js @@ -1494,8 +1494,8 @@ class ReceivingService extends Service { } /** - * 发送收货单创建/首次绑定货主通知(receiving_store_bound),提醒货主确认/补填车牌号或快递单号。 - * 已填写车牌号或快递单号时,文案展示已登记信息;均未填写时才提示及时补充。 + * 发送收货单创建/首次绑定货主通知(receiving_store_bound)。 + * 车牌号/快递单号始终展示登记状态:已登记显示「车牌号:X 已登记」「快递单号:X 已登记」,未登记显示「车牌号:无」「快递单号:无」。 * 路由由 notice 固定订阅回退链处理:货主收货群 → 无则货主售后群 → 均无则仓库异常群。 * @param {Object} options 发送参数 * @param {Object} options.receiving 收货单快照 @@ -1525,16 +1525,10 @@ class ReceivingService extends Service { const licensePlate = String(receiving.license_plate || '').trim(); const trackingNumber = String(receiving.tracking_number || '').trim(); - const vehicleInfoLines = []; - if (licensePlate) { - vehicleInfoLines.push(`车牌号:${licensePlate} 已登记`); - } - if (trackingNumber) { - vehicleInfoLines.push(`快递单号:${trackingNumber} 已登记`); - } - if (vehicleInfoLines.length === 0) { - vehicleInfoLines.push('请确认是否已填写车牌号或快递单号,未填写请及时补充'); - } + const vehicleInfoLines = [ + licensePlate ? `车牌号:${licensePlate} 已登记` : '车牌号:无', + trackingNumber ? `快递单号:${trackingNumber} 已登记` : '快递单号:无', + ]; const contentLines = [ `收货单号:${receivingNumber} 正在收货`, @@ -4309,6 +4303,76 @@ class ReceivingService extends Service { }); } + /** + * 发送收货完成未匹配商品货主通知(receiving_store_unmatched),提醒货主核实未匹配商品资料。 + * 路由由 notice 固定订阅回退链处理:货主收货群 → 无则货主售后群 → 均无则仓库异常群。 + * @param {Object} options 发送参数 + * @param {Object} options.receiving 收货单快照 + * @param {Array} [options.unmatchedDetails=[]] 未匹配明细列表(含 barcode/product_name) + * @return {Promise} 发送结果 + */ + async sendStoreUnmatchedNotice({ receiving, unmatchedDetails = [] } = {}) { + const { ctx } = this; + const rawNoticeService = ctx && ctx.service && ctx.service.systems && ctx.service.systems.notice; + const noticeService = rawNoticeService && typeof rawNoticeService.send === 'function' + ? rawNoticeService + : (rawNoticeService && rawNoticeService.index && typeof rawNoticeService.index.send === 'function' + ? rawNoticeService.index + : null); + + if (!receiving || !noticeService || !Array.isArray(unmatchedDetails) || unmatchedDetails.length === 0) { + return null; + } + + const warehouseId = Number(receiving.warehouse_id || (ctx.user && ctx.user.store_id) || 0); + const storeId = Number(receiving.store_id || 0); + if (!Number.isFinite(warehouseId) || warehouseId <= 0 || !Number.isFinite(storeId) || storeId <= 0) { + return null; + } + + const receivingNumber = String(receiving.receiving_number || receiving.id || '').trim(); + const storeFrontendUrl = String(ctx.app.config.storeFrontendUrl || ctx.app.config.frontendUrl || '').trim(); + const barcodeLines = unmatchedDetails.map((detail, index) => `${index + 1}.${String(detail.barcode || '').trim() || '无条码'},`); + const contentLines = [ + `收货单号:${receivingNumber} 提交完成收货,有未匹配商品资料`, + '条码:', + ...barcodeLines, + '核实是否是新商品未推送资料', + `详情以及收货图片查看:${storeFrontendUrl}/storage/receiving_owner?id=${receivingNumber}`, + '如果没有账户请联系人工客服开通', + ]; + const content = contentLines.join('\n') + '。'; + + return await noticeService.send({ + warehouseId, + storeId, + messageType: 'text', + businessName: 'receiving', + event: 'receiving_store_unmatched', + channel: 'warehouse', + title: `收货单${receivingNumber}有未匹配商品资料`, + content, + storeContent: content, + businessId: receiving.id, + subject: { + id: warehouseId, + type: 'warehouse', + name: String((ctx.user && (ctx.user.store_name || ctx.user.company_name)) || ''), + }, + sender: { + id: (ctx.user && (ctx.user.employees_id || ctx.user.id)) || null, + name: (ctx.user && ctx.user.employees_name) || '', + }, + metadata: { + receivingId: receiving.id, + receivingNumber, + warehouseId, + storeId, + unmatchedBarcodes: unmatchedDetails.map(detail => detail.barcode || ''), + }, + }); + } + /** * 完成收货单:校验明细、更新状态并写入库存。 * @param {Object} data 请求体 @@ -4619,6 +4683,33 @@ class ReceivingService extends Service { }); } + // 11.1 存在未匹配商品明细且已绑定货主时,通知货主核实商品资料(失败不影响主流程) + if (unmatchedDetails.length > 0 && Number(receiving.store_id || 0) > 0) { + try { + const unmatchedNoticeResult = await this.sendStoreUnmatchedNotice({ + receiving: receivingSnapshot, + unmatchedDetails: unmatchedDetails.map(detail => ({ + barcode: detail.barcode, + product_name: detail.product_name, + })), + }); + ctx.logger.info('收货完成未匹配商品货主通知结果', { + receiving_id: id, + receiving_number: receiving.receiving_number, + warehouseId, + unmatchedCount: unmatchedDetails.length, + success: !!(unmatchedNoticeResult && unmatchedNoticeResult.success), + message: unmatchedNoticeResult && unmatchedNoticeResult.message, + }); + } catch (notifyError) { + ctx.logger.error(`收货完成未匹配商品货主通知发送失败: ${notifyError.message}`, { + receiving_id: id, + warehouseId, + error: notifyError.stack, + }); + } + } + ctx.logger.info('收货单已完成', { receiving_id: id, receiving_number: receiving.receiving_number, diff --git a/methods/changes/warehouse.json b/methods/changes/warehouse.json index 667bc9f..8f1b5d4 100644 --- a/methods/changes/warehouse.json +++ b/methods/changes/warehouse.json @@ -239,5 +239,36 @@ "背景:R20682003 创建时已写入车牌粤EH22E2,但通知为固定提醒文案导致货主误以为车牌未生效" ], "module": "receiving" + }, + { + "version": "2026-08-26-warehouse-01", + "date": "2026-08-26", + "type": "changed", + "summary": "调整 receiving_store_bound 通知模板:不再向货主发送「请确认是否已填写车牌号或快递单号,未填写请及时补充」提示,车牌号/快递单号未登记时展示「车牌号:无 / 快递单号:无」", + "methods": [ + "notify.reply" + ], + "notes": [ + "storage/receiving.js sendStoreBoundNotice:车牌号/快递单号两行始终输出,已登记显示「车牌号:X 已登记」「快递单号:X 已登记」,未登记显示「车牌号:无」「快递单号:无」", + "notification_webhook.js AVAILABLE_EVENTS.receiving_store_bound 描述同步更新:展示车牌号/快递单号登记状态", + "背景:车牌号/快递单号由仓库侧登记,货主端无法填写,「请确认/及时补充」提示对货主无意义,改为直接展示登记状态" + ], + "module": "receiving" + }, + { + "version": "2026-08-26-warehouse-02", + "date": "2026-08-26", + "type": "added", + "summary": "新增收货完成未匹配商品货主通知(receiving_store_unmatched):收货单提交完成时存在未匹配商品明细,通知货主核实是否为新商品未推送资料", + "methods": [ + "notify.reply" + ], + "notes": [ + "新事件码 receiving_store_unmatched 注册(notification_webhook.js AVAILABLE_EVENTS 与 notice/index.js DEFAULT_REGISTERED_EVENT_CODES)", + "FIXED_GROUP_SUBSCRIPTIONS.receiving_store_unmatched:仅货主侧目标 store:receiving + fallbackTargets store:after_sales(与 receiving_store_bound 一致)", + "storage/receiving.js 新增 sendStoreUnmatchedNotice:内容「收货单号:xxx 提交完成收货,有未匹配商品资料 / 条码:1.xxx,2.xxx / 核实是否是新商品未推送资料 / 详情以及收货图片查看:货主端 receiving_owner 链接 / 如果没有账户请联系人工客服开通」", + "触发点:completeReceiving 事务提交后,unmatchedDetails 非空且已绑定货主时发送,失败不影响主流程" + ], + "module": "receiving" } ]