@pisell/pisellos 2.3.28 → 2.3.30

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.
Files changed (57) hide show
  1. package/dist/modules/Order/index.d.ts +32 -8
  2. package/dist/modules/Order/index.js +883 -521
  3. package/dist/modules/Order/payment-utils.d.ts +23 -0
  4. package/dist/modules/Order/payment-utils.js +203 -0
  5. package/dist/modules/Order/types.d.ts +33 -1
  6. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  7. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  8. package/dist/modules/Order/utils.d.ts +2 -1
  9. package/dist/modules/Order/utils.js +6 -12
  10. package/dist/modules/Payment/index.d.ts +2 -0
  11. package/dist/modules/Payment/index.js +78 -49
  12. package/dist/modules/Payment/types.d.ts +26 -24
  13. package/dist/modules/Payment/types.js +2 -0
  14. package/dist/modules/Product/index.d.ts +1 -1
  15. package/dist/server/index.d.ts +14 -0
  16. package/dist/server/index.js +1826 -1000
  17. package/dist/server/modules/order/index.d.ts +47 -4
  18. package/dist/server/modules/order/index.js +1415 -711
  19. package/dist/server/modules/order/types.d.ts +11 -3
  20. package/dist/server/modules/order/types.js +1 -1
  21. package/dist/solution/BaseSales/index.d.ts +40 -4
  22. package/dist/solution/BaseSales/index.js +1268 -749
  23. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  24. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  25. package/dist/solution/BookingByStep/index.d.ts +1 -1
  26. package/dist/solution/BookingTicket/index.d.ts +13 -1
  27. package/dist/solution/BookingTicket/index.js +2 -1
  28. package/dist/utils/payment-number.d.ts +9 -0
  29. package/dist/utils/payment-number.js +69 -0
  30. package/lib/modules/Order/index.d.ts +32 -8
  31. package/lib/modules/Order/index.js +270 -64
  32. package/lib/modules/Order/payment-utils.d.ts +23 -0
  33. package/lib/modules/Order/payment-utils.js +193 -0
  34. package/lib/modules/Order/types.d.ts +33 -1
  35. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  36. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  37. package/lib/modules/Order/utils.d.ts +2 -1
  38. package/lib/modules/Order/utils.js +6 -14
  39. package/lib/modules/Payment/index.d.ts +2 -0
  40. package/lib/modules/Payment/index.js +33 -12
  41. package/lib/modules/Payment/types.d.ts +26 -24
  42. package/lib/modules/Product/index.d.ts +1 -1
  43. package/lib/server/index.d.ts +14 -0
  44. package/lib/server/index.js +604 -8
  45. package/lib/server/modules/order/index.d.ts +47 -4
  46. package/lib/server/modules/order/index.js +578 -116
  47. package/lib/server/modules/order/types.d.ts +11 -3
  48. package/lib/solution/BaseSales/index.d.ts +40 -4
  49. package/lib/solution/BaseSales/index.js +363 -37
  50. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  51. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  52. package/lib/solution/BookingByStep/index.d.ts +1 -1
  53. package/lib/solution/BookingTicket/index.d.ts +13 -1
  54. package/lib/solution/BookingTicket/index.js +2 -1
  55. package/lib/utils/payment-number.d.ts +9 -0
  56. package/lib/utils/payment-number.js +64 -0
  57. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- 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; } } }; }
2
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
3
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
@@ -20,9 +19,10 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
20
19
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
20
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
22
21
  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."); }
23
- 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); }
24
22
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
25
23
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
+ 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; } } }; }
25
+ 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); }
26
26
  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; }
27
27
  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; }
28
28
  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; }
@@ -37,6 +37,9 @@ 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";
41
+ import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
42
+ import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollection, normalizeOrderCollections, setOrderCollectionUid } from "../../modules/Order/utils/orderCollectionIdentity";
40
43
  import dayjs from 'dayjs';
41
44
  export * from "./types";
42
45
  import { QuotationModule } from "../../modules/Quotation";
@@ -73,7 +76,17 @@ function isBaseSalesHistoricalDiscountEntry(discount) {
73
76
  }
74
77
  function getBaseSalesUniqueArrayMetadataKey(key) {
75
78
  if (key === 'products' || key === 'bookings') return 'unique_identification_number';
76
- if (key === 'payments' || key === 'payment') return 'unique_payment_number';
79
+ return null;
80
+ }
81
+ var BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
82
+ product: 'order_detail_id',
83
+ booking: 'schedule_event_id',
84
+ payment: 'order_payment_id'
85
+ };
86
+ function getBaseSalesOrderCollectionKind(key) {
87
+ if (key === 'products') return 'product';
88
+ if (key === 'bookings') return 'booking';
89
+ if (key === 'payments' || key === 'payment') return 'payment';
77
90
  return null;
78
91
  }
79
92
  function isSameBaseSalesOrderRecord(left, right) {
@@ -86,12 +99,6 @@ function isSameBaseSalesOrderRecord(left, right) {
86
99
  return value !== undefined && value !== null && value !== '' && leftIdentities.has(String(value));
87
100
  });
88
101
  }
89
- function getBaseSalesMetadataUid(item, metadataKey) {
90
- var _item$metadata$metada, _item$metadata;
91
- var uid = (_item$metadata$metada = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata[metadataKey]) !== null && _item$metadata$metada !== void 0 ? _item$metadata$metada : item === null || item === void 0 ? void 0 : item[metadataKey];
92
- if (uid === undefined || uid === null || uid === '') return null;
93
- return String(uid);
94
- }
95
102
  function isBaseSalesBlankValue(value) {
96
103
  return value === undefined || value === null || value === '';
97
104
  }
@@ -109,7 +116,92 @@ function mergeBaseSalesProductSnapshotFields(currentItem, loadedItem) {
109
116
  }
110
117
  return mergedItem;
111
118
  }
112
- function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey, arrayKey) {
119
+ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps) {
120
+ var currentReferenceUid = getOrderCollectionReferenceUid(kind, currentItem);
121
+ var incomingReferenceUid = getOrderCollectionReferenceUid(kind, incomingItem);
122
+ var identityMergedItem = mergeOrderCollectionItems(kind, currentItem, incomingItem);
123
+ var mergedUid = getOrderCollectionUid(kind, identityMergedItem);
124
+ if (mergedUid) {
125
+ var _iterator = _createForOfIteratorHelper(new Set([currentReferenceUid, incomingReferenceUid])),
126
+ _step;
127
+ try {
128
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
129
+ var from = _step.value;
130
+ if (!from || from === mergedUid) continue;
131
+ uidRemaps.push({
132
+ kind: kind,
133
+ from: from,
134
+ to: mergedUid,
135
+ persistentId: getOrderCollectionPersistentId(kind, incomingItem) || getOrderCollectionPersistentId(kind, currentItem)
136
+ });
137
+ }
138
+ } catch (err) {
139
+ _iterator.e(err);
140
+ } finally {
141
+ _iterator.f();
142
+ }
143
+ }
144
+ var mergedItem = mergedUid ? setOrderCollectionUid(kind, incomingItem, mergedUid) : cloneDeep(incomingItem);
145
+ var persistentIdField = BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND[kind];
146
+ if (isBaseSalesBlankValue(mergedItem[persistentIdField]) && !isBaseSalesBlankValue(identityMergedItem[persistentIdField])) {
147
+ mergedItem[persistentIdField] = identityMergedItem[persistentIdField];
148
+ }
149
+ return kind === 'product' ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
150
+ }
151
+ function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
152
+ var currentItems = normalizeOrderCollection(kind, currentValue, {
153
+ ensureUid: false
154
+ }).items;
155
+ var incomingItems = normalizeOrderCollection(kind, incomingValue, {
156
+ ensureUid: false
157
+ }).items;
158
+ if (strategy === 'authoritative-incoming') {
159
+ var _result = cloneDeep(incomingItems);
160
+ currentItems.forEach(function (currentItem) {
161
+ var incomingIndex = _result.findIndex(function (incomingItem) {
162
+ return isSameOrderCollectionItem(kind, currentItem, incomingItem);
163
+ });
164
+ if (incomingIndex !== -1) {
165
+ _result[incomingIndex] = mergeBaseSalesCollectionItem(kind, currentItem, _result[incomingIndex], uidRemaps);
166
+ return;
167
+ }
168
+
169
+ // 完整服务端快照负责已落库行;仅保留尚未提交的本地新行。
170
+ if (!getOrderCollectionPersistentId(kind, currentItem)) {
171
+ _result.push(cloneDeep(currentItem));
172
+ }
173
+ });
174
+ return _result;
175
+ }
176
+ var result = cloneDeep(currentItems);
177
+ incomingItems.forEach(function (incomingItem) {
178
+ var currentIndex = result.findIndex(function (currentItem) {
179
+ return isSameOrderCollectionItem(kind, currentItem, incomingItem);
180
+ });
181
+ if (currentIndex !== -1) {
182
+ result[currentIndex] = mergeBaseSalesCollectionItem(kind, result[currentIndex], incomingItem, uidRemaps);
183
+ return;
184
+ }
185
+ result.push(cloneDeep(incomingItem));
186
+ });
187
+ return result;
188
+ }
189
+ function normalizeBaseSalesRecordCollections(sourceRecord, options) {
190
+ var normalizedRecord = normalizeOrderCollections(cloneDeep(sourceRecord || {}), options).order;
191
+
192
+ // 兼容旧调用方偶尔使用的单数 payment 字段。
193
+ if (Array.isArray(normalizedRecord.payment)) {
194
+ normalizedRecord.payment = normalizeOrderCollection('payment', normalizedRecord.payment, options).items;
195
+ }
196
+ return normalizedRecord;
197
+ }
198
+ function getBaseSalesMetadataUid(item, metadataKey) {
199
+ var _item$metadata$metada, _item$metadata;
200
+ var uid = (_item$metadata$metada = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata[metadataKey]) !== null && _item$metadata$metada !== void 0 ? _item$metadata$metada : item === null || item === void 0 ? void 0 : item[metadataKey];
201
+ if (uid === undefined || uid === null || uid === '') return null;
202
+ return String(uid);
203
+ }
204
+ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
113
205
  var result = [];
114
206
  var indexByUid = new Map();
115
207
  var appendOrReplaceByUid = function appendOrReplaceByUid(item) {
@@ -121,7 +213,7 @@ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey, array
121
213
  }
122
214
  var existingIndex = indexByUid.get(uid);
123
215
  if (existingIndex !== undefined) {
124
- result[existingIndex] = arrayKey === 'products' ? mergeBaseSalesProductSnapshotFields(result[existingIndex], clonedItem) : clonedItem;
216
+ result[existingIndex] = clonedItem;
125
217
  return;
126
218
  }
127
219
  indexByUid.set(uid, result.length);
@@ -131,13 +223,31 @@ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey, array
131
223
  loadedValue.forEach(appendOrReplaceByUid);
132
224
  return result;
133
225
  }
134
- function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
135
- if (!currentTempOrder) return loadedRecord;
136
- var mergedRecord = mergeWith(cloneDeep(currentTempOrder), cloneDeep(loadedRecord || {}), function (currentValue, loadedValue, key) {
226
+ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
227
+ var normalizedLoadedRecord = normalizeBaseSalesRecordCollections(loadedRecord || {}, {
228
+ ensureUid: false
229
+ });
230
+ if (!currentTempOrder) {
231
+ return normalizeBaseSalesRecordCollections(normalizedLoadedRecord);
232
+ }
233
+ var normalizedCurrentTempOrder = normalizeBaseSalesRecordCollections(currentTempOrder, {
234
+ ensureUid: false
235
+ });
236
+ var uidRemaps = [];
237
+ var mergedRecord = mergeWith(normalizedCurrentTempOrder, normalizedLoadedRecord, function (currentValue, loadedValue, key) {
238
+ var collectionKind = getBaseSalesOrderCollectionKind(key);
239
+ if (collectionKind && Array.isArray(loadedValue)) {
240
+ return mergeBaseSalesOrderCollection(collectionKind, Array.isArray(currentValue) ? currentValue : [], loadedValue, strategy, uidRemaps);
241
+ }
137
242
  if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
243
+ if (key === 'payments' || key === 'payment') {
244
+ return mergeOrderPaymentListsByIdentity(currentValue, loadedValue, {
245
+ preserveUnmatchedExisting: true
246
+ });
247
+ }
138
248
  var metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
139
249
  if (metadataKey) {
140
- return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey, key);
250
+ return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
141
251
  }
142
252
  return [].concat(_toConsumableArray(cloneDeep(currentValue)), _toConsumableArray(cloneDeep(loadedValue)));
143
253
  }
@@ -148,7 +258,7 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
148
258
  return undefined;
149
259
  });
150
260
  delete mergedRecord.request_unique_idempotency_token;
151
- return mergedRecord;
261
+ return normalizeBaseSalesRecordCollections(applyOrderCollectionUidRemaps(mergedRecord, uidRemaps));
152
262
  }
153
263
  export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
154
264
  _inherits(BaseSalesImpl, _BaseModule);
@@ -184,9 +294,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
184
294
  _defineProperty(_assertThisInitialized(_this), "queuedAutoPaymentSync", false);
185
295
  _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncFlushing", false);
186
296
  _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncTimer", null);
187
- _defineProperty(_assertThisInitialized(_this), "salesDetailLoadInFlight", false);
297
+ _defineProperty(_assertThisInitialized(_this), "salesDetailLoadInFlightCount", 0);
298
+ _defineProperty(_assertThisInitialized(_this), "salesDetailLoadSequence", 0);
299
+ _defineProperty(_assertThisInitialized(_this), "salesDetailHydrateQueue", Promise.resolve());
188
300
  _defineProperty(_assertThisInitialized(_this), "serverOrderChangeUnsubscribe", null);
189
301
  _defineProperty(_assertThisInitialized(_this), "serverOrderChangeHydrateInFlight", null);
302
+ _defineProperty(_assertThisInitialized(_this), "queuedServerOrderChanges", []);
190
303
  _defineProperty(_assertThisInitialized(_this), "serverOrderChangeSyncEnabled", false);
191
304
  return _this;
192
305
  }
@@ -281,75 +394,139 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
281
394
  key: "setServerOrderChangeSyncEnabled",
282
395
  value: function setServerOrderChangeSyncEnabled(enabled) {
283
396
  this.serverOrderChangeSyncEnabled = enabled;
397
+ if (!enabled) this.queuedServerOrderChanges = [];
398
+ }
399
+ }, {
400
+ key: "queueLatestServerOrderChange",
401
+ value: function queueLatestServerOrderChange(order) {
402
+ var snapshot = cloneDeep(order);
403
+ var existingIndex = this.queuedServerOrderChanges.findIndex(function (queued) {
404
+ return isSameBaseSalesOrderRecord(queued, snapshot);
405
+ });
406
+ if (existingIndex >= 0) {
407
+ this.queuedServerOrderChanges[existingIndex] = snapshot;
408
+ return;
409
+ }
410
+ this.queuedServerOrderChanges.push(snapshot);
284
411
  }
412
+ }, {
413
+ key: "drainQueuedServerOrderChanges",
414
+ value: function () {
415
+ var _drainQueuedServerOrderChanges = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
416
+ var changedOrders;
417
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
418
+ while (1) switch (_context.prev = _context.next) {
419
+ case 0:
420
+ if (!(!this.serverOrderChangeSyncEnabled || this.salesDetailLoadInFlightCount > 0 || this.serverOrderChangeHydrateInFlight || this.queuedServerOrderChanges.length === 0)) {
421
+ _context.next = 2;
422
+ break;
423
+ }
424
+ return _context.abrupt("return");
425
+ case 2:
426
+ changedOrders = this.queuedServerOrderChanges;
427
+ this.queuedServerOrderChanges = [];
428
+ _context.next = 6;
429
+ return this.syncCurrentSalesDetailFromServerOrderChange({
430
+ changedOrders: changedOrders
431
+ });
432
+ case 6:
433
+ case "end":
434
+ return _context.stop();
435
+ }
436
+ }, _callee, this);
437
+ }));
438
+ function drainQueuedServerOrderChanges() {
439
+ return _drainQueuedServerOrderChanges.apply(this, arguments);
440
+ }
441
+ return drainQueuedServerOrderChanges;
442
+ }()
285
443
  }, {
286
444
  key: "syncCurrentSalesDetailFromServerOrderChange",
287
445
  value: function () {
288
- var _syncCurrentSalesDetailFromServerOrderChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload) {
446
+ var _syncCurrentSalesDetailFromServerOrderChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payload) {
289
447
  var _this2 = this;
290
448
  var changedOrders, changedOrder;
291
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
292
- while (1) switch (_context2.prev = _context2.next) {
449
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
450
+ while (1) switch (_context3.prev = _context3.next) {
293
451
  case 0:
294
452
  changedOrders = Array.isArray(payload) ? payload : Array.isArray(payload === null || payload === void 0 ? void 0 : payload.changedOrders) ? payload.changedOrders : payload !== null && payload !== void 0 && payload.data && _typeof(payload.data) === 'object' ? [payload.data] : [];
295
- if (!(!this.serverOrderChangeSyncEnabled || this.salesDetailLoadInFlight || this.serverOrderChangeHydrateInFlight)) {
296
- _context2.next = 3;
453
+ if (this.serverOrderChangeSyncEnabled) {
454
+ _context3.next = 3;
297
455
  break;
298
456
  }
299
- return _context2.abrupt("return");
457
+ return _context3.abrupt("return");
300
458
  case 3:
459
+ if (!(this.salesDetailLoadInFlightCount > 0)) {
460
+ _context3.next = 6;
461
+ break;
462
+ }
463
+ changedOrders.forEach(function (order) {
464
+ return _this2.queueLatestServerOrderChange(order);
465
+ });
466
+ return _context3.abrupt("return");
467
+ case 6:
301
468
  changedOrder = changedOrders.find(function (order) {
302
469
  return _this2.isCurrentSalesOrderRecord(order);
303
470
  });
304
471
  if (changedOrder) {
305
- _context2.next = 6;
472
+ _context3.next = 9;
306
473
  break;
307
474
  }
308
- return _context2.abrupt("return");
309
- case 6:
475
+ return _context3.abrupt("return");
476
+ case 9:
477
+ if (!this.serverOrderChangeHydrateInFlight) {
478
+ _context3.next = 12;
479
+ break;
480
+ }
481
+ this.queueLatestServerOrderChange(changedOrder);
482
+ return _context3.abrupt("return");
483
+ case 12:
310
484
  if (this.store.order) {
311
- _context2.next = 8;
485
+ _context3.next = 14;
312
486
  break;
313
487
  }
314
- return _context2.abrupt("return");
315
- case 8:
316
- this.serverOrderChangeHydrateInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
488
+ return _context3.abrupt("return");
489
+ case 14:
490
+ this.serverOrderChangeHydrateInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
317
491
  var _getTempOrder, _ref2;
318
492
  var currentTempOrder, record, sales;
319
- return _regeneratorRuntime().wrap(function _callee$(_context) {
320
- while (1) switch (_context.prev = _context.next) {
493
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
494
+ while (1) switch (_context2.prev = _context2.next) {
321
495
  case 0:
322
496
  currentTempOrder = (_getTempOrder = (_ref2 = _this2.store.order).getTempOrder) === null || _getTempOrder === void 0 ? void 0 : _getTempOrder.call(_ref2);
323
- record = mergeSalesDetailRecordWithTempOrder(currentTempOrder, changedOrder);
324
- _context.next = 4;
497
+ record = mergeSalesDetailRecordWithTempOrder(currentTempOrder, changedOrder, 'authoritative-incoming');
498
+ _context2.next = 4;
325
499
  return _this2.store.order.hydrateTempOrderFromRecord(record, {
326
500
  recalcOnHydrate: false
327
501
  });
328
502
  case 4:
329
- sales = _context.sent;
503
+ sales = _context2.sent;
330
504
  _this2.currentSalesDetail = sales;
331
- _context.next = 8;
505
+ _context2.next = 8;
332
506
  return _this2.core.effects.emit("".concat(_this2.name, ":onSalesOrderLoaded"), {
333
507
  sales: sales
334
508
  });
335
509
  case 8:
336
510
  case "end":
337
- return _context.stop();
511
+ return _context2.stop();
338
512
  }
339
- }, _callee);
513
+ }, _callee2);
340
514
  }))();
341
- _context2.prev = 9;
342
- _context2.next = 12;
515
+ _context3.prev = 15;
516
+ _context3.next = 18;
343
517
  return this.serverOrderChangeHydrateInFlight;
344
- case 12:
345
- _context2.prev = 12;
518
+ case 18:
519
+ _context3.prev = 18;
346
520
  this.serverOrderChangeHydrateInFlight = null;
347
- return _context2.finish(12);
348
- case 15:
521
+ _context3.next = 22;
522
+ return this.drainQueuedServerOrderChanges();
523
+ case 22:
524
+ return _context3.finish(18);
525
+ case 23:
349
526
  case "end":
350
- return _context2.stop();
527
+ return _context3.stop();
351
528
  }
