@pisell/pisellos 2.2.192 → 2.2.193

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 (36) hide show
  1. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  2. package/dist/modules/Order/index.d.ts +12 -10
  3. package/dist/modules/Order/index.js +462 -571
  4. package/dist/modules/Order/types.d.ts +5 -5
  5. package/dist/modules/Order/utils.js +3 -3
  6. package/dist/modules/Payment/utils.js +2 -1
  7. package/dist/modules/SalesSummary/utils.js +1 -1
  8. package/dist/server/index.d.ts +8 -1
  9. package/dist/server/index.js +651 -464
  10. package/dist/server/modules/order/index.d.ts +3 -2
  11. package/dist/server/modules/order/index.js +68 -52
  12. package/dist/solution/BaseSales/index.d.ts +2 -1
  13. package/dist/solution/BaseSales/index.js +116 -122
  14. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  15. package/dist/solution/BookingByStep/index.d.ts +1 -1
  16. package/dist/solution/BookingTicket/index.d.ts +1 -1
  17. package/dist/solution/ScanOrder/index.js +3 -1
  18. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  19. package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
  20. package/lib/modules/Order/index.d.ts +12 -10
  21. package/lib/modules/Order/index.js +94 -118
  22. package/lib/modules/Order/types.d.ts +5 -5
  23. package/lib/modules/Order/utils.js +4 -4
  24. package/lib/modules/Payment/utils.js +2 -1
  25. package/lib/modules/SalesSummary/utils.js +1 -3
  26. package/lib/server/index.d.ts +8 -1
  27. package/lib/server/index.js +143 -24
  28. package/lib/server/modules/order/index.d.ts +3 -2
  29. package/lib/server/modules/order/index.js +25 -15
  30. package/lib/solution/BaseSales/index.d.ts +2 -1
  31. package/lib/solution/BaseSales/index.js +53 -16
  32. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  33. package/lib/solution/BookingByStep/index.d.ts +1 -1
  34. package/lib/solution/BookingTicket/index.d.ts +1 -1
  35. package/lib/solution/ScanOrder/index.js +3 -1
  36. package/package.json +1 -1
@@ -41,7 +41,6 @@ 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';
45
44
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
46
45
  _inherits(OrderModule, _BaseModule);
47
46
  var _super = _createSuper(OrderModule);
@@ -55,7 +54,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
55
54
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
56
55
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
57
56
  // LoggerManager 实例
58
- _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
59
57
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
60
58
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
61
59
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
@@ -129,7 +127,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
129
127
  case 8:
130
128
  app = appPlugin.getApp();
131
129
  this.logger = app.logger;
132
- this.dbManager = app.sqlite;
133
130
  this.window = this.core.getPlugin('window');
134
131
  otherParams = options.otherParams || {};
135
132
  this.cacheId = otherParams.cacheId;
@@ -139,7 +136,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
139
136
  this.otherParams = otherParams;
140
137
  this.registerDiscountModules(options);
141
138
  this.logInfo('OrderModule initialized successfully');
142
- case 20:
139
+ case 19:
143
140
  case "end":
144
141
  return _context.stop();
145
142
  }
@@ -880,211 +877,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
880
877
  return "".concat(baseToken, "_payment_").concat(paidCount);
881
878
  }
882
879
  }, {
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",
880
+ key: "saveDraft",
901
881
  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;
882
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
904
883
  return _regeneratorRuntime().wrap(function _callee5$(_context7) {
905
884
  while (1) switch (_context7.prev = _context7.next) {
906
885
  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
886
  case "end":
941
887
  return _context7.stop();
942
888
  }
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]]);
889
+ }, _callee5);
1088
890
  }));
1089
891
  function saveDraft() {
1090
892
  return _saveDraft.apply(this, arguments);
@@ -1099,18 +901,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1099
901
  }, {
1100
902
  key: "hydrateTempOrderFromLocalRecord",
1101
903
  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) {
904
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(record) {
905
+ return _regeneratorRuntime().wrap(function _callee6$(_context8) {
906
+ while (1) switch (_context8.prev = _context8.next) {
1105
907
  case 0:
1106
- return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
908
+ return _context8.abrupt("return", this.hydrateTempOrderFromRecord(record));
1107
909
  case 1:
1108
910
  case "end":
1109
- return _context11.stop();
911
+ return _context8.stop();
1110
912
  }
1111
- }, _callee9, this);
913
+ }, _callee6, this);
1112
914
  }));
1113
- function hydrateTempOrderFromLocalRecord(_x9) {
915
+ function hydrateTempOrderFromLocalRecord(_x6) {
1114
916
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
1115
917
  }
1116
918
  return hydrateTempOrderFromLocalRecord;
@@ -1168,11 +970,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1168
970
  return;
1169
971
  }
1170
972
  if (paymentTotal.lte(0)) {
1171
- tempOrder.payment_status = tempOrder.payment_status || 'payment_processing';
973
+ tempOrder.payment_status = 'payment_processing';
1172
974
  return;
1173
975
  }
1174
976
  tempOrder.payment_status = paymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
1175
977
  }
978
+ }, {
979
+ key: "resolveWalletPassUseValue",
980
+ value: function resolveWalletPassUseValue(payment, amount) {
981
+ var usageUnit = payment.wallet_pass_usage_unit && _typeof(payment.wallet_pass_usage_unit) === 'object' ? payment.wallet_pass_usage_unit : null;
982
+ if (!usageUnit) return payment.wallet_pass_use_value;
983
+ var price = new Decimal(usageUnit.price || 0);
984
+ var points = new Decimal(usageUnit.points || 0);
985
+ if (price.lte(0) || points.lte(0)) return payment.wallet_pass_use_value;
986
+ return amount.div(price).times(points).toDecimalPlaces(2).toFixed(2);
987
+ }
988
+ }, {
989
+ key: "capVoucherPaymentsByRemainingAmount",
990
+ value: function capVoucherPaymentsByRemainingAmount(params) {
991
+ var targetAmount = this.getPaymentTargetAmount();
992
+ var nonVoucherTotal = this.calculatePaymentTotal(params.nonVoucherPayments);
993
+ if (targetAmount.lte(0)) return [];
994
+ var remainingAmount = Decimal.max(targetAmount.minus(nonVoucherTotal), 0);
995
+ var cappedVouchers = [];
996
+ var _iterator5 = _createForOfIteratorHelper(params.vouchers),
997
+ _step5;
998
+ try {
999
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1000
+ var voucher = _step5.value;
1001
+ if (remainingAmount.lte(0)) break;
1002
+ var voucherAmount = Decimal.max(new Decimal(voucher.amount || 0), 0);
1003
+ if (voucherAmount.lte(0)) continue;
1004
+ var cappedAmount = Decimal.min(voucherAmount, remainingAmount);
1005
+ var amountText = cappedAmount.toDecimalPlaces(2).toFixed(2);
1006
+ cappedVouchers.push(_objectSpread(_objectSpread({}, voucher), {}, {
1007
+ amount: amountText,
1008
+ origin_amount: amountText,
1009
+ wallet_pass_use_value: this.resolveWalletPassUseValue(voucher, cappedAmount)
1010
+ }));
1011
+ remainingAmount = remainingAmount.minus(cappedAmount);
1012
+ }
1013
+ } catch (err) {
1014
+ _iterator5.e(err);
1015
+ } finally {
1016
+ _iterator5.f();
1017
+ }
1018
+ return cappedVouchers;
1019
+ }
1176
1020
  }, {
1177
1021
  key: "calculatePaidPaymentSummary",
1178
1022
  value: function calculatePaidPaymentSummary(payments) {
@@ -1183,7 +1027,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1183
1027
  return {
1184
1028
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1185
1029
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
1186
- gapPaidAmount: summary.gapPaidAmount.plus(_this4.calculatePaymentEffectiveAmount(paymentRecord)),
1030
+ gapPaidAmount: summary.gapPaidAmount.plus(_this4.calculatePaymentGapAmount(paymentRecord)),
1187
1031
  payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this4.calculatePaymentServiceFee(paymentRecord))
1188
1032
  };
1189
1033
  }, {
@@ -1204,6 +1048,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1204
1048
  var fixedAmount = new Decimal(serviceCharge.amount || 0);
1205
1049
  return new Decimal(payment.amount || 0).times(percentage).plus(fixedAmount);
1206
1050
  }
