@pisell/pisellos 2.2.192 → 2.2.194

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  2. package/dist/modules/Order/index.d.ts +12 -9
  3. package/dist/modules/Order/index.js +503 -580
  4. package/dist/modules/Order/types.d.ts +5 -5
  5. package/dist/modules/Order/utils/manualProductDiscount.js +1 -1
  6. package/dist/modules/Order/utils.js +3 -3
  7. package/dist/modules/Payment/utils.js +2 -1
  8. package/dist/modules/SalesSummary/index.d.ts +0 -25
  9. package/dist/modules/SalesSummary/types.d.ts +1 -0
  10. package/dist/modules/SalesSummary/utils.d.ts +2 -25
  11. package/dist/modules/SalesSummary/utils.js +529 -160
  12. package/dist/server/index.d.ts +8 -1
  13. package/dist/server/index.js +653 -466
  14. package/dist/server/modules/order/index.d.ts +3 -2
  15. package/dist/server/modules/order/index.js +68 -52
  16. package/dist/server/modules/products/index.js +4 -4
  17. package/dist/solution/BaseSales/index.d.ts +2 -1
  18. package/dist/solution/BaseSales/index.js +116 -122
  19. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  20. package/dist/solution/ScanOrder/index.js +3 -1
  21. package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
  22. package/lib/modules/Order/index.d.ts +12 -9
  23. package/lib/modules/Order/index.js +124 -120
  24. package/lib/modules/Order/types.d.ts +5 -5
  25. package/lib/modules/Order/utils/manualProductDiscount.js +1 -1
  26. package/lib/modules/Order/utils.js +4 -4
  27. package/lib/modules/Payment/utils.js +2 -1
  28. package/lib/modules/SalesSummary/index.d.ts +0 -25
  29. package/lib/modules/SalesSummary/types.d.ts +1 -0
  30. package/lib/modules/SalesSummary/utils.d.ts +2 -25
  31. package/lib/modules/SalesSummary/utils.js +420 -92
  32. package/lib/server/index.d.ts +8 -1
  33. package/lib/server/index.js +145 -26
  34. package/lib/server/modules/order/index.d.ts +3 -2
  35. package/lib/server/modules/order/index.js +25 -15
  36. package/lib/server/modules/products/index.js +0 -4
  37. package/lib/solution/BaseSales/index.d.ts +2 -1
  38. package/lib/solution/BaseSales/index.js +53 -16
  39. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  40. package/lib/solution/ScanOrder/index.js +3 -1
  41. package/package.json +1 -1
@@ -41,7 +41,21 @@ import { RulesModule } from "../Rules";
41
41
  import { UnavailableReason } from "../Rules/types";
42
42
  import Decimal from 'decimal.js';
43
43
  import { cloneDeep } from 'lodash-es';
44
- var LOCAL_ORDER_STORE_NAME = 'orders';
44
+ function normalizeDiscountListSignature(discountList) {
45
+ return (discountList || []).map(function (item) {
46
+ var _item$type, _item$discount_id, _item$order_discount_;
47
+ return {
48
+ type: (_item$type = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type !== void 0 ? _item$type : '',
49
+ discount_id: (_item$discount_id = item === null || item === void 0 ? void 0 : item.discount_id) !== null && _item$discount_id !== void 0 ? _item$discount_id : null,
50
+ order_discount_id: (_item$order_discount_ = item === null || item === void 0 ? void 0 : item.order_discount_id) !== null && _item$order_discount_ !== void 0 ? _item$order_discount_ : null,
51
+ amount: new Decimal(Number(item === null || item === void 0 ? void 0 : item.amount) || 0).toFixed(2)
52
+ };
53
+ });
54
+ }
55
+ function isSameDiscountList(left, right) {
56
+ if (!Array.isArray(left) || !Array.isArray(right)) return false;
57
+ return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(normalizeDiscountListSignature(right));
58
+ }
45
59
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
46
60
  _inherits(OrderModule, _BaseModule);
47
61
  var _super = _createSuper(OrderModule);
@@ -55,7 +69,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
55
69
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
56
70
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
57
71
  // LoggerManager 实例
58
- _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
59
72
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
60
73
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
61
74
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
@@ -86,6 +99,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
86
99
  return (products || []).map(function (product) {
87
100
  var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
88
101
  if ((_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.is_manual_discount) return product;
102
+ var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
103
+ var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
104
+ return (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== undefined && (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null;
105
+ });
106
+ if (hasOnlyPersistedDiscountSnapshots) {
107
+ return product;
108
+ }
89
109
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
90
110
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
91
111
  var sourcePrice = (_product$metadata$sou = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
@@ -129,7 +149,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
129
149
  case 8:
130
150
  app = appPlugin.getApp();
131
151
  this.logger = app.logger;
132
- this.dbManager = app.sqlite;
133
152
  this.window = this.core.getPlugin('window');
134
153
  otherParams = options.otherParams || {};
135
154
  this.cacheId = otherParams.cacheId;
@@ -139,7 +158,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
139
158
  this.otherParams = otherParams;
140
159
  this.registerDiscountModules(options);
141
160
  this.logInfo('OrderModule initialized successfully');
142
- case 20:
161
+ case 19:
143
162
  case "end":
144
163
  return _context.stop();
145
164
  }
@@ -880,211 +899,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
880
899
  return "".concat(baseToken, "_payment_").concat(paidCount);
881
900
  }
882
901
  }, {
883
- key: "hasLocalDatabase",
884
- value: function hasLocalDatabase() {
885
- return !!this.dbManager;
886
- }
887
- }, {
888
- key: "buildLocalOrderRecord",
889
- value: function buildLocalOrderRecord(tempOrder) {
890
- var _tempOrder$order_id;
891
- var externalSaleNumber = this.ensureExternalSaleNumber(tempOrder);
892
- return _objectSpread(_objectSpread({}, tempOrder), {}, {
893
- id: (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : externalSaleNumber,
894
- external_sale_number: externalSaleNumber,
895
- summary: this.store.summary || createEmptySummary(),
896
- lastOrderInfo: this.store.lastOrderInfo
897
- });
898
- }
899
- }, {
900
- key: "getLocalOrderByOrderId",
902
+ key: "saveDraft",
901
903
  value: function () {
902
- var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderId) {
903
- var _this$dbManager$get, _this$dbManager, _this$dbManager$getAl, _this$dbManager2, direct, orders;
904
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
904
905
  return _regeneratorRuntime().wrap(function _callee5$(_context7) {
905
906
  while (1) switch (_context7.prev = _context7.next) {
906
907
  case 0:
907
- if (!(!this.dbManager || orderId === undefined || orderId === null)) {
908
- _context7.next = 2;
909
- break;
910
- }
911
- return _context7.abrupt("return", null);
912
- case 2:
913
- _context7.prev = 2;
914
- _context7.next = 5;
915
- return (_this$dbManager$get = (_this$dbManager = this.dbManager).get) === null || _this$dbManager$get === void 0 ? void 0 : _this$dbManager$get.call(_this$dbManager, LOCAL_ORDER_STORE_NAME, orderId);
916
- case 5:
917
- direct = _context7.sent;
918
- if (!direct) {
919
- _context7.next = 8;
920
- break;
921
- }
922
- return _context7.abrupt("return", direct);
923
- case 8:
924
- _context7.next = 10;
925
- return (_this$dbManager$getAl = (_this$dbManager2 = this.dbManager).getAll) === null || _this$dbManager$getAl === void 0 ? void 0 : _this$dbManager$getAl.call(_this$dbManager2, LOCAL_ORDER_STORE_NAME);
926
- case 10:
927
- orders = _context7.sent;
928
- return _context7.abrupt("return", (orders || []).find(function (order) {
929
- return String(order === null || order === void 0 ? void 0 : order.order_id) === String(orderId);
930
- }) || null);
931
- case 14:
932
- _context7.prev = 14;
933
- _context7.t0 = _context7["catch"](2);
934
- this.logWarning('getLocalOrderByOrderId failed', {
935
- orderId: orderId,
936
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
937
- });
938
- return _context7.abrupt("return", null);
939
- case 18:
940
908
  case "end":
941
909
  return _context7.stop();
942
910
  }
943
- }, _callee5, this, [[2, 14]]);
944
- }));
945
- function getLocalOrderByOrderId(_x6) {
946
- return _getLocalOrderByOrderId.apply(this, arguments);
947
- }
948
- return getLocalOrderByOrderId;
949
- }()
950
- }, {
951
- key: "getLocalOrderByOrderNumber",
952
- value: function () {
953
- var _getLocalOrderByOrderNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderNumber) {
954
- var _this$dbManager$get2, _this$dbManager3, _this$dbManager$getAl2, _this$dbManager4, direct, orders;
955
- return _regeneratorRuntime().wrap(function _callee6$(_context8) {
956
- while (1) switch (_context8.prev = _context8.next) {
957
- case 0:
958
- if (!(!this.dbManager || !orderNumber)) {
959
- _context8.next = 2;
960
- break;
961
- }
962
- return _context8.abrupt("return", null);
963
- case 2:
964
- _context8.prev = 2;
965
- _context8.next = 5;
966
- return (_this$dbManager$get2 = (_this$dbManager3 = this.dbManager).get) === null || _this$dbManager$get2 === void 0 ? void 0 : _this$dbManager$get2.call(_this$dbManager3, LOCAL_ORDER_STORE_NAME, orderNumber);
967
- case 5:
968
- direct = _context8.sent;
969
- if (!direct) {
970
- _context8.next = 8;
971
- break;
972
- }
973
- return _context8.abrupt("return", direct);
974
- case 8:
975
- _context8.next = 10;
976
- return (_this$dbManager$getAl2 = (_this$dbManager4 = this.dbManager).getAll) === null || _this$dbManager$getAl2 === void 0 ? void 0 : _this$dbManager$getAl2.call(_this$dbManager4, LOCAL_ORDER_STORE_NAME);
977
- case 10:
978
- orders = _context8.sent;
979
- return _context8.abrupt("return", (orders || []).find(function (order) {
980
- return String(order === null || order === void 0 ? void 0 : order.order_number) === String(orderNumber);
981
- }) || null);
982
- case 14:
983
- _context8.prev = 14;
984
- _context8.t0 = _context8["catch"](2);
985
- this.logWarning('getLocalOrderByOrderNumber failed', {
986
- orderNumber: orderNumber,
987
- error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
988
- });
989
- return _context8.abrupt("return", null);
990
- case 18:
991
- case "end":
992
- return _context8.stop();
993
- }
994
- }, _callee6, this, [[2, 14]]);
995
- }));
996
- function getLocalOrderByOrderNumber(_x7) {
997
- return _getLocalOrderByOrderNumber.apply(this, arguments);
998
- }
999
- return getLocalOrderByOrderNumber;
1000
- }()
1001
- }, {
1002
- key: "getLocalOrderByExternalSaleNumber",
1003
- value: function () {
1004
- var _getLocalOrderByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(externalSaleNumber) {
1005
- var _this$dbManager$get3, _this$dbManager5, _this$dbManager$getAl3, _this$dbManager6, direct, orders;
1006
- return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1007
- while (1) switch (_context9.prev = _context9.next) {
1008
- case 0:
1009
- if (!(!this.dbManager || !externalSaleNumber)) {
1010
- _context9.next = 2;
1011
- break;
1012
- }
1013
- return _context9.abrupt("return", null);
1014
- case 2:
1015
- _context9.prev = 2;
1016
- _context9.next = 5;
1017
- return (_this$dbManager$get3 = (_this$dbManager5 = this.dbManager).get) === null || _this$dbManager$get3 === void 0 ? void 0 : _this$dbManager$get3.call(_this$dbManager5, LOCAL_ORDER_STORE_NAME, externalSaleNumber);
1018
- case 5:
1019
- direct = _context9.sent;
1020
- if (!direct) {
1021
- _context9.next = 8;
1022
- break;
1023
- }
1024
- return _context9.abrupt("return", direct);
1025
- case 8:
1026
- _context9.next = 10;
1027
- return (_this$dbManager$getAl3 = (_this$dbManager6 = this.dbManager).getAll) === null || _this$dbManager$getAl3 === void 0 ? void 0 : _this$dbManager$getAl3.call(_this$dbManager6, LOCAL_ORDER_STORE_NAME);
1028
- case 10:
1029
- orders = _context9.sent;
1030
- return _context9.abrupt("return", (orders || []).find(function (order) {
1031
- return String(order === null || order === void 0 ? void 0 : order.external_sale_number) === String(externalSaleNumber);
1032
- }) || null);
1033
- case 14:
1034
- _context9.prev = 14;
1035
- _context9.t0 = _context9["catch"](2);
1036
- this.logWarning('getLocalOrderByExternalSaleNumber failed', {
1037
- externalSaleNumber: externalSaleNumber,
1038
- error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0)
1039
- });
1040
- return _context9.abrupt("return", null);
1041
- case 18:
1042
- case "end":
1043
- return _context9.stop();
1044
- }
1045
- }, _callee7, this, [[2, 14]]);
1046
- }));
1047
- function getLocalOrderByExternalSaleNumber(_x8) {
1048
- return _getLocalOrderByExternalSaleNumber.apply(this, arguments);
1049
- }
1050
- return getLocalOrderByExternalSaleNumber;
1051
- }()
1052
- }, {
1053
- key: "saveDraft",
1054
- value: function () {
1055
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1056
- var tempOrder, record, _this$dbManager$updat, _this$dbManager7;
1057
- return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1058
- while (1) switch (_context10.prev = _context10.next) {
1059
- case 0:
1060
- if (!(!this.draftPersistEnabled || !this.dbManager)) {
1061
- _context10.next = 2;
1062
- break;
1063
- }
1064
- return _context10.abrupt("return");
1065
- case 2:
1066
- tempOrder = this.ensureTempOrder();
1067
- record = this.buildLocalOrderRecord(tempOrder);
1068
- _context10.prev = 4;
1069
- _context10.next = 7;
1070
- return (_this$dbManager$updat = (_this$dbManager7 = this.dbManager).update) === null || _this$dbManager$updat === void 0 ? void 0 : _this$dbManager$updat.call(_this$dbManager7, LOCAL_ORDER_STORE_NAME, record);
1071
- case 7:
1072
- _context10.next = 12;
1073
- break;
1074
- case 9:
1075
- _context10.prev = 9;
1076
- _context10.t0 = _context10["catch"](4);
1077
- this.logWarning('saveDraft failed', {
1078
- externalSaleNumber: tempOrder.external_sale_number,
1079
- orderNumber: tempOrder.order_number,
1080
- orderId: tempOrder.order_id,
1081
- error: _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0)
1082
- });
1083
- case 12:
1084
- case "end":
1085
- return _context10.stop();
1086
- }
1087
- }, _callee8, this, [[4, 9]]);
911
+ }, _callee5);
1088
912
  }));