352
- }, _callee2, this, [[9,, 12, 15]]);
529
+ }, _callee3, this, [[15,, 18, 23]]);
353
530
  }));
354
531
  function syncCurrentSalesDetailFromServerOrderChange(_x) {
355
532
  return _syncCurrentSalesDetailFromServerOrderChange.apply(this, arguments);
@@ -366,13 +543,100 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
366
543
  var effects = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.effects;
367
544
  if (!effects || typeof effects.on !== 'function') return;
368
545
  this.serverOrderChangeUnsubscribe = effects.on(SERVER_ORDER_CHANGED_EVENT, function (payload) {
369
- void _this3.syncCurrentSalesDetailFromServerOrderChange(payload).catch(function (error) {
546
+ return _this3.syncCurrentSalesDetailFromServerOrderChange(payload).catch(function (error) {
370
547
  _this3.logError('sync sales detail from server order change failed', {
371
548
  error: error instanceof Error ? error.message : String(error)
372
549
  });
373
550
  });
374
551
  });
375
552
  }
553
+ }, {
554
+ key: "hydrateLatestLoadedSalesDetail",
555
+ value: function () {
556
+ var _hydrateLatestLoadedSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record, loadSequence) {
557
+ var _this4 = this;
558
+ var hydratedSales, skippedBeforeHydrate, hydrateTask, queuedTask;
559
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
560
+ while (1) switch (_context5.prev = _context5.next) {
561
+ case 0:
562
+ hydratedSales = null;
563
+ skippedBeforeHydrate = false;
564
+ hydrateTask = /*#__PURE__*/function () {
565
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
566
+ var sales;
567
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
568
+ while (1) switch (_context4.prev = _context4.next) {
569
+ case 0:
570
+ if (!(loadSequence !== _this4.salesDetailLoadSequence)) {
571
+ _context4.next = 3;
572
+ break;
573
+ }
574
+ skippedBeforeHydrate = true;
575
+ return _context4.abrupt("return");
576
+ case 3:
577
+ if (_this4.store.order) {
578
+ _context4.next = 5;
579
+ break;
580
+ }
581
+ throw new Error('order 模块未初始化');
582
+ case 5:
583
+ _context4.next = 7;
584
+ return _this4.store.order.hydrateTempOrderFromRecord(record, {
585
+ recalcOnHydrate: false
586
+ });
587
+ case 7:
588
+ sales = _context4.sent;
589
+ hydratedSales = sales;
590
+
591
+ // hydrate 期间可能又发起了更新请求;后续任务已串行排队,将负责最终状态。
592
+ if (!(loadSequence !== _this4.salesDetailLoadSequence)) {
593
+ _context4.next = 11;
594
+ break;
595
+ }
596
+ return _context4.abrupt("return");
597
+ case 11:
598
+ _this4.currentSalesDetail = sales;
599
+ _context4.next = 14;
600
+ return _this4.core.effects.emit("".concat(_this4.name, ":onSalesOrderLoaded"), {
601
+ sales: sales
602
+ });
603
+ case 14:
604
+ case "end":
605
+ return _context4.stop();
606
+ }
607
+ }, _callee4);
608
+ }));
609
+ return function hydrateTask() {
610
+ return _ref3.apply(this, arguments);
611
+ };
612
+ }();
613
+ queuedTask = this.salesDetailHydrateQueue.then(hydrateTask, hydrateTask);
614
+ this.salesDetailHydrateQueue = queuedTask.then(function () {
615
+ return undefined;
616
+ }, function () {
617
+ return undefined;
618
+ });
619
+ _context5.next = 7;
620
+ return queuedTask;
621
+ case 7:
622
+ if (!skippedBeforeHydrate) {
623
+ _context5.next = 9;
624
+ break;
625
+ }
626
+ return _context5.abrupt("return", record);
627
+ case 9:
628
+ return _context5.abrupt("return", hydratedSales || this.currentSalesDetail || record);
629
+ case 10:
630
+ case "end":
631
+ return _context5.stop();
632
+ }
633
+ }, _callee5, this);
634
+ }));
635
+ function hydrateLatestLoadedSalesDetail(_x2, _x3) {
636
+ return _hydrateLatestLoadedSalesDetail.apply(this, arguments);
637
+ }
638
+ return hydrateLatestLoadedSalesDetail;
639
+ }()
376
640
  }, {
377
641
  key: "hydrateOrderPaymentNames",
378
642
  value: function hydrateOrderPaymentNames(payments) {
@@ -437,10 +701,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
437
701
  });
438
702
  }
439
703
  quotation.setScheduleResolver(function (id) {
440
- var _scheduleModule$getSc, _getScheduleByIds, _ref3;
704
+ var _scheduleModule$getSc, _getScheduleByIds, _ref4;
441
705
  var scheduleId = String(id);
442
706
  if (scheduleById.has(scheduleId)) return scheduleById.get(scheduleId);
443
- var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref3 = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref3, [id])) || [];
707
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref4 = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref4, [id])) || [];
444
708
  if (schedules[0]) scheduleById.set(scheduleId, schedules[0]);
445
709
  return schedules[0];
446
710
  });
@@ -448,30 +712,30 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
448
712
  }, {
449
713
  key: "loadQuotationForPriceQuery",
450
714
  value: function () {
451
- var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
715
+ var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
452
716
  var _this$otherParams;
453
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
454
- while (1) switch (_context3.prev = _context3.next) {
717
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
718
+ while (1) switch (_context6.prev = _context6.next) {
455
719
  case 0:
456
720
  if (params.quotation) {
457
- _context3.next = 2;
721
+ _context6.next = 2;
458
722
  break;
459
723
  }
460
- return _context3.abrupt("return");
724
+ return _context6.abrupt("return");
461
725
  case 2:
462
726
  this.applyQuotationScheduleResolver(params.quotation);
463
- _context3.next = 5;
727
+ _context6.next = 5;
464
728
  return params.quotation.loadQuotations({
465
729
  channel: params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel),
466
730
  customer_id: params.customer_id
467
731
  });
468
732
  case 5:
469
733
  case "end":
470
- return _context3.stop();
734
+ return _context6.stop();
471
735
  }
472
- }, _callee3, this);
736
+ }, _callee6, this);
473
737
  }));
474
- function loadQuotationForPriceQuery(_x2) {
738
+ function loadQuotationForPriceQuery(_x4) {
475
739
  return _loadQuotationForPriceQuery.apply(this, arguments);
476
740
  }
477
741
  return loadQuotationForPriceQuery;
@@ -515,23 +779,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
515
779
  }, {
516
780
  key: "loadProductsForPriceQuery",
517
781
  value: function () {
518
- var _loadProductsForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
782
+ var _loadProductsForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
519
783
  var ids, productsById, _this$otherParams2, _response$data, response, list;
520
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
521
- while (1) switch (_context4.prev = _context4.next) {
784
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
785
+ while (1) switch (_context7.prev = _context7.next) {
522
786
  case 0:
523
787
  ids = Array.from(new Set(params.ids.filter(function (id) {
524
788
  return Number.isFinite(id);
525
789
  })));
526
790
  productsById = new Map();
527
791
  if (!(!ids.length || !this.request)) {
528
- _context4.next = 4;
792
+ _context7.next = 4;
529
793
  break;
530
794
  }
531
- return _context4.abrupt("return", productsById);
795
+ return _context7.abrupt("return", productsById);
532
796
  case 4:
533
- _context4.prev = 4;
534
- _context4.next = 7;
797
+ _context7.prev = 4;
798
+ _context7.next = 7;
535
799
  return this.request.post('/product/query', {
536
800
  ids: ids,
537
801
  open_quotation: 1,
@@ -548,35 +812,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
548
812
  customToast: function customToast() {}
549
813
  });
550
814
  case 7:
551
- response = _context4.sent;
815
+ response = _context7.sent;
552
816
  list = (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || (response === null || response === void 0 ? void 0 : response.list) || [];
553
817
  if (Array.isArray(list)) {
554
- _context4.next = 11;
818
+ _context7.next = 11;
555
819
  break;
556
820
  }
557
- return _context4.abrupt("return", productsById);
821
+ return _context7.abrupt("return", productsById);
558
822
  case 11:
559
823
  list.forEach(function (item) {
560
824
  var _item$id;
561
825
  var productId = Number((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id);
562
826
  if (Number.isFinite(productId)) productsById.set(productId, item);
563
827
  });
564
- return _context4.abrupt("return", productsById);
828
+ return _context7.abrupt("return", productsById);
565
829
  case 15:
566
- _context4.prev = 15;
567
- _context4.t0 = _context4["catch"](4);
830
+ _context7.prev = 15;
831
+ _context7.t0 = _context7["catch"](4);
568
832
  this.logWarning('loadProductsForPriceQuery: 商品批量重查失败,使用入参 fallback', {
569
833
  ids: ids,
570
- error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
834
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
571
835
  });
572
- return _context4.abrupt("return", productsById);
836
+ return _context7.abrupt("return", productsById);
573
837
  case 19:
574
838
  case "end":
575
- return _context4.stop();
839
+ return _context7.stop();
576
840
  }
577
- }, _callee4, this, [[4, 15]]);
841
+ }, _callee7, this, [[4, 15]]);
578
842
  }));
579
- function loadProductsForPriceQuery(_x3) {
843
+ function loadProductsForPriceQuery(_x5) {
580
844
  return _loadProductsForPriceQuery.apply(this, arguments);
581
845
  }
582
846
  return loadProductsForPriceQuery;
@@ -584,21 +848,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
584
848
  }, {
585
849
  key: "loadProductForPriceQuery",
586
850
  value: function () {
587
- var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params, customerId) {
851
+ var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params, customerId) {
588
852
  var product, productId, schedule, productsById;
589
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
590
- while (1) switch (_context5.prev = _context5.next) {
853
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
854
+ while (1) switch (_context8.prev = _context8.next) {
591
855
  case 0:
592
856
  product = params.product || {};
593
857
  productId = this.getPriceQueryProductId(product);
594
858
  if (!(productId === null || !this.request)) {
595
- _context5.next = 4;
859
+ _context8.next = 4;
596
860
  break;
597
861
  }
598
- return _context5.abrupt("return", null);
862
+ return _context8.abrupt("return", null);
599
863
  case 4:
600
864
  schedule = this.getPriceQuerySchedule(params);
601
- _context5.next = 7;
865
+ _context8.next = 7;
602
866
  return this.loadProductsForPriceQuery({
603
867
  ids: [productId],
604
868
  schedule: schedule,
@@ -606,15 +870,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
606
870
  channel: params.channel
607
871
  });
608
872
  case 7:
609
- productsById = _context5.sent;
610
- return _context5.abrupt("return", productsById.get(productId) || null);
873
+ productsById = _context8.sent;
874
+ return _context8.abrupt("return", productsById.get(productId) || null);
611
875
  case 9:
612
876
  case "end":
613
- return _context5.stop();
877
+ return _context8.stop();
614
878
  }
615
- }, _callee5, this);
879
+ }, _callee8, this);
616
880
  }));