1051
+ }, {
1052
+ key: "calculatePaymentGapAmount",
1053
+ value: function calculatePaymentGapAmount(payment) {
1054
+ if (payment.origin_amount === undefined || payment.origin_amount === null || payment.origin_amount === '') {
1055
+ return new Decimal(0);
1056
+ }
1057
+ var rounding = new Decimal(payment.rounding_amount || 0);
1058
+ return new Decimal(payment.origin_amount || 0).minus(rounding);
1059
+ }
1207
1060
  }, {
1208
1061
  key: "formatSummaryMetadataMoney",
1209
1062
  value: function formatSummaryMetadataMoney(value) {
@@ -1215,28 +1068,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1215
1068
  key: "syncSummaryProductMetadata",
1216
1069
  value: function syncSummaryProductMetadata(products) {
1217
1070
  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;
1071
+ var _iterator6 = _createForOfIteratorHelper(products || []),
1072
+ _step6;
1220
1073
  try {
1221
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1222
- var product = _step5.value;
1074
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1075
+ var product = _step6.value;
1223
1076
  var productRecord = product;
1224
1077
  var metadata = productRecord.metadata && _typeof(productRecord.metadata) === 'object' ? _objectSpread({}, productRecord.metadata) : {};
1225
1078
  var hasMetadataPatch = false;
1226
- var _iterator6 = _createForOfIteratorHelper(moneyKeys),
1227
- _step6;
1079
+ var _iterator7 = _createForOfIteratorHelper(moneyKeys),
1080
+ _step7;
1228
1081
  try {
1229
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1230
- var key = _step6.value;
1082
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1083
+ var key = _step7.value;
1231
1084
  var value = this.formatSummaryMetadataMoney(productRecord[key]);
1232
1085
  if (value === undefined) continue;
1233
1086
  metadata[key] = value;
1234
1087
  hasMetadataPatch = true;
1235
1088
  }
1236
1089
  } catch (err) {
1237
- _iterator6.e(err);
1090
+ _iterator7.e(err);
1238
1091
  } finally {
1239
- _iterator6.f();
1092
+ _iterator7.f();
1240
1093
  }
1241
1094
  if (Array.isArray(productRecord.relation_surcharge_ids)) {
1242
1095
  metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
@@ -1244,11 +1097,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1244
1097
  }
1245
1098
  if (hasMetadataPatch) productRecord.metadata = metadata;
1246
1099
  if (!Array.isArray(productRecord.product_bundle)) continue;
1247
- var _iterator7 = _createForOfIteratorHelper(productRecord.product_bundle),
1248
- _step7;
1100
+ var _iterator8 = _createForOfIteratorHelper(productRecord.product_bundle),
1101
+ _step8;
1249
1102
  try {
1250
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1251
- var bundle = _step7.value;
1103
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1104
+ var bundle = _step8.value;
1252
1105
  var bundleRecord = bundle;
1253
1106
  var bundleMetadata = bundleRecord.metadata && _typeof(bundleRecord.metadata) === 'object' ? _objectSpread({}, bundleRecord.metadata) : {};
1254
1107
  var hasBundleMetadataPatch = false;
@@ -1264,15 +1117,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1264
1117
  if (hasBundleMetadataPatch) bundleRecord.metadata = bundleMetadata;
1265
1118
  }
1266
1119
  } catch (err) {
1267
- _iterator7.e(err);
1120
+ _iterator8.e(err);
1268
1121
  } finally {
1269
- _iterator7.f();
1122
+ _iterator8.f();
1270
1123
  }
1271
1124
  }
1272
1125
  } catch (err) {
1273
- _iterator5.e(err);
1126
+ _iterator6.e(err);
1274
1127
  } finally {
1275
- _iterator5.f();
1128
+ _iterator6.f();
1276
1129
  }
1277
1130
  }
1278
1131
  }, {
@@ -1332,13 +1185,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1332
1185
  }, {
1333
1186
  key: "replaceTempOrder",
1334
1187
  value: function () {
1335
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
1188
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(tempOrder, options) {
1336
1189
  var nextTempOrder;
1337
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1338
- while (1) switch (_context12.prev = _context12.next) {
1190
+ return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1191
+ while (1) switch (_context9.prev = _context9.next) {
1339
1192
  case 0:
1340
1193
  if (isTempOrder(tempOrder)) {
1341
- _context12.next = 2;
1194
+ _context9.next = 2;
1342
1195
  break;
1343
1196
  }
1344
1197
  throw new Error('无效的 tempOrder 数据');
@@ -1348,15 +1201,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1348
1201
  });
1349
1202
  this.store.tempOrder = nextTempOrder;
1350
1203
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
1351
- _context12.next = 9;
1204
+ _context9.next = 9;
1352
1205
  break;
1353
1206
  }
1354
- _context12.next = 7;
1207
+ _context9.next = 7;
1355
1208
  return this.recalculateSummary({
1356
1209
  createIfMissing: false
1357
1210
  });
1358
1211
  case 7:
1359
- _context12.next = 10;
1212
+ _context9.next = 10;
1360
1213
  break;
1361
1214
  case 9:
1362
1215
  this.store.summary = createEmptySummary();
@@ -1365,20 +1218,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1365
1218
  this.persistTempOrder();
1366
1219
  }
1367
1220
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
1368
- _context12.next = 14;
1221
+ _context9.next = 14;
1369
1222
  break;
1370
1223
  }
1371
- _context12.next = 14;
1224
+ _context9.next = 14;
1372
1225
  return this.saveDraft();
1373
1226
  case 14:
1374
- return _context12.abrupt("return", nextTempOrder);
1227
+ return _context9.abrupt("return", nextTempOrder);
1375
1228
  case 15:
1376
1229
  case "end":
1377
- return _context12.stop();
1230
+ return _context9.stop();
1378
1231
  }
1379
- }, _callee10, this);
1232
+ }, _callee7, this);
1380
1233
  }));
1381
- function replaceTempOrder(_x10, _x11) {
1234
+ function replaceTempOrder(_x7, _x8) {
1382
1235
  return _replaceTempOrder.apply(this, arguments);
1383
1236
  }
1384
1237
  return replaceTempOrder;
@@ -1386,11 +1239,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1386
1239
  }, {
1387
1240
  key: "getOrderIdentity",
1388
1241
  value: function getOrderIdentity() {
1389
- var _ref7, _ref8, _tempOrder$order_id2, _tempOrder$_extend;
1242
+ var _ref7, _ref8, _tempOrder$order_id, _tempOrder$_extend;
1390
1243
  var tempOrder = this.store.tempOrder;
1391
1244
  if (!tempOrder) return null;
1392
1245
  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;
1246
+ 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
1247
  return {
1395
1248
  localId: this.cacheId || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.localId),
1396
1249
  orderId: orderId,
@@ -1461,32 +1314,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1461
1314
  }, {
1462
1315
  key: "addNewOrder",
1463
1316
  value: function () {
1464
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1317
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1465
1318
  var tempOrder;
1466
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1467
- while (1) switch (_context13.prev = _context13.next) {
1319
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1320
+ while (1) switch (_context10.prev = _context10.next) {
1468
1321
  case 0:
1469
1322
  tempOrder = this.ensureTempOrder();
1470
1323
  this.ensureExternalSaleNumber(tempOrder);
1471
- _context13.next = 4;
1324
+ _context10.next = 4;
1472
1325
  return this.recalculateSummary({
1473
1326
  createIfMissing: true
1474
1327
  });
1475
1328
  case 4:
1476
1329
  this.persistTempOrder();
1477
1330
  if (!this.draftPersistEnabled) {
1478
- _context13.next = 8;
1331
+ _context10.next = 8;
1479
1332
  break;
1480
1333
  }
1481
- _context13.next = 8;
1334
+ _context10.next = 8;
1482
1335
  return this.saveDraft();
1483
1336
  case 8:
1484
- return _context13.abrupt("return", tempOrder);
1337
+ return _context10.abrupt("return", tempOrder);
1485
1338
  case 9:
1486
1339
  case "end":
1487
- return _context13.stop();
1340
+ return _context10.stop();
1488
1341
  }
1489
- }, _callee11, this);
1342
+ }, _callee8, this);
1490
1343
  }));
1491
1344
  function addNewOrder() {
1492
1345
  return _addNewOrder.apply(this, arguments);
@@ -1508,6 +1361,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1508
1361
  product.metadata = metadata;
1509
1362
  return String(uid);
1510
1363
  }
