@pisell/pisellos 0.0.236 → 0.0.238

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.
@@ -1,11 +1,11 @@
1
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
5
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
11
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
@@ -313,7 +313,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
313
313
  }, {
314
314
  key: "getProductListByOrder",
315
315
  value: function getProductListByOrder() {
316
- var _this$store$currentOr;
316
+ var _this$store$currentOr, _this$store$currentOr2;
317
317
  if (!this.store.currentOrder) {
318
318
  return [];
319
319
  }
@@ -322,26 +322,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
322
322
  return pre + (item.amount || 0);
323
323
  }, 0);
324
324
  };
325
- var productList = (_this$store$currentOr = this.store.currentOrder.order_info) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.original_order_data.bookings.map(function (item) {
325
+ var productList = ((_this$store$currentOr = this.store.currentOrder.order_info) === null || _this$store$currentOr === void 0 || (_this$store$currentOr = _this$store$currentOr.original_order_data.bookings) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.map(function (item) {
326
326
  return {
327
327
  product_id: item.product.product_id,
328
328
  product_variant_id: item.product.product_variant_id,
329
329
  quantity: item.product.num,
330
330
  selling_price: item.product.price - (item.product.discount_amount || 0) - getDiscountListAmount(item.product.discount_list)
331
331
  };
332
- });
333
- return productList;
332
+ })) || [];
333
+ var relationProducts = ((_this$store$currentOr2 = this.store.currentOrder.order_info) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.original_order_data) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.relation_products) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.map(function (item) {
334
+ return {
335
+ product_id: item.product_id,
336
+ product_variant_id: item.product_variant_id,
337
+ quantity: item.num,
338
+ selling_price: item.source_product_price
339
+ };
340
+ })) || [];
341
+ return [].concat(_toConsumableArray(productList), _toConsumableArray(relationProducts));
334
342
  }