617
- function loadProductForPriceQuery(_x4, _x5) {
881
+ function loadProductForPriceQuery(_x6, _x7) {
618
882
  return _loadProductForPriceQuery.apply(this, arguments);
619
883
  }
620
884
  return loadProductForPriceQuery;
@@ -627,10 +891,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
627
891
  return groups.flatMap(function (group) {
628
892
  var items = Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group === null || group === void 0 ? void 0 : group.bundleItem) ? group.bundleItem : [];
629
893
  return items.map(function (item) {
630
- var _item$group_id, _ref4, _item$bundle_group_id;
894
+ var _item$group_id, _ref5, _item$bundle_group_id;
631
895
  return _objectSpread(_objectSpread({}, item), {}, {
632
896
  group_id: (_item$group_id = item === null || item === void 0 ? void 0 : item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group === null || group === void 0 ? void 0 : group.id,
633
- bundle_group_id: (_ref4 = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref4 !== void 0 ? _ref4 : group === null || group === void 0 ? void 0 : group.id
897
+ bundle_group_id: (_ref5 = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref5 !== void 0 ? _ref5 : group === null || group === void 0 ? void 0 : group.id
634
898
  });
635
899
  });
636
900
  });
@@ -661,21 +925,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
661
925
  }, {
662
926
  key: "getAuthoritativeBundleUnitPrice",
663
927
  value: function getAuthoritativeBundleUnitPrice(bundle) {
664
- var _ref5, _ref6, _ref7, _bundle$price;
665
- return (_ref5 = (_ref6 = (_ref7 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.custom_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.product_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.base_price;
928
+ var _ref6, _ref7, _ref8, _bundle$price;
929
+ return (_ref6 = (_ref7 = (_ref8 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref8 !== void 0 ? _ref8 : bundle.custom_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.base_price;
666
930
  }
667
931
  }, {
668
932
  key: "mergeProductForPriceQuery",
669
933
  value: function mergeProductForPriceQuery(product, authoritativeProduct) {
670
- var _this4 = this,
934
+ var _this5 = this,
671
935
  _product$id,
672
- _ref8,
673
- _product$product_id2,
674
936
  _ref9,
675
- _product$product_vari,
937
+ _product$product_id2,
676
938
  _ref10,
677
- _product$num,
939
+ _product$product_vari,
678
940
  _ref11,
941
+ _product$num,
942
+ _ref12,
679
943
  _product$quantity,
680
944
  _product$metadata4;
681
945
  if (!authoritativeProduct) return product;
@@ -683,8 +947,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
683
947
  var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
684
948
  var productBundle = selectedBundles.map(function (bundle) {
685
949
  var _authoritativeBundle$, _authoritativeBundle$2;
686
- var authoritativeBundle = _this4.findAuthoritativeBundleItem(bundle, authoritativeBundles);
687
- var unitPrice = authoritativeBundle ? _this4.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
950
+ var authoritativeBundle = _this5.findAuthoritativeBundleItem(bundle, authoritativeBundles);
951
+ var unitPrice = authoritativeBundle ? _this5.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
688
952
  if (unitPrice === undefined || unitPrice === null || unitPrice === '') return bundle;
689
953
  return _objectSpread(_objectSpread({}, bundle), {}, {
690
954
  price: unitPrice,
@@ -695,10 +959,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
695
959
  });
696
960
  return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
697
961
  id: (_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : authoritativeProduct.id,
698
- product_id: (_ref8 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref8 !== void 0 ? _ref8 : authoritativeProduct.id,
699
- product_variant_id: (_ref9 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref9 !== void 0 ? _ref9 : 0,
700
- num: (_ref10 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref10 !== void 0 ? _ref10 : authoritativeProduct.num,
701
- quantity: (_ref11 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref11 !== void 0 ? _ref11 : authoritativeProduct.quantity,
962
+ product_id: (_ref9 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref9 !== void 0 ? _ref9 : authoritativeProduct.id,
963
+ product_variant_id: (_ref10 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
964
+ num: (_ref11 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref11 !== void 0 ? _ref11 : authoritativeProduct.num,
965
+ quantity: (_ref12 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref12 !== void 0 ? _ref12 : authoritativeProduct.quantity,
702
966
  product_sku: function () {
703
967
  var authoritativeSku = ensureProductSku(authoritativeProduct);
704
968
  var productSku = ensureProductSku(product);
@@ -772,61 +1036,61 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
772
1036
  }, {
773
1037
  key: "syncOtherParamsToSubModules",
774
1038
  value: (function () {
775
- var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(changedParams) {
776
- var _this5 = this;
777
- var _ref12,
778
- _ref12$cover,
1039
+ var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(changedParams) {
1040
+ var _this6 = this;
1041
+ var _ref13,
1042
+ _ref13$cover,
779
1043
  cover,
780
1044
  nextSubModuleOtherParams,
781
- _args7 = arguments;
782
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
783
- while (1) switch (_context7.prev = _context7.next) {
1045
+ _args10 = arguments;
1046
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1047
+ while (1) switch (_context10.prev = _context10.next) {
784
1048
  case 0:
785
- _ref12 = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {}, _ref12$cover = _ref12.cover, cover = _ref12$cover === void 0 ? false : _ref12$cover;
1049
+ _ref13 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref13$cover = _ref13.cover, cover = _ref13$cover === void 0 ? false : _ref13$cover;
786
1050
  nextSubModuleOtherParams = this.buildSubModuleOtherParams();
787
- _context7.next = 4;
1051
+ _context10.next = 4;
788
1052
  return Promise.all(Object.entries(this.store).map( /*#__PURE__*/function () {
789
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref13) {
790
- var _ref15, moduleName, subModule, targetModule;
791
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
792
- while (1) switch (_context6.prev = _context6.next) {
1053
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref14) {
1054
+ var _ref16, moduleName, subModule, targetModule;
1055
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1056
+ while (1) switch (_context9.prev = _context9.next) {
793
1057
  case 0:
794
- _ref15 = _slicedToArray(_ref13, 2), moduleName = _ref15[0], subModule = _ref15[1];
795
- if (!_this5.reusedSharedSubModuleNames.has(moduleName)) {
796
- _context6.next = 3;
1058
+ _ref16 = _slicedToArray(_ref14, 2), moduleName = _ref16[0], subModule = _ref16[1];
1059
+ if (!_this6.reusedSharedSubModuleNames.has(moduleName)) {
1060
+ _context9.next = 3;
797
1061
  break;
798
1062
  }
799
- return _context6.abrupt("return");
1063
+ return _context9.abrupt("return");
800
1064
  case 3:
801
1065
  targetModule = subModule;
802
1066
  if (!(!targetModule || typeof targetModule.updateOtherParams !== 'function')) {
803
- _context6.next = 6;
1067
+ _context9.next = 6;
804
1068
  break;
805
1069
  }
806
- return _context6.abrupt("return");
1070
+ return _context9.abrupt("return");
807
1071
  case 6:
808
- _context6.next = 8;
1072
+ _context9.next = 8;
809
1073
  return targetModule.updateOtherParams(nextSubModuleOtherParams, {
810
1074
  changedParams: changedParams,
811
1075
  cover: cover
812
1076
  });
813
1077
  case 8:
814
1078
  case "end":
815
- return _context6.stop();
1079
+ return _context9.stop();
816
1080
  }
817
- }, _callee6);
1081
+ }, _callee9);
818
1082
  }));
819
- return function (_x7) {
820
- return _ref14.apply(this, arguments);
1083
+ return function (_x9) {
1084
+ return _ref15.apply(this, arguments);
821
1085
  };
822
1086
  }()));
823
1087
  case 4:
824
1088
  case "end":
825
- return _context7.stop();
1089
+ return _context10.stop();
826
1090
  }
827
- }, _callee7, this);
1091
+ }, _callee10, this);
828
1092
  }));
829
- function syncOtherParamsToSubModules(_x6) {
1093
+ function syncOtherParamsToSubModules(_x8) {
830
1094
  return _syncOtherParamsToSubModules.apply(this, arguments);
831
1095
  }
832
1096
  return syncOtherParamsToSubModules;
@@ -859,6 +1123,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
859
1123
  var coreData = app === null || app === void 0 || (_app$models = app.models) === null || _app$models === void 0 || (_app$models$getStore = _app$models.getStore) === null || _app$models$getStore === void 0 || (_app$models$getStore$ = (_app$models$getStore$2 = _app$models$getStore.call(_app$models)).getDataByModel) === null || _app$models$getStore$ === void 0 ? void 0 : _app$models$getStore$.call(_app$models$getStore$2, 'core', 'core');
860
1124
  return coreData === null || coreData === void 0 ? void 0 : coreData[key];
861
1125
  }
1126
+ }, {
1127
+ key: "getPaymentNumberDevicePrefixSync",
1128
+ value: function getPaymentNumberDevicePrefixSync() {
1129
+ var _this7 = this;
1130
+ if (!this.appPlugin) return 'LOCAL';
1131
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1132
+ return _this7.getAppData(key);
1133
+ });
1134
+ }
1135
+ }, {
1136
+ key: "getPaymentNumberDevicePrefixAsync",
1137
+ value: function getPaymentNumberDevicePrefixAsync() {
1138
+ var _this8 = this;
1139
+ if (!this.appPlugin) return Promise.resolve('LOCAL');
1140
+ return resolvePaymentNumberDevicePrefix(function (key) {
1141
+ return _this8.getAppData(key);
1142
+ });
1143
+ }
862
1144
  }, {
863
1145
  key: "syncAppDataToTempOrder",
864
1146
  value: function syncAppDataToTempOrder(tempOrder) {
@@ -900,19 +1182,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
900
1182
  }, {
901
1183
  key: "initialize",
902
1184
  value: function () {
903
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(core) {
1185
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(core) {
904
1186
  var _this$otherParams4,
905
- _this6 = this,
1187
+ _this9 = this,
906
1188
  _this$otherParams5;
907
1189
  var options,
908
1190
  app,
909
1191
  targetCacheData,
910
1192
  moduleNames,
911
- _args8 = arguments;
912
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
913
- while (1) switch (_context8.prev = _context8.next) {
1193
+ _args11 = arguments;
1194
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1195
+ while (1) switch (_context11.prev = _context11.next) {
914
1196
  case 0:
915
- options = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1197
+ options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
916
1198
  this.core = core;
917
1199
  this.initializeOptions = options || {};
918
1200
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
@@ -925,7 +1207,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
925
1207
  // 获取 logger 实例
926
1208
  this.appPlugin = core.getPlugin('app');
927
1209
  if (this.appPlugin) {
928
- _context8.next = 11;
1210
+ _context11.next = 11;
929
1211
  break;
930
1212
  }
931
1213
  throw new Error('Checkout 解决方案需要 app 插件支持');
@@ -935,48 +1217,48 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
935
1217
  targetCacheData = this.readSessionCacheData();
936
1218
  moduleNames = this.getRegisteredModuleNames();
937
1219
  moduleNames.forEach(function (step) {
938
- var reusedModule = _this6.getReusableSharedSubModule(step);
1220
+ var reusedModule = _this9.getReusableSharedSubModule(step);
939
1221
  if (reusedModule) {
940
- _this6.store[step] = reusedModule;
941
- _this6.reusedSharedSubModuleNames.add(step);
1222
+ _this9.store[step] = reusedModule;
1223
+ _this9.reusedSharedSubModuleNames.add(step);
942
1224
  return;
943
1225
  }
944
- var targetModule = _this6.createSubModule(step);
1226
+ var targetModule = _this9.createSubModule(step);
945
1227
  if (!targetModule) {
946
1228
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
947
1229
  }
948
- var hooks = _this6.getSubModuleHooks(step);
949
- _this6.store[step] = targetModule;
950
- _this6.core.registerModule(targetModule, _objectSpread(_objectSpread({
1230
+ var hooks = _this9.getSubModuleHooks(step);
1231
+ _this9.store[step] = targetModule;
1232
+ _this9.core.registerModule(targetModule, _objectSpread(_objectSpread({
951
1233
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
952
1234
  }, hooks ? {
953
1235
  hooks: hooks
954
1236
  } : {}), {}, {
955
- otherParams: _this6.buildSubModuleOtherParams()
1237
+ otherParams: _this9.buildSubModuleOtherParams()
956
1238
  }));
957
1239
  });
958
1240
  if (!(this.store.schedule && !this.isScheduleListLoaded(this.store.schedule))) {
959
- _context8.next = 19;
1241
+ _context11.next = 19;
960
1242
  break;
961
1243
  }
962
- _context8.next = 19;
1244
+ _context11.next = 19;
963
1245
  return this.store.schedule.loadAllSchedule();
964
1246
  case 19:
965
1247
  if (this.store.order && typeof ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.enableTempOrderPersist) === 'boolean') {
966
1248
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
967
1249
  }
968
- _context8.next = 22;
1250
+ _context11.next = 22;
969
1251
  return this.getPaymentMethodsAsync();
970
1252
  case 22:
971
1253
  this.registerServerOrderChangeSync();
972
1254
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
973
1255
  case 24:
974
1256
  case "end":
975
- return _context8.stop();
1257
+ return _context11.stop();
976
1258
  }
977
- }, _callee8, this);
1259
+ }, _callee11, this);
978
1260
  }));
979
- function initialize(_x8) {
1261
+ function initialize(_x10) {
980
1262
  return _initialize.apply(this, arguments);
981
1263
  }
982
1264
  return initialize;
@@ -984,17 +1266,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
984
1266
  }, {
985
1267
  key: "destroy",
986
1268
  value: function () {
987
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1269
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
988
1270
  var _this$serverOrderChan2,
989
- _this7 = this;
990
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
991
- while (1) switch (_context9.prev = _context9.next) {
1271
+ _this10 = this;
1272
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1273
+ while (1) switch (_context12.prev = _context12.next) {
992
1274
  case 0:
993
1275
  (_this$serverOrderChan2 = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan2 === void 0 || _this$serverOrderChan2.call(this);
994
1276
  this.serverOrderChangeUnsubscribe = null;
995
1277
  Object.keys(this.store).forEach(function (key) {
996
- if (_this7.reusedSharedSubModuleNames.has(key)) return;
997
- var sub = _this7.store[key];
1278
+ if (_this10.reusedSharedSubModuleNames.has(key)) return;
1279
+ var sub = _this10.store[key];
998
1280
  if (sub && typeof sub.destroy === 'function') {
999
1281
  try {
1000
1282
  sub.destroy();
@@ -1004,15 +1286,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1004
1286
  }
1005
1287
  });
1006
1288
  this.currentSalesDetail = null;
1007
- _context9.next = 6;
1289
+ this.queuedServerOrderChanges = [];
1290
+ this.salesDetailLoadSequence += 1;
1291
+ _context12.next = 8;
1008
1292
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
1009
- case 6:
1293
+ case 8:
1010
1294
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
1011
- case 7:
1295
+ case 9:
1012
1296
  case "end":
1013
- return _context9.stop();
1297
+ return _context12.stop();
1014
1298
  }
1015
- }, _callee9, this);
1299
+ }, _callee12, this);
1016
1300
  }));
1017
1301
  function destroy() {
1018
1302
  return _destroy.apply(this, arguments);
@@ -1029,82 +1313,91 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1029
1313
  }, {
1030
1314
  key: "loadSalesDetail",
1031
1315
  value: (function () {
1032
- var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderIdOrParams) {
1033
- var _ref16, _ref17, _ref18, _ref19, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record, sales;
1034
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1035
- while (1) switch (_context10.prev = _context10.next) {
1316
+ var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderIdOrParams) {
1317
+ var loadSequence, _ref17, _ref18, _ref19, _ref20, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record;
1318
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1319
+ while (1) switch (_context13.prev = _context13.next) {
1036
1320
  case 0:
1037
1321
  if (this.store.order) {
1038
- _context10.next = 2;
1322
+ _context13.next = 2;
1039
1323
  break;
1040
1324
  }
1041
1325
  throw new Error('order 模块未初始化');
1042
1326
  case 2:
1043
- this.salesDetailLoadInFlight = true;
1044
- _context10.prev = 3;
1327
+ loadSequence = ++this.salesDetailLoadSequence;
1328
+ this.salesDetailLoadInFlightCount += 1;
1329
+ _context13.prev = 4;
1045
1330
  params = _typeof(orderIdOrParams) === 'object' ? orderIdOrParams : {
1046
1331
  orderId: orderIdOrParams
1047
1332
  };
1048
1333
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
1049
1334
  preloadedSalesDetail = params.preloadedSalesDetail;
1050
- lookup = (_ref16 = (_ref17 = (_ref18 = (_ref19 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref19 !== void 0 ? _ref19 : params.orderNumber) !== null && _ref18 !== void 0 ? _ref18 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref17 !== void 0 ? _ref17 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref16 !== void 0 ? _ref16 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1335
+ lookup = (_ref17 = (_ref18 = (_ref19 = (_ref20 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref20 !== void 0 ? _ref20 : params.orderNumber) !== null && _ref19 !== void 0 ? _ref19 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref18 !== void 0 ? _ref18 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref17 !== void 0 ? _ref17 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1051
1336
  if (!(!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === ''))) {
1052
- _context10.next = 10;
1337
+ _context13.next = 11;
1053
1338
  break;
1054
1339
  }
1055
1340
  throw new Error('加载销售详情需要 orderId、externalSaleNumber 或 orderNumber');
1056
- case 10:
1341
+ case 11:
1057
1342
  if (!(preloadedSalesDetail !== null && preloadedSalesDetail !== void 0)) {
1058
- _context10.next = 14;
1343
+ _context13.next = 15;
1059
1344
  break;
1060
1345
  }
1061
- _context10.t0 = preloadedSalesDetail;
1062
- _context10.next = 17;
1346
+ _context13.t0 = preloadedSalesDetail;
1347
+ _context13.next = 18;
1063
1348
  break;
1064
- case 14:
1065
- _context10.next = 16;
1349
+ case 15:
1350
+ _context13.next = 17;
1066
1351
  return this.store.order.getSalesOrderByLookup({
1067
1352
  lookup: lookup,
1068
1353
  forceRemote: params.forceRemote
1069
1354
  });
1070
- case 16:
1071
- _context10.t0 = _context10.sent;
1072
1355
  case 17:
1073
- loadedRecord = _context10.t0;
1356
+ _context13.t0 = _context13.sent;
1357
+ case 18:
1358
+ loadedRecord = _context13.t0;
1074
1359
  if (!(!preloadedSalesDetail && (!loadedRecord || loadedRecord.code !== 200))) {
1075
- _context10.next = 21;
1360
+ _context13.next = 22;
1076
1361
  break;
1077
1362
  }
1078
1363
  message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
1079
1364
  throw new Error(message);
1080
- case 21:
1365
+ case 22:
1081
1366
  remoteRecord = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data;
1082
1367
  currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
1083
- record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord) : remoteRecord;
1084
- _context10.next = 26;
1085
- return this.store.order.hydrateTempOrderFromRecord(record, {
1086
- recalcOnHydrate: false
1087
- });
1088
- case 26:
1089
- sales = _context10.sent;
1090
- this.currentSalesDetail = sales;
1091
- _context10.next = 30;
1092
- return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
1093
- sales: sales
1094
- });
1095
- case 30:
1096
- return _context10.abrupt("return", sales);
1097
- case 31:
1098
- _context10.prev = 31;
1099
- this.salesDetailLoadInFlight = false;
1100
- return _context10.finish(31);
1368
+ record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1369
+ _context13.next = 27;
1370
+ return this.hydrateLatestLoadedSalesDetail(record, loadSequence);
1371
+ case 27:
1372
+ return _context13.abrupt("return", _context13.sent);
1373
+ case 28:
1374
+ _context13.prev = 28;
1375
+ this.salesDetailLoadInFlightCount = Math.max(0, this.salesDetailLoadInFlightCount - 1);
1376
+ if (!(this.salesDetailLoadInFlightCount === 0)) {
1377
+ _context13.next = 39;
1378
+ break;
1379
+ }
1380
+ _context13.prev = 31;
1381
+ _context13.next = 34;
1382
+ return this.drainQueuedServerOrderChanges();
1101
1383
  case 34:
1384
+ _context13.next = 39;
1385
+ break;
1386
+ case 36:
1387
+ _context13.prev = 36;
1388
+ _context13.t1 = _context13["catch"](31);
1389
+ this.logError('drain queued server order changes failed', {
1390
+ error: _context13.t1 instanceof Error ? _context13.t1.message : String(_context13.t1)
1391
+ });
1392
+ case 39:
1393
+ return _context13.finish(28);
1394
+ case 40:
1102
1395
  case "end":
1103
- return _context10.stop();
1396
+ return _context13.stop();
1104
1397
  }
1105
- }, _callee10, this, [[3,, 31, 34]]);
1398
+ }, _callee13, this, [[4,, 28, 40], [31, 36]]);
1106
1399
  }));
1107
- function loadSalesDetail(_x9) {
1400
+ function loadSalesDetail(_x11) {
1108
1401
  return _loadSalesDetail.apply(this, arguments);
1109
1402
  }
1110
1403
  return loadSalesDetail;
@@ -1184,34 +1477,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1184
1477
  }, {
1185
1478
  key: "replaceTempOrder",
1186
1479
  value: function () {
1187
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(tempOrder) {
1480
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(tempOrder) {
1188
1481
  var nextTempOrder;
1189
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1190
- while (1) switch (_context11.prev = _context11.next) {
1482
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1483
+ while (1) switch (_context14.prev = _context14.next) {
1191
1484
  case 0:
1192
1485
  if (this.store.order) {
1193
- _context11.next = 2;
1486
+ _context14.next = 2;
1194
1487
  break;
1195
1488
  }
1196
1489
  throw new Error('order 模块未初始化');
1197
1490
  case 2:
1198
- _context11.next = 4;
1491
+ _context14.next = 4;
1199
1492
  return this.store.order.replaceTempOrder(tempOrder);
1200
1493
  case 4:
1201
- nextTempOrder = _context11.sent;
1202
- _context11.next = 7;
1494
+ nextTempOrder = _context14.sent;
1495
+ _context14.next = 7;
1203
1496
  return this.effectsEmit('onTempOrderReplaced', {
1204
1497
  tempOrder: nextTempOrder
1205
1498
  });
1206
1499
  case 7:
1207
- return _context11.abrupt("return", nextTempOrder);
1500
+ return _context14.abrupt("return", nextTempOrder);
1208
1501
  case 8:
1209
1502
  case "end":
1210
- return _context11.stop();
1503
+ return _context14.stop();
1211
1504
  }
1212
- }, _callee11, this);
1505
+ }, _callee14, this);
1213
1506
  }));
1214
- function replaceTempOrder(_x10) {
1507
+ function replaceTempOrder(_x12) {
1215
1508
  return _replaceTempOrder.apply(this, arguments);
1216
1509
  }
1217
1510
  return replaceTempOrder;
@@ -1309,40 +1602,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1309
1602
  }, {
1310
1603
  key: "addNewOrder",
1311
1604
  value: function () {
1312
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1605
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1313
1606
  var tempOrder;
1314
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1315
- while (1) switch (_context12.prev = _context12.next) {
1607
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1608
+ while (1) switch (_context15.prev = _context15.next) {
1316
1609
  case 0:
1317
- _context12.prev = 0;
1610
+ _context15.prev = 0;
1318
1611
  if (this.store.order) {
1319
- _context12.next = 3;
1612
+ _context15.next = 3;
1320
1613
  break;
1321
1614
  }
1322
1615
  throw new Error('order 模块未初始化');
1323
1616
  case 3:
1324
- _context12.next = 5;
1617
+ _context15.next = 5;
1325
1618
  return this.store.order.addNewOrder();
1326
1619
  case 5:
1327
- tempOrder = _context12.sent;
1620
+ tempOrder = _context15.sent;
1328
1621
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1329
- _context12.next = 10;
1622
+ _context15.next = 10;
1330
1623
  break;
1331
1624
  }
1332
1625
  this.store.order.persistTempOrder();
1333
- _context12.next = 10;
1626
+ _context15.next = 10;
1334
1627
  return this.store.order.saveDraft();
1335
1628
  case 10:
1336
- return _context12.abrupt("return", tempOrder);
1629
+ return _context15.abrupt("return", tempOrder);
1337
1630
  case 13:
1338
- _context12.prev = 13;
1339
- _context12.t0 = _context12["catch"](0);
1340
- throw _context12.t0;
1631
+ _context15.prev = 13;
1632
+ _context15.t0 = _context15["catch"](0);
1633
+ throw _context15.t0;
1341
1634
  case 16:
1342
1635
  case "end":
1343
- return _context12.stop();
1636
+ return _context15.stop();
1344
1637
  }
1345
- }, _callee12, this, [[0, 13]]);
1638
+ }, _callee15, this, [[0, 13]]);
1346
1639
  }));
1347
1640
  function addNewOrder() {
1348
1641
  return _addNewOrder.apply(this, arguments);
@@ -1352,22 +1645,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1352
1645
  }, {
1353
1646
  key: "saveDraft",
1354
1647
  value: function () {
1355
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1356
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1357
- while (1) switch (_context13.prev = _context13.next) {
1648
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1649
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1650
+ while (1) switch (_context16.prev = _context16.next) {
1358
1651
  case 0:
1359
1652
  if (this.store.order) {
1360
- _context13.next = 2;
1653
+ _context16.next = 2;
1361
1654
  break;
1362
1655
  }
1363
1656
  throw new Error('order 模块未初始化');
1364
1657
  case 2:
1365
- return _context13.abrupt("return", this.store.order.saveDraft());
1658
+ return _context16.abrupt("return", this.store.order.saveDraft());
1366
1659
  case 3:
1367
1660
  case "end":
1368
- return _context13.stop();
1661
+ return _context16.stop();
1369
1662
  }
1370
- }, _callee13, this);
1663
+ }, _callee16, this);
1371
1664
  }));
1372
1665
  function saveDraft() {
1373
1666
  return _saveDraft.apply(this, arguments);
@@ -1378,14 +1671,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1378
1671
  }, {
1379
1672
  key: "restoreOrder",
1380
1673
  value: function () {
1381
- var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1674
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1382
1675
  var tempOrder;
1383
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1384
- while (1) switch (_context14.prev = _context14.next) {
1676
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1677
+ while (1) switch (_context17.prev = _context17.next) {
1385
1678
  case 0:
1386
- _context14.prev = 0;
1679
+ _context17.prev = 0;
1387
1680
  if (this.store.order) {
1388
- _context14.next = 3;
1681
+ _context17.next = 3;
1389
1682
  break;
1390
1683
  }
1391
1684
  throw new Error('scanOrder 解决方案需要 order 模块支持');
@@ -1395,29 +1688,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1395
1688
  this.currentSalesDetail = null;
1396
1689
  this.discountConfigCacheKey = null;
1397
1690
  this.hasManualDiscountSelection = false;
1398
- _context14.next = 9;
1691
+ _context17.next = 9;
1399
1692
  return this.effectsEmit('onTempOrderReplaced', {
1400
1693
  tempOrder: tempOrder
1401
1694
  });
1402
1695
  case 9:
1403
1696
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1404
- _context14.next = 13;
1697
+ _context17.next = 13;
1405
1698
  break;
1406
1699
  }
1407
1700
  this.store.order.persistTempOrder();
1408
- _context14.next = 13;
1701
+ _context17.next = 13;
1409
1702
  return this.store.order.saveDraft();
1410
1703
  case 13:
1411
- return _context14.abrupt("return", tempOrder);
1704
+ return _context17.abrupt("return", tempOrder);
1412
1705
  case 16:
1413
- _context14.prev = 16;
1414
- _context14.t0 = _context14["catch"](0);
1415
- throw _context14.t0;
1706
+ _context17.prev = 16;
1707
+ _context17.t0 = _context17["catch"](0);
1708
+ throw _context17.t0;
1416
1709
  case 19:
1417
1710
  case "end":
1418
- return _context14.stop();
1711
+ return _context17.stop();
1419
1712
  }
1420
- }, _callee14, this, [[0, 16]]);
1713
+ }, _callee17, this, [[0, 16]]);
1421
1714
  }));
