@pisell/pisellos 2.3.102 → 2.3.103

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.
@@ -137,8 +137,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
137
137
  _defineProperty(_assertThisInitialized(_this), "promotionEvaluator", null);
138
138
  /** 赠品选择 resolver;由 SDK host bridge 注入 */
139
139
  _defineProperty(_assertThisInitialized(_this), "giftSelectResolver", null);
140
- /** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
140
+ /** 促销评估递归保护 flag(写路径同步评估促销,禁止重入) */
141
141
  _defineProperty(_assertThisInitialized(_this), "isApplyingPromotion", false);
142
+ /** 保持旧事件语义:同步事件监听器内触发的订单写入不得递归评估促销。 */
143
+ _defineProperty(_assertThisInitialized(_this), "isEmittingPromotionApplied", false);
142
144
  /** 商品曾应用过客户券卡,客户变更剥离后需强制跑一次 calcDiscount 复位价格 */
143
145
  _defineProperty(_assertThisInitialized(_this), "hasActiveCustomerBoundDiscount", false);
144
146
  /** 最近一次 applyPromotion 的未满足促销提示 */
@@ -991,7 +993,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
991
993
  }
992
994
 
993
995
  /**
994
- * 应用购物车促销:计算 → 差异化赠品 → 写回 tempOrder.products → emit onPromotionApplied。
996
+ * 只执行购物车促销评估与赠品写回,不发布稳定态事件。
995
997
  *
996
998
  * 调用时机:写路径(add/update/remove/clear/setCustomer)末尾自动触发;外部一般无需手动调。
997
999
  *
@@ -999,12 +1001,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
999
1001
  * - 不调用任何公开 CRUD API(如 removeProductFromOrder),全部内部 mutate tempOrder.products,避免事件风暴;
1000
1002
  * - 用 `isApplyingPromotion` 防递归;
1001
1003
  * - 多选项赠品依赖 giftSelectResolver,未注入则跳过且 console.warn;
1002
- * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
1004
+ * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进;
1005
+ * - 返回的 payload 只能在 applyDiscount(商品写路径还需 summary/persist)完成后发布。
1003
1006
  */
1004
1007
  }, {
1005
- key: "applyPromotion",
1008
+ key: "evaluatePromotion",
1006
1009
  value: (function () {
1007
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1010
+ var _evaluatePromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1008
1011
  var _this$promotionEvalua,
1009
1012
  _this$promotionEvalua2,
1010
1013
  _this3 = this;
@@ -1012,38 +1015,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1012
1015
  return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1013
1016
  while (1) switch (_context9.prev = _context9.next) {
1014
1017
  case 0:
1015
- if (!this.isApplyingPromotion) {
1018
+ if (!(this.isApplyingPromotion || this.isEmittingPromotionApplied)) {
1016
1019
  _context9.next = 2;
1017
1020
  break;
1018
1021
  }
1019
- return _context9.abrupt("return");
1022
+ return _context9.abrupt("return", null);
1020
1023
  case 2:
1021
1024
  if (this.promotionEvaluator) {
1022
1025
  _context9.next = 4;
1023
1026
  break;
1024
1027
  }
1025
- return _context9.abrupt("return");
1028
+ return _context9.abrupt("return", null);
1026
1029
  case 4:
1027
1030
  tempOrder = this.store.tempOrder;
1028
1031
  if (tempOrder) {
1029
1032
  _context9.next = 7;
1030
1033
  break;
1031
1034
  }
1032
- return _context9.abrupt("return");
1035
+ return _context9.abrupt("return", null);
1033
1036
  case 7:
1034
1037
  if (!this.isActiveVirtualSettlementOrder(tempOrder)) {
1035
1038
  _context9.next = 10;
1036
1039
  break;
1037
1040
  }
1038
1041
  tempOrder.products = normalizeVirtualSettlementProducts(tempOrder.products);
1039
- return _context9.abrupt("return");
1042
+ return _context9.abrupt("return", null);
1040
1043
  case 10:
1041
1044
  strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
1042
1045
  if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
1043
1046
  _context9.next = 13;
1044
1047
  break;
1045
1048
  }
1046
- return _context9.abrupt("return");
1049
+ return _context9.abrupt("return", null);
1047
1050
  case 13:
1048
1051
  this.isApplyingPromotion = true;
1049
1052
  _context9.prev = 14;
@@ -1283,22 +1286,84 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1283
1286
  }),
1284
1287
  products: tempOrder.products
1285
1288
  };
1286
- this.effectsEmit('onPromotionApplied', payload);
1287
- _context9.next = 81;
1288
- break;
1289
+ return _context9.abrupt("return", payload);
1289
1290
  case 78:
1290
1291
  _context9.prev = 78;
1291
1292
  _context9.t5 = _context9["catch"](14);
1292
1293
  console.error('[OrderModule] applyPromotion failed', _context9.t5);
1293
- case 81:
1294
- _context9.prev = 81;
1294
+ return _context9.abrupt("return", null);
1295
+ case 82:
1296
+ _context9.prev = 82;
1295
1297
  this.isApplyingPromotion = false;
1296
- return _context9.finish(81);
1297
- case 84:
1298
+ return _context9.finish(82);
1299
+ case 85:
1298
1300
  case "end":
1299
1301
  return _context9.stop();
1300
1302
  }
1301
- }, _callee7, this, [[14, 78, 81, 84], [18, 42, 45, 48], [23, 32, 35, 38], [54, 65, 68, 71]]);
1303
+ }, _callee7, this, [[14, 78, 82, 85], [18, 42, 45, 48], [23, 32, 35, 38], [54, 65, 68, 71]]);
1304
+ }));
1305
+ function evaluatePromotion() {
1306
+ return _evaluatePromotion.apply(this, arguments);
1307
+ }
1308
+ return evaluatePromotion;
1309
+ }() /** 发布促销稳定态;products 必须读取折扣计算后的当前数组。 */)
1310
+ }, {
1311
+ key: "emitPromotionApplied",
1312
+ value: function emitPromotionApplied(payload) {
1313
+ var _this$store$tempOrder3;
1314
+ if (!payload) return;
1315
+ var products = ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.products) || payload.products;
1316
+ this.isEmittingPromotionApplied = true;
1317
+ try {
1318
+ void this.effectsEmit('onPromotionApplied', _objectSpread(_objectSpread({}, payload), {}, {
1319
+ products: products
1320
+ }));
1321
+ } finally {
1322
+ // effectsEmit 同步调用监听器后返回 Promise;保持既有的非阻塞事件行为。
1323
+ this.isEmittingPromotionApplied = false;
1324
+ }
1325
+ }
1326
+
1327
+ /** 公开入口:促销、折扣、summary 与持久化完成后发布稳定态事件。 */
1328
+ }, {
1329
+ key: "applyPromotion",
1330
+ value: (function () {
1331
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1332
+ var payload, tempOrder;
1333
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1334
+ while (1) switch (_context10.prev = _context10.next) {
1335
+ case 0:
1336
+ _context10.next = 2;
1337
+ return this.evaluatePromotion();
1338
+ case 2:
1339
+ payload = _context10.sent;
1340
+ if (payload) {
1341
+ _context10.next = 5;
1342
+ break;
1343
+ }
1344
+ return _context10.abrupt("return");
1345
+ case 5:
1346
+ tempOrder = this.store.tempOrder;
1347
+ if (tempOrder) {
1348
+ _context10.next = 8;
1349
+ break;
1350
+ }
1351
+ return _context10.abrupt("return");
1352
+ case 8:
1353
+ this.applyDiscount();
1354
+ this.sanitizeTempOrderProducts(tempOrder);
1355
+ _context10.next = 12;
1356
+ return this.recalculateSummary({
1357
+ createIfMissing: true
1358
+ });
1359
+ case 12:
1360
+ this.persistTempOrder();
1361
+ this.emitPromotionApplied(payload);
1362
+ case 14:
1363
+ case "end":
1364
+ return _context10.stop();
1365
+ }
1366
+ }, _callee8, this);
1302
1367
  }));
1303
1368
  function applyPromotion() {
1304
1369
  return _applyPromotion.apply(this, arguments);
@@ -1497,14 +1562,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1497
1562
  }, {
1498
1563
  key: "saveDraft",
1499
1564
  value: function () {
1500
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1501
- return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1502
- while (1) switch (_context10.prev = _context10.next) {
1565
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1566
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1567
+ while (1) switch (_context11.prev = _context11.next) {
1503
1568
  case 0:
1504
1569
  case "end":
1505
- return _context10.stop();
1570
+ return _context11.stop();
1506
1571
  }
1507
- }, _callee8);
1572
+ }, _callee9);
1508
1573
  }));
1509
1574
  function saveDraft() {
1510
1575
  return _saveDraft.apply(this, arguments);
@@ -1519,16 +1584,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1519
1584
  }, {
1520
1585
  key: "hydrateTempOrderFromLocalRecord",
1521
1586
  value: function () {
1522
- var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
1523
- return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1524
- while (1) switch (_context11.prev = _context11.next) {
1587
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(record) {
1588
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1589
+ while (1) switch (_context12.prev = _context12.next) {
1525
1590
  case 0:
1526
- return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
1591
+ return _context12.abrupt("return", this.hydrateTempOrderFromRecord(record));
1527
1592
  case 1:
1528
1593
  case "end":
1529
- return _context11.stop();
1594
+ return _context12.stop();
1530
1595
  }
1531
- }, _callee9, this);
1596
+ }, _callee10, this);
1532
1597
  }));
1533
1598
  function hydrateTempOrderFromLocalRecord(_x8) {
1534
1599
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
@@ -2548,13 +2613,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2548
2613
  }, {
2549
2614
  key: "replaceTempOrder",
2550
2615
  value: function () {
2551
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
2616
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(tempOrder, options) {
2552
2617
  var nextTempOrder;
2553
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
2554
- while (1) switch (_context12.prev = _context12.next) {
2618
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2619
+ while (1) switch (_context13.prev = _context13.next) {
2555
2620
  case 0:
2556
2621
  if (isTempOrder(tempOrder)) {
2557
- _context12.next = 2;
2622
+ _context13.next = 2;
2558
2623
  break;
2559
2624
  }
2560
2625
  throw new Error('无效的 tempOrder 数据');
@@ -2565,15 +2630,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2565
2630
  });
2566
2631
  this.store.tempOrder = nextTempOrder;
2567
2632
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
2568
- _context12.next = 10;
2633
+ _context13.next = 10;
2569
2634
  break;
2570
2635
  }
2571
- _context12.next = 8;
2636
+ _context13.next = 8;
2572
2637
  return this.recalculateSummary({
2573
2638
  createIfMissing: false
2574
2639
  });
2575
2640
  case 8:
2576
- _context12.next = 11;
2641
+ _context13.next = 11;
2577
2642
  break;
2578
2643
  case 10:
2579
2644
  this.store.summary = createEmptySummary();
@@ -2582,18 +2647,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2582
2647
  this.persistTempOrder();
2583
2648
  }
2584
2649
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
2585
- _context12.next = 15;
2650
+ _context13.next = 15;
2586
2651
  break;
2587
2652
  }
2588
- _context12.next = 15;
2653
+ _context13.next = 15;
2589
2654
  return this.saveDraft();
2590
2655
  case 15:
2591
- return _context12.abrupt("return", nextTempOrder);
2656
+ return _context13.abrupt("return", nextTempOrder);
2592
2657
  case 16:
2593
2658
  case "end":
2594
- return _context12.stop();
2659
+ return _context13.stop();
2595
2660
  }
2596
- }, _callee10, this);
2661
+ }, _callee11, this);
2597
2662
  }));
2598
2663
  function replaceTempOrder(_x9, _x10) {
2599
2664
  return _replaceTempOrder.apply(this, arguments);
@@ -2681,32 +2746,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2681
2746
  }, {
2682
2747
  key: "addNewOrder",
2683
2748
  value: function () {
2684
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
2749
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
2685
2750
  var tempOrder;
2686
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2687
- while (1) switch (_context13.prev = _context13.next) {
2751
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2752
+ while (1) switch (_context14.prev = _context14.next) {
2688
2753
  case 0:
2689
2754
  tempOrder = this.ensureTempOrder();
2690
2755
  this.ensureExternalSaleNumber(tempOrder);
2691
- _context13.next = 4;
2756
+ _context14.next = 4;
2692
2757
  return this.recalculateSummary({
2693
2758
  createIfMissing: true
2694
2759
  });
2695
2760
  case 4:
2696
2761
  this.persistTempOrder();
2697
2762
  if (!this.draftPersistEnabled) {
2698
- _context13.next = 8;
2763
+ _context14.next = 8;
2699
2764
  break;
2700
2765
  }
2701
- _context13.next = 8;
2766
+ _context14.next = 8;
2702
2767
  return this.saveDraft();
2703
2768
  case 8:
2704
- return _context13.abrupt("return", tempOrder);
2769
+ return _context14.abrupt("return", tempOrder);
2705
2770
  case 9:
2706
2771
  case "end":
2707
- return _context13.stop();
2772
+ return _context14.stop();
2708
2773
  }
2709
- }, _callee11, this);
2774
+ }, _callee12, this);
2710
2775
  }));