1364
+ }, {
1365
+ key: "sanitizeOrderProductForTempOrder",
1366
+ value: function sanitizeOrderProductForTempOrder(product) {
1367
+ if (product.metadata && _typeof(product.metadata) === 'object') {
1368
+ delete product.metadata.origin;
1369
+ }
1370
+ return product;
1371
+ }
1372
+ }, {
1373
+ key: "sanitizeTempOrderProducts",
1374
+ value: function sanitizeTempOrderProducts(tempOrder) {
1375
+ var _this5 = this;
1376
+ tempOrder.products = (tempOrder.products || []).map(function (product) {
1377
+ return _this5.sanitizeOrderProductForTempOrder(product);
1378
+ });
1379
+ }
1511
1380
  }, {
1512
1381
  key: "ensureExtend",
1513
1382
  value: function ensureExtend(tempOrder) {
@@ -1573,9 +1442,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1573
1442
  }, {
1574
1443
  key: "findBookingIndexByUniqueIdentificationNumber",
1575
1444
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1576
- var _this5 = this;
1445
+ var _this6 = this;
1577
1446
  return (tempOrder.bookings || []).findIndex(function (booking) {
1578
- return _this5.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1447
+ return _this6.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1579
1448
  });
1580
1449
  }
1581
1450
  }, {
@@ -1583,12 +1452,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1583
1452
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
1584
1453
  var _product$metadata4,
1585
1454
  _product$metadata5,
1586
- _this6 = this;
1455
+ _this7 = this;
1587
1456
  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
1457
  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
1458
  if (!productUid && !bookingUid) return;
1590
1459
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1591
- var currentBookingUid = _this6.getBookingUniqueIdentificationNumber(booking);
1460
+ var currentBookingUid = _this7.getBookingUniqueIdentificationNumber(booking);
1592
1461
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1593
1462
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1594
1463
  return true;
@@ -1605,23 +1474,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1605
1474
  }, {
1606
1475
  key: "recalculateSummary",
1607
1476
  value: function () {
1608
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
1477
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(options) {
1609
1478
  var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1610
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1611
- while (1) switch (_context14.prev = _context14.next) {
1479
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1480
+ while (1) switch (_context11.prev = _context11.next) {
1612
1481
  case 0:
1613
1482
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1614
1483
  if (tempOrder) {
1615
- _context14.next = 3;
1484
+ _context11.next = 3;
1616
1485
  break;
1617
1486
  }
1618
- return _context14.abrupt("return", null);
1487
+ return _context11.abrupt("return", null);
1619
1488
  case 3:
1489
+ this.sanitizeTempOrderProducts(tempOrder);
1620
1490
  salesSummary = this.getSalesSummary();
1621
1491
  existedSummary = this.store.summary || createEmptySummary();
1622
1492
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1623
1493
  if (salesSummary) {
1624
- _context14.next = 11;
1494
+ _context11.next = 13;
1625
1495
  break;
1626
1496
  }
1627
1497
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
@@ -1635,18 +1505,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1635
1505
  }),
1636
1506
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1637
1507
  });
1638
- this.store.summary = emptySummary;
1639
1508
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1640
- return _context14.abrupt("return", this.store.summary);
1641
- case 11:
1642
- _context14.next = 13;
1509
+ this.updateTempOrderPaymentStatus(tempOrder);
1510
+ this.store.summary = emptySummary;
1511
+ return _context11.abrupt("return", this.store.summary);
1512
+ case 13:
1513
+ _context11.next = 15;
1643
1514
  return salesSummary.getSummary({
1644
1515
  products: tempOrder.products,
1645
1516
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1646
1517
  shopDiscount: tempOrder.shop_discount
1647
1518
  });
1648
- case 13:
1649
- salesSummaryResult = _context14.sent;
1519
+ case 15:
1520
+ salesSummaryResult = _context11.sent;
1650
1521
  this.syncSummaryProductMetadata(tempOrder.products || []);
1651
1522
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1652
1523
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
@@ -1670,14 +1541,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1670
1541
  tempOrder.surcharges = summary.surcharges || [];
1671
1542
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1672
1543
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1673
- return _context14.abrupt("return", this.store.summary);
1674
- case 24:
1544
+ this.updateTempOrderPaymentStatus(tempOrder);
1545
+ return _context11.abrupt("return", this.store.summary);
1546
+ case 27:
1675
1547
  case "end":
1676
- return _context14.stop();
1548
+ return _context11.stop();
1677
1549
  }
1678
- }, _callee12, this);
1550
+ }, _callee9, this);
1679
1551
  }));
1680
- function recalculateSummary(_x12) {
1552
+ function recalculateSummary(_x9) {
1681
1553
  return _recalculateSummary.apply(this, arguments);
1682
1554
  }
1683
1555
  return recalculateSummary;
@@ -1685,30 +1557,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1685
1557
  }, {
1686
1558
  key: "getOrderSummary",
1687
1559
  value: function () {
1688
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1560
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1689
1561
  var summary;
1690
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1691
- while (1) switch (_context15.prev = _context15.next) {
1562
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1563
+ while (1) switch (_context12.prev = _context12.next) {
1692
1564
  case 0:
1693
- _context15.next = 2;
1565
+ _context12.next = 2;
1694
1566
  return this.recalculateSummary({
1695
1567
  createIfMissing: true
1696
1568
  });
1697
1569
  case 2:
1698
- summary = _context15.sent;
1570
+ summary = _context12.sent;
1699
1571
  if (summary) {
1700
- _context15.next = 5;
1572
+ _context12.next = 5;
1701
1573
  break;
1702
1574
  }
1703
- return _context15.abrupt("return", createEmptySummary());
1575
+ return _context12.abrupt("return", createEmptySummary());
1704
1576
  case 5:
1705
1577
  this.persistTempOrder();
1706
- return _context15.abrupt("return", summary);
1578
+ return _context12.abrupt("return", summary);
1707
1579
  case 7:
1708
1580
  case "end":
1709
- return _context15.stop();
1581
+ return _context12.stop();
1710
1582
  }
1711
- }, _callee13, this);
1583
+ }, _callee10, this);
1712
1584
  }));
1713
1585
  function getOrderSummary() {
1714
1586
  return _getOrderSummary.apply(this, arguments);
@@ -1732,23 +1604,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1732
1604
  }, {
1733
1605
  key: "syncTempOrderNoteToRemote",
1734
1606
  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) {
1607
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderId, note) {
1608
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
1609
+ while (1) switch (_context13.prev = _context13.next) {
1738
1610
  case 0:
1739
- _context16.next = 2;
1611
+ _context13.next = 2;
1740
1612
  return this.request.put("/order/order/".concat(orderId, "/note"), {
1741
1613
  note: note
1742
1614
  });
1743
1615
  case 2:
1744
- return _context16.abrupt("return", note);
1616
+ return _context13.abrupt("return", note);
1745
1617
  case 3:
1746
1618
  case "end":
1747
- return _context16.stop();
1619
+ return _context13.stop();
1748
1620
  }
1749
- }, _callee14, this);
1621
+ }, _callee11, this);
1750
1622
  }));
1751
- function syncTempOrderNoteToRemote(_x13, _x14) {
1623
+ function syncTempOrderNoteToRemote(_x10, _x11) {
1752
1624
  return _syncTempOrderNoteToRemote.apply(this, arguments);
1753
1625
  }
1754
1626
  return syncTempOrderNoteToRemote;
@@ -1960,7 +1832,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1960
1832
  }, {
1961
1833
  key: "addOrderPayment",
1962
1834
  value: function addOrderPayment(payment) {
1963
- var _this7 = this;
1835
+ var _this8 = this;
1964
1836
  this.logInfo('addOrderPayment', {
1965
1837
  payment: payment
1966
1838
  });
@@ -1973,7 +1845,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1973
1845
  void this.recalculateSummary({
1974
1846
  createIfMissing: true
1975
1847
  }).catch(function (error) {
1976
- _this7.logError('recalculate summary after addOrderPayment failed', {
1848
+ _this8.logError('recalculate summary after addOrderPayment failed', {
1977
1849
  error: error instanceof Error ? error.message : String(error)
1978
1850
  });
1979
1851
  });
@@ -2038,10 +1910,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2038
1910
  }, {
2039
1911
  key: "updateVoucherOrderPayments",
2040
1912
  value: function updateVoucherOrderPayments(payments) {
2041
- var _this8 = this;
1913
+ var _this9 = this;
2042
1914
  var tempOrder = this.ensureTempOrder();
2043
1915
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
2044
- return _this8.normalizePaymentSource(payment, {
1916
+ return _this9.normalizePaymentSource(payment, {
2045
1917
  defaultPaid: false
2046
1918
  });
2047
1919
  })).filter(function (payment) {
@@ -2050,13 +1922,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2050
1922
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
2051
1923
  return payment.voucher_id === undefined || Number(payment.voucher_id) === 0;
2052
1924
  });
2053
- tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(mappedVouchers));
1925
+ var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
1926
+ vouchers: mappedVouchers,
1927
+ nonVoucherPayments: nonVoucherPayments
1928
+ });
1929
+ tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(cappedVouchers));
2054
1930
  this.updateTempOrderPaymentStatus(tempOrder);
2055
1931
  this.persistTempOrder();
2056
1932
  void this.recalculateSummary({
2057
1933
  createIfMissing: true
2058
1934
  }).catch(function (error) {
2059
- _this8.logError('recalculate summary after updateVoucherOrderPayments failed', {
1935
+ _this9.logError('recalculate summary after updateVoucherOrderPayments failed', {
2060
1936
  error: error instanceof Error ? error.message : String(error)
2061
1937
  });
2062
1938
  });
@@ -2065,45 +1941,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2065
1941
  }, {
2066
1942
  key: "shouldMergeProductToOrder",
2067
1943
  value: function () {
2068
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1944
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
2069
1945
  var _this$orderHooks;
2070
1946
  var onBeforeMergeProductToOrder, result;
2071
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2072
- while (1) switch (_context17.prev = _context17.next) {
1947
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
1948
+ while (1) switch (_context14.prev = _context14.next) {
2073
1949
  case 0:
2074
1950
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
2075
1951
  if (onBeforeMergeProductToOrder) {
2076
- _context17.next = 3;
1952
+ _context14.next = 3;
2077
1953
  break;
2078
1954
  }
2079
- return _context17.abrupt("return", true);
1955
+ return _context14.abrupt("return", true);
2080
1956
  case 3:
2081
- _context17.next = 5;
1957
+ _context14.next = 5;
2082
1958
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
2083
1959
  defaultShouldMerge: true
2084
1960
  }));
2085
1961
  case 5:
2086
- result = _context17.sent;
1962
+ result = _context14.sent;
2087
1963
  if (!(typeof result === 'boolean')) {
2088
- _context17.next = 8;
1964
+ _context14.next = 8;
2089
1965
  break;
2090
1966
  }
2091
- return _context17.abrupt("return", result);
1967
+ return _context14.abrupt("return", result);
2092
1968
  case 8:
2093
1969
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
2094
- _context17.next = 10;
1970
+ _context14.next = 10;
2095
1971
  break;
2096
1972
  }
2097
- return _context17.abrupt("return", result.shouldMerge);
1973
+ return _context14.abrupt("return", result.shouldMerge);
2098
1974
  case 10:
2099
- return _context17.abrupt("return", true);
1975
+ return _context14.abrupt("return", true);
2100
1976
  case 11:
2101
1977
  case "end":
2102
- return _context17.stop();
1978
+ return _context14.stop();
2103
1979
  }