1089
913
  function saveDraft() {
1090
914
  return _saveDraft.apply(this, arguments);
@@ -1099,18 +923,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1099
923
  }, {
1100
924
  key: "hydrateTempOrderFromLocalRecord",
1101
925
  value: function () {
1102
- var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
1103
- return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1104
- while (1) switch (_context11.prev = _context11.next) {
926
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(record) {
927
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
928
+ while (1) switch (_context8.prev = _context8.next) {
1105
929
  case 0:
1106
- return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
930
+ return _context8.abrupt("return", this.hydrateTempOrderFromRecord(record));
1107
931
  case 1:
1108
932
  case "end":
1109
- return _context11.stop();
933
+ return _context8.stop();
1110
934
  }
1111
- }, _callee9, this);
935
+ }, _callee6, this);
1112
936
  }));
1113
- function hydrateTempOrderFromLocalRecord(_x9) {
937
+ function hydrateTempOrderFromLocalRecord(_x6) {
1114
938
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
1115
939
  }
1116
940
  return hydrateTempOrderFromLocalRecord;
@@ -1161,6 +985,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1161
985
  }, {
1162
986
  key: "updateTempOrderPaymentStatus",
1163
987
  value: function updateTempOrderPaymentStatus(tempOrder) {
988
+ if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
989
+ return;
990
+ }
1164
991
  var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
1165
992
  var targetAmount = this.getPaymentTargetAmount();
1166
993
  if (targetAmount.lte(0)) {
@@ -1168,11 +995,59 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1168
995
  return;
1169
996
  }
1170
997
  if (paymentTotal.lte(0)) {
1171
- tempOrder.payment_status = tempOrder.payment_status || 'payment_processing';
998
+ tempOrder.payment_status = 'payment_processing';
1172
999
  return;
1173
1000
  }
1174
1001
  tempOrder.payment_status = paymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
1175
1002
  }
1003
+ }, {
1004
+ key: "shouldKeepPaymentStatusAfterAmountRecalc",
1005
+ value: function shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
1006
+ var normalizedStatus = String(paymentStatus || '').trim().toLowerCase();
1007
+ return normalizedStatus === 'refunded' || normalizedStatus === 'partially_refunded';
1008
+ }
1009
+ }, {
1010
+ key: "resolveWalletPassUseValue",
1011
+ value: function resolveWalletPassUseValue(payment, amount) {
1012
+ var usageUnit = payment.wallet_pass_usage_unit && _typeof(payment.wallet_pass_usage_unit) === 'object' ? payment.wallet_pass_usage_unit : null;
1013
+ if (!usageUnit) return payment.wallet_pass_use_value;
1014
+ var price = new Decimal(usageUnit.price || 0);
1015
+ var points = new Decimal(usageUnit.points || 0);
1016
+ if (price.lte(0) || points.lte(0)) return payment.wallet_pass_use_value;
1017
+ return amount.div(price).times(points).toDecimalPlaces(2).toFixed(2);
1018
+ }
1019
+ }, {
1020
+ key: "capVoucherPaymentsByRemainingAmount",
1021
+ value: function capVoucherPaymentsByRemainingAmount(params) {
1022
+ var targetAmount = this.getPaymentTargetAmount();
1023
+ var nonVoucherTotal = this.calculatePaymentTotal(params.nonVoucherPayments);
1024
+ if (targetAmount.lte(0)) return [];
1025
+ var remainingAmount = Decimal.max(targetAmount.minus(nonVoucherTotal), 0);
1026
+ var cappedVouchers = [];
1027
+ var _iterator5 = _createForOfIteratorHelper(params.vouchers),
1028
+ _step5;
1029
+ try {
1030
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1031
+ var voucher = _step5.value;
1032
+ if (remainingAmount.lte(0)) break;
1033
+ var voucherAmount = Decimal.max(new Decimal(voucher.amount || 0), 0);
1034
+ if (voucherAmount.lte(0)) continue;
1035
+ var cappedAmount = Decimal.min(voucherAmount, remainingAmount);
1036
+ var amountText = cappedAmount.toDecimalPlaces(2).toFixed(2);
1037
+ cappedVouchers.push(_objectSpread(_objectSpread({}, voucher), {}, {
1038
+ amount: amountText,
1039
+ origin_amount: amountText,
1040
+ wallet_pass_use_value: this.resolveWalletPassUseValue(voucher, cappedAmount)
1041
+ }));
1042
+ remainingAmount = remainingAmount.minus(cappedAmount);
1043
+ }
1044
+ } catch (err) {
1045
+ _iterator5.e(err);
1046
+ } finally {
1047
+ _iterator5.f();
1048
+ }
1049
+ return cappedVouchers;
1050
+ }
1176
1051
  }, {
1177
1052
  key: "calculatePaidPaymentSummary",
1178
1053
  value: function calculatePaidPaymentSummary(payments) {
@@ -1183,7 +1058,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1183
1058
  return {
1184
1059
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1185
1060
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
1186
- gapPaidAmount: summary.gapPaidAmount.plus(_this4.calculatePaymentEffectiveAmount(paymentRecord)),
1061
+ gapPaidAmount: summary.gapPaidAmount.plus(_this4.calculatePaymentGapAmount(paymentRecord)),
1187
1062
  payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this4.calculatePaymentServiceFee(paymentRecord))
1188
1063
  };
1189
1064
  }, {
@@ -1204,6 +1079,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1204
1079
  var fixedAmount = new Decimal(serviceCharge.amount || 0);
1205
1080
  return new Decimal(payment.amount || 0).times(percentage).plus(fixedAmount);
1206
1081
  }
1082
+ }, {
1083
+ key: "calculatePaymentGapAmount",
1084
+ value: function calculatePaymentGapAmount(payment) {
1085
+ if (payment.origin_amount === undefined || payment.origin_amount === null || payment.origin_amount === '') {
1086
+ return new Decimal(0);
1087
+ }
1088
+ var rounding = new Decimal(payment.rounding_amount || 0);
1089
+ return new Decimal(payment.origin_amount || 0).minus(rounding);
1090
+ }
1207
1091
  }, {
1208
1092
  key: "formatSummaryMetadataMoney",
1209
1093
  value: function formatSummaryMetadataMoney(value) {
@@ -1215,28 +1099,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1215
1099
  key: "syncSummaryProductMetadata",
1216
1100
  value: function syncSummaryProductMetadata(products) {
1217
1101
  var moneyKeys = ['main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_tax_fee', 'surcharge_rounding_remainder', 'tax_fee_rounding_remainder'];
1218
- var _iterator5 = _createForOfIteratorHelper(products || []),
1219
- _step5;
1102
+ var _iterator6 = _createForOfIteratorHelper(products || []),
1103
+ _step6;
1220
1104
  try {
1221
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1222
- var product = _step5.value;
1105
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1106
+ var product = _step6.value;
1223
1107
  var productRecord = product;
1224
1108
  var metadata = productRecord.metadata && _typeof(productRecord.metadata) === 'object' ? _objectSpread({}, productRecord.metadata) : {};
1225
1109
  var hasMetadataPatch = false;
1226
- var _iterator6 = _createForOfIteratorHelper(moneyKeys),
1227
- _step6;
1110
+ var _iterator7 = _createForOfIteratorHelper(moneyKeys),
1111
+ _step7;
1228
1112
  try {
1229
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1230
- var key = _step6.value;
1113
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1114
+ var key = _step7.value;
1231
1115
  var value = this.formatSummaryMetadataMoney(productRecord[key]);
1232
1116
  if (value === undefined) continue;
1233
1117
  metadata[key] = value;
1234
1118
  hasMetadataPatch = true;
1235
1119
  }
1236
1120
  } catch (err) {
1237
- _iterator6.e(err);
1121
+ _iterator7.e(err);
1238
1122
  } finally {
1239
- _iterator6.f();
1123
+ _iterator7.f();
1240
1124
  }
1241
1125
  if (Array.isArray(productRecord.relation_surcharge_ids)) {
1242
1126
  metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
@@ -1244,11 +1128,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1244
1128
  }
1245
1129
  if (hasMetadataPatch) productRecord.metadata = metadata;
1246
1130
  if (!Array.isArray(productRecord.product_bundle)) continue;
1247
- var _iterator7 = _createForOfIteratorHelper(productRecord.product_bundle),
1248
- _step7;
1131
+ var _iterator8 = _createForOfIteratorHelper(productRecord.product_bundle),
1132
+ _step8;
1249
1133
  try {
1250
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1251
- var bundle = _step7.value;
1134
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1135
+ var bundle = _step8.value;
1252
1136
  var bundleRecord = bundle;
1253
1137
  var bundleMetadata = bundleRecord.metadata && _typeof(bundleRecord.metadata) === 'object' ? _objectSpread({}, bundleRecord.metadata) : {};
1254
1138
  var hasBundleMetadataPatch = false;
@@ -1264,15 +1148,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1264
1148
  if (hasBundleMetadataPatch) bundleRecord.metadata = bundleMetadata;
1265
1149
  }
1266
1150
  } catch (err) {
1267
- _iterator7.e(err);
1151
+ _iterator8.e(err);
1268
1152
  } finally {
1269
- _iterator7.f();
1153
+ _iterator8.f();
1270
1154
  }
1271
1155
  }
1272
1156
  } catch (err) {
1273
- _iterator5.e(err);
1157
+ _iterator6.e(err);
1274
1158
  } finally {
1275
- _iterator5.f();
1159
+ _iterator6.f();
1276
1160
  }
