@pisell/pisellos 2.3.33 → 2.3.35
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/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +84 -34
- package/dist/modules/Order/payment-utils.d.ts +3 -0
- package/dist/modules/Order/payment-utils.js +25 -3
- package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +73 -10
- package/dist/server/modules/order/index.d.ts +4 -1
- package/dist/server/modules/order/index.js +108 -18
- package/dist/solution/BaseSales/index.js +10 -1
- package/dist/solution/BaseSales/utils/cartPromotion.js +19 -7
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +10 -2
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +75 -11
- package/lib/modules/Order/payment-utils.d.ts +3 -0
- package/lib/modules/Order/payment-utils.js +33 -2
- package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
- package/lib/server/index.d.ts +2 -0
- package/lib/server/index.js +60 -10
- package/lib/server/modules/order/index.d.ts +4 -1
- package/lib/server/modules/order/index.js +89 -10
- package/lib/solution/BaseSales/index.js +9 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +13 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +5 -3
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -23,6 +23,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
23
23
|
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); }
|
|
24
24
|
import dayjs from 'dayjs';
|
|
25
25
|
import Decimal from 'decimal.js';
|
|
26
|
+
import { cloneDeep } from 'lodash-es';
|
|
26
27
|
import { ProductsModule } from "./modules/products";
|
|
27
28
|
import { MenuModule } from "./modules/menu";
|
|
28
29
|
import { QuotationModule } from "./modules/quotation";
|
|
@@ -40,6 +41,7 @@ import { filterOrders } from "./modules/order/utils/filterOrders";
|
|
|
40
41
|
import { filterBookingsFromOrders, sortBookings } from "./modules/order/utils/filterBookings";
|
|
41
42
|
import { buildSmallTicketData, hasSmallTicketData } from "./utils/small-ticket";
|
|
42
43
|
import { BaseSalesImpl } from "../solution/BaseSales";
|
|
44
|
+
import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPendingOrderPayment, mergeOrderPaymentListsByIdentity } from "../modules/Order/payment-utils";
|
|
43
45
|
|
|
44
46
|
// 重新导出类型供外部使用
|
|
45
47
|
|
|
@@ -2472,7 +2474,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
2472
2474
|
return this.ensureCheckoutOrderNumbers(normalizedData, title);
|
|
2473
2475
|
case 6:
|
|
2474
2476
|
checkoutData = _context31.sent;
|
|
2475
|
-
remoteCheckoutData = this.
|
|
2477
|
+
remoteCheckoutData = this.buildRemoteCheckoutData(checkoutData, title);
|
|
2476
2478
|
if ((_this$app6 = this.app) !== null && _this$app6 !== void 0 && (_this$app6 = _this$app6.request) !== null && _this$app6 !== void 0 && _this$app6.post) {
|
|
2477
2479
|
_context31.next = 10;
|
|
2478
2480
|
break;
|
|
@@ -2496,18 +2498,18 @@ var Server = /*#__PURE__*/function () {
|
|
|
2496
2498
|
errorResponse: response,
|
|
2497
2499
|
response: response,
|
|
2498
2500
|
normalizedResponse: this.normalizeCheckoutResponse(response),
|
|
2499
|
-
checkoutData:
|
|
2501
|
+
checkoutData: checkoutData
|
|
2500
2502
|
});
|
|
2501
2503
|
case 15:
|
|
2502
2504
|
fresh = this.extractOrderDataFromCheckoutResponse(response);
|
|
2503
|
-
externalSaleNumber = this.getCheckoutExternalSaleNumber(
|
|
2505
|
+
externalSaleNumber = this.getCheckoutExternalSaleNumber(checkoutData, {
|
|
2504
2506
|
external_sale_number: params.externalSaleNumber,
|
|
2505
|
-
data:
|
|
2507
|
+
data: checkoutData
|
|
2506
2508
|
});
|
|
2507
2509
|
_context31.next = 19;
|
|
2508
2510
|
return this.persistSyncedCheckoutOrder({
|
|
2509
2511
|
backendPath: backendPath,
|
|
2510
|
-
checkoutData:
|
|
2512
|
+
checkoutData: checkoutData,
|
|
2511
2513
|
externalSaleNumber: externalSaleNumber,
|
|
2512
2514
|
fresh: fresh,
|
|
2513
2515
|
title: title,
|
|
@@ -2520,7 +2522,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
2520
2522
|
checkoutResponseOrder: fresh
|
|
2521
2523
|
}) : undefined;
|
|
2522
2524
|
if (!(printableSyncedOrder && this.shouldPrintSyncedOrder({
|
|
2523
|
-
checkoutData:
|
|
2525
|
+
checkoutData: checkoutData,
|
|
2524
2526
|
syncedOrder: printableSyncedOrder
|
|
2525
2527
|
}))) {
|
|
2526
2528
|
_context31.next = 24;
|
|
@@ -2528,7 +2530,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
2528
2530
|
}
|
|
2529
2531
|
_context31.next = 24;
|
|
2530
2532
|
return this.dispatchPrintOtherReceiptTask({
|
|
2531
|
-
checkoutData:
|
|
2533
|
+
checkoutData: checkoutData,
|
|
2532
2534
|
syncedOrder: printableSyncedOrder,
|
|
2533
2535
|
response: response,
|
|
2534
2536
|
deviceId: params.deviceId
|
|
@@ -2538,7 +2540,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
2538
2540
|
rejected: false,
|
|
2539
2541
|
response: response,
|
|
2540
2542
|
normalizedResponse: this.normalizeCheckoutResponse(response),
|
|
2541
|
-
checkoutData:
|
|
2543
|
+
checkoutData: checkoutData,
|
|
2542
2544
|
syncedOrder: syncedOrder,
|
|
2543
2545
|
fresh: fresh
|
|
2544
2546
|
});
|
|
@@ -2562,6 +2564,67 @@ var Server = /*#__PURE__*/function () {
|
|
|
2562
2564
|
delete next.syncMode;
|
|
2563
2565
|
return next;
|
|
2564
2566
|
}
|
|
2567
|
+
}, {
|
|
2568
|
+
key: "buildRemoteCheckoutData",
|
|
2569
|
+
value: function buildRemoteCheckoutData(data, title) {
|
|
2570
|
+
var next = cloneDeep(this.omitCheckoutSyncMode(data));
|
|
2571
|
+
if (!next || _typeof(next) !== 'object') return next;
|
|
2572
|
+
var record = next;
|
|
2573
|
+
if (!Array.isArray(record.payments)) return next;
|
|
2574
|
+
var originalPayments = record.payments;
|
|
2575
|
+
var filteredPayments = originalPayments.filter(function (payment) {
|
|
2576
|
+
return !isPendingOrderPayment(payment);
|
|
2577
|
+
});
|
|
2578
|
+
var removedPayments = originalPayments.filter(function (payment) {
|
|
2579
|
+
return isPendingOrderPayment(payment);
|
|
2580
|
+
});
|
|
2581
|
+
record.payments = filteredPayments;
|
|
2582
|
+
this.logInfo("".concat(title, ": checkout \u4E91\u7AEF\u652F\u4ED8\u9879\u5DF2\u8FC7\u6EE4"), {
|
|
2583
|
+
external_sale_number: record.external_sale_number,
|
|
2584
|
+
original_payment_count: originalPayments.length,
|
|
2585
|
+
remote_payment_count: filteredPayments.length,
|
|
2586
|
+
filtered_pending_count: removedPayments.length,
|
|
2587
|
+
filtered_payment_identities: removedPayments.map(function (payment) {
|
|
2588
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2589
|
+
})
|
|
2590
|
+
});
|
|
2591
|
+
return next;
|
|
2592
|
+
}
|
|
2593
|
+
}, {
|
|
2594
|
+
key: "mergeCheckoutSyncPayments",
|
|
2595
|
+
value: function mergeCheckoutSyncPayments(checkoutData, fresh, title) {
|
|
2596
|
+
var localPayments = Array.isArray(checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.payments) ? checkoutData.payments : [];
|
|
2597
|
+
var freshRecord = fresh;
|
|
2598
|
+
if (!Array.isArray(freshRecord.payments)) {
|
|
2599
|
+
return localPayments.length > 0 ? _objectSpread(_objectSpread({}, freshRecord), {}, {
|
|
2600
|
+
payments: cloneDeep(localPayments)
|
|
2601
|
+
}) : freshRecord;
|
|
2602
|
+
}
|
|
2603
|
+
var freshPayments = freshRecord.payments;
|
|
2604
|
+
var mergedPayments = mergeOrderPaymentListsByIdentity(localPayments, freshPayments, {
|
|
2605
|
+
preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
|
|
2606
|
+
});
|
|
2607
|
+
var remoteIdentityKeys = new Set(freshPayments.flatMap(function (payment) {
|
|
2608
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2609
|
+
}));
|
|
2610
|
+
var preservedPending = localPayments.filter(function (payment) {
|
|
2611
|
+
return isIdentifiedPendingOrderPayment(payment) && !getOrderPaymentIdentityKeys(payment).some(function (key) {
|
|
2612
|
+
return remoteIdentityKeys.has(key);
|
|
2613
|
+
});
|
|
2614
|
+
});
|
|
2615
|
+
if (preservedPending.length > 0) {
|
|
2616
|
+
this.logInfo("".concat(title, ": checkout \u54CD\u5E94\u5408\u5E76\u4FDD\u7559\u672C\u5730 pending \u652F\u4ED8\u9879"), {
|
|
2617
|
+
external_sale_number: checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.external_sale_number,
|
|
2618
|
+
preserved_pending_count: preservedPending.length,
|
|
2619
|
+
preserved_payment_identities: preservedPending.map(function (payment) {
|
|
2620
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2621
|
+
})
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
return _objectSpread(_objectSpread({}, freshRecord), {}, {
|
|
2625
|
+
payments: mergedPayments
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2565
2628
|
}, {
|
|
2566
2629
|
key: "persistSyncedCheckoutOrder",
|
|
2567
2630
|
value: function () {
|
|
@@ -2576,11 +2639,11 @@ var Server = /*#__PURE__*/function () {
|
|
|
2576
2639
|
_context32.next = 9;
|
|
2577
2640
|
break;
|
|
2578
2641
|
}
|
|
2579
|
-
syncedOrder = persistCheckoutDataWithResponse ? _objectSpread(_objectSpread(_objectSpread({}, checkoutData), fresh), {}, {
|
|
2642
|
+
syncedOrder = persistCheckoutDataWithResponse ? _objectSpread(_objectSpread(_objectSpread({}, checkoutData), this.mergeCheckoutSyncPayments(checkoutData, fresh, title)), {}, {
|
|
2580
2643
|
external_sale_number: (_external_sale_number2 = fresh.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : externalSaleNumber,
|
|
2581
2644
|
need_sync: 0,
|
|
2582
2645
|
is_draft_order: 0
|
|
2583
|
-
}) : _objectSpread(_objectSpread({}, fresh), {}, {
|
|
2646
|
+
}) : _objectSpread(_objectSpread({}, this.mergeCheckoutSyncPayments(checkoutData, fresh, title)), {}, {
|
|
2584
2647
|
external_sale_number: (_external_sale_number3 = fresh.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : externalSaleNumber,
|
|
2585
2648
|
need_sync: 0,
|
|
2586
2649
|
is_draft_order: 0
|
|
@@ -260,6 +260,9 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
260
260
|
private getProductIdentityKeys;
|
|
261
261
|
private mergeOrderProductLists;
|
|
262
262
|
private mergeOrderPaymentLists;
|
|
263
|
+
private getIdentifiedPendingPayments;
|
|
264
|
+
private shouldProtectLocalOrderFromRemoteSnapshot;
|
|
265
|
+
private getUnmatchedIdentifiedPendingPayments;
|
|
263
266
|
private mergeOrderRecords;
|
|
264
267
|
private summarizeDuplicateOrders;
|
|
265
268
|
private logDuplicateOrders;
|
|
@@ -305,7 +308,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
305
308
|
*/
|
|
306
309
|
private updateOrderInSQLite;
|
|
307
310
|
/**
|
|
308
|
-
* 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync
|
|
311
|
+
* 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync / pending 支付订单。
|
|
309
312
|
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
310
313
|
*
|
|
311
314
|
* @example
|
|
@@ -7,11 +7,11 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
|
|
|
7
7
|
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."); }
|
|
8
8
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
-
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; }
|
|
11
|
-
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; }
|
|
12
10
|
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; } } }; }
|
|
13
11
|
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); }
|
|
14
12
|
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; }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
15
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
16
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
17
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -35,7 +35,7 @@ import dayjs from 'dayjs';
|
|
|
35
35
|
import { BaseModule } from "../../../modules/BaseModule";
|
|
36
36
|
import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
|
|
37
37
|
import { OrderHooks } from "./types";
|
|
38
|
-
import { mergeOrderPaymentListsByIdentity, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "../../../modules/Order/payment-utils";
|
|
38
|
+
import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPendingOrderPayment, mergeOrderPaymentListsByIdentity, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "../../../modules/Order/payment-utils";
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* SQLite 存储名称
|
|
@@ -57,6 +57,7 @@ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPen
|
|
|
57
57
|
* 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
|
|
58
58
|
*/
|
|
59
59
|
var ORDER_MERGE_SELF_CHECK = false;
|
|
60
|
+
var PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER = '__pisell_os_pending_payment_without_unique_number__';
|
|
60
61
|
var ORDER_AUTHORITATIVE_COLLECTION_FIELDS = ['products', 'bookings', 'payments'];
|
|
61
62
|
var ORDER_COLLECTION_KIND_BY_FIELD = {
|
|
62
63
|
products: 'product',
|
|
@@ -245,7 +246,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
245
246
|
}, {
|
|
246
247
|
key: "normalizeOrderCollectionsForIngress",
|
|
247
248
|
value: function normalizeOrderCollectionsForIngress(order, source) {
|
|
248
|
-
var
|
|
249
|
+
var sourceOrder = cloneDeep(order);
|
|
250
|
+
var sourceOrderRecord = sourceOrder;
|
|
251
|
+
if (Array.isArray(sourceOrderRecord.payments)) {
|
|
252
|
+
sourceOrderRecord.payments = sourceOrderRecord.payments.map(function (payment) {
|
|
253
|
+
if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
|
|
254
|
+
return key.startsWith('unique_payment_number:');
|
|
255
|
+
})) {
|
|
256
|
+
return payment;
|
|
257
|
+
}
|
|
258
|
+
return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
var result = normalizeOrderCollections(sourceOrder);
|
|
262
|
+
var normalizedOrderRecord = result.order;
|
|
263
|
+
if (Array.isArray(normalizedOrderRecord.payments)) {
|
|
264
|
+
normalizedOrderRecord.payments = normalizedOrderRecord.payments.map(function (payment) {
|
|
265
|
+
if (!(payment !== null && payment !== void 0 && payment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER])) return payment;
|
|
266
|
+
var nextPayment = _objectSpread({}, payment);
|
|
267
|
+
var metadata = _objectSpread({}, nextPayment.metadata || {});
|
|
268
|
+
delete metadata.unique_payment_number;
|
|
269
|
+
delete nextPayment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER];
|
|
270
|
+
nextPayment.metadata = metadata;
|
|
271
|
+
return nextPayment;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
249
274
|
var kinds = ['product', 'booking', 'payment'];
|
|
250
275
|
var hasChanges = kinds.some(function (kind) {
|
|
251
276
|
var stats = result.stats[kind];
|
|
@@ -289,8 +314,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
289
314
|
key: "mergeAuthoritativeOrderCollection",
|
|
290
315
|
value: function mergeAuthoritativeOrderCollection(field, existing, incoming) {
|
|
291
316
|
var uidRemaps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
317
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
292
318
|
var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
|
|
293
319
|
var existingItems = Array.isArray(existing) ? existing : [];
|
|
320
|
+
if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
|
|
321
|
+
return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
|
|
322
|
+
preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
|
|
323
|
+
});
|
|
324
|
+
}
|
|
294
325
|
return incoming.map(function (incomingItem) {
|
|
295
326
|
var existingItem = existingItems.find(function (item) {
|
|
296
327
|
return isSameOrderCollectionItem(kind, item, incomingItem);
|
|
@@ -961,12 +992,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
961
992
|
return this.loadOrdersFromSQLite();
|
|
962
993
|
case 3:
|
|
963
994
|
protectedOrdersBeforeRemoteFetch = _context7.sent.filter(function (order) {
|
|
964
|
-
return _this5.
|
|
995
|
+
return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
|
|
965
996
|
});
|
|
966
997
|
this.logInfo('loadOrdersByServer-开始', {
|
|
967
998
|
hasOrderDataSource: !!this.orderDataSource,
|
|
968
999
|
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
|
|
969
|
-
protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length
|
|
1000
|
+
protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
|
|
1001
|
+
protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
|
|
1002
|
+
return count + _this5.getIdentifiedPendingPayments(order).length;
|
|
1003
|
+
}, 0)
|
|
970
1004
|
});
|
|
971
1005
|
if (!this.orderDataSource) {
|
|
972
1006
|
_context7.next = 20;
|
|
@@ -2745,6 +2779,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2745
2779
|
if (incomingList.length === 0) return cloneDeep(existingList);
|
|
2746
2780
|
return mergeOrderPaymentListsByIdentity(existingList, incomingList);
|
|
2747
2781
|
}
|
|
2782
|
+
}, {
|
|
2783
|
+
key: "getIdentifiedPendingPayments",
|
|
2784
|
+
value: function getIdentifiedPendingPayments(order) {
|
|
2785
|
+
var payments = Array.isArray(order === null || order === void 0 ? void 0 : order.payments) ? order.payments : [];
|
|
2786
|
+
return payments.filter(function (payment) {
|
|
2787
|
+
return isIdentifiedPendingOrderPayment(payment);
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
}, {
|
|
2791
|
+
key: "shouldProtectLocalOrderFromRemoteSnapshot",
|
|
2792
|
+
value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
|
|
2793
|
+
return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
|
|
2794
|
+
}
|
|
2795
|
+
}, {
|
|
2796
|
+
key: "getUnmatchedIdentifiedPendingPayments",
|
|
2797
|
+
value: function getUnmatchedIdentifiedPendingPayments(existing, incoming) {
|
|
2798
|
+
var existingPayments = Array.isArray(existing) ? existing : [];
|
|
2799
|
+
var incomingPayments = Array.isArray(incoming) ? incoming : [];
|
|
2800
|
+
var incomingIdentityKeys = new Set(incomingPayments.flatMap(function (payment) {
|
|
2801
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2802
|
+
}));
|
|
2803
|
+
return existingPayments.filter(function (payment) {
|
|
2804
|
+
return isIdentifiedPendingOrderPayment(payment) && !getOrderPaymentIdentityKeys(payment).some(function (key) {
|
|
2805
|
+
return incomingIdentityKeys.has(key);
|
|
2806
|
+
});
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2748
2809
|
}, {
|
|
2749
2810
|
key: "mergeOrderRecords",
|
|
2750
2811
|
value: function mergeOrderRecords(existing, incoming) {
|
|
@@ -2782,7 +2843,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2782
2843
|
for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
|
|
2783
2844
|
var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
|
|
2784
2845
|
if (Array.isArray(incomingRecord[_field2])) {
|
|
2785
|
-
|
|
2846
|
+
if (_field2 === 'payments') {
|
|
2847
|
+
var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
|
|
2848
|
+
if (preservedPending.length > 0) {
|
|
2849
|
+
var _ref5, _existing$order_id, _ref6, _existingRecord$exter;
|
|
2850
|
+
this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
|
|
2851
|
+
order_id: (_ref5 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
|
|
2852
|
+
external_sale_number: (_ref6 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref6 !== void 0 ? _ref6 : null,
|
|
2853
|
+
preserved_pending_count: preservedPending.length,
|
|
2854
|
+
preserved_payment_identities: preservedPending.map(function (payment) {
|
|
2855
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2856
|
+
})
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
mergedRecord[_field2] = this.mergeAuthoritativeOrderCollection(_field2, existingRecord[_field2], incomingRecord[_field2], childUidRemaps, {
|
|
2861
|
+
preserveIdentifiedPendingPayments: _field2 === 'payments'
|
|
2862
|
+
});
|
|
2786
2863
|
continue;
|
|
2787
2864
|
}
|
|
2788
2865
|
if (Object.prototype.hasOwnProperty.call(existingRecord, _field2)) {
|
|
@@ -2825,14 +2902,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2825
2902
|
} finally {
|
|
2826
2903
|
_iterator26.f();
|
|
2827
2904
|
}
|
|
2828
|
-
return _toConsumableArray(groups.entries()).filter(function (
|
|
2829
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
2830
|
-
group = _ref6[1];
|
|
2831
|
-
return group.length > 1;
|
|
2832
|
-
}).slice(0, 20).map(function (_ref7) {
|
|
2905
|
+
return _toConsumableArray(groups.entries()).filter(function (_ref7) {
|
|
2833
2906
|
var _ref8 = _slicedToArray(_ref7, 2),
|
|
2834
|
-
key = _ref8[0],
|
|
2835
2907
|
group = _ref8[1];
|
|
2908
|
+
return group.length > 1;
|
|
2909
|
+
}).slice(0, 20).map(function (_ref9) {
|
|
2910
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
2911
|
+
key = _ref10[0],
|
|
2912
|
+
group = _ref10[1];
|
|
2836
2913
|
return {
|
|
2837
2914
|
key: key,
|
|
2838
2915
|
count: group.length,
|
|
@@ -3069,7 +3146,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3069
3146
|
for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
|
|
3070
3147
|
var rawOrder = _step29.value;
|
|
3071
3148
|
var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
|
|
3072
|
-
if (!this.
|
|
3149
|
+
if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
|
|
3073
3150
|
var matchIndex = this.findOrderIndexByIdentity(merged, order);
|
|
3074
3151
|
if (matchIndex >= 0) {
|
|
3075
3152
|
if (this.isDraftOrder(order)) {
|
|
@@ -3443,7 +3520,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3443
3520
|
return updateOrderInSQLite;
|
|
3444
3521
|
}()
|
|
3445
3522
|
/**
|
|
3446
|
-
* 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync
|
|
3523
|
+
* 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync / pending 支付订单。
|
|
3447
3524
|
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
3448
3525
|
*
|
|
3449
3526
|
* @example
|
|
@@ -3501,7 +3578,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3501
3578
|
protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
|
|
3502
3579
|
return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
|
|
3503
3580
|
}).filter(function (order) {
|
|
3504
|
-
return _this23.
|
|
3581
|
+
return _this23.shouldProtectLocalOrderFromRemoteSnapshot(order);
|
|
3505
3582
|
});
|
|
3506
3583
|
_iterator31 = _createForOfIteratorHelper(existingOrders || []);
|
|
3507
3584
|
_context25.prev = 10;
|
|
@@ -3514,7 +3591,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3514
3591
|
rawCurrentOrder = _step31.value;
|
|
3515
3592
|
currentOrder = _this23.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
|
|
3516
3593
|
protectedIndex = _this23.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
|
|
3517
|
-
currentNeedsProtection = _this23.
|
|
3594
|
+
currentNeedsProtection = _this23.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
|
|
3518
3595
|
if (!(protectedIndex >= 0)) {
|
|
3519
3596
|
_context25.next = 20;
|
|
3520
3597
|
break;
|
|
@@ -3550,7 +3627,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3550
3627
|
remoteCount: remoteSnapshot.length,
|
|
3551
3628
|
protectedBeforeRemoteFetchCount: protectedOrdersBeforeRemoteFetch.length,
|
|
3552
3629
|
protectedLocalOrderCount: protectedLocalOrders.length,
|
|
3553
|
-
preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length
|
|
3630
|
+
preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
|
|
3631
|
+
protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
|
|
3632
|
+
return count + _this23.getIdentifiedPendingPayments(order).length;
|
|
3633
|
+
}, 0),
|
|
3634
|
+
protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
|
|
3635
|
+
return _this23.getIdentifiedPendingPayments(order).map(function (payment) {
|
|
3636
|
+
var _order$order_id5, _external_sale_number5;
|
|
3637
|
+
return {
|
|
3638
|
+
order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
|
|
3639
|
+
external_sale_number: (_external_sale_number5 = order.external_sale_number) !== null && _external_sale_number5 !== void 0 ? _external_sale_number5 : null,
|
|
3640
|
+
payment_identities: getOrderPaymentIdentityKeys(payment)
|
|
3641
|
+
};
|
|
3642
|
+
});
|
|
3643
|
+
})
|
|
3554
3644
|
});
|
|
3555
3645
|
_context25.next = 36;
|
|
3556
3646
|
return _this23.dbManager.clear(INDEXDB_STORE_NAME);
|
|
@@ -37,7 +37,7 @@ import Decimal from 'decimal.js';
|
|
|
37
37
|
import { cloneDeep, mergeWith } from 'lodash-es';
|
|
38
38
|
import { createModule } from "../BookingByStep/types";
|
|
39
39
|
import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, resolveIsFormSubject, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
40
|
-
import { ensureOrderPaymentNumber, mergeOrderPaymentListsByIdentity, resolveOrderPaymentIdentity } from "../../modules/Order/payment-utils";
|
|
40
|
+
import { ensureOrderPaymentNumber, isIdentifiedPendingOrderPayment, mergeOrderPaymentListsByIdentity, resolveOrderPaymentIdentity } from "../../modules/Order/payment-utils";
|
|
41
41
|
import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
|
|
42
42
|
import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollection, normalizeOrderCollections, setOrderCollectionUid } from "../../modules/Order/utils/orderCollectionIdentity";
|
|
43
43
|
import dayjs from 'dayjs';
|
|
@@ -149,6 +149,15 @@ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps
|
|
|
149
149
|
return kind === 'product' ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
|
|
150
150
|
}
|
|
151
151
|
function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
|
|
152
|
+
if (kind === 'payment') {
|
|
153
|
+
return mergeOrderPaymentListsByIdentity(currentValue, incomingValue, strategy === 'preserve-local' ? {
|
|
154
|
+
preserveUnmatchedExisting: true
|
|
155
|
+
} : {
|
|
156
|
+
preserveUnmatchedExistingWhen: function preserveUnmatchedExistingWhen(payment) {
|
|
157
|
+
return isIdentifiedPendingOrderPayment(payment) || !getOrderCollectionPersistentId('payment', payment);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
152
161
|
var currentItems = normalizeOrderCollection(kind, currentValue, {
|
|
153
162
|
ensureUid: false
|
|
154
163
|
}).items;
|
|
@@ -245,9 +245,10 @@ export function mergeIdenticalPromotionCartLines(products) {
|
|
|
245
245
|
var unitPrice = String((_ref2 = (_line$metadata$source = (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.source_product_price) !== null && _line$metadata$source !== void 0 ? _line$metadata$source : line.selling_price) !== null && _ref2 !== void 0 ? _ref2 : '');
|
|
246
246
|
var promoUnitPrice = String((_ref3 = (_promotion$finalPrice = promotion.finalPrice) !== null && _promotion$finalPrice !== void 0 ? _promotion$finalPrice : (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.main_product_selling_price) !== null && _ref3 !== void 0 ? _ref3 : '');
|
|
247
247
|
var noteSignature = getProductLineNoteSignature(line);
|
|
248
|
+
var lineMergeBoundary = getPromotionLineMergeBoundary(line);
|
|
248
249
|
var bookingUid = (_line$booking_uid = line === null || line === void 0 ? void 0 : line.booking_uid) !== null && _line$booking_uid !== void 0 ? _line$booking_uid : line === null || line === void 0 || (_line$metadata4 = line.metadata) === null || _line$metadata4 === void 0 ? void 0 : _line$metadata4.booking_uid;
|
|
249
250
|
var orderDetailId = (_line$order_detail_id = line === null || line === void 0 ? void 0 : line.order_detail_id) !== null && _line$order_detail_id !== void 0 ? _line$order_detail_id : line === null || line === void 0 ? void 0 : line.orderDetailId;
|
|
250
|
-
var mergeKey = [line.product_id, (_line$product_variant = line.product_variant_id) !== null && _line$product_variant !== void 0 ? _line$product_variant : 0, fingerprint, noteSignature, bookingUid ? String(bookingUid) : '', orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '' ? String(orderDetailId) : '', promotion.strategyId, unitPrice, promoUnitPrice].join('#');
|
|
251
|
+
var mergeKey = [line.product_id, (_line$product_variant = line.product_variant_id) !== null && _line$product_variant !== void 0 ? _line$product_variant : 0, fingerprint, noteSignature, lineMergeBoundary, bookingUid ? String(bookingUid) : '', orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '' ? String(orderDetailId) : '', promotion.strategyId, unitPrice, promoUnitPrice].join('#');
|
|
251
252
|
var hitIndex = indexByKey.get(mergeKey);
|
|
252
253
|
if (hitIndex === undefined) {
|
|
253
254
|
indexByKey.set(mergeKey, merged.length);
|
|
@@ -423,6 +424,16 @@ function getProductLineNoteSignature(product) {
|
|
|
423
424
|
var uid = getOrderProductUid(product);
|
|
424
425
|
return uid ? "note:".concat(uid) : "note:".concat(normalizedNote);
|
|
425
426
|
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 编辑订单时,历史行仍参与整车促销评估,但不能与本次新增行合并。
|
|
430
|
+
* 以历史行 uid 作为促销前后的行边界;新增行返回空边界,仍保留原有合并语义。
|
|
431
|
+
*/
|
|
432
|
+
function getPromotionLineMergeBoundary(product) {
|
|
433
|
+
var _product$metadata3;
|
|
434
|
+
if ((product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.is_edit_for_runtime) !== true) return '';
|
|
435
|
+
return "edit:".concat(getOrderProductUid(product));
|
|
436
|
+
}
|
|
426
437
|
function isPersistedGeneratedVoucher(product) {
|
|
427
438
|
var _product$order_detail;
|
|
428
439
|
var orderDetailId = (_product$order_detail = product === null || product === void 0 ? void 0 : product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : product === null || product === void 0 ? void 0 : product.orderDetailId;
|
|
@@ -463,17 +474,18 @@ export function buildConsolidateKeyForPromotion(item) {
|
|
|
463
474
|
var _item$booking_uid, _item$metadata, _item$order_detail_id, _item$product_variant3;
|
|
464
475
|
var fingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
|
|
465
476
|
var noteSignature = getProductLineNoteSignature(item);
|
|
477
|
+
var lineMergeBoundary = getPromotionLineMergeBoundary(item);
|
|
466
478
|
var bookingUid = (_item$booking_uid = item === null || item === void 0 ? void 0 : item.booking_uid) !== null && _item$booking_uid !== void 0 ? _item$booking_uid : item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.booking_uid;
|
|
467
479
|
var orderDetailId = (_item$order_detail_id = item === null || item === void 0 ? void 0 : item.order_detail_id) !== null && _item$order_detail_id !== void 0 ? _item$order_detail_id : item === null || item === void 0 ? void 0 : item.orderDetailId;
|
|
468
480
|
if (orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '') {
|
|
469
481
|
var _item$product_variant;
|
|
470
|
-
return [item.product_id, (_item$product_variant = item.product_variant_id) !== null && _item$product_variant !== void 0 ? _item$product_variant : 0, fingerprint, noteSignature, String(orderDetailId)].join('#');
|
|
482
|
+
return [item.product_id, (_item$product_variant = item.product_variant_id) !== null && _item$product_variant !== void 0 ? _item$product_variant : 0, fingerprint, noteSignature, lineMergeBoundary, String(orderDetailId)].join('#');
|
|
471
483
|
}
|
|
472
484
|
if (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '') {
|
|
473
485
|
var _item$product_variant2;
|
|
474
|
-
return [item.product_id, (_item$product_variant2 = item.product_variant_id) !== null && _item$product_variant2 !== void 0 ? _item$product_variant2 : 0, fingerprint, noteSignature, String(bookingUid)].join('#');
|
|
486
|
+
return [item.product_id, (_item$product_variant2 = item.product_variant_id) !== null && _item$product_variant2 !== void 0 ? _item$product_variant2 : 0, fingerprint, noteSignature, lineMergeBoundary, String(bookingUid)].join('#');
|
|
475
487
|
}
|
|
476
|
-
return [item.product_id, (_item$product_variant3 = item.product_variant_id) !== null && _item$product_variant3 !== void 0 ? _item$product_variant3 : 0, fingerprint, noteSignature].join('#');
|
|
488
|
+
return [item.product_id, (_item$product_variant3 = item.product_variant_id) !== null && _item$product_variant3 !== void 0 ? _item$product_variant3 : 0, fingerprint, noteSignature, lineMergeBoundary].join('#');
|
|
477
489
|
}
|
|
478
490
|
function consolidateMainProductsForPromotion(entries) {
|
|
479
491
|
if (!Array.isArray(entries) || entries.length <= 1) {
|
|
@@ -838,13 +850,13 @@ export function resolveStrategyEligibleProducts(matched) {
|
|
|
838
850
|
export function calculateUnfulfilledPromotions(processedProducts, applicableStrategiesResult, mainProducts) {
|
|
839
851
|
var unfulfilledMap = new Map();
|
|
840
852
|
var _loop2 = function _loop2() {
|
|
841
|
-
var _product$
|
|
853
|
+
var _product$metadata4, _ref13, _product$_originalPro, _product$metadata5, _product$num2;
|
|
842
854
|
var product = processedProducts[i];
|
|
843
|
-
var promotion = product === null || product === void 0 || (_product$
|
|
855
|
+
var promotion = product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4._promotion;
|
|
844
856
|
if (!promotion || promotion.inPromotion !== false) return 0; // continue
|
|
845
857
|
var strategyId = promotion.strategyId;
|
|
846
858
|
if (!strategyId) return 0; // continue
|
|
847
|
-
var lookupUid = String((_ref13 = (_product$_originalPro = product === null || product === void 0 ? void 0 : product._originalProductUid) !== null && _product$_originalPro !== void 0 ? _product$_originalPro : product === null || product === void 0 || (_product$
|
|
859
|
+
var lookupUid = String((_ref13 = (_product$_originalPro = product === null || product === void 0 ? void 0 : product._originalProductUid) !== null && _product$_originalPro !== void 0 ? _product$_originalPro : product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) !== null && _ref13 !== void 0 ? _ref13 : '');
|
|
848
860
|
var originalIndex = mainProducts.findIndex(function (item) {
|
|
849
861
|
return getOrderProductUid(item) === lookupUid;
|
|
850
862
|
});
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -83,6 +83,7 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
83
83
|
private getBookingAppointmentStatus;
|
|
84
84
|
private isBookingIncludedInStats;
|
|
85
85
|
private getBookingOrderPaymentStatus;
|
|
86
|
+
private isUnpaidBooking;
|
|
86
87
|
private countBookingOrders;
|
|
87
88
|
private countCompletedBookings;
|
|
88
89
|
private groupBookingsByResource;
|
|
@@ -29,6 +29,7 @@ import dayjs from 'dayjs';
|
|
|
29
29
|
import { BaseModule } from "../../modules/BaseModule";
|
|
30
30
|
import { SalesHooks } from "./types";
|
|
31
31
|
export * from "./types";
|
|
32
|
+
var UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Sales 解决方案基础骨架
|
|
@@ -415,6 +416,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
415
416
|
var _booking$order$paymen, _booking$order;
|
|
416
417
|
return String((_booking$order$paymen = (_booking$order = booking.order) === null || _booking$order === void 0 ? void 0 : _booking$order.payment_status) !== null && _booking$order$paymen !== void 0 ? _booking$order$paymen : '');
|
|
417
418
|
}
|
|
419
|
+
}, {
|
|
420
|
+
key: "isUnpaidBooking",
|
|
421
|
+
value: function isUnpaidBooking(booking) {
|
|
422
|
+
return UNPAID_PAYMENT_STATUSES.has(this.getBookingOrderPaymentStatus(booking));
|
|
423
|
+
}
|
|
418
424
|
}, {
|
|
419
425
|
key: "countBookingOrders",
|
|
420
426
|
value: function countBookingOrders(bookings) {
|
|
@@ -895,9 +901,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
895
901
|
});
|
|
896
902
|
completedBookingList = matchedBookingList.filter(function (booking) {
|
|
897
903
|
return _this7.getBookingAppointmentStatus(booking) === 'completed';
|
|
898
|
-
});
|
|
904
|
+
}); // const unpaidBookingList = matchedBookingList.filter(
|
|
905
|
+
// (booking) => this.getBookingOrderPaymentStatus(booking) === 'unpaid' || this.getBookingOrderPaymentStatus(booking) === 'payment_processing',
|
|
906
|
+
// );
|
|
899
907
|
unpaidBookingList = matchedBookingList.filter(function (booking) {
|
|
900
|
-
return _this7.
|
|
908
|
+
return _this7.isUnpaidBooking(booking);
|
|
901
909
|
});
|
|
902
910
|
bookings = this.pickBookingsForCurrentPoint(current, this.normalizeResourceBookings(current, deviceCurrent, matchedBookingList));
|
|
903
911
|
completedBookings = completedBookingList.map(function (booking) {
|
|
@@ -48,7 +48,7 @@ export interface BookingResourceInput {
|
|
|
48
48
|
capacity?: number;
|
|
49
49
|
like_status?: string;
|
|
50
50
|
metadata?: Record<string, any>;
|
|
51
|
-
children?:
|
|
51
|
+
children?: BookingResourceInput[];
|
|
52
52
|
}
|
|
53
53
|
/** custom / package 人数维度快照,与 info2 `_extend.capacity` / `metadata.capacity` 对齐。 */
|
|
54
54
|
export interface BookingCapacityMetadataItem {
|
|
@@ -88,6 +88,24 @@ function resolveDurationMinutes(value) {
|
|
|
88
88
|
const n = Number(value);
|
|
89
89
|
return Number.isNaN(n) ? void 0 : n;
|
|
90
90
|
}
|
|
91
|
+
function normalizeChildResource(child, parentFormId) {
|
|
92
|
+
const item = {
|
|
93
|
+
form_id: (child == null ? void 0 : child.form_id) ?? parentFormId,
|
|
94
|
+
relation_type: (child == null ? void 0 : child.relation_type) || "form",
|
|
95
|
+
relation_id: (child == null ? void 0 : child.relation_id) ?? (child == null ? void 0 : child.id),
|
|
96
|
+
capacity: child == null ? void 0 : child.capacity,
|
|
97
|
+
like_status: (child == null ? void 0 : child.like_status) || "common"
|
|
98
|
+
};
|
|
99
|
+
if ((child == null ? void 0 : child.metadata) !== void 0) {
|
|
100
|
+
item.metadata = { ...child.metadata };
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(child == null ? void 0 : child.children)) {
|
|
103
|
+
item.children = child.children.map(
|
|
104
|
+
(nestedChild) => normalizeChildResource(nestedChild, item.form_id)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return item;
|
|
108
|
+
}
|
|
91
109
|
function flattenResources(cacheItem) {
|
|
92
110
|
var _a;
|
|
93
111
|
const resourceMap = ((_a = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _a.resource) || {};
|
|
@@ -107,8 +125,11 @@ function flattenResources(cacheItem) {
|
|
|
107
125
|
if ((r == null ? void 0 : r.metadata) !== void 0) {
|
|
108
126
|
item.metadata = { ...r.metadata };
|
|
109
127
|
}
|
|
110
|
-
if ((r == null ? void 0 : r.children)
|
|
111
|
-
item.children = r.children
|
|
128
|
+
if (Array.isArray(r == null ? void 0 : r.children)) {
|
|
129
|
+
item.children = r.children.map(
|
|
130
|
+
(child) => normalizeChildResource(child, item.form_id)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
112
133
|
result.push(item);
|
|
113
134
|
});
|
|
114
135
|
});
|