2104
- }, _callee15, this);
1980
+ }, _callee12, this);
2105
1981
  }));
2106
- function shouldMergeProductToOrder(_x15) {
1982
+ function shouldMergeProductToOrder(_x12) {
2107
1983
  return _shouldMergeProductToOrder.apply(this, arguments);
2108
1984
  }
2109
1985
  return shouldMergeProductToOrder;
@@ -2111,11 +1987,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2111
1987
  }, {
2112
1988
  key: "addProductToOrder",
2113
1989
  value: function () {
2114
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2115
- var _this9 = this;
1990
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1991
+ var _this10 = this;
2116
1992
  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) {
1993
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1994
+ while (1) switch (_context15.prev = _context15.next) {
2119
1995
  case 0:
2120
1996
  tempOrder = this.ensureTempOrder();
2121
1997
  linked = booking ? this.createLinkedProductAndBooking({
@@ -2129,7 +2005,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2129
2005
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
2130
2006
  shouldForceNewLine = !!booking;
2131
2007
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
2132
- if (_this9.hasGoodPassDiscount(item)) return false;
2008
+ if (_this10.hasGoodPassDiscount(item)) return false;
2133
2009
  if (item.product_id !== productToAdd.product_id) return false;
2134
2010
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
2135
2011
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -2138,10 +2014,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2138
2014
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
2139
2015
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
2140
2016
  if (!matchedProduct) {
2141
- _context18.next = 17;
2017
+ _context15.next = 17;
2142
2018
  break;
2143
2019
  }
2144
- _context18.next = 14;
2020
+ _context15.next = 14;
2145
2021
  return this.shouldMergeProductToOrder({
2146
2022
  incomingProduct: productToAdd,
2147
2023
  normalizedIncoming: normalizedIncoming,
@@ -2153,13 +2029,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2153
2029
  booking: booking
2154
2030
  });
2155
2031
  case 14:
2156
- _context18.t0 = _context18.sent;
2157
- _context18.next = 18;
2032
+ _context15.t0 = _context15.sent;
2033
+ _context15.next = 18;
2158
2034
  break;
2159
2035
  case 17:
2160
- _context18.t0 = false;
2036
+ _context15.t0 = false;
2161
2037
  case 18:
2162
- shouldMerge = _context18.t0;
2038
+ shouldMerge = _context15.t0;
2163
2039
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
2164
2040
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
2165
2041
  if (linked) {
@@ -2198,24 +2074,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2198
2074
  if (linked) {
2199
2075
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
2200
2076
  }
2201
- _context18.next = 23;
2077
+ _context15.next = 23;
2202
2078
  return this.applyPromotion();
2203
2079
  case 23:
2204
2080
  this.applyDiscount();
2205
- _context18.next = 26;
2081
+ this.sanitizeTempOrderProducts(tempOrder);
2082
+ _context15.next = 27;
2206
2083
  return this.recalculateSummary({
2207
2084
  createIfMissing: true
2208
2085
  });
2209
- case 26:
2086
+ case 27:
2210
2087
  this.persistTempOrder();
2211
- return _context18.abrupt("return", tempOrder.products);
2212
- case 28:
2088
+ return _context15.abrupt("return", tempOrder.products);
2089
+ case 29:
2213
2090
  case "end":
2214
- return _context18.stop();
2091
+ return _context15.stop();
2215
2092
  }
2216
- }, _callee16, this);
2093
+ }, _callee13, this);
2217
2094
  }));
2218
- function addProductToOrder(_x16, _x17) {
2095
+ function addProductToOrder(_x13, _x14) {
2219
2096
  return _addProductToOrder.apply(this, arguments);
2220
2097
  }
2221
2098
  return addProductToOrder;
@@ -2242,11 +2119,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2242
2119
  }, {
2243
2120
  key: "updateOrderProduct",
2244
2121
  value: function () {
2245
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
2122
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2246
2123
  var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada7, _tempOrder$products$p;
2247
2124
  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) {
2125
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2126
+ while (1) switch (_context16.prev = _context16.next) {
2250
2127
  case 0:
2251
2128
  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
2129
  tempOrder = this.ensureTempOrder();
@@ -2277,7 +2154,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2277
2154
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2278
2155
  }
2279
2156
  if (!(productIndex === -1)) {
2280
- _context19.next = 12;
2157
+ _context16.next = 12;
2281
2158
  break;
2282
2159
  }
2283
2160
  throw new Error('[Order] 目标商品不存在,无法更新');
@@ -2358,24 +2235,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2358
2235
  }
2359
2236
  tempOrder.products[productIndex] = normalizedProduct;
2360
2237
  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;
2238
+ _context16.next = 29;
2362
2239
  return this.applyPromotion();
2363
2240
  case 29:
2364
2241
  this.applyDiscount();
2365
- _context19.next = 32;
2242
+ this.sanitizeTempOrderProducts(tempOrder);
2243
+ _context16.next = 33;
2366
2244
  return this.recalculateSummary({
2367
2245
  createIfMissing: true
2368
2246
  });
2369
- case 32:
2247
+ case 33:
2370
2248
  this.persistTempOrder();
2371
- return _context19.abrupt("return", tempOrder.products);
2372
- case 34:
2249
+ return _context16.abrupt("return", tempOrder.products);
2250
+ case 35:
2373
2251
  case "end":
2374
- return _context19.stop();
2252
+ return _context16.stop();
2375
2253
  }
2376
- }, _callee17, this);
2254
+ }, _callee14, this);
2377
2255
  }));
2378
- function updateOrderProduct(_x18) {
2256
+ function updateOrderProduct(_x15) {
2379
2257
  return _updateOrderProduct.apply(this, arguments);
2380
2258
  }
2381
2259
  return updateOrderProduct;
@@ -2383,11 +2261,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2383
2261
  }, {
2384
2262
  key: "updateOrderProductQuantity",
2385
2263
  value: function () {
2386
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2264
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
2387
2265
  var _targetProduct$metada9;
2388
2266
  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) {
2267
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2268
+ while (1) switch (_context17.prev = _context17.next) {
2391
2269
  case 0:
2392
2270
  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
2271
  tempOrder = this.ensureTempOrder();
@@ -2416,7 +2294,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2416
2294
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
2417
2295
  }
2418
2296
  if (!(productIndex === -1)) {
2419
- _context20.next = 12;
2297
+ _context17.next = 12;
2420
2298
  break;
2421
2299
  }
2422
2300
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -2430,24 +2308,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2430
2308
  }));
2431
2309
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2432
2310
  tempOrder.products[productIndex] = normalizedProduct;
2433
- _context20.next = 18;
2311
+ _context17.next = 18;
2434
2312
  return this.applyPromotion();
2435
2313
  case 18:
2436
2314
  this.applyDiscount();
2437
- _context20.next = 21;
2315
+ this.sanitizeTempOrderProducts(tempOrder);
2316
+ _context17.next = 22;
2438
2317
  return this.recalculateSummary({
2439
2318
  createIfMissing: true
2440
2319
  });
2441
- case 21:
2320
+ case 22:
2442
2321
  this.persistTempOrder();
2443
- return _context20.abrupt("return", tempOrder.products);
2444
- case 23:
2322
+ return _context17.abrupt("return", tempOrder.products);
2323
+ case 24:
2445
2324
  case "end":
2446
- return _context20.stop();
2325
+ return _context17.stop();
2447
2326
  }
2448
- }, _callee18, this);
2327
+ }, _callee15, this);
2449
2328
  }));