1277
1161
  }
1278
1162
  }, {
@@ -1332,13 +1216,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1332
1216
  }, {
1333
1217
  key: "replaceTempOrder",
1334
1218
  value: function () {
1335
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
1219
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(tempOrder, options) {
1336
1220
  var nextTempOrder;
1337
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1338
- while (1) switch (_context12.prev = _context12.next) {
1221
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1222
+ while (1) switch (_context9.prev = _context9.next) {
1339
1223
  case 0:
1340
1224
  if (isTempOrder(tempOrder)) {
1341
- _context12.next = 2;
1225
+ _context9.next = 2;
1342
1226
  break;
1343
1227
  }
1344
1228
  throw new Error('无效的 tempOrder 数据');
@@ -1348,15 +1232,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1348
1232
  });
1349
1233
  this.store.tempOrder = nextTempOrder;
1350
1234
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1351
- _context12.next = 9;
1235
+ _context9.next = 9;
1352
1236
  break;
1353
1237
  }
1354
- _context12.next = 7;
1238
+ _context9.next = 7;
1355
1239
  return this.recalculateSummary({
1356
1240
  createIfMissing: false
1357
1241
  });
1358
1242
  case 7:
1359
- _context12.next = 10;
1243
+ _context9.next = 10;
1360
1244
  break;
1361
1245
  case 9:
1362
1246
  this.store.summary = createEmptySummary();
@@ -1365,20 +1249,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1365
1249
  this.persistTempOrder();
1366
1250
  }
1367
1251
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
1368
- _context12.next = 14;
1252
+ _context9.next = 14;
1369
1253
  break;
1370
1254
  }
1371
- _context12.next = 14;
1255
+ _context9.next = 14;
1372
1256
  return this.saveDraft();
1373
1257
  case 14:
1374
- return _context12.abrupt("return", nextTempOrder);
1258
+ return _context9.abrupt("return", nextTempOrder);
1375
1259
  case 15:
1376
1260
  case "end":
1377
- return _context12.stop();
1261
+ return _context9.stop();
1378
1262
  }
1379
- }, _callee10, this);
1263
+ }, _callee7, this);
1380
1264
  }));
1381
- function replaceTempOrder(_x10, _x11) {
1265
+ function replaceTempOrder(_x7, _x8) {
1382
1266
  return _replaceTempOrder.apply(this, arguments);
1383
1267
  }
1384
1268
  return replaceTempOrder;
@@ -1386,11 +1270,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1386
1270
  }, {
1387
1271
  key: "getOrderIdentity",
1388
1272
  value: function getOrderIdentity() {
1389
- var _ref7, _ref8, _tempOrder$order_id2, _tempOrder$_extend;
1273
+ var _ref7, _ref8, _tempOrder$order_id, _tempOrder$_extend;
1390
1274
  var tempOrder = this.store.tempOrder;
1391
1275
  if (!tempOrder) return null;
1392
1276
  var lastOrderInfo = this.store.lastOrderInfo || {};
1393
- var orderId = (_ref7 = (_ref8 = (_tempOrder$order_id2 = tempOrder.order_id) !== null && _tempOrder$order_id2 !== void 0 ? _tempOrder$order_id2 : lastOrderInfo.order_id) !== null && _ref8 !== void 0 ? _ref8 : lastOrderInfo.id) !== null && _ref7 !== void 0 ? _ref7 : null;
1277
+ var orderId = (_ref7 = (_ref8 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref8 !== void 0 ? _ref8 : lastOrderInfo.id) !== null && _ref7 !== void 0 ? _ref7 : null;
1394
1278
  return {
1395
1279
  localId: this.cacheId || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.localId),
1396
1280
  orderId: orderId,
@@ -1461,32 +1345,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1461
1345
  }, {
1462
1346
  key: "addNewOrder",
1463
1347
  value: function () {
1464
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1348
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1465
1349
  var tempOrder;
1466
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1467
- while (1) switch (_context13.prev = _context13.next) {
1350
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1351
+ while (1) switch (_context10.prev = _context10.next) {
1468
1352
  case 0:
1469
1353
  tempOrder = this.ensureTempOrder();
1470
1354
  this.ensureExternalSaleNumber(tempOrder);
1471
- _context13.next = 4;
1355
+ _context10.next = 4;
1472
1356
  return this.recalculateSummary({
1473
1357
  createIfMissing: true
1474
1358
  });
1475
1359
  case 4:
1476
1360
  this.persistTempOrder();
1477
1361
  if (!this.draftPersistEnabled) {
1478
- _context13.next = 8;
1362
+ _context10.next = 8;
1479
1363
  break;
1480
1364
  }
1481
- _context13.next = 8;
1365
+ _context10.next = 8;
1482
1366
  return this.saveDraft();
1483
1367
  case 8:
1484
- return _context13.abrupt("return", tempOrder);
1368
+ return _context10.abrupt("return", tempOrder);
1485
1369
  case 9:
1486
1370
  case "end":
1487
- return _context13.stop();
1371
+ return _context10.stop();
1488
1372
  }
1489
- }, _callee11, this);
1373
+ }, _callee8, this);
1490
1374
  }));
1491
1375
  function addNewOrder() {
1492
1376
  return _addNewOrder.apply(this, arguments);
@@ -1508,6 +1392,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1508
1392
  product.metadata = metadata;
1509
1393
  return String(uid);
1510
1394
  }
1395
+ }, {
1396
+ key: "sanitizeOrderProductForTempOrder",
1397
+ value: function sanitizeOrderProductForTempOrder(product) {
1398
+ if (product.metadata && _typeof(product.metadata) === 'object') {
1399
+ delete product.metadata.origin;
1400
+ }
1401
+ return product;
1402
+ }
1403
+ }, {
1404
+ key: "sanitizeTempOrderProducts",
1405
+ value: function sanitizeTempOrderProducts(tempOrder) {
1406
+ var _this5 = this;
1407
+ tempOrder.products = (tempOrder.products || []).map(function (product) {
1408
+ return _this5.sanitizeOrderProductForTempOrder(product);
1409
+ });
1410
+ }
1511
1411
  }, {
1512
1412
  key: "ensureExtend",
1513
1413
  value: function ensureExtend(tempOrder) {
@@ -1573,9 +1473,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1573
1473
  }, {
1574
1474
  key: "findBookingIndexByUniqueIdentificationNumber",
1575
1475
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1576
- var _this5 = this;
1476
+ var _this6 = this;
1577
1477
  return (tempOrder.bookings || []).findIndex(function (booking) {
1578
- return _this5.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1478
+ return _this6.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1579
1479
  });
1580
1480
  }
1581
1481
  }, {
@@ -1583,12 +1483,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1583
1483
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
1584
1484
  var _product$metadata4,
1585
1485
  _product$metadata5,
1586
- _this6 = this;
1486
+ _this7 = this;
1587
1487
  var productUid = (product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
1588
1488
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.booking_uid);
1589
1489
  if (!productUid && !bookingUid) return;
1590
1490
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1591
- var currentBookingUid = _this6.getBookingUniqueIdentificationNumber(booking);
1491
+ var currentBookingUid = _this7.getBookingUniqueIdentificationNumber(booking);
1592
1492
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1593
1493
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1594
1494
  return true;
@@ -1605,23 +1505,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1605
1505
  }, {
1606
1506
  key: "recalculateSummary",
1607
1507
  value: function () {
1608
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
1508
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(options) {
1609
1509
  var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1610
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1611
- while (1) switch (_context14.prev = _context14.next) {
1510
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1511
+ while (1) switch (_context11.prev = _context11.next) {
1612
1512
  case 0:
1613
1513
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1614
1514
  if (tempOrder) {
1615
- _context14.next = 3;
1515
+ _context11.next = 3;
1616
1516
  break;
1617
1517
  }
1618
- return _context14.abrupt("return", null);
1518
+ return _context11.abrupt("return", null);
1619
1519
  case 3:
1520
+ this.sanitizeTempOrderProducts(tempOrder);
1620
1521
  salesSummary = this.getSalesSummary();
1621
1522
  existedSummary = this.store.summary || createEmptySummary();
1622
1523
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1623
1524
  if (salesSummary) {
1624
- _context14.next = 11;
1525
+ _context11.next = 13;
1625
1526
  break;
1626
1527
  }
1627
1528
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
@@ -1635,18 +1536,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1635
1536
  }),
1636
1537
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1637
1538
  });
1638
- this.store.summary = emptySummary;
1639
1539
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1640
- return _context14.abrupt("return", this.store.summary);
1641
- case 11:
1642
- _context14.next = 13;
1540
+ this.updateTempOrderPaymentStatus(tempOrder);
1541
+ this.store.summary = emptySummary;
1542
+ return _context11.abrupt("return", this.store.summary);
1543
+ case 13:
1544
+ _context11.next = 15;
1643
1545
  return salesSummary.getSummary({
1644
1546
  products: tempOrder.products,
1645
1547
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1646
1548
  shopDiscount: tempOrder.shop_discount
1647
1549
  });
1648
- case 13:
1649
- salesSummaryResult = _context14.sent;
1550
+ case 15:
1551
+ salesSummaryResult = _context11.sent;
1650
1552
  this.syncSummaryProductMetadata(tempOrder.products || []);
1651
1553
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1652
1554
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
@@ -1670,14 +1572,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1670
1572
  tempOrder.surcharges = summary.surcharges || [];
1671
1573
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1672
1574
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1673
- return _context14.abrupt("return", this.store.summary);
1674
- case 24:
1575
+ this.updateTempOrderPaymentStatus(tempOrder);
1576
+ return _context11.abrupt("return", this.store.summary);
1577
+ case 27:
1675
1578
  case "end":
1676
- return _context14.stop();
1579
+ return _context11.stop();
1677
1580
  }
