@pisell/pisellos 2.2.264 → 2.2.266
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/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 +1379 -810
- 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 +61 -64
- 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 -8
- package/dist/modules/Rules/index.js +55 -9
- 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 +67 -4
- package/dist/solution/BaseSales/index.js +1476 -792
- package/dist/solution/BaseSales/types.d.ts +6 -1
- package/dist/solution/BaseSales/types.js +1 -1
- package/dist/solution/BaseSales/utils/cartPromotion.js +19 -7
- 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 +94 -54
- 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/ShopDiscount/index.js +15 -14
- 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/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 +514 -122
- 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 +26 -20
- 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 -8
- package/lib/modules/Rules/index.js +57 -6
- 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 +67 -4
- package/lib/solution/BaseSales/index.js +496 -50
- package/lib/solution/BaseSales/types.d.ts +6 -1
- package/lib/solution/BaseSales/utils/cartPromotion.js +13 -1
- 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 +39 -11
- 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/ShopDiscount/index.js +2 -1
- 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,225 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
var PAYMENT_IDENTITY_TYPES = ['payment_number', 'order_payment_id', 'unique_payment_number'];
|
|
15
|
+
function normalizePaymentIdentityValue(value) {
|
|
16
|
+
if (value === undefined || value === null || value === '') return null;
|
|
17
|
+
return String(value);
|
|
18
|
+
}
|
|
19
|
+
function getPaymentIdentityValue(payment, type) {
|
|
20
|
+
if (type === 'unique_payment_number') {
|
|
21
|
+
var _payment$metadata;
|
|
22
|
+
return payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.unique_payment_number;
|
|
23
|
+
}
|
|
24
|
+
return payment === null || payment === void 0 ? void 0 : payment[type];
|
|
25
|
+
}
|
|
26
|
+
export function getOrderPaymentIdentityKeys(payment) {
|
|
27
|
+
var record = payment;
|
|
28
|
+
if (!record) return [];
|
|
29
|
+
return PAYMENT_IDENTITY_TYPES.flatMap(function (type) {
|
|
30
|
+
var value = normalizePaymentIdentityValue(getPaymentIdentityValue(record, type));
|
|
31
|
+
return value === null ? [] : ["".concat(type, ":").concat(value)];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function isPendingOrderPayment(payment) {
|
|
35
|
+
var record = payment;
|
|
36
|
+
return String((record === null || record === void 0 ? void 0 : record.status) || '').toLowerCase() === 'payment_pending';
|
|
37
|
+
}
|
|
38
|
+
export function isIdentifiedPendingOrderPayment(payment) {
|
|
39
|
+
return isPendingOrderPayment(payment) && getOrderPaymentIdentityKeys(payment).length > 0;
|
|
40
|
+
}
|
|
41
|
+
export function hasOrderPaymentIdentityOverlap(left, right) {
|
|
42
|
+
var leftKeys = new Set(getOrderPaymentIdentityKeys(left));
|
|
43
|
+
if (leftKeys.size === 0) return false;
|
|
44
|
+
return getOrderPaymentIdentityKeys(right).some(function (key) {
|
|
45
|
+
return leftKeys.has(key);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function resolveOrderPaymentIdentity(payments, identity) {
|
|
49
|
+
var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'payment_number';
|
|
50
|
+
var target = String(identity);
|
|
51
|
+
var identityTypes = mode === 'payment_number' ? ['payment_number'] : PAYMENT_IDENTITY_TYPES;
|
|
52
|
+
var matchesByIndex = new Map();
|
|
53
|
+
var _iterator = _createForOfIteratorHelper(identityTypes),
|
|
54
|
+
_step;
|
|
55
|
+
try {
|
|
56
|
+
var _loop = function _loop() {
|
|
57
|
+
var type = _step.value;
|
|
58
|
+
(payments || []).forEach(function (payment, index) {
|
|
59
|
+
var value = normalizePaymentIdentityValue(getPaymentIdentityValue(payment, type));
|
|
60
|
+
if (value === target && !matchesByIndex.has(index)) {
|
|
61
|
+
matchesByIndex.set(index, {
|
|
62
|
+
index: index,
|
|
63
|
+
payment: payment,
|
|
64
|
+
matchedBy: type
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
70
|
+
_loop();
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
_iterator.e(err);
|
|
74
|
+
} finally {
|
|
75
|
+
_iterator.f();
|
|
76
|
+
}
|
|
77
|
+
var matches = _toConsumableArray(matchesByIndex.values());
|
|
78
|
+
if (matches.length > 1) {
|
|
79
|
+
throw new Error("\u652F\u4ED8\u9879\u8EAB\u4EFD\u5B58\u5728\u6B67\u4E49: ".concat(target));
|
|
80
|
+
}
|
|
81
|
+
return matches[0] || null;
|
|
82
|
+
}
|
|
83
|
+
export function ensureOrderPaymentNumber(payment, devicePrefix, createPaymentNumber) {
|
|
84
|
+
var existing = normalizePaymentIdentityValue(payment.payment_number);
|
|
85
|
+
if (existing) return _objectSpread(_objectSpread({}, payment), {}, {
|
|
86
|
+
payment_number: existing
|
|
87
|
+
});
|
|
88
|
+
var uuid = normalizePaymentIdentityValue(payment.uuid) || createPaymentNumber();
|
|
89
|
+
var prefix = normalizePaymentIdentityValue(devicePrefix) || 'LOCAL';
|
|
90
|
+
// TODO: 使用 ID Generator 替换当前 UUID 段生成器。
|
|
91
|
+
return _objectSpread(_objectSpread({}, payment), {}, {
|
|
92
|
+
payment_number: "".concat(prefix, "_").concat(uuid)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export function mergeOrderPaymentTransactions(current, incoming) {
|
|
96
|
+
var records = new Map();
|
|
97
|
+
var append = function append(value) {
|
|
98
|
+
if (!Array.isArray(value)) return;
|
|
99
|
+
value.forEach(function (item) {
|
|
100
|
+
var number = item && _typeof(item) === 'object' ? String(item.number || '') : '';
|
|
101
|
+
var status = item && _typeof(item) === 'object' ? item.status : undefined;
|
|
102
|
+
if (!number || status !== 'success' && status !== 'fail') return;
|
|
103
|
+
var previous = records.get(number);
|
|
104
|
+
if ((previous === null || previous === void 0 ? void 0 : previous.status) === 'success' && status === 'fail') return;
|
|
105
|
+
records.set(number, {
|
|
106
|
+
number: number,
|
|
107
|
+
status: status
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
append(current);
|
|
112
|
+
append(incoming);
|
|
113
|
+
return _toConsumableArray(records.values());
|
|
114
|
+
}
|
|
115
|
+
export function mergeOrderPaymentRecord(payment, updates) {
|
|
116
|
+
var _updates$status, _updates$updated_at;
|
|
117
|
+
var currentMetadata = payment.metadata || {};
|
|
118
|
+
var incomingMetadata = updates.metadata || {};
|
|
119
|
+
var transactions = mergeOrderPaymentTransactions(currentMetadata.transactions, incomingMetadata.transactions);
|
|
120
|
+
var currentPaid = payment.status === 'paid';
|
|
121
|
+
var nextStatus = currentPaid && updates.status !== 'paid' ? 'paid' : (_updates$status = updates.status) !== null && _updates$status !== void 0 ? _updates$status : payment.status;
|
|
122
|
+
return _objectSpread(_objectSpread(_objectSpread({}, payment), updates), {}, {
|
|
123
|
+
status: nextStatus,
|
|
124
|
+
updated_at: (_updates$updated_at = updates.updated_at) !== null && _updates$updated_at !== void 0 ? _updates$updated_at : payment.updated_at,
|
|
125
|
+
metadata: _objectSpread(_objectSpread(_objectSpread({}, currentMetadata), incomingMetadata), transactions.length > 0 || Array.isArray(incomingMetadata.transactions) ? {
|
|
126
|
+
transactions: transactions
|
|
127
|
+
} : {})
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
export function mergeOrderPaymentSnapshot(current, incoming) {
|
|
131
|
+
var currentMetadata = current.metadata || {};
|
|
132
|
+
var incomingMetadata = incoming.metadata || {};
|
|
133
|
+
var currentUniquePaymentNumber = normalizePaymentIdentityValue(currentMetadata.unique_payment_number);
|
|
134
|
+
var incomingUniquePaymentNumber = normalizePaymentIdentityValue(incomingMetadata.unique_payment_number);
|
|
135
|
+
var incomingOrderPaymentId = normalizePaymentIdentityValue(incoming.order_payment_id);
|
|
136
|
+
var incomingFallbackPrefix = incomingOrderPaymentId ? "os-fallback:payment:order-payment:".concat(incomingOrderPaymentId) : null;
|
|
137
|
+
var incomingUsesDerivedUniquePaymentNumber = Boolean(incomingUniquePaymentNumber && incomingFallbackPrefix && (incomingUniquePaymentNumber === incomingFallbackPrefix || incomingUniquePaymentNumber.startsWith("".concat(incomingFallbackPrefix, ":conflict:"))));
|
|
138
|
+
var transactions = mergeOrderPaymentTransactions(currentMetadata.transactions, incomingMetadata.transactions);
|
|
139
|
+
return _objectSpread(_objectSpread(_objectSpread({}, current), incoming), {}, {
|
|
140
|
+
order_payment_id: normalizePaymentIdentityValue(incoming.order_payment_id) !== null ? incoming.order_payment_id : current.order_payment_id,
|
|
141
|
+
payment_number: incoming.payment_number || current.payment_number,
|
|
142
|
+
metadata: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, currentMetadata), incomingMetadata), incomingUsesDerivedUniquePaymentNumber && currentUniquePaymentNumber ? {
|
|
143
|
+
unique_payment_number: currentUniquePaymentNumber
|
|
144
|
+
} : {}), transactions.length > 0 ? {
|
|
145
|
+
transactions: transactions
|
|
146
|
+
} : {})
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function compactOrderPaymentList(payments) {
|
|
150
|
+
var result = [];
|
|
151
|
+
var _iterator2 = _createForOfIteratorHelper(payments),
|
|
152
|
+
_step2;
|
|
153
|
+
try {
|
|
154
|
+
var _loop2 = function _loop2() {
|
|
155
|
+
var payment = _step2.value;
|
|
156
|
+
var matchingIndexes = result.flatMap(function (existing, index) {
|
|
157
|
+
return hasOrderPaymentIdentityOverlap(existing, payment) ? [index] : [];
|
|
158
|
+
});
|
|
159
|
+
if (matchingIndexes.length === 0) {
|
|
160
|
+
result.push(mergeOrderPaymentSnapshot({}, payment));
|
|
161
|
+
return 1; // continue
|
|
162
|
+
}
|
|
163
|
+
var firstIndex = matchingIndexes[0];
|
|
164
|
+
var merged = result[firstIndex];
|
|
165
|
+
var _iterator3 = _createForOfIteratorHelper(matchingIndexes.slice(1)),
|
|
166
|
+
_step3;
|
|
167
|
+
try {
|
|
168
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
169
|
+
var index = _step3.value;
|
|
170
|
+
merged = mergeOrderPaymentSnapshot(merged, result[index]);
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
_iterator3.e(err);
|
|
174
|
+
} finally {
|
|
175
|
+
_iterator3.f();
|
|
176
|
+
}
|
|
177
|
+
result[firstIndex] = mergeOrderPaymentSnapshot(merged, payment);
|
|
178
|
+
var _iterator4 = _createForOfIteratorHelper(matchingIndexes.slice(1).sort(function (a, b) {
|
|
179
|
+
return b - a;
|
|
180
|
+
})),
|
|
181
|
+
_step4;
|
|
182
|
+
try {
|
|
183
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
184
|
+
var _index = _step4.value;
|
|
185
|
+
result.splice(_index, 1);
|
|
186
|
+
}
|
|
187
|
+
} catch (err) {
|
|
188
|
+
_iterator4.e(err);
|
|
189
|
+
} finally {
|
|
190
|
+
_iterator4.f();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
194
|
+
if (_loop2()) continue;
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
_iterator2.e(err);
|
|
198
|
+
} finally {
|
|
199
|
+
_iterator2.f();
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
export function mergeOrderPaymentListsByIdentity(existing, incoming) {
|
|
204
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
205
|
+
var existingList = compactOrderPaymentList(_toConsumableArray(existing || []));
|
|
206
|
+
var incomingList = compactOrderPaymentList(_toConsumableArray(incoming || []));
|
|
207
|
+
if (options.preserveUnmatchedExisting) {
|
|
208
|
+
return compactOrderPaymentList([].concat(_toConsumableArray(existingList), _toConsumableArray(incomingList)));
|
|
209
|
+
}
|
|
210
|
+
var mergedIncoming = incomingList.map(function (incomingPayment) {
|
|
211
|
+
var matchingExisting = existingList.filter(function (existingPayment) {
|
|
212
|
+
return hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment);
|
|
213
|
+
});
|
|
214
|
+
return matchingExisting.reduce(function (merged, existingPayment) {
|
|
215
|
+
return mergeOrderPaymentSnapshot(existingPayment, merged);
|
|
216
|
+
}, incomingPayment);
|
|
217
|
+
});
|
|
218
|
+
var preservedExisting = options.preserveUnmatchedExistingWhen ? existingList.filter(function (existingPayment) {
|
|
219
|
+
var _options$preserveUnma;
|
|
220
|
+
return !incomingList.some(function (incomingPayment) {
|
|
221
|
+
return hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment);
|
|
222
|
+
}) && ((_options$preserveUnma = options.preserveUnmatchedExistingWhen) === null || _options$preserveUnma === void 0 ? void 0 : _options$preserveUnma.call(options, existingPayment));
|
|
223
|
+
}) : [];
|
|
224
|
+
return compactOrderPaymentList([].concat(_toConsumableArray(mergedIncoming), _toConsumableArray(preservedExisting)));
|
|
225
|
+
}
|
|
@@ -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>;
|