1422
1715
  function restoreOrder() {
1423
1716
  return _restoreOrder.apply(this, arguments);
@@ -1431,22 +1724,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1431
1724
  }, {
1432
1725
  key: "clearOrderCartLines",
1433
1726
  value: (function () {
1434
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1727
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1435
1728
  var tempOrder;
1436
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1437
- while (1) switch (_context15.prev = _context15.next) {
1729
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1730
+ while (1) switch (_context18.prev = _context18.next) {
1438
1731
  case 0:
1439
- _context15.prev = 0;
1732
+ _context18.prev = 0;
1440
1733
  if (this.store.order) {
1441
- _context15.next = 3;
1734
+ _context18.next = 3;
1442
1735
  break;
1443
1736
  }
1444
1737
  throw new Error('order 模块未初始化');
1445
1738
  case 3:
1446
- _context15.next = 5;
1739
+ _context18.next = 5;
1447
1740
  return this.store.order.clearOrderCartLines();
1448
1741
  case 5:
1449
- tempOrder = _context15.sent;
1742
+ tempOrder = _context18.sent;
1450
1743
  if (this.currentSalesDetail) {
1451
1744
  this.currentSalesDetail = _objectSpread(_objectSpread({}, this.currentSalesDetail), {}, {
1452
1745
  products: [],
@@ -1456,29 +1749,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1456
1749
  discount_list: []
1457
1750
  });
1458
1751
  }
1459
- _context15.next = 9;
1752
+ _context18.next = 9;
1460
1753
  return this.effectsEmit('onTempOrderReplaced', {
1461
1754
  tempOrder: tempOrder
1462
1755
  });
1463
1756
  case 9:
1464
1757
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1465
- _context15.next = 13;
1758
+ _context18.next = 13;
1466
1759
  break;
1467
1760
  }
1468
1761
  this.store.order.persistTempOrder();
1469
- _context15.next = 13;
1762
+ _context18.next = 13;
1470
1763
  return this.store.order.saveDraft();
1471
1764
  case 13:
1472
- return _context15.abrupt("return", tempOrder);
1765
+ return _context18.abrupt("return", tempOrder);
1473
1766
  case 16:
1474
- _context15.prev = 16;
1475
- _context15.t0 = _context15["catch"](0);
1476
- throw _context15.t0;
1767
+ _context18.prev = 16;
1768
+ _context18.t0 = _context18["catch"](0);
1769
+ throw _context18.t0;
1477
1770
  case 19:
1478
1771
  case "end":
1479
- return _context15.stop();
1772
+ return _context18.stop();
1480
1773
  }
1481
- }, _callee15, this, [[0, 16]]);
1774
+ }, _callee18, this, [[0, 16]]);
1482
1775
  }));
1483
1776
  function clearOrderCartLines() {
1484
1777
  return _clearOrderCartLines.apply(this, arguments);
@@ -1495,32 +1788,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1495
1788
  }, {
1496
1789
  key: "getSummary",
1497
1790
  value: function () {
1498
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1791
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1499
1792
  var summary;
1500
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1501
- while (1) switch (_context16.prev = _context16.next) {
1793
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1794
+ while (1) switch (_context19.prev = _context19.next) {
1502
1795
  case 0:
1503
- _context16.prev = 0;
1796
+ _context19.prev = 0;
1504
1797
  if (this.store.order) {
1505
- _context16.next = 3;
1798
+ _context19.next = 3;
1506
1799
  break;
1507
1800
  }
1508
1801
  throw new Error('order 模块未初始化');
1509
1802
  case 3:
1510
- _context16.next = 5;
1803
+ _context19.next = 5;
1511
1804
  return this.store.order.getOrderSummary();
1512
1805
  case 5:
1513
- summary = _context16.sent;
1514
- return _context16.abrupt("return", summary);
1806
+ summary = _context19.sent;
1807
+ return _context19.abrupt("return", summary);
1515
1808
  case 9:
1516
- _context16.prev = 9;
1517
- _context16.t0 = _context16["catch"](0);
1518
- throw _context16.t0;
1809
+ _context19.prev = 9;
1810
+ _context19.t0 = _context19["catch"](0);
1811
+ throw _context19.t0;
1519
1812
  case 12:
1520
1813
  case "end":
1521
- return _context16.stop();
1814
+ return _context19.stop();
1522
1815
  }
1523
- }, _callee16, this, [[0, 9]]);
1816
+ }, _callee19, this, [[0, 9]]);
1524
1817
  }));
1525
1818
  function getSummary() {
1526
1819
  return _getSummary.apply(this, arguments);
@@ -1530,10 +1823,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1530
1823
  }, {
1531
1824
  key: "getHistoricalProductDiscountList",
1532
1825
  value: function getHistoricalProductDiscountList(products) {
1533
- var _this8 = this;
1826
+ var _this11 = this;
1534
1827
  var historyDiscountList = [];
1535
1828
  products.forEach(function (item) {
1536
- if (!_this8.isPersistedOrderProduct(item)) return;
1829
+ if (!_this11.isPersistedOrderProduct(item)) return;
1537
1830
  (item.discount_list || []).forEach(function (discount) {
1538
1831
  var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1539
1832
  var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
@@ -1593,11 +1886,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1593
1886
  }, {
1594
1887
  key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1595
1888
  value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1596
- var _this9 = this;
1889
+ var _this12 = this;
1597
1890
  if (params.discountAction !== 'edit') return false;
1598
1891
  if (!params.products.length) return false;
1599
1892
  var hasDraftProduct = params.products.some(function (product) {
1600
- return !_this9.isPersistedOrderProduct(product);
1893
+ return !_this12.isPersistedOrderProduct(product);
1601
1894
  });
1602
1895
  if (hasDraftProduct) return false;
1603
1896
  var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
@@ -1637,14 +1930,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1637
1930
  }, {
1638
1931
  key: "loadDiscountConfig",
1639
1932
  value: function () {
1640
- var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1933
+ var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1641
1934
  var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getOr, _discountModule$getDi2;
1642
- var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _orderStore$summary, orderTotalAmount, result, _iterator, _step, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1643
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1644
- while (1) switch (_context17.prev = _context17.next) {
1935
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _orderStore$summary, orderTotalAmount, result, _iterator2, _step2, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1936
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1937
+ while (1) switch (_context20.prev = _context20.next) {
1645
1938
  case 0:
1646
1939
  if (this.store.order) {
1647
- _context17.next = 2;
1940
+ _context20.next = 2;
1648
1941
  break;
1649
1942
  }
1650
1943
  throw new Error('order 模块未初始化');
@@ -1664,18 +1957,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1664
1957
  discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
1665
1958
  preparedDiscountList = [];
1666
1959
  if (!(customerId && customerId !== 1)) {
1667
- _context17.next = 25;
1960
+ _context20.next = 25;
1668
1961
  break;
1669
1962
  }
1670
1963
  if (!(this.discountConfigCacheKey === discountConfigCacheKey)) {
1671
- _context17.next = 19;
1964
+ _context20.next = 19;
1672
1965
  break;
1673
1966
  }
1674
1967
  preparedDiscountList = originalDiscountList;
1675
- _context17.next = 25;
1968
+ _context20.next = 25;
1676
1969
  break;
1677
1970
  case 19:
1678
- _context17.next = 21;
1971
+ _context20.next = 21;
1679
1972
  return this.store.order.loadDiscountConfig({
1680
1973
  customerId: customerId,
1681
1974
  action: discountAction,
@@ -1683,23 +1976,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1683
1976
  apply: false
1684
1977
  });
1685
1978
  case 21:
1686
- preparedDiscountList = _context17.sent;
1979
+ preparedDiscountList = _context20.sent;
1687
1980
  this.discountConfigCacheKey = discountConfigCacheKey;
1688
- _context17.next = 25;
1981
+ _context20.next = 25;
1689
1982
  return discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, preparedDiscountList);
1690
1983
  case 25:
1691
1984
  if (!(hasManualDiscountSelection && currentDiscountList.length)) {
1692
- _context17.next = 27;
1985
+ _context20.next = 27;
1693
1986
  break;
1694
1987
  }
1695
- return _context17.abrupt("return", {
1988
+ return _context20.abrupt("return", {
1696
1989
  productList: tempOrder.products || [],
1697
1990
  discountList: currentDiscountList
1698
1991
  });
1699
1992
  case 27:
1700
1993
  nextDiscountList = this.mergeHistoricalDiscountList(preparedDiscountList || (discountModule === null || discountModule === void 0 || (_discountModule$getDi2 = discountModule.getDiscountList) === null || _discountModule$getDi2 === void 0 ? void 0 : _discountModule$getDi2.call(discountModule)) || [], tempOrder.products || []);
1701
1994
  nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
1702
- _context17.next = 31;
1995
+ _context20.next = 31;
1703
1996
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1704
1997
  case 31:
1705
1998
  shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
@@ -1709,17 +2002,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1709
2002
  nextDiscountList: nextDiscountList
1710
2003
  });
1711
2004
  if (!shouldSkipAutoApplyFetchedDiscounts) {
1712
- _context17.next = 40;
2005
+ _context20.next = 40;
1713
2006
  break;
1714
2007
  }
1715
- _context17.next = 35;
2008
+ _context20.next = 35;
1716
2009
  return this.store.order.recalculateSummary({
1717
2010
  createIfMissing: true
1718
2011
  });
1719
2012
  case 35:
1720
- _summary = _context17.sent;
2013
+ _summary = _context20.sent;
1721
2014
  this.store.order.persistTempOrder();
1722
- _context17.next = 39;
2015
+ _context20.next = 39;
1723
2016
  return this.effectsEmit('onDiscountApplied', {
1724
2017
  productList: tempOrder.products || [],
1725
2018
  discountList: nextDiscountList,
@@ -1727,13 +2020,13 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1727
2020
  tempOrder: tempOrder
1728
2021
  });
1729
2022
  case 39:
1730
- return _context17.abrupt("return", {
2023
+ return _context20.abrupt("return", {
1731
2024
  productList: tempOrder.products || [],
1732
2025
  discountList: nextDiscountList
1733
2026
  });
1734
2027
  case 40:
1735
2028
  if (!rulesModule) {
1736
- _context17.next = 77;
2029
+ _context20.next = 77;
1737
2030
  break;
1738
2031
  }
1739
2032
  orderTotalAmount = Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0);
@@ -1753,22 +2046,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1753
2046
  if (result.productList) {
1754
2047
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1755
2048
  }
1756
- _iterator = _createForOfIteratorHelper(tempOrder.products || []);
1757
- _context17.prev = 46;
1758
- _iterator.s();
2049
+ _iterator2 = _createForOfIteratorHelper(tempOrder.products || []);
2050
+ _context20.prev = 46;
2051
+ _iterator2.s();
1759
2052
  case 48:
1760
- if ((_step = _iterator.n()).done) {
1761
- _context17.next = 63;
2053
+ if ((_step2 = _iterator2.n()).done) {
2054
+ _context20.next = 63;
1762
2055
  break;
1763
2056
  }
1764
- product = _step.value;
2057
+ product = _step2.value;
1765
2058
  productUid = (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number;
1766
2059
  runtimeOrigin = productUid ? (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.productsByUid) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3[productUid]) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.origin : undefined;
1767
2060
  if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1768
- _context17.next = 54;
2061
+ _context20.next = 54;
1769
2062
  break;
1770
2063
  }
1771
- return _context17.abrupt("continue", 61);
2064
+ return _context20.abrupt("continue", 61);
1772
2065
  case 54:
1773
2066
  totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
1774
2067
  return sum + Number(pd.amount || 0);
@@ -1786,41 +2079,41 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1786
2079
  bundle: product.product_bundle
1787
2080
  });
1788
2081
  case 61:
1789
- _context17.next = 48;
2082
+ _context20.next = 48;
1790
2083
  break;
1791
2084
  case 63:
1792
- _context17.next = 68;
2085
+ _context20.next = 68;
1793
2086
  break;
1794
2087
  case 65:
1795
- _context17.prev = 65;
1796
- _context17.t0 = _context17["catch"](46);
1797
- _iterator.e(_context17.t0);
2088
+ _context20.prev = 65;
2089
+ _context20.t0 = _context20["catch"](46);
2090
+ _iterator2.e(_context20.t0);
1798
2091
  case 68:
1799
- _context17.prev = 68;
1800
- _iterator.f();
1801
- return _context17.finish(68);
2092
+ _context20.prev = 68;
2093
+ _iterator2.f();
2094
+ return _context20.finish(68);
1802
2095
  case 71:
1803
2096
  if (!result.discountList) {
1804
- _context17.next = 77;
2097
+ _context20.next = 77;
1805
2098
  break;
1806
2099
  }
1807
2100
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1808
2101
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1809
- _context17.next = 76;
2102
+ _context20.next = 76;
1810
2103
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1811
2104
  case 76:
1812
2105
  tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1813
2106
  return discount.isSelected;
1814
2107
  });
1815
2108
  case 77:
1816
- _context17.next = 79;
2109
+ _context20.next = 79;
1817
2110
  return this.store.order.recalculateSummary({
1818
2111
  createIfMissing: true
1819
2112
  });
1820
2113
  case 79:
1821
- summary = _context17.sent;
2114
+ summary = _context20.sent;
1822
2115
  this.store.order.persistTempOrder();
1823
- _context17.next = 83;
2116
+ _context20.next = 83;
1824
2117
  return this.effectsEmit('onDiscountApplied', {
1825
2118
  productList: tempOrder.products || [],
1826
2119
  discountList: nextDiscountList,
@@ -1828,17 +2121,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1828
2121
  tempOrder: tempOrder
1829
2122
  });
1830
2123
  case 83:
1831
- return _context17.abrupt("return", {
2124
+ return _context20.abrupt("return", {
1832
2125
  productList: tempOrder.products || [],
1833
2126
  discountList: nextDiscountList
1834
2127
  });
1835
2128
  case 84:
1836
2129
  case "end":
1837
- return _context17.stop();
2130
+ return _context20.stop();
1838
2131
  }
1839
- }, _callee17, this, [[46, 65, 68, 71]]);
2132
+ }, _callee20, this, [[46, 65, 68, 71]]);
1840
2133
  }));
1841
- function loadDiscountConfig(_x11) {
2134
+ function loadDiscountConfig(_x13) {
1842
2135
  return _loadDiscountConfig.apply(this, arguments);
1843
2136
  }
1844
2137
  return loadDiscountConfig;
@@ -1846,14 +2139,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1846
2139
  }, {
1847
2140
  key: "bestDiscount",
1848
2141
  value: function () {
1849
- var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(cb) {
2142
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(cb) {
1850
2143
  var _discountModule$getOr2, _discountModule$getDi3;
1851
2144
  var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, currentDiscountList, nextDiscountList, result, _orderStore$summary2, orderTotalAmount;
1852
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1853
- while (1) switch (_context18.prev = _context18.next) {
2145
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2146
+ while (1) switch (_context21.prev = _context21.next) {
1854
2147
  case 0:
1855
2148
  if (this.store.order) {
1856
- _context18.next = 2;
2149
+ _context21.next = 2;
1857
2150
  break;
1858
2151
  }
1859
2152
  throw new Error('order 模块未初始化');
@@ -1869,11 +2162,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1869
2162
  productList: tempOrder.products || [],
1870
2163
  discountList: nextDiscountList
1871
2164
  };
1872
- _context18.next = 12;
2165
+ _context21.next = 12;
1873
2166
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1874
2167
  case 12:
1875
2168
  if (!rulesModule) {
1876
- _context18.next = 24;
2169
+ _context21.next = 24;
1877
2170
  break;
1878
2171
  }
1879
2172
  orderTotalAmount = Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0);
@@ -1891,12 +2184,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1891
2184
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1892
2185
  }
1893
2186
  if (!result.discountList) {
1894
- _context18.next = 24;
2187
+ _context21.next = 24;
1895
2188
  break;
1896
2189
  }
1897
2190
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1898
2191
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1899
- _context18.next = 22;
2192
+ _context21.next = 22;
1900
2193
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1901
2194
  case 22:
1902
2195
  tempOrder.discount_list = nextDiscountList.filter(function (discount) {
@@ -1907,13 +2200,13 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1907
2200
  discountList: nextDiscountList
1908
2201
  };
1909
2202
  case 24:
1910
- _context18.next = 26;
2203
+ _context21.next = 26;
1911
2204
  return this.store.order.recalculateSummary({
1912
2205
  createIfMissing: true
1913
2206
  });
1914
2207
  case 26:
1915
2208
  this.store.order.persistTempOrder();
1916
- _context18.next = 29;
2209
+ _context21.next = 29;
1917
2210
  return this.effectsEmit('onDiscountApplied', {
1918
2211
  productList: tempOrder.products || [],
1919
2212
  discountList: nextDiscountList,
@@ -1922,14 +2215,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1922
2215
  });
1923
2216
  case 29:
1924
2217
  cb === null || cb === void 0 || cb(result);
1925
- return _context18.abrupt("return", result);
2218
+ return _context21.abrupt("return", result);
1926
2219
  case 31:
1927
2220
  case "end":
1928
- return _context18.stop();
2221
+ return _context21.stop();
1929
2222
  }
1930
- }, _callee18, this);
2223
+ }, _callee21, this);
1931
2224
  }));
1932
- function bestDiscount(_x12) {
2225
+ function bestDiscount(_x14) {
1933
2226
  return _bestDiscount.apply(this, arguments);
1934
2227
  }
1935
2228
  return bestDiscount;
@@ -1958,41 +2251,41 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1958
2251
  }, {
1959
2252
  key: "replaceDiscountStoreLists",
1960
2253
  value: (function () {
1961
- var _replaceDiscountStoreLists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
2254
+ var _replaceDiscountStoreLists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1962
2255
  var _store2;
1963
2256
  var discountModule;
1964
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1965
- while (1) switch (_context19.prev = _context19.next) {
2257
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2258
+ while (1) switch (_context22.prev = _context22.next) {
1966
2259
  case 0:
1967
2260
  if (this.store.order) {
1968
- _context19.next = 2;
2261
+ _context22.next = 2;
1969
2262
  break;
1970
2263
  }
1971
2264
  throw new Error('order 模块未初始化');
1972
2265
  case 2:
1973
2266
  discountModule = (_store2 = this.store.order.store) === null || _store2 === void 0 ? void 0 : _store2.discount;
1974
2267
  if (discountModule) {
1975
- _context19.next = 5;
2268
+ _context22.next = 5;
1976
2269
  break;
1977
2270
  }
1978
- return _context19.abrupt("return");
2271
+ return _context22.abrupt("return");
1979
2272
  case 5:
1980
2273
  if (!params.originalDiscountList) {
1981
- _context19.next = 8;
2274
+ _context22.next = 8;
1982
2275
  break;
1983
2276
  }
1984
- _context19.next = 8;
2277
+ _context22.next = 8;
1985
2278
  return discountModule.setOriginalDiscountList(params.originalDiscountList);
1986
2279
  case 8:
1987
- _context19.next = 10;
2280
+ _context22.next = 10;
1988
2281
  return discountModule.setDiscountList(params.discountList);
1989
2282
  case 10:
1990
2283
  case "end":
1991
- return _context19.stop();
2284
+ return _context22.stop();
1992
2285
  }
1993
- }, _callee19, this);
2286
+ }, _callee22, this);
1994
2287
  }));