2450
- function updateOrderProductQuantity(_x19) {
2329
+ function updateOrderProductQuantity(_x16) {
2451
2330
  return _updateOrderProductQuantity.apply(this, arguments);
2452
2331
  }
2453
2332
  return updateOrderProductQuantity;
@@ -2478,10 +2357,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2478
2357
  }, {
2479
2358
  key: "removeProductFromOrder",
2480
2359
  value: function () {
2481
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2360
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(identity) {
2482
2361
  var tempOrder, removedProducts, _i, _removedProducts, product;
2483
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2484
- while (1) switch (_context21.prev = _context21.next) {
2362
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
2363
+ while (1) switch (_context18.prev = _context18.next) {
2485
2364
  case 0:
2486
2365
  tempOrder = this.ensureTempOrder();
2487
2366
  removedProducts = [];
@@ -2494,24 +2373,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2494
2373
  product = _removedProducts[_i];
2495
2374
  this.removeLinkedBookingsForProduct(tempOrder, product);
2496
2375
  }
2497
- _context21.next = 6;
2376
+ _context18.next = 6;
2498
2377
  return this.applyPromotion();
2499
2378
  case 6:
2500
2379
  this.applyDiscount();
2501
- _context21.next = 9;
2380
+ this.sanitizeTempOrderProducts(tempOrder);
2381
+ _context18.next = 10;
2502
2382
  return this.recalculateSummary({
2503
2383
  createIfMissing: true
2504
2384
  });
2505
- case 9:
2385
+ case 10:
2506
2386
  this.persistTempOrder();
2507
- return _context21.abrupt("return", tempOrder.products);
2508
- case 11:
2387
+ return _context18.abrupt("return", tempOrder.products);
2388
+ case 12:
2509
2389
  case "end":
2510
- return _context21.stop();
2390
+ return _context18.stop();
2511
2391
  }
2512
- }, _callee19, this);
2392
+ }, _callee16, this);
2513
2393
  }));
2514
- function removeProductFromOrder(_x20) {
2394
+ function removeProductFromOrder(_x17) {
2515
2395
  return _removeProductFromOrder.apply(this, arguments);
2516
2396
  }
2517
2397
  return removeProductFromOrder;
@@ -2523,10 +2403,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2523
2403
  }, {
2524
2404
  key: "clearOrderCartLines",
2525
2405
  value: (function () {
2526
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2406
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2527
2407
  var tempOrder;
2528
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2529
- while (1) switch (_context22.prev = _context22.next) {
2408
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
2409
+ while (1) switch (_context19.prev = _context19.next) {
2530
2410
  case 0:
2531
2411
  tempOrder = this.ensureTempOrder();
2532
2412
  tempOrder.products = [];
@@ -2536,22 +2416,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2536
2416
  productsByUid: {}
2537
2417
  });
2538
2418
  }
2539
- _context22.next = 6;
2419
+ _context19.next = 6;
2540
2420
  return this.applyPromotion();
2541
2421
  case 6:
2542
2422
  this.applyDiscount();
2543
- _context22.next = 9;
2423
+ this.sanitizeTempOrderProducts(tempOrder);
2424
+ _context19.next = 10;
2544
2425
  return this.recalculateSummary({
2545
2426
  createIfMissing: true
2546
2427
  });
2547
- case 9:
2428
+ case 10:
2548
2429
  this.persistTempOrder();
2549
- return _context22.abrupt("return", tempOrder);
2550
- case 11:
2430
+ return _context19.abrupt("return", tempOrder);
2431
+ case 12:
2551
2432
  case "end":
2552
- return _context22.stop();
2433
+ return _context19.stop();
2553
2434
  }
2554
- }, _callee20, this);
2435
+ }, _callee17, this);
2555
2436
  }));
2556
2437
  function clearOrderCartLines() {
2557
2438
  return _clearOrderCartLines.apply(this, arguments);
@@ -2562,17 +2443,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2562
2443
  * 提交当前 Sales tempOrder。
2563
2444
  *
2564
2445
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
2565
- * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
2446
+ * 应传 1,确保 /shop/order/sales/checkout 返回打印所需数据。
2566
2447
  */
2567
2448
  )
2568
2449
  }, {
2569
2450
  key: "submitTempOrder",
2570
2451
  value: function () {
2571
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2452
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
2572
2453
  var _params$cacheId, _this$otherParams, _ref23, _params$businessCode, _this$otherParams2, _this$otherParams3;
2573
2454
  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) {
2455
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
2456
+ while (1) switch (_context20.prev = _context20.next) {
2576
2457
  case 0:
2577
2458
  tempOrder = this.ensureTempOrder();
2578
2459
  this.persistTempOrder();
@@ -2601,10 +2482,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2601
2482
  enhance: enhancePayload
2602
2483
  }); // TODO: 前端生成的时间现在是有问题的,后面要统一优化
2603
2484
  payload.created_at = undefined;
2604
- _context23.next = 11;
2485
+ _context20.next = 11;
2605
2486
  return this.saveDraft();
2606
2487
  case 11:
2607
- _context23.prev = 11;
2488
+ _context20.prev = 11;
2608
2489
  this.logInfo('submitTempOrder calling sales checkout', {
2609
2490
  orderId: payload.order_id,
2610
2491
  externalSaleNumber: payload.external_sale_number,
@@ -2613,62 +2494,62 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2613
2494
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
2614
2495
  smallTicketDataFlag: payload.small_ticket_data_flag
2615
2496
  });
2616
- _context23.next = 15;
2497
+ _context20.next = 15;
2617
2498
  return this.submitSalesOrder({
2618
2499
  query: payload
2619
2500
  });
2620
2501
  case 15:
2621
- result = _context23.sent;
2622
- _context23.next = 28;
2502
+ result = _context20.sent;
2503
+ _context20.next = 28;
2623
2504
  break;
2624
2505
  case 18:
2625
- _context23.prev = 18;
2626
- _context23.t0 = _context23["catch"](11);
2627
- backendErrorResponse = this.extractSubmitErrorResponse(_context23.t0);
2506
+ _context20.prev = 18;
2507
+ _context20.t0 = _context20["catch"](11);
2508
+ backendErrorResponse = this.extractSubmitErrorResponse(_context20.t0);
2628
2509
  if (!backendErrorResponse) {
2629
- _context23.next = 25;
2510
+ _context20.next = 25;
2630
2511
  break;
2631
2512
  }
2632
2513
  this.store.syncState = 'failed';
2633
2514
  this.logSubmitBackendRejected(backendErrorResponse, payload);
2634
- return _context23.abrupt("return", backendErrorResponse);
2515
+ return _context20.abrupt("return", backendErrorResponse);
2635
2516
  case 25:
2636
2517
  this.store.syncState = 'failed';
2637
2518
  this.logError('submitTempOrder failed', {
2638
- error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
2519
+ error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
2639
2520
  orderId: payload.order_id,
2640
2521
  externalSaleNumber: payload.external_sale_number,
2641
2522
  paymentStatus: payload.payment_status,
2642
2523
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
2643
2524
  });
2644
- throw _context23.t0;
2525
+ throw _context20.t0;
2645
2526
  case 28:
2646
2527
  if (!this.isSubmitResponseRejected(result)) {
2647
- _context23.next = 32;
2528
+ _context20.next = 32;
2648
2529
  break;
2649
2530
  }
2650
2531
  this.store.syncState = 'failed';
2651
2532
  this.logSubmitBackendRejected(result, payload);
2652
- return _context23.abrupt("return", result);
2533
+ return _context20.abrupt("return", result);
2653
2534
  case 32:
2654
2535
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
2655
2536
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
2656
- _context23.next = 38;
2537
+ _context20.next = 38;
2657
2538
  break;
2658
2539
  }
2659
2540
  tempOrder.order_id = submittedOrderId;
2660
2541
  resultRecord = result;
2661
- _context23.next = 38;
2542
+ _context20.next = 38;
2662
2543
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
2663
2544
  case 38:
2664
- return _context23.abrupt("return", result);
2545
+ return _context20.abrupt("return", result);
2665
2546
  case 39:
2666
2547
  case "end":
2667
- return _context23.stop();
2548
+ return _context20.stop();
2668
2549
  }
2669
- }, _callee21, this, [[11, 18]]);
2550
+ }, _callee18, this, [[11, 18]]);
2670
2551
  }));
2671
- function submitTempOrder(_x21) {
2552
+ function submitTempOrder(_x18) {
2672
2553
  return _submitTempOrder.apply(this, arguments);
2673
2554
  }
2674
2555
  return submitTempOrder;
@@ -2676,25 +2557,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2676
2557
  }, {
2677
2558
  key: "markLocalOrderSynced",
2678
2559
  value: function () {
2679
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderId, remoteOrder) {
2560
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderId, remoteOrder) {
2680
2561
  var tempOrder;
2681
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2682
- while (1) switch (_context24.prev = _context24.next) {
2562
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
2563
+ while (1) switch (_context21.prev = _context21.next) {
2683
2564
  case 0:
2684
2565
  tempOrder = this.ensureTempOrder();
2685
2566
  tempOrder.order_id = orderId;
2686
2567
  this.store.lastOrderInfo = remoteOrder;
2687
2568
  this.store.syncState = 'submitted';
2688
2569
  this.persistTempOrder();
2689
- _context24.next = 7;
2570
+ _context21.next = 7;
2690
2571
  return this.saveDraft();
2691
2572
  case 7:
2692
2573
  case "end":
2693
- return _context24.stop();
2574
+ return _context21.stop();
2694
2575
  }
2695
- }, _callee22, this);
2576
+ }, _callee19, this);
2696
2577
  }));
