feat(receiving): 收货单通知模板调整(车牌/快递单号未登记显示无)并新增完成时未匹配商品货主通知

This commit is contained in:
liufumingren 2026-08-26 17:22:52 +08:00
parent 93c0a620c7
commit fbd9ac2326
4 changed files with 146 additions and 13 deletions

View File

@ -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: '定时兜底扫描任务在仓库维度触发失败时通知' }),

View File

@ -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' }),
]),

View File

@ -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<Object>} [options.unmatchedDetails=[]] 未匹配明细列表(含 barcode/product_name)
* @return {Promise<Object|null>} 发送结果
*/
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,

View File

@ -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"
}
]