1995
- function replaceDiscountStoreLists(_x13) {
2288
+ function replaceDiscountStoreLists(_x15) {
1996
2289
  return _replaceDiscountStoreLists.apply(this, arguments);
1997
2290
  }
1998
2291
  return replaceDiscountStoreLists;
@@ -2000,34 +2293,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2000
2293
  }, {
2001
2294
  key: "scanPromotionCode",
2002
2295
  value: function () {
2003
- var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(code, customerId) {
2296
+ var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(code, customerId) {
2004
2297
  var raw, tempOrder;
2005
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2006
- while (1) switch (_context20.prev = _context20.next) {
2298
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2299
+ while (1) switch (_context23.prev = _context23.next) {
2007
2300
  case 0:
2008
- _context20.prev = 0;
2301
+ _context23.prev = 0;
2009
2302
  if (this.store.order) {
2010
- _context20.next = 3;
2303
+ _context23.next = 3;
2011
2304
  break;
2012
2305
  }
2013
2306
  throw new Error('order 模块未初始化');
2014
2307
  case 3:
2015
- _context20.next = 5;
2308
+ _context23.next = 5;
2016
2309
  return this.store.order.scanCode(code, customerId);
2017
2310
  case 5:
2018
- raw = _context20.sent;
2311
+ raw = _context23.sent;
2019
2312
  if (!raw.isAvailable) {
2020
- _context20.next = 13;
2313
+ _context23.next = 13;
2021
2314
  break;
2022
2315
  }
2023
- _context20.next = 9;
2316
+ _context23.next = 9;
2024
2317
  return this.store.order.recalculateSummary({
2025
2318
  createIfMissing: true
2026
2319
  });
2027
2320
  case 9:
2028
2321
  this.store.order.persistTempOrder();
2029
2322
  tempOrder = this.store.order.ensureTempOrder();
2030
- _context20.next = 13;
2323
+ _context23.next = 13;
2031
2324
  return this.effectsEmit('onDiscountApplied', {
2032
2325
  productList: tempOrder.products || [],
2033
2326
  discountList: this.store.order.getDiscountList(),
@@ -2035,23 +2328,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2035
2328
  tempOrder: tempOrder
2036
2329
  });
2037
2330
  case 13:
2038
- return _context20.abrupt("return", {
2331
+ return _context23.abrupt("return", {
2039
2332
  isAvailable: raw.isAvailable,
2040
2333
  type: raw.type,
2041
2334
  unavailableReason: raw.unavailableReason,
2042
2335
  scannedDiscountList: raw.scannedDiscountList
2043
2336
  });
2044
2337
  case 16:
2045
- _context20.prev = 16;
2046
- _context20.t0 = _context20["catch"](0);
2047
- throw _context20.t0;
2338
+ _context23.prev = 16;
2339
+ _context23.t0 = _context23["catch"](0);
2340
+ throw _context23.t0;
2048
2341
  case 19:
2049
2342
  case "end":
2050
- return _context20.stop();
2343
+ return _context23.stop();
2051
2344
  }
2052
- }, _callee20, this, [[0, 16]]);
2345
+ }, _callee23, this, [[0, 16]]);
2053
2346
  }));
2054
- function scanPromotionCode(_x14, _x15) {
2347
+ function scanPromotionCode(_x16, _x17) {
2055
2348
  return _scanPromotionCode.apply(this, arguments);
2056
2349
  }
2057
2350
  return scanPromotionCode;
@@ -2059,14 +2352,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2059
2352
  }, {
2060
2353
  key: "setDiscountSelected",
2061
2354
  value: function () {
2062
- var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2063
- var list, updated, tempOrder, orderStore, discountModule, rulesModule, nextDiscountList, _orderStore$summary3, orderTotalAmount, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, filterSelectedDiscountDetails, _iterator3, _step3, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
2064
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2065
- while (1) switch (_context21.prev = _context21.next) {
2355
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2356
+ var list, updated, tempOrder, orderStore, discountModule, rulesModule, nextDiscountList, _orderStore$summary3, orderTotalAmount, result, beforeSelectedIds, _iterator3, _step3, d, selectedResourceIds, filterSelectedDiscountDetails, _iterator4, _step4, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
2357
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2358
+ while (1) switch (_context24.prev = _context24.next) {
2066
2359
  case 0:
2067
- _context21.prev = 0;
2360
+ _context24.prev = 0;
2068
2361
  if (this.store.order) {
2069
- _context21.next = 3;
2362
+ _context24.next = 3;
2070
2363
  break;
2071
2364
  }
2072
2365
  throw new Error('order 模块未初始化');
@@ -2084,7 +2377,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2084
2377
  discountModule = orderStore.discount;
2085
2378
  rulesModule = orderStore.rules;
2086
2379
  nextDiscountList = updated;
2087
- _context21.next = 13;
2380
+ _context24.next = 13;
2088
2381
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
2089
2382
  case 13:
2090
2383
  if (rulesModule) {
@@ -2116,10 +2409,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2116
2409
  }).map(function (d) {
2117
2410
  return d.id;
2118
2411
  }));
2119
- _iterator2 = _createForOfIteratorHelper(nextDiscountList);
2412
+ _iterator3 = _createForOfIteratorHelper(nextDiscountList);
2120
2413
  try {
2121
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2122
- d = _step2.value;
2414
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2415
+ d = _step3.value;
2123
2416
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
2124
2417
  d.isSelected = false;
2125
2418
  d.isManualSelect = true;
@@ -2127,9 +2420,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2127
2420
  }
2128
2421
  }
2129
2422
  } catch (err) {
2130
- _iterator2.e(err);
2423
+ _iterator3.e(err);
2131
2424
  } finally {
2132
- _iterator2.f();
2425
+ _iterator3.f();
2133
2426
  }
2134
2427
  }
2135
2428
  }
@@ -2146,30 +2439,30 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2146
2439
  return rid != null && selectedResourceIds.has(rid);
2147
2440
  });
2148
2441
  };
2149
- _iterator3 = _createForOfIteratorHelper(tempOrder.products);
2150
- _context21.prev = 17;
2151
- _iterator3.s();
2442
+ _iterator4 = _createForOfIteratorHelper(tempOrder.products);
2443
+ _context24.prev = 17;
2444
+ _iterator4.s();
2152
2445
  case 19:
2153
- if ((_step3 = _iterator3.n()).done) {
2154
- _context21.next = 36;
2446
+ if ((_step4 = _iterator4.n()).done) {
2447
+ _context24.next = 36;
2155
2448
  break;
2156
2449
  }
2157
- product = _step3.value;
2450
+ product = _step4.value;
2158
2451
  productUid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
2159
2452
  runtimeOrigin = productUid ? (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4.productsByUid) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4[productUid]) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.origin : undefined;
2160
2453
  if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
2161
- _context21.next = 25;
2454
+ _context24.next = 25;
2162
2455
  break;
2163
2456
  }
2164
- return _context21.abrupt("continue", 34);
2457
+ return _context24.abrupt("continue", 34);
2165
2458
  case 25:
2166
2459
  product.discount_list = filterSelectedDiscountDetails(product.discount_list);
2167
2460
  if (Array.isArray(product.product_bundle)) {
2168
2461
  product.product_bundle = product.product_bundle.map(function (bundle) {
2169
- var _ref20, _bundle$original_pric;
2462
+ var _ref21, _bundle$original_pric;
2170
2463
  var nextBundleDiscountList = filterSelectedDiscountDetails(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
2171
2464
  var shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
2172
- var restoredBundlePrice = (_ref20 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref20 !== void 0 ? _ref20 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2465
+ var restoredBundlePrice = (_ref21 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref21 !== void 0 ? _ref21 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2173
2466
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), shouldRestoreBundlePrice ? {
2174
2467
  price: restoredBundlePrice,
2175
2468
  bundle_selling_price: restoredBundlePrice
@@ -2197,28 +2490,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2197
2490
  bundle: product.product_bundle
2198
2491
  });
2199
2492
  case 34:
2200
- _context21.next = 19;
2493
+ _context24.next = 19;
2201
2494
  break;
2202
2495
  case 36:
2203
- _context21.next = 41;
2496
+ _context24.next = 41;
2204
2497
  break;
2205
2498
  case 38:
2206
- _context21.prev = 38;
2207
- _context21.t0 = _context21["catch"](17);
2208
- _iterator3.e(_context21.t0);
2499
+ _context24.prev = 38;
2500
+ _context24.t0 = _context24["catch"](17);
2501
+ _iterator4.e(_context24.t0);
2209
2502
  case 41:
2210
- _context21.prev = 41;
2211
- _iterator3.f();
2212
- return _context21.finish(41);
2503
+ _context24.prev = 41;
2504
+ _iterator4.f();
2505
+ return _context24.finish(41);
2213
2506
  case 44:
2214
2507
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
2215
- _context21.next = 47;
2508
+ _context24.next = 47;
2216
2509
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
2217
2510
  case 47:
2218
2511
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
2219
2512
  return d.isSelected;
2220
2513
  });
2221
- _context21.next = 50;
2514
+ _context24.next = 50;
2222
2515
  return this.store.order.recalculateSummary({
2223
2516
  createIfMissing: true
2224
2517
  });
@@ -2230,19 +2523,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2230
2523
  selectedDiscountList: tempOrder.discount_list,
2231
2524
  tempOrder: tempOrder
2232
2525
  });
2233
- _context21.next = 57;
2526
+ _context24.next = 57;
2234
2527
  break;
2235
2528
  case 54:
2236
- _context21.prev = 54;
2237
- _context21.t1 = _context21["catch"](0);
2238
- throw _context21.t1;
2529
+ _context24.prev = 54;
2530
+ _context24.t1 = _context24["catch"](0);
2531
+ throw _context24.t1;
2239
2532
  case 57:
2240
2533
  case "end":
2241
- return _context21.stop();
2534
+ return _context24.stop();
2242
2535
  }
2243
- }, _callee21, this, [[0, 54], [17, 38, 41, 44]]);
2536
+ }, _callee24, this, [[0, 54], [17, 38, 41, 44]]);
2244
2537
  }));
2245
- function setDiscountSelected(_x16) {
2538
+ function setDiscountSelected(_x18) {
2246
2539
  return _setDiscountSelected.apply(this, arguments);
2247
2540
  }
2248
2541
  return setDiscountSelected;
@@ -2250,23 +2543,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2250
2543
  }, {
2251
2544
  key: "applyDiscountCalculationResult",
2252
2545
  value: function () {
2253
- var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(result) {
2546
+ var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(result) {
2254
2547
  var tempOrder, orderStore, discountModule;
2255
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2256
- while (1) switch (_context22.prev = _context22.next) {
2548
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2549
+ while (1) switch (_context25.prev = _context25.next) {
2257
2550
  case 0:
2258
- _context22.prev = 0;
2551
+ _context25.prev = 0;
2259
2552
  if (this.store.order) {
2260
- _context22.next = 3;
2553
+ _context25.next = 3;
2261
2554
  break;
2262
2555
  }
2263
2556
  throw new Error('order 模块未初始化');
2264
2557
  case 3:
2265
2558
  if (result) {
2266
- _context22.next = 5;
2559
+ _context25.next = 5;
2267
2560
  break;
2268
2561
  }
2269
- return _context22.abrupt("return");
2562
+ return _context25.abrupt("return");
2270
2563
  case 5:
2271
2564
  tempOrder = this.store.order.ensureTempOrder();
2272
2565
  orderStore = this.store.order.store || {};
@@ -2275,24 +2568,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2275
2568
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2276
2569
  }
2277
2570
  if (!result.discountList) {
2278
- _context22.next = 14;
2571
+ _context25.next = 14;
2279
2572
  break;
2280
2573
  }
2281
2574
  OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
2282
- _context22.next = 13;
2575
+ _context25.next = 13;
2283
2576
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(result.discountList);
2284
2577
  case 13:
2285
2578
  tempOrder.discount_list = result.discountList.filter(function (discount) {
2286
2579
  return discount.isSelected;
2287
2580
  });
2288
2581
  case 14:
2289
- _context22.next = 16;
2582
+ _context25.next = 16;
2290
2583
  return this.store.order.recalculateSummary({
2291
2584
  createIfMissing: true
2292
2585
  });
2293
2586
  case 16:
2294
2587
  this.store.order.persistTempOrder();
2295
- _context22.next = 19;
2588
+ _context25.next = 19;
2296
2589
  return this.effectsEmit('onDiscountApplied', {
2297
2590
  productList: tempOrder.products || [],
2298
2591
  discountList: result.discountList || [],
@@ -2300,19 +2593,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2300
2593
  tempOrder: tempOrder
2301
2594
  });
2302
2595
  case 19:
2303
- _context22.next = 24;
2596
+ _context25.next = 24;
2304
2597
  break;
2305
2598
  case 21:
2306
- _context22.prev = 21;
2307
- _context22.t0 = _context22["catch"](0);
2308
- throw _context22.t0;
2599
+ _context25.prev = 21;
2600
+ _context25.t0 = _context25["catch"](0);
2601
+ throw _context25.t0;
2309
2602
  case 24:
2310
2603
  case "end":
2311
- return _context22.stop();
2604
+ return _context25.stop();
2312
2605
  }
2313
- }, _callee22, this, [[0, 21]]);
2606
+ }, _callee25, this, [[0, 21]]);
2314
2607
  }));
2315
- function applyDiscountCalculationResult(_x17) {
2608
+ function applyDiscountCalculationResult(_x19) {
2316
2609
  return _applyDiscountCalculationResult.apply(this, arguments);
2317
2610
  }
2318
2611
  return applyDiscountCalculationResult;
@@ -2320,18 +2613,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2320
2613
  }, {
2321
2614
  key: "submitScanOrder",
2322
2615
  value: function () {
2323
- var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2324
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2325
- while (1) switch (_context23.prev = _context23.next) {
2616
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2617
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2618
+ while (1) switch (_context26.prev = _context26.next) {
2326
2619
  case 0:
2327
- return _context23.abrupt("return", this.submitSalesOrder(params));
2620
+ return _context26.abrupt("return", this.submitSalesOrder(params));
2328
2621
  case 1:
2329
2622
  case "end":
2330
- return _context23.stop();
2623
+ return _context26.stop();
2331
2624
  }
2332
- }, _callee23, this);
2625
+ }, _callee26, this);
2333
2626
  }));
2334
- function submitScanOrder(_x18) {
2627
+ function submitScanOrder(_x20) {
2335
2628
  return _submitScanOrder.apply(this, arguments);
2336
2629
  }
2337
2630
  return submitScanOrder;
@@ -2345,14 +2638,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2345
2638
  }, {
2346
2639
  key: "submitSalesOrder",
2347
2640
  value: (function () {
2348
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2641
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2349
2642
  var _this$otherParams6, _this$otherParams7, _this$otherParams8, _this$otherParams9;
2350
2643
  var inferredPaymentStatus, submitParams;
2351
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2352
- while (1) switch (_context24.prev = _context24.next) {
2644
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2645
+ while (1) switch (_context27.prev = _context27.next) {
2353
2646
  case 0:
2354
2647
  if (this.store.order) {
2355
- _context24.next = 2;
2648
+ _context27.next = 2;
2356
2649
  break;
2357
2650
  }
2358
2651
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2377,29 +2670,63 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2377
2670
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2378
2671
  enhancePayload: params.enhancePayload
2379
2672
  } : {});
2380
- return _context24.abrupt("return", this.store.order.submitTempOrder(submitParams));
2673
+ return _context27.abrupt("return", this.store.order.submitTempOrder(submitParams));
2381
2674
  case 5:
2382
2675
  case "end":
2383
- return _context24.stop();
2676
+ return _context27.stop();
2384
2677
  }
2385
- }, _callee24, this);
2678
+ }, _callee27, this);
2386
2679
  }));
2387
- function submitSalesOrder(_x19) {
2680
+ function submitSalesOrder(_x21) {
2388
2681
  return _submitSalesOrder.apply(this, arguments);
2389
2682
  }
2390
2683
  return submitSalesOrder;
2391
2684
  }())
2685
+ }, {
2686
+ key: "saveSalesOrderDraft",
2687
+ value: function () {
2688
+ var _saveSalesOrderDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2689
+ var _params$platform, _this$otherParams10, _ref22, _params$businessCode, _this$otherParams11, _this$otherParams12, _params$channel, _params$type, _this$otherParams13;
2690
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2691
+ while (1) switch (_context28.prev = _context28.next) {
2692
+ case 0:
2693
+ if (this.store.order) {
2694
+ _context28.next = 2;
2695
+ break;
2696
+ }
2697
+ throw new Error('BaseSales 解决方案需要 order 模块支持');
2698
+ case 2:
2699
+ return _context28.abrupt("return", this.store.order.saveTempOrderAsDraft(_objectSpread({
2700
+ cacheId: this.cacheId,
2701
+ platform: (_params$platform = params === null || params === void 0 ? void 0 : params.platform) !== null && _params$platform !== void 0 ? _params$platform : (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2702
+ businessCode: (_ref22 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref22 !== void 0 ? _ref22 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
2703
+ channel: (_params$channel = params === null || params === void 0 ? void 0 : params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel(),
2704
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.type
2705
+ }, (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2706
+ enhancePayload: params.enhancePayload
2707
+ } : {})));
2708
+ case 3:
2709
+ case "end":
2710
+ return _context28.stop();
2711
+ }
2712
+ }, _callee28, this);
2713
+ }));
2714
+ function saveSalesOrderDraft(_x22) {
2715
+ return _saveSalesOrderDraft.apply(this, arguments);
2716
+ }
2717
+ return saveSalesOrderDraft;
2718
+ }()
2392
2719
  }, {
2393
2720
  key: "submitTempOrderAsync",
2394
2721
  value: function () {
2395
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2396
- var _this$otherParams10, _this$otherParams11, _this$otherParams12, _this$otherParams13;
2722
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2723
+ var _this$otherParams14, _this$otherParams15, _this$otherParams16, _this$otherParams17;
2397
2724
  var inferredPaymentStatus, submitParams;
2398
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2399
- while (1) switch (_context25.prev = _context25.next) {
2725
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2726
+ while (1) switch (_context29.prev = _context29.next) {
2400
2727
  case 0:
2401
2728
  if (this.store.order) {
2402
- _context25.next = 2;
2729
+ _context29.next = 2;
2403
2730
  break;
2404
2731
  }
2405
2732
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2407,10 +2734,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2407
2734
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2408
2735
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2409
2736
  cacheId: this.cacheId,
2410
- platform: (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2411
- businessCode: ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code),
2737
+ platform: (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.platform,
2738
+ businessCode: ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.businessCode) || ((_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.business_code),
2412
2739
  channel: this.getSubmitOrderSalesChannel(),
2413
- type: (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.type
2740
+ type: (_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.type
2414
2741
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
2415
2742
  payments: params.payments
2416
2743
  } : {}), inferredPaymentStatus !== undefined ? {
@@ -2422,14 +2749,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2422
2749
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2423
2750
  enhancePayload: params.enhancePayload
2424
2751
  } : {});
2425
- return _context25.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2752
+ return _context29.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2426
2753
  case 5:
2427
2754
  case "end":
2428
- return _context25.stop();
2755
+ return _context29.stop();
2429
2756
  }
2430
- }, _callee25, this);
2757
+ }, _callee29, this);
2431
2758
  }));
