@pisell/pisellos 2.2.264 → 2.2.265
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
- package/dist/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +5 -1
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
- package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
- package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
- package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
- package/dist/model/strategy/adapter/promotion/examples.js +0 -99
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
- package/dist/model/strategy/adapter/promotion/type.js +0 -45
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
- package/dist/modules/Discount/index.d.ts +5 -2
- package/dist/modules/Discount/index.js +30 -7
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +41 -10
- package/dist/modules/Order/index.js +1370 -808
- package/dist/modules/Order/payment-utils.d.ts +26 -0
- package/dist/modules/Order/payment-utils.js +225 -0
- package/dist/modules/Order/types.d.ts +49 -1
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +410 -0
- package/dist/modules/Order/utils.d.ts +4 -3
- package/dist/modules/Order/utils.js +62 -66
- package/dist/modules/Payment/index.d.ts +2 -0
- package/dist/modules/Payment/index.js +78 -49
- package/dist/modules/Payment/types.d.ts +26 -24
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Product/types.d.ts +22 -0
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +4 -2
- package/dist/modules/ProductList/types.d.ts +2 -0
- package/dist/modules/Rules/index.d.ts +2 -9
- package/dist/modules/Rules/index.js +69 -43
- package/dist/modules/Rules/types.d.ts +10 -1
- package/dist/server/index.d.ts +71 -0
- package/dist/server/index.js +2504 -1187
- package/dist/server/modules/order/index.d.ts +56 -5
- package/dist/server/modules/order/index.js +1718 -834
- package/dist/server/modules/order/types.d.ts +15 -3
- package/dist/server/modules/order/types.js +1 -1
- package/dist/server/modules/products/index.d.ts +31 -8
- package/dist/server/modules/products/index.js +549 -390
- package/dist/server/modules/products/types.d.ts +18 -0
- package/dist/solution/BaseSales/index.d.ts +54 -4
- package/dist/solution/BaseSales/index.js +1448 -788
- package/dist/solution/BaseSales/types.d.ts +6 -1
- package/dist/solution/BaseSales/types.js +1 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +50 -97
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +61 -26
- package/dist/solution/BookingTicket/types.d.ts +2 -0
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +10 -2
- package/dist/solution/ScanOrder/index.js +20 -31
- package/dist/solution/ShopDiscount/index.js +15 -14
- package/dist/solution/VenueBooking/index.js +19 -30
- package/dist/utils/payment-number.d.ts +9 -0
- package/dist/utils/payment-number.js +69 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +13 -2
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
- package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
- package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
- package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
- package/lib/model/strategy/adapter/promotion/examples.js +0 -91
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +0 -2
- package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
- package/lib/model/strategy/adapter/promotion/type.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
- package/lib/modules/Discount/index.d.ts +5 -2
- package/lib/modules/Discount/index.js +23 -3
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +41 -10
- package/lib/modules/Order/index.js +505 -119
- package/lib/modules/Order/payment-utils.d.ts +26 -0
- package/lib/modules/Order/payment-utils.js +224 -0
- package/lib/modules/Order/types.d.ts +49 -1
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +418 -0
- package/lib/modules/Order/utils.d.ts +4 -3
- package/lib/modules/Order/utils.js +27 -26
- package/lib/modules/Payment/index.d.ts +2 -0
- package/lib/modules/Payment/index.js +33 -12
- package/lib/modules/Payment/types.d.ts +26 -24
- package/lib/modules/Product/types.d.ts +22 -0
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +4 -2
- package/lib/modules/ProductList/types.d.ts +2 -0
- package/lib/modules/Rules/index.d.ts +2 -9
- package/lib/modules/Rules/index.js +61 -29
- package/lib/modules/Rules/types.d.ts +10 -1
- package/lib/server/index.d.ts +71 -0
- package/lib/server/index.js +1002 -52
- package/lib/server/modules/order/index.d.ts +56 -5
- package/lib/server/modules/order/index.js +798 -148
- package/lib/server/modules/order/types.d.ts +15 -3
- package/lib/server/modules/products/index.d.ts +31 -8
- package/lib/server/modules/products/index.js +134 -35
- package/lib/server/modules/products/types.d.ts +18 -0
- package/lib/solution/BaseSales/index.d.ts +54 -4
- package/lib/solution/BaseSales/index.js +475 -50
- package/lib/solution/BaseSales/types.d.ts +6 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +25 -64
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +35 -9
- package/lib/solution/BookingTicket/types.d.ts +2 -0
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +5 -3
- package/lib/solution/ScanOrder/index.js +0 -8
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/lib/solution/VenueBooking/index.js +0 -8
- package/lib/utils/payment-number.d.ts +9 -0
- package/lib/utils/payment-number.js +64 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type OrderPaymentTransactionStatus = 'success' | 'fail';
|
|
2
|
+
export interface OrderPaymentTransaction {
|
|
3
|
+
number: string;
|
|
4
|
+
status: OrderPaymentTransactionStatus;
|
|
5
|
+
}
|
|
6
|
+
export type OrderPaymentIdentityType = 'order_payment_id' | 'payment_number' | 'unique_payment_number';
|
|
7
|
+
export interface OrderPaymentIdentityMatch<T> {
|
|
8
|
+
index: number;
|
|
9
|
+
payment: T;
|
|
10
|
+
matchedBy: OrderPaymentIdentityType;
|
|
11
|
+
}
|
|
12
|
+
export declare function getOrderPaymentIdentityKeys(payment: unknown): string[];
|
|
13
|
+
export declare function isPendingOrderPayment(payment: unknown): boolean;
|
|
14
|
+
export declare function isIdentifiedPendingOrderPayment(payment: unknown): boolean;
|
|
15
|
+
export declare function hasOrderPaymentIdentityOverlap(left: unknown, right: unknown): boolean;
|
|
16
|
+
export declare function resolveOrderPaymentIdentity<T extends Record<string, any>>(payments: T[] | null | undefined, identity: string | number, mode?: 'payment_number' | 'compat'): OrderPaymentIdentityMatch<T> | null;
|
|
17
|
+
export declare function ensureOrderPaymentNumber<T extends Record<string, any>>(payment: T, devicePrefix: string, createPaymentNumber: () => string): T & {
|
|
18
|
+
payment_number: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function mergeOrderPaymentTransactions(current: unknown, incoming: unknown): OrderPaymentTransaction[];
|
|
21
|
+
export declare function mergeOrderPaymentRecord<T extends Record<string, any>>(payment: T, updates: Record<string, any>): T;
|
|
22
|
+
export declare function mergeOrderPaymentSnapshot<T extends Record<string, any>>(current: T, incoming: T): T;
|
|
23
|
+
export declare function mergeOrderPaymentListsByIdentity<T extends Record<string, any>>(existing: T[] | null | undefined, incoming: T[] | null | undefined, options?: {
|
|
24
|
+
preserveUnmatchedExisting?: boolean;
|
|
25
|
+
preserveUnmatchedExistingWhen?: (payment: T) => boolean;
|
|
26
|
+
}): T[];
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/Order/payment-utils.ts
|
|
20
|
+
var payment_utils_exports = {};
|
|
21
|
+
__export(payment_utils_exports, {
|
|
22
|
+
ensureOrderPaymentNumber: () => ensureOrderPaymentNumber,
|
|
23
|
+
getOrderPaymentIdentityKeys: () => getOrderPaymentIdentityKeys,
|
|
24
|
+
hasOrderPaymentIdentityOverlap: () => hasOrderPaymentIdentityOverlap,
|
|
25
|
+
isIdentifiedPendingOrderPayment: () => isIdentifiedPendingOrderPayment,
|
|
26
|
+
isPendingOrderPayment: () => isPendingOrderPayment,
|
|
27
|
+
mergeOrderPaymentListsByIdentity: () => mergeOrderPaymentListsByIdentity,
|
|
28
|
+
mergeOrderPaymentRecord: () => mergeOrderPaymentRecord,
|
|
29
|
+
mergeOrderPaymentSnapshot: () => mergeOrderPaymentSnapshot,
|
|
30
|
+
mergeOrderPaymentTransactions: () => mergeOrderPaymentTransactions,
|
|
31
|
+
resolveOrderPaymentIdentity: () => resolveOrderPaymentIdentity
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(payment_utils_exports);
|
|
34
|
+
var PAYMENT_IDENTITY_TYPES = [
|
|
35
|
+
"payment_number",
|
|
36
|
+
"order_payment_id",
|
|
37
|
+
"unique_payment_number"
|
|
38
|
+
];
|
|
39
|
+
function normalizePaymentIdentityValue(value) {
|
|
40
|
+
if (value === void 0 || value === null || value === "")
|
|
41
|
+
return null;
|
|
42
|
+
return String(value);
|
|
43
|
+
}
|
|
44
|
+
function getPaymentIdentityValue(payment, type) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (type === "unique_payment_number") {
|
|
47
|
+
return (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
|
|
48
|
+
}
|
|
49
|
+
return payment == null ? void 0 : payment[type];
|
|
50
|
+
}
|
|
51
|
+
function getOrderPaymentIdentityKeys(payment) {
|
|
52
|
+
const record = payment;
|
|
53
|
+
if (!record)
|
|
54
|
+
return [];
|
|
55
|
+
return PAYMENT_IDENTITY_TYPES.flatMap((type) => {
|
|
56
|
+
const value = normalizePaymentIdentityValue(getPaymentIdentityValue(record, type));
|
|
57
|
+
return value === null ? [] : [`${type}:${value}`];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function isPendingOrderPayment(payment) {
|
|
61
|
+
const record = payment;
|
|
62
|
+
return String((record == null ? void 0 : record.status) || "").toLowerCase() === "payment_pending";
|
|
63
|
+
}
|
|
64
|
+
function isIdentifiedPendingOrderPayment(payment) {
|
|
65
|
+
return isPendingOrderPayment(payment) && getOrderPaymentIdentityKeys(payment).length > 0;
|
|
66
|
+
}
|
|
67
|
+
function hasOrderPaymentIdentityOverlap(left, right) {
|
|
68
|
+
const leftKeys = new Set(getOrderPaymentIdentityKeys(left));
|
|
69
|
+
if (leftKeys.size === 0)
|
|
70
|
+
return false;
|
|
71
|
+
return getOrderPaymentIdentityKeys(right).some((key) => leftKeys.has(key));
|
|
72
|
+
}
|
|
73
|
+
function resolveOrderPaymentIdentity(payments, identity, mode = "payment_number") {
|
|
74
|
+
const target = String(identity);
|
|
75
|
+
const identityTypes = mode === "payment_number" ? ["payment_number"] : PAYMENT_IDENTITY_TYPES;
|
|
76
|
+
const matchesByIndex = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const type of identityTypes) {
|
|
78
|
+
(payments || []).forEach((payment, index) => {
|
|
79
|
+
const value = normalizePaymentIdentityValue(getPaymentIdentityValue(payment, type));
|
|
80
|
+
if (value === target && !matchesByIndex.has(index)) {
|
|
81
|
+
matchesByIndex.set(index, { index, payment, matchedBy: type });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const matches = [...matchesByIndex.values()];
|
|
86
|
+
if (matches.length > 1) {
|
|
87
|
+
throw new Error(`支付项身份存在歧义: ${target}`);
|
|
88
|
+
}
|
|
89
|
+
return matches[0] || null;
|
|
90
|
+
}
|
|
91
|
+
function ensureOrderPaymentNumber(payment, devicePrefix, createPaymentNumber) {
|
|
92
|
+
const existing = normalizePaymentIdentityValue(payment.payment_number);
|
|
93
|
+
if (existing)
|
|
94
|
+
return { ...payment, payment_number: existing };
|
|
95
|
+
const uuid = normalizePaymentIdentityValue(payment.uuid) || createPaymentNumber();
|
|
96
|
+
const prefix = normalizePaymentIdentityValue(devicePrefix) || "LOCAL";
|
|
97
|
+
return { ...payment, payment_number: `${prefix}_${uuid}` };
|
|
98
|
+
}
|
|
99
|
+
function mergeOrderPaymentTransactions(current, incoming) {
|
|
100
|
+
const records = /* @__PURE__ */ new Map();
|
|
101
|
+
const append = (value) => {
|
|
102
|
+
if (!Array.isArray(value))
|
|
103
|
+
return;
|
|
104
|
+
value.forEach((item) => {
|
|
105
|
+
const number = item && typeof item === "object" ? String(item.number || "") : "";
|
|
106
|
+
const status = item && typeof item === "object" ? item.status : void 0;
|
|
107
|
+
if (!number || status !== "success" && status !== "fail")
|
|
108
|
+
return;
|
|
109
|
+
const previous = records.get(number);
|
|
110
|
+
if ((previous == null ? void 0 : previous.status) === "success" && status === "fail")
|
|
111
|
+
return;
|
|
112
|
+
records.set(number, { number, status });
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
append(current);
|
|
116
|
+
append(incoming);
|
|
117
|
+
return [...records.values()];
|
|
118
|
+
}
|
|
119
|
+
function mergeOrderPaymentRecord(payment, updates) {
|
|
120
|
+
const currentMetadata = payment.metadata || {};
|
|
121
|
+
const incomingMetadata = updates.metadata || {};
|
|
122
|
+
const transactions = mergeOrderPaymentTransactions(
|
|
123
|
+
currentMetadata.transactions,
|
|
124
|
+
incomingMetadata.transactions
|
|
125
|
+
);
|
|
126
|
+
const currentPaid = payment.status === "paid";
|
|
127
|
+
const nextStatus = currentPaid && updates.status !== "paid" ? "paid" : updates.status ?? payment.status;
|
|
128
|
+
return {
|
|
129
|
+
...payment,
|
|
130
|
+
...updates,
|
|
131
|
+
status: nextStatus,
|
|
132
|
+
updated_at: updates.updated_at ?? payment.updated_at,
|
|
133
|
+
metadata: {
|
|
134
|
+
...currentMetadata,
|
|
135
|
+
...incomingMetadata,
|
|
136
|
+
...transactions.length > 0 || Array.isArray(incomingMetadata.transactions) ? { transactions } : {}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function mergeOrderPaymentSnapshot(current, incoming) {
|
|
141
|
+
const currentMetadata = current.metadata || {};
|
|
142
|
+
const incomingMetadata = incoming.metadata || {};
|
|
143
|
+
const currentUniquePaymentNumber = normalizePaymentIdentityValue(
|
|
144
|
+
currentMetadata.unique_payment_number
|
|
145
|
+
);
|
|
146
|
+
const incomingUniquePaymentNumber = normalizePaymentIdentityValue(
|
|
147
|
+
incomingMetadata.unique_payment_number
|
|
148
|
+
);
|
|
149
|
+
const incomingOrderPaymentId = normalizePaymentIdentityValue(
|
|
150
|
+
incoming.order_payment_id
|
|
151
|
+
);
|
|
152
|
+
const incomingFallbackPrefix = incomingOrderPaymentId ? `os-fallback:payment:order-payment:${incomingOrderPaymentId}` : null;
|
|
153
|
+
const incomingUsesDerivedUniquePaymentNumber = Boolean(
|
|
154
|
+
incomingUniquePaymentNumber && incomingFallbackPrefix && (incomingUniquePaymentNumber === incomingFallbackPrefix || incomingUniquePaymentNumber.startsWith(`${incomingFallbackPrefix}:conflict:`))
|
|
155
|
+
);
|
|
156
|
+
const transactions = mergeOrderPaymentTransactions(
|
|
157
|
+
currentMetadata.transactions,
|
|
158
|
+
incomingMetadata.transactions
|
|
159
|
+
);
|
|
160
|
+
return {
|
|
161
|
+
...current,
|
|
162
|
+
...incoming,
|
|
163
|
+
order_payment_id: normalizePaymentIdentityValue(incoming.order_payment_id) !== null ? incoming.order_payment_id : current.order_payment_id,
|
|
164
|
+
payment_number: incoming.payment_number || current.payment_number,
|
|
165
|
+
metadata: {
|
|
166
|
+
...currentMetadata,
|
|
167
|
+
...incomingMetadata,
|
|
168
|
+
...incomingUsesDerivedUniquePaymentNumber && currentUniquePaymentNumber ? { unique_payment_number: currentUniquePaymentNumber } : {},
|
|
169
|
+
...transactions.length > 0 ? { transactions } : {}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function compactOrderPaymentList(payments) {
|
|
174
|
+
const result = [];
|
|
175
|
+
for (const payment of payments) {
|
|
176
|
+
const matchingIndexes = result.flatMap((existing, index) => hasOrderPaymentIdentityOverlap(existing, payment) ? [index] : []);
|
|
177
|
+
if (matchingIndexes.length === 0) {
|
|
178
|
+
result.push(mergeOrderPaymentSnapshot({}, payment));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const firstIndex = matchingIndexes[0];
|
|
182
|
+
let merged = result[firstIndex];
|
|
183
|
+
for (const index of matchingIndexes.slice(1)) {
|
|
184
|
+
merged = mergeOrderPaymentSnapshot(merged, result[index]);
|
|
185
|
+
}
|
|
186
|
+
result[firstIndex] = mergeOrderPaymentSnapshot(merged, payment);
|
|
187
|
+
for (const index of matchingIndexes.slice(1).sort((a, b) => b - a)) {
|
|
188
|
+
result.splice(index, 1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
function mergeOrderPaymentListsByIdentity(existing, incoming, options = {}) {
|
|
194
|
+
const existingList = compactOrderPaymentList([...existing || []]);
|
|
195
|
+
const incomingList = compactOrderPaymentList([...incoming || []]);
|
|
196
|
+
if (options.preserveUnmatchedExisting) {
|
|
197
|
+
return compactOrderPaymentList([...existingList, ...incomingList]);
|
|
198
|
+
}
|
|
199
|
+
const mergedIncoming = incomingList.map((incomingPayment) => {
|
|
200
|
+
const matchingExisting = existingList.filter((existingPayment) => hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment));
|
|
201
|
+
return matchingExisting.reduce(
|
|
202
|
+
(merged, existingPayment) => mergeOrderPaymentSnapshot(existingPayment, merged),
|
|
203
|
+
incomingPayment
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
const preservedExisting = options.preserveUnmatchedExistingWhen ? existingList.filter((existingPayment) => {
|
|
207
|
+
var _a;
|
|
208
|
+
return !incomingList.some((incomingPayment) => hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment)) && ((_a = options.preserveUnmatchedExistingWhen) == null ? void 0 : _a.call(options, existingPayment));
|
|
209
|
+
}) : [];
|
|
210
|
+
return compactOrderPaymentList([...mergedIncoming, ...preservedExisting]);
|
|
211
|
+
}
|
|
212
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
213
|
+
0 && (module.exports = {
|
|
214
|
+
ensureOrderPaymentNumber,
|
|
215
|
+
getOrderPaymentIdentityKeys,
|
|
216
|
+
hasOrderPaymentIdentityOverlap,
|
|
217
|
+
isIdentifiedPendingOrderPayment,
|
|
218
|
+
isPendingOrderPayment,
|
|
219
|
+
mergeOrderPaymentListsByIdentity,
|
|
220
|
+
mergeOrderPaymentRecord,
|
|
221
|
+
mergeOrderPaymentSnapshot,
|
|
222
|
+
mergeOrderPaymentTransactions,
|
|
223
|
+
resolveOrderPaymentIdentity
|
|
224
|
+
});
|
|
@@ -198,6 +198,7 @@ export interface OrderProduct extends OrderProductIdentity {
|
|
|
198
198
|
product_bundle: any[];
|
|
199
199
|
booking_uid?: string;
|
|
200
200
|
product_title?: OrderLocalizedText;
|
|
201
|
+
product_cover?: string;
|
|
201
202
|
metadata: Record<string, any>;
|
|
202
203
|
note?: string;
|
|
203
204
|
}
|
|
@@ -308,6 +309,7 @@ export interface OrderState {
|
|
|
308
309
|
lastOrderInfo?: Record<string, any>;
|
|
309
310
|
syncState?: OrderSyncState;
|
|
310
311
|
discountList: any[];
|
|
312
|
+
availableWalletIds?: number[];
|
|
311
313
|
discount: DiscountModule | null;
|
|
312
314
|
rules: RulesModule | null;
|
|
313
315
|
}
|
|
@@ -340,6 +342,19 @@ export interface UpdateOrderProductParams {
|
|
|
340
342
|
* });
|
|
341
343
|
*/
|
|
342
344
|
allow_booking_reprice?: boolean;
|
|
345
|
+
/**
|
|
346
|
+
* Change time 重报价后,允许当前预约商品行重新应用已选编辑态折扣卡。
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* await order.updateOrderProduct({
|
|
350
|
+
* product_id: 1,
|
|
351
|
+
* product_variant_id: 0,
|
|
352
|
+
* updates: { discount_list: [] },
|
|
353
|
+
* booking: { duration: 2 },
|
|
354
|
+
* allow_booking_discount_reapply: true,
|
|
355
|
+
* });
|
|
356
|
+
*/
|
|
357
|
+
allow_booking_discount_reapply?: boolean;
|
|
343
358
|
}
|
|
344
359
|
/** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
|
|
345
360
|
export interface UpdateOrderProductQuantityParams extends OrderProductIdentity {
|
|
@@ -453,6 +468,8 @@ export interface SubmitSalesOrderParams {
|
|
|
453
468
|
export interface PaymentItemData {
|
|
454
469
|
/** 当前支付项的唯一 ID */
|
|
455
470
|
uuid: string;
|
|
471
|
+
/** 支付项稳定唯一号 */
|
|
472
|
+
payment_number?: string;
|
|
456
473
|
/** 当前支付方式付出去多少钱 */
|
|
457
474
|
amount: string;
|
|
458
475
|
/** 支付类型代码 */
|
|
@@ -475,13 +492,22 @@ export interface PaymentItemData {
|
|
|
475
492
|
export interface OrderPaymentMetadata {
|
|
476
493
|
rounding_rule?: Record<string, any>;
|
|
477
494
|
unique_payment_number?: string;
|
|
495
|
+
/** 刷卡机设备快照;OS 不解析内部字段,仅透传并持久化 */
|
|
496
|
+
card_reader_snapshot?: Record<string, unknown>;
|
|
478
497
|
shop_wallet_pass_id?: number | string;
|
|
479
498
|
actual_paid_amount?: number | string;
|
|
480
499
|
change_given_amount?: number | string;
|
|
500
|
+
transactions?: OrderPaymentTransaction[];
|
|
481
501
|
[key: string]: any;
|
|
482
502
|
}
|
|
503
|
+
export interface OrderPaymentTransaction {
|
|
504
|
+
number: string;
|
|
505
|
+
status: 'success' | 'fail';
|
|
506
|
+
}
|
|
483
507
|
export interface OrderPaymentData {
|
|
484
508
|
order_payment_id?: number | string;
|
|
509
|
+
/** 支付项稳定唯一号;历史支付项允许缺失 */
|
|
510
|
+
payment_number?: string;
|
|
485
511
|
amount: string;
|
|
486
512
|
code: string;
|
|
487
513
|
custom_payment_id: number;
|
|
@@ -508,6 +534,15 @@ export interface OrderPaymentData {
|
|
|
508
534
|
created_at?: string;
|
|
509
535
|
updated_at?: string;
|
|
510
536
|
}
|
|
537
|
+
export interface OrderPaymentUpdateOptions {
|
|
538
|
+
matchBy?: 'payment_number' | 'compat' | 'legacy';
|
|
539
|
+
}
|
|
540
|
+
export interface OrderPaymentUpdateResult {
|
|
541
|
+
updated: boolean;
|
|
542
|
+
payment: OrderPaymentData | null;
|
|
543
|
+
payments: OrderPaymentData[];
|
|
544
|
+
summary: OrderSummary | null;
|
|
545
|
+
}
|
|
511
546
|
export type OrderPaymentSource = PaymentItem | OrderPaymentData | Record<string, any>;
|
|
512
547
|
export interface MapOrderPaymentsOptions {
|
|
513
548
|
includeVoided?: boolean;
|
|
@@ -658,6 +693,14 @@ export interface OrderModuleAPI {
|
|
|
658
693
|
channel?: string;
|
|
659
694
|
type?: string;
|
|
660
695
|
}) => OrderSubmitPayload;
|
|
696
|
+
saveTempOrderAsDraft: <T = any>(params?: {
|
|
697
|
+
cacheId?: string;
|
|
698
|
+
platform?: string;
|
|
699
|
+
businessCode?: string;
|
|
700
|
+
channel?: string;
|
|
701
|
+
type?: string;
|
|
702
|
+
enhancePayload?: SubmitPayloadEnhancer;
|
|
703
|
+
}) => Promise<T>;
|
|
661
704
|
applyLocalPrintOrderNumbers: (order?: Record<string, any> | null) => Promise<OrderTempOrder>;
|
|
662
705
|
getTempOrderNote: () => string;
|
|
663
706
|
updateTempOrderNote: {
|
|
@@ -715,11 +758,15 @@ export interface OrderModuleAPI {
|
|
|
715
758
|
getOrderPayments: () => OrderPaymentData[];
|
|
716
759
|
setOrderPayments: (payments: OrderPaymentSource[]) => OrderPaymentData[];
|
|
717
760
|
addOrderPayment: (payment: OrderPaymentSource) => OrderPaymentData[];
|
|
718
|
-
|
|
761
|
+
addOrderPaymentAsync: (payment: OrderPaymentSource) => Promise<OrderPaymentData[]>;
|
|
762
|
+
updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>, options?: OrderPaymentUpdateOptions) => Promise<OrderPaymentUpdateResult>;
|
|
719
763
|
deleteOrderPayment: (paymentIdentity: string | number) => OrderPaymentData[];
|
|
720
764
|
updateVoucherOrderPayments: (payments: OrderPaymentSource[], options?: {
|
|
721
765
|
status?: 'paid' | 'payment_pending';
|
|
722
766
|
}) => OrderPaymentData[];
|
|
767
|
+
updateVoucherOrderPaymentsAsync: (payments: OrderPaymentSource[], options?: {
|
|
768
|
+
status?: 'paid' | 'payment_pending';
|
|
769
|
+
}) => Promise<OrderPaymentData[]>;
|
|
723
770
|
confirmPendingVoucherPayments: (options?: {
|
|
724
771
|
persist?: boolean;
|
|
725
772
|
recalculateSummary?: boolean;
|
|
@@ -761,6 +808,7 @@ export interface OrderModuleAPI {
|
|
|
761
808
|
apply?: boolean;
|
|
762
809
|
}) => Promise<Discount[]>;
|
|
763
810
|
getDiscountList: () => Discount[];
|
|
811
|
+
getAvailableWalletIds: () => number[];
|
|
764
812
|
applyDiscount: () => void;
|
|
765
813
|
/**
|
|
766
814
|
* 注入促销评估器。
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type OrderCollectionKind = 'product' | 'booking' | 'payment';
|
|
2
|
+
export interface OrderCollectionIdentityStats {
|
|
3
|
+
backfilledUidCount: number;
|
|
4
|
+
collapsedDuplicateCount: number;
|
|
5
|
+
uidConflictCount: number;
|
|
6
|
+
anonymousRowCount: number;
|
|
7
|
+
}
|
|
8
|
+
export interface OrderCollectionUidRemap {
|
|
9
|
+
kind: OrderCollectionKind;
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
persistentId: string | null;
|
|
13
|
+
/** 默认全局迁移;UID 冲突时只能迁移能由另一侧 UID 明确定位的引用。 */
|
|
14
|
+
scope?: 'global' | 'linked-owner';
|
|
15
|
+
referenceOwnerUid?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface NormalizeOrderCollectionResult<T> {
|
|
18
|
+
items: T[];
|
|
19
|
+
stats: OrderCollectionIdentityStats;
|
|
20
|
+
uidRemaps: OrderCollectionUidRemap[];
|
|
21
|
+
}
|
|
22
|
+
export interface NormalizeOrderCollectionsResult<T> {
|
|
23
|
+
order: T;
|
|
24
|
+
stats: Record<OrderCollectionKind, OrderCollectionIdentityStats>;
|
|
25
|
+
uidRemaps: OrderCollectionUidRemap[];
|
|
26
|
+
}
|
|
27
|
+
export declare function createUuidV4(): string;
|
|
28
|
+
export declare function isBlankOrderCollectionIdentity(value: unknown): boolean;
|
|
29
|
+
export declare function getOrderCollectionPersistentId(kind: OrderCollectionKind, item: unknown): string | null;
|
|
30
|
+
export declare function getOrderCollectionUid(kind: OrderCollectionKind, item: unknown): string | null;
|
|
31
|
+
export declare function buildOrderCollectionFallbackUid(kind: OrderCollectionKind, persistentId: string | number): string;
|
|
32
|
+
export declare function getOrderCollectionReferenceUid(kind: OrderCollectionKind, item: unknown): string | null;
|
|
33
|
+
export declare function setOrderCollectionUid<T>(kind: OrderCollectionKind, item: T, uid: string): T;
|
|
34
|
+
/**
|
|
35
|
+
* 持久化行 ID 是服务端事实主键;只有至少一侧尚未持久化时,才允许用 runtime UID 对齐。
|
|
36
|
+
*/
|
|
37
|
+
export declare function isSameOrderCollectionItem(kind: OrderCollectionKind, left: unknown, right: unknown): boolean;
|
|
38
|
+
export declare function mergeOrderCollectionItems<T>(kind: OrderCollectionKind, currentItem: T, incomingItem: T, options?: {
|
|
39
|
+
ensureUid?: boolean;
|
|
40
|
+
createAnonymousUid?: () => string;
|
|
41
|
+
}): T;
|
|
42
|
+
/**
|
|
43
|
+
* 规范化单一数组:强身份重复时保留首次位置、用最后一条业务字段覆盖,并统一补 UID。
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeOrderCollection<T>(kind: OrderCollectionKind, items: T[] | null | undefined, options?: {
|
|
46
|
+
ensureUid?: boolean;
|
|
47
|
+
createAnonymousUid?: () => string;
|
|
48
|
+
}): NormalizeOrderCollectionResult<T>;
|
|
49
|
+
export declare function applyOrderCollectionUidRemaps<T extends Record<string, any>>(sourceOrder: T, uidRemaps: OrderCollectionUidRemap[]): T;
|
|
50
|
+
export declare function normalizeOrderCollections<T extends Record<string, any>>(sourceOrder: T, options?: {
|
|
51
|
+
ensureUid?: boolean;
|
|
52
|
+
createAnonymousUid?: () => string;
|
|
53
|
+
}): NormalizeOrderCollectionsResult<T>;
|