liufumingren 396e9d0581 feat(wms): 新增运单轨迹查询回调 waybill.getTrace
- notify/WaybillTraceHandler:按 {request:{waybill_codes}} 批量查询轨迹(10 单并发),
  输出裸数组 [{waybillNo, trace:[{opTime,outBizCode,memo,opOrgCityName,weight,scanType}]}]
- notify/WaybillCodes:抽取 waybill.* 系列共用的入参解析(兼容平铺结构、去空、去重保序、限量)
- WaybillReceiveHandler 改用 WaybillCodes,行为不变
- express/Trace::parseResult 增加 raw(上游原始轨迹),供 getTrace 原样透出
- Dispatcher 注册 waybill.getTrace

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-11 20:34:06 +08:00

56 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\index\library\new_wms\notify;
/**
* 入站回调运单号参数解析
*
* waybill.* 系列方法的请求体统一为 { request: { waybill_codes: [...] } },
* 这里统一做「兼容平铺结构 + 去空 + 去重保序 + 限量」,供各处理器复用。
*/
class WaybillCodes
{
/** 默认单次最多处理的运单号数量 */
const DEFAULT_MAX = 50;
/**
* @param array $body 请求体
* @param int $max 最多返回条数
* @return array 去重保序后的运单号列表
*/
public static function extract(array $body, $max = self::DEFAULT_MAX)
{
$raw = [];
if (isset($body['request']['waybill_codes'])) {
$raw = $body['request']['waybill_codes'];
} elseif (isset($body['request']['waybillCodes'])) {
$raw = $body['request']['waybillCodes'];
} elseif (isset($body['waybill_codes'])) {
$raw = $body['waybill_codes'];
} elseif (isset($body['waybillCodes'])) {
$raw = $body['waybillCodes'];
}
if (!is_array($raw)) {
$raw = [$raw];
}
$codes = [];
foreach ($raw as $item) {
if (is_array($item) || is_object($item)) {
continue;
}
$code = trim((string)$item);
if ($code === '' || isset($codes[$code])) {
continue;
}
$codes[$code] = $code;
if (count($codes) >= $max) {
break;
}
}
return array_values($codes);
}
}