2432
- function submitTempOrderAsync(_x20) {
2759
+ function submitTempOrderAsync(_x23) {
2433
2760
  return _submitTempOrderAsync.apply(this, arguments);
2434
2761
  }
2435
2762
  return submitTempOrderAsync;
@@ -2437,14 +2764,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2437
2764
  }, {
2438
2765
  key: "printLocalOrderReceipt",
2439
2766
  value: function () {
2440
- var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(lookup) {
2441
- var _this$otherParams14, _this$otherParams15, _this$otherParams16, _this$otherParams17;
2767
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(lookup) {
2768
+ var _this$otherParams18, _this$otherParams19, _this$otherParams20, _this$otherParams21;
2442
2769
  var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order4, _data;
2443
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2444
- while (1) switch (_context26.prev = _context26.next) {
2770
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2771
+ while (1) switch (_context30.prev = _context30.next) {
2445
2772
  case 0:
2446
2773
  if (this.store.order) {
2447
- _context26.next = 2;
2774
+ _context30.next = 2;
2448
2775
  break;
2449
2776
  }
2450
2777
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2456,10 +2783,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2456
2783
  external_sale_number: lookup
2457
2784
  };
2458
2785
  context = {
2459
- platform: (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.platform,
2460
- businessCode: ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.businessCode) || ((_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.business_code),
2786
+ platform: (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.platform,
2787
+ businessCode: ((_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.businessCode) || ((_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.business_code),
2461
2788
  channel: this.getSubmitOrderSalesChannel(),
2462
- type: (_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.type
2789
+ type: (_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21.type
2463
2790
  };
2464
2791
  payload = hasLookup ? _objectSpread(_objectSpread({}, lookupPayload), {}, {
2465
2792
  lookup_order_from_db: 1,
@@ -2475,28 +2802,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2475
2802
  channel: context.channel,
2476
2803
  type: context.type
2477
2804
  });
2478
- _context26.next = 8;
2805
+ _context30.next = 8;
2479
2806
  return this.request.post('/local/print-order', payload, {
2480
2807
  osServer: true,
2481
2808
  customToast: function customToast() {}
2482
2809
  });
2483
2810
  case 8:
2484
- response = _context26.sent;
2811
+ response = _context30.sent;
2485
2812
  if (hasLookup) {
2486
- _context26.next = 12;
2813
+ _context30.next = 12;
2487
2814
  break;
2488
2815
  }
2489
- _context26.next = 12;
2816
+ _context30.next = 12;
2490
2817
  return (_this$store$order$app = (_this$store$order4 = this.store.order).applyLocalPrintOrderNumbers) === null || _this$store$order$app === void 0 ? void 0 : _this$store$order$app.call(_this$store$order4, response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.order);
2491
2818
  case 12:
2492
- return _context26.abrupt("return", response);
2819
+ return _context30.abrupt("return", response);
2493
2820
  case 13:
2494
2821
  case "end":
2495
- return _context26.stop();
2822
+ return _context30.stop();
2496
2823
  }
2497
- }, _callee26, this);
2824
+ }, _callee30, this);
2498
2825
  }));
2499
- function printLocalOrderReceipt(_x21) {
2826
+ function printLocalOrderReceipt(_x24) {
2500
2827
  return _printLocalOrderReceipt.apply(this, arguments);
2501
2828
  }
2502
2829
  return printLocalOrderReceipt;
@@ -2517,20 +2844,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2517
2844
  }, {
2518
2845
  key: "syncPaymentsToOrder",
2519
2846
  value: function () {
2520
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2521
- var _ref21, _params$businessCode, _this$otherParams18, _this$otherParams19, _params$channel;
2847
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
2848
+ var _ref23, _params$businessCode2, _this$otherParams22, _this$otherParams23, _params$channel2;
2522
2849
  var businessCode, channel, syncParams, syncState, payments, syncResult, latestPayments, amountSnapshot, orderSnapshot, syncPayload;
2523
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2524
- while (1) switch (_context27.prev = _context27.next) {
2850
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2851
+ while (1) switch (_context31.prev = _context31.next) {
2525
2852
  case 0:
2526
2853
  if (this.store.order) {
2527
- _context27.next = 2;
2854
+ _context31.next = 2;
2528
2855
  break;
2529
2856
  }
2530
2857
  throw new Error('order 模块未初始化');
2531
2858
  case 2:
2532
- businessCode = (_ref21 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.businessCode) !== null && _ref21 !== void 0 ? _ref21 : (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.business_code;
2533
- channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
2859
+ businessCode = (_ref23 = (_params$businessCode2 = params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.businessCode) !== null && _ref23 !== void 0 ? _ref23 : (_this$otherParams23 = this.otherParams) === null || _this$otherParams23 === void 0 ? void 0 : _this$otherParams23.business_code;
2860
+ channel = (_params$channel2 = params.channel) !== null && _params$channel2 !== void 0 ? _params$channel2 : this.getSubmitOrderSalesChannel();
2534
2861
  syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), businessCode !== undefined ? {
2535
2862
  businessCode: businessCode
2536
2863
  } : {}), channel !== undefined ? {
@@ -2538,14 +2865,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2538
2865
  } : {});
2539
2866
  syncState = this.store.order.getOrderSyncState();
2540
2867
  if (!(params.submitWhenPaid && syncState === 'submitting')) {
2541
- _context27.next = 9;
2868
+ _context31.next = 9;
2542
2869
  break;
2543
2870
  }
2544
2871
  this.queueLatestAutoPaymentSync();
2545
- return _context27.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2872
+ return _context31.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2546
2873
  case 9:
2547
2874
  payments = params.payments || [];
2548
- _context27.next = 12;
2875
+ _context31.next = 12;
2549
2876
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2550
2877
  payments: payments,
2551
2878
  params: syncParams,
@@ -2553,11 +2880,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2553
2880
  orderSnapshot: this.store.order.getOrderSnapshot()
2554
2881
  });
2555
2882
  case 12:
2556
- _context27.prev = 12;
2557
- _context27.next = 15;
2883
+ _context31.prev = 12;
2884
+ _context31.next = 15;
2558
2885
  return this.store.order.syncPaymentsToOrder(syncParams);
2559
2886
  case 15:
2560
- syncResult = _context27.sent;
2887
+ syncResult = _context31.sent;
2561
2888
  latestPayments = this.store.order.getOrderPayments();
2562
2889
  amountSnapshot = this.store.order.getOrderAmountSnapshot();
2563
2890
  orderSnapshot = this.store.order.getOrderSnapshot();
@@ -2575,25 +2902,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2575
2902
  depositAmount: syncResult.depositAmount,
2576
2903
  orderExpectedAmount: syncResult.orderExpectedAmount
2577
2904
  };
2578
- _context27.next = 22;
2905
+ _context31.next = 22;
2579
2906
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
2580
2907
  case 22:
2581
2908
  if (!(syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid)) {
2582
- _context27.next = 25;
2909
+ _context31.next = 25;
2583
2910
  break;
2584
2911
  }
2585
- _context27.next = 25;
2912
+ _context31.next = 25;
2586
2913
  return this.effectsEmit(BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
2587
2914
  case 25:
2588
2915
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2589
- return _context27.abrupt("return", syncResult);
2916
+ return _context31.abrupt("return", syncResult);
2590
2917
  case 29:
2591
- _context27.prev = 29;
2592
- _context27.t0 = _context27["catch"](12);
2593
- _context27.next = 33;
2918
+ _context31.prev = 29;
2919
+ _context31.t0 = _context31["catch"](12);
2920
+ _context31.next = 33;
2594
2921
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2595
2922
  ok: false,
2596
- error: _context27.t0,
2923
+ error: _context31.t0,
2597
2924
  payments: this.store.order.getOrderPayments(),
2598
2925
  params: syncParams,
2599
2926
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
@@ -2601,14 +2928,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2601
2928
  });
2602
2929
  case 33:
2603
2930
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2604
- throw _context27.t0;
2931
+ throw _context31.t0;
2605
2932
  case 35:
2606
2933
  case "end":
2607
- return _context27.stop();
2934
+ return _context31.stop();
2608
2935
  }
2609
- }, _callee27, this, [[12, 29]]);
2936
+ }, _callee31, this, [[12, 29]]);
2610
2937
  }));
2611
- function syncPaymentsToOrder(_x22) {
2938
+ function syncPaymentsToOrder(_x25) {
2612
2939
  return _syncPaymentsToOrder.apply(this, arguments);
2613
2940
  }
2614
2941
  return syncPaymentsToOrder;
@@ -2645,58 +2972,58 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2645
2972
  }, {
2646
2973
  key: "scheduleQueuedAutoPaymentSyncFlush",
2647
2974
  value: function scheduleQueuedAutoPaymentSyncFlush() {
2648
- var _this10 = this;
2975
+ var _this13 = this;
2649
2976
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
2650
2977
  if (!this.queuedAutoPaymentSync) return;
2651
2978
  if (this.autoPaymentSyncTimer) return;
2652
2979
  this.autoPaymentSyncTimer = setTimeout(function () {
2653
- _this10.autoPaymentSyncTimer = null;
2654
- void _this10.flushQueuedAutoPaymentSync();
2980
+ _this13.autoPaymentSyncTimer = null;
2981
+ void _this13.flushQueuedAutoPaymentSync();
2655
2982
  }, delay);
2656
2983
  }
2657
2984
  }, {
2658
2985
  key: "flushQueuedAutoPaymentSync",
2659
2986
  value: function () {
2660
- var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2987
+ var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2661
2988
  var payments;
2662
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2663
- while (1) switch (_context28.prev = _context28.next) {
2989
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2990
+ while (1) switch (_context32.prev = _context32.next) {
2664
2991
  case 0:
2665
2992
  if (this.store.order) {
2666
- _context28.next = 2;
2993
+ _context32.next = 2;
2667
2994
  break;
2668
2995
  }
2669
- return _context28.abrupt("return");
2996
+ return _context32.abrupt("return");
2670
2997
  case 2:
2671
2998
  if (!(!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)) {
2672
- _context28.next = 4;
2999
+ _context32.next = 4;
2673
3000
  break;
2674
3001
  }
2675
- return _context28.abrupt("return");
3002
+ return _context32.abrupt("return");
2676
3003
  case 4:
2677
3004
  if (!(this.store.order.getOrderSyncState() === 'submitting')) {
2678
- _context28.next = 7;
3005
+ _context32.next = 7;
2679
3006
  break;
2680
3007
  }
2681
3008
  this.scheduleQueuedAutoPaymentSyncFlush();
2682
- return _context28.abrupt("return");
3009
+ return _context32.abrupt("return");
2683
3010
  case 7:
2684
3011
  this.autoPaymentSyncFlushing = true;
2685
- _context28.prev = 8;
3012
+ _context32.prev = 8;
2686
3013
  case 9:
2687
3014
  if (!this.queuedAutoPaymentSync) {
2688
- _context28.next = 18;
3015
+ _context32.next = 18;
2689
3016
  break;
2690
3017
  }
2691
3018
  this.queuedAutoPaymentSync = false;
2692
3019
  payments = this.store.order.getOrderPayments();
2693
3020
  if (payments.length) {
2694
- _context28.next = 14;
3021
+ _context32.next = 14;
2695
3022
  break;
2696
3023
  }
2697
- return _context28.abrupt("continue", 9);
3024
+ return _context32.abrupt("continue", 9);
2698
3025
  case 14:
2699
- _context28.next = 16;
3026
+ _context32.next = 16;
2700
3027
  return this.syncPaymentsToOrder({
2701
3028
  payments: payments,
2702
3029
  paymentStatus: this.getPaymentStatusForSync(payments),
@@ -2704,44 +3031,91 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2704
3031
  smallTicketDataFlag: 1
2705
3032
  });
2706
3033
  case 16:
2707
- _context28.next = 9;
3034
+ _context32.next = 9;
2708
3035
  break;
2709
3036
  case 18:
2710
- _context28.next = 23;
3037
+ _context32.next = 23;
2711
3038
  break;
2712
3039
  case 20:
2713
- _context28.prev = 20;
2714
- _context28.t0 = _context28["catch"](8);
3040
+ _context32.prev = 20;
3041
+ _context32.t0 = _context32["catch"](8);
2715
3042
  this.logError('queued auto sync payments failed', {
2716
- error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0)
3043
+ error: _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0)
2717
3044
  });
2718
3045
  case 23:
2719
- _context28.prev = 23;
3046
+ _context32.prev = 23;
2720
3047
  this.autoPaymentSyncFlushing = false;
2721
3048
  if (this.queuedAutoPaymentSync) {
2722
3049
  this.scheduleQueuedAutoPaymentSyncFlush(0);
2723
3050
  }
2724
- return _context28.finish(23);
3051
+ return _context32.finish(23);
2725
3052
  case 27:
2726
3053
  case "end":
2727
- return _context28.stop();
3054
+ return _context32.stop();
2728
3055
  }
2729
- }, _callee28, this, [[8, 20, 23, 27]]);
3056
+ }, _callee32, this, [[8, 20, 23, 27]]);
2730
3057
  }));
2731
3058
  function flushQueuedAutoPaymentSync() {
2732
3059
  return _flushQueuedAutoPaymentSync.apply(this, arguments);
2733
3060
  }
2734
3061
  return flushQueuedAutoPaymentSync;
2735
- }() /** 追加单个支付项到当前订单。 */
3062
+ }()
3063
+ /**
3064
+ * 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
3065
+ */
2736
3066
  }, {
2737
3067
  key: "addOrderPayment",
2738
3068
  value: function addOrderPayment(payment) {
2739
- var _this$otherParams20,
3069
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3070
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3071
+ }
3072
+
3073
+ /** 创建新支付项时读取最新设备短号,不缓存运行时设备信息。 */
3074
+ }, {
3075
+ key: "addOrderPaymentAsync",
3076
+ value: (function () {
3077
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(payment) {
3078
+ var paymentRecord, hasPaymentNumber, devicePrefix;
3079
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3080
+ while (1) switch (_context33.prev = _context33.next) {
3081
+ case 0:
3082
+ paymentRecord = payment;
3083
+ hasPaymentNumber = String(paymentRecord.payment_number || '').trim() !== '';
3084
+ if (!hasPaymentNumber) {
3085
+ _context33.next = 6;
3086
+ break;
3087
+ }
3088
+ _context33.t0 = 'LOCAL';
3089
+ _context33.next = 9;
3090
+ break;
3091
+ case 6:
3092
+ _context33.next = 8;
3093
+ return this.getPaymentNumberDevicePrefixAsync();
3094
+ case 8:
3095
+ _context33.t0 = _context33.sent;
3096
+ case 9:
3097
+ devicePrefix = _context33.t0;
3098
+ return _context33.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3099
+ case 11:
3100
+ case "end":
3101
+ return _context33.stop();
3102
+ }
3103
+ }, _callee33, this);
3104
+ }));
3105
+ function addOrderPaymentAsync(_x26) {
3106
+ return _addOrderPaymentAsync.apply(this, arguments);
3107
+ }
3108
+ return addOrderPaymentAsync;
3109
+ }())
3110
+ }, {
3111
+ key: "addOrderPaymentWithDevicePrefix",
3112
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3113
+ var _this$otherParams24,
2740
3114
  _paymentRecord$paymen,
2741
3115
  _paymentRecord$create,
2742
- _ref22,
3116
+ _ref24,
2743
3117
  _paymentRecord$origin,
2744
- _this11 = this;
3118
+ _this14 = this;
2745
3119
  if (!this.store.order) throw new Error('order 模块未初始化');
2746
3120
  var paymentRecord = payment;
2747
3121
  var paymentAmount = new Decimal(paymentRecord.amount || 0);
@@ -2752,25 +3126,26 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2752
3126
  return this.store.order.getOrderPayments();
2753
3127
  }
