Compare commits
No commits in common. "1bdae88c1129500dc78de7067c45b84023b361ab" and "12dc5ac876315d5e614c817a3303bc4980bb9649" have entirely different histories.
1bdae88c11
...
12dc5ac876
|
|
@ -643,37 +643,6 @@ export class OrderService {
|
||||||
o.payment_method as payment_method,
|
o.payment_method as payment_method,
|
||||||
cs.order_count as order_count,
|
cs.order_count as order_count,
|
||||||
cs.total_spent as total_spent,
|
cs.total_spent as total_spent,
|
||||||
CASE WHEN EXISTS (
|
|
||||||
SELECT 1 FROM subscription s
|
|
||||||
WHERE s.siteId = o.siteId AND s.parent_id = o.externalOrderId
|
|
||||||
) THEN 1 ELSE 0 END AS isSubscription,
|
|
||||||
(
|
|
||||||
SELECT COALESCE(
|
|
||||||
JSON_ARRAYAGG(
|
|
||||||
JSON_OBJECT(
|
|
||||||
'id', s.id,
|
|
||||||
'externalSubscriptionId', s.externalSubscriptionId,
|
|
||||||
'status', s.status,
|
|
||||||
'currency', s.currency,
|
|
||||||
'total', s.total,
|
|
||||||
'billing_period', s.billing_period,
|
|
||||||
'billing_interval', s.billing_interval,
|
|
||||||
'customer_id', s.customer_id,
|
|
||||||
'customer_email', s.customer_email,
|
|
||||||
'parent_id', s.parent_id,
|
|
||||||
'start_date', s.start_date,
|
|
||||||
'trial_end', s.trial_end,
|
|
||||||
'next_payment_date', s.next_payment_date,
|
|
||||||
'end_date', s.end_date,
|
|
||||||
'line_items', s.line_items,
|
|
||||||
'meta_data', s.meta_data
|
|
||||||
)
|
|
||||||
),
|
|
||||||
JSON_ARRAY()
|
|
||||||
)
|
|
||||||
FROM subscription s
|
|
||||||
WHERE s.siteId = o.siteId AND s.parent_id = o.externalOrderId
|
|
||||||
) AS related,
|
|
||||||
COALESCE(
|
COALESCE(
|
||||||
JSON_ARRAYAGG(
|
JSON_ARRAYAGG(
|
||||||
CASE WHEN s.id IS NOT NULL THEN JSON_OBJECT(
|
CASE WHEN s.id IS NOT NULL THEN JSON_OBJECT(
|
||||||
|
|
@ -1330,21 +1299,10 @@ export class OrderService {
|
||||||
let relatedList: any[] = [];
|
let relatedList: any[] = [];
|
||||||
try {
|
try {
|
||||||
const related = await this.getRelatedByOrder(id);
|
const related = await this.getRelatedByOrder(id);
|
||||||
const subs = Array.isArray(related?.subscriptions) ? related.subscriptions : [];
|
relatedList = [
|
||||||
const ords = Array.isArray(related?.orders) ? related.orders : [];
|
...(Array.isArray(related?.subscriptions) ? related.subscriptions : []),
|
||||||
const seen = new Set<string>();
|
...(Array.isArray(related?.orders) ? related.orders : []),
|
||||||
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) {
|
} catch (error) {
|
||||||
// 关联查询失败不影响详情返回
|
// 关联查询失败不影响详情返回
|
||||||
}
|
}
|
||||||
|
|
@ -1371,10 +1329,15 @@ export class OrderService {
|
||||||
WHERE s.siteId = ? AND s.parent_id = ?
|
WHERE s.siteId = ? AND s.parent_id = ?
|
||||||
`;
|
`;
|
||||||
const subscriptions = await this.orderModel.query(subSql, [siteId, order.externalOrderId]);
|
const subscriptions = await this.orderModel.query(subSql, [siteId, order.externalOrderId]);
|
||||||
|
|
||||||
|
|
||||||
|
const allOrdersMap = new Map<number, any>();
|
||||||
|
subscriptions.forEach(o => allOrdersMap.set(o.id, o));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
order,
|
order,
|
||||||
subscriptions,
|
subscriptions,
|
||||||
orders: [],
|
orders: Array.from(allOrdersMap.values()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue