diff --git a/src/service/order.service.ts b/src/service/order.service.ts index 780071d..7f7855c 100644 --- a/src/service/order.service.ts +++ b/src/service/order.service.ts @@ -1330,10 +1330,21 @@ export class OrderService { let relatedList: any[] = []; try { const related = await this.getRelatedByOrder(id); - relatedList = [ - ...(Array.isArray(related?.subscriptions) ? related.subscriptions : []), - ...(Array.isArray(related?.orders) ? related.orders : []), - ]; + const subs = Array.isArray(related?.subscriptions) ? related.subscriptions : []; + const ords = Array.isArray(related?.orders) ? related.orders : []; + const seen = new Set(); + const merge = [...subs, ...ords]; + for (const it of merge) { + const key = it?.externalSubscriptionId + ? `sub:${it.externalSubscriptionId}` + : it?.externalOrderId + ? `ord:${it.externalOrderId}` + : `id:${it?.id}`; + if (!seen.has(key)) { + seen.add(key); + relatedList.push(it); + } + } } catch (error) { // 关联查询失败不影响详情返回 } @@ -1360,15 +1371,10 @@ export class OrderService { WHERE s.siteId = ? AND s.parent_id = ? `; const subscriptions = await this.orderModel.query(subSql, [siteId, order.externalOrderId]); - - - const allOrdersMap = new Map(); - subscriptions.forEach(o => allOrdersMap.set(o.id, o)); - return { order, subscriptions, - orders: Array.from(allOrdersMap.values()), + orders: [], }; }