1678
- }, _callee12, this);
1581
+ }, _callee9, this);
1679
1582
  }));
1680
- function recalculateSummary(_x12) {
1583
+ function recalculateSummary(_x9) {
1681
1584
  return _recalculateSummary.apply(this, arguments);
1682
1585
  }
1683
1586
  return recalculateSummary;
@@ -1685,30 +1588,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1685
1588
  }, {
1686
1589
  key: "getOrderSummary",
1687
1590
  value: function () {
1688
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1591
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1689
1592
  var summary;
1690
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1691
- while (1) switch (_context15.prev = _context15.next) {
1593
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1594
+ while (1) switch (_context12.prev = _context12.next) {
1692
1595
  case 0:
1693
- _context15.next = 2;
1596
+ _context12.next = 2;
1694
1597
  return this.recalculateSummary({
1695
1598
  createIfMissing: true
1696
1599
  });
1697
1600
  case 2:
1698
- summary = _context15.sent;
1601
+ summary = _context12.sent;
1699
1602
  if (summary) {
1700
- _context15.next = 5;
1603
+ _context12.next = 5;
1701
1604
  break;
1702
1605
  }
1703
- return _context15.abrupt("return", createEmptySummary());
1606
+ return _context12.abrupt("return", createEmptySummary());
1704
1607
  case 5:
1705
1608
  this.persistTempOrder();
1706
- return _context15.abrupt("return", summary);
1609
+ return _context12.abrupt("return", summary);
1707
1610
  case 7:
1708
1611
  case "end":
1709
- return _context15.stop();
1612
+ return _context12.stop();
1710
1613
  }
1711
- }, _callee13, this);
1614
+ }, _callee10, this);
1712
1615
  }));
1713
1616
  function getOrderSummary() {
1714
1617
  return _getOrderSummary.apply(this, arguments);
@@ -1732,23 +1635,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1732
1635
  }, {
1733
1636
  key: "syncTempOrderNoteToRemote",
1734
1637
  value: function () {
1735
- var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
1736
- return _regeneratorRuntime().wrap(function _callee14$(_context16) {
1737
- while (1) switch (_context16.prev = _context16.next) {
1638
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderId, note) {
1639
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1640
+ while (1) switch (_context13.prev = _context13.next) {
1738
1641
  case 0:
1739
- _context16.next = 2;
1642
+ _context13.next = 2;
1740
1643
  return this.request.put("/order/order/".concat(orderId, "/note"), {
1741
1644
  note: note
1742
1645
  });
1743
1646
  case 2:
1744
- return _context16.abrupt("return", note);
1647
+ return _context13.abrupt("return", note);
1745
1648
  case 3:
1746
1649
  case "end":
1747
- return _context16.stop();
1650
+ return _context13.stop();
1748
1651
  }
1749
- }, _callee14, this);
1652
+ }, _callee11, this);
1750
1653
  }));
1751
- function syncTempOrderNoteToRemote(_x13, _x14) {
1654
+ function syncTempOrderNoteToRemote(_x10, _x11) {
1752
1655
  return _syncTempOrderNoteToRemote.apply(this, arguments);
1753
1656
  }
1754
1657
  return syncTempOrderNoteToRemote;
@@ -1960,7 +1863,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1960
1863
  }, {
1961
1864
  key: "addOrderPayment",
1962
1865
  value: function addOrderPayment(payment) {
1963
- var _this7 = this;
1866
+ var _this8 = this;
1964
1867
  this.logInfo('addOrderPayment', {
1965
1868
  payment: payment
1966
1869
  });
@@ -1973,7 +1876,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1973
1876
  void this.recalculateSummary({
1974
1877
  createIfMissing: true
1975
1878
  }).catch(function (error) {
1976
- _this7.logError('recalculate summary after addOrderPayment failed', {
1879
+ _this8.logError('recalculate summary after addOrderPayment failed', {
1977
1880
  error: error instanceof Error ? error.message : String(error)
1978
1881
  });
1979
1882
  });
@@ -2038,10 +1941,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2038
1941
  }, {
2039
1942
  key: "updateVoucherOrderPayments",
2040
1943
  value: function updateVoucherOrderPayments(payments) {
2041
- var _this8 = this;
1944
+ var _this9 = this;
2042
1945
  var tempOrder = this.ensureTempOrder();
2043
1946
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
2044
- return _this8.normalizePaymentSource(payment, {
1947
+ return _this9.normalizePaymentSource(payment, {
2045
1948
  defaultPaid: false
2046
1949
  });
2047
1950
  })).filter(function (payment) {
@@ -2050,13 +1953,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2050
1953
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
2051
1954
  return payment.voucher_id === undefined || Number(payment.voucher_id) === 0;
2052
1955
  });
2053
- tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(mappedVouchers));
1956
+ var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
1957
+ vouchers: mappedVouchers,
1958
+ nonVoucherPayments: nonVoucherPayments
1959
+ });
1960
+ tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(cappedVouchers));
2054
1961
  this.updateTempOrderPaymentStatus(tempOrder);
2055
1962
  this.persistTempOrder();
2056
1963
  void this.recalculateSummary({
2057
1964
  createIfMissing: true
2058
1965
  }).catch(function (error) {
2059
- _this8.logError('recalculate summary after updateVoucherOrderPayments failed', {
1966
+ _this9.logError('recalculate summary after updateVoucherOrderPayments failed', {
2060
1967
  error: error instanceof Error ? error.message : String(error)
2061
1968
  });
2062
1969
  });
@@ -2065,45 +1972,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2065
1972
  }, {
2066
1973
  key: "shouldMergeProductToOrder",
2067
1974
  value: function () {
2068
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1975
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
2069
1976
  var _this$orderHooks;
2070
1977
  var onBeforeMergeProductToOrder, result;
2071
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2072
- while (1) switch (_context17.prev = _context17.next) {
1978
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1979
+ while (1) switch (_context14.prev = _context14.next) {
2073
1980
  case 0:
2074
1981
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
2075
1982
  if (onBeforeMergeProductToOrder) {
2076
- _context17.next = 3;
1983
+ _context14.next = 3;
2077
1984
  break;
2078
1985
  }
2079
- return _context17.abrupt("return", true);
1986
+ return _context14.abrupt("return", true);
2080
1987
  case 3:
2081
- _context17.next = 5;
1988
+ _context14.next = 5;
2082
1989
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
2083
1990
  defaultShouldMerge: true
2084
1991
  }));
2085
1992
  case 5:
2086
- result = _context17.sent;
1993
+ result = _context14.sent;
2087
1994
  if (!(typeof result === 'boolean')) {
2088
- _context17.next = 8;
1995
+ _context14.next = 8;
2089
1996
  break;
2090
1997
  }
2091
- return _context17.abrupt("return", result);
1998
+ return _context14.abrupt("return", result);
2092
1999
  case 8:
2093
2000
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
2094
- _context17.next = 10;
2001
+ _context14.next = 10;
2095
2002
  break;
2096
2003
  }
2097
- return _context17.abrupt("return", result.shouldMerge);
2004
+ return _context14.abrupt("return", result.shouldMerge);
2098
2005
  case 10:
2099
- return _context17.abrupt("return", true);
2006
+ return _context14.abrupt("return", true);
2100
2007
  case 11:
2101
2008
  case "end":
2102
- return _context17.stop();
2009
+ return _context14.stop();
2103
2010
  }
2104
- }, _callee15, this);
2011
+ }, _callee12, this);
2105
2012
  }));
2106
- function shouldMergeProductToOrder(_x15) {
2013
+ function shouldMergeProductToOrder(_x12) {
2107
2014
  return _shouldMergeProductToOrder.apply(this, arguments);
2108
2015
  }
2109
2016
  return shouldMergeProductToOrder;
@@ -2111,11 +2018,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2111
2018
  }, {
2112
2019
  key: "addProductToOrder",
2113
2020
  value: function () {
2114
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2115
- var _this9 = this;
2021
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
2022
+ var _this10 = this;
2116
2023
  var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
2117
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2118
- while (1) switch (_context18.prev = _context18.next) {
2024
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
2025
+ while (1) switch (_context15.prev = _context15.next) {
2119
2026
  case 0:
2120
2027
  tempOrder = this.ensureTempOrder();
2121
2028
  linked = booking ? this.createLinkedProductAndBooking({
@@ -2129,7 +2036,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2129
2036
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
2130
2037
  shouldForceNewLine = !!booking;
2131
2038
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
2132
- if (_this9.hasGoodPassDiscount(item)) return false;
2039
+ if (_this10.hasGoodPassDiscount(item)) return false;
2133
2040
  if (item.product_id !== productToAdd.product_id) return false;
2134
2041
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
2135
2042
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -2138,10 +2045,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2138
2045
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
2139
2046
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
2140
2047
  if (!matchedProduct) {
2141
- _context18.next = 17;
2048
+ _context15.next = 17;
2142
2049
  break;
2143
2050
  }
2144
- _context18.next = 14;
2051
+ _context15.next = 14;
2145
2052
  return this.shouldMergeProductToOrder({
2146
2053
  incomingProduct: productToAdd,
2147
2054
  normalizedIncoming: normalizedIncoming,
@@ -2153,13 +2060,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2153
2060
  booking: booking
2154
2061
  });
2155
2062
  case 14:
2156
- _context18.t0 = _context18.sent;
2157
- _context18.next = 18;
2063
+ _context15.t0 = _context15.sent;
2064
+ _context15.next = 18;
2158
2065
  break;
2159
2066
  case 17:
2160
- _context18.t0 = false;
2067
+ _context15.t0 = false;
2161
2068
  case 18:
2162
- shouldMerge = _context18.t0;
2069
+ shouldMerge = _context15.t0;
2163
2070
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
2164
2071
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
2165
2072
  if (linked) {
@@ -2198,24 +2105,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2198
2105
  if (linked) {
2199
2106
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2200
2107
  }
2201
- _context18.next = 23;
2108
+ _context15.next = 23;
2202
2109
  return this.applyPromotion();
2203
2110
  case 23:
2204
2111
  this.applyDiscount();
2205
- _context18.next = 26;
2112
+ this.sanitizeTempOrderProducts(tempOrder);
2113
+ _context15.next = 27;
2206
2114
  return this.recalculateSummary({
2207
2115
  createIfMissing: true
2208
2116
  });
2209
- case 26:
2117
+ case 27:
2210
2118
  this.persistTempOrder();
2211
- return _context18.abrupt("return", tempOrder.products);
2212
- case 28:
2119
+ return _context15.abrupt("return", tempOrder.products);
2120
+ case 29:
2213
2121
  case "end":
2214
- return _context18.stop();
2122
+ return _context15.stop();
2215
2123
  }
2216
- }, _callee16, this);
2124
+ }, _callee13, this);
2217
2125
  }));