2711
2776
  function addNewOrder() {
2712
2777
  return _addNewOrder.apply(this, arguments);
@@ -3075,18 +3140,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3075
3140
  }, {
3076
3141
  key: "recalculateSummary",
3077
3142
  value: function () {
3078
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
3143
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(options) {
3079
3144
  var _this$otherParams3, _ref46, _salesSummaryResult$e;
3080
3145
  var tempOrder, originalSnapshot, hasShopDiscountChanged, shouldReuseOriginalSnapshot, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
3081
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
3082
- while (1) switch (_context14.prev = _context14.next) {
3146
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
3147
+ while (1) switch (_context15.prev = _context15.next) {
3083
3148
  case 0:
3084
3149
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
3085
3150
  if (tempOrder) {
3086
- _context14.next = 3;
3151
+ _context15.next = 3;
3087
3152
  break;
3088
3153
  }
3089
- return _context14.abrupt("return", null);
3154
+ return _context15.abrupt("return", null);
3090
3155
  case 3:
3091
3156
  this.sanitizeTempOrderProducts(tempOrder);
3092
3157
  originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
@@ -3094,10 +3159,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3094
3159
  shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
3095
3160
  snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
3096
3161
  if (!snapshotSummary) {
3097
- _context14.next = 10;
3162
+ _context15.next = 10;
3098
3163
  break;
3099
3164
  }
3100
- return _context14.abrupt("return", snapshotSummary);
3165
+ return _context15.abrupt("return", snapshotSummary);
3101
3166
  case 10:
3102
3167
  shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
3103
3168
  summaryProducts = shouldFullRecalculateFromSnapshot ? cloneDeep(tempOrder.products || []) : tempOrder.products;
@@ -3109,7 +3174,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3109
3174
  totalRefundAmount = existedSummary.total_refund_amount || '0.00';
3110
3175
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
3111
3176
  if (salesSummary) {
3112
- _context14.next = 26;
3177
+ _context15.next = 26;
3113
3178
  break;
3114
3179
  }
3115
3180
  emptyBaseSummary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), existedSummary), {}, {
@@ -3135,9 +3200,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3135
3200
  previousSummary: existedSummary,
3136
3201
  summary: emptySummary
3137
3202
  });
3138
- return _context14.abrupt("return", this.store.summary);
3203
+ return _context15.abrupt("return", this.store.summary);
3139
3204
  case 26:
3140
- _context14.next = 28;
3205
+ _context15.next = 28;
3141
3206
  return salesSummary.getSummary(_objectSpread({
3142
3207
  products: summaryProducts,
3143
3208
  isPriceIncludeTax: tempOrder.is_price_include_tax,
@@ -3147,7 +3212,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3147
3212
  channel: this.otherParams.channel
3148
3213
  } : {}));
3149
3214
  case 28:
3150
- salesSummaryResult = _context14.sent;
3215
+ salesSummaryResult = _context15.sent;
3151
3216
  if (shouldFullRecalculateFromSnapshot) {
3152
3217
  tempOrder.products = summaryProducts;
3153
3218
  }
@@ -3192,12 +3257,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3192
3257
  previousSummary: existedSummary,
3193
3258
  summary: summary
3194
3259
  });
3195
- return _context14.abrupt("return", this.store.summary);
3260
+ return _context15.abrupt("return", this.store.summary);
3196
3261
  case 46:
3197
3262
  case "end":
3198
- return _context14.stop();
3263
+ return _context15.stop();
3199
3264
  }
3200
- }, _callee12, this);
3265
+ }, _callee13, this);
3201
3266
  }));
3202
3267
  function recalculateSummary(_x11) {
3203
3268
  return _recalculateSummary.apply(this, arguments);
@@ -3207,30 +3272,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3207
3272
  }, {
3208
3273
  key: "getOrderSummary",
3209
3274
  value: function () {
3210
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
3275
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
3211
3276
  var summary;
3212
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
3213
- while (1) switch (_context15.prev = _context15.next) {
3277
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
3278
+ while (1) switch (_context16.prev = _context16.next) {
3214
3279
  case 0:
3215
- _context15.next = 2;
3280
+ _context16.next = 2;
3216
3281
  return this.recalculateSummary({
3217
3282
  createIfMissing: true
3218
3283
  });
3219
3284
  case 2:
3220
- summary = _context15.sent;
3285
+ summary = _context16.sent;
3221
3286
  if (summary) {
3222
- _context15.next = 5;
3287
+ _context16.next = 5;
3223
3288
  break;
3224
3289
  }
3225
- return _context15.abrupt("return", createEmptySummary());
3290
+ return _context16.abrupt("return", createEmptySummary());
3226
3291
  case 5:
3227
3292
  this.persistTempOrder();
3228
- return _context15.abrupt("return", summary);
3293
+ return _context16.abrupt("return", summary);
3229
3294
  case 7:
3230
3295
  case "end":
3231
- return _context15.stop();
3296
+ return _context16.stop();
3232
3297
  }
3233
- }, _callee13, this);
3298
+ }, _callee14, this);
3234
3299
  }));
3235
3300
  function getOrderSummary() {
3236
3301
  return _getOrderSummary.apply(this, arguments);
@@ -3254,21 +3319,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3254
3319
  }, {
3255
3320
  key: "syncTempOrderNoteToRemote",
3256
3321
  value: function () {
3257
- var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
3258
- return _regeneratorRuntime().wrap(function _callee14$(_context16) {
3259
- while (1) switch (_context16.prev = _context16.next) {
3322
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderId, note) {
3323
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3324
+ while (1) switch (_context17.prev = _context17.next) {
3260
3325
  case 0:
3261
- _context16.next = 2;
3326
+ _context17.next = 2;
3262
3327
  return this.request.put("/order/order/".concat(orderId, "/note"), {
3263
3328
  note: note
3264
3329
  });
3265
3330
  case 2:
3266
- return _context16.abrupt("return", note);
3331
+ return _context17.abrupt("return", note);
3267
3332
  case 3:
3268
3333
  case "end":
3269
- return _context16.stop();
3334
+ return _context17.stop();
3270
3335
  }
3271
- }, _callee14, this);
3336
+ }, _callee15, this);
3272
3337
  }));
3273
3338
  function syncTempOrderNoteToRemote(_x12, _x13) {
3274
3339
  return _syncTempOrderNoteToRemote.apply(this, arguments);
@@ -3278,8 +3343,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3278
3343
  }, {
3279
3344
  key: "getTempOrderNote",
3280
3345
  value: function getTempOrderNote() {
3281
- var _this$store$tempOrder3;
3282
- return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
3346
+ var _this$store$tempOrder4;
3347
+ return ((_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.note) || '';
3283
3348
  }
3284
3349
  }, {
3285
3350
  key: "ensureSalesNotesRuntimeState",
@@ -3471,20 +3536,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3471
3536
  }, {
3472
3537
  key: "setSalesNote",
3473
3538
  value: function () {
3474
- var _setSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(input) {
3539
+ var _setSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(input) {
3475
3540
  var tempOrder, note;
3476
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3477
- while (1) switch (_context17.prev = _context17.next) {
3541
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3542
+ while (1) switch (_context18.prev = _context18.next) {
3478
3543
  case 0:
3479
3544
  tempOrder = this.ensureTempOrder();
3480
3545
  note = this.setSalesNoteOnTempOrder(tempOrder, input);
3481
3546
  this.notifyTempOrderChanged();
3482
- return _context17.abrupt("return", cloneDeep(note));
3547
+ return _context18.abrupt("return", cloneDeep(note));
3483
3548
  case 4:
3484
3549
  case "end":
3485
- return _context17.stop();
3550
+ return _context18.stop();
3486
3551
  }
3487
- }, _callee15, this);
3552
+ }, _callee16, this);
3488
3553
  }));
3489
3554
  function setSalesNote(_x14) {
3490
3555
  return _setSalesNote.apply(this, arguments);
@@ -3494,10 +3559,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3494
3559
  }, {
3495
3560
  key: "removeSalesNote",
3496
3561
  value: function () {
3497
- var _removeSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(uuid) {
3562
+ var _removeSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(uuid) {
3498
3563
  var tempOrder, normalizedUuid, notes, nextNotes, state;
3499
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3500
- while (1) switch (_context18.prev = _context18.next) {
3564
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3565
+ while (1) switch (_context19.prev = _context19.next) {
3501
3566
  case 0:
3502
3567
  tempOrder = this.ensureTempOrder();
3503
3568
  this.ensureSalesNotesLoadedForMutation(tempOrder);
@@ -3507,10 +3572,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3507
3572
  return note.uuid !== normalizedUuid;
3508
3573
  });
3509
3574
  if (!(nextNotes.length === notes.length)) {
3510
- _context18.next = 7;
3575
+ _context19.next = 7;
3511
3576
  break;
3512
3577
  }
3513
- return _context18.abrupt("return");
3578
+ return _context19.abrupt("return");
3514
3579
  case 7:
3515
3580
  tempOrder.notes = nextNotes;
3516
3581
  state = this.ensureSalesNotesRuntimeState(tempOrder);
@@ -3518,9 +3583,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3518
3583
  this.notifyTempOrderChanged();
3519
3584
  case 11:
3520
3585
  case "end":
3521
- return _context18.stop();
3586
+ return _context19.stop();
3522
3587
  }
3523
- }, _callee16, this);
3588
+ }, _callee17, this);
3524
3589
  }));
3525
3590
  function removeSalesNote(_x15) {
3526
3591
  return _removeSalesNote.apply(this, arguments);
@@ -3530,10 +3595,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3530
3595
  }, {
3531
3596
  key: "clearSalesNotes",
3532
3597
  value: function () {
3533
- var _clearSalesNotes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
3598
+ var _clearSalesNotes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
3534
3599
  var tempOrder, state;
3535
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3536
- while (1) switch (_context19.prev = _context19.next) {
3600
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3601
+ while (1) switch (_context20.prev = _context20.next) {
3537
3602
  case 0:
3538
3603
  tempOrder = this.ensureTempOrder();
3539
3604
  tempOrder.notes = [];
@@ -3543,9 +3608,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3543
3608
  this.notifyTempOrderChanged();
3544
3609
  case 6:
3545
3610
  case "end":
3546
- return _context19.stop();
3611
+ return _context20.stop();
3547
3612
  }
3548
- }, _callee17, this);
3613
+ }, _callee18, this);
3549
3614
  }));
3550
3615
  function clearSalesNotes() {
3551
3616
  return _clearSalesNotes.apply(this, arguments);
@@ -3831,8 +3896,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3831
3896
  }, {
3832
3897
  key: "getOrderCustomerSnapshot",
3833
3898
  value: function getOrderCustomerSnapshot() {
3834
- var _this$store$tempOrder4;
3835
- var snapshot = (_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 || (_this$store$tempOrder4 = _this$store$tempOrder4._extend) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.customerSnapshot;
3899
+ var _this$store$tempOrder5;
3900
+ var snapshot = (_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 || (_this$store$tempOrder5 = _this$store$tempOrder5._extend) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.customerSnapshot;
3836
3901
  return snapshot ? cloneDeep(snapshot) : null;
3837
3902
  }
3838
3903
  }, {
@@ -3916,32 +3981,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3916
3981
  }, {
3917
3982
  key: "addOrderPaymentAsync",
3918
3983
  value: (function () {
3919
- var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(payment) {
3984
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(payment) {
3920
3985
  var hasPaymentNumber, devicePrefix;
3921
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3922
- while (1) switch (_context20.prev = _context20.next) {
3986
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3987
+ while (1) switch (_context21.prev = _context21.next) {
3923
3988
  case 0:
3924
3989
  hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3925
3990
  if (!hasPaymentNumber) {
3926
- _context20.next = 5;
3991
+ _context21.next = 5;
3927
3992
  break;
3928
3993
  }
3929
- _context20.t0 = 'LOCAL';
3930
- _context20.next = 8;
3994
+ _context21.t0 = 'LOCAL';
3995
+ _context21.next = 8;
3931
3996
  break;
3932
3997
  case 5:
3933
- _context20.next = 7;
3998
+ _context21.next = 7;
3934
3999
  return this.getPaymentNumberDevicePrefixAsync();
3935
4000
  case 7:
3936
- _context20.t0 = _context20.sent;
4001
+ _context21.t0 = _context21.sent;
3937
4002
  case 8:
3938
- devicePrefix = _context20.t0;
3939
- return _context20.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
4003
+ devicePrefix = _context21.t0;
4004
+ return _context21.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3940
4005
  case 10:
3941
4006
  case "end":
3942
- return _context20.stop();
4007
+ return _context21.stop();
3943
4008
  }
3944
- }, _callee18, this);
4009
+ }, _callee19, this);
3945
4010
  }));
3946
4011
  function addOrderPaymentAsync(_x16) {
3947
4012
  return _addOrderPaymentAsync.apply(this, arguments);
@@ -3983,7 +4048,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3983
4048
  }, {
3984
4049
  key: "updateOrderPayment",
3985
4050
  value: (function () {
3986
- var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(paymentIdentity, updates) {
4051
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paymentIdentity, updates) {
3987
4052
  var options,
3988
4053
  tempOrder,
3989
4054
  identity,
@@ -3992,17 +4057,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3992
4057
  updatedPayment,
3993
4058
  summary,
3994
4059
  payments,
3995
- _args21 = arguments;
3996
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3997
- while (1) switch (_context21.prev = _context21.next) {
4060
+ _args22 = arguments;
4061
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4062
+ while (1) switch (_context22.prev = _context22.next) {
3998
4063
  case 0:
3999
- options = _args21.length > 2 && _args21[2] !== undefined ? _args21[2] : {};
4064
+ options = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
4000
4065
  tempOrder = this.ensureTempOrder();
4001
4066
  identity = String(paymentIdentity);
4002
4067
  matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
4003
4068
  matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
4004
4069
  if (matchedPayment) {
4005
- _context21.next = 7;
4070
+ _context22.next = 7;
4006
4071
  break;
4007
4072
  }
4008
4073
  throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
@@ -4017,15 +4082,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4017
4082
  return nextPayment;
4018
4083
  });
4019
4084
  this.persistTempOrder();
4020
- _context21.next = 12;
4085
+ _context22.next = 12;
4021
4086
  return this.recalculateSummary({
4022
4087
  createIfMissing: true
4023
4088
  });
4024
4089
  case 12:
4025
- summary = _context21.sent;
4090
+ summary = _context22.sent;
4026
4091
  this.persistTempOrder();
4027
4092
  payments = tempOrder.payments;
4028
- return _context21.abrupt("return", {
4093
+ return _context22.abrupt("return", {
4029
4094
  updated: true,
4030
4095
  payment: payments[matchedPayment.index] || updatedPayment,
4031
4096
  payments: payments,
@@ -4033,9 +4098,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4033
4098
  });
4034
4099
  case 16:
4035
4100
  case "end":
4036
- return _context21.stop();
4101
+ return _context22.stop();
4037
4102
  }
4038
- }, _callee19, this);
4103
+ }, _callee20, this);
4039
4104
  }));
4040
4105
  function updateOrderPayment(_x17, _x18) {
4041
4106
  return _updateOrderPayment.apply(this, arguments);
@@ -4233,36 +4298,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4233
4298
  }, {
4234
4299
  key: "updateVoucherOrderPaymentsAsync",
4235
4300
  value: function () {
4236
- var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(payments, options) {
4301
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(payments, options) {
4237
4302
  var needsPaymentNumber, devicePrefix;
4238
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4239
- while (1) switch (_context22.prev = _context22.next) {
4303
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4304
+ while (1) switch (_context23.prev = _context23.next) {
4240
4305
  case 0:
4241
4306
  needsPaymentNumber = (payments || []).some(function (payment) {
4242
4307
  return String(payment.payment_number || '').trim() === '';
4243
4308
  });
4244
4309
  if (!needsPaymentNumber) {
4245
- _context22.next = 7;
4310
+ _context23.next = 7;
4246
4311
  break;
4247
4312
  }
4248
- _context22.next = 4;
4313
+ _context23.next = 4;
4249
4314
  return this.getPaymentNumberDevicePrefixAsync();
4250
4315
  case 4:
4251
- _context22.t0 = _context22.sent;
4252
- _context22.next = 8;
4316
+ _context23.t0 = _context23.sent;
4317
+ _context23.next = 8;
4253
4318
  break;
4254
4319
  case 7:
4255
- _context22.t0 = 'LOCAL';
4320
+ _context23.t0 = 'LOCAL';
4256
4321
  case 8:
4257
- devicePrefix = _context22.t0;
4258
- return _context22.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
4322
+ devicePrefix = _context23.t0;
4323
+ return _context23.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
4259
4324
  devicePrefix: devicePrefix
4260
4325
  })));
4261
4326
  case 10:
4262
4327
  case "end":
4263
- return _context22.stop();
4328
+ return _context23.stop();
4264
4329
  }
4265
- }, _callee20, this);
4330
+ }, _callee21, this);
4266
4331
  }));