2754
3128
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
2755
- var shopWalletPassId = (_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.shop_wallet_pass_id;
3129
+ var shopWalletPassId = (_this$otherParams24 = this.otherParams) === null || _this$otherParams24 === void 0 ? void 0 : _this$otherParams24.shop_wallet_pass_id;
2756
3130
  if (shopWalletPassId !== undefined && shopWalletPassId !== null) {
2757
3131
  metadata.shop_wallet_pass_id = shopWalletPassId;
2758
3132
  }
2759
- if (!metadata.unique_payment_number) {
2760
- metadata.unique_payment_number = createUuidV4();
2761
- }
3133
+ var normalizedPaymentRecord = ensureOrderPaymentNumber(paymentRecord, devicePrefix, createUuidV4);
2762
3134
  var paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
2763
3135
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
2764
3136
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
2765
3137
  var serviceCharge = paymentRecord.service_charge && _typeof(paymentRecord.service_charge) === 'object' ? paymentRecord.service_charge : null;
2766
- var calculatedServiceFee = serviceCharge ? new Decimal((_ref22 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref22 !== void 0 ? _ref22 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
2767
- var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, paymentRecord), calculatedServiceFee !== undefined ? {
3138
+ var calculatedServiceFee = serviceCharge ? new Decimal((_ref24 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref24 !== void 0 ? _ref24 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
3139
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, normalizedPaymentRecord), calculatedServiceFee !== undefined ? {
2768
3140
  service_fee: calculatedServiceFee
2769
3141
  } : {}), {}, {
2770
3142
  metadata: metadata,
2771
3143
  payment_time: paymentTime,
2772
3144
  created_at: createdAt
2773
3145
  }));
3146
+ if (paymentRecord.status === 'payment_pending') {
3147
+ return payments;
3148
+ }
2774
3149
  var amountSnapshot = this.store.order.getOrderAmountSnapshot();
2775
3150
  var syncState = this.store.order.getOrderSyncState();
2776
3151
  if (amountSnapshot) {
@@ -2784,7 +3159,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2784
3159
  submitWhenPaid: true,
2785
3160
  smallTicketDataFlag: 1
2786
3161
  }).catch(function (error) {
2787
- _this11.logError('auto sync payments failed', {
3162
+ _this14.logError('auto sync payments failed', {
2788
3163
  error: error instanceof Error ? error.message : String(error)
2789
3164
  });
2790
3165
  });
@@ -2795,12 +3170,131 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2795
3170
  /** 更新当前订单中的指定支付项。 */
2796
3171
  }, {
2797
3172
  key: "updateOrderPayment",
2798
- value: function updateOrderPayment(paymentIdentity, updates) {
2799
- if (!this.store.order) throw new Error('order 模块未初始化');
2800
- return this.store.order.updateOrderPayment(paymentIdentity, updates);
2801
- }
2802
-
2803
- /** 删除当前订单中的指定支付项。 */
3173
+ value: (function () {
3174
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(paymentIdentity, updates) {
3175
+ var _result$payment, _result$payment2;
3176
+ var options,
3177
+ matchMode,
3178
+ previousMatch,
3179
+ previousPayment,
3180
+ _this$store$order$get2,
3181
+ currentPayments,
3182
+ _syncResult,
3183
+ _options$smallTicketD,
3184
+ result,
3185
+ draftResult,
3186
+ draftError,
3187
+ becamePaid,
3188
+ shouldSubmit,
3189
+ syncResult,
3190
+ _options$smallTicketD2,
3191
+ _args34 = arguments;
3192
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3193
+ while (1) switch (_context34.prev = _context34.next) {
3194
+ case 0:
3195
+ options = _args34.length > 2 && _args34[2] !== undefined ? _args34[2] : {};
3196
+ if (this.store.order) {
3197
+ _context34.next = 3;
3198
+ break;
3199
+ }
3200
+ throw new Error('order 模块未初始化');
3201
+ case 3:
3202
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3203
+ previousMatch = resolveOrderPaymentIdentity(this.store.order.getOrderPayments(), paymentIdentity, matchMode);
3204
+ previousPayment = previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.payment;
3205
+ if (!((previousPayment === null || previousPayment === void 0 ? void 0 : previousPayment.status) === 'paid' && !options.applyUpdatesWhenPaid)) {
3206
+ _context34.next = 13;
3207
+ break;
3208
+ }
3209
+ currentPayments = this.store.order.getOrderPayments();
3210
+ if (!(options.submitWhenPaid && options.forceSubmitIfPaid)) {
3211
+ _context34.next = 12;
3212
+ break;
3213
+ }
3214
+ _context34.next = 11;
3215
+ return this.syncPaymentsToOrder({
3216
+ payments: currentPayments,
3217
+ paymentStatus: this.getPaymentStatusForSync(currentPayments),
3218
+ submitWhenPaid: true,
3219
+ smallTicketDataFlag: (_options$smallTicketD = options.smallTicketDataFlag) !== null && _options$smallTicketD !== void 0 ? _options$smallTicketD : 1
3220
+ });
3221
+ case 11:
3222
+ _syncResult = _context34.sent;
3223
+ case 12:
3224
+ return _context34.abrupt("return", _objectSpread({
3225
+ updated: false,
3226
+ payment: previousPayment,
3227
+ payments: currentPayments,
3228
+ summary: ((_this$store$order$get2 = this.store.order.getOrderAmountSnapshot()) === null || _this$store$order$get2 === void 0 ? void 0 : _this$store$order$get2.summary) || null
3229
+ }, _syncResult !== undefined ? {
3230
+ syncResult: _syncResult
3231
+ } : {}));
3232
+ case 13:
3233
+ _context34.next = 15;
3234
+ return this.store.order.updateOrderPayment(paymentIdentity, updates, {
3235
+ matchBy: matchMode
3236
+ });
3237
+ case 15:
3238
+ result = _context34.sent;
3239
+ if (!(options.persistDraft !== false)) {
3240
+ _context34.next = 29;
3241
+ break;
3242
+ }
3243
+ _context34.prev = 17;
3244
+ _context34.next = 20;
3245
+ return this.saveSalesOrderDraft();
3246
+ case 20:
3247
+ draftResult = _context34.sent;
3248
+ _context34.next = 29;
3249
+ break;
3250
+ case 23:
3251
+ _context34.prev = 23;
3252
+ _context34.t0 = _context34["catch"](17);
3253
+ draftError = _context34.t0;
3254
+ this.logError('updateOrderPayment: 保存支付草稿失败', {
3255
+ paymentIdentity: paymentIdentity,
3256
+ error: _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0)
3257
+ });
3258
+ if (options.submitWhenPaid) {
3259
+ _context34.next = 29;
3260
+ break;
3261
+ }
3262
+ throw _context34.t0;
3263
+ case 29:
3264
+ becamePaid = (previousPayment === null || previousPayment === void 0 ? void 0 : previousPayment.status) !== 'paid' && ((_result$payment = result.payment) === null || _result$payment === void 0 ? void 0 : _result$payment.status) === 'paid';
3265
+ shouldSubmit = Boolean(options.submitWhenPaid && ((_result$payment2 = result.payment) === null || _result$payment2 === void 0 ? void 0 : _result$payment2.status) === 'paid' && (becamePaid || options.forceSubmitIfPaid));
3266
+ if (!shouldSubmit) {
3267
+ _context34.next = 35;
3268
+ break;
3269
+ }
3270
+ _context34.next = 34;
3271
+ return this.syncPaymentsToOrder({
3272
+ payments: result.payments,
3273
+ paymentStatus: this.getPaymentStatusForSync(result.payments),
3274
+ submitWhenPaid: true,
3275
+ smallTicketDataFlag: (_options$smallTicketD2 = options.smallTicketDataFlag) !== null && _options$smallTicketD2 !== void 0 ? _options$smallTicketD2 : 1
3276
+ });
3277
+ case 34:
3278
+ syncResult = _context34.sent;
3279
+ case 35:
3280
+ return _context34.abrupt("return", _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, result), draftResult !== undefined ? {
3281
+ draftResult: draftResult
3282
+ } : {}), draftError !== undefined ? {
3283
+ draftError: draftError
3284
+ } : {}), syncResult !== undefined ? {
3285
+ syncResult: syncResult
3286
+ } : {}));
3287
+ case 36:
3288
+ case "end":
3289
+ return _context34.stop();
3290
+ }
3291
+ }, _callee34, this, [[17, 23]]);
3292
+ }));
3293
+ function updateOrderPayment(_x27, _x28) {
3294
+ return _updateOrderPayment.apply(this, arguments);
3295
+ }
3296
+ return updateOrderPayment;
3297
+ }() /** 删除当前订单中的指定支付项。 */)
2804
3298
  }, {
2805
3299
  key: "deleteOrderPayment",
2806
3300
  value: function deleteOrderPayment(paymentIdentity) {
@@ -2815,6 +3309,31 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2815
3309
  if (!this.store.order) throw new Error('order 模块未初始化');
2816
3310
  return this.store.order.updateVoucherOrderPayments(payments, options);
2817
3311
  }
3312
+ }, {
3313
+ key: "updateVoucherOrderPaymentsAsync",
3314
+ value: function () {
3315
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(payments, options) {
3316
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3317
+ while (1) switch (_context35.prev = _context35.next) {
3318
+ case 0:
3319
+ if (this.store.order) {
3320
+ _context35.next = 2;
3321
+ break;
3322
+ }
3323
+ throw new Error('order 模块未初始化');
3324
+ case 2:
3325
+ return _context35.abrupt("return", this.store.order.updateVoucherOrderPaymentsAsync(payments, options));
3326
+ case 3:
3327
+ case "end":
3328
+ return _context35.stop();
3329
+ }
3330
+ }, _callee35, this);
3331
+ }));
3332
+ function updateVoucherOrderPaymentsAsync(_x29, _x30) {
3333
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3334
+ }
3335
+ return updateVoucherOrderPaymentsAsync;
3336
+ }()
2818
3337
  }, {
2819
3338
  key: "confirmPendingVoucherPayments",
2820
3339
  value: function confirmPendingVoucherPayments() {
@@ -2891,20 +3410,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2891
3410
  }, {
2892
3411
  key: "initWalletData",
2893
3412
  value: function () {
2894
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
2895
- var _params$order_wait_pa, _ref23, _tempOrder$is_price_i;
3413
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3414
+ var _params$order_wait_pa, _ref25, _tempOrder$is_price_i;
2896
3415
  var snapshot, tempOrder, amount, walletBusinessData, result;
2897
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2898
- while (1) switch (_context29.prev = _context29.next) {
3416
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3417
+ while (1) switch (_context36.prev = _context36.next) {
2899
3418
  case 0:
2900
3419
  if (this.store.order) {
2901
- _context29.next = 2;
3420
+ _context36.next = 2;
2902
3421
  break;
2903
3422
  }
2904
3423
  throw new Error('order 模块未初始化');
2905
3424
  case 2:
2906
3425
  if (this.store.payment) {
2907
- _context29.next = 4;
3426
+ _context36.next = 4;
2908
3427
  break;
2909
3428
  }
2910
3429
  throw new Error('payment 模块未初始化');
@@ -2913,10 +3432,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2913
3432
  tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
2914
3433
  amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
2915
3434
  if (!(!tempOrder || !amount)) {
2916
- _context29.next = 9;
3435
+ _context36.next = 9;
2917
3436
  break;
2918
3437
  }
2919
- return _context29.abrupt("return", {
3438
+ return _context36.abrupt("return", {
2920
3439
  walletRecommendList: [],
2921
3440
  userIdentificationCodes: [],
2922
3441
  transformList: [],
@@ -2935,15 +3454,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2935
3454
  },
2936
3455
  products: this.getWalletProductList(),
2937
3456
  order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
2938
- is_price_include_tax: (_ref23 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref23 !== void 0 ? _ref23 : 1
3457
+ is_price_include_tax: (_ref25 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref25 !== void 0 ? _ref25 : 1
2939
3458
  }, snapshot.identity.orderId ? {
2940
3459
  payment_order_id: String(snapshot.identity.orderId)
2941
3460
  } : {});
2942
- _context29.next = 12;
3461
+ _context36.next = 12;
2943
3462
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
2944
3463
  case 12:
2945
- result = _context29.sent;
2946
- _context29.next = 15;
3464
+ result = _context36.sent;
3465
+ _context36.next = 15;
2947
3466
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
2948
3467
  orderId: snapshot.identity.orderId,
2949
3468
  customerId: walletBusinessData.customer_id,
@@ -2955,14 +3474,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2955
3474
  timestamp: Date.now()
2956
3475
  });
2957
3476
  case 15:
2958
- return _context29.abrupt("return", result);
3477
+ return _context36.abrupt("return", result);
2959
3478
  case 16:
2960
3479
  case "end":
2961
- return _context29.stop();
3480
+ return _context36.stop();
2962
3481
  }
2963
- }, _callee29, this);
3482
+ }, _callee36, this);
2964
3483
  }));
2965
- function initWalletData(_x23) {
3484
+ function initWalletData(_x31) {
2966
3485
  return _initWalletData.apply(this, arguments);
2967
3486
  }
2968
3487
  return initWalletData;
@@ -2989,35 +3508,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2989
3508
  }, {
2990
3509
  key: "getPaymentMethodsAsync",
2991
3510
  value: (function () {
2992
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
3511
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
2993
3512
  var response, paymentMethods;
2994
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2995
- while (1) switch (_context30.prev = _context30.next) {
3513
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3514
+ while (1) switch (_context37.prev = _context37.next) {
2996
3515
  case 0:
2997
- _context30.prev = 0;
2998
- _context30.next = 3;
3516
+ _context37.prev = 0;
3517
+ _context37.next = 3;
2999
3518
  return this.request.get('/pay/custom-payment/all', {
3000
3519
  filterPaymentMethods: true
3001
3520
  }, {
3002
3521
  osServer: true
3003
3522
  });
3004
3523
  case 3:
3005
- response = _context30.sent;
3524
+ response = _context37.sent;
3006
3525
  paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
3007
3526
  this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
3008
- return _context30.abrupt("return", this.getPaymentMethods());
3527
+ return _context37.abrupt("return", this.getPaymentMethods());
3009
3528
  case 9:
3010
- _context30.prev = 9;
3011
- _context30.t0 = _context30["catch"](0);
3529
+ _context37.prev = 9;
3530
+ _context37.t0 = _context37["catch"](0);
3012
3531
  this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
3013
- error: _context30.t0 instanceof Error ? _context30.t0.message : String(_context30.t0)
3532
+ error: _context37.t0 instanceof Error ? _context37.t0.message : String(_context37.t0)
3014
3533
  });
3015
- return _context30.abrupt("return", this.getPaymentMethods());
3534
+ return _context37.abrupt("return", this.getPaymentMethods());
3016
3535
  case 13:
3017
3536
  case "end":
3018
- return _context30.stop();
3537
+ return _context37.stop();
3019
3538
  }
3020
- }, _callee30, this, [[0, 9]]);
3539
+ }, _callee37, this, [[0, 9]]);
3021
3540
  }));
3022
3541
  function getPaymentMethodsAsync() {
3023
3542
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -3065,49 +3584,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3065
3584
  }, {
3066
3585
  key: "sendCustomerPayLink",
3067
3586
  value: (function () {
3068
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
3069
- var orderIds, _ref24, _ref25, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
3070
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
3071
- while (1) switch (_context31.prev = _context31.next) {
3587
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3588
+ var orderIds, _ref26, _ref27, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
3589
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3590
+ while (1) switch (_context38.prev = _context38.next) {
3072
3591
  case 0:
3073
3592
  if (this.store.order) {
3074
- _context31.next = 2;
3593
+ _context38.next = 2;
3075
3594
  break;
3076
3595
  }
3077
3596
  throw new Error('order 模块未初始化');
3078
3597
  case 2:
3079
3598
  orderIds = params.order_ids || params.orderIds || [];
3080
3599
  if (!(!orderIds.length || params.submitBeforeSend)) {
3081
- _context31.next = 11;
3600
+ _context38.next = 11;
3082
3601
  break;
3083
3602
  }
3084
- _context31.next = 6;
3603
+ _context38.next = 6;
3085
3604
  return this.submitSalesOrder({
3086
3605
  smallTicketDataFlag: 1
3087
3606
  });
3088
3607
  case 6:
3089
- submitResult = _context31.sent;
3090
- orderId = (_ref24 = (_ref25 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref25 !== void 0 ? _ref25 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref24 !== void 0 ? _ref24 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
3608
+ submitResult = _context38.sent;
3609
+ orderId = (_ref26 = (_ref27 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref27 !== void 0 ? _ref27 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref26 !== void 0 ? _ref26 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
3091
3610
  if (orderId) {
3092
- _context31.next = 10;
3611
+ _context38.next = 10;
3093
3612
  break;
3094
3613
  }
3095
3614
  throw new Error('本地订单提交云端失败,无法发送支付链接');
3096
3615
  case 10:
3097
3616
  orderIds = [orderId];
3098
3617
  case 11:
3099
- return _context31.abrupt("return", this.store.order.sendCustomerPayLink({
3618
+ return _context38.abrupt("return", this.store.order.sendCustomerPayLink({
3100
3619
  emails: params.emails,
3101
3620
  notify_action: params.notify_action,
3102
3621
  order_ids: orderIds
3103
3622
  }));
3104
3623
  case 12:
3105
3624
  case "end":
3106
- return _context31.stop();
3625
+ return _context38.stop();
3107
3626
  }
3108
- }, _callee31, this);
3627
+ }, _callee38, this);
3109
3628
  }));
3110
- function sendCustomerPayLink(_x24) {
3629
+ function sendCustomerPayLink(_x32) {
3111
3630
  return _sendCustomerPayLink.apply(this, arguments);
3112
3631
  }
3113
3632
  return sendCustomerPayLink;
@@ -3120,27 +3639,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3120
3639
  }, {
3121
3640
  key: "calculateProductBookingPrice",
3122
3641
  value: function () {
3123
- var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
3642
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3124
3643
  var _params$customer_id;
3125
3644
  var quotation, customerId, authoritativeProduct, product;
3126
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3127
- while (1) switch (_context32.prev = _context32.next) {
3645
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3646
+ while (1) switch (_context39.prev = _context39.next) {
3128
3647
  case 0:
3129
3648
  quotation = this.store.quotation;
3130
3649
  customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
3131
- _context32.next = 4;
3650
+ _context39.next = 4;
3132
3651
  return this.loadProductForPriceQuery(params, customerId);
3133
3652
  case 4:
3134
- authoritativeProduct = _context32.sent;
3653
+ authoritativeProduct = _context39.sent;
3135
3654
  product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
3136
- _context32.next = 8;
3655
+ _context39.next = 8;
3137
3656
  return this.loadQuotationForPriceQuery({
3138
3657
  quotation: quotation,
3139
3658
  customer_id: customerId,
3140
3659
  channel: params.channel
3141
3660
  });
3142
3661
  case 8:
3143
- return _context32.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3662
+ return _context39.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3144
3663
  product: product,
3145
3664
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
3146
3665
  customer_id: customerId,
@@ -3148,11 +3667,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3148
3667
  })));
3149
3668
  case 9:
3150
3669
  case "end":
3151
- return _context32.stop();
3670
+ return _context39.stop();
3152
3671
  }
3153
- }, _callee32, this);
3672
+ }, _callee39, this);
3154
3673
  }));
