feat(setting.expressInterface.list): 新增 quantity/recycled_quantity/cancel_quantity/allocated_quantity 扁平字段
- Promise.all 并行调用 index.getShopExpressList 获取店铺快递签约数据 - 三层匹配: sys_express_code → site_code/branch_code → shipperno/customer_code_list - 无店铺或无数据时四字段均为 0 - 补全 response 全部 42 个子字段文档
This commit is contained in:
parent
11e8bedfaf
commit
7e39159f0b
@ -119,7 +119,125 @@ class expressInterfaceService extends MainService {
|
||||
},
|
||||
});
|
||||
|
||||
return await this.callSystemExpressInterface('list', payload, '获取快递接口列表失败');
|
||||
const result = await this.callSystemExpressInterface('list', payload, '获取快递接口列表失败');
|
||||
if (result.flag !== 'success') {
|
||||
return result;
|
||||
}
|
||||
|
||||
const list = result.data?.list || result.list || [];
|
||||
if (list.length === 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 收集唯一 shop_id(去重)
|
||||
const shopIds = [...new Set(
|
||||
list
|
||||
.map(item => item.shop_id)
|
||||
.filter(id => id !== null && id !== undefined && Number(id) !== 0)
|
||||
)];
|
||||
|
||||
if (shopIds.length === 0) {
|
||||
const defaultList = list.map(item => ({ ...item, quantity: 0, recycled_quantity: 0, cancel_quantity: 0, allocated_quantity: 0 }));
|
||||
if (result.data) {
|
||||
result.data.list = defaultList;
|
||||
} else {
|
||||
result.list = defaultList;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const { ctx } = this;
|
||||
|
||||
// 并行调用 getShopExpressList,构建 Map<shopId, expressList>
|
||||
const shopExpressMap = new Map();
|
||||
const shopResults = await Promise.all(
|
||||
shopIds.map(async (shopId) => {
|
||||
try {
|
||||
const shopExpressResult = await ctx.service.systemMethods.index.getShopExpressList({
|
||||
shop_id: shopId,
|
||||
});
|
||||
return { shopId: Number(shopId), result: shopExpressResult };
|
||||
} catch (err) {
|
||||
ctx.logger.warn(
|
||||
`[expressInterface.list] 获取店铺 ${shopId} 快递签约数据异常: ${err.message}`
|
||||
);
|
||||
return { shopId: Number(shopId), result: null };
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
for (const { shopId, result: shopResult } of shopResults) {
|
||||
ctx.logger.info('[expressInterface.list] shopId=' + shopId + ' flag=' + (shopResult ? shopResult.flag : 'null') + ' msg=' + (shopResult ? shopResult.message : 'null'));
|
||||
if (shopResult && shopResult.flag === 'success') {
|
||||
const shopExpressList = shopResult.data?.list || shopResult.list || [];
|
||||
if (shopExpressList.length > 0) {
|
||||
shopExpressMap.set(shopId, shopExpressList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 为每条记录匹配并汇总 quantity
|
||||
const enrichedList = list.map(item => {
|
||||
const shopId = item.shop_id;
|
||||
if (shopId === null || shopId === undefined) {
|
||||
return { ...item, quantity: 0, recycled_quantity: 0, cancel_quantity: 0, allocated_quantity: 0 };
|
||||
}
|
||||
|
||||
const shopExpressList = shopExpressMap.get(Number(shopId));
|
||||
if (!shopExpressList || shopExpressList.length === 0) {
|
||||
return { ...item, quantity: 0, recycled_quantity: 0, cancel_quantity: 0, allocated_quantity: 0 };
|
||||
}
|
||||
|
||||
const sysExpressCode = (item.sys_express_code || '').trim().toUpperCase();
|
||||
const expressCode = (item.express_code || '').trim().toUpperCase();
|
||||
|
||||
// 按 sys_express_code 或 express_code(wp_code) 匹配
|
||||
const matchedExpress = shopExpressList.find(expressItem => {
|
||||
const itemSysCode = (expressItem.sys_express_code || '').trim().toUpperCase();
|
||||
const itemWpCode = (expressItem.wp_code || '').trim().toUpperCase();
|
||||
return itemSysCode === sysExpressCode
|
||||
|| itemWpCode === expressCode
|
||||
|| itemSysCode === expressCode;
|
||||
});
|
||||
|
||||
if (!matchedExpress) {
|
||||
return { ...item, quantity: 0, recycled_quantity: 0, cancel_quantity: 0, allocated_quantity: 0 };
|
||||
}
|
||||
|
||||
let accounts = Array.isArray(matchedExpress.accounts) ? matchedExpress.accounts : [];
|
||||
|
||||
// 若有 site_code,进一步按 branch_code 筛选匹配的网点账号
|
||||
const siteCode = (item.site_code || '').trim().toUpperCase();
|
||||
if (siteCode) {
|
||||
const branchMatched = accounts.filter(acc =>
|
||||
(acc.branch_code || '').trim().toUpperCase() === siteCode
|
||||
);
|
||||
if (branchMatched.length > 0) {
|
||||
accounts = branchMatched;
|
||||
}
|
||||
}
|
||||
|
||||
// 若有 shipperno,进一步按 customer_code_list 筛选匹配的账号
|
||||
const shipperNo = (item.shipperno || '').trim();
|
||||
if (shipperNo && accounts.length > 0) {
|
||||
const shipperMatched = accounts.filter(acc =>
|
||||
Array.isArray(acc.customer_code_list) && acc.customer_code_list.includes(shipperNo)
|
||||
);
|
||||
if (shipperMatched.length > 0) {
|
||||
accounts = shipperMatched;
|
||||
}
|
||||
}
|
||||
|
||||
return { ...item, quantity: accounts.reduce((sum, acc) => sum + (Number(acc.quantity) || 0), 0), recycled_quantity: accounts.reduce((sum, acc) => sum + (Number(acc.recycled_quantity) || 0), 0), cancel_quantity: accounts.reduce((sum, acc) => sum + (Number(acc.cancel_quantity) || 0), 0), allocated_quantity: accounts.reduce((sum, acc) => sum + (Number(acc.allocated_quantity) || 0), 0) };
|
||||
});
|
||||
|
||||
if (result.data) {
|
||||
result.data.list = enrichedList;
|
||||
} else {
|
||||
result.list = enrichedList;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1715,7 +1715,7 @@
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "统一 where 条件对象;推荐使用 { operator, value, type } 标准结构,历史简写会自动标准化;禁止传入 warehouse_id / warehouseId。"
|
||||
"description": "统一 where 条件对象;推荐使用 { operator, value, type } 标准结构,历史简写会自动标准化;禁止传入 warehouse_id / warehouseId。支持虚拟字段:buyer_message_has(覆盖 buyer_message/seller_message/remark 三个字段,任一有值即为有留言,value=true/false),express_numbers / waybill_codes(运单号筛选)。"
|
||||
},
|
||||
{
|
||||
"name": "sort",
|
||||
@ -8161,7 +8161,7 @@
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "筛选白名单字段(object)。仅支持下列字段,且禁止传入 warehouse_id / warehouseId:\n- id(等值)\n- delivery_no / deliveryNo(模糊)\n- tracking_no / trackingNo(模糊)\n- items_count_min / items_count_max(范围)\n- items_total_min / items_total_max(范围)\n- sys_logistics_name(模糊)\n- store_name(模糊)\n- owner_name(等值)\n- province(模糊)\n- sys_platform_name(模糊)\n说明:若传入未列出的字段或禁止字段(如 warehouse_id)接口会返回 400。"
|
||||
"description": "筛选白名单字段(object)。仅支持下列字段,且禁止传入 warehouse_id / warehouseId:\n- id(等值)\n- delivery_no / deliveryNo(模糊)\n- tracking_no / trackingNo(模糊)\n- items_count_min / items_count_max(范围)\n- items_total_min / items_total_max(范围)\n- sys_logistics_name(模糊)\n- store_name(模糊)\n- owner_name(等值)\n- province(模糊)\n- sys_platform_name(模糊)\n- buyer_message_has(虚拟字段,覆盖 buyer_message/seller_message/remark 三个字段,任一有值即为有留言,value=true/false)\n说明:若传入未列出的字段或禁止字段(如 warehouse_id)接口会返回 400。"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
@ -14167,12 +14167,12 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"groupName": "快递接口管理模块",
|
||||
"groupName": "快递接口管理",
|
||||
"module": "setting.expressInterface",
|
||||
"list": [
|
||||
{
|
||||
"method": "setting.expressInterface.list",
|
||||
"description": "查询当前仓库范围的快递接口列表,支持 where + pagination;返回 data:{ list, total, page, page_size }。按 weight 升序、id 降序排序,优先按权重排序。",
|
||||
"description": "查询当前仓库范围的快递接口列表,支持 where + pagination;返回 data:{ list, total, page, page_size }。按 weight 升序、id 降序排序,优先按权重排序。每条记录新增 quantity/recycled_quantity/cancel_quantity/allocated_quantity 扁平字段,数据源为 index.getShopExpressList,按 sys_express_code/site_code/shipperno 三层匹配汇总。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -14189,14 +14189,14 @@
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "pagination"
|
||||
"description": "分页参数,含 page、pageSize"
|
||||
},
|
||||
{
|
||||
"name": "where",
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "支持按 shop_id 过滤"
|
||||
"description": "筛选条件,支持 id/name/express_code/platform_code/sender_name/sender_tel/viewer/client_id/share_id/site_code/product_type/shop_name/is_enabled/quickWhere"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
@ -14208,26 +14208,298 @@
|
||||
{
|
||||
"name": "id",
|
||||
"type": "number",
|
||||
"description": "id",
|
||||
"required": true
|
||||
"required": true,
|
||||
"description": "主键ID"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string",
|
||||
"description": "name",
|
||||
"required": true
|
||||
"required": true,
|
||||
"description": "接口名称"
|
||||
},
|
||||
{
|
||||
"name": "express_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "快递编码"
|
||||
},
|
||||
{
|
||||
"name": "sys_express_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "系统快递编码"
|
||||
},
|
||||
{
|
||||
"name": "warehouse_id",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "仓库ID"
|
||||
},
|
||||
{
|
||||
"name": "shop_id",
|
||||
"type": "number",
|
||||
"description": "店铺 ID,未绑定时返回 null",
|
||||
"required": false
|
||||
"required": false,
|
||||
"description": "店铺ID,未绑定时为 null"
|
||||
},
|
||||
{
|
||||
"name": "platform_shop_id",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "平台店铺ID"
|
||||
},
|
||||
{
|
||||
"name": "template_id",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "模板ID"
|
||||
},
|
||||
{
|
||||
"name": "paymode",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "付款方式"
|
||||
},
|
||||
{
|
||||
"name": "brandno",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "品牌编码"
|
||||
},
|
||||
{
|
||||
"name": "providertype",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "服务商类型编码"
|
||||
},
|
||||
{
|
||||
"name": "providerid",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "服务商ID"
|
||||
},
|
||||
{
|
||||
"name": "platform_code",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "平台编码(PDD/CAINIAO/DY/KS/SPH/XHS/JD/QT)"
|
||||
},
|
||||
{
|
||||
"name": "sender_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "寄件人"
|
||||
},
|
||||
{
|
||||
"name": "sender_tel",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "寄件电话"
|
||||
},
|
||||
{
|
||||
"name": "weight",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "排序权重"
|
||||
},
|
||||
{
|
||||
"name": "weight_type",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "重量类型"
|
||||
},
|
||||
{
|
||||
"name": "viewer",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "查看者/备注"
|
||||
},
|
||||
{
|
||||
"name": "client_id",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "客户ID"
|
||||
},
|
||||
{
|
||||
"name": "is_enabled",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "是否启用(1启用 0禁用)"
|
||||
},
|
||||
{
|
||||
"name": "is_share",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "是否共享"
|
||||
},
|
||||
{
|
||||
"name": "ispickup",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"description": "是否上门取件"
|
||||
},
|
||||
{
|
||||
"name": "shipperno",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "发货编号/客户代码"
|
||||
},
|
||||
{
|
||||
"name": "template_url",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "模板URL"
|
||||
},
|
||||
{
|
||||
"name": "ext_data",
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"description": "扩展数据(JSON对象)"
|
||||
},
|
||||
{
|
||||
"name": "province_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "省份"
|
||||
},
|
||||
{
|
||||
"name": "city_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "城市"
|
||||
},
|
||||
{
|
||||
"name": "district_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "区县"
|
||||
},
|
||||
{
|
||||
"name": "address",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "详细地址"
|
||||
},
|
||||
{
|
||||
"name": "town_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "镇/街道"
|
||||
},
|
||||
{
|
||||
"name": "site_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "网点编码"
|
||||
},
|
||||
{
|
||||
"name": "product_type",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "产品类型"
|
||||
},
|
||||
{
|
||||
"name": "shop_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "店铺名称"
|
||||
},
|
||||
{
|
||||
"name": "express",
|
||||
"type": "object",
|
||||
"required": false,
|
||||
"description": "关联的系统快递对象",
|
||||
"children": [
|
||||
{
|
||||
"name": "code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "系统快递编码"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "快递名称"
|
||||
},
|
||||
{
|
||||
"name": "polyapi_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "PolyAPI编码"
|
||||
},
|
||||
{
|
||||
"name": "polyapi_extra_info",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "PolyAPI扩展信息"
|
||||
},
|
||||
{
|
||||
"name": "pdd_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "拼多多快递编码"
|
||||
},
|
||||
{
|
||||
"name": "ks_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "快手快递编码"
|
||||
},
|
||||
{
|
||||
"name": "dyxd_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "抖音快递编码"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "express_name",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "快递名称(扁平字段)"
|
||||
},
|
||||
{
|
||||
"name": "express_polyapi_extra_info",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "PolyAPI扩展信息(扁平字段)"
|
||||
},
|
||||
{
|
||||
"name": "express_pdd_code",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "拼多多快递编码(扁平字段)"
|
||||
},
|
||||
{
|
||||
"name": "is_system_express_code",
|
||||
"type": "number",
|
||||
"description": "该行 express_code 是否为系统快递编码;若不是系统快递编码返回 0,否则返回 1",
|
||||
"required": true
|
||||
"required": true,
|
||||
"description": "是否为系统快递编码(1是 0否)"
|
||||
},
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "可用面单数量(从店铺快递签约数据汇总),无店铺或无数据时为 0"
|
||||
},
|
||||
{
|
||||
"name": "recycled_quantity",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "已回收面单数量"
|
||||
},
|
||||
{
|
||||
"name": "cancel_quantity",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "已取消面单数量"
|
||||
},
|
||||
{
|
||||
"name": "allocated_quantity",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "已分配面单数量"
|
||||
}
|
||||
],
|
||||
"description": "list,按 weight 升序、id 降序排序;优先按权重排序,权重相同再按 id 倒序"
|
||||
@ -14235,20 +14507,20 @@
|
||||
{
|
||||
"name": "total",
|
||||
"type": "number",
|
||||
"description": "total",
|
||||
"required": true
|
||||
"required": true,
|
||||
"description": "总记录数"
|
||||
},
|
||||
{
|
||||
"name": "page",
|
||||
"type": "number",
|
||||
"description": "page",
|
||||
"required": true
|
||||
"required": true,
|
||||
"description": "当前页码"
|
||||
},
|
||||
{
|
||||
"name": "page_size",
|
||||
"type": "number",
|
||||
"description": "page_size",
|
||||
"required": true
|
||||
"required": true,
|
||||
"description": "每页条数"
|
||||
}
|
||||
],
|
||||
"errors": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user