2218
- function addProductToOrder(_x16, _x17) {
2126
+ function addProductToOrder(_x13, _x14) {
2219
2127
  return _addProductToOrder.apply(this, arguments);
2220
2128
  }
2221
2129
  return addProductToOrder;
@@ -2242,11 +2150,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2242
2150
  }, {
2243
2151
  key: "updateOrderProduct",
2244
2152
  value: function () {
2245
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
2246
- var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada7, _tempOrder$products$p;
2247
- var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_sku, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, isPersistedOrderLine, callerUpdatesManualPrice, _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$metada8, productUid, linked;
2248
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2249
- while (1) switch (_context19.prev = _context19.next) {
2153
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2154
+ var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p;
2155
+ var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_sku, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, isPersistedOrderLine, callerChangesDiscountList, callerUpdatesManualPrice, _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, _targetProduct$metada7, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$metada9, productUid, linked;
2156
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2157
+ while (1) switch (_context16.prev = _context16.next) {
2250
2158
  case 0:
2251
2159
  product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle, booking = params.booking;
2252
2160
  tempOrder = this.ensureTempOrder();
@@ -2277,7 +2185,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2277
2185
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2278
2186
  }
2279
2187
  if (!(productIndex === -1)) {
2280
- _context19.next = 12;
2188
+ _context16.next = 12;
2281
2189
  break;
2282
2190
  }
2283
2191
  throw new Error('[Order] 目标商品不存在,无法更新');
@@ -2305,7 +2213,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2305
2213
  callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
2306
2214
  callerUpdatesMainMeta = (updates === null || updates === void 0 || (_metadata = updates.metadata) === null || _metadata === void 0 ? void 0 : _metadata.main_product_selling_price) !== undefined || (updates === null || updates === void 0 || (_metadata2 = updates.metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.main_product_original_price) !== undefined || (updates === null || updates === void 0 || (_metadata3 = updates.metadata) === null || _metadata3 === void 0 ? void 0 : _metadata3.source_product_price) !== undefined;
2307
2215
  isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
2308
- callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.product_discount_reason) !== undefined || Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
2216
+ callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
2217
+ callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.product_discount_reason) !== undefined || callerChangesDiscountList;
2309
2218
  if (isPersistedOrderLine && !callerUpdatesManualPrice) {
2310
2219
  nextProduct.selling_price = targetProduct.selling_price;
2311
2220
  nextProduct.original_price = targetProduct.original_price;
@@ -2314,7 +2223,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2314
2223
  source_product_price: (_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.source_product_price,
2315
2224
  main_product_selling_price: (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_selling_price,
2316
2225
  main_product_original_price: (_targetProduct$metada5 = targetProduct.metadata) === null || _targetProduct$metada5 === void 0 ? void 0 : _targetProduct$metada5.main_product_original_price,
2317
- price_schema_version: (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.price_schema_version
2226
+ price_schema_version: (_targetProduct$metada6 = (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.price_schema_version) !== null && _targetProduct$metada6 !== void 0 ? _targetProduct$metada6 : 2
2318
2227
  });
2319
2228
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
2320
2229
  existedMeta = nextProduct.metadata || {};
@@ -2328,7 +2237,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2328
2237
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
2329
2238
  normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
2330
2239
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2331
- preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.booking_uid);
2240
+ preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.booking_uid);
2332
2241
  if (!booking && preservedBookingUid) {
2333
2242
  normalizedProduct.booking_uid = preservedBookingUid;
2334
2243
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
@@ -2336,7 +2245,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2336
2245
  });
2337
2246
  }
2338
2247
  if (booking) {
2339
- productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.unique_identification_number) || unique_identification_number || createUuidV4());
2248
+ productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number || createUuidV4());
2340
2249
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2341
2250
  unique_identification_number: productUid
2342
2251
  });
@@ -2358,24 +2267,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2358
2267
  }
2359
2268
  tempOrder.products[productIndex] = normalizedProduct;
2360
2269
  this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
2361
- _context19.next = 29;
2270
+ _context16.next = 30;
2362
2271
  return this.applyPromotion();
2363
- case 29:
2272
+ case 30:
2364
2273
  this.applyDiscount();
2365
- _context19.next = 32;
2274
+ this.sanitizeTempOrderProducts(tempOrder);
2275
+ _context16.next = 34;
2366
2276
  return this.recalculateSummary({
2367
2277
  createIfMissing: true
2368
2278
  });
2369
- case 32:
2370
- this.persistTempOrder();
2371
- return _context19.abrupt("return", tempOrder.products);
2372
2279
  case 34:
2280
+ this.persistTempOrder();
2281
+ return _context16.abrupt("return", tempOrder.products);
2282
+ case 36:
2373
2283
  case "end":
2374
- return _context19.stop();
2284
+ return _context16.stop();
2375
2285
  }
2376
- }, _callee17, this);
2286
+ }, _callee14, this);
2377
2287
  }));
2378
- function updateOrderProduct(_x18) {
2288
+ function updateOrderProduct(_x15) {
2379
2289
  return _updateOrderProduct.apply(this, arguments);
2380
2290
  }
2381
2291
  return updateOrderProduct;
@@ -2383,11 +2293,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2383
2293
  }, {
2384
2294
  key: "updateOrderProductQuantity",
2385
2295
  value: function () {
2386
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2387
- var _targetProduct$metada9;
2296
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
2297
+ var _targetProduct$metada10;
2388
2298
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2389
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2390
- while (1) switch (_context20.prev = _context20.next) {
2299
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2300
+ while (1) switch (_context17.prev = _context17.next) {
2391
2301
  case 0:
2392
2302
  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;
2393
2303
  tempOrder = this.ensureTempOrder();
@@ -2416,7 +2326,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2416
2326
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2417
2327
  }
2418
2328
  if (!(productIndex === -1)) {
2419
- _context20.next = 12;
2329
+ _context17.next = 12;
2420
2330
  break;
2421
2331
  }
2422
2332
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -2425,29 +2335,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2425
2335
  normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2426
2336
  num: getSafeProductNum(num),
2427
2337
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2428
- unique_identification_number: ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number
2338
+ unique_identification_number: ((_targetProduct$metada10 = targetProduct.metadata) === null || _targetProduct$metada10 === void 0 ? void 0 : _targetProduct$metada10.unique_identification_number) || unique_identification_number
2429
2339
  })
2430
2340
  }));
2431
2341
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2432
2342
  tempOrder.products[productIndex] = normalizedProduct;
2433
- _context20.next = 18;
2343
+ _context17.next = 18;
2434
2344
  return this.applyPromotion();
2435
2345
  case 18:
2436
2346
  this.applyDiscount();
2437
- _context20.next = 21;
2347
+ this.sanitizeTempOrderProducts(tempOrder);
2348
+ _context17.next = 22;
2438
2349
  return this.recalculateSummary({
2439
2350
  createIfMissing: true
2440
2351
  });
2441
- case 21:
2352
+ case 22:
2442
2353
  this.persistTempOrder();
2443
- return _context20.abrupt("return", tempOrder.products);
2444
- case 23:
2354
+ return _context17.abrupt("return", tempOrder.products);
2355
+ case 24:
2445
2356
  case "end":
2446
- return _context20.stop();
2357
+ return _context17.stop();
2447
2358
  }
2448
- }, _callee18, this);
2359
+ }, _callee15, this);
2449
2360
  }));
2450
- function updateOrderProductQuantity(_x19) {
2361
+ function updateOrderProductQuantity(_x16) {
2451
2362
  return _updateOrderProductQuantity.apply(this, arguments);
2452
2363
  }
2453
2364
  return updateOrderProductQuantity;
@@ -2478,10 +2389,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2478
2389
  }, {
2479
2390
  key: "removeProductFromOrder",
2480
2391
  value: function () {
2481
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2392
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(identity) {
2482
2393
  var tempOrder, removedProducts, _i, _removedProducts, product;
2483
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2484
- while (1) switch (_context21.prev = _context21.next) {
2394
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2395
+ while (1) switch (_context18.prev = _context18.next) {
2485
2396
  case 0:
2486
2397
  tempOrder = this.ensureTempOrder();
2487
2398
  removedProducts = [];
@@ -2494,24 +2405,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2494
2405
  product = _removedProducts[_i];
2495
2406
  this.removeLinkedBookingsForProduct(tempOrder, product);
2496
2407
  }
2497
- _context21.next = 6;
2408
+ _context18.next = 6;
2498
2409
  return this.applyPromotion();
2499
2410
  case 6:
2500
2411
  this.applyDiscount();
2501
- _context21.next = 9;
2412
+ this.sanitizeTempOrderProducts(tempOrder);
2413
+ _context18.next = 10;
2502
2414
  return this.recalculateSummary({
2503
2415
  createIfMissing: true
2504
2416
  });
2505
- case 9:
2417
+ case 10:
2506
2418
  this.persistTempOrder();
2507
- return _context21.abrupt("return", tempOrder.products);
2508
- case 11:
2419
+ return _context18.abrupt("return", tempOrder.products);
2420
+ case 12:
2509
2421
  case "end":
2510
- return _context21.stop();
2422
+ return _context18.stop();
2511
2423
  }
2512
- }, _callee19, this);
2424
+ }, _callee16, this);
2513
2425
  }));
2514
- function removeProductFromOrder(_x20) {
2426
+ function removeProductFromOrder(_x17) {
2515
2427
  return _removeProductFromOrder.apply(this, arguments);
2516
2428
  }
2517
2429
  return removeProductFromOrder;
@@ -2523,10 +2435,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2523
2435
  }, {
2524
2436
  key: "clearOrderCartLines",
2525
2437
  value: (function () {
2526
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2438
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2527
2439
  var tempOrder;
2528
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2529
- while (1) switch (_context22.prev = _context22.next) {
2440
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2441
+ while (1) switch (_context19.prev = _context19.next) {
2530
2442
  case 0:
2531
2443
  tempOrder = this.ensureTempOrder();
2532
2444
  tempOrder.products = [];
@@ -2536,22 +2448,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2536
2448
  productsByUid: {}
2537
2449
  });
2538
2450
  }
2539
- _context22.next = 6;
2451
+ _context19.next = 6;
2540
2452
  return this.applyPromotion();
2541
2453
  case 6:
2542
2454
  this.applyDiscount();
2543
- _context22.next = 9;
2455
+ this.sanitizeTempOrderProducts(tempOrder);
2456
+ _context19.next = 10;
2544
2457
  return this.recalculateSummary({
2545
2458
  createIfMissing: true
2546
2459
  });
2547
- case 9:
2460
+ case 10:
2548
2461
  this.persistTempOrder();
2549
- return _context22.abrupt("return", tempOrder);
2550
- case 11:
2462
+ return _context19.abrupt("return", tempOrder);
2463
+ case 12:
2551
2464
  case "end":
2552
- return _context22.stop();
2465
+ return _context19.stop();
2553
2466
  }
2554
- }, _callee20, this);
2467
+ }, _callee17, this);
2555
2468
  }));
2556
2469
  function clearOrderCartLines() {
2557
2470
  return _clearOrderCartLines.apply(this, arguments);
@@ -2562,17 +2475,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2562
2475
  * 提交当前 Sales tempOrder。
2563
2476
  *
2564
2477
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
2565
- * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
2478
+ * 应传 1,确保 /shop/order/sales/checkout 返回打印所需数据。
2566
2479
  */
2567
2480
  )