335
343
  }, {
336
344
  key: "initWalletData",
337
345
  value: function () {
338
346
  var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
339
- var _this$store$currentOr2, _this$store$currentCu;
347
+ var _this$store$currentOr3, _this$store$currentCu;
340
348
  var amountInfo, walletBusinessData;
341
349
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
342
350
  while (1) switch (_context8.prev = _context8.next) {
343
351
  case 0:
344
- amountInfo = (_this$store$currentOr2 = this.store.currentOrder) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.order_info) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.amount_breakdown;
352
+ amountInfo = (_this$store$currentOr3 = this.store.currentOrder) === null || _this$store$currentOr3 === void 0 || (_this$store$currentOr3 = _this$store$currentOr3.order_info) === null || _this$store$currentOr3 === void 0 ? void 0 : _this$store$currentOr3.amount_breakdown;
345
353
  if (amountInfo) {
346
354
  _context8.next = 3;
347
355
  break;
@@ -978,12 +986,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
978
986
  key: "getCheckoutSummaryAsync",
979
987
  value: (function () {
980
988
  var _getCheckoutSummaryAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
981
- var _this$store$currentOr3, _this$store$currentOr4;
989
+ var _this$store$currentOr4, _this$store$currentOr5;
982
990
  var totalAmount, paidAmount, remainingAmount;
983
991
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
984
992
  while (1) switch (_context15.prev = _context15.next) {
985
993
  case 0:
986
- totalAmount = ((_this$store$currentOr3 = this.store.currentOrder) === null || _this$store$currentOr3 === void 0 ? void 0 : _this$store$currentOr3.total_amount) || '0.00';
994
+ totalAmount = ((_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.total_amount) || '0.00';
987
995
  _context15.next = 3;
988
996
  return this.calculatePaidAmountAsync();
989
997
  case 3:
@@ -997,7 +1005,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
997
1005
  totalAmount: totalAmount,
998
1006
  paidAmount: paidAmount,
999
1007
  remainingAmount: remainingAmount,
1000
- paymentStatus: ((_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.payment_status) || PaymentStatus.Processing,
1008
+ paymentStatus: ((_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.payment_status) || PaymentStatus.Processing,
1001
1009
  availablePaymentMethods: this.store.paymentMethods
1002
1010
  });
1003
1011
  case 8:
@@ -1084,8 +1092,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1084
1092
  }, {
1085
1093
  key: "getOrderOriginalData",
1086
1094
  value: function getOrderOriginalData() {
1087
- var _this$store$currentOr5;
1088
- return (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.order_info;
1095
+ var _this$store$currentOr6;
1096
+ return (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_info;
1089
1097
  }
1090
1098
 
1091
1099
  /**
@@ -1633,7 +1641,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1633
1641
  key: "addPaymentItemAsync",
1634
1642
  value: (function () {
1635
1643
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(paymentItem) {
1636
- var currentOrderId, isCurrentOrderReal;
1644
+ var _paymentItem$type, _paymentItem$code, isEftposPayment;
1637
1645
  return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1638
1646
  while (1) switch (_context25.prev = _context25.next) {
1639
1647
  case 0:
@@ -1661,89 +1669,63 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1661
1669
  case 6:
1662
1670
  console.log('[Checkout] 支付项添加成功');
1663
1671
 
1664
- // 重新从Payment模块获取最新的订单数据,确保支付项同步
1665
- currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1666
- isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1667
- console.log('[Checkout] 准备同步订单数据:', {
1668
- 当前订单ID: currentOrderId,
1669
- 是否为真实ID: isCurrentOrderReal
1672
+ // 检查是否是 EFTPOS 支付,如果是则立即同步订单
1673
+ isEftposPayment = ((_paymentItem$type = paymentItem.type) === null || _paymentItem$type === void 0 ? void 0 : _paymentItem$type.toLowerCase()) === 'eftpos' || ((_paymentItem$code = paymentItem.code) === null || _paymentItem$code === void 0 ? void 0 : _paymentItem$code.toUpperCase().includes('EFTPOS'));
1674
+ console.log('[Checkout] EFTPOS 支付检查:', {
1675
+ paymentCode: paymentItem.code,
1676
+ paymentType: paymentItem.type,
1677
+ isEftposPayment: isEftposPayment,
1678
+ currentOrderSynced: this.store.isOrderSynced
1670
1679
  });
1671
-
1672
- // const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1673
- // if (updatedOrder) {
1674
- // // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1675
- // if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1676
- // console.warn('[Checkout] 检测到订单ID回退,保护真实订单ID:', {
1677
- // 当前真实ID: currentOrderId,
1678
- // 获取到的虚拟ID: updatedOrder.order_id
1679
- // });
1680
- // updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1681
- // }
1682
-
1683
- // this.store.currentOrder = updatedOrder;
1684
- // console.log('[Checkout] 订单数据已同步:', {
1685
- // 支付项数量: updatedOrder.payment.length,
1686
- // 最终订单ID: updatedOrder.order_id,
1687
- // 是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
1688
- // });
1689
- // }
1690
-
1691
- // // 检查是否需要同步订单到后端
1692
- // const needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
1693
-
1694
- // console.log('[Checkout] 支付项同步检查:', {
1695
- // paymentCode: paymentItem.code,
1696
- // paymentType: paymentItem.type,
1697
- // paymentAmount: paymentItem.amount,
1698
- // expectedCashCode: PaymentMethodType.Cash,
1699
- // needsOrderSync,
1700
- // isOrderSynced: this.store.isOrderSynced
1701
- // });
1702
-
1703
- // if (needsOrderSync) {
1704
- // console.log('[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...', {
1705
- // 同步前订单ID: this.store.currentOrder.order_id,
1706
- // 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1707
- // 订单同步状态: this.store.isOrderSynced,
1708
- // 订单UUID: this.store.currentOrder.uuid
1709
- // });
1710
-
1711
- // await this.syncOrderToBackend();
1712
-
1713
- // console.log('[Checkout] addPaymentItemAsync 中的同步完成:', {
1714
- // 同步后订单ID: this.store.currentOrder.order_id,
1715
- // 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1716
- // 订单同步状态: this.store.isOrderSynced
1717
- // });
1718
- // }
1719
-
1720
- // 支付项添加后,更新 stateAmount 为剩余未支付金额
1721
- _context25.next = 12;
1722
- return this.updateStateAmountToRemaining();
1723
- case 12:
1680
+ if (!isEftposPayment) {
1681
+ _context25.next = 22;
1682
+ break;
1683
+ }
1684
+ console.log('[Checkout] 检测到 EFTPOS 支付,立即同步订单到后端...');
1685
+ _context25.prev = 11;
1724
1686
  _context25.next = 14;
1687
+ return this.syncOrderToBackendWithReturn(true);
1688
+ case 14:
1689
+ console.log('[Checkout] EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1690
+ 订单ID: this.store.currentOrder.order_id,
1691
+ 是否已同步: this.store.isOrderSynced
1692
+ });
1693
+ _context25.next = 22;
1694
+ break;
1695
+ case 17:
1696
+ _context25.prev = 17;
1697
+ _context25.t0 = _context25["catch"](11);
1698
+ console.error('[Checkout] EFTPOS 支付后订单同步失败:', _context25.t0);
1699
+ // 不抛出错误,避免影响支付流程,但记录错误
1700
+ _context25.next = 22;
1701
+ return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0))), CheckoutErrorType.OrderCreationFailed);
1702
+ case 22:
1703
+ _context25.next = 24;
1704
+ return this.updateStateAmountToRemaining();
1705
+ case 24:
1706
+ _context25.next = 26;
1725
1707
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1726
1708
  orderUuid: this.store.currentOrder.uuid,
1727
1709
  paymentMethodCode: paymentItem.code,
1728
1710
  amount: String(paymentItem.amount),
1729
1711
  timestamp: Date.now()
1730
1712
  });
1731
- case 14:
1732
- _context25.next = 22;
1713
+ case 26:
1714
+ _context25.next = 34;
1733
1715
  break;
1734
- case 16:
1735
- _context25.prev = 16;
1736
- _context25.t0 = _context25["catch"](0);
1737
- console.error('[Checkout] 添加支付项失败:', _context25.t0);
1738
- _context25.next = 21;
1739
- return this.handleError(_context25.t0, CheckoutErrorType.PaymentFailed);
1740
- case 21:
1741
- throw _context25.t0;
1742
- case 22:
1716
+ case 28:
1717
+ _context25.prev = 28;
1718
+ _context25.t1 = _context25["catch"](0);
1719
+ console.error('[Checkout] 添加支付项失败:', _context25.t1);
1720
+ _context25.next = 33;
1721
+ return this.handleError(_context25.t1, CheckoutErrorType.PaymentFailed);
1722
+ case 33:
1723
+ throw _context25.t1;
1724
+ case 34:
1743
1725
  case "end":
1744
1726
  return _context25.stop();
1745
1727
  }
1746
- }, _callee25, this, [[0, 16]]);
1728
+ }, _callee25, this, [[0, 28], [11, 17]]);
1747
1729
  }));
1748
1730
  function addPaymentItemAsync(_x16) {
1749
1731
  return _addPaymentItemAsync.apply(this, arguments);
@@ -2258,7 +2240,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2258
2240
  key: "manualSyncOrderAsync",
2259
2241
  value: (function () {
2260
2242
  var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2261
- var orderUuid, oldOrderId, realOrderId, finalOrderId, finalIsVirtual, _this$store$currentOr6, errorMessage;
2243
+ var orderUuid, oldOrderId, realOrderId, finalOrderId, finalIsVirtual, _this$store$currentOr7, errorMessage;
2262
2244
  return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2263
2245
  while (1) switch (_context31.prev = _context31.next) {
2264
2246
  case 0:
@@ -2334,7 +2316,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2334
2316
  return _context31.abrupt("return", {
2335
2317
  success: false,
2336
2318
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2337
- orderUuid: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.uuid
2319
+ orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid
2338
2320
  });
2339
2321
  case 32:
2340
2322
  case "end":
@@ -2411,15 +2393,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2411
2393
  key: "cancelCurrentOrderAsync",
2412
2394
  value: (function () {
2413
2395
  var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(cancelReason) {
2414
- var _this$store$currentOr7, _this$store$currentOr8, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2396
+ var _this$store$currentOr8, _this$store$currentOr9, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2415
2397
  return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2416
2398
  while (1) switch (_context32.prev = _context32.next) {
2417
2399
  case 0:
2418
2400
  _context32.prev = 0;
2419
2401
  console.log('[Checkout] 开始取消当前本地订单:', {
2420
2402
  hasCurrentOrder: !!this.store.currentOrder,
2421
- orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
2422
- orderId: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_id,
2403
+ orderUuid: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.uuid,
2404
+ orderId: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_id,
2423
2405
  isOrderSynced: this.store.isOrderSynced,
2424
2406
  cancelReason: cancelReason
2425
2407
  });
@@ -2532,7 +2514,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2532
2514
  key: "saveForLaterPaymentAsync",
2533
2515
  value: (function () {
2534
2516
  var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2535
- var orderUuid, currentOrderId, allPaymentItems, filteredPaymentItems, voucherItems, realOrderId, finalOrderId, _this$store$currentOr9, errorMessage;
2517
+ var orderUuid, currentOrderId, allPaymentItems, filteredPaymentItems, voucherItems, realOrderId, finalOrderId, _this$store$currentOr10, errorMessage;
2536
2518
  return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2537
2519
  while (1) switch (_context33.prev = _context33.next) {
2538
2520
  case 0:
@@ -2561,10 +2543,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2561
2543
  allPaymentItems = _context33.sent;
2562
2544
  // 过滤掉带有 voucher_id 的支付项(代金券类支付项)
2563
2545
  filteredPaymentItems = allPaymentItems.filter(function (payment) {
2564
- return !payment.voucher_id || payment.voucher_id.trim() === '';
2546
+ return !payment.voucher_id;
2565
2547
  }); // 记录过滤结果
2566
2548
  voucherItems = allPaymentItems.filter(function (payment) {
2567
- return payment.voucher_id && payment.voucher_id.trim() !== '';
2549
+ return payment.voucher_id;
2568
2550
  });
2569
2551
  console.log('[Checkout] 支付项过滤结果:', {
2570
2552
  总支付项: allPaymentItems.length,
@@ -2622,7 +2604,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2622
2604
  return _context33.abrupt("return", {
2623
2605
  success: false,
2624
2606
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2625
- orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid
2607
+ orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid
2626
2608
  });
2627
2609
  case 26:
2628
2610
  case "end":
@@ -2673,14 +2655,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2673
2655
  key: "updateShopDiscountAsync",
2674
2656
  value: (function () {
2675
2657
  var _updateShopDiscountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(discountAmount) {
2676
- var _this$store$currentOr10, _this$store$currentOr11, oldDiscount, shopDiscountItem, updatedAmountInfo;
2658
+ var _this$store$currentOr11, _this$store$currentOr12, oldDiscount, shopDiscountItem, updatedAmountInfo;
2677
2659
  return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2678
2660
  while (1) switch (_context34.prev = _context34.next) {
2679
2661
  case 0:
2680
2662
  _context34.prev = 0;
2681
2663
  oldDiscount = this.getShopDiscount();
2682
2664
  console.log('[Checkout] 更新商店折扣:', {
2683
- orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
2665
+ orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid,
2684
2666
  oldDiscount: oldDiscount,
2685
2667
  newDiscount: discountAmount
2686
2668
  });
@@ -2730,7 +2712,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2730
2712
  case 8:
2731
2713
  _context34.next = 10;
2732
2714
  return this.core.effects.emit(CheckoutHooks.OnShopDiscountChanged, {
2733
- orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid,
2715
+ orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
2734
2716
  oldDiscount: oldDiscount,
2735
2717
  newDiscount: discountAmount,
2736
2718
  timestamp: Date.now()
@@ -2771,7 +2753,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2771
2753
  key: "updateOrderNoteAsync",
2772
2754
  value: (function () {
2773
2755
  var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(note) {
2774
- var _this$store$currentOr12, _this$store$currentOr13, oldNote, orderInPayment;
2756
+ var _this$store$currentOr13, _this$store$currentOr14, oldNote, orderInPayment;
2775
2757
  return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2776
2758
  while (1) switch (_context35.prev = _context35.next) {
2777
2759
  case 0:
@@ -2783,7 +2765,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2783
2765
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2784
2766
  case 3:
2785
2767
  console.log('[Checkout] 更新订单备注:', {
2786
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
2768
+ orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
2787
2769
  oldNote: this.store.localOrderData.shop_note,
2788
2770
  newNote: note
2789
2771
  });
@@ -2816,7 +2798,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2816
2798
  case 17:
2817
2799
  _context35.next = 19;
2818
2800
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2819
- orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
2801
+ orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid,
2820
2802
  oldNote: oldNote,
2821
2803
  newNote: note,
2822
2804
  timestamp: Date.now()
@@ -2956,7 +2938,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2956
2938
  key: "handlePaymentSuccess",
2957
2939
  value: (function () {
2958
2940
  var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(data) {
2959
- var _this$store$currentOr14;
2941
+ var _this$store$currentOr15;
2960
2942
  return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2961
2943
  while (1) switch (_context39.prev = _context39.next) {
2962
2944
  case 0:
@@ -2970,7 +2952,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2970
2952
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2971
2953
  orderUuid: data.orderUuid,
2972
2954
  paymentMethodCode: '',
2973
- amount: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.total_amount) || '0',
2955
+ amount: ((_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.total_amount) || '0',
2974
2956
  timestamp: data.timestamp
2975
2957
  });
2976
2958
  case 6:
@@ -2995,7 +2977,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2995
2977
  key: "handlePaymentError",
2996
2978
  value: (function () {
2997
2979
  var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(data) {
2998
- var _this$store$currentOr15;
2980
+ var _this$store$currentOr16;
2999
2981
  var error;
3000
2982
  return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3001
2983
  while (1) switch (_context40.prev = _context40.next) {
@@ -3008,7 +2990,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3008
2990
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
3009
2991
  orderUuid: data.orderUuid,
3010
2992
  paymentMethodCode: '',
3011
- amount: ((_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.total_amount) || '0',
2993
+ amount: ((_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.total_amount) || '0',
3012
2994
  timestamp: data.timestamp
3013
2995
  });
3014
2996
  case 5:
@@ -3354,7 +3336,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3354
3336
  key: "updateStateAmountToRemaining",
3355
3337
  value: (function () {
3356
3338
  var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3357
- var _this$store$currentOr16, remainingAmount, currentStateAmount;
3339
+ var _this$store$currentOr17, remainingAmount, currentStateAmount;
3358
3340
  return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3359
3341
  while (1) switch (_context46.prev = _context46.next) {
3360
3342
  case 0:
@@ -3368,7 +3350,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3368
3350
  calculatedRemainingAmount: remainingAmount,
3369
3351
  currentStateAmount: currentStateAmount,
3370
3352
  needsUpdate: remainingAmount !== currentStateAmount,
3371
- orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid
3353
+ orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid
3372
3354
  });
3373
3355
 
3374
3356
  // 只有当剩余金额与当前 stateAmount 不同时才更新
@@ -3428,7 +3410,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3428
3410
  key: "checkOrderPaymentCompletion",
3429
3411
  value: (function () {
3430
3412
  var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
3431
- var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, allPaymentsHaveVoucherId;
3413
+ var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
3432
3414
  return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3433
3415
  while (1) switch (_context47.prev = _context47.next) {
3434
3416
  case 0:
@@ -3445,7 +3427,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3445
3427
  remainingAmount = _context47.sent;
3446
3428
  remainingValue = parseFloat(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3447
3429
  if (!(remainingValue <= 0)) {
3448
- _context47.next = 27;
3430
+ _context47.next = 29;
3449
3431
  break;
3450
3432
  }
3451
3433
  totalAmount = this.store.currentOrder.total_amount;
@@ -3462,18 +3444,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3462
3444
  isOrderSynced: this.store.isOrderSynced
3463
3445
  });
3464
3446
 
3465
- // 从 Payment 模块获取最新支付项,检查是否所有支付项都带有 voucher_id
3447
+ // 从 Payment 模块获取最新支付项,检查自动同步条件
3466
3448
  _context47.next = 15;
3467
3449
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3468
3450
  );
3469
3451
  case 15:
3470
3452
  currentPayments = _context47.sent;
3471
- allPaymentsHaveVoucherId = currentPayments.length > 0 && currentPayments.every(function (item) {
3453
+ // 检查自动同步条件:
3454
+ // 1. 待付金额为 0 ✓ (已在上面检查)
3455
+ // 2. 需要有支付项
3456
+ // 3. 支付项不能全是带 voucher_id 的数据
3457
+ hasPaymentItems = currentPayments.length > 0;
3458
+ allPaymentsHaveVoucherId = hasPaymentItems && currentPayments.every(function (item) {
3472
3459
  return item.status !== 'voided' && item.voucher_id;
3473
- });
3474
- console.log('[Checkout] 支付项voucher_id检查:', {
3460
+ }); // 判断是否需要自动同步订单
3461
+ // 条件:
3462
+ // 1. 有支付项
3463
+ // 2. 不全是代金券支付
3464
+ // 3. 订单未同步 OR (订单已同步但支付刚完成,需要同步最终支付状态)
3465
+ shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
3466
+ console.log('[Checkout] 自动同步订单条件检查:', {
3475
3467
  paymentCount: currentPayments.length,
3468
+ hasPaymentItems: hasPaymentItems,
3476
3469
  allHaveVoucherId: allPaymentsHaveVoucherId,
3470
+ isOrderSynced: this.store.isOrderSynced,
3471
+ shouldAutoSync: shouldAutoSync,
3472
+ reason: shouldAutoSync ? '支付完成,需要同步最终支付状态' : '跳过同步',
3477
3473
  paymentItems: currentPayments.map(function (p) {
3478
3474
  return {
3479
3475
  uuid: p.uuid,
@@ -3484,29 +3480,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3484
3480
  };
3485
3481
  })
3486
3482
  });
3487
-
3488
- // // 如果支付完成但订单未同步,需要判断是否同步
3489
- // if (!this.store.isOrderSynced) {
3490
- // if (allPaymentsHaveVoucherId) {
3491
- // console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3492
- // } else {
3493
- // console.log('[Checkout] 支付完成但订单未同步,开始同步订单到后端...');
3494
- // await this.syncOrderToBackend();
3495
- // }
3496
- // }
3497
- if (!allPaymentsHaveVoucherId) {
3498
- _context47.next = 22;
3483
+ if (!shouldAutoSync) {
3484
+ _context47.next = 26;
3499
3485
  break;
3500
3486
  }
3501
- console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3502
- _context47.next = 25;
3503
- break;
3504
- case 22:
3505
- console.log('[Checkout] 支付完成但订单未同步,开始同步订单到后端...');
3506
- _context47.next = 25;
3487
+ console.log('[Checkout] 满足自动同步条件,开始同步订单到后端...');
3488
+ _context47.next = 24;
3507
3489
  return this.syncOrderToBackend();
3508
- case 25:
3490
+ case 24:
3509
3491
  _context47.next = 27;
3492
+ break;
3493
+ case 26:
3494
+ if (!hasPaymentItems) {
3495
+ console.log('[Checkout] 没有支付项,跳过订单同步');
3496
+ } else if (allPaymentsHaveVoucherId) {
3497
+ console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3498
+ }
3499
+ case 27:
3500
+ _context47.next = 29;
3510
3501
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3511
3502
  orderUuid: this.store.currentOrder.uuid,
3512
3503
  orderId: this.store.currentOrder.order_id,
@@ -3515,18 +3506,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3515
3506
  remainingAmount: remainingAmount,
3516
3507
  timestamp: Date.now()
3517
3508
  });
3518
- case 27:
3519
- _context47.next = 32;
3520
- break;
3521
3509
  case 29:
3522
- _context47.prev = 29;
3510
+ _context47.next = 34;
3511
+ break;
3512
+ case 31:
3513
+ _context47.prev = 31;
3523
3514
  _context47.t0 = _context47["catch"](0);
3524
3515
  console.error('[Checkout] 检查订单支付完成状态失败:', _context47.t0);
3525
- case 32:
3516
+ case 34:
3526
3517
  case "end":
3527
3518
  return _context47.stop();
3528
3519
  }
3529
- }, _callee47, this, [[0, 29]]);
3520
+ }, _callee47, this, [[0, 31]]);
3530
3521
  }));
3531
3522
  function checkOrderPaymentCompletion() {
3532
3523
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -3599,7 +3590,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3599
3590
  key: "syncOrderToBackendWithReturn",
3600
3591
  value: (function () {
3601
3592
  var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48() {
3602
- var _this$store$currentCu2, _this$store$currentOr17, _this$store$currentOr18;
3593
+ var _this$store$currentCu2, _this$store$currentOr18, _this$store$currentOr19, _checkoutResponse3, _checkoutResponse4, _checkoutResponse5, _checkoutResponse6;
3603
3594
  var isManual,
3604
3595
  customPaymentItems,
3605
3596
  syncType,
@@ -3610,10 +3601,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3610
3601
  operation,
3611
3602
  paymentItems,
3612
3603
  orderParams,
3604
+ startTime,
3613
3605
  checkoutResponse,
3606
+ submitSuccess,
3607
+ submitError,
3608
+ _checkoutResponse,
3609
+ _checkoutResponse2,
3614
3610
  realOrderId,
3615
- _data3,
3611
+ _checkoutResponse7,
3616
3612
  extractedOrderId,
3613
+ _checkoutResponse8,
3617
3614
  updatedOrder,
3618
3615
  beforeManualUpdate,
3619
3616
  finalOrderId,
@@ -3717,8 +3714,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3717
3714
  currency_code: this.otherParams.currency_code,
3718
3715
  currency_symbol: this.otherParams.currency_symbol,
3719
3716
  currency_format: this.otherParams.currency_format,
3720
- is_deposit: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.is_deposit) || 0,
3721
- deposit_amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.deposit_amount) || '0.00',
3717
+ is_deposit: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.is_deposit) || 0,
3718
+ deposit_amount: ((_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.deposit_amount) || '0.00',
3722
3719
  // surcharge_fee: this.otherParams.surcharge_fee,
3723
3720
  // surcharges: ,
3724
3721
  note: this.store.localOrderData.shop_note
@@ -3747,31 +3744,70 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3747
3744
  console.log('[Checkout] 创建新订单操作');
3748
3745
  }
3749
3746
 
3750
- // 调用 Order 模块的专用 createOrderByCheckout 方法
3751
- _context48.next = 24;
3747
+ // 发送下单接口请求开始事件
3748
+ startTime = Date.now();
3749
+ _context48.next = 25;
3750
+ return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3751
+ orderUuid: this.store.currentOrder.uuid,
3752
+ operation: isUpdateOperation ? 'update' : 'create',
3753
+ isManual: isManual,
3754
+ paymentItemCount: paymentItems.length,
3755
+ timestamp: startTime
3756
+ });
3757
+ case 25:
3758
+ submitSuccess = false;
3759
+ _context48.prev = 26;
3760
+ _context48.next = 29;
3752
3761
  return this.order.createOrderByCheckout(orderParams);
3753
- case 24:
3762
+ case 29:
3754
3763
  checkoutResponse = _context48.sent;
3764
+ submitSuccess = true;
3765
+ console.log('[Checkout] 下单接口调用成功');
3766
+ _context48.next = 40;
3767
+ break;
3768
+ case 34:
3769
+ _context48.prev = 34;
3770
+ _context48.t1 = _context48["catch"](26);
3771
+ submitSuccess = false;
3772
+ submitError = _context48.t1 instanceof Error ? _context48.t1.message : String(_context48.t1);
3773
+ console.error('[Checkout] 下单接口调用失败:', submitError);
3774
+ throw _context48.t1;
3775
+ case 40:
3776
+ _context48.prev = 40;
3777
+ _context48.next = 43;
3778
+ return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3779
+ success: submitSuccess,
3780
+ orderUuid: this.store.currentOrder.uuid,
3781
+ operation: isUpdateOperation ? 'update' : 'create',
3782
+ isManual: isManual,
3783
+ orderId: submitSuccess ? ((_checkoutResponse = checkoutResponse) === null || _checkoutResponse === void 0 || (_checkoutResponse = _checkoutResponse.data) === null || _checkoutResponse === void 0 ? void 0 : _checkoutResponse.order_id) || ((_checkoutResponse2 = checkoutResponse) === null || _checkoutResponse2 === void 0 ? void 0 : _checkoutResponse2.order_id) : undefined,
3784
+ error: submitError,
3785
+ duration: Date.now() - startTime,
3786
+ timestamp: Date.now()
3787
+ });
3788
+ case 43:
3789
+ return _context48.finish(40);
3790
+ case 44:
3755
3791
  console.log('[Checkout] 后端返回的响应数据:', {
3756
- status: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.status,
3757
- code: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.code,
3758
- message: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.message,
3759
- data: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.data
3792
+ status: (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status,
3793
+ code: (_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code,
3794
+ message: (_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message,
3795
+ data: (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.data
3760
3796
  });
3761
3797
  if (!isUpdateOperation) {
3762
- _context48.next = 31;
3798
+ _context48.next = 50;
3763
3799
  break;
3764
3800
  }
3765
3801
  // 更新操作:使用现有的订单ID
3766
3802
  realOrderId = currentOrderId;
3767
3803
  console.log("[Checkout] \u8BA2\u5355\u66F4\u65B0\u6210\u529F\uFF0C\u8BA2\u5355ID: ".concat(realOrderId));
3768
- _context48.next = 52;
3804
+ _context48.next = 71;
3769
3805
  break;
3770
- case 31:
3806
+ case 50:
3771
3807
  // 创建操作:从响应中提取新的订单ID
3772
- extractedOrderId = checkoutResponse === null || checkoutResponse === void 0 || (_data3 = checkoutResponse.data) === null || _data3 === void 0 ? void 0 : _data3.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3808
+ extractedOrderId = (_checkoutResponse7 = checkoutResponse) === null || _checkoutResponse7 === void 0 || (_checkoutResponse7 = _checkoutResponse7.data) === null || _checkoutResponse7 === void 0 ? void 0 : _checkoutResponse7.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3773
3809
  if (!extractedOrderId) {
3774
- extractedOrderId = checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.order_id;
3810
+ extractedOrderId = (_checkoutResponse8 = checkoutResponse) === null || _checkoutResponse8 === void 0 ? void 0 : _checkoutResponse8.order_id;
3775
3811
  }
3776
3812
 
3777
3813
  // 确保转换为字符串类型
@@ -3779,11 +3815,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3779
3815
  extractedOrderId = String(extractedOrderId);
3780
3816
  }
3781
3817
  if (extractedOrderId) {
3782
- _context48.next = 36;
3818
+ _context48.next = 55;
3783
3819
  break;
3784
3820
  }
3785
3821
  throw new Error('后端返回的订单信息中未包含订单ID');
3786
- case 36:
3822
+ case 55:
3787
3823
  realOrderId = extractedOrderId;
3788
3824
  console.log('[Checkout] 订单创建成功,真实订单ID:', realOrderId);
3789
3825
 
@@ -3793,10 +3829,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3793
3829
  oldOrderId: this.store.currentOrder.order_id,
3794
3830
  newOrderId: realOrderId
3795
3831
  });
3796
- _context48.prev = 39;
3797
- _context48.next = 42;
3832
+ _context48.prev = 58;
3833
+ _context48.next = 61;
3798
3834
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3799
- case 42:
3835
+ case 61:
3800
3836
  updatedOrder = _context48.sent;
3801
3837
  console.log('[Checkout] Payment模块替换订单ID结果:', {
3802
3838
  wasSuccessful: !!updatedOrder,
@@ -3823,22 +3859,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3823
3859
  目标ID: realOrderId
3824
3860
  });
3825
3861
  }
3826
- _context48.next = 52;
3862
+ _context48.next = 71;
3827
3863
  break;
3828
- case 47:
3829
- _context48.prev = 47;
3830
- _context48.t1 = _context48["catch"](39);
3831
- console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context48.t1);
3864
+ case 66:
3865
+ _context48.prev = 66;
3866
+ _context48.t2 = _context48["catch"](58);
3867
+ console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context48.t2);
3832
3868
 
3833
3869
  // 发生错误时也进行手动替换
3834
3870
  this.store.currentOrder.order_id = realOrderId;
3835
3871
  console.log('[Checkout] 错误恢复:手动设置订单ID:', realOrderId);
3836
- case 52:
3872
+ case 71:
3837
3873
  // 标记订单已同步
3838
3874
  this.store.isOrderSynced = true;
3839
3875
 
3840
3876
  // 触发订单同步完成事件
3841
- _context48.next = 55;
3877
+ _context48.next = 74;
3842
3878
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3843
3879
  orderUuid: this.store.currentOrder.uuid,
3844
3880
  realOrderId: realOrderId,
@@ -3847,7 +3883,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3847
3883
  isManual: isManual,
3848
3884
  response: checkoutResponse
3849
3885
  });
3850
- case 55:
3886
+ case 74:
3851
3887
  // 验证最终状态
3852
3888
  finalOrderId = this.store.currentOrder.order_id;
3853
3889
  finalIsVirtual = this.isVirtualOrderId(finalOrderId || '');
@@ -3865,11 +3901,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3865
3901
 
3866
3902
  // 返回真实订单ID
3867
3903
  return _context48.abrupt("return", realOrderId);
3868
- case 60:
3904
+ case 79:
3869
3905
  case "end":
3870
3906
  return _context48.stop();
3871
3907
  }
3872
- }, _callee48, this, [[39, 47]]);
3908
+ }, _callee48, this, [[26, 34, 40, 44], [58, 66]]);
3873
3909
  }));
3874
3910
  function syncOrderToBackendWithReturn() {
3875
3911
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -4297,17 +4333,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4297
4333
  // 清空购物车项目
4298
4334
  this.store.cartItems = [];
4299
4335
 
4336
+ // 清理钱包缓存
4337
+ this.payment.wallet.clearAllCache();
4338
+
4300
4339
  // 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
4301
4340
 
4302
4341
  // 重置状态和步骤为初始状态
4303
- _context55.next = 13;
4342
+ _context55.next = 14;
4304
4343
  return this.setStatus(CheckoutStatus.Ready);
4305
- case 13:
4306
- _context55.next = 15;
4344
+ case 14:
4345
+ _context55.next = 16;
4307
4346
  return this.setStep(CheckoutStep.OrderConfirmation);
4308
- case 15:
4309
- // 清理钱包缓存
4310
- this.payment.wallet.clearAllCache();
4347
+ case 16:
4311
4348
  console.log('[Checkout] Store 状态重置完成');
4312
4349
 
4313
4350
  // 触发订单清理事件(如果之前有订单)