2697
- function markLocalOrderSynced(_x22, _x23) {
2578
+ function markLocalOrderSynced(_x19, _x20) {
2698
2579
  return _markLocalOrderSynced.apply(this, arguments);
2699
2580
  }
2700
2581
  return markLocalOrderSynced;
@@ -2718,10 +2599,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2718
2599
  value: function extractSubmitErrorResponse(error) {
2719
2600
  var _error$response,
2720
2601
  _error$response2,
2721
- _this10 = this;
2602
+ _this11 = this;
2722
2603
  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
2604
  return candidates.find(function (candidate) {
2724
- return _this10.isSubmitErrorResponse(candidate);
2605
+ return _this11.isSubmitErrorResponse(candidate);
2725
2606
  }) || null;
2726
2607
  }
2727
2608
  }, {
@@ -2741,10 +2622,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2741
2622
  }, {
2742
2623
  key: "syncPaymentsToOrder",
2743
2624
  value: function () {
2744
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2625
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2745
2626
  var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
2746
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2747
- while (1) switch (_context25.prev = _context25.next) {
2627
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
2628
+ while (1) switch (_context22.prev = _context22.next) {
2748
2629
  case 0:
2749
2630
  tempOrder = this.ensureTempOrder();
2750
2631
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
@@ -2755,28 +2636,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2755
2636
  tempOrder.payments = mappedPayments;
2756
2637
  tempOrder.payment_status = paymentStatus;
2757
2638
  this.persistTempOrder();
2758
- _context25.next = 11;
2639
+ _context22.next = 11;
2759
2640
  return this.saveDraft();
2760
2641
  case 11:
2761
2642
  if (params.submitWhenPaid) {
2762
- _context25.next = 13;
2643
+ _context22.next = 13;
2763
2644
  break;
2764
2645
  }
2765
- return _context25.abrupt("return", {
2646
+ return _context22.abrupt("return", {
2766
2647
  isFullyPaid: isFullyPaid
2767
2648
  });
2768
2649
  case 13:
2769
2650
  if (!(this.store.syncState === 'submitting')) {
2770
- _context25.next = 15;
2651
+ _context22.next = 15;
2771
2652
  break;
2772
2653
  }
2773
- return _context25.abrupt("return", {
2654
+ return _context22.abrupt("return", {
2774
2655
  isFullyPaid: isFullyPaid
2775
2656
  });
2776
2657
  case 15:
2777
2658
  this.store.syncState = 'submitting';
2778
2659
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
2779
- _context25.next = 19;
2660
+ _context22.next = 19;
2780
2661
  return this.submitTempOrder({
2781
2662
  payments: mappedPayments,
2782
2663
  paymentStatus: paymentStatus,
@@ -2791,18 +2672,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2791
2672
  }
2792
2673
  });
2793
2674
  case 19:
2794
- submitResult = _context25.sent;
2795
- return _context25.abrupt("return", {
2675
+ submitResult = _context22.sent;
2676
+ return _context22.abrupt("return", {
2796
2677
  isFullyPaid: isFullyPaid,
2797
2678
  submitResult: submitResult
2798
2679
  });
2799
2680
  case 21:
2800
2681
  case "end":
2801
- return _context25.stop();
2682
+ return _context22.stop();
2802
2683
  }
2803
- }, _callee23, this);
2684
+ }, _callee20, this);
2804
2685
  }));
2805
- function syncPaymentsToOrder(_x24) {
2686
+ function syncPaymentsToOrder(_x21) {
2806
2687
  return _syncPaymentsToOrder.apply(this, arguments);
2807
2688
  }
2808
2689
  return syncPaymentsToOrder;
@@ -2891,11 +2772,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2891
2772
  }, {
2892
2773
  key: "submitOrder",
2893
2774
  value: function () {
2894
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order) {
2775
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order) {
2895
2776
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
2896
2777
  var url, query, fetchUrl, params;
2897
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2898
- while (1) switch (_context26.prev = _context26.next) {
2778
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
2779
+ while (1) switch (_context23.prev = _context23.next) {
2899
2780
  case 0:
2900
2781
  this.logInfo('submitOrder called', {
2901
2782
  url: order.url,
@@ -2915,14 +2796,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2915
2796
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
2916
2797
  scheduleDate: params.schedule_date
2917
2798
  });
2918
- return _context26.abrupt("return", this.request.post(fetchUrl, params));
2799
+ return _context23.abrupt("return", this.request.post(fetchUrl, params));
2919
2800
  case 6:
2920
2801
  case "end":
2921
- return _context26.stop();
2802
+ return _context23.stop();
2922
2803
  }
2923
- }, _callee24, this);
2804
+ }, _callee21, this);
2924
2805
  }));
2925
- function submitOrder(_x25) {
2806
+ function submitOrder(_x22) {
2926
2807
  return _submitOrder.apply(this, arguments);
2927
2808
  }
2928
2809
  return submitOrder;
@@ -2930,13 +2811,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2930
2811
  }, {
2931
2812
  key: "cancelOrder",
2932
2813
  value: function () {
2933
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2814
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2934
2815
  var payload;
2935
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
2936
- while (1) switch (_context27.prev = _context27.next) {
2816
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
2817
+ while (1) switch (_context24.prev = _context24.next) {
2937
2818
  case 0:
2938
2819
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
2939
- _context27.next = 2;
2820
+ _context24.next = 2;
2940
2821
  break;
2941
2822
  }
2942
2823
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -2952,16 +2833,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2952
2833
  method: 'PUT',
2953
2834
  orderIdsCount: params.order_ids.length
2954
2835
  });
2955
- return _context27.abrupt("return", this.request.put('/order/update-status', payload, {
2836
+ return _context24.abrupt("return", this.request.put('/order/update-status', payload, {
2956
2837
  isShopApi: true
2957
2838
  }));
2958
2839
  case 5:
2959
2840
  case "end":
2960
- return _context27.stop();
2841
+ return _context24.stop();
2961
2842
  }
2962
- }, _callee25, this);
2843
+ }, _callee22, this);
2963
2844
  }));
2964
- function cancelOrder(_x26) {
2845
+ function cancelOrder(_x23) {
2965
2846
  return _cancelOrder.apply(this, arguments);
2966
2847
  }
2967
2848
  return cancelOrder;
@@ -2969,19 +2850,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2969
2850
  }, {
2970
2851
  key: "changeBookingStatus",
2971
2852
  value: function () {
2972
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2853
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2973
2854
  var url, payload;
2974
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
2975
- while (1) switch (_context28.prev = _context28.next) {
2855
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
2856
+ while (1) switch (_context25.prev = _context25.next) {
2976
2857
  case 0:
2977
2858
  if (params.booking_id) {
2978
- _context28.next = 2;
2859
+ _context25.next = 2;
2979
2860
  break;
2980
2861
  }
2981
2862
  throw new Error('变更预约状态失败:booking_id 不能为空');
2982
2863
  case 2:
2983
2864
  if (params.appointment_status) {
2984
- _context28.next = 4;
2865
+ _context25.next = 4;
2985
2866
  break;
2986
2867
  }
2987
2868
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2996,16 +2877,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2996
2877
  bookingId: params.booking_id,
2997
2878
  appointmentStatus: params.appointment_status
2998
2879
  });
2999
- return _context28.abrupt("return", this.request.put(url, payload, {
2880
+ return _context25.abrupt("return", this.request.put(url, payload, {
3000
2881
  isShopApi: true
3001
2882
  }));
3002
2883
  case 8:
3003
2884
  case "end":
3004
- return _context28.stop();
2885
+ return _context25.stop();
3005
2886
  }
3006
- }, _callee26, this);
2887
+ }, _callee23, this);
3007
2888
  }));