4267
4332
  function updateVoucherOrderPaymentsAsync(_x19, _x20) {
4268
4333
  return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
@@ -4419,43 +4484,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4419
4484
  }, {
4420
4485
  key: "finalizeProductOrderMutation",
4421
4486
  value: function () {
4422
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(tempOrder, options) {
4423
- var isVirtualSettlement;
4424
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4425
- while (1) switch (_context23.prev = _context23.next) {
4487
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(tempOrder, options) {
4488
+ var isVirtualSettlement, promotionPayload;
4489
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4490
+ while (1) switch (_context24.prev = _context24.next) {
4426
4491
  case 0:
4427
4492
  this.syncTempOrderHolderFromBookings(tempOrder);
4428
4493
  this.prepareVirtualSettlementTempOrder(tempOrder);
4429
4494
  isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
4430
4495
  if (!(!(options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) && !isVirtualSettlement)) {
4431
- _context23.next = 6;
4496
+ _context24.next = 6;
4432
4497
  break;
4433
4498
  }
4434
- _context23.next = 6;
4499
+ _context24.next = 6;
4435
4500
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
4436
4501
  case 6:
4437
4502
  if (!(!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement)) {
4438
- _context23.next = 9;
4503
+ _context24.next = 12;
4439
4504
  break;
4440
4505
  }
4441
- _context23.next = 9;
4442
- return this.applyPromotion();
4506
+ _context24.next = 9;
4507
+ return this.evaluatePromotion();
4443
4508
  case 9:
4509
+ _context24.t0 = _context24.sent;
4510
+ _context24.next = 13;
4511
+ break;
4512
+ case 12:
4513
+ _context24.t0 = null;
4514
+ case 13:
4515
+ promotionPayload = _context24.t0;
4444
4516
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement) {
4445
4517
  this.applyDiscount();
4446
4518
  }
4447
4519
  this.sanitizeTempOrderProducts(tempOrder);
4448
- _context23.next = 13;
4520
+ _context24.next = 18;
4449
4521
  return this.recalculateSummary({
4450
4522
  createIfMissing: true
4451
4523
  });
4452
- case 13:
4524
+ case 18:
4453
4525
  this.persistTempOrder();
4454
- case 14:
4526
+ this.emitPromotionApplied(promotionPayload);
4527
+ case 20:
4455
4528
  case "end":
4456
- return _context23.stop();
4529
+ return _context24.stop();
4457
4530
  }
4458
- }, _callee21, this);
4531
+ }, _callee22, this);
4459
4532
  }));
4460
4533
  function finalizeProductOrderMutation(_x21, _x22) {
4461
4534
  return _finalizeProductOrderMutation.apply(this, arguments);
@@ -4604,6 +4677,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4604
4677
  return commitProductLine(shouldMerge);
4605
4678
  }
4606
4679
 