2568
2481
  }, {
2569
2482
  key: "submitTempOrder",
2570
2483
  value: function () {
2571
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2484
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2572
2485
  var _params$cacheId, _this$otherParams, _ref23, _params$businessCode, _this$otherParams2, _this$otherParams3;
2573
2486
  var tempOrder, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
2574
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2575
- while (1) switch (_context23.prev = _context23.next) {
2487
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2488
+ while (1) switch (_context20.prev = _context20.next) {
2576
2489
  case 0:
2577
2490
  tempOrder = this.ensureTempOrder();
2578
2491
  this.persistTempOrder();
@@ -2601,10 +2514,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2601
2514
  enhance: enhancePayload
2602
2515
  }); // TODO: 前端生成的时间现在是有问题的,后面要统一优化
2603
2516
  payload.created_at = undefined;
2604
- _context23.next = 11;
2517
+ _context20.next = 11;
2605
2518
  return this.saveDraft();
2606
2519
  case 11:
2607
- _context23.prev = 11;
2520
+ _context20.prev = 11;
2608
2521
  this.logInfo('submitTempOrder calling sales checkout', {
2609
2522
  orderId: payload.order_id,
2610
2523
  externalSaleNumber: payload.external_sale_number,
@@ -2613,62 +2526,62 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2613
2526
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
2614
2527
  smallTicketDataFlag: payload.small_ticket_data_flag
2615
2528
  });
2616
- _context23.next = 15;
2529
+ _context20.next = 15;
2617
2530
  return this.submitSalesOrder({
2618
2531
  query: payload
2619
2532
  });
2620
2533
  case 15:
2621
- result = _context23.sent;
2622
- _context23.next = 28;
2534
+ result = _context20.sent;
2535
+ _context20.next = 28;
2623
2536
  break;
2624
2537
  case 18:
2625
- _context23.prev = 18;
2626
- _context23.t0 = _context23["catch"](11);
2627
- backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
2538
+ _context20.prev = 18;
2539
+ _context20.t0 = _context20["catch"](11);
2540
+ backendErrorResponse = this.extractSubmitErrorResponse(_context20.t0);
2628
2541
  if (!backendErrorResponse) {
2629
- _context23.next = 25;
2542
+ _context20.next = 25;
2630
2543
  break;
2631
2544
  }
2632
2545
  this.store.syncState = 'failed';
2633
2546
  this.logSubmitBackendRejected(backendErrorResponse, payload);
2634
- return _context23.abrupt("return", backendErrorResponse);
2547
+ return _context20.abrupt("return", backendErrorResponse);
2635
2548
  case 25:
2636
2549
  this.store.syncState = 'failed';
2637
2550
  this.logError('submitTempOrder failed', {
2638
- error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
2551
+ error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
2639
2552
  orderId: payload.order_id,
2640
2553
  externalSaleNumber: payload.external_sale_number,
2641
2554
  paymentStatus: payload.payment_status,
2642
2555
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
2643
2556
  });
2644
- throw _context23.t0;
2557
+ throw _context20.t0;
2645
2558
  case 28:
2646
2559
  if (!this.isSubmitResponseRejected(result)) {
2647
- _context23.next = 32;
2560
+ _context20.next = 32;
2648
2561
  break;
2649
2562
  }
2650
2563
  this.store.syncState = 'failed';
2651
2564
  this.logSubmitBackendRejected(result, payload);
2652
- return _context23.abrupt("return", result);
2565
+ return _context20.abrupt("return", result);
2653
2566
  case 32:
2654
2567
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
2655
2568
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
2656
- _context23.next = 38;
2569
+ _context20.next = 38;
2657
2570
  break;
2658
2571
  }
2659
2572
  tempOrder.order_id = submittedOrderId;
2660
2573
  resultRecord = result;
2661
- _context23.next = 38;
2574
+ _context20.next = 38;
2662
2575
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
2663
2576
  case 38:
2664
- return _context23.abrupt("return", result);
2577
+ return _context20.abrupt("return", result);
2665
2578
  case 39:
2666
2579
  case "end":
2667
- return _context23.stop();
2580
+ return _context20.stop();
2668
2581
  }
2669
- }, _callee21, this, [[11, 18]]);
2582
+ }, _callee18, this, [[11, 18]]);
2670
2583
  }));
2671
- function submitTempOrder(_x21) {
2584
+ function submitTempOrder(_x18) {
2672
2585
  return _submitTempOrder.apply(this, arguments);
2673
2586
  }
2674
2587
  return submitTempOrder;
@@ -2676,25 +2589,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2676
2589
  }, {
2677
2590
  key: "markLocalOrderSynced",
2678
2591
  value: function () {
2679
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
2592
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderId, remoteOrder) {
2680
2593
  var tempOrder;
2681
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2682
- while (1) switch (_context24.prev = _context24.next) {
2594
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2595
+ while (1) switch (_context21.prev = _context21.next) {
2683
2596
  case 0:
2684
2597
  tempOrder = this.ensureTempOrder();
2685
2598
  tempOrder.order_id = orderId;
2686
2599
  this.store.lastOrderInfo = remoteOrder;
2687
2600
  this.store.syncState = 'submitted';
2688
2601
  this.persistTempOrder();
2689
- _context24.next = 7;
2602
+ _context21.next = 7;
2690
2603
  return this.saveDraft();
2691
2604
  case 7:
2692
2605
  case "end":
2693
- return _context24.stop();
2606
+ return _context21.stop();
2694
2607
  }
2695
- }, _callee22, this);
2608
+ }, _callee19, this);
2696
2609
  }));
2697
- function markLocalOrderSynced(_x22, _x23) {
2610
+ function markLocalOrderSynced(_x19, _x20) {
2698
2611
  return _markLocalOrderSynced.apply(this, arguments);
2699
2612
  }
2700
2613
  return markLocalOrderSynced;
@@ -2718,10 +2631,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2718
2631
  value: function extractSubmitErrorResponse(error) {
2719
2632
  var _error$response,
2720
2633
  _error$response2,
2721
- _this10 = this;
2634
+ _this11 = this;
2722
2635
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
2723
2636
  return candidates.find(function (candidate) {
2724
- return _this10.isSubmitErrorResponse(candidate);
2637
+ return _this11.isSubmitErrorResponse(candidate);
2725
2638
  }) || null;
2726
2639
  }
2727
2640
  }, {
@@ -2741,10 +2654,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2741
2654
  }, {
2742
2655
  key: "syncPaymentsToOrder",
2743
2656
  value: function () {
2744
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2657
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2745
2658
  var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2746
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2747
- while (1) switch (_context25.prev = _context25.next) {
2659
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2660
+ while (1) switch (_context22.prev = _context22.next) {
2748
2661
  case 0:
2749
2662
  tempOrder = this.ensureTempOrder();
2750
2663
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
@@ -2755,28 +2668,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2755
2668
  tempOrder.payments = mappedPayments;
2756
2669
  tempOrder.payment_status = paymentStatus;
2757
2670
  this.persistTempOrder();
2758
- _context25.next = 11;
2671
+ _context22.next = 11;
2759
2672
  return this.saveDraft();
2760
2673
  case 11:
2761
2674
  if (params.submitWhenPaid) {
2762
- _context25.next = 13;
2675
+ _context22.next = 13;
2763
2676
  break;
2764
2677
  }
2765
- return _context25.abrupt("return", {
2678
+ return _context22.abrupt("return", {
2766
2679
  isFullyPaid: isFullyPaid
2767
2680
  });
2768
2681
  case 13:
2769
2682
  if (!(this.store.syncState === 'submitting')) {
2770
- _context25.next = 15;
2683
+ _context22.next = 15;
2771
2684
  break;
2772
2685
  }
2773
- return _context25.abrupt("return", {
2686
+ return _context22.abrupt("return", {
2774
2687
  isFullyPaid: isFullyPaid
2775
2688
  });
2776
2689
  case 15:
2777
2690
  this.store.syncState = 'submitting';
2778
2691
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2779
- _context25.next = 19;
2692
+ _context22.next = 19;
2780
2693
  return this.submitTempOrder({
2781
2694
  payments: mappedPayments,
2782
2695
  paymentStatus: paymentStatus,
@@ -2791,18 +2704,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2791
2704
  }
2792
2705
  });
2793
2706
  case 19:
2794
- submitResult = _context25.sent;
2795
- return _context25.abrupt("return", {
2707
+ submitResult = _context22.sent;
2708
+ return _context22.abrupt("return", {
2796
2709
  isFullyPaid: isFullyPaid,
2797
2710
  submitResult: submitResult
2798
2711
  });
2799
2712
  case 21:
2800
2713
  case "end":
2801
- return _context25.stop();
2714
+ return _context22.stop();
2802
2715
  }
2803
- }, _callee23, this);
2716
+ }, _callee20, this);
2804
2717
  }));
2805
- function syncPaymentsToOrder(_x24) {
2718
+ function syncPaymentsToOrder(_x21) {
2806
2719
  return _syncPaymentsToOrder.apply(this, arguments);
2807
2720
  }
2808
2721
  return syncPaymentsToOrder;
@@ -2891,11 +2804,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2891
2804
  }, {
2892
2805
  key: "submitOrder",
2893
2806
  value: function () {
2894
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
2807
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order) {
2895
2808
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
2896
2809
  var url, query, fetchUrl, params;
2897
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2898
- while (1) switch (_context26.prev = _context26.next) {
2810
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2811
+ while (1) switch (_context23.prev = _context23.next) {
2899
2812
  case 0:
2900
2813
  this.logInfo('submitOrder called', {
2901
2814
  url: order.url,
@@ -2915,14 +2828,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2915
2828
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
2916
2829
  scheduleDate: params.schedule_date
2917
2830
  });
2918
- return _context26.abrupt("return", this.request.post(fetchUrl, params));
2831
+ return _context23.abrupt("return", this.request.post(fetchUrl, params));
2919
2832
  case 6:
2920
2833
  case "end":
2921
- return _context26.stop();
2834
+ return _context23.stop();
2922
2835
  }
2923
- }, _callee24, this);
2836
+ }, _callee21, this);
2924
2837
  }));
2925
- function submitOrder(_x25) {
2838
+ function submitOrder(_x22) {
2926
2839
  return _submitOrder.apply(this, arguments);
2927
2840
  }
2928
2841
  return submitOrder;
@@ -2930,13 +2843,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2930
2843
  }, {
2931
2844
  key: "cancelOrder",
2932
2845
  value: function () {
2933
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2846
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2934
2847
  var payload;
2935
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
2936
- while (1) switch (_context27.prev = _context27.next) {
2848
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2849
+ while (1) switch (_context24.prev = _context24.next) {
2937
2850
  case 0:
2938
2851
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
2939
- _context27.next = 2;
2852
+ _context24.next = 2;
2940
2853
  break;
2941
2854
  }
2942
2855
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -2952,16 +2865,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2952
2865
  method: 'PUT',
2953
2866
  orderIdsCount: params.order_ids.length
2954
2867
  });
2955
- return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
2868
+ return _context24.abrupt("return", this.request.put('/order/update-status', payload, {
2956
2869
  isShopApi: true
2957
2870
  }));
2958
2871
  case 5:
2959
2872
  case "end":
2960
- return _context27.stop();
2873
+ return _context24.stop();
2961
2874
  }
2962
- }, _callee25, this);
2875
+ }, _callee22, this);
2963
2876
  }));
2964
- function cancelOrder(_x26) {
2877
+ function cancelOrder(_x23) {
2965
2878
  return _cancelOrder.apply(this, arguments);
2966
2879
  }
2967
2880
  return cancelOrder;
@@ -2969,19 +2882,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2969
2882
  }, {
2970
2883
  key: "changeBookingStatus",
2971
2884
  value: function () {
2972
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2885
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2973
2886
  var url, payload;
2974
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
2975
- while (1) switch (_context28.prev = _context28.next) {
2887
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2888
+ while (1) switch (_context25.prev = _context25.next) {
2976
2889
  case 0:
2977
2890
  if (params.booking_id) {
2978
- _context28.next = 2;
2891
+ _context25.next = 2;
2979
2892
  break;
2980
2893
  }
2981
2894
  throw new Error('变更预约状态失败:booking_id 不能为空');
2982
2895
  case 2:
2983
2896
  if (params.appointment_status) {
2984
- _context28.next = 4;
2897
+ _context25.next = 4;
2985
2898
  break;
2986
2899
  }
2987
2900
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2996,16 +2909,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2996
2909
  bookingId: params.booking_id,
2997
2910
  appointmentStatus: params.appointment_status
2998
2911
  });
2999
- return _context28.abrupt("return", this.request.put(url, payload, {
2912
+ return _context25.abrupt("return", this.request.put(url, payload, {
3000
2913
  isShopApi: true
3001
2914
  }));
3002
2915
  case 8:
3003
2916
  case "end":
3004
- return _context28.stop();
2917
+ return _context25.stop();
3005
2918
  }
3006
- }, _callee26, this);
2919
+ }, _callee23, this);
3007
2920
  }));
3008
- function changeBookingStatus(_x27) {
2921
+ function changeBookingStatus(_x24) {
3009
2922
  return _changeBookingStatus.apply(this, arguments);
3010
2923
  }
3011
2924
  return changeBookingStatus;
@@ -3014,7 +2927,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3014
2927
  * Checkout 专用:创建订单到后端
3015
2928
  *
3016
2929
  * 专门为 Checkout 模块设计的订单创建方法,
3017
- * 直接调用 /order/checkout 接口创建订单
2930
+ * 通过 OS Server 调用 checkout 接口创建订单
3018
2931
  * 接收已经处理好的订单数据,无需再处理购物车
3019
2932
  *
3020
2933
  * @param params Checkout 订单参数(已处理的订单数据)
@@ -3023,11 +2936,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3023
2936
  }, {
3024
2937
  key: "createOrderByCheckout",
3025
2938
  value: (function () {
3026
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2939
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
3027
2940
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
3028
2941
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _orderData$bookings2, _orderData$relation_p2, _orderData$payments4, _orderData$payments5, _response$data, orderData, response;
3029
- return _regeneratorRuntime().wrap(function _callee27$(_context29) {
3030
- while (1) switch (_context29.prev = _context29.next) {
2942
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2943
+ while (1) switch (_context26.prev = _context26.next) {
3031
2944
  case 0:
3032
2945
  // 过滤掉由在线店铺下单的 payment 支付数据
3033
2946
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -3061,7 +2974,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3061
2974
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
3062
2975
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
3063
2976
  });
3064
- _context29.prev = 4;
2977
+ _context26.prev = 4;
3065
2978
  // 构建订单数据,设置默认值并允许 params 覆盖
3066
2979
  orderData = _objectSpread({
3067
2980
  sales_channel: 'my_pisel',
@@ -3084,7 +2997,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3084
2997
  orderData.schedule_date = dayjs().format('YYYY-MM-DD HH:mm:ss');
3085
2998
  }
3086
2999
  console.log('[Order] 调用后端接口创建订单:', {
3087
- url: '/order/checkout',
3000
+ url: '/shop/order/checkout',
3088
3001
  orderType: orderData.type,
3089
3002
  platform: orderData.platform,
3090
3003
  isDeposit: orderData.is_deposit,
@@ -3099,7 +3012,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3099
3012
 
3100
3013
  // 记录接口调用详情
3101
3014
  this.logInfo('Calling backend checkout API', {
3102
- url: '/order/checkout',
3015
+ url: '/shop/order/checkout',
3103
3016
  orderType: orderData.type,
3104
3017
  platform: orderData.platform,
3105
3018
  isDeposit: orderData.is_deposit,
@@ -3123,12 +3036,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3123
3036
  hasOrderId: !!orderData.order_id,
3124
3037
  smallTicketDataFlag: orderData.small_ticket_data_flag
3125
3038
  });
3126
-
3127
- // 调用后端接口
3128
- _context29.next = 12;
3129
- return this.request.post('/order/checkout', orderData);
3039
+ _context26.next = 12;
3040
+ return this.request.post('/shop/order/checkout', orderData, {
3041
+ osServer: true,
3042
+ customToast: function customToast() {}
3043
+ });
3130
3044
  case 12:
3131
- response = _context29.sent;
3045
+ response = _context26.sent;
3132
3046
  this.logInfo('Order API called successfully', {
3133
3047
  response: response
3134
3048
  });
@@ -3136,22 +3050,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3136
3050
  success: !!response,
3137
3051
  hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
3138
3052
  });
3139
- return _context29.abrupt("return", response);
3053
+ return _context26.abrupt("return", response);
3140
3054
  case 18:
3141
- _context29.prev = 18;
3142
- _context29.t0 = _context29["catch"](4);
3143
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
3055
+ _context26.prev = 18;
3056
+ _context26.t0 = _context26["catch"](4);
3057
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context26.t0);
3144
3058
  this.logInfo('Order API called failed', {
3145
- error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
3059
+ error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0)
3146
3060
  });
3147
- throw _context29.t0;
3061
+ throw _context26.t0;
3148
3062
  case 23:
3149
3063
  case "end":
3150
- return _context29.stop();
3064
+ return _context26.stop();
3151
3065
  }
3152
- }, _callee27, this, [[4, 18]]);
3066
+ }, _callee24, this, [[4, 18]]);
3153
3067
  }));
3154
- function createOrderByCheckout(_x28) {
3068
+ function createOrderByCheckout(_x25) {
3155
3069
  return _createOrderByCheckout.apply(this, arguments);
3156
3070
  }
3157
3071
  return createOrderByCheckout;
@@ -3159,23 +3073,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3159
3073
  }, {
3160
3074
  key: "submitSalesOrder",
3161
3075
  value: function () {
3162
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
3076
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
3163
3077
  var url, query, fetchUrl;
3164
- return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3165
- while (1) switch (_context30.prev = _context30.next) {
3078
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
3079
+ while (1) switch (_context27.prev = _context27.next) {
3166
3080
  case 0:
3167
3081
  url = params.url, query = params.query;
3168
3082
  fetchUrl = url || '/order/sales/checkout';
3169
- return _context30.abrupt("return", this.request.post(fetchUrl, query, {
3083
+ return _context27.abrupt("return", this.request.post(fetchUrl, query, {
3084
+ osServer: true,
3170
3085
  customToast: function customToast() {}
3171
3086
  }));
3172
3087
  case 3:
3173
3088
  case "end":
3174
- return _context30.stop();
3089
+ return _context27.stop();
3175
3090
  }
3176
- }, _callee28, this);
3091
+ }, _callee25, this);
3177
3092
  }));
3178
- function submitSalesOrder(_x29) {
3093
+ function submitSalesOrder(_x26) {
3179
3094
  return _submitSalesOrder.apply(this, arguments);
3180
3095
  }
3181
3096
  return submitSalesOrder;
@@ -3189,72 +3104,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3189
3104
  }, {
3190
3105
  key: "sendCustomerPayLink",
3191
3106
  value: (function () {
3192
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
3107
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
3193
3108
  var _params$emails;
3194
3109
  var orderIds;
3195
- return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3196
- while (1) switch (_context31.prev = _context31.next) {
3110
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
3111
+ while (1) switch (_context28.prev = _context28.next) {
3197
3112
  case 0:
3198
3113
  orderIds = params.order_ids || params.orderIds || [];
3199
3114
  if (orderIds.length) {
3200
- _context31.next = 3;
3115
+ _context28.next = 3;
3201
3116
  break;
3202
3117
  }
3203
3118
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
3204
3119
  case 3:
3205
3120
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
3206
- _context31.next = 5;
3121
+ _context28.next = 5;
3207
3122
  break;
3208
3123
  }
3209
3124
  throw new Error('发送支付链接需要至少一个邮箱');
3210
3125
  case 5:
3211
- return _context31.abrupt("return", this.request.post('/order/batch-email', {
3126
+ return _context28.abrupt("return", this.request.post('/order/batch-email', {
3212
3127
  order_ids: orderIds,
3213
3128
  notify_action: params.notify_action || 'order_payment_reminder',
3214
3129
  emails: params.emails
3215
3130
  }));
3216
3131
  case 6:
3217
3132
  case "end":
3218
- return _context31.stop();
3133
+ return _context28.stop();
3219
3134
  }
3220
- }, _callee29, this);
3135
+ }, _callee26, this);
3221
3136
  }));
3222
- function sendCustomerPayLink(_x30) {
3137
+ function sendCustomerPayLink(_x27) {
3223
3138
  return _sendCustomerPayLink.apply(this, arguments);
3224
3139
  }
3225
3140
  return sendCustomerPayLink;
3226
- }() // TODO 获取详情的接口
3227
- )
3141
+ }())
3228
3142
  }, {
3229
- key: "getOrderInfoByRemote",
3143
+ key: "getSalesOrderByLookup",
3230
3144
  value: function () {
3231
- var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order_id) {
3232
- var res;
3233
- return _regeneratorRuntime().wrap(function _callee30$(_context32) {
3234
- while (1) switch (_context32.prev = _context32.next) {
3145
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
3146
+ var lookup, res;
3147
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
3148
+ while (1) switch (_context29.prev = _context29.next) {
3235
3149
  case 0:
3236
- _context32.next = 2;
3237
- return this.request.get("/order/sales/".concat(order_id), {
3150
+ lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
3151
+ if (lookup) {
3152
+ _context29.next = 3;
3153
+ break;
3154
+ }
3155
+ throw new Error('加载销售详情需要 lookup');
3156
+ case 3:
3157
+ _context29.next = 5;
3158
+ return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
3238
3159
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
3239
- }, {
3160
+ }, params.forceRemote ? {
3161
+ forceRemote: true
3162
+ } : {}), {
3240
3163
  osServer: true
3241
3164
  });
3242
- case 2:
3243
- res = _context32.sent;
3165
+ case 5:
3166
+ res = _context29.sent;
3244
3167
  if (res.code === 200) {
3245
3168
  this.store.lastOrderInfo = res.data;
3246
3169
  }
3247
- return _context32.abrupt("return", res);
3248
- case 5:
3170
+ return _context29.abrupt("return", res);
3171
+ case 8:
3249
3172
  case "end":
3250
- return _context32.stop();
3173
+ return _context29.stop();
3251
3174
  }
3252
- }, _callee30, this);
3175
+ }, _callee27, this);
3253
3176
  }));
3254
- function getOrderInfoByRemote(_x31) {
3255
- return _getOrderInfoByRemote.apply(this, arguments);
3177
+ function getSalesOrderByLookup(_x28) {
3178
+ return _getSalesOrderByLookup.apply(this, arguments);
3256
3179
  }
3257
- return getOrderInfoByRemote;
3180
+ return getSalesOrderByLookup;
3258
3181
  }()
3259
3182
  /**
3260
3183
  * 把 sqlite / 后端返回的订单记录直接恢复为 tempOrder。
@@ -3265,10 +3188,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3265
3188
  }, {
3266
3189
  key: "hydrateTempOrderFromRecord",
3267
3190
  value: (function () {
3268
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
3191
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(record, options) {
3269
3192
  var raw, nextTempOrder;
3270
- return _regeneratorRuntime().wrap(function _callee31$(_context33) {
3271
- while (1) switch (_context33.prev = _context33.next) {
3193
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3194
+ while (1) switch (_context30.prev = _context30.next) {
3272
3195
  case 0:
3273
3196
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
3274
3197
  nextTempOrder = this.normalizeTempOrderForRuntime(raw);
@@ -3276,23 +3199,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3276
3199
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
3277
3200
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
3278
3201
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
3279
- _context33.next = 8;
3202
+ _context30.next = 8;
3280
3203
  break;
3281
3204
  }
3282
- _context33.next = 8;
3205
+ _context30.next = 8;
3283
3206
  return this.recalculateSummary({
3284
3207
  createIfMissing: false
3285
3208
  });
3286
3209
  case 8:
3287
3210
  this.persistTempOrder();
3288
- return _context33.abrupt("return", nextTempOrder);
3211
+ return _context30.abrupt("return", nextTempOrder);
3289
3212
  case 10:
3290
3213
  case "end":
3291
- return _context33.stop();
3214
+ return _context30.stop();
3292
3215
  }
3293
- }, _callee31, this);
3216
+ }, _callee28, this);
3294
3217
  }));
3295
- function hydrateTempOrderFromRecord(_x32, _x33) {
3218
+ function hydrateTempOrderFromRecord(_x29, _x30) {
3296
3219
  return _hydrateTempOrderFromRecord.apply(this, arguments);
3297
3220
  }
3298
3221
  return hydrateTempOrderFromRecord;
@@ -3300,7 +3223,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3300
3223
  }, {
3301
3224
  key: "normalizeTempOrderForRuntime",
3302
3225
  value: function normalizeTempOrderForRuntime(raw, options) {
3303
- var _this11 = this;
3226
+ var _this12 = this;
3304
3227
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3305
3228
  delete nextTempOrder.summary;
3306
3229
  delete nextTempOrder.lastOrderInfo;
@@ -3319,7 +3242,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3319
3242
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3320
3243
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
3321
3244
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
3322
- return _this11.normalizeHydratedOrderProduct(p);
3245
+ return _this12.normalizeHydratedOrderProduct(p);
3323
3246
  }) : [];
3324
3247
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3325
3248
  return _objectSpread(_objectSpread({}, b || {}), {}, {
@@ -3347,14 +3270,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3347
3270
  };
3348
3271
  var tempOrderExtend = nextTempOrder._extend;
3349
3272
  var productsByUid = tempOrderExtend.productsByUid || {};
3350
- var _iterator8 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3351
- _step8;
3273
+ var _iterator9 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3274
+ _step9;
3352
3275
  try {
3353
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3276
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3354
3277
  var _product$metadata6, _ref24, _ref25, _existed$origin, _rawProduct$metadata;
3355
- var _step8$value = _slicedToArray(_step8.value, 2),
3356
- index = _step8$value[0],
3357
- product = _step8$value[1];
3278
+ var _step9$value = _slicedToArray(_step9.value, 2),
3279
+ index = _step9$value[0],
3280
+ product = _step9$value[1];
3358
3281
  var uid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
3359
3282
  if (!uid) continue;
3360
3283
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
@@ -3375,9 +3298,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3375
3298
  });
3376
3299
  }
3377
3300
  } catch (err) {
3378
- _iterator8.e(err);
3301
+ _iterator9.e(err);
3379
3302
  } finally {
3380
- _iterator8.f();
3303
+ _iterator9.f();
3381
3304
  }
3382
3305
  tempOrderExtend.productsByUid = productsByUid;
3383
3306
  if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
@@ -3408,18 +3331,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3408
3331
  var segments = [];
3409
3332
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
3410
3333
  if (Array.isArray(sku.variant)) {
3411
- var _iterator9 = _createForOfIteratorHelper(sku.variant),
3412
- _step9;
3334
+ var _iterator10 = _createForOfIteratorHelper(sku.variant),
3335
+ _step10;
3413
3336
  try {
3414
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3415
- var variant = _step9.value;
3337
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3338
+ var variant = _step10.value;
3416
3339
  var segment = this.formatHydratedNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
3417
3340
  if (segment) segments.push(segment);
3418
3341
  }
3419
3342
  } catch (err) {
3420
- _iterator9.e(err);
3343
+ _iterator10.e(err);
3421
3344
  } finally {
3422
- _iterator9.f();
3345
+ _iterator10.f();
3423
3346
  }
3424
3347
  }
3425
3348
  return segments.join(', ');
@@ -3447,7 +3370,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3447
3370
  }, {
3448
3371
  key: "normalizeHydratedOrderProduct",
3449
3372
  value: function normalizeHydratedOrderProduct(product) {
3450
- var _this12 = this;
3373
+ var _this13 = this;
3451
3374
  var row = _objectSpread({}, product || {});
3452
3375
  if (row.num === undefined && row.product_quantity !== undefined) {
3453
3376
  row.num = row.product_quantity;
@@ -3455,7 +3378,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3455
3378
  var productSku = ensureProductSku(row);
3456
3379
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
3457
3380
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
3458
- return _this12.normalizeHydratedProductOptionItem(optionItem || {});
3381
+ return _this13.normalizeHydratedProductOptionItem(optionItem || {});
3459
3382
  }))
3460
3383
  });
3461
3384
  delete row["product_".concat('option', "_item")];
@@ -3475,7 +3398,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3475
3398
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
3476
3399
  });
3477
3400
  if (result.metadata) delete result.metadata.price_schema_version;
3478
- return result;
3401
+ return this.sanitizeOrderProductForTempOrder(result);
3479
3402
  }
3480
3403
  }, {
3481
3404
  key: "getLastOrderInfo",
@@ -3486,25 +3409,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3486
3409
  }, {
3487
3410
  key: "getOrderInfo",
3488
3411
  value: function () {
3489
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
3412
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order_id) {
3490
3413
  var res;
3491
- return _regeneratorRuntime().wrap(function _callee32$(_context34) {
3492
- while (1) switch (_context34.prev = _context34.next) {
3414
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3415
+ while (1) switch (_context31.prev = _context31.next) {
3493
3416
  case 0:
3494
- _context34.next = 2;
3417
+ _context31.next = 2;
3495
3418
  return this.request.get("/order/sales/".concat(order_id), {
3496
3419
  with: ['products', 'bookings']
3497
3420
  });
3498
3421
  case 2:
3499
- res = _context34.sent;
3500
- return _context34.abrupt("return", res);
3422
+ res = _context31.sent;
3423
+ return _context31.abrupt("return", res);
3501
3424
  case 4:
3502
3425
  case "end":
3503
- return _context34.stop();
3426
+ return _context31.stop();
3504
3427
  }
3505
- }, _callee32, this);
3428
+ }, _callee29, this);
3506
3429
  }));
3507
- function getOrderInfo(_x34) {
3430
+ function getOrderInfo(_x31) {
3508
3431
  return _getOrderInfo.apply(this, arguments);
3509
3432
  }
3510
3433
  return getOrderInfo;
@@ -3526,67 +3449,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3526
3449
  var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
3527
3450
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3528
3451
  };
3529
- var _iterator10 = _createForOfIteratorHelper(productList),
3530
- _step10;
3452
+ var _iterator11 = _createForOfIteratorHelper(productList),
3453
+ _step11;
3531
3454
  try {
3532
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3533
- var product = _step10.value;
3455
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3456
+ var product = _step11.value;
3534
3457
  var qty = product.num || 1;
3535
- var _iterator12 = _createForOfIteratorHelper(product.discount_list || []),
3536
- _step12;
3458
+ var _iterator13 = _createForOfIteratorHelper(product.discount_list || []),
3459
+ _step13;
3537
3460
  try {
3538
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3539
- var pd = _step12.value;
3461
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3462
+ var pd = _step13.value;
3540
3463
  addDiscountAmount(pd, qty);
3541
3464
  }
3542
3465
  } catch (err) {
3543
- _iterator12.e(err);
3466
+ _iterator13.e(err);
3544
3467
  } finally {
3545
- _iterator12.f();
3468
+ _iterator13.f();
3546
3469
  }
3547
- var _iterator13 = _createForOfIteratorHelper(product.product_bundle || []),
3548
- _step13;
3470
+ var _iterator14 = _createForOfIteratorHelper(product.product_bundle || []),
3471
+ _step14;
3549
3472
  try {
3550
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3473
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3551
3474
  var _ref28, _bundle$num;
3552
- var bundle = _step13.value;
3475
+ var bundle = _step14.value;
3553
3476
  var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref28 = (_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref28 !== void 0 ? _ref28 : 1) || 1).toNumber();
3554
- var _iterator14 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3555
- _step14;
3477
+ var _iterator15 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3478
+ _step15;
3556
3479
  try {
3557
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3558
- var _pd = _step14.value;
3480
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
3481
+ var _pd = _step15.value;
3559
3482
  addDiscountAmount(_pd, bundleQty);
3560
3483
  }
3561
3484
  } catch (err) {
3562
- _iterator14.e(err);
3485
+ _iterator15.e(err);
3563
3486
  } finally {
3564
- _iterator14.f();
3487
+ _iterator15.f();
3565
3488
  }
3566
3489
  }
3567
3490
  } catch (err) {
3568
- _iterator13.e(err);
3491
+ _iterator14.e(err);
3569
3492
  } finally {
3570
- _iterator13.f();
3493
+ _iterator14.f();
3571
3494
  }
3572
3495
  }
3573
3496
  } catch (err) {
3574
- _iterator10.e(err);
3497
+ _iterator11.e(err);
3575
3498
  } finally {
3576
- _iterator10.f();
3499
+ _iterator11.f();
3577
3500
  }
3578
- var _iterator11 = _createForOfIteratorHelper(discountList),
3579
- _step11;
3501
+ var _iterator12 = _createForOfIteratorHelper(discountList),
3502
+ _step12;
3580
3503
  try {
3581
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3582
- var d = _step11.value;
3504
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3505
+ var d = _step12.value;
3583
3506
  var key = d.id;
3584
3507
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
3585
3508
  }
3586
3509
  } catch (err) {
3587
- _iterator11.e(err);
3510
+ _iterator12.e(err);
3588
3511
  } finally {
3589
- _iterator11.f();
3512
+ _iterator12.f();
3590
3513
  }
3591
3514
  }
3592
3515
  }]);