3155
- function calculateProductBookingPrice(_x25) {
3674
+ function calculateProductBookingPrice(_x33) {
3156
3675
  return _calculateProductBookingPrice.apply(this, arguments);
3157
3676
  }
3158
3677
  return calculateProductBookingPrice;
@@ -3160,7 +3679,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3160
3679
  }, {
3161
3680
  key: "getQuotationCustomerScopeInfo",
3162
3681
  value: function getQuotationCustomerScopeInfo() {
3163
- var _this12 = this;
3682
+ var _this15 = this;
3164
3683
  var quotation = this.store.quotation;
3165
3684
  if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
3166
3685
  return quotation.getQuotationCustomerScopeInfo();
@@ -3172,7 +3691,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3172
3691
  }).map(function (item) {
3173
3692
  var localSeen = new Set();
3174
3693
  var customers = item.customer.filter(function (customer) {
3175
- var customerId = _this12.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3694
+ var customerId = _this15.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3176
3695
  if (!customerId || localSeen.has(customerId)) return false;
3177
3696
  localSeen.add(customerId);
3178
3697
  if (!customerById.has(customerId)) customerById.set(customerId, customer);
@@ -3222,32 +3741,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3222
3741
  }, {
3223
3742
  key: "calculateProductBookingPrices",
3224
3743
  value: function () {
3225
- var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(paramsList) {
3744
+ var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(paramsList) {
3226
3745
  var _paramsList$0$custome,
3227
3746
  _paramsList$,
3228
- _this13 = this,
3747
+ _this16 = this,
3229
3748
  _paramsList$2;
3230
3749
  var quotation, customerId, productMapsByGroup, groups;
3231
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3232
- while (1) switch (_context34.prev = _context34.next) {
3750
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3751
+ while (1) switch (_context41.prev = _context41.next) {
3233
3752
  case 0:
3234
3753
  if (paramsList.length) {
3235
- _context34.next = 2;
3754
+ _context41.next = 2;
3236
3755
  break;
3237
3756
  }
3238
- return _context34.abrupt("return", []);
3757
+ return _context41.abrupt("return", []);
3239
3758
  case 2:
3240
3759
  quotation = this.store.quotation;
3241
3760
  customerId = (_paramsList$0$custome = (_paramsList$ = paramsList[0]) === null || _paramsList$ === void 0 ? void 0 : _paramsList$.customer_id) !== null && _paramsList$0$custome !== void 0 ? _paramsList$0$custome : this.getCurrentOrderCustomerId();
3242
3761
  productMapsByGroup = new Map();
3243
3762
  groups = new Map();
3244
3763
  paramsList.forEach(function (params) {
3245
- var _this13$otherParams;
3764
+ var _this16$otherParams;
3246
3765
  var product = params.product || {};
3247
- var productId = _this13.getPriceQueryProductId(product);
3766
+ var productId = _this16.getPriceQueryProductId(product);
3248
3767
  if (productId === null) return;
3249
- var schedule = _this13.getPriceQuerySchedule(params);
3250
- var channel = params.channel || ((_this13$otherParams = _this13.otherParams) === null || _this13$otherParams === void 0 ? void 0 : _this13$otherParams.channel);
3768
+ var schedule = _this16.getPriceQuerySchedule(params);
3769
+ var channel = params.channel || ((_this16$otherParams = _this16.otherParams) === null || _this16$otherParams === void 0 ? void 0 : _this16$otherParams.channel);
3251
3770
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3252
3771
  var group = groups.get(groupKey) || {
3253
3772
  ids: new Set(),
@@ -3257,51 +3776,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3257
3776
  group.ids.add(productId);
3258
3777
  groups.set(groupKey, group);
3259
3778
  });
3260
- _context34.next = 9;
3779
+ _context41.next = 9;
3261
3780
  return Promise.all(Array.from(groups.entries()).map( /*#__PURE__*/function () {
3262
- var _ref27 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(_ref26) {
3263
- var _ref28, groupKey, group, productsById;
3264
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3265
- while (1) switch (_context33.prev = _context33.next) {
3781
+ var _ref29 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(_ref28) {
3782
+ var _ref30, groupKey, group, productsById;
3783
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3784
+ while (1) switch (_context40.prev = _context40.next) {
3266
3785
  case 0:
3267
- _ref28 = _slicedToArray(_ref26, 2), groupKey = _ref28[0], group = _ref28[1];
3268
- _context33.next = 3;
3269
- return _this13.loadProductsForPriceQuery({
3786
+ _ref30 = _slicedToArray(_ref28, 2), groupKey = _ref30[0], group = _ref30[1];
3787
+ _context40.next = 3;
3788
+ return _this16.loadProductsForPriceQuery({
3270
3789
  ids: Array.from(group.ids),
3271
3790
  schedule: group.schedule,
3272
3791
  customerId: customerId,
3273
3792
  channel: group.channel
3274
3793
  });
3275
3794
  case 3:
3276
- productsById = _context33.sent;
3795
+ productsById = _context40.sent;
3277
3796
  productMapsByGroup.set(groupKey, productsById);
3278
3797
  case 5:
3279
3798
  case "end":
3280
- return _context33.stop();
3799
+ return _context40.stop();
3281
3800
  }
3282
- }, _callee33);
3801
+ }, _callee40);
3283
3802
  }));
3284
- return function (_x27) {
3285
- return _ref27.apply(this, arguments);
3803
+ return function (_x35) {
3804
+ return _ref29.apply(this, arguments);
3286
3805
  };
3287
3806
  }()));
3288
3807
  case 9:
3289
- _context34.next = 11;
3808
+ _context41.next = 11;
3290
3809
  return this.loadQuotationForPriceQuery({
3291
3810
  quotation: quotation,
3292
3811
  customer_id: customerId,
3293
3812
  channel: (_paramsList$2 = paramsList[0]) === null || _paramsList$2 === void 0 ? void 0 : _paramsList$2.channel
3294
3813
  });
3295
3814
  case 11:
3296
- return _context34.abrupt("return", paramsList.map(function (params) {
3297
- var _this13$otherParams2, _productMapsByGroup$g;
3815
+ return _context41.abrupt("return", paramsList.map(function (params) {
3816
+ var _this16$otherParams2, _productMapsByGroup$g;
3298
3817
  var productInput = params.product || {};
3299
- var productId = _this13.getPriceQueryProductId(productInput);
3300
- var schedule = _this13.getPriceQuerySchedule(params);
3301
- var channel = params.channel || ((_this13$otherParams2 = _this13.otherParams) === null || _this13$otherParams2 === void 0 ? void 0 : _this13$otherParams2.channel);
3818
+ var productId = _this16.getPriceQueryProductId(productInput);
3819
+ var schedule = _this16.getPriceQuerySchedule(params);
3820
+ var channel = params.channel || ((_this16$otherParams2 = _this16.otherParams) === null || _this16$otherParams2 === void 0 ? void 0 : _this16$otherParams2.channel);
3302
3821
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
3303
3822
  var authoritativeProduct = productId === null ? null : ((_productMapsByGroup$g = productMapsByGroup.get(groupKey)) === null || _productMapsByGroup$g === void 0 ? void 0 : _productMapsByGroup$g.get(productId)) || null;
3304
- var product = _this13.mergeProductForPriceQuery(productInput, authoritativeProduct);
3823
+ var product = _this16.mergeProductForPriceQuery(productInput, authoritativeProduct);
3305
3824
  return calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3306
3825
  product: product,
3307
3826
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
@@ -3311,11 +3830,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3311
3830
  }));
3312
3831
  case 12:
3313
3832
  case "end":
3314
- return _context34.stop();
3833
+ return _context41.stop();
3315
3834
  }
3316
- }, _callee34, this);
3835
+ }, _callee41, this);
3317
3836
  }));
3318
- function calculateProductBookingPrices(_x26) {
3837
+ function calculateProductBookingPrices(_x34) {
3319
3838
  return _calculateProductBookingPrices.apply(this, arguments);
3320
3839
  }
3321
3840
  return calculateProductBookingPrices;
@@ -3323,34 +3842,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3323
3842
  }, {
3324
3843
  key: "addProductToOrder",
3325
3844
  value: function () {
3326
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(product, booking) {
3845
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(product, booking) {
3327
3846
  var products;
3328
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3329
- while (1) switch (_context35.prev = _context35.next) {
3847
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3848
+ while (1) switch (_context42.prev = _context42.next) {
3330
3849
  case 0:
3331
- _context35.prev = 0;
3850
+ _context42.prev = 0;
3332
3851
  if (this.store.order) {
3333
- _context35.next = 3;
3852
+ _context42.next = 3;
3334
3853
  break;
3335
3854
  }
3336
3855
  throw new Error('order 模块未初始化');
3337
3856
  case 3:
3338
- _context35.next = 5;
3857
+ _context42.next = 5;
3339
3858
  return this.store.order.addProductToOrder(product, booking);
3340
3859
  case 5:
3341
- products = _context35.sent;
3342
- return _context35.abrupt("return", products);
3860
+ products = _context42.sent;
3861
+ return _context42.abrupt("return", products);
3343
3862
  case 9:
3344
- _context35.prev = 9;
3345
- _context35.t0 = _context35["catch"](0);
3346
- throw _context35.t0;
3863
+ _context42.prev = 9;
3864
+ _context42.t0 = _context42["catch"](0);
3865
+ throw _context42.t0;
3347
3866
  case 12:
3348
3867
  case "end":
3349
- return _context35.stop();
3868
+ return _context42.stop();
3350
3869
  }
3351
- }, _callee35, this, [[0, 9]]);
3870
+ }, _callee42, this, [[0, 9]]);
3352
3871
  }));
3353
- function addProductToOrder(_x28, _x29) {
3872
+ function addProductToOrder(_x36, _x37) {
3354
3873
  return _addProductToOrder.apply(this, arguments);
3355
3874
  }
3356
3875
  return addProductToOrder;
@@ -3358,34 +3877,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3358
3877
  }, {
3359
3878
  key: "updateOrderProduct",
3360
3879
  value: function () {
3361
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3880
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
3362
3881
  var products;
3363
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3364
- while (1) switch (_context36.prev = _context36.next) {
3882
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3883
+ while (1) switch (_context43.prev = _context43.next) {
3365
3884
  case 0:
3366
- _context36.prev = 0;
3885
+ _context43.prev = 0;
3367
3886
  if (this.store.order) {
3368
- _context36.next = 3;
3887
+ _context43.next = 3;
3369
3888
  break;
3370
3889
  }
3371
3890
  throw new Error('order 模块未初始化');
3372
3891
  case 3:
3373
- _context36.next = 5;
3892
+ _context43.next = 5;
3374
3893
  return this.store.order.updateOrderProduct(params);
3375
3894
  case 5:
3376
- products = _context36.sent;
3377
- return _context36.abrupt("return", products);
3895
+ products = _context43.sent;
3896
+ return _context43.abrupt("return", products);
3378
3897
  case 9:
3379
- _context36.prev = 9;
3380
- _context36.t0 = _context36["catch"](0);
3381
- throw _context36.t0;
3898
+ _context43.prev = 9;
3899
+ _context43.t0 = _context43["catch"](0);
3900
+ throw _context43.t0;
3382
3901
  case 12:
3383
3902
  case "end":
3384
- return _context36.stop();
3903
+ return _context43.stop();
3385
3904
  }
3386
- }, _callee36, this, [[0, 9]]);
3905
+ }, _callee43, this, [[0, 9]]);
3387
3906
  }));
3388
- function updateOrderProduct(_x30) {
3907
+ function updateOrderProduct(_x38) {
3389
3908
  return _updateOrderProduct.apply(this, arguments);
3390
3909
  }
3391
3910
  return updateOrderProduct;
@@ -3393,34 +3912,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3393
3912
  }, {
3394
3913
  key: "updateOrderProducts",
3395
3914
  value: function () {
3396
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paramsList) {
3915
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(paramsList) {
3397
3916
  var products;
3398
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3399
- while (1) switch (_context37.prev = _context37.next) {
3917
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3918
+ while (1) switch (_context44.prev = _context44.next) {
3400
3919
  case 0:
3401
- _context37.prev = 0;
3920
+ _context44.prev = 0;
3402
3921
  if (this.store.order) {
3403
- _context37.next = 3;
3922
+ _context44.next = 3;
3404
3923
  break;
3405
3924
  }
3406
3925
  throw new Error('order 模块未初始化');
3407
3926
  case 3:
3408
- _context37.next = 5;
3927
+ _context44.next = 5;
3409
3928
  return this.store.order.updateOrderProducts(paramsList);
3410
3929
  case 5:
3411
- products = _context37.sent;
3412
- return _context37.abrupt("return", products);
3930
+ products = _context44.sent;
3931
+ return _context44.abrupt("return", products);
3413
3932
  case 9:
3414
- _context37.prev = 9;
3415
- _context37.t0 = _context37["catch"](0);
3416
- throw _context37.t0;
3933
+ _context44.prev = 9;
3934
+ _context44.t0 = _context44["catch"](0);
3935
+ throw _context44.t0;
3417
3936
  case 12:
3418
3937
  case "end":
3419
- return _context37.stop();
3938
+ return _context44.stop();
3420
3939
  }
3421
- }, _callee37, this, [[0, 9]]);
3940
+ }, _callee44, this, [[0, 9]]);
3422
3941
  }));
3423
- function updateOrderProducts(_x31) {
3942
+ function updateOrderProducts(_x39) {
3424
3943
  return _updateOrderProducts.apply(this, arguments);
3425
3944
  }
3426
3945
  return updateOrderProducts;
@@ -3428,34 +3947,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3428
3947
  }, {
3429
3948
  key: "updateOrderProductQuantity",
3430
3949
  value: function () {
3431
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3950
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(params) {
3432
3951
  var products;
3433
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3434
- while (1) switch (_context38.prev = _context38.next) {
3952
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3953
+ while (1) switch (_context45.prev = _context45.next) {
3435
3954
  case 0:
3436
- _context38.prev = 0;
3955
+ _context45.prev = 0;
3437
3956
  if (this.store.order) {
3438
- _context38.next = 3;
3957
+ _context45.next = 3;
3439
3958
  break;
3440
3959
  }
3441
3960
  throw new Error('order 模块未初始化');
3442
3961
  case 3:
3443
- _context38.next = 5;
3962
+ _context45.next = 5;
3444
3963
  return this.store.order.updateOrderProductQuantity(params);
3445
3964
  case 5:
3446
- products = _context38.sent;
3447
- return _context38.abrupt("return", products);
3965
+ products = _context45.sent;
3966
+ return _context45.abrupt("return", products);
3448
3967
  case 9:
3449
- _context38.prev = 9;
3450
- _context38.t0 = _context38["catch"](0);
3451
- throw _context38.t0;
3968
+ _context45.prev = 9;
3969
+ _context45.t0 = _context45["catch"](0);
3970
+ throw _context45.t0;
3452
3971
  case 12:
3453
3972
  case "end":
3454
- return _context38.stop();
3973
+ return _context45.stop();
3455
3974
  }
3456
- }, _callee38, this, [[0, 9]]);
3975
+ }, _callee45, this, [[0, 9]]);
3457
3976
  }));
3458
- function updateOrderProductQuantity(_x32) {
3977
+ function updateOrderProductQuantity(_x40) {
3459
3978
  return _updateOrderProductQuantity.apply(this, arguments);
3460
3979
  }
3461
3980
  return updateOrderProductQuantity;
@@ -3478,12 +3997,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3478
3997
  }, {
3479
3998
  key: "setOrderProductLineNote",
3480
3999
  value: (function () {
3481
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(identity, note) {
4000
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(identity, note) {
3482
4001
  var params, products;
3483
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3484
- while (1) switch (_context39.prev = _context39.next) {
4002
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4003
+ while (1) switch (_context46.prev = _context46.next) {
3485
4004
  case 0:
3486
- _context39.prev = 0;
4005
+ _context46.prev = 0;
3487
4006
  params = {
3488
4007
  product_id: identity.product_id,
3489
4008
  product_variant_id: identity.product_variant_id,
@@ -3498,22 +4017,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3498
4017
  params.product_sku = identity.product_sku;
3499
4018
  }
3500
4019
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
3501
- _context39.next = 7;
4020
+ _context46.next = 7;
3502
4021
  return this.updateOrderProduct(params);
3503
4022
  case 7:
3504
- products = _context39.sent;
3505
- return _context39.abrupt("return", products);
4023
+ products = _context46.sent;
4024
+ return _context46.abrupt("return", products);
3506
4025
  case 11:
3507
- _context39.prev = 11;
3508
- _context39.t0 = _context39["catch"](0);
3509
- throw _context39.t0;
4026
+ _context46.prev = 11;
4027
+ _context46.t0 = _context46["catch"](0);
4028
+ throw _context46.t0;
3510
4029
  case 14:
3511
4030
  case "end":
3512
- return _context39.stop();
4031
+ return _context46.stop();
3513
4032
  }
3514
- }, _callee39, this, [[0, 11]]);
4033
+ }, _callee46, this, [[0, 11]]);
3515
4034
  }));
3516
- function setOrderProductLineNote(_x33, _x34) {
4035
+ function setOrderProductLineNote(_x41, _x42) {
3517
4036
  return _setOrderProductLineNote.apply(this, arguments);
3518
4037
  }
3519
4038
  return setOrderProductLineNote;
@@ -3528,32 +4047,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3528
4047
  }, {
3529
4048
  key: "removeProductsFromOrder",
3530
4049
  value: (function () {
3531
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(identities) {
3532
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3533
- while (1) switch (_context40.prev = _context40.next) {
4050
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(identities) {
4051
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4052
+ while (1) switch (_context47.prev = _context47.next) {
3534
4053
  case 0:
3535
- _context40.prev = 0;
4054
+ _context47.prev = 0;
3536
4055
  if (this.store.order) {
3537
- _context40.next = 3;
4056
+ _context47.next = 3;
3538
4057
  break;
3539
4058
  }
3540
4059
  throw new Error('order 模块未初始化');
3541
4060
  case 3:
3542
- _context40.next = 5;
4061
+ _context47.next = 5;
3543
4062
  return this.store.order.removeProductsFromOrder(identities);
3544
4063
  case 5:
3545
- return _context40.abrupt("return", _context40.sent);
4064
+ return _context47.abrupt("return", _context47.sent);
3546
4065
  case 8:
3547
- _context40.prev = 8;
3548
- _context40.t0 = _context40["catch"](0);
3549
- throw _context40.t0;
4066
+ _context47.prev = 8;
4067
+ _context47.t0 = _context47["catch"](0);
4068
+ throw _context47.t0;
3550
4069
  case 11:
3551
4070
  case "end":
3552
- return _context40.stop();
4071
+ return _context47.stop();
3553
4072
  }
3554
- }, _callee40, this, [[0, 8]]);
4073
+ }, _callee47, this, [[0, 8]]);
3555
4074
  }));
3556
- function removeProductsFromOrder(_x35) {
4075
+ function removeProductsFromOrder(_x43) {
3557
4076
  return _removeProductsFromOrder.apply(this, arguments);
3558
4077
  }
3559
4078
  return removeProductsFromOrder;
@@ -3561,18 +4080,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3561
4080
  }, {
3562
4081
  key: "removeProductFromOrder",
3563
4082
  value: function () {
3564
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(identity) {
3565
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3566
- while (1) switch (_context41.prev = _context41.next) {
4083
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(identity) {
4084
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4085
+ while (1) switch (_context48.prev = _context48.next) {
3567
4086
  case 0:
3568
- return _context41.abrupt("return", this.removeProductsFromOrder([identity]));
4087
+ return _context48.abrupt("return", this.removeProductsFromOrder([identity]));
3569
4088
  case 1:
3570
4089
  case "end":
3571
- return _context41.stop();
4090
+ return _context48.stop();
3572
4091
  }
3573
- }, _callee41, this);
4092
+ }, _callee48, this);
3574
4093
  }));
3575
- function removeProductFromOrder(_x36) {
4094
+ function removeProductFromOrder(_x44) {
3576
4095
  return _removeProductFromOrder.apply(this, arguments);
3577
4096
  }
3578
4097
  return removeProductFromOrder;
@@ -3622,23 +4141,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3622
4141
  }, {
3623
4142
  key: "applyPromotion",
3624
4143
  value: (function () {
3625
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3626
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3627
- while (1) switch (_context42.prev = _context42.next) {
4144
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49() {
4145
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4146
+ while (1) switch (_context49.prev = _context49.next) {
3628
4147
  case 0:
3629
4148
  if (this.store.order) {
3630
- _context42.next = 2;
4149
+ _context49.next = 2;
3631
4150
  break;
3632
4151
  }
3633
4152
  throw new Error('order 模块未初始化');
3634
4153
  case 2:
3635
- _context42.next = 4;
4154
+ _context49.next = 4;
3636
4155
  return this.store.order.applyPromotion();
3637
4156
  case 4:
3638
4157
  case "end":
3639
- return _context42.stop();
4158
+ return _context49.stop();
3640
4159
  }
3641
- }, _callee42, this);
4160
+ }, _callee49, this);
3642
4161
  }));
3643
4162
  function applyPromotion() {
3644
4163
  return _applyPromotion.apply(this, arguments);
@@ -3665,18 +4184,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3665
4184
  }, {
3666
4185
  key: "getProductList",
3667
4186
  value: function () {
3668
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3669
- var _this$otherParams21;
4187
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50() {
4188
+ var _this$otherParams25;
3670
4189
  var menu_list_ids, _this$store$products, res;
3671
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3672
- while (1) switch (_context43.prev = _context43.next) {
4190
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4191
+ while (1) switch (_context50.prev = _context50.next) {
3673
4192
  case 0:
3674
4193
  // 可以直接通过配置里的 menu 读取
3675
- menu_list_ids = ((_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 || (_this$otherParams21 = _this$otherParams21.dineInConfig) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21['menu.associated_menus'].map(function (n) {
4194
+ menu_list_ids = ((_this$otherParams25 = this.otherParams) === null || _this$otherParams25 === void 0 || (_this$otherParams25 = _this$otherParams25.dineInConfig) === null || _this$otherParams25 === void 0 ? void 0 : _this$otherParams25['menu.associated_menus'].map(function (n) {
3676
4195
  return Number(n.value);
3677
4196
  })) || [];
3678
- _context43.prev = 1;
3679
- _context43.next = 4;
4197
+ _context50.prev = 1;
4198
+ _context50.next = 4;
3680
4199
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
3681
4200
  menu_list_ids: menu_list_ids,
3682
4201
  cacheId: this.cacheId,
@@ -3684,17 +4203,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3684
4203
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3685
4204
  });
3686
4205
  case 4:
3687
- res = _context43.sent;
3688
- return _context43.abrupt("return", res);
4206
+ res = _context50.sent;
4207
+ return _context50.abrupt("return", res);
3689
4208
  case 8:
3690
- _context43.prev = 8;
3691
- _context43.t0 = _context43["catch"](1);
3692
- throw _context43.t0;
4209
+ _context50.prev = 8;
4210
+ _context50.t0 = _context50["catch"](1);
4211
+ throw _context50.t0;
3693
4212
  case 11:
3694
4213
  case "end":
3695
- return _context43.stop();
4214
+ return _context50.stop();
3696
4215
  }
3697
- }, _callee43, this, [[1, 8]]);
4216
+ }, _callee50, this, [[1, 8]]);
3698
4217
  }));
3699
4218
  function getProductList() {
3700
4219
  return _getProductList.apply(this, arguments);
@@ -3709,33 +4228,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3709
4228
  }, {
3710
4229
  key: "setOtherParams",
3711
4230
  value: function () {
3712
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
3713
- var _this$otherParams22;
3714
- var _ref29,
3715
- _ref29$cover,
4231
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(params) {
4232
+ var _this$otherParams26;
4233
+ var _ref31,
4234
+ _ref31$cover,
3716
4235
  cover,
3717
- _args44 = arguments;
3718
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3719
- while (1) switch (_context44.prev = _context44.next) {
4236
+ _args51 = arguments;
4237
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4238
+ while (1) switch (_context51.prev = _context51.next) {
3720
4239
  case 0:
3721
- _ref29 = _args44.length > 1 && _args44[1] !== undefined ? _args44[1] : {}, _ref29$cover = _ref29.cover, cover = _ref29$cover === void 0 ? false : _ref29$cover;
4240
+ _ref31 = _args51.length > 1 && _args51[1] !== undefined ? _args51[1] : {}, _ref31$cover = _ref31.cover, cover = _ref31$cover === void 0 ? false : _ref31$cover;
3722
4241
  if (cover) {
3723
4242
  this.otherParams = _objectSpread({}, params);
3724
4243
  } else {
3725
4244
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3726
4245
  }
3727
- this.cacheId = (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.cacheId;
3728
- _context44.next = 5;
4246
+ this.cacheId = (_this$otherParams26 = this.otherParams) === null || _this$otherParams26 === void 0 ? void 0 : _this$otherParams26.cacheId;
4247
+ _context51.next = 5;
3729
4248
  return this.syncOtherParamsToSubModules(params, {
3730
4249
  cover: cover
3731
4250
  });
3732
4251
  case 5:
3733
4252
  case "end":
3734
- return _context44.stop();
4253
+ return _context51.stop();
3735
4254
  }
3736
- }, _callee44, this);
4255
+ }, _callee51, this);
3737
4256
  }));
3738
- function setOtherParams(_x37) {
4257
+ function setOtherParams(_x45) {
3739
4258
  return _setOtherParams.apply(this, arguments);
3740
4259
  }
3741
4260
  return setOtherParams;