4680
+ /**
4681
+ * booking 数量拆行时,若 Holder 数量与拆行数严格一致,则按下标分配。
4682
+ * 数量不一致时保持旧数据,避免猜测 Holder 与商品份数的对应关系。
4683
+ */
4684
+ }, {
4685
+ key: "createSplitBookingLine",
4686
+ value: function createSplitBookingLine(product, booking, index, splitCount) {
4687
+ var _booking$metadata6, _ref62, _ref63, _bookingHolder$form_r, _booking$metadata7, _product$metadata10, _bookingHolder$name, _singleBooking$metada;
4688
+ var singleLine = cloneDeep(product);
4689
+ singleLine.num = 1;
4690
+ delete singleLine.product_quantity;
4691
+ var singleBooking = cloneDeep(booking);
4692
+ var bookingHolder = booking !== null && booking !== void 0 && booking.holder && _typeof(booking.holder) === 'object' ? booking.holder : null;
4693
+ var metadataHolder = booking !== null && booking !== void 0 && (_booking$metadata6 = booking.metadata) !== null && _booking$metadata6 !== void 0 && _booking$metadata6.holder && _typeof(booking.metadata.holder) === 'object' ? booking.metadata.holder : null;
4694
+ var rawHolderIds = (_ref62 = (_ref63 = (_bookingHolder$form_r = bookingHolder === null || bookingHolder === void 0 ? void 0 : bookingHolder.form_record) !== null && _bookingHolder$form_r !== void 0 ? _bookingHolder$form_r : booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.holder_id) !== null && _ref63 !== void 0 ? _ref63 : metadataHolder === null || metadataHolder === void 0 ? void 0 : metadataHolder.form_record) !== null && _ref62 !== void 0 ? _ref62 : product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.holder_id;
4695
+ var holderIds = (Array.isArray(rawHolderIds) ? rawHolderIds : [rawHolderIds]).map(function (holderId) {
4696
+ return holderId && _typeof(holderId) === 'object' ? holderId.form_record_id : holderId;
4697
+ }).filter(function (holderId) {
4698
+ return holderId !== undefined && holderId !== null && holderId !== '';
4699
+ });
4700
+ if (holderIds.length !== splitCount) {
4701
+ return {
4702
+ product: singleLine,
4703
+ booking: singleBooking
4704
+ };
4705
+ }
4706
+ var holderId = holderIds[index];
4707
+ var rawHolderName = (_bookingHolder$name = bookingHolder === null || bookingHolder === void 0 ? void 0 : bookingHolder.name) !== null && _bookingHolder$name !== void 0 ? _bookingHolder$name : metadataHolder === null || metadataHolder === void 0 ? void 0 : metadataHolder.name;
4708
+ var holderNames = Array.isArray(rawHolderName) ? rawHolderName.map(function (name) {
4709
+ return String(name || '').trim();
4710
+ }) : typeof rawHolderName === 'string' ? rawHolderName.split(',').map(function (name) {
4711
+ return name.trim();
4712
+ }) : [];
4713
+ var holderName = holderNames.length === splitCount ? holderNames[index] : undefined;
4714
+ var splitHolder = function splitHolder(holder) {
4715
+ return _objectSpread(_objectSpread({}, holder), {}, {
4716
+ form_record: [holderId]
4717
+ }, holderName ? {
4718
+ name: holderName
4719
+ } : Object.prototype.hasOwnProperty.call(holder, 'name') ? {
4720
+ name: undefined
4721
+ } : {});
4722
+ };
4723
+ singleLine.metadata = _objectSpread(_objectSpread({}, singleLine.metadata || {}), {}, {
4724
+ holder_id: [holderId]
4725
+ });
4726
+ if (singleLine._extend && _typeof(singleLine._extend) === 'object') {
4727
+ singleLine._extend = _objectSpread(_objectSpread({}, singleLine._extend), {}, {
4728
+ holder_id: [holderId]
4729
+ });
4730
+ }
4731
+ if (singleBooking.holder && _typeof(singleBooking.holder) === 'object') {
4732
+ singleBooking.holder = splitHolder(singleBooking.holder);
4733
+ }
4734
+ singleBooking.metadata = _objectSpread(_objectSpread({}, singleBooking.metadata || {}), {}, {
4735
+ holder_id: [holderId]
4736
+ }, (_singleBooking$metada = singleBooking.metadata) !== null && _singleBooking$metada !== void 0 && _singleBooking$metada.holder && _typeof(singleBooking.metadata.holder) === 'object' ? {
4737
+ holder: splitHolder(singleBooking.metadata.holder)
4738
+ } : {});
4739
+ if (Object.prototype.hasOwnProperty.call(singleBooking, 'holder_id')) {
4740
+ singleBooking.holder_id = [holderId];
4741
+ }
4742
+ return {
4743
+ product: singleLine,
4744
+ booking: singleBooking
4745
+ };
4746
+ }
4747
+
4607
4748
  /**
4608
4749
  * 添加商品行。带 booking 时强制独立行;num>1 时拆成多条 num=1 的 product+booking(对齐 BookingByStep / ticketBooking addService)。
4609
4750
  *
@@ -4614,11 +4755,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4614
4755
  }, {
4615
4756
  key: "addProductToOrder",
4616
4757
  value: (function () {
4617
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(product, booking, options) {
4758
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(product, booking, options) {
4618
4759
  var _this30 = this;
4619
- var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref62, _productRecord$num, productRecord, splitCount, i, singleLine, singleBooking, committedProduct, _committedProduct, _committedProduct2;
4620
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4621
- while (1) switch (_context24.prev = _context24.next) {
4760
+ var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref64, _productRecord$num, productRecord, splitCount, i, splitLine, committedProduct, _committedProduct, _committedProduct2;
4761
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4762
+ while (1) switch (_context25.prev = _context25.next) {
4622
4763
  case 0:
4623
4764
  tempOrder = this.ensureTempOrder();
4624
4765
  salesNoteDrafts = ((options === null || options === void 0 ? void 0 : options.salesNotes) || []).map(function (draft) {
@@ -4668,100 +4809,97 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4668
4809
  return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
4669
4810
  }) : -1;
4670
4811
  insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
4671
- _context24.prev = 8;
4812
+ _context25.prev = 8;
4672
4813
  if (!booking) {
4673
- _context24.next = 36;
4814
+ _context25.next = 33;
4674
4815
  break;
4675
4816
  }
4676
4817
  productRecord = product;
4677
- splitCount = getSafeProductNum((_ref62 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
4818
+ splitCount = getSafeProductNum((_ref64 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref64 !== void 0 ? _ref64 : 1);
4678
4819
  if (!(splitCount > 1)) {
4679
- _context24.next = 30;
4820
+ _context25.next = 27;
4680
4821
  break;
4681
4822
  }
4682
4823
  i = 0;
4683
4824
  case 14:
4684
4825
  if (!(i < splitCount)) {
4685
- _context24.next = 28;
4826
+ _context25.next = 25;
4686
4827
  break;
4687
4828
  }
4688
- singleLine = cloneDeep(productRecord);
4689
- singleBooking = cloneDeep(booking);
4690
- singleLine.num = 1;
4691
- delete singleLine.product_quantity;
4829
+ splitLine = this.createSplitBookingLine(productRecord, booking, i, splitCount);
4692
4830
  if (i > 0) {
4693
- delete singleLine.unique_identification_number;
4694
- delete singleLine.identity_key;
4695
- if (singleLine.metadata) {
4696
- singleLine.metadata = _objectSpread({}, singleLine.metadata);
4697
- delete singleLine.metadata.unique_identification_number;
4698
- delete singleLine.metadata.identity_key;
4831
+ delete splitLine.product.unique_identification_number;
4832
+ delete splitLine.product.identity_key;
4833
+ if (splitLine.product.metadata) {
4834
+ splitLine.product.metadata = _objectSpread({}, splitLine.product.metadata);
4835
+ delete splitLine.product.metadata.unique_identification_number;
4836
+ delete splitLine.product.metadata.identity_key;
4699
4837
  }
4700
- delete singleBooking.booking_uid;
4701
- if (singleBooking.metadata) {
4702
- singleBooking.metadata = _objectSpread({}, singleBooking.metadata);
4703
- delete singleBooking.metadata.unique_identification_number;
4838
+ delete splitLine.booking.booking_uid;
4839
+ if (splitLine.booking.metadata) {
4840
+ splitLine.booking.metadata = _objectSpread({}, splitLine.booking.metadata);
4841
+ delete splitLine.booking.metadata.unique_identification_number;
4704
4842
  }
4705
4843
  }
4706
- _context24.next = 22;
4707
- return this.appendProductLineToTempOrder(tempOrder, singleLine, singleBooking, {
4844
+ _context25.next = 19;
4845
+ return this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
4708
4846
  insertAtIndex: insertAtIndex,
4709
4847
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4710
4848
  });
4711
- case 22:
4712
- committedProduct = _context24.sent;
4849
+ case 19:
4850
+ committedProduct = _context25.sent;
4713
4851
  attachSalesNoteDrafts(committedProduct);
4714
4852
  if (insertAtIndex !== undefined) insertAtIndex += 1;
4715
- case 25:
4853
+ case 22:
4716
4854
  i += 1;
4717
- _context24.next = 14;
4855
+ _context25.next = 14;
4718
4856
  break;
4719
- case 28:
4720
- _context24.next = 34;
4857
+ case 25:
4858
+ _context25.next = 31;
4721
4859
  break;
4722
- case 30:
4723
- _context24.next = 32;
4860
+ case 27:
4861
+ _context25.next = 29;
4724
4862
  return this.appendProductLineToTempOrder(tempOrder, product, cloneDeep(booking), {
4725
4863
  insertAtIndex: insertAtIndex,
4726
4864
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4727
4865
  });
4728
- case 32:
4729
- _committedProduct = _context24.sent;
4866
+ case 29:
4867
+ _committedProduct = _context25.sent;
4730
4868
  attachSalesNoteDrafts(_committedProduct);
4731
- case 34:
4732
- _context24.next = 40;
4869
+ case 31:
4870
+ _context25.next = 37;
4733
4871
  break;
4734
- case 36:
4735
- _context24.next = 38;
4872
+ case 33:
4873
+ _context25.next = 35;
4736
4874
  return this.appendProductLineToTempOrder(tempOrder, product, undefined, {
4737
4875
  insertAtIndex: insertAtIndex,
4738
4876
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4739
4877
  });
4740
- case 38:
4741
- _committedProduct2 = _context24.sent;
4878
+ case 35:
4879
+ _committedProduct2 = _context25.sent;
4742
4880
  attachSalesNoteDrafts(_committedProduct2);
4743
- case 40:
4744
- _context24.next = 46;
4881
+ case 37:
4882
+ _context25.next = 43;
4745
4883
  break;
4746
- case 42:
4747
- _context24.prev = 42;
4748
- _context24.t0 = _context24["catch"](8);
4884
+ case 39:
4885
+ _context25.prev = 39;
4886
+ _context25.t0 = _context25["catch"](8);
4749
4887
  rollbackProductAndNotesMutation();
4750
- throw _context24.t0;
4751
- case 46:
4752
- _context24.next = 48;
4888
+ throw _context25.t0;
4889
+ case 43:
4890
+ _context25.next = 45;
4753
4891
  return this.finalizeProductOrderMutation(tempOrder);
4754
- case 48:
4892
+ case 45:
4755
4893
  this.logInfo('addProductToOrder success', {
4756
4894
  product_id: product.product_id,
4757
4895
  with_booking: !!booking
4758
4896
  });
4759
- return _context24.abrupt("return", tempOrder.products);
4760
- case 50:
4897
+ return _context25.abrupt("return", tempOrder.products);
4898
+ case 47:
4761
4899
  case "end":
4762
- return _context24.stop();
4900
+ return _context25.stop();
4763
4901
  }
4764
- }, _callee22, this, [[8, 42]]);
4902
+ }, _callee23, this, [[8, 39]]);
4765
4903
  }));
4766
4904
  function addProductToOrder(_x23, _x24, _x25) {
4767
4905
  return _addProductToOrder.apply(this, arguments);
@@ -4781,101 +4919,99 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4781
4919
  }, {
4782
4920
  key: "addProductsToOrder",
4783
4921
  value: (function () {
4784
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(items, options) {
4785
- var tempOrder, _iterator20, _step20, item, product, booking, _ref63, _productRecord$num2, productRecord, splitCount, i, singleLine, _appendResult, appendResult;
4786
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4787
- while (1) switch (_context25.prev = _context25.next) {
4922
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(items, options) {
4923
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref65, _productRecord$num2, productRecord, splitCount, i, splitLine, _appendResult, appendResult;
4924
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4925
+ while (1) switch (_context26.prev = _context26.next) {
4788
4926
  case 0:
4789
4927
  tempOrder = this.ensureTempOrder();
4790
4928
  if (!(!Array.isArray(items) || items.length === 0)) {
4791
- _context25.next = 3;
4929
+ _context26.next = 3;
4792
4930
  break;
4793
4931
  }
4794
- return _context25.abrupt("return", tempOrder.products);
4932
+ return _context26.abrupt("return", tempOrder.products);
4795
4933
  case 3:
4796
4934
  _iterator20 = _createForOfIteratorHelper(items || []);
4797
- _context25.prev = 4;
4935
+ _context26.prev = 4;
4798
4936
  _iterator20.s();
4799
4937
  case 6:
4800
4938
  if ((_step20 = _iterator20.n()).done) {
4801
- _context25.next = 34;
4939
+ _context26.next = 32;
4802
4940
  break;
4803
4941
  }
4804
4942
  item = _step20.value;
4805
4943
  product = item.product, booking = item.booking;
4806
4944
  if (product) {
4807
- _context25.next = 11;
4945
+ _context26.next = 11;
4808
4946
  break;
4809
4947
  }
4810
- return _context25.abrupt("continue", 32);
4948
+ return _context26.abrupt("continue", 30);
4811
4949
  case 11:
4812
4950
  if (!booking) {
4813
- _context25.next = 28;
4951
+ _context26.next = 26;
4814
4952
  break;
4815
4953
  }
4816
4954
  productRecord = product;
4817
- splitCount = getSafeProductNum((_ref63 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref63 !== void 0 ? _ref63 : 1);
4955
+ splitCount = getSafeProductNum((_ref65 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref65 !== void 0 ? _ref65 : 1);
4818
4956
  if (!(splitCount > 1)) {
4819
- _context25.next = 28;
4957
+ _context26.next = 26;
4820
4958
  break;
4821
4959
  }
4822
4960
  i = 0;
4823
4961
  case 16:
4824
4962
  if (!(i < splitCount)) {
4825
- _context25.next = 27;
4963
+ _context26.next = 25;
4826
4964
  break;
4827
4965
  }
4828
- singleLine = cloneDeep(productRecord);
4829
- singleLine.num = 1;
4830
- delete singleLine.product_quantity;
4831
- _appendResult = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4966
+ splitLine = this.createSplitBookingLine(productRecord, booking, i, splitCount);
4967
+ _appendResult = this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking);
4832
4968
  if (!_appendResult) {
4833
- _context25.next = 24;
4969
+ _context26.next = 22;
4834
4970
  break;
4835
4971
  }
4836
- _context25.next = 24;
4972
+ _context26.next = 22;
4837
4973
  return _appendResult;
4838
- case 24:
4974
+ case 22:
4839
4975
  i += 1;
4840
- _context25.next = 16;
4976
+ _context26.next = 16;
4841
4977
  break;
4842
- case 27:
4843
- return _context25.abrupt("continue", 32);
4844
- case 28:
4978
+ case 25:
4979
+ return _context26.abrupt("continue", 30);
4980
+ case 26:
4845
4981
  appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking);
4846
4982
  if (!appendResult) {
4847
- _context25.next = 32;
4983
+ _context26.next = 30;
4848
4984
  break;
4849
4985
  }
4850
- _context25.next = 32;
4986
+ _context26.next = 30;
4851
4987
  return appendResult;
4988
+ case 30:
4989
+ _context26.next = 6;
4990
+ break;
4852
4991
  case 32:
4853
- _context25.next = 6;
4992
+ _context26.next = 37;
4854
4993
  break;
4855
4994
  case 34:
4856
- _context25.next = 39;
4857
- break;
4858
- case 36:
4859
- _context25.prev = 36;
4860
- _context25.t0 = _context25["catch"](4);
4861
- _iterator20.e(_context25.t0);
4862
- case 39:
4863
- _context25.prev = 39;
4995
+ _context26.prev = 34;
4996
+ _context26.t0 = _context26["catch"](4);
4997
+ _iterator20.e(_context26.t0);
4998
+ case 37:
4999
+ _context26.prev = 37;
4864
5000
  _iterator20.f();
4865
- return _context25.finish(39);
4866
- case 42:
4867
- _context25.next = 44;
5001
+ return _context26.finish(37);
5002
+ case 40:
5003
+ _context26.next = 42;
4868
5004
  return this.finalizeProductOrderMutation(tempOrder, options);
4869
- case 44:
5005
+ case 42:
4870
5006
  this.logInfo('addProductsToOrder success', {
4871
5007
  itemsCount: items.length
4872
5008
  });
4873
- return _context25.abrupt("return", tempOrder.products);
4874
- case 46:
5009
+ return _context26.abrupt("return", tempOrder.products);
5010
+ case 44:
4875
5011
  case "end":
4876
- return _context25.stop();
5012
+ return _context26.stop();
4877
5013
  }
4878
- }, _callee23, this, [[4, 36, 39, 42]]);
5014
+ }, _callee24, this, [[4, 34, 37, 40]]);
4879
5015
  }));
4880
5016
  function addProductsToOrder(_x26, _x27) {
4881
5017
  return _addProductsToOrder.apply(this, arguments);
@@ -4904,9 +5040,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4904
5040
  }, {
4905
5041
  key: "getBundleRuntimeIdentity",
4906
5042
  value: function getBundleRuntimeIdentity(bundle) {
4907
- var _ref64, _bundle$bundle_id2, _ref65, _bundle$bundle_group_2, _ref66, _ref67, _bundle$bundle_produc3, _ref68, _bundle$bundle_varian3;
5043
+ var _ref66, _bundle$bundle_id2, _ref67, _bundle$bundle_group_2, _ref68, _ref69, _bundle$bundle_produc3, _ref70, _bundle$bundle_varian3;
4908
5044
  if (!bundle || _typeof(bundle) !== 'object') return '';
4909
- return [(_ref64 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref64 !== void 0 ? _ref64 : '', (_ref65 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref65 !== void 0 ? _ref65 : '', (_ref66 = (_ref67 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref67 !== void 0 ? _ref67 : bundle.product_id) !== null && _ref66 !== void 0 ? _ref66 : '', (_ref68 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref68 !== void 0 ? _ref68 : 0].join('|');
5045
+ return [(_ref66 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref66 !== void 0 ? _ref66 : '', (_ref67 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref67 !== void 0 ? _ref67 : '', (_ref68 = (_ref69 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref69 !== void 0 ? _ref69 : bundle.product_id) !== null && _ref68 !== void 0 ? _ref68 : '', (_ref70 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref70 !== void 0 ? _ref70 : 0].join('|');
4910
5046
  }
4911
5047
  }, {
4912
5048
  key: "preservePersistedBundlePriceFields",
@@ -5057,13 +5193,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5057
5193
  delete nextProduct.metadata.main_product_original_price;
5058
5194
  delete nextProduct.metadata.price_schema_version;
5059
5195
  } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5060
- var _ref69, _targetProduct$metada10, _targetProduct$metada11, _ref70, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5196
+ var _ref71, _targetProduct$metada10, _targetProduct$metada11, _ref72, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5061
5197
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
5062
5198
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
5063
5199
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
5064
5200
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
5065
- var _previousMainOriginal = new Decimal(Number((_ref69 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref69 !== void 0 ? _ref69 : 0) || 0);
5066
- var _previousMainSelling = new Decimal(Number((_ref70 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref70 !== void 0 ? _ref70 : _previousMainOriginal.toNumber()) || 0);
5201
+ var _previousMainOriginal = new Decimal(Number((_ref71 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref71 !== void 0 ? _ref71 : 0) || 0);
5202
+ var _previousMainSelling = new Decimal(Number((_ref72 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref72 !== void 0 ? _ref72 : _previousMainOriginal.toNumber()) || 0);
5067
5203
  var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
5068
5204
  var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
5069
5205
  var _nextMainOriginal = previousSource.plus(nextOptionSum);
@@ -5122,35 +5258,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5122
5258
  }, {
5123
5259
  key: "updateOrderProduct",
5124
5260
  value: function () {
5125
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
5126
- var tempOrder, updatedProductUid;
5127
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
5128
- while (1) switch (_context26.prev = _context26.next) {
5261
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
5262
+ var tempOrder, updatedProductUid, promotionPayload;
5263
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
5264
+ while (1) switch (_context27.prev = _context27.next) {
5129
5265
  case 0:
5130
5266
  tempOrder = this.ensureTempOrder();
5131
5267
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
5132
- _context26.next = 4;
5133
- return this.applyPromotion();
5268
+ _context27.next = 4;
5269
+ return this.evaluatePromotion();
5134
5270
  case 4:
5271
+ promotionPayload = _context27.sent;
5135
5272
  this.applyDiscount({
5136
5273
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
5137
5274
  });
5138
5275
  this.sanitizeTempOrderProducts(tempOrder);
5139
- _context26.next = 8;
5276
+ _context27.next = 9;
5140
5277
  return this.recalculateSummary({
5141
5278
  createIfMissing: true
5142
5279
  });
5143
- case 8:
5280
+ case 9:
5144
5281
  this.persistTempOrder();
5282
+ this.emitPromotionApplied(promotionPayload);
5145
5283
  this.logInfo('updateOrderProduct success', {
5146
5284
  params: params
5147
5285
  });
5148
- return _context26.abrupt("return", tempOrder.products);
5149
- case 11:
5286
+ return _context27.abrupt("return", tempOrder.products);
5287
+ case 13:
5150
5288
  case "end":
5151
- return _context26.stop();
5289
+ return _context27.stop();
5152
5290
  }
5153
- }, _callee24, this);
5291
+ }, _callee25, this);
5154
5292
  }));
5155
5293
  function updateOrderProduct(_x28) {
5156
5294
  return _updateOrderProduct.apply(this, arguments);
@@ -5160,18 +5298,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5160
5298
  }, {
5161
5299
  key: "updateOrderProducts",
5162
5300
  value: function () {
5163
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(paramsList) {
5301
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
5164
5302
  var _this32 = this;
5165
5303
  var tempOrder, reapplyBookingDiscountProductUids;
5166
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
5167
- while (1) switch (_context27.prev = _context27.next) {
5304
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5305
+ while (1) switch (_context28.prev = _context28.next) {
5168
5306
  case 0:
5169
5307
  tempOrder = this.ensureTempOrder();
5170
5308
  if (paramsList.length) {
5171
- _context27.next = 3;
5309
+ _context28.next = 3;
5172
5310
  break;
5173
5311
  }
5174
- return _context27.abrupt("return", tempOrder.products);
5312
+ return _context28.abrupt("return", tempOrder.products);
5175
5313
  case 3:
5176
5314
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
5177
5315
  var updatedProductUid = _this32.applyOrderProductUpdateToTempOrder(tempOrder, params);
@@ -5181,7 +5319,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5181
5319
  }
5182
5320
  return acc;
5183
5321
  }, []);
5184
- _context27.next = 6;
5322
+ _context28.next = 6;
5185
5323
  return this.finalizeAfterProductsMutation(tempOrder, {
5186
5324
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
5187
5325
  });
@@ -5189,12 +5327,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5189
5327
  this.logInfo('updateOrderProduct success', {
5190
5328
  paramsList: paramsList
5191
5329
  });
5192
- return _context27.abrupt("return", tempOrder.products);
5330
+ return _context28.abrupt("return", tempOrder.products);
5193
5331
  case 8:
5194
5332
  case "end":
5195
- return _context27.stop();
5333
+ return _context28.stop();
5196
5334
  }
5197
- }, _callee25, this);
5335
+ }, _callee26, this);
5198
5336
  }));
5199
5337
  function updateOrderProducts(_x29) {
5200
5338
  return _updateOrderProducts.apply(this, arguments);
@@ -5204,11 +5342,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5204
5342
  }, {
5205
5343
  key: "updateOrderProductQuantity",
5206
5344
  value: function () {
5207
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
5345
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
5208
5346
  var _targetProduct$metada17;
5209
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance;
5210
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5211
- while (1) switch (_context28.prev = _context28.next) {
5347
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
5348
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5349
+ while (1) switch (_context29.prev = _context29.next) {
5212
5350
  case 0:
5213
5351
  product_id = params.product_id, product_variant_id = params.product_variant_id, num = params.num, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle;
5214
5352
  tempOrder = this.ensureTempOrder();
@@ -5238,7 +5376,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5238
5376
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
5239
5377
  }
5240
5378
  if (!(productIndex === -1)) {
5241
- _context28.next = 13;
5379
+ _context29.next = 13;
5242
5380
  break;
5243
5381
  }
5244
5382
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -5253,7 +5391,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5253
5391
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5254
5392
  settlementSnapshot = getSelectedSettlementSnapshot(normalizedProduct);
5255
5393
  if (!(this.isMultiCurrencySettlementEnabled() && (settlementSnapshot === null || settlementSnapshot === void 0 ? void 0 : settlementSnapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1)) {
5256
- _context28.next = 26;
5394
+ _context29.next = 26;
5257
5395
  break;
5258
5396
  }
5259
5397
  currencyProductId = Number(settlementSnapshot.currency_product_id);
@@ -5261,7 +5399,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5261
5399
  return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
5262
5400
  });
5263
5401
  if (asset) {
5264
- _context28.next = 22;
5402
+ _context29.next = 22;
5265
5403
  break;
5266
5404
  }
5267
5405
  throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
@@ -5273,38 +5411,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5273
5411
  }, new Decimal(0));
5274
5412
  balance = new Decimal(asset.balance || 0);
5275
5413
  if (!balance.lt(requiredAmount)) {
5276
- _context28.next = 26;
5414
+ _context29.next = 26;
5277
5415
  break;
5278
5416
  }
5279
5417
  throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
5280
5418
  case 26:
5281
5419
  tempOrder.products[productIndex] = normalizedProduct;
5282
5420
  this.prepareVirtualSettlementTempOrder(tempOrder);
5283
- if (this.isActiveVirtualSettlementOrder(tempOrder)) {
5284
- _context28.next = 32;
5421
+ isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
5422
+ if (isVirtualSettlement) {
5423
+ _context29.next = 35;
5285
5424
  break;
5286
5425
  }
5287
- _context28.next = 31;
5288
- return this.applyPromotion();
5289
- case 31:
5290
- this.applyDiscount();
5426
+ _context29.next = 32;
5427
+ return this.evaluatePromotion();
5291
5428
  case 32:
5429
+ _context29.t0 = _context29.sent;
5430
+ _context29.next = 36;
5431
+ break;
5432
+ case 35:
5433
+ _context29.t0 = null;
5434
+ case 36:
5435
+ promotionPayload = _context29.t0;
5436
+ if (!isVirtualSettlement) {
5437
+ this.applyDiscount();
5438
+ }
5292
5439
  this.sanitizeTempOrderProducts(tempOrder);
5293
- _context28.next = 35;
5440
+ _context29.next = 41;
5294
5441
  return this.recalculateSummary({
5295
5442
  createIfMissing: true
5296
5443
  });
5297
- case 35:
5444
+ case 41:
5298
5445
  this.persistTempOrder();
5446
+ this.emitPromotionApplied(promotionPayload);
5299
5447
  this.logInfo('updateOrderProductQuantity success', {
5300
5448
  params: params
5301
5449
  });
5302
- return _context28.abrupt("return", tempOrder.products);
5303
- case 38:
5450
+ return _context29.abrupt("return", tempOrder.products);
5451
+ case 45:
5304
5452
  case "end":
5305
- return _context28.stop();
5453
+ return _context29.stop();
5306
5454
  }
5307
- }, _callee26, this);
5455
+ }, _callee27, this);
5308
5456
  }));
5309
5457
  function updateOrderProductQuantity(_x30) {
5310
5458
  return _updateOrderProductQuantity.apply(this, arguments);
@@ -5347,29 +5495,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5347
5495
  }, {
5348
5496
  key: "finalizeAfterProductsMutation",
5349
5497
  value: (function () {
5350
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(tempOrder, options) {
5351
- return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5352
- while (1) switch (_context29.prev = _context29.next) {
5498
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(tempOrder, options) {
5499
+ var promotionPayload;
5500
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
5501
+ while (1) switch (_context30.prev = _context30.next) {
5353
5502
  case 0:
5354
5503
  this.syncTempOrderHolderFromBookings(tempOrder);
5355
- _context29.next = 3;
5356
- return this.applyPromotion();
5504
+ _context30.next = 3;
5505
+ return this.evaluatePromotion();
5357
5506
  case 3:
5507
+ promotionPayload = _context30.sent;
5358
5508
  this.applyDiscount({
5359
5509
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
5360
5510
  });
5361
5511
  this.sanitizeTempOrderProducts(tempOrder);
5362
- _context29.next = 7;
5512
+ _context30.next = 8;
5363
5513
  return this.recalculateSummary({
5364
5514
  createIfMissing: true
5365
5515
  });
5366
- case 7:
5367
- this.persistTempOrder();
5368
5516
  case 8:
5517
+ this.persistTempOrder();
5518
+ this.emitPromotionApplied(promotionPayload);
5519
+ case 10:
5369
5520
  case "end":
5370
- return _context29.stop();
5521
+ return _context30.stop();
5371
5522
  }
5372
- }, _callee27, this);
5523
+ }, _callee28, this);
5373
5524
  }));
5374
5525
  function finalizeAfterProductsMutation(_x31, _x32) {
5375
5526
  return _finalizeAfterProductsMutation.apply(this, arguments);
@@ -5386,18 +5537,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5386
5537
  }, {
5387
5538
  key: "removeProductsFromOrder",
5388
5539
  value: (function () {
5389
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identities, options) {
5540
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identities, options) {
5390
5541
  var _this33 = this;
5391
5542
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
5392
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
5393
- while (1) switch (_context31.prev = _context31.next) {
5543
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5544
+ while (1) switch (_context32.prev = _context32.next) {
5394
5545
  case 0:
5395
5546
  tempOrder = this.ensureTempOrder();
5396
5547
  if (identities.length) {
5397
- _context31.next = 3;
5548
+ _context32.next = 3;
5398
5549
  break;
5399
5550
  }
5400
- return _context31.abrupt("return", tempOrder.products);
5551
+ return _context32.abrupt("return", tempOrder.products);
5401
5552
  case 3:
5402
5553
  // 商品删除会同步删除以商品行为主关系的 Notes;快照不完整时禁止产生孤儿 Relation。
5403
5554
  this.ensureSalesNotesLoadedForMutation(tempOrder);
@@ -5430,22 +5581,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5430
5581
  }
5431
5582
  linkedBookingUidsToRemove = new Set();
5432
5583
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
5433
- _context31.prev = 16;
5584
+ _context32.prev = 16;
5434
5585
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
5435
5586
  var _metadata11, _metadata12, _metadata13, _metadata14;
5436
5587
  var product, productUid, productBookingUid, isAddTimeProduct;
5437
- return _regeneratorRuntime().wrap(function _loop3$(_context30) {
5438
- while (1) switch (_context30.prev = _context30.next) {
5588
+ return _regeneratorRuntime().wrap(function _loop3$(_context31) {
5589
+ while (1) switch (_context31.prev = _context31.next) {
5439
5590
  case 0:
5440
5591
  product = _step21.value;
5441
5592
  productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5442
5593
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
5443
5594
  isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
5444
5595
  if (!isAddTimeProduct) {
5445
- _context30.next = 6;
5596
+ _context31.next = 6;
5446
5597
  break;
5447
5598
  }
5448
- return _context30.abrupt("return", 1);
5599
+ return _context31.abrupt("return", 1);
5449
5600
  case 6:
5450
5601
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
5451
5602
  linkedBookingUidsToRemove.add(String(productBookingUid));
@@ -5460,37 +5611,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5460
5611
  }
5461
5612
  case 8:
5462
5613
  case "end":
5463
- return _context30.stop();
5614
+ return _context31.stop();
5464
5615
  }
5465
5616
  }, _loop3);
5466
5617
  });
5467
5618
  _iterator21.s();
5468
5619
  case 19:
5469
5620
  if ((_step21 = _iterator21.n()).done) {
5470
- _context31.next = 25;
5621
+ _context32.next = 25;
5471
5622
  break;
5472
5623
  }
5473
- return _context31.delegateYield(_loop3(), "t0", 21);
5624
+ return _context32.delegateYield(_loop3(), "t0", 21);
5474
5625
  case 21:
5475
- if (!_context31.t0) {
5476
- _context31.next = 23;
5626
+ if (!_context32.t0) {
5627
+ _context32.next = 23;
5477
5628
  break;
5478
5629
  }
5479
- return _context31.abrupt("continue", 23);
5630
+ return _context32.abrupt("continue", 23);
5480
5631
  case 23:
5481
- _context31.next = 19;
5632
+ _context32.next = 19;
5482
5633
  break;
5483
5634
  case 25:
5484
- _context31.next = 30;
5635
+ _context32.next = 30;
5485
5636
  break;
5486
5637
  case 27:
5487
- _context31.prev = 27;
5488
- _context31.t1 = _context31["catch"](16);
5489
- _iterator21.e(_context31.t1);
5638
+ _context32.prev = 27;
5639
+ _context32.t1 = _context32["catch"](16);
5640
+ _iterator21.e(_context32.t1);
5490
5641
  case 30:
5491
- _context31.prev = 30;
5642
+ _context32.prev = 30;
5492
5643
  _iterator21.f();
5493
- return _context31.finish(30);
5644
+ return _context32.finish(30);
5494
5645
  case 33:
5495
5646
  if (linkedBookingUidsToRemove.size > 0) {
5496
5647
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -5518,18 +5669,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5518
5669
  }
5519
5670
  }
5520
5671
  this.removeSalesNotesForMissingProductLines(tempOrder);
5521
- _context31.next = 38;
5672
+ _context32.next = 38;
5522
5673
  return this.finalizeAfterProductsMutation(tempOrder);
5523
5674
  case 38:
5524
5675
  this.logInfo('removeProductsFromOrder success', {
5525
5676
  identities: identities
5526
5677
  });
5527
- return _context31.abrupt("return", tempOrder.products);
5678
+ return _context32.abrupt("return", tempOrder.products);
5528
5679
  case 40:
5529
5680
  case "end":
5530
- return _context31.stop();
5681
+ return _context32.stop();
5531
5682
  }
5532
- }, _callee28, this, [[16, 27, 30, 33]]);
5683
+ }, _callee29, this, [[16, 27, 30, 33]]);
5533
5684
  }));
5534
5685
  function removeProductsFromOrder(_x33, _x34) {
5535
5686
  return _removeProductsFromOrder.apply(this, arguments);
@@ -5539,16 +5690,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5539
5690
  }, {
5540
5691
  key: "removeProductFromOrder",
5541
5692
  value: function () {
5542
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identity, options) {
5543
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5544
- while (1) switch (_context32.prev = _context32.next) {
5693
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(identity, options) {
5694
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5695
+ while (1) switch (_context33.prev = _context33.next) {
5545
5696
  case 0:
5546
- return _context32.abrupt("return", this.removeProductsFromOrder([identity], options));
5697
+ return _context33.abrupt("return", this.removeProductsFromOrder([identity], options));
5547
5698
  case 1:
5548
5699
  case "end":
5549
- return _context32.stop();
5700
+ return _context33.stop();
5550
5701
  }
5551
- }, _callee29, this);
5702
+ }, _callee30, this);
5552
5703
  }));
5553
5704
  function removeProductFromOrder(_x35, _x36) {
5554
5705
  return _removeProductFromOrder.apply(this, arguments);
@@ -5562,10 +5713,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5562
5713
  }, {
5563
5714
  key: "clearOrderCartLines",
5564
5715
  value: (function () {
5565
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
5566
- var tempOrder;
5567
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5568
- while (1) switch (_context33.prev = _context33.next) {
5716
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
5717
+ var tempOrder, promotionPayload;
5718
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5719
+ while (1) switch (_context34.prev = _context34.next) {
5569
5720
  case 0:
5570
5721
  tempOrder = this.ensureTempOrder();
5571
5722
  this.ensureSalesNotesLoadedForMutation(tempOrder);
@@ -5579,24 +5730,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5579
5730
  productsByUid: {}
5580
5731
  });
5581
5732
  }
5582
- _context33.next = 10;
5583
- return this.applyPromotion();
5733
+ _context34.next = 10;
5734
+ return this.evaluatePromotion();
5584
5735
  case 10:
5736
+ promotionPayload = _context34.sent;
5585
5737
  this.applyDiscount();
5586
5738
  this.sanitizeTempOrderProducts(tempOrder);
5587
- _context33.next = 14;
5739
+ _context34.next = 15;
5588
5740
  return this.recalculateSummary({
5589
5741
  createIfMissing: true
5590
5742
  });
5591
- case 14:
5743
+ case 15:
5592
5744
  this.persistTempOrder();
5745
+ this.emitPromotionApplied(promotionPayload);
5593
5746
  this.logInfo('clearOrderCartLines success', {});
5594
- return _context33.abrupt("return", tempOrder);
5595
- case 17:
5747
+ return _context34.abrupt("return", tempOrder);
5748
+ case 19:
5596
5749
  case "end":
5597
- return _context33.stop();
5750
+ return _context34.stop();
5598
5751
  }
5599
- }, _callee30, this);
5752
+ }, _callee31, this);
5600
5753
  }));
5601
5754
  function clearOrderCartLines() {
5602
5755
  return _clearOrderCartLines.apply(this, arguments);
@@ -5610,11 +5763,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5610
5763
  }, {
5611
5764
  key: "clearOrderForSettlementSwitch",
5612
5765
  value: (function () {
5613
- var _clearOrderForSettlementSwitch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
5766
+ var _clearOrderForSettlementSwitch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
5614
5767
  var _this$store$discount22, _this$store$discount23;
5615
5768
  var tempOrder;
5616
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5617
- while (1) switch (_context34.prev = _context34.next) {
5769
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5770
+ while (1) switch (_context35.prev = _context35.next) {
5618
5771
  case 0:
5619
5772
  tempOrder = this.ensureTempOrder();
5620
5773
  this.ensureSalesNotesLoadedForMutation(tempOrder);
@@ -5633,28 +5786,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5633
5786
  productsByUid: {}
5634
5787
  });
5635
5788
  }
5636
- _context34.next = 15;
5789
+ _context35.next = 15;
5637
5790
  return (_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.setDiscountList([]);
5638
5791
  case 15:
5639
- _context34.next = 17;
5792
+ _context35.next = 17;
5640
5793
  return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList([]);
5641
5794
  case 17:
5642
5795
  this.hasActiveCustomerBoundDiscount = false;
5643
5796
  this.lastUnfulfilledPromotions = [];
5644
5797
  this.lastGiftActions = null;
5645
- _context34.next = 22;
5798
+ _context35.next = 22;
5646
5799
  return this.recalculateSummary({
5647
5800
  createIfMissing: true
5648
5801
  });
5649
5802
  case 22:
5650
5803
  this.persistTempOrder();
5651
5804
  this.logInfo('clearOrderForSettlementSwitch success', {});
5652
- return _context34.abrupt("return", tempOrder);
5805
+ return _context35.abrupt("return", tempOrder);
5653
5806
  case 25:
5654
5807
  case "end":
5655
- return _context34.stop();
5808
+ return _context35.stop();
5656
5809
  }
5657
- }, _callee31, this);
5810
+ }, _callee32, this);
5658
5811
  }));
5659
5812
  function clearOrderForSettlementSwitch() {
5660
5813
  return _clearOrderForSettlementSwitch.apply(this, arguments);
@@ -5665,23 +5818,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5665
5818
  }, {
5666
5819
  key: "buildCurrentSubmitPayloadForLocalPrint",
5667
5820
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
5668
- var _params$cacheId, _this$otherParams5, _ref71, _params$businessCode, _this$otherParams6, _this$otherParams7;
5821
+ var _params$cacheId, _this$otherParams5, _ref73, _params$businessCode, _this$otherParams6, _this$otherParams7;
5669
5822
  var tempOrder = this.ensureTempOrder();
5670
5823
  this.persistTempOrder();
5671
5824
  var payload = buildSubmitPayload({
5672
5825
  tempOrder: tempOrder,
5673
5826
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
5674
5827
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
5675
- businessCode: (_ref71 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref71 !== void 0 ? _ref71 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
5828
+ businessCode: (_ref73 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
5676
5829
  channel: params === null || params === void 0 ? void 0 : params.channel,
5677
5830
  type: params === null || params === void 0 ? void 0 : params.type,
5678
5831
  summary: this.store.summary || createEmptySummary(),
5679
5832
  enhance: function enhance(nextPayload) {
5680
- var _ref72, _tempOrder$order_numb, _ref73, _tempOrder$shop_order2, _ref74, _tempOrder$shop_full_;
5833
+ var _ref74, _tempOrder$order_numb, _ref75, _tempOrder$shop_order2, _ref76, _tempOrder$shop_full_;
5681
5834
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
5682
- order_number: (_ref72 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
5683
- shop_order_number: (_ref73 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref73 !== void 0 ? _ref73 : null,
5684
- shop_full_order_number: (_ref74 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref74 !== void 0 ? _ref74 : null,
5835
+ order_number: (_ref74 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref74 !== void 0 ? _ref74 : null,
5836
+ shop_order_number: (_ref75 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref75 !== void 0 ? _ref75 : null,
5837
+ shop_full_order_number: (_ref76 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref76 !== void 0 ? _ref76 : null,
5685
5838
  small_ticket_data_flag: 1
5686
5839
  });
5687
5840
  }
@@ -5692,17 +5845,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5692
5845
  }, {
5693
5846
  key: "applyLocalPrintOrderNumbers",
5694
5847
  value: function () {
5695
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order) {
5848
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5696
5849
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
5697
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5698
- while (1) switch (_context35.prev = _context35.next) {
5850
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5851
+ while (1) switch (_context36.prev = _context36.next) {
5699
5852
  case 0:
5700
5853
  tempOrder = this.ensureTempOrder();
5701
5854
  if (!(!order || _typeof(order) !== 'object')) {
5702
- _context35.next = 3;
5855
+ _context36.next = 3;
5703
5856
  break;
5704
5857
  }
5705
- return _context35.abrupt("return", tempOrder);
5858
+ return _context36.abrupt("return", tempOrder);
5706
5859
  case 3:
5707
5860
  shopOrderNumber = order.shop_order_number;
5708
5861
  shopFullOrderNumber = order.shop_full_order_number;
@@ -5713,15 +5866,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5713
5866
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
5714
5867
  }
5715
5868
  this.persistTempOrder();
5716
- _context35.next = 10;
5869
+ _context36.next = 10;
5717
5870
  return this.saveDraft();
5718
5871
  case 10:
5719
- return _context35.abrupt("return", tempOrder);
5872
+ return _context36.abrupt("return", tempOrder);
5720
5873
  case 11:
5721
5874
  case "end":
5722
- return _context35.stop();
5875
+ return _context36.stop();
5723
5876
  }
5724
- }, _callee32, this);
5877
+ }, _callee33, this);
5725
5878
  }));
5726
5879
  function applyLocalPrintOrderNumbers(_x37) {
5727
5880
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
@@ -5731,35 +5884,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5731
5884
  }, {
5732
5885
  key: "saveTempOrderAsDraft",
5733
5886
  value: function () {
5734
- var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5887
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5735
5888
  var _params$cacheId2, _this$otherParams8, _this$otherParams9, _this$otherParams10, _params$type, _this$otherParams11, _payload$products;
5736
5889
  var tempOrder, latestSummary, payload;
5737
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5738
- while (1) switch (_context36.prev = _context36.next) {
5890
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5891
+ while (1) switch (_context37.prev = _context37.next) {
5739
5892
  case 0:
5740
5893
  tempOrder = this.ensureTempOrder();
5741
5894
  this.ensureExternalSaleNumber(tempOrder);
5742
5895
  this.persistTempOrder();
5743
- _context36.next = 5;
5896
+ _context37.next = 5;
5744
5897
  return this.recalculateSummary({
5745
5898
  createIfMissing: true
5746
5899
  });
5747
5900
  case 5:
5748
- _context36.t1 = _context36.sent;
5749
- if (_context36.t1) {
5750
- _context36.next = 8;
5901
+ _context37.t1 = _context37.sent;
5902
+ if (_context37.t1) {
5903
+ _context37.next = 8;
5751
5904
  break;
5752
5905
  }
5753
- _context36.t1 = this.store.summary;
5906
+ _context37.t1 = this.store.summary;
5754
5907
  case 8:
5755
- _context36.t0 = _context36.t1;
5756
- if (_context36.t0) {
5757
- _context36.next = 11;
5908
+ _context37.t0 = _context37.t1;
5909
+ if (_context37.t0) {
5910
+ _context37.next = 11;
5758
5911
  break;
5759
5912
  }
5760
- _context36.t0 = createEmptySummary();
5913
+ _context37.t0 = createEmptySummary();
5761
5914
  case 11:
5762
- latestSummary = _context36.t0;
5915
+ latestSummary = _context37.t0;
5763
5916
  payload = buildSubmitPayload({
5764
5917
  tempOrder: tempOrder,
5765
5918
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
@@ -5780,15 +5933,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5780
5933
  externalSaleNumber: payload.external_sale_number,
5781
5934
  productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5782
5935
  });
5783
- return _context36.abrupt("return", this.request.post('/order/sales/draft', payload, {
5936
+ return _context37.abrupt("return", this.request.post('/order/sales/draft', payload, {
5784
5937
  osServer: true,
5785
5938
  customToast: function customToast() {}
5786
5939
  }));
5787
5940
  case 18:
5788
5941
  case "end":
5789
- return _context36.stop();
5942
+ return _context37.stop();
5790
5943
  }
5791
- }, _callee33, this);
5944
+ }, _callee34, this);
5792
5945
  }));
5793
5946
  function saveTempOrderAsDraft(_x38) {
5794
5947
  return _saveTempOrderAsDraft.apply(this, arguments);
@@ -5804,16 +5957,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5804
5957
  }, {
5805
5958
  key: "submitTempOrder",
5806
5959
  value: (function () {
5807
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5808
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5809
- while (1) switch (_context37.prev = _context37.next) {
5960
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5961
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5962
+ while (1) switch (_context38.prev = _context38.next) {
5810
5963
  case 0:
5811
- return _context37.abrupt("return", this.runSubmitTempOrder(params));
5964
+ return _context38.abrupt("return", this.runSubmitTempOrder(params));
5812
5965
  case 1:
5813
5966
  case "end":
5814
- return _context37.stop();
5967
+ return _context38.stop();
5815
5968
  }
5816
- }, _callee34, this);
5969
+ }, _callee35, this);
5817
5970
  }));
5818
5971
  function submitTempOrder(_x39) {
5819
5972
  return _submitTempOrder.apply(this, arguments);
@@ -5823,18 +5976,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5823
5976
  }, {
5824
5977
  key: "submitTempOrderAsync",
5825
5978
  value: function () {
5826
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5827
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5828
- while (1) switch (_context38.prev = _context38.next) {
5979
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5980
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5981
+ while (1) switch (_context39.prev = _context39.next) {
5829
5982
  case 0:
5830
- return _context38.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5983
+ return _context39.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5831
5984
  syncMode: true
5832
5985
  })));
5833
5986
  case 1:
5834
5987
  case "end":
5835
- return _context38.stop();
5988
+ return _context39.stop();
5836
5989
  }
5837
- }, _callee35, this);
5990
+ }, _callee36, this);
5838
5991
  }));
5839
5992
  function submitTempOrderAsync(_x40) {
5840
5993
  return _submitTempOrderAsync.apply(this, arguments);
@@ -5844,11 +5997,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5844
5997
  }, {
5845
5998
  key: "runSubmitTempOrder",
5846
5999
  value: function () {
5847
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5848
- var _params$cacheId3, _this$otherParams12, _ref75, _ref76, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6000
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6001
+ var _params$cacheId3, _this$otherParams12, _ref77, _ref78, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
5849
6002
  var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
5850
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5851
- while (1) switch (_context39.prev = _context39.next) {
6003
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6004
+ while (1) switch (_context40.prev = _context40.next) {
5852
6005
  case 0:
5853
6006
  tempOrder = this.ensureTempOrder();
5854
6007
  this.prepareVirtualSettlementTempOrder(tempOrder);
@@ -5872,26 +6025,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5872
6025
  }
5873
6026
  }
5874
6027
  this.persistTempOrder();
5875
- _context39.next = 10;
6028
+ _context40.next = 10;
5876
6029
  return this.recalculateSummary({
5877
6030
  createIfMissing: true
5878
6031
  });
5879
6032
  case 10:
5880
- _context39.t1 = _context39.sent;
5881
- if (_context39.t1) {
5882
- _context39.next = 13;
6033
+ _context40.t1 = _context40.sent;
6034
+ if (_context40.t1) {
6035
+ _context40.next = 13;
5883
6036
  break;
5884
6037
  }
5885
- _context39.t1 = this.store.summary;
6038
+ _context40.t1 = this.store.summary;
5886
6039
  case 13:
5887
- _context39.t0 = _context39.t1;
5888
- if (_context39.t0) {
5889
- _context39.next = 16;
6040
+ _context40.t0 = _context40.t1;
6041
+ if (_context40.t0) {
6042
+ _context40.next = 16;
5890
6043
  break;
5891
6044
  }
5892
- _context39.t0 = createEmptySummary();
6045
+ _context40.t0 = createEmptySummary();
5893
6046
  case 16:
5894
- latestSummary = _context39.t0;
6047
+ latestSummary = _context40.t0;
5895
6048
  effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
5896
6049
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
5897
6050
  shouldOverridePaymentStatus = hasPaymentStatusOverride && !isOnlineStorePlatform && !shouldConfirmPendingVoucherPayments;
@@ -5912,7 +6065,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5912
6065
  tempOrder: tempOrder,
5913
6066
  cacheId: effectiveCacheId,
5914
6067
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
5915
- businessCode: (_ref75 = (_ref76 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref76 !== void 0 ? _ref76 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6068
+ businessCode: (_ref77 = (_ref78 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref78 !== void 0 ? _ref78 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref77 !== void 0 ? _ref77 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
5916
6069
  channel: params === null || params === void 0 ? void 0 : params.channel,
5917
6070
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
5918
6071
  summary: latestSummary,
@@ -5927,10 +6080,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5927
6080
  if (!payload.created_at) {
5928
6081
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5929
6082
  }
5930
- _context39.next = 28;
6083
+ _context40.next = 28;
5931
6084
  return this.saveDraft();
5932
6085
  case 28:
5933
- _context39.prev = 28;
6086
+ _context40.prev = 28;
5934
6087
  this.logInfo('submitTempOrder calling sales checkout', {
5935
6088
  orderId: payload.order_id,
5936
6089
  externalSaleNumber: payload.external_sale_number,
@@ -5940,43 +6093,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5940
6093
  smallTicketDataFlag: payload.small_ticket_data_flag,
5941
6094
  syncMode: payload.sync_mode
5942
6095
  });
5943
- _context39.next = 32;
6096
+ _context40.next = 32;
5944
6097
  return this.submitSalesOrder({
5945
6098
  query: payload
5946
6099
  });
5947
6100
  case 32:
5948
- result = _context39.sent;
5949
- _context39.next = 45;
6101
+ result = _context40.sent;
6102
+ _context40.next = 45;
5950
6103
  break;
5951
6104
  case 35:
5952
- _context39.prev = 35;
5953
- _context39.t2 = _context39["catch"](28);
5954
- backendErrorResponse = this.extractSubmitErrorResponse(_context39.t2);
6105
+ _context40.prev = 35;
6106
+ _context40.t2 = _context40["catch"](28);
6107
+ backendErrorResponse = this.extractSubmitErrorResponse(_context40.t2);
5955
6108
  if (!backendErrorResponse) {
5956
- _context39.next = 42;
6109
+ _context40.next = 42;
5957
6110
  break;
5958
6111
  }
5959
6112
  this.store.syncState = 'failed';
5960
6113
  this.logSubmitBackendRejected(backendErrorResponse, payload);
5961
- return _context39.abrupt("return", backendErrorResponse);
6114
+ return _context40.abrupt("return", backendErrorResponse);
5962
6115
  case 42:
5963
6116
  this.store.syncState = 'failed';
5964
6117
  this.logError('submitTempOrder failed', {
5965
- error: _context39.t2 instanceof Error ? _context39.t2.message : String(_context39.t2),
6118
+ error: _context40.t2 instanceof Error ? _context40.t2.message : String(_context40.t2),
5966
6119
  orderId: payload.order_id,
5967
6120
  externalSaleNumber: payload.external_sale_number,
5968
6121
  paymentStatus: payload.payment_status,
5969
6122
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
5970
6123
  });
5971
- throw _context39.t2;
6124
+ throw _context40.t2;
5972
6125
  case 45:
5973
6126
  if (!this.isSubmitResponseRejected(result)) {
5974
- _context39.next = 49;
6127
+ _context40.next = 49;
5975
6128
  break;
5976
6129
  }
5977
6130
  this.store.syncState = 'failed';
5978
6131
  this.logSubmitBackendRejected(result, payload);
5979
- return _context39.abrupt("return", result);
6132
+ return _context40.abrupt("return", result);
5980
6133
  case 49:
5981
6134
  isLocalPendingSubmit = this.isLocalPendingSubmitResult(result); // need_sync=1 仅表示已进入本地同步队列,不能视为远端已确认 Notes。
5982
6135
  if (Object.prototype.hasOwnProperty.call(payload, 'notes') && !isLocalPendingSubmit) {
@@ -5992,12 +6145,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5992
6145
  })
5993
6146
  });
5994
6147
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
5995
- _context39.next = 58;
6148
+ _context40.next = 58;
5996
6149
  break;
5997
6150
  }
5998
6151
  tempOrder.order_id = submittedOrderId;
5999
6152
  resultRecord = result;
6000
- _context39.next = 58;
6153
+ _context40.next = 58;
6001
6154
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
6002
6155
  case 58:
6003
6156
  if (isLocalPendingSubmit) {
@@ -6005,12 +6158,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6005
6158
  } else if (submittedOrderId === null || submittedOrderId === undefined) {
6006
6159
  this.store.syncState = 'submitted';
6007
6160
  }
6008
- return _context39.abrupt("return", result);
6161
+ return _context40.abrupt("return", result);
6009
6162
  case 60:
6010
6163
  case "end":
6011
- return _context39.stop();
6164
+ return _context40.stop();
6012
6165
  }
6013
- }, _callee36, this, [[28, 35]]);
6166
+ }, _callee37, this, [[28, 35]]);
6014
6167
  }));
6015
6168
  function runSubmitTempOrder(_x41) {
6016
6169
  return _runSubmitTempOrder.apply(this, arguments);
@@ -6020,10 +6173,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6020
6173
  }, {
6021
6174
  key: "markLocalOrderSynced",
6022
6175
  value: function () {
6023
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(orderId, remoteOrder) {
6176
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderId, remoteOrder) {
6024
6177
  var tempOrder;
6025
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6026
- while (1) switch (_context40.prev = _context40.next) {
6178
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
6179
+ while (1) switch (_context41.prev = _context41.next) {
6027
6180
  case 0:
6028
6181
  tempOrder = this.ensureTempOrder();
6029
6182
  tempOrder.order_id = orderId;
@@ -6031,13 +6184,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6031
6184
  this.store.lastOrderInfo = remoteOrder;
6032
6185
  this.store.syncState = 'submitted';
6033
6186
  this.persistTempOrder();
6034
- _context40.next = 8;
6187
+ _context41.next = 8;
6035
6188
  return this.saveDraft();
6036
6189
  case 8:
6037
6190
  case "end":
6038
- return _context40.stop();
6191
+ return _context41.stop();
6039
6192
  }
6040
- }, _callee37, this);
6193
+ }, _callee38, this);
6041
6194
  }));
6042
6195
  function markLocalOrderSynced(_x42, _x43) {
6043
6196
  return _markLocalOrderSynced.apply(this, arguments);
@@ -6112,31 +6265,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6112
6265
  }, {
6113
6266
  key: "syncPaymentsToOrder",
6114
6267
  value: function () {
6115
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
6268
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6116
6269
  var _this35 = this,
6117
6270
  _params$confirmPendin;
6118
6271
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
6119
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
6120
- while (1) switch (_context41.prev = _context41.next) {
6272
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6273
+ while (1) switch (_context42.prev = _context42.next) {
6121
6274
  case 0:
6122
6275
  tempOrder = this.ensureTempOrder();
6123
6276
  needsPaymentNumber = (params.payments || []).some(function (payment) {
6124
6277
  return String(payment.payment_number || '').trim() === '';
6125
6278
  });
6126
6279
  if (!needsPaymentNumber) {
6127
- _context41.next = 8;
6280
+ _context42.next = 8;
6128
6281
  break;
6129
6282
  }
6130
- _context41.next = 5;
6283
+ _context42.next = 5;
6131
6284
  return this.getPaymentNumberDevicePrefixAsync();
6132
6285
  case 5:
6133
- _context41.t0 = _context41.sent;
6134
- _context41.next = 9;
6286
+ _context42.t0 = _context42.sent;
6287
+ _context42.next = 9;
6135
6288
  break;
6136
6289
  case 8:
6137
- _context41.t0 = 'LOCAL';
6290
+ _context42.t0 = 'LOCAL';
6138
6291
  case 9:
6139
- devicePrefix = _context41.t0;
6292
+ devicePrefix = _context42.t0;
6140
6293
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
6141
6294
  return _this35.normalizePaymentSource(payment, {
6142
6295
  defaultPaid: false,
@@ -6151,20 +6304,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6151
6304
  tempOrder.payments = effectivePayments;
6152
6305
  tempOrder.payment_status = paymentStatus;
6153
6306
  this.persistTempOrder();
6154
- _context41.next = 21;
6307
+ _context42.next = 21;
6155
6308
  return this.saveDraft();
6156
6309
  case 21:
6157
6310
  if (params.submitWhenPaid) {
6158
- _context41.next = 23;
6311
+ _context42.next = 23;
6159
6312
  break;
6160
6313
  }
6161
- return _context41.abrupt("return", completion);
6314
+ return _context42.abrupt("return", completion);
6162
6315
  case 23:
6163
6316
  if (!(this.store.syncState === 'submitting')) {
6164
- _context41.next = 25;
6317
+ _context42.next = 25;
6165
6318
  break;
6166
6319
  }
6167
- return _context41.abrupt("return", completion);
6320
+ return _context42.abrupt("return", completion);
6168
6321
  case 25:
6169
6322
  this.store.syncState = 'submitting';
6170
6323
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
@@ -6184,30 +6337,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6184
6337
  enhancePayload: enhancePayload
6185
6338
  };
6186
6339
  if (!(params.checkoutSyncTaskEnabled === false)) {
6187
- _context41.next = 35;
6340
+ _context42.next = 35;
6188
6341
  break;
6189
6342
  }
6190
- _context41.next = 32;
6343
+ _context42.next = 32;
6191
6344
  return this.submitTempOrderAsync(submitParams);
6192
6345
  case 32:
6193
- _context41.t1 = _context41.sent;
6194
- _context41.next = 38;
6346
+ _context42.t1 = _context42.sent;
6347
+ _context42.next = 38;
6195
6348
  break;
6196
6349
  case 35:
6197
- _context41.next = 37;
6350
+ _context42.next = 37;
6198
6351
  return this.submitTempOrder(submitParams);
6199
6352
  case 37:
6200
- _context41.t1 = _context41.sent;
6353
+ _context42.t1 = _context42.sent;
6201
6354
  case 38:
6202
- submitResult = _context41.t1;
6203
- return _context41.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
6355
+ submitResult = _context42.t1;
6356
+ return _context42.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
6204
6357
  submitResult: submitResult
6205
6358
  }));
6206
6359
  case 40:
6207
6360
  case "end":
6208
- return _context41.stop();
6361
+ return _context42.stop();
6209
6362
  }
6210
- }, _callee38, this);
6363
+ }, _callee39, this);
6211
6364
  }));
6212
6365
  function syncPaymentsToOrder(_x44) {
6213
6366
  return _syncPaymentsToOrder.apply(this, arguments);
@@ -6306,11 +6459,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6306
6459
  }, {
6307
6460
  key: "submitOrder",
6308
6461
  value: function () {
6309
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(order) {
6462
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(order) {
6310
6463
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
6311
6464
  var url, query, fetchUrl, params;
6312
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6313
- while (1) switch (_context42.prev = _context42.next) {
6465
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6466
+ while (1) switch (_context43.prev = _context43.next) {
6314
6467
  case 0:
6315
6468
  this.logInfo('submitOrder called', {
6316
6469
  url: order.url,
@@ -6330,12 +6483,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6330
6483
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
6331
6484
  scheduleDate: params.schedule_date
6332
6485
  });
6333
- return _context42.abrupt("return", this.request.post(fetchUrl, params));
6486
+ return _context43.abrupt("return", this.request.post(fetchUrl, params));
6334
6487
  case 6:
6335
6488
  case "end":
6336
- return _context42.stop();
6489
+ return _context43.stop();
6337
6490
  }
6338
- }, _callee39, this);
6491
+ }, _callee40, this);
6339
6492
  }));
6340
6493
  function submitOrder(_x45) {
6341
6494
  return _submitOrder.apply(this, arguments);
@@ -6345,13 +6498,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6345
6498
  }, {
6346
6499
  key: "cancelOrder",
6347
6500
  value: function () {
6348
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
6501
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
6349
6502
  var payload;
6350
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6351
- while (1) switch (_context43.prev = _context43.next) {
6503
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6504
+ while (1) switch (_context44.prev = _context44.next) {
6352
6505
  case 0:
6353
6506
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
6354
- _context43.next = 2;
6507
+ _context44.next = 2;
6355
6508
  break;
6356
6509
  }
6357
6510
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -6367,14 +6520,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6367
6520
  method: 'PUT',
6368
6521
  orderIdsCount: params.order_ids.length
6369
6522
  });
6370
- return _context43.abrupt("return", this.request.put('/order/update-status', payload, {
6523
+ return _context44.abrupt("return", this.request.put('/order/update-status', payload, {
6371
6524
  isShopApi: true
6372
6525
  }));
6373
6526
  case 5:
6374
6527
  case "end":
6375
- return _context43.stop();
6528
+ return _context44.stop();
6376
6529
  }
6377
- }, _callee40, this);
6530
+ }, _callee41, this);
6378
6531
  }));
6379
6532
  function cancelOrder(_x46) {
6380
6533
  return _cancelOrder.apply(this, arguments);
@@ -6384,19 +6537,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6384
6537
  }, {
6385
6538
  key: "changeBookingStatus",
6386
6539
  value: function () {
6387
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
6540
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
6388
6541
  var url, payload;
6389
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6390
- while (1) switch (_context44.prev = _context44.next) {
6542
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6543
+ while (1) switch (_context45.prev = _context45.next) {
6391
6544
  case 0:
6392
6545
  if (params.booking_id) {
6393
- _context44.next = 2;
6546
+ _context45.next = 2;
6394
6547
  break;
6395
6548
  }
6396
6549
  throw new Error('变更预约状态失败:booking_id 不能为空');
6397
6550
  case 2:
6398
6551
  if (params.appointment_status) {
6399
- _context44.next = 4;
6552
+ _context45.next = 4;
6400
6553
  break;
6401
6554
  }
6402
6555
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -6411,14 +6564,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6411
6564
  bookingId: params.booking_id,
6412
6565
  appointmentStatus: params.appointment_status
6413
6566
  });
6414
- return _context44.abrupt("return", this.request.put(url, payload, {
6567
+ return _context45.abrupt("return", this.request.put(url, payload, {
6415
6568
  isShopApi: true
6416
6569
  }));
6417
6570
  case 8:
6418
6571
  case "end":
6419
- return _context44.stop();
6572
+ return _context45.stop();
6420
6573
  }
6421
- }, _callee41, this);
6574
+ }, _callee42, this);
6422
6575
  }));
6423
6576
  function changeBookingStatus(_x47) {
6424
6577
  return _changeBookingStatus.apply(this, arguments);
@@ -6438,11 +6591,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6438
6591
  }, {
6439
6592
  key: "createOrderByCheckout",
6440
6593
  value: (function () {
6441
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
6594
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
6442
6595
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3;
6443
6596
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, orderData, response;
6444
- return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6445
- while (1) switch (_context45.prev = _context45.next) {
6597
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6598
+ while (1) switch (_context46.prev = _context46.next) {
6446
6599
  case 0:
6447
6600
  // 过滤掉由在线店铺下单的 payment 支付数据
6448
6601
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -6467,7 +6620,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6467
6620
  return p.code;
6468
6621
  })) || []
6469
6622
  });
6470
- _context45.prev = 3;
6623
+ _context46.prev = 3;
6471
6624
  // 构建订单数据,设置默认值并允许 params 覆盖
6472
6625
  orderData = _objectSpread({
6473
6626
  sales_channel: 'my_pisel',
@@ -6515,30 +6668,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6515
6668
  hasOrderId: !!orderData.order_id,
6516
6669
  smallTicketDataFlag: orderData.small_ticket_data_flag
6517
6670
  });
6518
- _context45.next = 10;
6671
+ _context46.next = 10;
6519
6672
  return this.request.post('/order/checkout', orderData, {
6520
6673
  osServer: true,
6521
6674
  customToast: function customToast() {}
6522
6675
  });
6523
6676
  case 10:
6524
- response = _context45.sent;
6677
+ response = _context46.sent;
6525
6678
  this.logInfo('Order API called successfully', {
6526
6679
  response: response
6527
6680
  });
6528
- return _context45.abrupt("return", response);
6681
+ return _context46.abrupt("return", response);
6529
6682
  case 15:
6530
- _context45.prev = 15;
6531
- _context45.t0 = _context45["catch"](3);
6532
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context45.t0);
6683
+ _context46.prev = 15;
6684
+ _context46.t0 = _context46["catch"](3);
6685
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context46.t0);
6533
6686
  this.logInfo('Order API called failed', {
6534
- error: _context45.t0 instanceof Error ? _context45.t0.message : String(_context45.t0)
6687
+ error: _context46.t0 instanceof Error ? _context46.t0.message : String(_context46.t0)
6535
6688
  });
6536
- throw _context45.t0;
6689
+ throw _context46.t0;
6537
6690
  case 20:
6538
6691
  case "end":
6539
- return _context45.stop();
6692
+ return _context46.stop();
6540
6693
  }
6541
- }, _callee42, this, [[3, 15]]);
6694
+ }, _callee43, this, [[3, 15]]);
6542
6695
  }));
6543
6696
  function createOrderByCheckout(_x48) {
6544
6697
  return _createOrderByCheckout.apply(this, arguments);
@@ -6548,22 +6701,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6548
6701
  }, {
6549
6702
  key: "submitSalesOrder",
6550
6703
  value: function () {
6551
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
6704
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
6552
6705
  var url, query, fetchUrl;
6553
- return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6554
- while (1) switch (_context46.prev = _context46.next) {
6706
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6707
+ while (1) switch (_context47.prev = _context47.next) {
6555
6708
  case 0:
6556
6709
  url = params.url, query = params.query;
6557
6710
  fetchUrl = url || '/order/sales/checkout';
6558
- return _context46.abrupt("return", this.request.post(fetchUrl, query, {
6711
+ return _context47.abrupt("return", this.request.post(fetchUrl, query, {
6559
6712
  osServer: true,
6560
6713
  customToast: function customToast() {}
6561
6714
  }));
6562
6715
  case 3:
6563
6716
  case "end":
6564
- return _context46.stop();
6717
+ return _context47.stop();
6565
6718
  }
6566
- }, _callee43, this);
6719
+ }, _callee44, this);
6567
6720
  }));
6568
6721
  function submitSalesOrder(_x49) {
6569
6722
  return _submitSalesOrder.apply(this, arguments);
@@ -6579,35 +6732,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6579
6732
  }, {
6580
6733
  key: "sendCustomerPayLink",
6581
6734
  value: (function () {
6582
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
6735
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(params) {
6583
6736
  var _params$emails;
6584
6737
  var orderIds;
6585
- return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6586
- while (1) switch (_context47.prev = _context47.next) {
6738
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6739
+ while (1) switch (_context48.prev = _context48.next) {
6587
6740
  case 0:
6588
6741
  orderIds = params.order_ids || params.orderIds || [];
6589
6742
  if (orderIds.length) {
6590
- _context47.next = 3;
6743
+ _context48.next = 3;
6591
6744
  break;
6592
6745
  }
6593
6746
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
6594
6747
  case 3:
6595
6748
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
6596
- _context47.next = 5;
6749
+ _context48.next = 5;
6597
6750
  break;
6598
6751
  }
6599
6752
  throw new Error('发送支付链接需要至少一个邮箱');
6600
6753
  case 5:
6601
- return _context47.abrupt("return", this.request.post('/order/batch-email', {
6754
+ return _context48.abrupt("return", this.request.post('/order/batch-email', {
6602
6755
  order_ids: orderIds,
6603
6756
  notify_action: params.notify_action || 'order_payment_reminder',
6604
6757
  emails: params.emails
6605
6758
  }));
6606
6759
  case 6:
6607
6760
  case "end":
6608
- return _context47.stop();
6761
+ return _context48.stop();
6609
6762
  }
6610
- }, _callee44, this);
6763
+ }, _callee45, this);
6611
6764
  }));
6612
6765
  function sendCustomerPayLink(_x50) {
6613
6766
  return _sendCustomerPayLink.apply(this, arguments);
@@ -6617,14 +6770,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6617
6770
  }, {
6618
6771
  key: "getSalesOrderByLookup",
6619
6772
  value: function () {
6620
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(params) {
6773
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(params) {
6621
6774
  var lookup, res;
6622
- return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6623
- while (1) switch (_context48.prev = _context48.next) {
6775
+ return _regeneratorRuntime().wrap(function _callee46$(_context49) {
6776
+ while (1) switch (_context49.prev = _context49.next) {
6624
6777
  case 0:
6625
6778
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
6626
6779
  if (lookup) {
6627
- _context48.next = 3;
6780
+ _context49.next = 3;
6628
6781
  break;
6629
6782
  }
6630
6783
  throw new Error('加载销售详情需要 lookup');
@@ -6633,7 +6786,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6633
6786
  if (lookup.startsWith('LOCAL_')) {
6634
6787
  params.forceRemote = false;
6635
6788
  }
6636
- _context48.next = 6;
6789
+ _context49.next = 6;
6637
6790
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
6638
6791
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds', 'notes']
6639
6792
  }, params.forceRemote ? {
@@ -6642,16 +6795,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6642
6795
  osServer: true
6643
6796
  });
6644
6797
  case 6:
6645
- res = _context48.sent;
6798
+ res = _context49.sent;
6646
6799
  if (res.code === 200) {
6647
6800
  this.store.lastOrderInfo = res.data;
6648
6801
  }
6649
- return _context48.abrupt("return", res);
6802
+ return _context49.abrupt("return", res);
6650
6803
  case 9:
6651
6804
  case "end":
6652
- return _context48.stop();
6805
+ return _context49.stop();
6653
6806
  }
6654
- }, _callee45, this);
6807
+ }, _callee46, this);
6655
6808
  }));
6656
6809
  function getSalesOrderByLookup(_x51) {
6657
6810
  return _getSalesOrderByLookup.apply(this, arguments);
@@ -6667,11 +6820,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6667
6820
  }, {
6668
6821
  key: "hydrateTempOrderFromRecord",
6669
6822
  value: (function () {
6670
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(record, options) {
6823
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(record, options) {
6671
6824
  var _sourceRaw$_extend, _this$store$discount26;
6672
6825
  var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, isMergedSalesDetailHydrate, nextTempOrder, _this$store$discount24, _this$store$discount25, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, historicalDepositSnapshot, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount27, _this$store$discount28;
6673
- return _regeneratorRuntime().wrap(function _callee46$(_context49) {
6674
- while (1) switch (_context49.prev = _context49.next) {
6826
+ return _regeneratorRuntime().wrap(function _callee47$(_context50) {
6827
+ while (1) switch (_context50.prev = _context50.next) {
6675
6828
  case 0:
6676
6829
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
6677
6830
  duplicateProductIdentityRepair = repairDuplicateOrderProductLineIdentities(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], (_sourceRaw$_extend = sourceRaw._extend) === null || _sourceRaw$_extend === void 0 ? void 0 : _sourceRaw$_extend.productsByUid);
@@ -6712,7 +6865,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6712
6865
  });
6713
6866
  this.store.tempOrder = nextTempOrder;
6714
6867
  if (!isSessionStorageHydrate) {
6715
- _context49.next = 30;
6868
+ _context50.next = 30;
6716
6869
  break;
6717
6870
  }
6718
6871
  // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
@@ -6728,23 +6881,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6728
6881
  nextTempOrder.discount_list = restoredSessionDiscounts;
6729
6882
  this.store.summary = createEmptySummary();
6730
6883
  this.store.lastOrderInfo = undefined;
6731
- _context49.next = 23;
6884
+ _context50.next = 23;
6732
6885
  return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6733
6886
  case 23:
6734
- _context49.next = 25;
6887
+ _context50.next = 25;
6735
6888
  return (_this$store$discount25 = this.store.discount) === null || _this$store$discount25 === void 0 ? void 0 : _this$store$discount25.setDiscountList(cloneDeep(restoredSessionDiscounts));
6736
6889
  case 25:
6737
6890
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6738
- _context49.next = 28;
6891
+ _context50.next = 28;
6739
6892
  break;
6740
6893
  }
6741
- _context49.next = 28;
6894
+ _context50.next = 28;
6742
6895
  return this.recalculateSummary({
6743
6896
  createIfMissing: false
6744
6897
  });
6745
6898
  case 28:
6746
6899
  this.persistTempOrder();
6747
- return _context49.abrupt("return", nextTempOrder);
6900
+ return _context50.abrupt("return", nextTempOrder);
6748
6901
  case 30:
6749
6902
  // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6750
6903
  sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
@@ -6796,32 +6949,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6796
6949
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
6797
6950
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
6798
6951
  if (shouldSkipEmptyDiscountSync) {
6799
- _context49.next = 54;
6952
+ _context50.next = 54;
6800
6953
  break;
6801
6954
  }
6802
6955
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
6803
- _context49.next = 52;
6956
+ _context50.next = 52;
6804
6957
  return (_this$store$discount27 = this.store.discount) === null || _this$store$discount27 === void 0 ? void 0 : _this$store$discount27.setOriginalDiscountList(nextDiscounts);
6805
6958
  case 52:
6806
- _context49.next = 54;
6959
+ _context50.next = 54;
6807
6960
  return (_this$store$discount28 = this.store.discount) === null || _this$store$discount28 === void 0 ? void 0 : _this$store$discount28.setDiscountList(nextDiscounts);
6808
6961
  case 54:
6809
6962
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6810
- _context49.next = 57;
6963
+ _context50.next = 57;
6811
6964
  break;
6812
6965
  }
6813
- _context49.next = 57;
6966
+ _context50.next = 57;
6814
6967
  return this.recalculateSummary({
6815
6968
  createIfMissing: false
6816
6969
  });
6817
6970
  case 57:
6818
6971
  this.persistTempOrder();
6819
- return _context49.abrupt("return", nextTempOrder);
6972
+ return _context50.abrupt("return", nextTempOrder);
6820
6973
  case 59:
6821
6974
  case "end":
6822
- return _context49.stop();
6975
+ return _context50.stop();
6823
6976
  }
6824
- }, _callee46, this);
6977
+ }, _callee47, this);
6825
6978
  }));
6826
6979
  function hydrateTempOrderFromRecord(_x52, _x53) {
6827
6980
  return _hydrateTempOrderFromRecord.apply(this, arguments);
@@ -6876,10 +7029,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6876
7029
  _step22;
6877
7030
  try {
6878
7031
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
6879
- var _product$metadata10;
7032
+ var _product$metadata11;
6880
7033
  var product = _step22.value;
6881
7034
  var productUid = getOrderCollectionUid('product', product);
6882
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.booking_uid);
7035
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.booking_uid);
6883
7036
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
6884
7037
  continue;
6885
7038
  }
@@ -6898,12 +7051,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6898
7051
  _step23;
6899
7052
  try {
6900
7053
  for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
6901
- var _booking$metadata7;
7054
+ var _booking$metadata9;
6902
7055
  var booking = _step23.value;
6903
7056
  if (getOrderCollectionPersistentId('booking', booking) || getOrderCollectionUid('booking', booking)) {
6904
7057
  continue;
6905
7058
  }
6906
- var _productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.product_uid);
7059
+ var _productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata9 = booking.metadata) === null || _booking$metadata9 === void 0 ? void 0 : _booking$metadata9.product_uid);
6907
7060
  if (_productUid === undefined || _productUid === null || _productUid === '') continue;
6908
7061
  var key = String(_productUid);
6909
7062
  anonymousBookingCountByProductUid.set(key, (anonymousBookingCountByProductUid.get(key) || 0) + 1);
@@ -6915,11 +7068,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6915
7068
  }
6916
7069
  return _objectSpread(_objectSpread({}, raw), {}, {
6917
7070
  bookings: raw.bookings.map(function (booking) {
6918
- var _booking$metadata6;
7071
+ var _booking$metadata8;
6919
7072
  if (getOrderCollectionPersistentId('booking', booking) || getOrderCollectionUid('booking', booking)) {
6920
7073
  return booking;
6921
7074
  }
6922
- var productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata6 = booking.metadata) === null || _booking$metadata6 === void 0 ? void 0 : _booking$metadata6.product_uid);
7075
+ var productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata8 = booking.metadata) === null || _booking$metadata8 === void 0 ? void 0 : _booking$metadata8.product_uid);
6923
7076
  if (productUid === undefined || productUid === null || productUid === '') {
6924
7077
  return booking;
6925
7078
  }
@@ -7016,15 +7169,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7016
7169
  _step24;
7017
7170
  try {
7018
7171
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
7019
- var _product$metadata11, _ref77, _ref78, _existed$origin, _rawProduct$metadata;
7172
+ var _product$metadata12, _ref79, _ref80, _existed$origin, _rawProduct$metadata;
7020
7173
  var _step24$value = _slicedToArray(_step24.value, 2),
7021
7174
  index = _step24$value[0],
7022
7175
  product = _step24$value[1];
7023
- var uid = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number;
7176
+ var uid = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number;
7024
7177
  if (!uid) continue;
7025
7178
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
7026
7179
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
7027
- var origin = (_ref77 = (_ref78 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref78 !== void 0 ? _ref78 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref77 !== void 0 ? _ref77 : rawProduct;
7180
+ var origin = (_ref79 = (_ref80 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref80 !== void 0 ? _ref80 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref79 !== void 0 ? _ref79 : rawProduct;
7028
7181
  var originSnapshot = cloneDeep(origin);
7029
7182
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
7030
7183
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -7075,8 +7228,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7075
7228
  var bookingUidByProductUid = new Map();
7076
7229
  var productByUid = new Map();
7077
7230
  (tempOrder.products || []).forEach(function (product) {
7078
- var _product$metadata12;
7079
- var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7231
+ var _product$metadata13;
7232
+ var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7080
7233
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
7081
7234
  productByUid.set(String(productUid), product);
7082
7235
  }
@@ -7097,8 +7250,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7097
7250
  bookingUidByProductUid.set(String(productUid), bookingUid);
7098
7251
  });
7099
7252
  (tempOrder.products || []).forEach(function (product) {
7100
- var _product$metadata13;
7101
- var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7253
+ var _product$metadata14;
7254
+ var productUid = (product === null || product === void 0 || (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7102
7255
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
7103
7256
  var bookingUid = bookingUidByProductUid.get(String(productUid));
7104
7257
  if (!bookingUid) return;
@@ -7153,10 +7306,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7153
7306
  }, {
7154
7307
  key: "normalizeHydratedProductOptionItem",
7155
7308
  value: function normalizeHydratedProductOptionItem(optionItem) {
7156
- var _ref79, _optionItem$num, _ref80, _optionItem$add_price;
7157
- var rawNum = (_ref79 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1;
7309
+ var _ref81, _optionItem$num, _ref82, _optionItem$add_price;
7310
+ var rawNum = (_ref81 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref81 !== void 0 ? _ref81 : 1;
7158
7311
  var parsedNum = Number(rawNum);
7159
- var rawPrice = (_ref80 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref80 !== void 0 ? _ref80 : 0;
7312
+ var rawPrice = (_ref82 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref82 !== void 0 ? _ref82 : 0;
7160
7313
  var parsedPrice = Number(rawPrice);
7161
7314
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
7162
7315
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -7221,25 +7374,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7221
7374
  }, {
7222
7375
  key: "getOrderInfo",
7223
7376
  value: function () {
7224
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(order_id) {
7377
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(order_id) {
7225
7378
  var res;
7226
- return _regeneratorRuntime().wrap(function _callee47$(_context50) {
7227
- while (1) switch (_context50.prev = _context50.next) {
7379
+ return _regeneratorRuntime().wrap(function _callee48$(_context51) {
7380
+ while (1) switch (_context51.prev = _context51.next) {
7228
7381
  case 0:
7229
- _context50.next = 2;
7382
+ _context51.next = 2;
7230
7383
  return this.request.get("/order/sales/".concat(order_id), {
7231
7384
  with: ['products', 'bookings', 'notes']
7232
7385
  }, {
7233
7386
  osServer: true
7234
7387
  });
7235
7388
  case 2:
7236
- res = _context50.sent;
7237
- return _context50.abrupt("return", res);
7389
+ res = _context51.sent;
7390
+ return _context51.abrupt("return", res);
7238
7391
  case 4:
7239
7392
  case "end":
7240
- return _context50.stop();
7393
+ return _context51.stop();
7241
7394
  }
7242
- }, _callee47, this);
7395
+ }, _callee48, this);
7243
7396
  }));
7244
7397
  function getOrderInfo(_x54) {
7245
7398
  return _getOrderInfo.apply(this, arguments);
@@ -7249,8 +7402,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7249
7402
  }, {
7250
7403
  key: "getVouchers",
7251
7404
  value: function getVouchers() {
7252
- var _this$store$tempOrder5;
7253
- return ((_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.vouchers) || [];
7405
+ var _this$store$tempOrder6;
7406
+ return ((_this$store$tempOrder6 = this.store.tempOrder) === null || _this$store$tempOrder6 === void 0 ? void 0 : _this$store$tempOrder6.vouchers) || [];
7254
7407
  }
7255
7408
  }], [{
7256
7409
  key: "populateSavedAmounts",