3008
- function changeBookingStatus(_x27) {
2889
+ function changeBookingStatus(_x24) {
3009
2890
  return _changeBookingStatus.apply(this, arguments);
3010
2891
  }
3011
2892
  return changeBookingStatus;
@@ -3014,7 +2895,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3014
2895
  * Checkout 专用:创建订单到后端
3015
2896
  *
3016
2897
  * 专门为 Checkout 模块设计的订单创建方法,
3017
- * 直接调用 /order/checkout 接口创建订单
2898
+ * 通过 OS Server 调用 checkout 接口创建订单
3018
2899
  * 接收已经处理好的订单数据,无需再处理购物车
3019
2900
  *
3020
2901
  * @param params Checkout 订单参数(已处理的订单数据)
@@ -3023,11 +2904,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3023
2904
  }, {
3024
2905
  key: "createOrderByCheckout",
3025
2906
  value: (function () {
3026
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2907
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
3027
2908
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
3028
2909
  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) {
2910
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
2911
+ while (1) switch (_context26.prev = _context26.next) {
3031
2912
  case 0:
3032
2913
  // 过滤掉由在线店铺下单的 payment 支付数据
3033
2914
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -3061,7 +2942,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3061
2942
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
3062
2943
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
3063
2944
  });
3064
- _context29.prev = 4;
2945
+ _context26.prev = 4;
3065
2946
  // 构建订单数据,设置默认值并允许 params 覆盖
3066
2947
  orderData = _objectSpread({
3067
2948
  sales_channel: 'my_pisel',
@@ -3084,7 +2965,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3084
2965
  orderData.schedule_date = dayjs().format('YYYY-MM-DD HH:mm:ss');
3085
2966
  }
3086
2967
  console.log('[Order] 调用后端接口创建订单:', {
3087
- url: '/order/checkout',
2968
+ url: '/shop/order/checkout',
3088
2969
  orderType: orderData.type,
3089
2970
  platform: orderData.platform,
3090
2971
  isDeposit: orderData.is_deposit,
@@ -3099,7 +2980,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3099
2980
 
3100
2981
  // 记录接口调用详情
3101
2982
  this.logInfo('Calling backend checkout API', {
3102
- url: '/order/checkout',
2983
+ url: '/shop/order/checkout',
3103
2984
  orderType: orderData.type,
3104
2985
  platform: orderData.platform,
3105
2986
  isDeposit: orderData.is_deposit,
@@ -3123,12 +3004,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3123
3004
  hasOrderId: !!orderData.order_id,
3124
3005
  smallTicketDataFlag: orderData.small_ticket_data_flag
3125
3006
  });
3126
-
3127
- // 调用后端接口
3128
- _context29.next = 12;
3129
- return this.request.post('/order/checkout', orderData);
3007
+ _context26.next = 12;
3008
+ return this.request.post('/shop/order/checkout', orderData, {
3009
+ osServer: true,
3010
+ customToast: function customToast() {}
3011
+ });
3130
3012
  case 12:
3131
- response = _context29.sent;
3013
+ response = _context26.sent;
3132
3014
  this.logInfo('Order API called successfully', {
3133
3015
  response: response
3134
3016
  });
@@ -3136,22 +3018,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3136
3018
  success: !!response,
3137
3019
  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
3020
  });
3139
- return _context29.abrupt("return", response);
3021
+ return _context26.abrupt("return", response);
3140
3022
  case 18:
3141
- _context29.prev = 18;
3142
- _context29.t0 = _context29["catch"](4);
3143
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context29.t0);
3023
+ _context26.prev = 18;
3024
+ _context26.t0 = _context26["catch"](4);
3025
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context26.t0);
3144
3026
  this.logInfo('Order API called failed', {
3145
- error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
3027
+ error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0)
3146
3028
  });
3147
- throw _context29.t0;
3029
+ throw _context26.t0;
3148
3030
  case 23:
3149
3031
  case "end":
3150
- return _context29.stop();
3032
+ return _context26.stop();
3151
3033
  }
3152
- }, _callee27, this, [[4, 18]]);
3034
+ }, _callee24, this, [[4, 18]]);
3153
3035
  }));
3154
- function createOrderByCheckout(_x28) {
3036
+ function createOrderByCheckout(_x25) {
3155
3037
  return _createOrderByCheckout.apply(this, arguments);
3156
3038
  }
3157
3039
  return createOrderByCheckout;
@@ -3159,23 +3041,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3159
3041
  }, {
3160
3042
  key: "submitSalesOrder",
3161
3043
  value: function () {
3162
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
3044
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
3163
3045
  var url, query, fetchUrl;
3164
- return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3165
- while (1) switch (_context30.prev = _context30.next) {
3046
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
3047
+ while (1) switch (_context27.prev = _context27.next) {
3166
3048
  case 0:
3167
3049
  url = params.url, query = params.query;
3168
3050
  fetchUrl = url || '/order/sales/checkout';
3169
- return _context30.abrupt("return", this.request.post(fetchUrl, query, {
3051
+ return _context27.abrupt("return", this.request.post(fetchUrl, query, {
3052
+ osServer: true,
3170
3053
  customToast: function customToast() {}
3171
3054
  }));
3172
3055
  case 3:
3173
3056
  case "end":
3174
- return _context30.stop();
3057
+ return _context27.stop();
3175
3058
  }
3176
- }, _callee28, this);
3059
+ }, _callee25, this);
3177
3060
  }));
3178
- function submitSalesOrder(_x29) {
3061
+ function submitSalesOrder(_x26) {
3179
3062
  return _submitSalesOrder.apply(this, arguments);
3180
3063
  }
3181
3064
  return submitSalesOrder;
@@ -3189,72 +3072,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3189
3072
  }, {
3190
3073
  key: "sendCustomerPayLink",
3191
3074
  value: (function () {
3192
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
3075
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
3193
3076
  var _params$emails;
3194
3077
  var orderIds;
3195
- return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3196
- while (1) switch (_context31.prev = _context31.next) {
3078
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
3079
+ while (1) switch (_context28.prev = _context28.next) {
3197
3080
  case 0:
3198
3081
  orderIds = params.order_ids || params.orderIds || [];
3199
3082
  if (orderIds.length) {
3200
- _context31.next = 3;
3083
+ _context28.next = 3;
3201
3084
  break;
3202
3085
  }
3203
3086
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
3204
3087
  case 3:
3205
3088
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
3206
- _context31.next = 5;
3089
+ _context28.next = 5;
3207
3090
  break;
3208
3091
  }
3209
3092
  throw new Error('发送支付链接需要至少一个邮箱');
3210
3093
  case 5:
3211
- return _context31.abrupt("return", this.request.post('/order/batch-email', {
3094
+ return _context28.abrupt("return", this.request.post('/order/batch-email', {
3212
3095
  order_ids: orderIds,
3213
3096
  notify_action: params.notify_action || 'order_payment_reminder',
3214
3097
  emails: params.emails
3215
3098
  }));
3216
3099
  case 6:
3217
3100
  case "end":
3218
- return _context31.stop();
3101
+ return _context28.stop();
3219
3102
  }
3220
- }, _callee29, this);
3103
+ }, _callee26, this);
3221
3104
  }));
3222
- function sendCustomerPayLink(_x30) {
3105
+ function sendCustomerPayLink(_x27) {
3223
3106
  return _sendCustomerPayLink.apply(this, arguments);
3224
3107
  }
3225
3108
  return sendCustomerPayLink;
3226
- }() // TODO 获取详情的接口
3227
- )
3109
+ }())
3228
3110
  }, {
3229
- key: "getOrderInfoByRemote",
3111
+ key: "getSalesOrderByLookup",
3230
3112
  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) {
3113
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
3114
+ var lookup, res;
3115
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
3116
+ while (1) switch (_context29.prev = _context29.next) {
3235
3117
  case 0:
3236
- _context32.next = 2;
3237
- return this.request.get("/order/sales/".concat(order_id), {
3118
+ lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
3119
+ if (lookup) {
3120
+ _context29.next = 3;
3121
+ break;
3122
+ }
3123
+ throw new Error('加载销售详情需要 lookup');
3124
+ case 3:
3125
+ _context29.next = 5;
3126
+ return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
3238
3127
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
3239
- }, {
3128
+ }, params.forceRemote ? {
3129
+ forceRemote: true
3130
+ } : {}), {
3240
3131
  osServer: true
3241
3132
  });
3242
- case 2:
3243
- res = _context32.sent;
3133
+ case 5:
3134
+ res = _context29.sent;
3244
3135
  if (res.code === 200) {
3245
3136
  this.store.lastOrderInfo = res.data;
3246
3137
  }
3247
- return _context32.abrupt("return", res);
3248
- case 5:
3138
+ return _context29.abrupt("return", res);
3139
+ case 8:
3249
3140
  case "end":
3250
- return _context32.stop();
3141
+ return _context29.stop();
3251
3142
  }
3252
- }, _callee30, this);
3143
+ }, _callee27, this);
3253
3144
  }));
3254
- function getOrderInfoByRemote(_x31) {
3255
- return _getOrderInfoByRemote.apply(this, arguments);
3145
+ function getSalesOrderByLookup(_x28) {
3146
+ return _getSalesOrderByLookup.apply(this, arguments);
3256
3147
  }
3257
- return getOrderInfoByRemote;
3148
+ return getSalesOrderByLookup;
3258
3149
  }()
3259
3150
  /**
3260
3151
  * 把 sqlite / 后端返回的订单记录直接恢复为 tempOrder。
@@ -3265,10 +3156,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3265
3156
  }, {
3266
3157
  key: "hydrateTempOrderFromRecord",
3267
3158
  value: (function () {
3268
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(record, options) {
3159
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(record, options) {
3269
3160
  var raw, nextTempOrder;
3270
- return _regeneratorRuntime().wrap(function _callee31$(_context33) {
3271
- while (1) switch (_context33.prev = _context33.next) {
3161
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
3162
+ while (1) switch (_context30.prev = _context30.next) {
3272
3163
  case 0:
3273
3164
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
3274
3165
  nextTempOrder = this.normalizeTempOrderForRuntime(raw);
@@ -3276,23 +3167,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3276
3167
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
3277
3168
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
3278
3169
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
3279
- _context33.next = 8;
3170
+ _context30.next = 8;
3280
3171
  break;
3281
3172
  }
3282
- _context33.next = 8;
3173
+ _context30.next = 8;
3283
3174
  return this.recalculateSummary({
3284
3175
  createIfMissing: false
3285
3176
  });
3286
3177
  case 8:
3287
3178
  this.persistTempOrder();
3288
- return _context33.abrupt("return", nextTempOrder);
3179
+ return _context30.abrupt("return", nextTempOrder);
3289
3180
  case 10:
3290
3181
  case "end":
3291
- return _context33.stop();
3182
+ return _context30.stop();
3292
3183
  }
3293
- }, _callee31, this);
3184
+ }, _callee28, this);
3294
3185
  }));
3295
- function hydrateTempOrderFromRecord(_x32, _x33) {
3186
+ function hydrateTempOrderFromRecord(_x29, _x30) {
3296
3187
  return _hydrateTempOrderFromRecord.apply(this, arguments);
3297
3188
  }
3298
3189
  return hydrateTempOrderFromRecord;
@@ -3300,7 +3191,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3300
3191
  }, {
3301
3192
  key: "normalizeTempOrderForRuntime",
3302
3193
  value: function normalizeTempOrderForRuntime(raw, options) {
3303
- var _this11 = this;
3194
+ var _this12 = this;
3304
3195
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
3305
3196
  delete nextTempOrder.summary;
3306
3197
  delete nextTempOrder.lastOrderInfo;
@@ -3319,7 +3210,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3319
3210
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
3320
3211
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
3321
3212
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
3322
- return _this11.normalizeHydratedOrderProduct(p);
3213
+ return _this12.normalizeHydratedOrderProduct(p);
3323
3214
  }) : [];
3324
3215
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
3325
3216
  return _objectSpread(_objectSpread({}, b || {}), {}, {
@@ -3347,14 +3238,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3347
3238
  };
3348
3239
  var tempOrderExtend = nextTempOrder._extend;
3349
3240
  var productsByUid = tempOrderExtend.productsByUid || {};
3350
- var _iterator8 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3351
- _step8;
3241
+ var _iterator9 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
3242
+ _step9;
3352
3243
  try {
3353
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
3244
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3354
3245
  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];
3246
+ var _step9$value = _slicedToArray(_step9.value, 2),
3247
+ index = _step9$value[0],
3248
+ product = _step9$value[1];
3358
3249
  var uid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
3359
3250
  if (!uid) continue;
3360
3251
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
@@ -3375,9 +3266,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3375
3266
  });
3376
3267
  }
3377
3268
  } catch (err) {
3378
- _iterator8.e(err);
3269
+ _iterator9.e(err);
3379
3270
  } finally {
3380
- _iterator8.f();
3271
+ _iterator9.f();
3381
3272
  }
3382
3273
  tempOrderExtend.productsByUid = productsByUid;
3383
3274
  if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
@@ -3408,18 +3299,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3408
3299
  var segments = [];
3409
3300
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
3410
3301
  if (Array.isArray(sku.variant)) {
3411
- var _iterator9 = _createForOfIteratorHelper(sku.variant),
3412
- _step9;
3302
+ var _iterator10 = _createForOfIteratorHelper(sku.variant),
3303
+ _step10;
3413
3304
  try {
3414
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3415
- var variant = _step9.value;
3305
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3306
+ var variant = _step10.value;
3416
3307
  var segment = this.formatHydratedNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
3417
3308
  if (segment) segments.push(segment);
3418
3309
  }
3419
3310
  } catch (err) {
3420
- _iterator9.e(err);
3311
+ _iterator10.e(err);
3421
3312
  } finally {
3422
- _iterator9.f();
3313
+ _iterator10.f();
3423
3314
  }
3424
3315
  }
3425
3316
  return segments.join(', ');
@@ -3447,7 +3338,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3447
3338
  }, {
3448
3339
  key: "normalizeHydratedOrderProduct",
3449
3340
  value: function normalizeHydratedOrderProduct(product) {
3450
- var _this12 = this;
3341
+ var _this13 = this;
3451
3342
  var row = _objectSpread({}, product || {});
3452
3343
  if (row.num === undefined && row.product_quantity !== undefined) {
3453
3344
  row.num = row.product_quantity;
@@ -3455,7 +3346,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3455
3346
  var productSku = ensureProductSku(row);
3456
3347
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
3457
3348
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
3458
- return _this12.normalizeHydratedProductOptionItem(optionItem || {});
3349
+ return _this13.normalizeHydratedProductOptionItem(optionItem || {});
3459
3350
  }))
3460
3351
  });
3461
3352
  delete row["product_".concat('option', "_item")];
@@ -3475,7 +3366,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3475
3366
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
3476
3367
  });
3477
3368
  if (result.metadata) delete result.metadata.price_schema_version;
3478
- return result;
3369
+ return this.sanitizeOrderProductForTempOrder(result);
3479
3370
  }
3480
3371
  }, {
3481
3372
  key: "getLastOrderInfo",
@@ -3486,25 +3377,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3486
3377
  }, {
3487
3378
  key: "getOrderInfo",
3488
3379
  value: function () {
3489
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order_id) {
3380
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order_id) {
3490
3381
  var res;
3491
- return _regeneratorRuntime().wrap(function _callee32$(_context34) {
3492
- while (1) switch (_context34.prev = _context34.next) {
3382
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
3383
+ while (1) switch (_context31.prev = _context31.next) {
3493
3384
  case 0:
3494
- _context34.next = 2;
3385
+ _context31.next = 2;
3495
3386
  return this.request.get("/order/sales/".concat(order_id), {
3496
3387
  with: ['products', 'bookings']
3497
3388
  });
3498
3389
  case 2:
3499
- res = _context34.sent;
3500
- return _context34.abrupt("return", res);
3390
+ res = _context31.sent;
3391
+ return _context31.abrupt("return", res);
3501
3392
  case 4:
3502
3393
  case "end":
3503
- return _context34.stop();
3394
+ return _context31.stop();
3504
3395
  }
3505
- }, _callee32, this);
3396
+ }, _callee29, this);
3506
3397
  }));
3507
- function getOrderInfo(_x34) {
3398
+ function getOrderInfo(_x31) {
3508
3399
  return _getOrderInfo.apply(this, arguments);
3509
3400
  }
3510
3401
  return getOrderInfo;
@@ -3526,67 +3417,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3526
3417
  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
3418
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
3528
3419
  };
3529
- var _iterator10 = _createForOfIteratorHelper(productList),
3530
- _step10;
3420
+ var _iterator11 = _createForOfIteratorHelper(productList),
3421
+ _step11;
3531
3422
  try {
3532
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
3533
- var product = _step10.value;
3423
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3424
+ var product = _step11.value;
3534
3425
  var qty = product.num || 1;
3535
- var _iterator12 = _createForOfIteratorHelper(product.discount_list || []),
3536
- _step12;
3426
+ var _iterator13 = _createForOfIteratorHelper(product.discount_list || []),
3427
+ _step13;
3537
3428
  try {
3538
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3539
- var pd = _step12.value;
3429
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3430
+ var pd = _step13.value;
3540
3431
  addDiscountAmount(pd, qty);
3541
3432
  }
3542
3433
  } catch (err) {
3543
- _iterator12.e(err);
3434
+ _iterator13.e(err);
3544
3435
  } finally {
3545
- _iterator12.f();
3436
+ _iterator13.f();
3546
3437
  }
3547
- var _iterator13 = _createForOfIteratorHelper(product.product_bundle || []),
3548
- _step13;
3438
+ var _iterator14 = _createForOfIteratorHelper(product.product_bundle || []),
3439
+ _step14;
3549
3440
  try {
3550
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
3441
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3551
3442
  var _ref28, _bundle$num;
3552
- var bundle = _step13.value;
3443
+ var bundle = _step14.value;
3553
3444
  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;
3445
+ var _iterator15 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
3446
+ _step15;
3556
3447
  try {
3557
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
3558
- var _pd = _step14.value;
3448
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
3449
+ var _pd = _step15.value;
3559
3450
  addDiscountAmount(_pd, bundleQty);
3560
3451
  }
3561
3452
  } catch (err) {
3562
- _iterator14.e(err);
3453
+ _iterator15.e(err);
3563
3454
  } finally {
3564
- _iterator14.f();
3455
+ _iterator15.f();
3565
3456
  }
3566
3457
  }
3567
3458
  } catch (err) {
3568
- _iterator13.e(err);
3459
+ _iterator14.e(err);
3569
3460
  } finally {
3570
- _iterator13.f();
3461
+ _iterator14.f();
3571
3462
  }
3572
3463
  }
3573
3464
  } catch (err) {
3574
- _iterator10.e(err);
3465
+ _iterator11.e(err);
3575
3466
  } finally {
3576
- _iterator10.f();
3467
+ _iterator11.f();
3577
3468
  }
3578
- var _iterator11 = _createForOfIteratorHelper(discountList),
3579
- _step11;
3469
+ var _iterator12 = _createForOfIteratorHelper(discountList),
3470
+ _step12;
3580
3471
  try {
3581
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
3582
- var d = _step11.value;
3472
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
3473
+ var d = _step12.value;
3583
3474
  var key = d.id;
3584
3475
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
3585
3476
  }
3586
3477
  } catch (err) {
3587
- _iterator11.e(err);
3478
+ _iterator12.e(err);
3588
3479
  } finally {
3589
- _iterator11.f();
3480
+ _iterator12.f();
3590
3481
  }
3591
3482
  }
3592
3483
  }]);