@pisell/pisellos 3.0.76 → 3.0.78
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.
- package/dist/core/index.js +1 -2
- package/dist/effects/index.d.ts +3 -5
- package/dist/effects/index.js +8 -40
- package/dist/modules/Account/index.js +3 -2
- package/dist/modules/AccountList/index.d.ts +1 -7
- package/dist/modules/AccountList/index.js +14 -81
- package/dist/modules/AccountList/types.d.ts +0 -28
- package/dist/modules/AccountList/types.js +0 -8
- package/dist/modules/BaseModule.d.ts +0 -3
- package/dist/modules/BaseModule.js +0 -15
- package/dist/modules/Cart/index.d.ts +0 -1
- package/dist/modules/Cart/index.js +1 -2
- package/dist/modules/Date/types.d.ts +3 -1
- package/dist/modules/Discount/index.d.ts +0 -1
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Guests/index.js +9 -9
- package/dist/modules/Order/index.d.ts +1 -25
- package/dist/modules/Order/index.js +3 -224
- package/dist/modules/Order/types.d.ts +0 -45
- package/dist/modules/Order/types.js +0 -8
- package/dist/modules/Order/utils.js +1 -1
- package/dist/modules/Payment/index.d.ts +9 -184
- package/dist/modules/Payment/index.js +109 -2084
- package/dist/modules/Payment/types.d.ts +30 -772
- package/dist/modules/Payment/types.js +12 -236
- package/dist/modules/ProductList/index.d.ts +1 -12
- package/dist/modules/ProductList/index.js +6 -29
- package/dist/modules/Resource/index.js +1 -1
- package/dist/modules/Rules/index.d.ts +4 -3
- package/dist/modules/Rules/index.js +121 -78
- package/dist/modules/Rules/types.d.ts +6 -1
- package/dist/modules/Rules/types.js +8 -0
- package/dist/modules/Schedule/index.d.ts +0 -9
- package/dist/modules/Schedule/index.js +0 -77
- package/dist/modules/index.d.ts +0 -1
- package/dist/modules/index.js +0 -1
- package/dist/plugins/window.d.ts +0 -1
- package/dist/solution/BookingByStep/index.d.ts +17 -0
- package/dist/solution/BookingByStep/index.js +525 -190
- package/dist/solution/BookingByStep/utils/products.d.ts +0 -6
- package/dist/solution/BookingByStep/utils/products.js +0 -10
- package/dist/solution/BookingByStep/utils/resources.js +4 -0
- package/dist/solution/BuyTickets/index.js +8 -7
- package/dist/solution/ShopDiscount/index.d.ts +12 -10
- package/dist/solution/ShopDiscount/index.js +64 -110
- package/dist/solution/ShopDiscount/types.d.ts +0 -8
- package/dist/solution/ShopDiscount/utils.js +1 -0
- package/dist/solution/index.d.ts +0 -2
- package/dist/solution/index.js +1 -3
- package/dist/types/index.d.ts +1 -4
- package/lib/core/index.js +1 -1
- package/lib/effects/index.d.ts +3 -5
- package/lib/effects/index.js +1 -17
- package/lib/modules/Account/index.js +3 -2
- package/lib/modules/AccountList/index.d.ts +1 -7
- package/lib/modules/AccountList/index.js +0 -27
- package/lib/modules/AccountList/types.d.ts +0 -28
- package/lib/modules/BaseModule.d.ts +0 -3
- package/lib/modules/BaseModule.js +0 -9
- package/lib/modules/Cart/index.d.ts +0 -1
- package/lib/modules/Cart/index.js +2 -5
- package/lib/modules/Date/types.d.ts +3 -1
- package/lib/modules/Discount/index.d.ts +0 -1
- package/lib/modules/Discount/index.js +1 -1
- package/lib/modules/Guests/index.js +9 -9
- package/lib/modules/Order/index.d.ts +1 -25
- package/lib/modules/Order/index.js +1 -186
- package/lib/modules/Order/types.d.ts +0 -45
- package/lib/modules/Order/utils.js +1 -1
- package/lib/modules/Payment/index.d.ts +9 -184
- package/lib/modules/Payment/index.js +51 -1084
- package/lib/modules/Payment/types.d.ts +30 -772
- package/lib/modules/Payment/types.js +6 -79
- package/lib/modules/ProductList/index.d.ts +1 -12
- package/lib/modules/ProductList/index.js +5 -31
- package/lib/modules/Resource/index.js +1 -1
- package/lib/modules/Rules/index.d.ts +4 -3
- package/lib/modules/Rules/index.js +64 -43
- package/lib/modules/Rules/types.d.ts +6 -1
- package/lib/modules/Rules/types.js +11 -2
- package/lib/modules/Schedule/index.d.ts +0 -9
- package/lib/modules/Schedule/index.js +0 -60
- package/lib/modules/index.d.ts +0 -1
- package/lib/modules/index.js +0 -2
- package/lib/plugins/window.d.ts +0 -1
- package/lib/solution/BookingByStep/index.d.ts +17 -0
- package/lib/solution/BookingByStep/index.js +325 -60
- package/lib/solution/BookingByStep/utils/products.d.ts +0 -6
- package/lib/solution/BookingByStep/utils/products.js +2 -8
- package/lib/solution/BookingByStep/utils/resources.js +4 -1
- package/lib/solution/BuyTickets/index.js +8 -7
- package/lib/solution/ShopDiscount/index.d.ts +12 -10
- package/lib/solution/ShopDiscount/index.js +30 -51
- package/lib/solution/ShopDiscount/types.d.ts +0 -8
- package/lib/solution/index.d.ts +0 -2
- package/lib/solution/index.js +1 -5
- package/lib/types/index.d.ts +1 -4
- package/package.json +1 -3
- package/dist/modules/Customer/constants.d.ts +0 -7
- package/dist/modules/Customer/constants.js +0 -12
- package/dist/modules/Customer/index.d.ts +0 -122
- package/dist/modules/Customer/index.js +0 -696
- package/dist/modules/Customer/types.d.ts +0 -146
- package/dist/modules/Customer/types.js +0 -41
- package/dist/modules/Payment/cash.d.ts +0 -19
- package/dist/modules/Payment/cash.js +0 -97
- package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +0 -22
- package/dist/modules/Payment/cashRecommendationAlgorithm.js +0 -423
- package/dist/modules/Payment/eftpos.d.ts +0 -11
- package/dist/modules/Payment/eftpos.js +0 -80
- package/dist/modules/Payment/mx51.d.ts +0 -0
- package/dist/modules/Payment/mx51.js +0 -0
- package/dist/modules/Payment/utils.d.ts +0 -17
- package/dist/modules/Payment/utils.js +0 -62
- package/dist/modules/Payment/walletpass.d.ts +0 -99
- package/dist/modules/Payment/walletpass.js +0 -711
- package/dist/plugins/app-types/app/app.d.ts +0 -83
- package/dist/plugins/app-types/app/const.d.ts +0 -4
- package/dist/plugins/app-types/app/index.d.ts +0 -14
- package/dist/plugins/app-types/applicationManager/application.d.ts +0 -50
- package/dist/plugins/app-types/applicationManager/index.d.ts +0 -13
- package/dist/plugins/app-types/config.d.ts +0 -3
- package/dist/plugins/app-types/cookie/index.d.ts +0 -13
- package/dist/plugins/app-types/data/index.d.ts +0 -8
- package/dist/plugins/app-types/history/config.d.ts +0 -24
- package/dist/plugins/app-types/history/index.d.ts +0 -20
- package/dist/plugins/app-types/history/type.d.ts +0 -2
- package/dist/plugins/app-types/hooks/index.d.ts +0 -12
- package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +0 -2
- package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +0 -2
- package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +0 -13
- package/dist/plugins/app-types/hooks/useStore/index.d.ts +0 -6
- package/dist/plugins/app-types/index.d.ts +0 -6
- package/dist/plugins/app-types/indexDB/index.d.ts +0 -178
- package/dist/plugins/app-types/locales/en.d.ts +0 -3
- package/dist/plugins/app-types/locales/index.d.ts +0 -37
- package/dist/plugins/app-types/locales/original.d.ts +0 -3
- package/dist/plugins/app-types/locales/type.d.ts +0 -19
- package/dist/plugins/app-types/locales/zh-CN.d.ts +0 -3
- package/dist/plugins/app-types/locales/zh-HK.d.ts +0 -3
- package/dist/plugins/app-types/logger/feishu.d.ts +0 -11
- package/dist/plugins/app-types/logger/index.d.ts +0 -122
- package/dist/plugins/app-types/menuManager/hooks.d.ts +0 -17
- package/dist/plugins/app-types/menuManager/index.d.ts +0 -28
- package/dist/plugins/app-types/models/global.d.ts +0 -32
- package/dist/plugins/app-types/models/index.d.ts +0 -45
- package/dist/plugins/app-types/models/type.d.ts +0 -2
- package/dist/plugins/app-types/package.json +0 -15
- package/dist/plugins/app-types/plugin/index.d.ts +0 -0
- package/dist/plugins/app-types/pubsub/example.d.ts +0 -5
- package/dist/plugins/app-types/pubsub/index.d.ts +0 -63
- package/dist/plugins/app-types/request/cache.d.ts +0 -46
- package/dist/plugins/app-types/request/cancelToken.d.ts +0 -38
- package/dist/plugins/app-types/request/config.d.ts +0 -3
- package/dist/plugins/app-types/request/constants.d.ts +0 -2
- package/dist/plugins/app-types/request/index.d.ts +0 -24
- package/dist/plugins/app-types/request/pisell2Request.d.ts +0 -6
- package/dist/plugins/app-types/request/type.d.ts +0 -41
- package/dist/plugins/app-types/request/utils.d.ts +0 -46
- package/dist/plugins/app-types/routes/config.d.ts +0 -7
- package/dist/plugins/app-types/routes/index.d.ts +0 -28
- package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +0 -6
- package/dist/plugins/app-types/socket/components/index.d.ts +0 -2
- package/dist/plugins/app-types/socket/constants.d.ts +0 -33
- package/dist/plugins/app-types/socket/events.d.ts +0 -31
- package/dist/plugins/app-types/socket/heartbeat.d.ts +0 -66
- package/dist/plugins/app-types/socket/index.d.ts +0 -61
- package/dist/plugins/app-types/socket/monitor.d.ts +0 -169
- package/dist/plugins/app-types/socket/reconnect.d.ts +0 -61
- package/dist/plugins/app-types/socket/socket.d.ts +0 -129
- package/dist/plugins/app-types/socket/types.d.ts +0 -85
- package/dist/plugins/app-types/storage/index.d.ts +0 -17
- package/dist/plugins/app-types/tasks/index.d.ts +0 -77
- package/dist/plugins/app-types/tasks/type.d.ts +0 -62
- package/dist/plugins/app-types/tasks/useTasks.d.ts +0 -5
- package/dist/plugins/app-types/type.d.ts +0 -2
- package/dist/plugins/app-types/variables/VariablesProvider.d.ts +0 -7
- package/dist/plugins/app-types/variables/config.d.ts +0 -3
- package/dist/plugins/app-types/variables/index.d.ts +0 -6
- package/dist/plugins/app-types/variables/type.d.ts +0 -2
- package/dist/plugins/app-types/website/index.d.ts +0 -6
- package/dist/plugins/app.d.ts +0 -8
- package/dist/plugins/app.js +0 -1
- package/dist/solution/BookingTicket/index.d.ts +0 -184
- package/dist/solution/BookingTicket/index.js +0 -698
- package/dist/solution/BookingTicket/types.d.ts +0 -68
- package/dist/solution/BookingTicket/types.js +0 -43
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +0 -22
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +0 -159
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +0 -22
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +0 -189
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -85
- package/dist/solution/BookingTicket/utils/scan/index.js +0 -294
- package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +0 -78
- package/dist/solution/BookingTicket/utils/scan/scanCache.js +0 -305
- package/dist/solution/Checkout/appointmentDemo.json +0 -1
- package/dist/solution/Checkout/index.d.ts +0 -432
- package/dist/solution/Checkout/index.js +0 -4452
- package/dist/solution/Checkout/types.d.ts +0 -727
- package/dist/solution/Checkout/types.js +0 -104
- package/dist/solution/Checkout/utils/index.d.ts +0 -121
- package/dist/solution/Checkout/utils/index.js +0 -511
- package/dist/utils/task.d.ts +0 -40
- package/dist/utils/task.js +0 -171
- package/dist/utils/watch.d.ts +0 -102
- package/dist/utils/watch.js +0 -294
- package/lib/modules/Customer/constants.d.ts +0 -7
- package/lib/modules/Customer/constants.js +0 -39
- package/lib/modules/Customer/index.d.ts +0 -122
- package/lib/modules/Customer/index.js +0 -439
- package/lib/modules/Customer/types.d.ts +0 -146
- package/lib/modules/Customer/types.js +0 -37
- package/lib/modules/Payment/cash.d.ts +0 -19
- package/lib/modules/Payment/cash.js +0 -64
- package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +0 -22
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +0 -342
- package/lib/modules/Payment/eftpos.d.ts +0 -11
- package/lib/modules/Payment/eftpos.js +0 -51
- package/lib/modules/Payment/mx51.d.ts +0 -0
- package/lib/modules/Payment/mx51.js +0 -0
- package/lib/modules/Payment/utils.d.ts +0 -17
- package/lib/modules/Payment/utils.js +0 -67
- package/lib/modules/Payment/walletpass.d.ts +0 -99
- package/lib/modules/Payment/walletpass.js +0 -484
- package/lib/plugins/app-types/app/app.d.ts +0 -83
- package/lib/plugins/app-types/app/const.d.ts +0 -4
- package/lib/plugins/app-types/app/index.d.ts +0 -14
- package/lib/plugins/app-types/applicationManager/application.d.ts +0 -50
- package/lib/plugins/app-types/applicationManager/index.d.ts +0 -13
- package/lib/plugins/app-types/config.d.ts +0 -3
- package/lib/plugins/app-types/cookie/index.d.ts +0 -13
- package/lib/plugins/app-types/data/index.d.ts +0 -8
- package/lib/plugins/app-types/history/config.d.ts +0 -24
- package/lib/plugins/app-types/history/index.d.ts +0 -20
- package/lib/plugins/app-types/history/type.d.ts +0 -2
- package/lib/plugins/app-types/hooks/index.d.ts +0 -12
- package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +0 -2
- package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +0 -2
- package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +0 -13
- package/lib/plugins/app-types/hooks/useStore/index.d.ts +0 -6
- package/lib/plugins/app-types/index.d.ts +0 -6
- package/lib/plugins/app-types/indexDB/index.d.ts +0 -178
- package/lib/plugins/app-types/locales/en.d.ts +0 -3
- package/lib/plugins/app-types/locales/index.d.ts +0 -37
- package/lib/plugins/app-types/locales/original.d.ts +0 -3
- package/lib/plugins/app-types/locales/type.d.ts +0 -19
- package/lib/plugins/app-types/locales/zh-CN.d.ts +0 -3
- package/lib/plugins/app-types/locales/zh-HK.d.ts +0 -3
- package/lib/plugins/app-types/logger/feishu.d.ts +0 -11
- package/lib/plugins/app-types/logger/index.d.ts +0 -122
- package/lib/plugins/app-types/menuManager/hooks.d.ts +0 -17
- package/lib/plugins/app-types/menuManager/index.d.ts +0 -28
- package/lib/plugins/app-types/models/global.d.ts +0 -32
- package/lib/plugins/app-types/models/index.d.ts +0 -45
- package/lib/plugins/app-types/models/type.d.ts +0 -2
- package/lib/plugins/app-types/package.json +0 -15
- package/lib/plugins/app-types/plugin/index.d.ts +0 -0
- package/lib/plugins/app-types/pubsub/example.d.ts +0 -5
- package/lib/plugins/app-types/pubsub/index.d.ts +0 -63
- package/lib/plugins/app-types/request/cache.d.ts +0 -46
- package/lib/plugins/app-types/request/cancelToken.d.ts +0 -38
- package/lib/plugins/app-types/request/config.d.ts +0 -3
- package/lib/plugins/app-types/request/constants.d.ts +0 -2
- package/lib/plugins/app-types/request/index.d.ts +0 -24
- package/lib/plugins/app-types/request/pisell2Request.d.ts +0 -6
- package/lib/plugins/app-types/request/type.d.ts +0 -41
- package/lib/plugins/app-types/request/utils.d.ts +0 -46
- package/lib/plugins/app-types/routes/config.d.ts +0 -7
- package/lib/plugins/app-types/routes/index.d.ts +0 -28
- package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +0 -6
- package/lib/plugins/app-types/socket/components/index.d.ts +0 -2
- package/lib/plugins/app-types/socket/constants.d.ts +0 -33
- package/lib/plugins/app-types/socket/events.d.ts +0 -31
- package/lib/plugins/app-types/socket/heartbeat.d.ts +0 -66
- package/lib/plugins/app-types/socket/index.d.ts +0 -61
- package/lib/plugins/app-types/socket/monitor.d.ts +0 -169
- package/lib/plugins/app-types/socket/reconnect.d.ts +0 -61
- package/lib/plugins/app-types/socket/socket.d.ts +0 -129
- package/lib/plugins/app-types/socket/types.d.ts +0 -85
- package/lib/plugins/app-types/storage/index.d.ts +0 -17
- package/lib/plugins/app-types/tasks/index.d.ts +0 -77
- package/lib/plugins/app-types/tasks/type.d.ts +0 -62
- package/lib/plugins/app-types/tasks/useTasks.d.ts +0 -5
- package/lib/plugins/app-types/type.d.ts +0 -2
- package/lib/plugins/app-types/variables/VariablesProvider.d.ts +0 -7
- package/lib/plugins/app-types/variables/config.d.ts +0 -3
- package/lib/plugins/app-types/variables/index.d.ts +0 -6
- package/lib/plugins/app-types/variables/type.d.ts +0 -2
- package/lib/plugins/app-types/website/index.d.ts +0 -6
- package/lib/plugins/app.d.ts +0 -8
- package/lib/plugins/app.js +0 -17
- package/lib/solution/BookingTicket/index.d.ts +0 -184
- package/lib/solution/BookingTicket/index.js +0 -426
- package/lib/solution/BookingTicket/types.d.ts +0 -68
- package/lib/solution/BookingTicket/types.js +0 -72
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +0 -22
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +0 -117
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +0 -22
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +0 -132
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -85
- package/lib/solution/BookingTicket/utils/scan/index.js +0 -216
- package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +0 -78
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +0 -231
- package/lib/solution/Checkout/appointmentDemo.json +0 -1
- package/lib/solution/Checkout/index.d.ts +0 -432
- package/lib/solution/Checkout/index.js +0 -2776
- package/lib/solution/Checkout/types.d.ts +0 -727
- package/lib/solution/Checkout/types.js +0 -63
- package/lib/solution/Checkout/utils/index.d.ts +0 -121
- package/lib/solution/Checkout/utils/index.js +0 -362
- package/lib/utils/task.d.ts +0 -40
- package/lib/utils/task.js +0 -109
- package/lib/utils/watch.d.ts +0 -102
- package/lib/utils/watch.js +0 -217
|
@@ -1,4452 +0,0 @@
|
|
|
1
|
-
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
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
-
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; } } }; }
|
|
7
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
-
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."); }
|
|
9
|
-
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); }
|
|
10
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
-
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; }
|
|
13
|
-
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; }
|
|
14
|
-
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; }
|
|
15
|
-
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; }
|
|
16
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
18
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
20
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
22
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
23
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
24
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
25
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
26
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
28
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
30
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
31
|
-
import { BaseModule } from "../../modules/BaseModule";
|
|
32
|
-
import Decimal from 'decimal.js';
|
|
33
|
-
import { OrderModule } from "../../modules/Order";
|
|
34
|
-
import { PaymentModule } from "../../modules/Payment";
|
|
35
|
-
import { CheckoutErrorType } from "./types";
|
|
36
|
-
import { PaymentStatus, PaymentHooks } from "../../modules/Payment/types";
|
|
37
|
-
import { validateCheckoutData, createCheckoutError, validateLocalOrderData, generateLocalOrderId, formatDateTime, extractAmountFromCartSummary, isVirtualOrderId, isCashPayment } from "./utils";
|
|
38
|
-
import { getProductDeposit } from "../../modules/Cart/utils";
|
|
39
|
-
export * from "./types";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 结账解决方案实现
|
|
43
|
-
*
|
|
44
|
-
* 整合订单处理和支付功能,提供完整的结账流程管理。
|
|
45
|
-
* 支持多种支付方式,提供实时状态跟踪和错误处理。
|
|
46
|
-
*/
|
|
47
|
-
export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
48
|
-
_inherits(CheckoutImpl, _BaseModule);
|
|
49
|
-
var _super = _createSuper(CheckoutImpl);
|
|
50
|
-
function CheckoutImpl(name, version) {
|
|
51
|
-
var _this;
|
|
52
|
-
_classCallCheck(this, CheckoutImpl);
|
|
53
|
-
_this = _super.call(this, name || 'checkout', version || '1.0.0');
|
|
54
|
-
_defineProperty(_assertThisInitialized(_this), "defaultName", 'checkout');
|
|
55
|
-
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
56
|
-
_defineProperty(_assertThisInitialized(_this), "isSolution", true);
|
|
57
|
-
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
58
|
-
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
59
|
-
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
60
|
-
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
|
61
|
-
// LoggerManager 实例
|
|
62
|
-
// 计算缓存(用于性能优化)
|
|
63
|
-
_defineProperty(_assertThisInitialized(_this), "calculationCache", {});
|
|
64
|
-
// 直接挂载的模块
|
|
65
|
-
_defineProperty(_assertThisInitialized(_this), "order", void 0);
|
|
66
|
-
_defineProperty(_assertThisInitialized(_this), "payment", void 0);
|
|
67
|
-
return _this;
|
|
68
|
-
}
|
|
69
|
-
_createClass(CheckoutImpl, [{
|
|
70
|
-
key: "initialize",
|
|
71
|
-
value: function () {
|
|
72
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
73
|
-
var appPlugin, app;
|
|
74
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
75
|
-
while (1) switch (_context.prev = _context.next) {
|
|
76
|
-
case 0:
|
|
77
|
-
this.core = core;
|
|
78
|
-
this.otherParams = options.otherParams || {};
|
|
79
|
-
|
|
80
|
-
// 获取依赖的插件
|
|
81
|
-
this.request = core.getPlugin('request');
|
|
82
|
-
if (this.request) {
|
|
83
|
-
_context.next = 5;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
throw new Error('Checkout 解决方案需要 request 插件支持');
|
|
87
|
-
case 5:
|
|
88
|
-
// 获取 logger 实例
|
|
89
|
-
appPlugin = core.getPlugin('app');
|
|
90
|
-
if (appPlugin) {
|
|
91
|
-
_context.next = 8;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
throw new Error('Checkout 解决方案需要 app 插件支持');
|
|
95
|
-
case 8:
|
|
96
|
-
app = appPlugin.getApp();
|
|
97
|
-
this.logger = app.logger;
|
|
98
|
-
|
|
99
|
-
// 初始化模块
|
|
100
|
-
this.order = new OrderModule();
|
|
101
|
-
this.payment = new PaymentModule();
|
|
102
|
-
|
|
103
|
-
// 初始化状态
|
|
104
|
-
this.store = {
|
|
105
|
-
cartItems: [],
|
|
106
|
-
paymentMethods: [],
|
|
107
|
-
stateAmount: '0.00',
|
|
108
|
-
balanceDueAmount: '0.00',
|
|
109
|
-
cartSummary: undefined,
|
|
110
|
-
isOrderSynced: false,
|
|
111
|
-
currentCustomer: undefined
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// 注册并初始化子模块
|
|
115
|
-
_context.next = 15;
|
|
116
|
-
return this.initializeSubModules(core, options);
|
|
117
|
-
case 15:
|
|
118
|
-
_context.next = 17;
|
|
119
|
-
return this.preloadPaymentMethods();
|
|
120
|
-
case 17:
|
|
121
|
-
_context.next = 19;
|
|
122
|
-
return this.cleanupExpiredOrdersAsync();
|
|
123
|
-
case 19:
|
|
124
|
-
console.log('[Checkout] 初始化完成');
|
|
125
|
-
_context.next = 22;
|
|
126
|
-
return this.core.effects.emit("".concat(this.name, ":onCheckoutInitialized"), {
|
|
127
|
-
timestamp: Date.now()
|
|
128
|
-
});
|
|
129
|
-
case 22:
|
|
130
|
-
this.logInfo('CheckoutModule initialized successfully');
|
|
131
|
-
case 23:
|
|
132
|
-
case "end":
|
|
133
|
-
return _context.stop();
|
|
134
|
-
}
|
|
135
|
-
}, _callee, this);
|
|
136
|
-
}));
|
|
137
|
-
function initialize(_x, _x2) {
|
|
138
|
-
return _initialize.apply(this, arguments);
|
|
139
|
-
}
|
|
140
|
-
return initialize;
|
|
141
|
-
}()
|
|
142
|
-
/**
|
|
143
|
-
* 记录信息日志
|
|
144
|
-
*/
|
|
145
|
-
}, {
|
|
146
|
-
key: "logInfo",
|
|
147
|
-
value: function logInfo(title, metadata) {
|
|
148
|
-
if (this.logger) {
|
|
149
|
-
this.logger.addLog({
|
|
150
|
-
type: 'info',
|
|
151
|
-
title: "[CheckoutModule] ".concat(this.getCurrentOrderId(), " ").concat(title),
|
|
152
|
-
metadata: metadata || {}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 记录警告日志
|
|
159
|
-
*/
|
|
160
|
-
}, {
|
|
161
|
-
key: "logWarning",
|
|
162
|
-
value: function logWarning(title, metadata) {
|
|
163
|
-
if (this.logger) {
|
|
164
|
-
this.logger.addLog({
|
|
165
|
-
type: 'warning',
|
|
166
|
-
title: "[CheckoutModule] ".concat(title),
|
|
167
|
-
metadata: metadata || {}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 记录错误日志
|
|
174
|
-
*/
|
|
175
|
-
}, {
|
|
176
|
-
key: "logError",
|
|
177
|
-
value: function logError(title, metadata) {
|
|
178
|
-
if (this.logger) {
|
|
179
|
-
this.logger.addLog({
|
|
180
|
-
type: 'error',
|
|
181
|
-
title: "[CheckoutModule] ".concat(title),
|
|
182
|
-
metadata: metadata || {}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* 初始化子模块
|
|
189
|
-
*/
|
|
190
|
-
}, {
|
|
191
|
-
key: "initializeSubModules",
|
|
192
|
-
value: (function () {
|
|
193
|
-
var _initializeSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
|
|
194
|
-
var _options$store, _options$store2;
|
|
195
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
196
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
197
|
-
case 0:
|
|
198
|
-
// 初始化订单模块
|
|
199
|
-
core.registerModule(this.order, {
|
|
200
|
-
store: ((_options$store = options.store) === null || _options$store === void 0 ? void 0 : _options$store.order) || {},
|
|
201
|
-
otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
|
|
202
|
-
fatherModule: this.name
|
|
203
|
-
})
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// 初始化支付模块
|
|
207
|
-
core.registerModule(this.payment, {
|
|
208
|
-
store: ((_options$store2 = options.store) === null || _options$store2 === void 0 ? void 0 : _options$store2.payment) || {},
|
|
209
|
-
otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
|
|
210
|
-
fatherModule: this.name
|
|
211
|
-
})
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// 监听支付模块事件
|
|
215
|
-
this.setupPaymentEventListeners();
|
|
216
|
-
case 3:
|
|
217
|
-
case "end":
|
|
218
|
-
return _context2.stop();
|
|
219
|
-
}
|
|
220
|
-
}, _callee2, this);
|
|
221
|
-
}));
|
|
222
|
-
function initializeSubModules(_x3, _x4) {
|
|
223
|
-
return _initializeSubModules.apply(this, arguments);
|
|
224
|
-
}
|
|
225
|
-
return initializeSubModules;
|
|
226
|
-
}()
|
|
227
|
-
/**
|
|
228
|
-
* 设置支付模块事件监听
|
|
229
|
-
*/
|
|
230
|
-
)
|
|
231
|
-
}, {
|
|
232
|
-
key: "setupPaymentEventListeners",
|
|
233
|
-
value: function setupPaymentEventListeners() {
|
|
234
|
-
var _this2 = this;
|
|
235
|
-
// 监听支付成功事件
|
|
236
|
-
this.core.effects.on('payment:onPaymentSyncSuccess', /*#__PURE__*/function () {
|
|
237
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(data) {
|
|
238
|
-
var _this2$store$currentO;
|
|
239
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
240
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
241
|
-
case 0:
|
|
242
|
-
if (!(((_this2$store$currentO = _this2.store.currentOrder) === null || _this2$store$currentO === void 0 ? void 0 : _this2$store$currentO.uuid) === data.orderUuid)) {
|
|
243
|
-
_context3.next = 3;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
_context3.next = 3;
|
|
247
|
-
return _this2.handlePaymentSuccess(data);
|
|
248
|
-
case 3:
|
|
249
|
-
case "end":
|
|
250
|
-
return _context3.stop();
|
|
251
|
-
}
|
|
252
|
-
}, _callee3);
|
|
253
|
-
}));
|
|
254
|
-
return function (_x5) {
|
|
255
|
-
return _ref.apply(this, arguments);
|
|
256
|
-
};
|
|
257
|
-
}());
|
|
258
|
-
|
|
259
|
-
// 监听支付失败事件
|
|
260
|
-
this.core.effects.on('payment:onPaymentSyncError', /*#__PURE__*/function () {
|
|
261
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(data) {
|
|
262
|
-
var _this2$store$currentO2;
|
|
263
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
264
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
265
|
-
case 0:
|
|
266
|
-
if (!(((_this2$store$currentO2 = _this2.store.currentOrder) === null || _this2$store$currentO2 === void 0 ? void 0 : _this2$store$currentO2.uuid) === data.orderUuid)) {
|
|
267
|
-
_context4.next = 3;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
_context4.next = 3;
|
|
271
|
-
return _this2.handlePaymentError(data);
|
|
272
|
-
case 3:
|
|
273
|
-
case "end":
|
|
274
|
-
return _context4.stop();
|
|
275
|
-
}
|
|
276
|
-
}, _callee4);
|
|
277
|
-
}));
|
|
278
|
-
return function (_x6) {
|
|
279
|
-
return _ref2.apply(this, arguments);
|
|
280
|
-
};
|
|
281
|
-
}());
|
|
282
|
-
|
|
283
|
-
// 监听支付方式加载完成事件
|
|
284
|
-
this.core.effects.on(PaymentHooks.OnPaymentMethodsLoaded, /*#__PURE__*/function () {
|
|
285
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(methods) {
|
|
286
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
287
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
288
|
-
case 0:
|
|
289
|
-
console.log('[Checkout] 收到支付方式加载完成事件:', methods.length);
|
|
290
|
-
_this2.store.paymentMethods = methods;
|
|
291
|
-
case 2:
|
|
292
|
-
case "end":
|
|
293
|
-
return _context5.stop();
|
|
294
|
-
}
|
|
295
|
-
}, _callee5);
|
|
296
|
-
}));
|
|
297
|
-
return function (_x7) {
|
|
298
|
-
return _ref3.apply(this, arguments);
|
|
299
|
-
};
|
|
300
|
-
}());
|
|
301
|
-
|
|
302
|
-
// 监听支付方式变更事件
|
|
303
|
-
this.core.effects.on(PaymentHooks.OnPaymentMethodsChanged, /*#__PURE__*/function () {
|
|
304
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(data) {
|
|
305
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
306
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
307
|
-
case 0:
|
|
308
|
-
console.log('[Checkout] 收到支付方式变更事件:', {
|
|
309
|
-
oldCount: data.oldMethods.length,
|
|
310
|
-
newCount: data.newMethods.length
|
|
311
|
-
});
|
|
312
|
-
_this2.store.paymentMethods = data.newMethods;
|
|
313
|
-
case 2:
|
|
314
|
-
case "end":
|
|
315
|
-
return _context6.stop();
|
|
316
|
-
}
|
|
317
|
-
}, _callee6);
|
|
318
|
-
}));
|
|
319
|
-
return function (_x8) {
|
|
320
|
-
return _ref4.apply(this, arguments);
|
|
321
|
-
};
|
|
322
|
-
}());
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* 初始化结账流程
|
|
327
|
-
*/
|
|
328
|
-
}, {
|
|
329
|
-
key: "initializeCheckoutAsync",
|
|
330
|
-
value: (function () {
|
|
331
|
-
var _initializeCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
|
|
332
|
-
var _params$cartItems;
|
|
333
|
-
var validation;
|
|
334
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
335
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
336
|
-
case 0:
|
|
337
|
-
this.logInfo('initializeCheckoutAsync called', {
|
|
338
|
-
cartItemsCount: ((_params$cartItems = params.cartItems) === null || _params$cartItems === void 0 ? void 0 : _params$cartItems.length) || 0,
|
|
339
|
-
orderType: params.orderType,
|
|
340
|
-
platform: params.platform
|
|
341
|
-
});
|
|
342
|
-
_context7.prev = 1;
|
|
343
|
-
// 验证参数
|
|
344
|
-
validation = this.validateCheckoutParams(params);
|
|
345
|
-
if (validation.valid) {
|
|
346
|
-
_context7.next = 5;
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
|
|
350
|
-
case 5:
|
|
351
|
-
// 保存购物车数据
|
|
352
|
-
this.store.cartItems = params.cartItems;
|
|
353
|
-
console.log('[Checkout] 结账流程初始化完成');
|
|
354
|
-
_context7.next = 14;
|
|
355
|
-
break;
|
|
356
|
-
case 9:
|
|
357
|
-
_context7.prev = 9;
|
|
358
|
-
_context7.t0 = _context7["catch"](1);
|
|
359
|
-
_context7.next = 13;
|
|
360
|
-
return this.handleError(_context7.t0, CheckoutErrorType.UnknownError);
|
|
361
|
-
case 13:
|
|
362
|
-
throw _context7.t0;
|
|
363
|
-
case 14:
|
|
364
|
-
case "end":
|
|
365
|
-
return _context7.stop();
|
|
366
|
-
}
|
|
367
|
-
}, _callee7, this, [[1, 9]]);
|
|
368
|
-
}));
|
|
369
|
-
function initializeCheckoutAsync(_x9) {
|
|
370
|
-
return _initializeCheckoutAsync.apply(this, arguments);
|
|
371
|
-
}
|
|
372
|
-
return initializeCheckoutAsync;
|
|
373
|
-
}())
|
|
374
|
-
}, {
|
|
375
|
-
key: "getHolderIdFromBooking",
|
|
376
|
-
value: function getHolderIdFromBooking(obj) {
|
|
377
|
-
var _obj$holder;
|
|
378
|
-
if (!obj) return undefined;
|
|
379
|
-
var ret = obj.holder_id || ((_obj$holder = obj.holder) === null || _obj$holder === void 0 ? void 0 : _obj$holder.form_record);
|
|
380
|
-
if (Array.isArray(ret)) {
|
|
381
|
-
return ret.length > 0 ? Number(ret[0]) : undefined;
|
|
382
|
-
}
|
|
383
|
-
return Number(ret) || undefined;
|
|
384
|
-
}
|
|
385
|
-
}, {
|
|
386
|
-
key: "getProductListByOrder",
|
|
387
|
-
value: function getProductListByOrder() {
|
|
388
|
-
var _this$store$currentOr,
|
|
389
|
-
_this3 = this,
|
|
390
|
-
_this$store$currentOr2;
|
|
391
|
-
if (!this.store.currentOrder) {
|
|
392
|
-
return [];
|
|
393
|
-
}
|
|
394
|
-
var getDiscountListAmount = function getDiscountListAmount(list) {
|
|
395
|
-
return list.reduce(function (pre, item) {
|
|
396
|
-
return pre + (item.amount || 0);
|
|
397
|
-
}, 0);
|
|
398
|
-
};
|
|
399
|
-
var formatProduct = function formatProduct(items) {
|
|
400
|
-
return items.map(function (item) {
|
|
401
|
-
var _item$is_charge_tax;
|
|
402
|
-
return {
|
|
403
|
-
product_id: item.product_id,
|
|
404
|
-
product_variant_id: item.product_variant_id,
|
|
405
|
-
quantity: item.num,
|
|
406
|
-
// 商品是否含税:1;0
|
|
407
|
-
is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
|
|
408
|
-
// 若商品不含税,计算得到的税费,单位(元)
|
|
409
|
-
tax_fee: item.tax_fee,
|
|
410
|
-
// 整个商品折扣后的总金额
|
|
411
|
-
selling_price: item.calculated_selling_price,
|
|
412
|
-
// 使用者id
|
|
413
|
-
holder_id: item.holder_id,
|
|
414
|
-
// 整个商品折扣前的总金额
|
|
415
|
-
original_price: item.calculated_original_price,
|
|
416
|
-
// 主商品折扣前金额,不包含套餐子商品
|
|
417
|
-
main_product_original_price: item.price,
|
|
418
|
-
// 主商品折扣后金额,不包含套餐子商品
|
|
419
|
-
main_product_selling_price: item.main_product_selling_price,
|
|
420
|
-
metadata: {
|
|
421
|
-
// 主商品+非原价(加减价)子商品税费
|
|
422
|
-
"main_product_attached_bundle_tax_fee": item.metadata.main_product_attached_bundle_tax_fee,
|
|
423
|
-
// 主商品+非原价(加减价)子商品附加费
|
|
424
|
-
"main_product_attached_bundle_surcharge_fee": item.metadata.main_product_attached_bundle_surcharge_fee,
|
|
425
|
-
// 可选,附加费均摊舍入金额
|
|
426
|
-
"surcharge_rounding_remainder": item.metadata.surcharge_rounding_remainder
|
|
427
|
-
},
|
|
428
|
-
product_bundle: item.product_bundle.map(function (bundle) {
|
|
429
|
-
return {
|
|
430
|
-
bundle_id: bundle.bundle_id,
|
|
431
|
-
bundle_product_id: bundle.bundle_product_id,
|
|
432
|
-
bundle_variant_id: bundle.bundle_variant_id,
|
|
433
|
-
price_type: bundle.price_type,
|
|
434
|
-
price_type_ext: bundle.price_type_ext,
|
|
435
|
-
// 套餐子商品总价,不包含折扣金额
|
|
436
|
-
bundle_sum_price: bundle.bundle_sum_price,
|
|
437
|
-
// 套餐子商品折扣后金额
|
|
438
|
-
bundle_selling_price: bundle.bundle_selling_price,
|
|
439
|
-
num: bundle.num,
|
|
440
|
-
is_charge_tax: bundle.is_charge_tax,
|
|
441
|
-
tax_fee: bundle.tax_fee,
|
|
442
|
-
metadata: {
|
|
443
|
-
// 子商品单数量附加费
|
|
444
|
-
"surcharge_fee": bundle.metadata.surcharge_fee,
|
|
445
|
-
// 可选,附加费均摊舍入金额
|
|
446
|
-
"surcharge_rounding_remainder": bundle.metadata.surcharge_rounding_remainder
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
})
|
|
450
|
-
};
|
|
451
|
-
}) || [];
|
|
452
|
-
};
|
|
453
|
-
var productList = formatProduct(((_this$store$currentOr = this.store.currentOrder.order_info) === null || _this$store$currentOr === void 0 || (_this$store$currentOr = _this$store$currentOr.original_order_data) === null || _this$store$currentOr === void 0 || (_this$store$currentOr = _this$store$currentOr.bookings) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.map(function (item) {
|
|
454
|
-
return _objectSpread(_objectSpread({}, item.product), {}, {
|
|
455
|
-
holder_id: _this3.getHolderIdFromBooking(item)
|
|
456
|
-
});
|
|
457
|
-
})) || []);
|
|
458
|
-
var relationProducts = formatProduct(((_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 ? void 0 : _this$store$currentOr2.relation_products) || []);
|
|
459
|
-
return [].concat(_toConsumableArray(productList), _toConsumableArray(relationProducts));
|
|
460
|
-
}
|
|
461
|
-
}, {
|
|
462
|
-
key: "initWalletData",
|
|
463
|
-
value: function () {
|
|
464
|
-
var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
|
|
465
|
-
var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr4, _this$store$currentOr5, _this$store$currentOr7;
|
|
466
|
-
var amountInfo, walletBusinessData, _this$store$currentOr6;
|
|
467
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
468
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
469
|
-
case 0:
|
|
470
|
-
this.logInfo('initWalletData called', {
|
|
471
|
-
params: params
|
|
472
|
-
});
|
|
473
|
-
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;
|
|
474
|
-
if (amountInfo) {
|
|
475
|
-
_context8.next = 5;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
this.logInfo('initWalletData amountInfo not found', {
|
|
479
|
-
params: params
|
|
480
|
-
});
|
|
481
|
-
return _context8.abrupt("return");
|
|
482
|
-
case 5:
|
|
483
|
-
// 准备钱包初始化的业务数据
|
|
484
|
-
walletBusinessData = _objectSpread({
|
|
485
|
-
customer_id: (_this$store$currentCu = this.store.currentCustomer) !== null && _this$store$currentCu !== void 0 && _this$store$currentCu.customer_id ? Number(this.store.currentCustomer.customer_id) : undefined,
|
|
486
|
-
amountInfo: {
|
|
487
|
-
totalAmount: amountInfo.totalAmount,
|
|
488
|
-
subTotal: amountInfo.subTotal,
|
|
489
|
-
depositAmount: (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.deposit_amount,
|
|
490
|
-
isDeposit: (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.is_deposit
|
|
491
|
-
},
|
|
492
|
-
products: this.getProductListByOrder(),
|
|
493
|
-
is_price_include_tax: this.otherParams.is_price_include_tax
|
|
494
|
-
}, params); // 判断订单是否已经同步,如果是则追加payment_order_id参数
|
|
495
|
-
if (this.store.isOrderSynced) {
|
|
496
|
-
walletBusinessData.payment_order_id = (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_id;
|
|
497
|
-
}
|
|
498
|
-
this.logInfo('开始拉取:initializeWalletDataFromBusinessAsync', {
|
|
499
|
-
walletBusinessData: walletBusinessData
|
|
500
|
-
});
|
|
501
|
-
_context8.next = 10;
|
|
502
|
-
return this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
|
|
503
|
-
case 10:
|
|
504
|
-
this.logInfo('调用结束:initializeWalletDataFromBusinessAsync', {
|
|
505
|
-
walletBusinessData: walletBusinessData
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
// 因为上面是接口 这里最好检查一下还有没有 currentOrder 了,如果没有,则不触发事件
|
|
509
|
-
if (this.store.currentOrder) {
|
|
510
|
-
_context8.next = 13;
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
return _context8.abrupt("return");
|
|
514
|
-
case 13:
|
|
515
|
-
this.logInfo('initWalletData currentOrder found', {
|
|
516
|
-
currentOrder: this.store.currentOrder
|
|
517
|
-
});
|
|
518
|
-
// 触发钱包数据初始化完成事件
|
|
519
|
-
_context8.next = 16;
|
|
520
|
-
return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
|
|
521
|
-
orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
|
|
522
|
-
customerId: walletBusinessData.customer_id,
|
|
523
|
-
walletBusinessData: {
|
|
524
|
-
customer_id: walletBusinessData.customer_id,
|
|
525
|
-
amountInfo: walletBusinessData.amountInfo,
|
|
526
|
-
order_wait_pay_amount: params === null || params === void 0 ? void 0 : params.order_wait_pay_amount
|
|
527
|
-
},
|
|
528
|
-
timestamp: Date.now()
|
|
529
|
-
});
|
|
530
|
-
case 16:
|
|
531
|
-
case "end":
|
|
532
|
-
return _context8.stop();
|
|
533
|
-
}
|
|
534
|
-
}, _callee8, this);
|
|
535
|
-
}));
|
|
536
|
-
function initWalletData(_x10) {
|
|
537
|
-
return _initWalletData.apply(this, arguments);
|
|
538
|
-
}
|
|
539
|
-
return initWalletData;
|
|
540
|
-
}()
|
|
541
|
-
}, {
|
|
542
|
-
key: "checkIsNeedDepositAsync",
|
|
543
|
-
value: function checkIsNeedDepositAsync(bookings, relationProducts) {
|
|
544
|
-
var summaryDeposit = {
|
|
545
|
-
total: 0,
|
|
546
|
-
protocols: [],
|
|
547
|
-
hasDeposit: false
|
|
548
|
-
};
|
|
549
|
-
bookings === null || bookings === void 0 || bookings.forEach(function (item) {
|
|
550
|
-
var total = item.product.calculated_selling_price;
|
|
551
|
-
var deposit = getProductDeposit({
|
|
552
|
-
cartItem: {
|
|
553
|
-
total: total
|
|
554
|
-
},
|
|
555
|
-
product: item.product,
|
|
556
|
-
bundle: item.bundle,
|
|
557
|
-
options: item.options,
|
|
558
|
-
num: item.num
|
|
559
|
-
});
|
|
560
|
-
item.deposit = deposit;
|
|
561
|
-
if (deposit !== null && deposit !== void 0 && deposit.total && Number(deposit.total) > 0) {
|
|
562
|
-
summaryDeposit.protocols = summaryDeposit.protocols.concat(deposit.protocols);
|
|
563
|
-
summaryDeposit.total = new Decimal(summaryDeposit.total).plus(deposit.total).toNumber();
|
|
564
|
-
summaryDeposit.hasDeposit = true;
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
relationProducts === null || relationProducts === void 0 || relationProducts.forEach(function (item) {
|
|
568
|
-
var deposit = getProductDeposit({
|
|
569
|
-
cartItem: {
|
|
570
|
-
total: item.price * item.num
|
|
571
|
-
},
|
|
572
|
-
product: item,
|
|
573
|
-
bundle: item.product_bundle,
|
|
574
|
-
options: item.product_option_item,
|
|
575
|
-
num: item.num
|
|
576
|
-
});
|
|
577
|
-
item.deposit = deposit;
|
|
578
|
-
if (deposit !== null && deposit !== void 0 && deposit.total && Number(deposit.total) > 0) {
|
|
579
|
-
// 需要减去商品券折扣卡抵扣的金额
|
|
580
|
-
summaryDeposit.total = new Decimal(summaryDeposit.total).plus(deposit.total).toNumber();
|
|
581
|
-
item.discount_list.forEach(function (discount) {
|
|
582
|
-
summaryDeposit.total = new Decimal(summaryDeposit.total).minus(discount.amount || 0).toNumber();
|
|
583
|
-
});
|
|
584
|
-
summaryDeposit.protocols = summaryDeposit.protocols.concat(deposit.protocols);
|
|
585
|
-
summaryDeposit.hasDeposit = true;
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
// 将总金额四舍五入到两位小数
|
|
590
|
-
summaryDeposit.total = new Decimal(summaryDeposit.total).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
591
|
-
return summaryDeposit;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* 创建本地订单 (前端模拟下单流程)
|
|
596
|
-
*
|
|
597
|
-
* 此方法用于在前端模拟整个下单流程,创建一个本地的虚拟订单。
|
|
598
|
-
* 用户在购物车点击下单时,会把购物车参数传递给此方法,
|
|
599
|
-
* 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
|
|
600
|
-
*/
|
|
601
|
-
}, {
|
|
602
|
-
key: "createLocalOrderAsync",
|
|
603
|
-
value: (function () {
|
|
604
|
-
var _createLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
|
|
605
|
-
var _params$orderData, _params$orderData2, _params$orderData3, _params$orderData4, _params$orderData5, _params$cartSummary;
|
|
606
|
-
var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, isNeedDeposit, paymentOrder, updateAmountStartTime, updateAmountDuration;
|
|
607
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
608
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
609
|
-
case 0:
|
|
610
|
-
this.logInfo('createLocalOrderAsync called', {
|
|
611
|
-
orderDataType: (_params$orderData = params.orderData) === null || _params$orderData === void 0 ? void 0 : _params$orderData.type,
|
|
612
|
-
platform: (_params$orderData2 = params.orderData) === null || _params$orderData2 === void 0 ? void 0 : _params$orderData2.platform,
|
|
613
|
-
bookingsCount: ((_params$orderData3 = params.orderData) === null || _params$orderData3 === void 0 || (_params$orderData3 = _params$orderData3.bookings) === null || _params$orderData3 === void 0 ? void 0 : _params$orderData3.length) || 0,
|
|
614
|
-
relationProductsCount: ((_params$orderData4 = params.orderData) === null || _params$orderData4 === void 0 || (_params$orderData4 = _params$orderData4.relation_products) === null || _params$orderData4 === void 0 ? void 0 : _params$orderData4.length) || 0,
|
|
615
|
-
customerId: (_params$orderData5 = params.orderData) === null || _params$orderData5 === void 0 ? void 0 : _params$orderData5.customer_id,
|
|
616
|
-
autoPayment: params.autoPayment,
|
|
617
|
-
cartSummaryCount: ((_params$cartSummary = params.cartSummary) === null || _params$cartSummary === void 0 ? void 0 : _params$cartSummary.length) || 0,
|
|
618
|
-
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
619
|
-
});
|
|
620
|
-
_context9.prev = 1;
|
|
621
|
-
// 🔧 修改:在创建新订单前,直接重置 store 状态(同步执行)
|
|
622
|
-
this.resetStoreState();
|
|
623
|
-
// 验证订单数据
|
|
624
|
-
validation = validateLocalOrderData(params.orderData);
|
|
625
|
-
if (validation.valid) {
|
|
626
|
-
_context9.next = 6;
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
|
|
630
|
-
case 6:
|
|
631
|
-
// 生成本地虚拟订单ID (后续可以被真实订单ID替换)
|
|
632
|
-
localOrderId = generateLocalOrderId(); // 从购物车小计数据中提取金额信息
|
|
633
|
-
amountInfo = extractAmountFromCartSummary(params.cartSummary); // TODO: 外面传的是 pos ,但是现在 后端只有 shop 和 kiosk
|
|
634
|
-
params.orderData.platform = 'pos';
|
|
635
|
-
// 补充 created_at 时间 (YYYY-MM-DD hh:mm:ss 格式)
|
|
636
|
-
params.orderData.created_at = formatDateTime(new Date());
|
|
637
|
-
// 补充附加费信息
|
|
638
|
-
params.orderData.surcharge_fee = (_params$totalInfo = params.totalInfo) === null || _params$totalInfo === void 0 || (_params$totalInfo = _params$totalInfo.total) === null || _params$totalInfo === void 0 ? void 0 : _params$totalInfo.otherAmount;
|
|
639
|
-
params.orderData.surcharges = (_params$totalInfo2 = params.totalInfo) === null || _params$totalInfo2 === void 0 || (_params$totalInfo2 = _params$totalInfo2.total) === null || _params$totalInfo2 === void 0 ? void 0 : _params$totalInfo2.surcharge;
|
|
640
|
-
// 补充订单折扣信息
|
|
641
|
-
params.orderData.shop_discount = (_params$totalInfo3 = params.totalInfo) === null || _params$totalInfo3 === void 0 || (_params$totalInfo3 = _params$totalInfo3.total) === null || _params$totalInfo3 === void 0 ? void 0 : _params$totalInfo3.shopDiscount;
|
|
642
|
-
// 补充税费信息
|
|
643
|
-
params.orderData.tax_fee = (_params$totalInfo4 = params.totalInfo) === null || _params$totalInfo4 === void 0 || (_params$totalInfo4 = _params$totalInfo4.total) === null || _params$totalInfo4 === void 0 ? void 0 : _params$totalInfo4.tax;
|
|
644
|
-
|
|
645
|
-
// 保存原始订单数据和小计数据到状态中
|
|
646
|
-
this.store.localOrderData = params.orderData;
|
|
647
|
-
this.store.cartSummary = params.cartSummary;
|
|
648
|
-
|
|
649
|
-
// 提取并保存客户信息(如果有)
|
|
650
|
-
customerInfo = {
|
|
651
|
-
customer_id: params.orderData.customer_id,
|
|
652
|
-
customer_name: params.orderData.customer_name
|
|
653
|
-
}; // 只有在有客户信息时才存储
|
|
654
|
-
if (customerInfo.customer_id || customerInfo.customer_name) {
|
|
655
|
-
this.store.currentCustomer = customerInfo;
|
|
656
|
-
console.log('[Checkout] 保存客户信息:', customerInfo);
|
|
657
|
-
} else {
|
|
658
|
-
this.store.currentCustomer = undefined;
|
|
659
|
-
console.log('[Checkout] 未提供客户信息');
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
|
|
663
|
-
isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 创建支付订单对象
|
|
664
|
-
_context9.next = 21;
|
|
665
|
-
return this.payment.createPaymentOrderAsync({
|
|
666
|
-
order_id: localOrderId,
|
|
667
|
-
total_amount: amountInfo.totalAmount,
|
|
668
|
-
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
669
|
-
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : '0.00',
|
|
670
|
-
order_info: {
|
|
671
|
-
original_order_data: params.orderData,
|
|
672
|
-
cart_summary: params.cartSummary,
|
|
673
|
-
created_at: new Date().toISOString(),
|
|
674
|
-
platform: params.orderData.platform,
|
|
675
|
-
type: params.orderData.type,
|
|
676
|
-
schedule_date: params.orderData.schedule_date,
|
|
677
|
-
shop_note: params.orderData.shop_note,
|
|
678
|
-
amount_breakdown: amountInfo
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
case 21:
|
|
682
|
-
paymentOrder = _context9.sent;
|
|
683
|
-
this.store.currentOrder = paymentOrder;
|
|
684
|
-
|
|
685
|
-
// // 如果设置了自动支付,直接跳转到支付步骤
|
|
686
|
-
// if (params.autoPayment) {
|
|
687
|
-
// // 自动支付模式标记
|
|
688
|
-
// }
|
|
689
|
-
|
|
690
|
-
this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
691
|
-
order: paymentOrder,
|
|
692
|
-
timestamp: Date.now()
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
// 自动设置 stateAmount 为剩余未支付金额
|
|
696
|
-
// 🚀 性能监控:记录 updateStateAmountToRemaining 操作耗时
|
|
697
|
-
updateAmountStartTime = Date.now();
|
|
698
|
-
_context9.next = 27;
|
|
699
|
-
return this.updateStateAmountToRemaining(false);
|
|
700
|
-
case 27:
|
|
701
|
-
updateAmountDuration = Date.now() - updateAmountStartTime;
|
|
702
|
-
this.logInfo('updateStateAmountToRemaining operation completed', {
|
|
703
|
-
operation: 'updateStateAmountToRemaining',
|
|
704
|
-
orderUuid: paymentOrder.uuid,
|
|
705
|
-
orderId: paymentOrder.order_id,
|
|
706
|
-
duration: "".concat(updateAmountDuration, "ms"),
|
|
707
|
-
performance: updateAmountDuration > 200 ? 'slow' : updateAmountDuration > 100 ? 'medium' : 'fast'
|
|
708
|
-
});
|
|
709
|
-
this.logInfo('本地订单创建成功:', {
|
|
710
|
-
localOrderId: localOrderId,
|
|
711
|
-
uuid: paymentOrder.uuid,
|
|
712
|
-
totalAmount: amountInfo.totalAmount,
|
|
713
|
-
subTotal: amountInfo.subTotal,
|
|
714
|
-
taxAmount: amountInfo.taxAmount,
|
|
715
|
-
stateAmount: this.store.stateAmount
|
|
716
|
-
});
|
|
717
|
-
this.initWalletData();
|
|
718
|
-
return _context9.abrupt("return", paymentOrder);
|
|
719
|
-
case 34:
|
|
720
|
-
_context9.prev = 34;
|
|
721
|
-
_context9.t0 = _context9["catch"](1);
|
|
722
|
-
_context9.next = 38;
|
|
723
|
-
return this.handleError(_context9.t0, CheckoutErrorType.OrderCreationFailed);
|
|
724
|
-
case 38:
|
|
725
|
-
this.logError('本地订单创建失败:', _context9.t0);
|
|
726
|
-
this.core.effects.emit("".concat(this.name, ":onOrderCreationFailed"), {
|
|
727
|
-
error: this.store.lastError,
|
|
728
|
-
timestamp: Date.now()
|
|
729
|
-
});
|
|
730
|
-
throw _context9.t0;
|
|
731
|
-
case 41:
|
|
732
|
-
case "end":
|
|
733
|
-
return _context9.stop();
|
|
734
|
-
}
|
|
735
|
-
}, _callee9, this, [[1, 34]]);
|
|
736
|
-
}));
|
|
737
|
-
function createLocalOrderAsync(_x11) {
|
|
738
|
-
return _createLocalOrderAsync.apply(this, arguments);
|
|
739
|
-
}
|
|
740
|
-
return createLocalOrderAsync;
|
|
741
|
-
}()
|
|
742
|
-
/**
|
|
743
|
-
* 更新本地订单(已同步后端的订单)并设置为当前订单
|
|
744
|
-
*
|
|
745
|
-
* 通过传入真实的 orderId,对已缓存的订单数据进行更新,
|
|
746
|
-
* 会覆盖 order_info 与金额等字段,并重新计算待付金额,最后设置为 currentOrder。
|
|
747
|
-
*/
|
|
748
|
-
)
|
|
749
|
-
}, {
|
|
750
|
-
key: "updateLocalOrderAsync",
|
|
751
|
-
value: (function () {
|
|
752
|
-
var _updateLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
753
|
-
var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8;
|
|
754
|
-
var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, syncedAmount, remainingExpectAmount, depositDiffAmount, isNeedDeposit, created;
|
|
755
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
756
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
757
|
-
case 0:
|
|
758
|
-
this.logInfo('updateLocalOrderAsync called', {
|
|
759
|
-
orderId: params.orderId,
|
|
760
|
-
orderDataType: (_params$orderData6 = params.orderData) === null || _params$orderData6 === void 0 ? void 0 : _params$orderData6.type,
|
|
761
|
-
bookingsCount: ((_params$orderData7 = params.orderData) === null || _params$orderData7 === void 0 || (_params$orderData7 = _params$orderData7.bookings) === null || _params$orderData7 === void 0 ? void 0 : _params$orderData7.length) || 0,
|
|
762
|
-
cartSummaryCount: ((_params$cartSummary2 = params.cartSummary) === null || _params$cartSummary2 === void 0 ? void 0 : _params$cartSummary2.length) || 0,
|
|
763
|
-
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
// 基础校验
|
|
767
|
-
validation = validateLocalOrderData(params.orderData);
|
|
768
|
-
if (validation.valid) {
|
|
769
|
-
_context10.next = 4;
|
|
770
|
-
break;
|
|
771
|
-
}
|
|
772
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
|
|
773
|
-
case 4:
|
|
774
|
-
// 计算金额
|
|
775
|
-
amountInfo = extractAmountFromCartSummary(params.cartSummary); // 规范化补充字段
|
|
776
|
-
params.orderData.created_at = formatDateTime(new Date());
|
|
777
|
-
params.orderData.platform = 'pos';
|
|
778
|
-
params.orderData.surcharge_fee = (_params$totalInfo5 = params.totalInfo) === null || _params$totalInfo5 === void 0 || (_params$totalInfo5 = _params$totalInfo5.total) === null || _params$totalInfo5 === void 0 ? void 0 : _params$totalInfo5.otherAmount;
|
|
779
|
-
params.orderData.surcharges = (_params$totalInfo6 = params.totalInfo) === null || _params$totalInfo6 === void 0 || (_params$totalInfo6 = _params$totalInfo6.total) === null || _params$totalInfo6 === void 0 ? void 0 : _params$totalInfo6.surcharge;
|
|
780
|
-
params.orderData.shop_discount = (_params$totalInfo7 = params.totalInfo) === null || _params$totalInfo7 === void 0 || (_params$totalInfo7 = _params$totalInfo7.total) === null || _params$totalInfo7 === void 0 ? void 0 : _params$totalInfo7.shopDiscount;
|
|
781
|
-
params.orderData.tax_fee = (_params$totalInfo8 = params.totalInfo) === null || _params$totalInfo8 === void 0 || (_params$totalInfo8 = _params$totalInfo8.total) === null || _params$totalInfo8 === void 0 ? void 0 : _params$totalInfo8.tax;
|
|
782
|
-
|
|
783
|
-
// 持久化原始数据
|
|
784
|
-
this.store.localOrderData = params.orderData;
|
|
785
|
-
this.store.cartSummary = params.cartSummary;
|
|
786
|
-
|
|
787
|
-
// 同步客户信息
|
|
788
|
-
customerInfo = {
|
|
789
|
-
customer_id: params.orderData.customer_id,
|
|
790
|
-
customer_name: params.orderData.customer_name
|
|
791
|
-
};
|
|
792
|
-
if (customerInfo.customer_id || customerInfo.customer_name) {
|
|
793
|
-
this.store.currentCustomer = customerInfo;
|
|
794
|
-
} else {
|
|
795
|
-
this.store.currentCustomer = undefined;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
// 保留原有支付项:通过 orderId 找到现有订单(按 id 或 order_id 匹配)
|
|
799
|
-
_context10.next = 17;
|
|
800
|
-
return this.payment.getOrderListAsync();
|
|
801
|
-
case 17:
|
|
802
|
-
allOrders = _context10.sent;
|
|
803
|
-
existingOrder = allOrders.find(function (o) {
|
|
804
|
-
return String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId);
|
|
805
|
-
});
|
|
806
|
-
if (!existingOrder) {
|
|
807
|
-
_context10.next = 44;
|
|
808
|
-
break;
|
|
809
|
-
}
|
|
810
|
-
// 基于现有支付项计算新的 expect_amount
|
|
811
|
-
totalAmount = new Decimal(amountInfo.totalAmount || '0');
|
|
812
|
-
activePayments = (existingOrder.payment || []).filter(function (p) {
|
|
813
|
-
return p.status !== 'voided';
|
|
814
|
-
});
|
|
815
|
-
paidAmount = activePayments.reduce(function (sum, p) {
|
|
816
|
-
var amt = new Decimal(p.amount || '0');
|
|
817
|
-
var rounding = new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || '0').abs();
|
|
818
|
-
return sum.plus(amt).plus(rounding);
|
|
819
|
-
}, new Decimal(0));
|
|
820
|
-
remaining = Decimal.max(0, totalAmount.minus(paidAmount)).toFixed(2); // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
|
|
821
|
-
_isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 更新到支付模块(使用 uuid,不修改 payment 列表)
|
|
822
|
-
_context10.next = 27;
|
|
823
|
-
return this.payment.updateOrderAsync(existingOrder.uuid, {
|
|
824
|
-
total_amount: amountInfo.totalAmount,
|
|
825
|
-
is_deposit: _isNeedDeposit.hasDeposit ? 1 : 0,
|
|
826
|
-
deposit_amount: _isNeedDeposit.total ? _isNeedDeposit.total.toString() : '0.00',
|
|
827
|
-
expect_amount: remaining,
|
|
828
|
-
order_info: {
|
|
829
|
-
original_order_data: params.orderData,
|
|
830
|
-
cart_summary: params.cartSummary,
|
|
831
|
-
created_at: new Date().toISOString(),
|
|
832
|
-
platform: params.orderData.platform,
|
|
833
|
-
type: params.orderData.type,
|
|
834
|
-
schedule_date: params.orderData.schedule_date,
|
|
835
|
-
shop_note: params.orderData.shop_note,
|
|
836
|
-
amount_breakdown: amountInfo
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
case 27:
|
|
840
|
-
_context10.next = 29;
|
|
841
|
-
return this.payment.getPaymentOrderByUuidAsync(existingOrder.uuid);
|
|
842
|
-
case 29:
|
|
843
|
-
updated = _context10.sent;
|
|
844
|
-
if (updated) {
|
|
845
|
-
_context10.next = 32;
|
|
846
|
-
break;
|
|
847
|
-
}
|
|
848
|
-
throw createCheckoutError(CheckoutErrorType.UnknownError, '订单更新失败');
|
|
849
|
-
case 32:
|
|
850
|
-
this.store.currentOrder = updated;
|
|
851
|
-
_context10.next = 35;
|
|
852
|
-
return this.updateStateAmountToRemaining(false);
|
|
853
|
-
case 35:
|
|
854
|
-
this.logInfo('本地订单更新成功(保留支付项):', {
|
|
855
|
-
orderId: params.orderId,
|
|
856
|
-
uuid: updated.uuid,
|
|
857
|
-
payments: ((_updated$payment = updated.payment) === null || _updated$payment === void 0 ? void 0 : _updated$payment.length) || 0,
|
|
858
|
-
totalAmount: updated.total_amount,
|
|
859
|
-
expectAmount: updated.expect_amount
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
// 事件通知(复用创建事件,便于上层监听刷新)
|
|
863
|
-
_context10.next = 38;
|
|
864
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
865
|
-
order: updated,
|
|
866
|
-
timestamp: Date.now()
|
|
867
|
-
});
|
|
868
|
-
case 38:
|
|
869
|
-
// 需要减去已经同步给后端的支付过的钱
|
|
870
|
-
syncedAmount = activePayments.reduce(function (sum, p) {
|
|
871
|
-
var amt = new Decimal(p.amount || '0');
|
|
872
|
-
var rounding = new Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || '0').abs();
|
|
873
|
-
return sum.plus(amt).plus(rounding);
|
|
874
|
-
}, new Decimal(0));
|
|
875
|
-
remainingExpectAmount = Decimal.max(0, totalAmount.minus(syncedAmount)).toFixed(2); // 要计算一个总价的差值和一个定金的差值,如果定金的差值>0,则需要使用定金的差值,否则使用总价的差值
|
|
876
|
-
depositDiffAmount = new Decimal(0).toFixed(2);
|
|
877
|
-
if (updated.is_deposit === 1) {
|
|
878
|
-
depositDiffAmount = new Decimal(updated.deposit_amount).minus(syncedAmount).toFixed(2);
|
|
879
|
-
}
|
|
880
|
-
this.initWalletData({
|
|
881
|
-
order_wait_pay_amount: Number(depositDiffAmount) > 0 ? Number(depositDiffAmount) : Number(remainingExpectAmount)
|
|
882
|
-
});
|
|
883
|
-
return _context10.abrupt("return", updated);
|
|
884
|
-
case 44:
|
|
885
|
-
// 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
|
|
886
|
-
isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 没找到现有订单时,回退为创建逻辑(用于异常兜底)
|
|
887
|
-
_context10.next = 47;
|
|
888
|
-
return this.payment.createPaymentOrderAsync({
|
|
889
|
-
order_id: String(params.orderId),
|
|
890
|
-
total_amount: amountInfo.totalAmount,
|
|
891
|
-
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
892
|
-
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : '0.00',
|
|
893
|
-
order_info: {
|
|
894
|
-
original_order_data: params.orderData,
|
|
895
|
-
cart_summary: params.cartSummary,
|
|
896
|
-
created_at: new Date().toISOString(),
|
|
897
|
-
platform: params.orderData.platform,
|
|
898
|
-
type: params.orderData.type,
|
|
899
|
-
schedule_date: params.orderData.schedule_date,
|
|
900
|
-
shop_note: params.orderData.shop_note,
|
|
901
|
-
amount_breakdown: amountInfo
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
case 47:
|
|
905
|
-
created = _context10.sent;
|
|
906
|
-
this.store.currentOrder = created;
|
|
907
|
-
this.initWalletData();
|
|
908
|
-
return _context10.abrupt("return", created);
|
|
909
|
-
case 51:
|
|
910
|
-
case "end":
|
|
911
|
-
return _context10.stop();
|
|
912
|
-
}
|
|
913
|
-
}, _callee10, this);
|
|
914
|
-
}));
|
|
915
|
-
function updateLocalOrderAsync(_x12) {
|
|
916
|
-
return _updateLocalOrderAsync.apply(this, arguments);
|
|
917
|
-
}
|
|
918
|
-
return updateLocalOrderAsync;
|
|
919
|
-
}()
|
|
920
|
-
/**
|
|
921
|
-
* 完成结账
|
|
922
|
-
*/
|
|
923
|
-
)
|
|
924
|
-
}, {
|
|
925
|
-
key: "completeCheckoutAsync",
|
|
926
|
-
value: (function () {
|
|
927
|
-
var _completeCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
928
|
-
var order;
|
|
929
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
930
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
931
|
-
case 0:
|
|
932
|
-
_context11.prev = 0;
|
|
933
|
-
if (this.store.currentOrder) {
|
|
934
|
-
_context11.next = 3;
|
|
935
|
-
break;
|
|
936
|
-
}
|
|
937
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单');
|
|
938
|
-
case 3:
|
|
939
|
-
_context11.next = 5;
|
|
940
|
-
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
941
|
-
case 5:
|
|
942
|
-
order = _context11.sent;
|
|
943
|
-
if (!(!order || order.payment_status !== PaymentStatus.Finished)) {
|
|
944
|
-
_context11.next = 8;
|
|
945
|
-
break;
|
|
946
|
-
}
|
|
947
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '订单支付未完成,无法完成结账');
|
|
948
|
-
case 8:
|
|
949
|
-
// 清理钱包模块的所有缓存数据
|
|
950
|
-
this.payment.wallet.clearAllCache();
|
|
951
|
-
_context11.next = 11;
|
|
952
|
-
return this.core.effects.emit("".concat(this.name, ":onCheckoutCompleted"), {
|
|
953
|
-
orderId: order.id,
|
|
954
|
-
timestamp: Date.now()
|
|
955
|
-
});
|
|
956
|
-
case 11:
|
|
957
|
-
console.log('[Checkout] 结账流程完成:', order.id);
|
|
958
|
-
|
|
959
|
-
// 🔧 新增:自动重置 store 状态(同步执行)
|
|
960
|
-
this.resetStoreState();
|
|
961
|
-
return _context11.abrupt("return", {
|
|
962
|
-
success: true,
|
|
963
|
-
orderId: String(order.id)
|
|
964
|
-
});
|
|
965
|
-
case 16:
|
|
966
|
-
_context11.prev = 16;
|
|
967
|
-
_context11.t0 = _context11["catch"](0);
|
|
968
|
-
_context11.next = 20;
|
|
969
|
-
return this.handleError(_context11.t0, CheckoutErrorType.UnknownError);
|
|
970
|
-
case 20:
|
|
971
|
-
return _context11.abrupt("return", {
|
|
972
|
-
success: false
|
|
973
|
-
});
|
|
974
|
-
case 21:
|
|
975
|
-
case "end":
|
|
976
|
-
return _context11.stop();
|
|
977
|
-
}
|
|
978
|
-
}, _callee11, this, [[0, 16]]);
|
|
979
|
-
}));
|
|
980
|
-
function completeCheckoutAsync() {
|
|
981
|
-
return _completeCheckoutAsync.apply(this, arguments);
|
|
982
|
-
}
|
|
983
|
-
return completeCheckoutAsync;
|
|
984
|
-
}()
|
|
985
|
-
/**
|
|
986
|
-
* 获取订单原始数据
|
|
987
|
-
*/
|
|
988
|
-
)
|
|
989
|
-
}, {
|
|
990
|
-
key: "getOrderOriginalData",
|
|
991
|
-
value: function getOrderOriginalData() {
|
|
992
|
-
var _this$store$currentOr8;
|
|
993
|
-
return (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_info;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* 获取当前订单基础信息
|
|
998
|
-
*
|
|
999
|
-
* 返回当前订单的基础信息,包括订单状态、金额、支付状态等
|
|
1000
|
-
*/
|
|
1001
|
-
}, {
|
|
1002
|
-
key: "getCurrentOrderInfo",
|
|
1003
|
-
value: function getCurrentOrderInfo() {
|
|
1004
|
-
try {
|
|
1005
|
-
var _this$store = this.store,
|
|
1006
|
-
_currentOrder = _this$store.currentOrder,
|
|
1007
|
-
cartItems = _this$store.cartItems,
|
|
1008
|
-
localOrderData = _this$store.localOrderData;
|
|
1009
|
-
if (!_currentOrder) {
|
|
1010
|
-
console.log('[Checkout] 当前没有活跃订单');
|
|
1011
|
-
return null;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
// 从本地订单数据或订单信息中提取基础信息
|
|
1015
|
-
var orderInfo = _currentOrder.order_info || {};
|
|
1016
|
-
var createdAt = orderInfo.created_at || new Date().toISOString();
|
|
1017
|
-
var orderType = (localOrderData === null || localOrderData === void 0 ? void 0 : localOrderData.type) || orderInfo.type || 'virtual';
|
|
1018
|
-
var platform = (localOrderData === null || localOrderData === void 0 ? void 0 : localOrderData.platform) || orderInfo.platform || 'pc';
|
|
1019
|
-
var result = {
|
|
1020
|
-
uuid: _currentOrder.uuid,
|
|
1021
|
-
orderId: _currentOrder.order_id,
|
|
1022
|
-
totalAmount: _currentOrder.total_amount,
|
|
1023
|
-
remainingAmount: _currentOrder.expect_amount,
|
|
1024
|
-
paymentStatus: _currentOrder.payment_status,
|
|
1025
|
-
isDeposit: Boolean(_currentOrder.is_deposit),
|
|
1026
|
-
depositAmount: _currentOrder.deposit_amount,
|
|
1027
|
-
orderType: orderType,
|
|
1028
|
-
platform: platform,
|
|
1029
|
-
createdAt: createdAt,
|
|
1030
|
-
itemCount: cartItems.length,
|
|
1031
|
-
hasLocalOrderData: Boolean(localOrderData)
|
|
1032
|
-
};
|
|
1033
|
-
return result;
|
|
1034
|
-
} catch (error) {
|
|
1035
|
-
console.error('[Checkout] 获取当前订单基础信息失败:', error);
|
|
1036
|
-
return null;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* 获取当前订单的支付项
|
|
1042
|
-
*
|
|
1043
|
-
* 返回当前订单的所有支付项,包括活跃和已撤销的支付项
|
|
1044
|
-
*/
|
|
1045
|
-
}, {
|
|
1046
|
-
key: "getCurrentOrderPaymentItemsAsync",
|
|
1047
|
-
value: (function () {
|
|
1048
|
-
var _getCurrentOrderPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
1049
|
-
var _currentOrder2, paymentItems;
|
|
1050
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1051
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
1052
|
-
case 0:
|
|
1053
|
-
_context12.prev = 0;
|
|
1054
|
-
_currentOrder2 = this.store.currentOrder;
|
|
1055
|
-
if (_currentOrder2) {
|
|
1056
|
-
_context12.next = 5;
|
|
1057
|
-
break;
|
|
1058
|
-
}
|
|
1059
|
-
console.log('[Checkout] 当前没有活跃订单,无法获取支付项');
|
|
1060
|
-
return _context12.abrupt("return", []);
|
|
1061
|
-
case 5:
|
|
1062
|
-
_context12.next = 7;
|
|
1063
|
-
return this.payment.getPaymentItemsAsync(_currentOrder2.uuid);
|
|
1064
|
-
case 7:
|
|
1065
|
-
paymentItems = _context12.sent;
|
|
1066
|
-
return _context12.abrupt("return", paymentItems);
|
|
1067
|
-
case 11:
|
|
1068
|
-
_context12.prev = 11;
|
|
1069
|
-
_context12.t0 = _context12["catch"](0);
|
|
1070
|
-
console.error('[Checkout] 获取当前订单支付项失败:', _context12.t0);
|
|
1071
|
-
return _context12.abrupt("return", []);
|
|
1072
|
-
case 15:
|
|
1073
|
-
case "end":
|
|
1074
|
-
return _context12.stop();
|
|
1075
|
-
}
|
|
1076
|
-
}, _callee12, this, [[0, 11]]);
|
|
1077
|
-
}));
|
|
1078
|
-
function getCurrentOrderPaymentItemsAsync() {
|
|
1079
|
-
return _getCurrentOrderPaymentItemsAsync.apply(this, arguments);
|
|
1080
|
-
}
|
|
1081
|
-
return getCurrentOrderPaymentItemsAsync;
|
|
1082
|
-
}()
|
|
1083
|
-
/**
|
|
1084
|
-
* 获取订单模块
|
|
1085
|
-
*/
|
|
1086
|
-
)
|
|
1087
|
-
}, {
|
|
1088
|
-
key: "getOrderModule",
|
|
1089
|
-
value: function getOrderModule() {
|
|
1090
|
-
return this.order;
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
/**
|
|
1094
|
-
* 获取支付模块
|
|
1095
|
-
*/
|
|
1096
|
-
}, {
|
|
1097
|
-
key: "getPaymentModule",
|
|
1098
|
-
value: function getPaymentModule() {
|
|
1099
|
-
return this.payment;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
/**
|
|
1103
|
-
* 替换本地订单ID为真实订单ID
|
|
1104
|
-
*
|
|
1105
|
-
* 当后端订单创建完成后,调用此方法将本地虚拟订单ID替换为真实订单ID
|
|
1106
|
-
*
|
|
1107
|
-
* @param newOrderId 后端返回的真实订单ID
|
|
1108
|
-
* @returns 更新后的订单对象,如果当前没有订单则返回null
|
|
1109
|
-
*/
|
|
1110
|
-
}, {
|
|
1111
|
-
key: "replaceLocalOrderIdAsync",
|
|
1112
|
-
value: (function () {
|
|
1113
|
-
var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(newOrderId) {
|
|
1114
|
-
var updatedOrder;
|
|
1115
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1116
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
1117
|
-
case 0:
|
|
1118
|
-
_context13.prev = 0;
|
|
1119
|
-
if (this.store.currentOrder) {
|
|
1120
|
-
_context13.next = 4;
|
|
1121
|
-
break;
|
|
1122
|
-
}
|
|
1123
|
-
console.warn('[Checkout] 没有当前订单,无法替换订单ID');
|
|
1124
|
-
return _context13.abrupt("return", null);
|
|
1125
|
-
case 4:
|
|
1126
|
-
_context13.next = 6;
|
|
1127
|
-
return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, newOrderId);
|
|
1128
|
-
case 6:
|
|
1129
|
-
updatedOrder = _context13.sent;
|
|
1130
|
-
if (!updatedOrder) {
|
|
1131
|
-
_context13.next = 15;
|
|
1132
|
-
break;
|
|
1133
|
-
}
|
|
1134
|
-
// 更新当前订单引用
|
|
1135
|
-
this.store.currentOrder = updatedOrder;
|
|
1136
|
-
|
|
1137
|
-
// 触发订单更新事件
|
|
1138
|
-
_context13.next = 11;
|
|
1139
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
1140
|
-
order: updatedOrder,
|
|
1141
|
-
timestamp: Date.now()
|
|
1142
|
-
});
|
|
1143
|
-
case 11:
|
|
1144
|
-
console.log('[Checkout] 本地订单ID替换成功:', {
|
|
1145
|
-
uuid: updatedOrder.uuid,
|
|
1146
|
-
newOrderId: updatedOrder.id
|
|
1147
|
-
});
|
|
1148
|
-
|
|
1149
|
-
// 标记订单已同步(替换ID意味着订单已在后端创建)
|
|
1150
|
-
this.store.isOrderSynced = true;
|
|
1151
|
-
|
|
1152
|
-
// 订单ID替换后更新 stateAmount
|
|
1153
|
-
_context13.next = 15;
|
|
1154
|
-
return this.updateStateAmountToRemaining(false);
|
|
1155
|
-
case 15:
|
|
1156
|
-
return _context13.abrupt("return", updatedOrder);
|
|
1157
|
-
case 18:
|
|
1158
|
-
_context13.prev = 18;
|
|
1159
|
-
_context13.t0 = _context13["catch"](0);
|
|
1160
|
-
console.error('[Checkout] 替换订单ID失败:', _context13.t0);
|
|
1161
|
-
_context13.next = 23;
|
|
1162
|
-
return this.handleError(_context13.t0, CheckoutErrorType.UnknownError);
|
|
1163
|
-
case 23:
|
|
1164
|
-
return _context13.abrupt("return", null);
|
|
1165
|
-
case 24:
|
|
1166
|
-
case "end":
|
|
1167
|
-
return _context13.stop();
|
|
1168
|
-
}
|
|
1169
|
-
}, _callee13, this, [[0, 18]]);
|
|
1170
|
-
}));
|
|
1171
|
-
function replaceLocalOrderIdAsync(_x13) {
|
|
1172
|
-
return _replaceLocalOrderIdAsync.apply(this, arguments);
|
|
1173
|
-
}
|
|
1174
|
-
return replaceLocalOrderIdAsync;
|
|
1175
|
-
}()
|
|
1176
|
-
/**
|
|
1177
|
-
* 设置自定义支付金额
|
|
1178
|
-
*
|
|
1179
|
-
* 允许UI自定义本次支付的金额,通常用于部分支付或调整支付金额场景
|
|
1180
|
-
*
|
|
1181
|
-
* @param amount 自定义支付金额,必须是有效的数字字符串
|
|
1182
|
-
*/
|
|
1183
|
-
)
|
|
1184
|
-
}, {
|
|
1185
|
-
key: "setStateAmountAsync",
|
|
1186
|
-
value: (function () {
|
|
1187
|
-
var _setStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(amount) {
|
|
1188
|
-
var numAmount, oldAmount, formattedAmount, errorMessage;
|
|
1189
|
-
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1190
|
-
while (1) switch (_context14.prev = _context14.next) {
|
|
1191
|
-
case 0:
|
|
1192
|
-
_context14.prev = 0;
|
|
1193
|
-
// 验证金额格式
|
|
1194
|
-
numAmount = parseFloat(amount);
|
|
1195
|
-
if (!(isNaN(numAmount) || numAmount < 0)) {
|
|
1196
|
-
_context14.next = 4;
|
|
1197
|
-
break;
|
|
1198
|
-
}
|
|
1199
|
-
throw new Error("\u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(amount));
|
|
1200
|
-
case 4:
|
|
1201
|
-
oldAmount = this.store.stateAmount;
|
|
1202
|
-
formattedAmount = numAmount.toFixed(2); // 如果金额没有变化,直接返回
|
|
1203
|
-
if (!(oldAmount === formattedAmount)) {
|
|
1204
|
-
_context14.next = 8;
|
|
1205
|
-
break;
|
|
1206
|
-
}
|
|
1207
|
-
return _context14.abrupt("return");
|
|
1208
|
-
case 8:
|
|
1209
|
-
this.logInfo('[Checkout] 设置自定义支付金额:', {
|
|
1210
|
-
oldAmount: oldAmount,
|
|
1211
|
-
newAmount: formattedAmount
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
// 更新状态
|
|
1215
|
-
this.store.stateAmount = formattedAmount;
|
|
1216
|
-
|
|
1217
|
-
// 触发金额变更事件
|
|
1218
|
-
_context14.next = 12;
|
|
1219
|
-
return this.core.effects.emit("".concat(this.name, ":onStateAmountChanged"), {
|
|
1220
|
-
oldAmount: oldAmount,
|
|
1221
|
-
newAmount: formattedAmount,
|
|
1222
|
-
timestamp: Date.now()
|
|
1223
|
-
});
|
|
1224
|
-
case 12:
|
|
1225
|
-
_context14.next = 21;
|
|
1226
|
-
break;
|
|
1227
|
-
case 14:
|
|
1228
|
-
_context14.prev = 14;
|
|
1229
|
-
_context14.t0 = _context14["catch"](0);
|
|
1230
|
-
errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : '设置支付金额失败';
|
|
1231
|
-
console.error('[Checkout] 设置自定义支付金额失败:', errorMessage);
|
|
1232
|
-
_context14.next = 20;
|
|
1233
|
-
return this.handleError(new Error(errorMessage), CheckoutErrorType.ValidationFailed);
|
|
1234
|
-
case 20:
|
|
1235
|
-
throw _context14.t0;
|
|
1236
|
-
case 21:
|
|
1237
|
-
case "end":
|
|
1238
|
-
return _context14.stop();
|
|
1239
|
-
}
|
|
1240
|
-
}, _callee14, this, [[0, 14]]);
|
|
1241
|
-
}));
|
|
1242
|
-
function setStateAmountAsync(_x14) {
|
|
1243
|
-
return _setStateAmountAsync.apply(this, arguments);
|
|
1244
|
-
}
|
|
1245
|
-
return setStateAmountAsync;
|
|
1246
|
-
}()
|
|
1247
|
-
/**
|
|
1248
|
-
* 获取当前自定义支付金额
|
|
1249
|
-
*
|
|
1250
|
-
* @returns 当前设置的自定义支付金额
|
|
1251
|
-
*/
|
|
1252
|
-
)
|
|
1253
|
-
}, {
|
|
1254
|
-
key: "getStateAmount",
|
|
1255
|
-
value: function getStateAmount() {
|
|
1256
|
-
return this.store.stateAmount;
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* 获取系统计算的待付金额(只读)
|
|
1261
|
-
*
|
|
1262
|
-
* 此方法返回系统内部计算的实际待付金额,不允许外部修改
|
|
1263
|
-
*
|
|
1264
|
-
* @returns 当前系统计算的待付金额
|
|
1265
|
-
*/
|
|
1266
|
-
}, {
|
|
1267
|
-
key: "getBalanceDueAmount",
|
|
1268
|
-
value: function getBalanceDueAmount() {
|
|
1269
|
-
return this.store.balanceDueAmount;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
/**
|
|
1273
|
-
* 获取购物车小计数据
|
|
1274
|
-
*
|
|
1275
|
-
* 返回当前结账流程中的购物车小计项数据,包含各种费用明细
|
|
1276
|
-
*
|
|
1277
|
-
* @returns 购物车小计数据数组,如果没有则返回 null
|
|
1278
|
-
*/
|
|
1279
|
-
}, {
|
|
1280
|
-
key: "getCartSummary",
|
|
1281
|
-
value: function getCartSummary() {
|
|
1282
|
-
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
1283
|
-
console.warn('[Checkout] 没有可用的购物车小计数据');
|
|
1284
|
-
return null;
|
|
1285
|
-
}
|
|
1286
|
-
this.logInfo('获取购物车小计数据:', {
|
|
1287
|
-
itemCount: this.store.cartSummary.length,
|
|
1288
|
-
items: this.store.cartSummary.map(function (item) {
|
|
1289
|
-
return {
|
|
1290
|
-
key: item.key,
|
|
1291
|
-
value: item.value,
|
|
1292
|
-
label: item.label
|
|
1293
|
-
};
|
|
1294
|
-
})
|
|
1295
|
-
});
|
|
1296
|
-
return _toConsumableArray(this.store.cartSummary); // 返回副本,避免外部修改
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
/**
|
|
1300
|
-
* 获取支付方式列表
|
|
1301
|
-
*
|
|
1302
|
-
* 优先使用 store 中的缓存数据,避免重复接口调用。
|
|
1303
|
-
* 如果 store 中没有数据,则调用 Payment 模块的方法获取。
|
|
1304
|
-
*
|
|
1305
|
-
* @returns 支付方式列表
|
|
1306
|
-
*/
|
|
1307
|
-
}, {
|
|
1308
|
-
key: "getPaymentMethodsAsync",
|
|
1309
|
-
value: (function () {
|
|
1310
|
-
var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
1311
|
-
var methods;
|
|
1312
|
-
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1313
|
-
while (1) switch (_context15.prev = _context15.next) {
|
|
1314
|
-
case 0:
|
|
1315
|
-
if (!(this.store.paymentMethods && this.store.paymentMethods.length > 0)) {
|
|
1316
|
-
_context15.next = 3;
|
|
1317
|
-
break;
|
|
1318
|
-
}
|
|
1319
|
-
this.logInfo("\u4F7F\u7528\u7F13\u5B58\u7684\u652F\u4ED8\u65B9\u5F0F\u6570\u636E\uFF0C\u5171 ".concat(this.store.paymentMethods.length, " \u79CD"));
|
|
1320
|
-
return _context15.abrupt("return", this.store.paymentMethods);
|
|
1321
|
-
case 3:
|
|
1322
|
-
// 如果缓存为空,调用 Payment 模块获取
|
|
1323
|
-
this.logInfo('store 中无缓存,从 Payment 模块获取支付方式...');
|
|
1324
|
-
_context15.prev = 4;
|
|
1325
|
-
_context15.next = 7;
|
|
1326
|
-
return this.payment.getPayMethodListAsync();
|
|
1327
|
-
case 7:
|
|
1328
|
-
methods = _context15.sent;
|
|
1329
|
-
// 更新缓存
|
|
1330
|
-
this.store.paymentMethods = methods;
|
|
1331
|
-
this.logInfo("\u4ECE Payment \u6A21\u5757\u83B7\u53D6\u5230 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F\uFF0C\u5DF2\u66F4\u65B0\u7F13\u5B58"));
|
|
1332
|
-
return _context15.abrupt("return", methods);
|
|
1333
|
-
case 13:
|
|
1334
|
-
_context15.prev = 13;
|
|
1335
|
-
_context15.t0 = _context15["catch"](4);
|
|
1336
|
-
this.logError('获取支付方式失败:', _context15.t0);
|
|
1337
|
-
return _context15.abrupt("return", []);
|
|
1338
|
-
case 17:
|
|
1339
|
-
case "end":
|
|
1340
|
-
return _context15.stop();
|
|
1341
|
-
}
|
|
1342
|
-
}, _callee15, this, [[4, 13]]);
|
|
1343
|
-
}));
|
|
1344
|
-
function getPaymentMethodsAsync() {
|
|
1345
|
-
return _getPaymentMethodsAsync.apply(this, arguments);
|
|
1346
|
-
}
|
|
1347
|
-
return getPaymentMethodsAsync;
|
|
1348
|
-
}()
|
|
1349
|
-
/**
|
|
1350
|
-
* 为当前订单添加支付项
|
|
1351
|
-
*
|
|
1352
|
-
* 向当前活跃订单添加一个支付项,支付项包含支付方式信息和金额
|
|
1353
|
-
*
|
|
1354
|
-
* @param paymentItem 支付项数据
|
|
1355
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1356
|
-
*/
|
|
1357
|
-
)
|
|
1358
|
-
}, {
|
|
1359
|
-
key: "addPaymentItemAsync",
|
|
1360
|
-
value: (function () {
|
|
1361
|
-
var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentItem) {
|
|
1362
|
-
var orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type, _paymentItem$code, isEftposPayment, _isCashPayment, isCustomePayment, syncResult;
|
|
1363
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1364
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
1365
|
-
case 0:
|
|
1366
|
-
this.logInfo('addPaymentItemAsync called', paymentItem);
|
|
1367
|
-
_context16.prev = 1;
|
|
1368
|
-
if (this.store.currentOrder) {
|
|
1369
|
-
_context16.next = 4;
|
|
1370
|
-
break;
|
|
1371
|
-
}
|
|
1372
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
|
|
1373
|
-
case 4:
|
|
1374
|
-
// 根据当前订单的定金状态设置订单支付类型
|
|
1375
|
-
orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 处理现金支付的找零逻辑
|
|
1376
|
-
_context16.next = 7;
|
|
1377
|
-
return this.processCashPaymentItem(paymentItem);
|
|
1378
|
-
case 7:
|
|
1379
|
-
processedPaymentItem = _context16.sent;
|
|
1380
|
-
// 从 otherParams 获取 metadata 字段
|
|
1381
|
-
metadata = _objectSpread(_objectSpread({}, processedPaymentItem.metadata), {}, {
|
|
1382
|
-
rounding_rule: this.otherParams.order_rounding_setting,
|
|
1383
|
-
shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
|
|
1384
|
-
}); // 设置支付项的订单支付类型和 metadata
|
|
1385
|
-
paymentItemWithType = _objectSpread(_objectSpread({}, processedPaymentItem), {}, {
|
|
1386
|
-
order_payment_type: orderPaymentType,
|
|
1387
|
-
metadata: metadata
|
|
1388
|
-
}); // 添加支付项到订单
|
|
1389
|
-
_context16.next = 12;
|
|
1390
|
-
return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItemWithType);
|
|
1391
|
-
case 12:
|
|
1392
|
-
this.logInfo('支付项添加成功');
|
|
1393
|
-
|
|
1394
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1395
|
-
this.clearCalculationCache();
|
|
1396
|
-
|
|
1397
|
-
// 支付项添加后,更新 stateAmount 为剩余未支付金额
|
|
1398
|
-
_context16.next = 16;
|
|
1399
|
-
return this.updateStateAmountToRemaining();
|
|
1400
|
-
case 16:
|
|
1401
|
-
_context16.next = 18;
|
|
1402
|
-
return this.calculateRemainingAmountAsync();
|
|
1403
|
-
case 18:
|
|
1404
|
-
remainingAmount = _context16.sent;
|
|
1405
|
-
if (!(Number(remainingAmount) > 0)) {
|
|
1406
|
-
_context16.next = 39;
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
|
|
1410
|
-
// 检查是否是 EFTPOS 支付,如果是则立即同步订单
|
|
1411
|
-
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'));
|
|
1412
|
-
_isCashPayment = paymentItem.code === 'CASHMANUAL';
|
|
1413
|
-
isCustomePayment = paymentItem.type === 'custom';
|
|
1414
|
-
this.logInfo('EFTPOS 支付检查:', {
|
|
1415
|
-
paymentCode: paymentItem.code,
|
|
1416
|
-
paymentType: paymentItem.type,
|
|
1417
|
-
isEftposPayment: isEftposPayment,
|
|
1418
|
-
currentOrderSynced: this.store.isOrderSynced
|
|
1419
|
-
});
|
|
1420
|
-
if (!(isEftposPayment || _isCashPayment || isCustomePayment)) {
|
|
1421
|
-
_context16.next = 39;
|
|
1422
|
-
break;
|
|
1423
|
-
}
|
|
1424
|
-
this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
|
|
1425
|
-
_context16.prev = 27;
|
|
1426
|
-
_context16.next = 30;
|
|
1427
|
-
return this.syncOrderToBackendWithReturn(true);
|
|
1428
|
-
case 30:
|
|
1429
|
-
syncResult = _context16.sent;
|
|
1430
|
-
this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
|
|
1431
|
-
orderId: syncResult.orderId,
|
|
1432
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
1433
|
-
backendResponse: syncResult.response
|
|
1434
|
-
});
|
|
1435
|
-
_context16.next = 39;
|
|
1436
|
-
break;
|
|
1437
|
-
case 34:
|
|
1438
|
-
_context16.prev = 34;
|
|
1439
|
-
_context16.t0 = _context16["catch"](27);
|
|
1440
|
-
this.logError('EFTPOS 支付后订单同步失败:', _context16.t0);
|
|
1441
|
-
// 不抛出错误,避免影响支付流程,但记录错误
|
|
1442
|
-
_context16.next = 39;
|
|
1443
|
-
return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0))), CheckoutErrorType.OrderCreationFailed);
|
|
1444
|
-
case 39:
|
|
1445
|
-
// 触发支付项添加事件(可以复用支付开始事件)
|
|
1446
|
-
this.core.effects.emit("".concat(this.name, ":onPaymentItemAdded"), {
|
|
1447
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1448
|
-
paymentMethodCode: paymentItem.code,
|
|
1449
|
-
paymentMethodName: paymentItem.name,
|
|
1450
|
-
amount: String(paymentItem.amount),
|
|
1451
|
-
timestamp: Date.now()
|
|
1452
|
-
});
|
|
1453
|
-
_context16.next = 48;
|
|
1454
|
-
break;
|
|
1455
|
-
case 42:
|
|
1456
|
-
_context16.prev = 42;
|
|
1457
|
-
_context16.t1 = _context16["catch"](1);
|
|
1458
|
-
this.logError('添加支付项失败:', _context16.t1);
|
|
1459
|
-
_context16.next = 47;
|
|
1460
|
-
return this.handleError(_context16.t1, CheckoutErrorType.PaymentFailed);
|
|
1461
|
-
case 47:
|
|
1462
|
-
throw _context16.t1;
|
|
1463
|
-
case 48:
|
|
1464
|
-
case "end":
|
|
1465
|
-
return _context16.stop();
|
|
1466
|
-
}
|
|
1467
|
-
}, _callee16, this, [[1, 42], [27, 34]]);
|
|
1468
|
-
}));
|
|
1469
|
-
function addPaymentItemAsync(_x15) {
|
|
1470
|
-
return _addPaymentItemAsync.apply(this, arguments);
|
|
1471
|
-
}
|
|
1472
|
-
return addPaymentItemAsync;
|
|
1473
|
-
}()
|
|
1474
|
-
/**
|
|
1475
|
-
* 删除当前订单的支付项
|
|
1476
|
-
*
|
|
1477
|
-
* 从当前活跃订单中删除指定的支付项,支付项将被标记为已撤销状态
|
|
1478
|
-
*
|
|
1479
|
-
* @param paymentUuid 要删除的支付项UUID
|
|
1480
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1481
|
-
* @throws 支付项不存在时抛出错误
|
|
1482
|
-
*/
|
|
1483
|
-
)
|
|
1484
|
-
}, {
|
|
1485
|
-
key: "deletePaymentItemAsync",
|
|
1486
|
-
value: (function () {
|
|
1487
|
-
var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(paymentUuid) {
|
|
1488
|
-
var currentPayments, paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
|
|
1489
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1490
|
-
while (1) switch (_context17.prev = _context17.next) {
|
|
1491
|
-
case 0:
|
|
1492
|
-
_context17.prev = 0;
|
|
1493
|
-
if (this.store.currentOrder) {
|
|
1494
|
-
_context17.next = 3;
|
|
1495
|
-
break;
|
|
1496
|
-
}
|
|
1497
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法删除支付项');
|
|
1498
|
-
case 3:
|
|
1499
|
-
this.logWarning('开始删除支付项:', {
|
|
1500
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1501
|
-
paymentUuid: paymentUuid
|
|
1502
|
-
});
|
|
1503
|
-
|
|
1504
|
-
// 从 Payment 模块验证支付项是否存在
|
|
1505
|
-
_context17.next = 6;
|
|
1506
|
-
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, true // 包括已撤销的支付项,因为我们需要验证是否存在
|
|
1507
|
-
);
|
|
1508
|
-
case 6:
|
|
1509
|
-
currentPayments = _context17.sent;
|
|
1510
|
-
paymentItem = currentPayments.find(function (p) {
|
|
1511
|
-
return p.uuid === paymentUuid;
|
|
1512
|
-
});
|
|
1513
|
-
if (paymentItem) {
|
|
1514
|
-
_context17.next = 10;
|
|
1515
|
-
break;
|
|
1516
|
-
}
|
|
1517
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
|
|
1518
|
-
case 10:
|
|
1519
|
-
this.logInfo('找到要删除的支付项:', {
|
|
1520
|
-
uuid: paymentItem.uuid,
|
|
1521
|
-
code: paymentItem.code,
|
|
1522
|
-
amount: paymentItem.amount,
|
|
1523
|
-
status: paymentItem.status
|
|
1524
|
-
});
|
|
1525
|
-
|
|
1526
|
-
// 调用 Payment 模块删除支付项
|
|
1527
|
-
_context17.next = 13;
|
|
1528
|
-
return this.payment.deletePaymentAsync(this.store.currentOrder.uuid, paymentUuid);
|
|
1529
|
-
case 13:
|
|
1530
|
-
this.logInfo('Payment支付项删除完成', paymentItem);
|
|
1531
|
-
|
|
1532
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1533
|
-
this.clearCalculationCache();
|
|
1534
|
-
|
|
1535
|
-
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1536
|
-
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1537
|
-
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1538
|
-
_context17.next = 19;
|
|
1539
|
-
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1540
|
-
case 19:
|
|
1541
|
-
updatedOrder = _context17.sent;
|
|
1542
|
-
if (updatedOrder) {
|
|
1543
|
-
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
1544
|
-
if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
|
|
1545
|
-
this.logWarning('[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:', {
|
|
1546
|
-
currentRealId: currentOrderId,
|
|
1547
|
-
retrievedVirtualId: updatedOrder.order_id
|
|
1548
|
-
});
|
|
1549
|
-
updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
|
|
1550
|
-
}
|
|
1551
|
-
this.store.currentOrder = updatedOrder;
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
// 更新 stateAmount 为剩余未支付金额
|
|
1555
|
-
_context17.next = 23;
|
|
1556
|
-
return this.updateStateAmountToRemaining(false);
|
|
1557
|
-
case 23:
|
|
1558
|
-
_context17.next = 25;
|
|
1559
|
-
return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
|
|
1560
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1561
|
-
paymentMethodCode: paymentItem.code,
|
|
1562
|
-
amount: "-".concat(paymentItem.amount),
|
|
1563
|
-
// 负数表示删除
|
|
1564
|
-
timestamp: Date.now()
|
|
1565
|
-
});
|
|
1566
|
-
case 25:
|
|
1567
|
-
_context17.next = 33;
|
|
1568
|
-
break;
|
|
1569
|
-
case 27:
|
|
1570
|
-
_context17.prev = 27;
|
|
1571
|
-
_context17.t0 = _context17["catch"](0);
|
|
1572
|
-
this.logError('删除支付项失败:', _context17.t0);
|
|
1573
|
-
_context17.next = 32;
|
|
1574
|
-
return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
|
|
1575
|
-
case 32:
|
|
1576
|
-
throw _context17.t0;
|
|
1577
|
-
case 33:
|
|
1578
|
-
case "end":
|
|
1579
|
-
return _context17.stop();
|
|
1580
|
-
}
|
|
1581
|
-
}, _callee17, this, [[0, 27]]);
|
|
1582
|
-
}));
|
|
1583
|
-
function deletePaymentItemAsync(_x16) {
|
|
1584
|
-
return _deletePaymentItemAsync.apply(this, arguments);
|
|
1585
|
-
}
|
|
1586
|
-
return deletePaymentItemAsync;
|
|
1587
|
-
}()
|
|
1588
|
-
/**
|
|
1589
|
-
* 批量更新当前订单的代金券支付项(覆盖更新)
|
|
1590
|
-
*
|
|
1591
|
-
* 删除所有现有的代金券支付项,然后添加新的代金券支付项。
|
|
1592
|
-
* 这是一个覆盖式更新操作,确保代金券支付项的一致性。
|
|
1593
|
-
*
|
|
1594
|
-
* @param voucherPaymentItems 新的代金券支付项列表,每个都必须包含 voucher_id
|
|
1595
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1596
|
-
* @throws 支付项缺少 voucher_id 时抛出错误
|
|
1597
|
-
*/
|
|
1598
|
-
)
|
|
1599
|
-
}, {
|
|
1600
|
-
key: "updateVoucherPaymentItemsAsync",
|
|
1601
|
-
value: (function () {
|
|
1602
|
-
var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
|
|
1603
|
-
var _this4 = this;
|
|
1604
|
-
var paymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
|
|
1605
|
-
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1606
|
-
while (1) switch (_context18.prev = _context18.next) {
|
|
1607
|
-
case 0:
|
|
1608
|
-
_context18.prev = 0;
|
|
1609
|
-
if (this.store.currentOrder) {
|
|
1610
|
-
_context18.next = 3;
|
|
1611
|
-
break;
|
|
1612
|
-
}
|
|
1613
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
|
|
1614
|
-
case 3:
|
|
1615
|
-
_context18.next = 5;
|
|
1616
|
-
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
1617
|
-
case 5:
|
|
1618
|
-
paymentItems = _context18.sent;
|
|
1619
|
-
allPaymentItemsSynced = paymentItems.every(function (item) {
|
|
1620
|
-
return item.isSynced;
|
|
1621
|
-
});
|
|
1622
|
-
_context18.next = 9;
|
|
1623
|
-
return this.calculateRemainingAmountAsync();
|
|
1624
|
-
case 9:
|
|
1625
|
-
remainingAmount = _context18.sent;
|
|
1626
|
-
remainingValue = new Decimal(remainingAmount);
|
|
1627
|
-
isOrderSynced = this.store.isOrderSynced;
|
|
1628
|
-
if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced)) {
|
|
1629
|
-
_context18.next = 15;
|
|
1630
|
-
break;
|
|
1631
|
-
}
|
|
1632
|
-
this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
|
|
1633
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1634
|
-
orderId: this.store.currentOrder.order_id,
|
|
1635
|
-
remainingAmount: remainingAmount,
|
|
1636
|
-
isOrderSynced: isOrderSynced,
|
|
1637
|
-
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
1638
|
-
reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
|
|
1639
|
-
});
|
|
1640
|
-
return _context18.abrupt("return");
|
|
1641
|
-
case 15:
|
|
1642
|
-
this.logInfo('开始批量更新代金券支付项:', {
|
|
1643
|
-
voucherPaymentItems: voucherPaymentItems
|
|
1644
|
-
});
|
|
1645
|
-
|
|
1646
|
-
// 根据当前订单的定金状态设置订单支付类型
|
|
1647
|
-
orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 验证所有支付项都包含 voucher_id,并设置 order_payment_type 和 metadata
|
|
1648
|
-
voucherPaymentItemsWithType = voucherPaymentItems.map(function (item) {
|
|
1649
|
-
if (!item.voucher_id) {
|
|
1650
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
// 从 otherParams 获取 metadata 字段
|
|
1654
|
-
var metadata = _objectSpread(_objectSpread({}, item.metadata), {}, {
|
|
1655
|
-
rounding_rule: _this4.otherParams.order_rounding_setting,
|
|
1656
|
-
shop_wallet_pass_id: _this4.otherParams.shop_wallet_pass_id
|
|
1657
|
-
});
|
|
1658
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
1659
|
-
order_payment_type: orderPaymentType,
|
|
1660
|
-
metadata: metadata
|
|
1661
|
-
});
|
|
1662
|
-
}); // 调用 Payment 模块的批量更新方法
|
|
1663
|
-
_context18.next = 20;
|
|
1664
|
-
return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
|
|
1665
|
-
case 20:
|
|
1666
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1667
|
-
this.clearCalculationCache();
|
|
1668
|
-
|
|
1669
|
-
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1670
|
-
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1671
|
-
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1672
|
-
_context18.next = 25;
|
|
1673
|
-
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1674
|
-
case 25:
|
|
1675
|
-
updatedOrder = _context18.sent;
|
|
1676
|
-
if (updatedOrder) {
|
|
1677
|
-
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
1678
|
-
if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
|
|
1679
|
-
this.logWarning('updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:', {
|
|
1680
|
-
currentRealId: currentOrderId,
|
|
1681
|
-
retrievedVirtualId: updatedOrder.order_id
|
|
1682
|
-
});
|
|
1683
|
-
updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
|
|
1684
|
-
}
|
|
1685
|
-
this.store.currentOrder = updatedOrder;
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
// 更新 stateAmount 为剩余未支付金额
|
|
1689
|
-
_context18.next = 29;
|
|
1690
|
-
return this.updateStateAmountToRemaining(false);
|
|
1691
|
-
case 29:
|
|
1692
|
-
_context18.next = 31;
|
|
1693
|
-
return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
|
|
1694
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1695
|
-
paymentMethodCode: 'VOUCHER_BATCH',
|
|
1696
|
-
amount: voucherPaymentItems.reduce(function (sum, item) {
|
|
1697
|
-
return sum + parseFloat(String(item.amount));
|
|
1698
|
-
}, 0).toFixed(2),
|
|
1699
|
-
timestamp: Date.now()
|
|
1700
|
-
});
|
|
1701
|
-
case 31:
|
|
1702
|
-
this.logInfo('代金券支付项批量更新成功');
|
|
1703
|
-
_context18.next = 40;
|
|
1704
|
-
break;
|
|
1705
|
-
case 34:
|
|
1706
|
-
_context18.prev = 34;
|
|
1707
|
-
_context18.t0 = _context18["catch"](0);
|
|
1708
|
-
this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
|
|
1709
|
-
_context18.next = 39;
|
|
1710
|
-
return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
|
|
1711
|
-
case 39:
|
|
1712
|
-
throw _context18.t0;
|
|
1713
|
-
case 40:
|
|
1714
|
-
case "end":
|
|
1715
|
-
return _context18.stop();
|
|
1716
|
-
}
|
|
1717
|
-
}, _callee18, this, [[0, 34]]);
|
|
1718
|
-
}));
|
|
1719
|
-
function updateVoucherPaymentItemsAsync(_x17) {
|
|
1720
|
-
return _updateVoucherPaymentItemsAsync.apply(this, arguments);
|
|
1721
|
-
}
|
|
1722
|
-
return updateVoucherPaymentItemsAsync;
|
|
1723
|
-
}()
|
|
1724
|
-
/**
|
|
1725
|
-
* 修改当前订单的定金状态
|
|
1726
|
-
*
|
|
1727
|
-
* 更新当前订单的 is_deposit 字段,用于标识订单是否为定金订单
|
|
1728
|
-
*
|
|
1729
|
-
* @param isDeposit 定金状态 (1: 定金订单, 0: 全款订单)
|
|
1730
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1731
|
-
*/
|
|
1732
|
-
)
|
|
1733
|
-
}, {
|
|
1734
|
-
key: "updateOrderDepositStatusAsync",
|
|
1735
|
-
value: (function () {
|
|
1736
|
-
var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(isDeposit) {
|
|
1737
|
-
var newDepositValue, oldDepositValue, deposit_amount, updateParams;
|
|
1738
|
-
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1739
|
-
while (1) switch (_context19.prev = _context19.next) {
|
|
1740
|
-
case 0:
|
|
1741
|
-
_context19.prev = 0;
|
|
1742
|
-
if (!(isDeposit !== 0 && isDeposit !== 1)) {
|
|
1743
|
-
_context19.next = 3;
|
|
1744
|
-
break;
|
|
1745
|
-
}
|
|
1746
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, 'isDeposit 参数只能是 0(全款订单)或 1(定金订单)');
|
|
1747
|
-
case 3:
|
|
1748
|
-
if (this.store.currentOrder) {
|
|
1749
|
-
_context19.next = 5;
|
|
1750
|
-
break;
|
|
1751
|
-
}
|
|
1752
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法修改定金状态');
|
|
1753
|
-
case 5:
|
|
1754
|
-
newDepositValue = isDeposit;
|
|
1755
|
-
oldDepositValue = this.store.currentOrder.is_deposit; // 如果状态没有变化,直接返回
|
|
1756
|
-
if (!(oldDepositValue === newDepositValue)) {
|
|
1757
|
-
_context19.next = 10;
|
|
1758
|
-
break;
|
|
1759
|
-
}
|
|
1760
|
-
console.log('[Checkout] 定金状态无变化,跳过更新');
|
|
1761
|
-
return _context19.abrupt("return");
|
|
1762
|
-
case 10:
|
|
1763
|
-
deposit_amount = this.store.currentOrder.deposit_amount || '0.00'; // 如果原来没有 deposit_amount,则默认把待付金额置为 deposit_amount
|
|
1764
|
-
if (!deposit_amount || Number(deposit_amount) === 0) {
|
|
1765
|
-
deposit_amount = this.store.currentOrder.expect_amount;
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
// 准备更新参数
|
|
1769
|
-
updateParams = {
|
|
1770
|
-
is_deposit: newDepositValue,
|
|
1771
|
-
deposit_amount: deposit_amount
|
|
1772
|
-
}; // 如果从定金改为全款,可以清空定金金额
|
|
1773
|
-
// if (
|
|
1774
|
-
// isDeposit === 0 &&
|
|
1775
|
-
// this.store.currentOrder.deposit_amount !== '0.00'
|
|
1776
|
-
// ) {
|
|
1777
|
-
// updateParams.deposit_amount = '0.00';
|
|
1778
|
-
// this.logInfo('订单从定金改为全款,清空定金金额');
|
|
1779
|
-
// }
|
|
1780
|
-
// 调用 Payment 模块更新订单
|
|
1781
|
-
_context19.next = 15;
|
|
1782
|
-
return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
|
|
1783
|
-
case 15:
|
|
1784
|
-
// 更新本地缓存的订单对象
|
|
1785
|
-
this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
|
|
1786
|
-
|
|
1787
|
-
// 同时更新本地订单数据(如果存在)
|
|
1788
|
-
if (this.store.localOrderData) {
|
|
1789
|
-
this.store.localOrderData.is_deposit = newDepositValue;
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1793
|
-
this.clearCalculationCache();
|
|
1794
|
-
this.updateStateAmountToRemaining(false);
|
|
1795
|
-
|
|
1796
|
-
// 触发订单更新事件
|
|
1797
|
-
_context19.next = 21;
|
|
1798
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
1799
|
-
order: this.store.currentOrder,
|
|
1800
|
-
timestamp: Date.now()
|
|
1801
|
-
});
|
|
1802
|
-
case 21:
|
|
1803
|
-
this.logInfo('订单定金状态更新成功:', {
|
|
1804
|
-
isDeposit: newDepositValue,
|
|
1805
|
-
depositAmount: this.store.currentOrder.deposit_amount
|
|
1806
|
-
});
|
|
1807
|
-
_context19.next = 30;
|
|
1808
|
-
break;
|
|
1809
|
-
case 24:
|
|
1810
|
-
_context19.prev = 24;
|
|
1811
|
-
_context19.t0 = _context19["catch"](0);
|
|
1812
|
-
this.logError('更新订单定金状态失败:', _context19.t0);
|
|
1813
|
-
_context19.next = 29;
|
|
1814
|
-
return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
|
|
1815
|
-
case 29:
|
|
1816
|
-
throw _context19.t0;
|
|
1817
|
-
case 30:
|
|
1818
|
-
case "end":
|
|
1819
|
-
return _context19.stop();
|
|
1820
|
-
}
|
|
1821
|
-
}, _callee19, this, [[0, 24]]);
|
|
1822
|
-
}));
|
|
1823
|
-
function updateOrderDepositStatusAsync(_x18) {
|
|
1824
|
-
return _updateOrderDepositStatusAsync.apply(this, arguments);
|
|
1825
|
-
}
|
|
1826
|
-
return updateOrderDepositStatusAsync;
|
|
1827
|
-
}()
|
|
1828
|
-
/**
|
|
1829
|
-
* 手动设置当前订单的定金金额
|
|
1830
|
-
*
|
|
1831
|
-
* 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
|
|
1832
|
-
*
|
|
1833
|
-
* @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
|
|
1834
|
-
* @throws 当前没有活跃订单时抛出错误
|
|
1835
|
-
* @throws 定金金额格式无效或超过订单总额时抛出错误
|
|
1836
|
-
*/
|
|
1837
|
-
)
|
|
1838
|
-
}, {
|
|
1839
|
-
key: "setDepositAmountAsync",
|
|
1840
|
-
value: (function () {
|
|
1841
|
-
var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(depositAmount) {
|
|
1842
|
-
var _this$store$currentOr9, _this$store$currentOr10;
|
|
1843
|
-
var depositValue, formattedDepositAmount, oldDepositAmount, updateParams;
|
|
1844
|
-
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1845
|
-
while (1) switch (_context20.prev = _context20.next) {
|
|
1846
|
-
case 0:
|
|
1847
|
-
this.logInfo('setDepositAmountAsync called', {
|
|
1848
|
-
depositAmount: depositAmount,
|
|
1849
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
1850
|
-
currentOrderId: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_id,
|
|
1851
|
-
currentTotalAmount: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.total_amount
|
|
1852
|
-
});
|
|
1853
|
-
_context20.prev = 1;
|
|
1854
|
-
// 验证定金金额格式
|
|
1855
|
-
depositValue = new Decimal(depositAmount);
|
|
1856
|
-
if (!(depositValue.isNaN() || depositValue.lt(0))) {
|
|
1857
|
-
_context20.next = 5;
|
|
1858
|
-
break;
|
|
1859
|
-
}
|
|
1860
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u65E0\u6548\u7684\u5B9A\u91D1\u91D1\u989D\u683C\u5F0F: ".concat(depositAmount));
|
|
1861
|
-
case 5:
|
|
1862
|
-
if (this.store.currentOrder) {
|
|
1863
|
-
_context20.next = 7;
|
|
1864
|
-
break;
|
|
1865
|
-
}
|
|
1866
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法设置定金金额');
|
|
1867
|
-
case 7:
|
|
1868
|
-
formattedDepositAmount = depositValue.toFixed(2);
|
|
1869
|
-
oldDepositAmount = this.store.currentOrder.deposit_amount || '0.00'; // 如果定金金额没有变化,直接返回
|
|
1870
|
-
if (!(formattedDepositAmount === oldDepositAmount)) {
|
|
1871
|
-
_context20.next = 12;
|
|
1872
|
-
break;
|
|
1873
|
-
}
|
|
1874
|
-
this.logInfo('定金金额无变化,跳过更新:', {
|
|
1875
|
-
currentAmount: oldDepositAmount,
|
|
1876
|
-
newAmount: formattedDepositAmount
|
|
1877
|
-
});
|
|
1878
|
-
return _context20.abrupt("return");
|
|
1879
|
-
case 12:
|
|
1880
|
-
this.logInfo('开始设置订单定金金额:', {
|
|
1881
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1882
|
-
orderId: this.store.currentOrder.order_id,
|
|
1883
|
-
oldDepositAmount: oldDepositAmount,
|
|
1884
|
-
newDepositAmount: formattedDepositAmount,
|
|
1885
|
-
totalAmount: this.store.currentOrder.total_amount
|
|
1886
|
-
});
|
|
1887
|
-
|
|
1888
|
-
// 准备更新参数
|
|
1889
|
-
updateParams = {
|
|
1890
|
-
deposit_amount: formattedDepositAmount
|
|
1891
|
-
}; // 如果设置的定金金额大于0,自动将订单标记为定金订单
|
|
1892
|
-
if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
|
|
1893
|
-
updateParams.is_deposit = 1;
|
|
1894
|
-
this.logInfo('定金金额大于0,自动设置为定金订单');
|
|
1895
|
-
}
|
|
1896
|
-
// 如果设置的定金金额为0,可以考虑将订单标记为全款订单
|
|
1897
|
-
else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
|
|
1898
|
-
updateParams.is_deposit = 0;
|
|
1899
|
-
this.logInfo('定金金额为0,自动设置为全款订单');
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
// 调用 Payment 模块更新订单
|
|
1903
|
-
_context20.next = 17;
|
|
1904
|
-
return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
|
|
1905
|
-
case 17:
|
|
1906
|
-
// 更新本地缓存的订单对象
|
|
1907
|
-
this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
|
|
1908
|
-
|
|
1909
|
-
// 同时更新本地订单数据(如果存在)
|
|
1910
|
-
if (this.store.localOrderData) {
|
|
1911
|
-
// 注意:本地订单数据中没有deposit_amount字段,但如果需要可以在这里添加
|
|
1912
|
-
if ('deposit_amount' in this.store.localOrderData) {
|
|
1913
|
-
this.store.localOrderData.deposit_amount = formattedDepositAmount;
|
|
1914
|
-
}
|
|
1915
|
-
// 同步更新 is_deposit 状态(如果有变化)
|
|
1916
|
-
if (updateParams.is_deposit !== undefined) {
|
|
1917
|
-
this.store.localOrderData.is_deposit = updateParams.is_deposit;
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1922
|
-
this.clearCalculationCache();
|
|
1923
|
-
this.updateStateAmountToRemaining(false);
|
|
1924
|
-
|
|
1925
|
-
// 触发订单更新事件
|
|
1926
|
-
_context20.next = 23;
|
|
1927
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
1928
|
-
order: this.store.currentOrder,
|
|
1929
|
-
timestamp: Date.now()
|
|
1930
|
-
});
|
|
1931
|
-
case 23:
|
|
1932
|
-
this.logInfo('订单定金金额设置成功:', {
|
|
1933
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
1934
|
-
orderId: this.store.currentOrder.order_id,
|
|
1935
|
-
oldDepositAmount: oldDepositAmount,
|
|
1936
|
-
newDepositAmount: formattedDepositAmount,
|
|
1937
|
-
isDeposit: this.store.currentOrder.is_deposit,
|
|
1938
|
-
totalAmount: this.store.currentOrder.total_amount
|
|
1939
|
-
});
|
|
1940
|
-
_context20.next = 32;
|
|
1941
|
-
break;
|
|
1942
|
-
case 26:
|
|
1943
|
-
_context20.prev = 26;
|
|
1944
|
-
_context20.t0 = _context20["catch"](1);
|
|
1945
|
-
this.logError('设置订单定金金额失败:', _context20.t0);
|
|
1946
|
-
_context20.next = 31;
|
|
1947
|
-
return this.handleError(_context20.t0, CheckoutErrorType.ValidationFailed);
|
|
1948
|
-
case 31:
|
|
1949
|
-
throw _context20.t0;
|
|
1950
|
-
case 32:
|
|
1951
|
-
case "end":
|
|
1952
|
-
return _context20.stop();
|
|
1953
|
-
}
|
|
1954
|
-
}, _callee20, this, [[1, 26]]);
|
|
1955
|
-
}));
|
|
1956
|
-
function setDepositAmountAsync(_x19) {
|
|
1957
|
-
return _setDepositAmountAsync.apply(this, arguments);
|
|
1958
|
-
}
|
|
1959
|
-
return setDepositAmountAsync;
|
|
1960
|
-
}()
|
|
1961
|
-
/**
|
|
1962
|
-
* 手动同步订单到后端
|
|
1963
|
-
*
|
|
1964
|
-
* 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
|
|
1965
|
-
*/
|
|
1966
|
-
)
|
|
1967
|
-
}, {
|
|
1968
|
-
key: "manualSyncOrderAsync",
|
|
1969
|
-
value: (function () {
|
|
1970
|
-
var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
1971
|
-
var _this$store$currentOr11, _this$store$currentOr12, _this$store$currentOr13;
|
|
1972
|
-
var _this$store$currentOr14, orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, newRes, _this$store$currentOr15, errorMessage;
|
|
1973
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1974
|
-
while (1) switch (_context21.prev = _context21.next) {
|
|
1975
|
-
case 0:
|
|
1976
|
-
console.log('manualSyncOrderAsync called');
|
|
1977
|
-
this.logInfo('manualSyncOrderAsync called', {
|
|
1978
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
1979
|
-
currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
|
|
1980
|
-
orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
|
|
1981
|
-
totalAmount: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.total_amount,
|
|
1982
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
1983
|
-
isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
|
|
1984
|
-
});
|
|
1985
|
-
_context21.prev = 2;
|
|
1986
|
-
if (this.store.currentOrder) {
|
|
1987
|
-
_context21.next = 5;
|
|
1988
|
-
break;
|
|
1989
|
-
}
|
|
1990
|
-
return _context21.abrupt("return", {
|
|
1991
|
-
success: false,
|
|
1992
|
-
message: '当前没有活跃订单,无法同步'
|
|
1993
|
-
});
|
|
1994
|
-
case 5:
|
|
1995
|
-
orderUuid = this.store.currentOrder.uuid;
|
|
1996
|
-
oldOrderId = this.store.currentOrder.order_id; // 检查订单是否已经同步
|
|
1997
|
-
if (this.store.isOrderSynced) {
|
|
1998
|
-
this.logInfo('订单已同步过,将执行更新操作');
|
|
1999
|
-
}
|
|
2000
|
-
_context21.t0 = this;
|
|
2001
|
-
_context21.t1 = orderUuid;
|
|
2002
|
-
_context21.t2 = oldOrderId;
|
|
2003
|
-
_context21.t3 = this.store.currentOrder.total_amount;
|
|
2004
|
-
_context21.next = 14;
|
|
2005
|
-
return this.calculateRemainingAmountAsync();
|
|
2006
|
-
case 14:
|
|
2007
|
-
_context21.t4 = _context21.sent;
|
|
2008
|
-
_context21.t5 = {
|
|
2009
|
-
orderUuid: _context21.t1,
|
|
2010
|
-
orderId: _context21.t2,
|
|
2011
|
-
totalAmount: _context21.t3,
|
|
2012
|
-
remainingAmount: _context21.t4
|
|
2013
|
-
};
|
|
2014
|
-
_context21.t0.logInfo.call(_context21.t0, '开始手动同步订单到后端:', _context21.t5);
|
|
2015
|
-
console.time('manualSyncOrderAsync');
|
|
2016
|
-
|
|
2017
|
-
// 强制同步订单到后端,并获取完整响应数据
|
|
2018
|
-
_context21.next = 20;
|
|
2019
|
-
return this.syncOrderToBackendWithReturn(true);
|
|
2020
|
-
case 20:
|
|
2021
|
-
syncResult = _context21.sent;
|
|
2022
|
-
console.timeEnd('manualSyncOrderAsync');
|
|
2023
|
-
this.logInfo('手动同步订单完成:', {
|
|
2024
|
-
orderUuid: orderUuid,
|
|
2025
|
-
syncResult: syncResult,
|
|
2026
|
-
oldOrderId: oldOrderId,
|
|
2027
|
-
realOrderId: syncResult.orderId,
|
|
2028
|
-
isOrderSynced: this.store.isOrderSynced
|
|
2029
|
-
});
|
|
2030
|
-
|
|
2031
|
-
// 🔍 关键验证:检查最终状态是否正确
|
|
2032
|
-
finalOrderId = this.store.currentOrder.order_id;
|
|
2033
|
-
finalIsVirtual = isVirtualOrderId(finalOrderId);
|
|
2034
|
-
if (finalIsVirtual) {
|
|
2035
|
-
this.logError('严重警告:手动同步完成后订单ID仍为虚拟ID!');
|
|
2036
|
-
}
|
|
2037
|
-
if (syncResult.orderId !== finalOrderId) {
|
|
2038
|
-
this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
|
|
2039
|
-
}
|
|
2040
|
-
newRes = _objectSpread(_objectSpread({}, syncResult), {}, {
|
|
2041
|
-
is_deposit: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.is_deposit) || 0
|
|
2042
|
-
});
|
|
2043
|
-
_context21.next = 30;
|
|
2044
|
-
return this.updateStateAmountToRemaining(false);
|
|
2045
|
-
case 30:
|
|
2046
|
-
return _context21.abrupt("return", newRes);
|
|
2047
|
-
case 33:
|
|
2048
|
-
_context21.prev = 33;
|
|
2049
|
-
_context21.t6 = _context21["catch"](2);
|
|
2050
|
-
this.logError('手动同步订单失败:', _context21.t6);
|
|
2051
|
-
errorMessage = _context21.t6 instanceof Error ? _context21.t6.message : '同步失败';
|
|
2052
|
-
return _context21.abrupt("return", {
|
|
2053
|
-
success: false,
|
|
2054
|
-
message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
|
|
2055
|
-
orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
|
|
2056
|
-
});
|
|
2057
|
-
case 38:
|
|
2058
|
-
case "end":
|
|
2059
|
-
return _context21.stop();
|
|
2060
|
-
}
|
|
2061
|
-
}, _callee21, this, [[2, 33]]);
|
|
2062
|
-
}));
|
|
2063
|
-
function manualSyncOrderAsync() {
|
|
2064
|
-
return _manualSyncOrderAsync.apply(this, arguments);
|
|
2065
|
-
}
|
|
2066
|
-
return manualSyncOrderAsync;
|
|
2067
|
-
}()
|
|
2068
|
-
/**
|
|
2069
|
-
* 获取当前订单备注
|
|
2070
|
-
*
|
|
2071
|
-
* @returns 当前订单的备注内容,如果没有则返回空字符串
|
|
2072
|
-
*/
|
|
2073
|
-
)
|
|
2074
|
-
}, {
|
|
2075
|
-
key: "getOrderNote",
|
|
2076
|
-
value: function getOrderNote() {
|
|
2077
|
-
if (!this.store.localOrderData) {
|
|
2078
|
-
console.log('[Checkout] 没有本地订单数据,无法获取备注');
|
|
2079
|
-
return '';
|
|
2080
|
-
}
|
|
2081
|
-
return this.store.localOrderData.shop_note || '';
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
/**
|
|
2085
|
-
* 获取当前订单ID
|
|
2086
|
-
*
|
|
2087
|
-
* @returns 当前订单的ID,如果没有订单则返回null
|
|
2088
|
-
*/
|
|
2089
|
-
}, {
|
|
2090
|
-
key: "getCurrentOrderId",
|
|
2091
|
-
value: function getCurrentOrderId() {
|
|
2092
|
-
if (!this.store.currentOrder) {
|
|
2093
|
-
return null;
|
|
2094
|
-
}
|
|
2095
|
-
return this.store.currentOrder.order_id;
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
/**
|
|
2099
|
-
* 获取当前订单是否已同步到后端
|
|
2100
|
-
*
|
|
2101
|
-
* @returns 当前订单是否已同步状态,如果没有订单则返回false
|
|
2102
|
-
*/
|
|
2103
|
-
}, {
|
|
2104
|
-
key: "isCurrentOrderSynced",
|
|
2105
|
-
value: function isCurrentOrderSynced() {
|
|
2106
|
-
// 如果没有当前订单,返回false
|
|
2107
|
-
if (!this.store.currentOrder) {
|
|
2108
|
-
console.log('[Checkout] 没有当前订单,同步状态为false');
|
|
2109
|
-
return false;
|
|
2110
|
-
}
|
|
2111
|
-
var syncStatus = this.store.isOrderSynced;
|
|
2112
|
-
console.log('[Checkout] 当前订单同步状态:', {
|
|
2113
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
2114
|
-
orderId: this.store.currentOrder.order_id,
|
|
2115
|
-
isOrderSynced: syncStatus
|
|
2116
|
-
});
|
|
2117
|
-
return syncStatus;
|
|
2118
|
-
}
|
|
2119
|
-
|
|
2120
|
-
/**
|
|
2121
|
-
* 取消当前本地订单
|
|
2122
|
-
*
|
|
2123
|
-
* 只能取消未同步到后端的本地订单,如果订单已同步则不能取消
|
|
2124
|
-
*
|
|
2125
|
-
* @param cancelReason 取消原因(可选)
|
|
2126
|
-
* @returns 取消结果
|
|
2127
|
-
*/
|
|
2128
|
-
}, {
|
|
2129
|
-
key: "cancelCurrentOrderAsync",
|
|
2130
|
-
value: (function () {
|
|
2131
|
-
var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(cancelReason) {
|
|
2132
|
-
var _this$store$currentOr16, _this$store$currentOr17, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
|
|
2133
|
-
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
2134
|
-
while (1) switch (_context22.prev = _context22.next) {
|
|
2135
|
-
case 0:
|
|
2136
|
-
_context22.prev = 0;
|
|
2137
|
-
this.logInfo('开始取消当前本地订单:', {
|
|
2138
|
-
hasCurrentOrder: !!this.store.currentOrder,
|
|
2139
|
-
orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
|
|
2140
|
-
orderId: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.order_id,
|
|
2141
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2142
|
-
cancelReason: cancelReason
|
|
2143
|
-
});
|
|
2144
|
-
|
|
2145
|
-
// 检查是否有当前订单
|
|
2146
|
-
if (this.store.currentOrder) {
|
|
2147
|
-
_context22.next = 5;
|
|
2148
|
-
break;
|
|
2149
|
-
}
|
|
2150
|
-
this.logInfo('没有当前订单,无需取消');
|
|
2151
|
-
return _context22.abrupt("return", {
|
|
2152
|
-
success: false,
|
|
2153
|
-
message: '没有当前订单可取消'
|
|
2154
|
-
});
|
|
2155
|
-
case 5:
|
|
2156
|
-
currentOrderUuid = this.store.currentOrder.uuid;
|
|
2157
|
-
currentOrderId = this.store.currentOrder.order_id;
|
|
2158
|
-
isOrderSynced = this.store.isOrderSynced; // 检查订单是否已同步,已同步的订单不能取消
|
|
2159
|
-
if (!isOrderSynced) {
|
|
2160
|
-
_context22.next = 11;
|
|
2161
|
-
break;
|
|
2162
|
-
}
|
|
2163
|
-
this.logInfo('订单已同步到后端,不能取消:', {
|
|
2164
|
-
orderId: currentOrderId,
|
|
2165
|
-
orderUuid: currentOrderUuid
|
|
2166
|
-
});
|
|
2167
|
-
return _context22.abrupt("return", {
|
|
2168
|
-
success: false,
|
|
2169
|
-
message: '订单已同步到后端,无法取消',
|
|
2170
|
-
orderId: currentOrderId
|
|
2171
|
-
});
|
|
2172
|
-
case 11:
|
|
2173
|
-
_context22.prev = 11;
|
|
2174
|
-
this.logInfo('删除本地订单数据');
|
|
2175
|
-
_context22.next = 15;
|
|
2176
|
-
return this.payment.deletePaymentOrderAsync(currentOrderUuid);
|
|
2177
|
-
case 15:
|
|
2178
|
-
this.logInfo('本地订单数据删除成功');
|
|
2179
|
-
_context22.next = 21;
|
|
2180
|
-
break;
|
|
2181
|
-
case 18:
|
|
2182
|
-
_context22.prev = 18;
|
|
2183
|
-
_context22.t0 = _context22["catch"](11);
|
|
2184
|
-
this.logWarning('删除本地订单数据失败,但继续执行:', _context22.t0);
|
|
2185
|
-
case 21:
|
|
2186
|
-
// 清理订单相关状态,确保正确释放 currentOrder
|
|
2187
|
-
this.logInfo('清理订单相关状态');
|
|
2188
|
-
this.store.currentOrder = undefined; // 释放 currentOrder
|
|
2189
|
-
this.store.localOrderData = undefined;
|
|
2190
|
-
this.store.stateAmount = '0.00';
|
|
2191
|
-
this.store.balanceDueAmount = '0.00';
|
|
2192
|
-
this.store.isOrderSynced = false;
|
|
2193
|
-
this.store.currentCustomer = undefined;
|
|
2194
|
-
|
|
2195
|
-
// 清理钱包缓存
|
|
2196
|
-
this.payment.wallet.clearAllCache();
|
|
2197
|
-
this.logInfo('订单状态清理完成,currentOrder已释放');
|
|
2198
|
-
|
|
2199
|
-
// 触发订单取消事件
|
|
2200
|
-
_context22.next = 32;
|
|
2201
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderCancelled"), {
|
|
2202
|
-
orderUuid: currentOrderUuid,
|
|
2203
|
-
orderId: currentOrderId,
|
|
2204
|
-
cancelReason: cancelReason,
|
|
2205
|
-
wasSynced: false,
|
|
2206
|
-
// 只有未同步订单可以被取消
|
|
2207
|
-
timestamp: Date.now()
|
|
2208
|
-
});
|
|
2209
|
-
case 32:
|
|
2210
|
-
this.logInfo('本地订单取消完成:', {
|
|
2211
|
-
orderUuid: currentOrderUuid,
|
|
2212
|
-
orderId: currentOrderId,
|
|
2213
|
-
cancelReason: cancelReason
|
|
2214
|
-
});
|
|
2215
|
-
return _context22.abrupt("return", {
|
|
2216
|
-
success: true,
|
|
2217
|
-
message: '本地订单已成功取消',
|
|
2218
|
-
orderId: currentOrderId
|
|
2219
|
-
});
|
|
2220
|
-
case 36:
|
|
2221
|
-
_context22.prev = 36;
|
|
2222
|
-
_context22.t1 = _context22["catch"](0);
|
|
2223
|
-
this.logError('取消本地订单失败:', _context22.t1);
|
|
2224
|
-
errorMessage = _context22.t1 instanceof Error ? _context22.t1.message : '未知错误';
|
|
2225
|
-
return _context22.abrupt("return", {
|
|
2226
|
-
success: false,
|
|
2227
|
-
message: "\u53D6\u6D88\u8BA2\u5355\u5931\u8D25: ".concat(errorMessage)
|
|
2228
|
-
});
|
|
2229
|
-
case 41:
|
|
2230
|
-
case "end":
|
|
2231
|
-
return _context22.stop();
|
|
2232
|
-
}
|
|
2233
|
-
}, _callee22, this, [[0, 36], [11, 18]]);
|
|
2234
|
-
}));
|
|
2235
|
-
function cancelCurrentOrderAsync(_x20) {
|
|
2236
|
-
return _cancelCurrentOrderAsync.apply(this, arguments);
|
|
2237
|
-
}
|
|
2238
|
-
return cancelCurrentOrderAsync;
|
|
2239
|
-
}()
|
|
2240
|
-
/**
|
|
2241
|
-
* 保存订单并稍后支付
|
|
2242
|
-
*
|
|
2243
|
-
* 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
|
|
2244
|
-
* 适用于用户想要保存订单但稍后完成支付的场景
|
|
2245
|
-
*/
|
|
2246
|
-
)
|
|
2247
|
-
}, {
|
|
2248
|
-
key: "saveForLaterPaymentAsync",
|
|
2249
|
-
value: (function () {
|
|
2250
|
-
var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
2251
|
-
var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr18, errorMessage;
|
|
2252
|
-
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
2253
|
-
while (1) switch (_context23.prev = _context23.next) {
|
|
2254
|
-
case 0:
|
|
2255
|
-
_context23.prev = 0;
|
|
2256
|
-
if (this.store.currentOrder) {
|
|
2257
|
-
_context23.next = 3;
|
|
2258
|
-
break;
|
|
2259
|
-
}
|
|
2260
|
-
return _context23.abrupt("return", {
|
|
2261
|
-
success: false,
|
|
2262
|
-
message: '当前没有活跃订单,无法保存'
|
|
2263
|
-
});
|
|
2264
|
-
case 3:
|
|
2265
|
-
orderUuid = this.store.currentOrder.uuid;
|
|
2266
|
-
currentOrderId = this.store.currentOrder.order_id;
|
|
2267
|
-
this.logInfo('开始保存订单并稍后支付:', {
|
|
2268
|
-
orderUuid: orderUuid,
|
|
2269
|
-
orderId: currentOrderId,
|
|
2270
|
-
totalAmount: this.store.currentOrder.total_amount
|
|
2271
|
-
});
|
|
2272
|
-
|
|
2273
|
-
// 获取当前订单的所有支付项
|
|
2274
|
-
_context23.next = 8;
|
|
2275
|
-
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2276
|
-
case 8:
|
|
2277
|
-
allPaymentItems = _context23.sent;
|
|
2278
|
-
_context23.next = 11;
|
|
2279
|
-
return this.syncOrderToBackendWithReturn(true, allPaymentItems);
|
|
2280
|
-
case 11:
|
|
2281
|
-
syncResult = _context23.sent;
|
|
2282
|
-
this.logInfo('保存订单完成:', {
|
|
2283
|
-
orderUuid: orderUuid,
|
|
2284
|
-
oldOrderId: currentOrderId,
|
|
2285
|
-
syncResult: syncResult,
|
|
2286
|
-
realOrderId: syncResult.orderId,
|
|
2287
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
2288
|
-
filteredPaymentsCount: allPaymentItems.length
|
|
2289
|
-
});
|
|
2290
|
-
return _context23.abrupt("return", {
|
|
2291
|
-
success: true,
|
|
2292
|
-
message: '订单保存成功,可稍后继续支付',
|
|
2293
|
-
orderId: syncResult.orderId,
|
|
2294
|
-
orderUuid: orderUuid,
|
|
2295
|
-
response: syncResult.response
|
|
2296
|
-
});
|
|
2297
|
-
case 16:
|
|
2298
|
-
_context23.prev = 16;
|
|
2299
|
-
_context23.t0 = _context23["catch"](0);
|
|
2300
|
-
this.logError('保存订单失败:', _context23.t0);
|
|
2301
|
-
errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : '保存失败';
|
|
2302
|
-
return _context23.abrupt("return", {
|
|
2303
|
-
success: false,
|
|
2304
|
-
message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
|
|
2305
|
-
orderUuid: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.uuid
|
|
2306
|
-
});
|
|
2307
|
-
case 21:
|
|
2308
|
-
case "end":
|
|
2309
|
-
return _context23.stop();
|
|
2310
|
-
}
|
|
2311
|
-
}, _callee23, this, [[0, 16]]);
|
|
2312
|
-
}));
|
|
2313
|
-
function saveForLaterPaymentAsync() {
|
|
2314
|
-
return _saveForLaterPaymentAsync.apply(this, arguments);
|
|
2315
|
-
}
|
|
2316
|
-
return saveForLaterPaymentAsync;
|
|
2317
|
-
}()
|
|
2318
|
-
/**
|
|
2319
|
-
* 更新订单备注
|
|
2320
|
-
*
|
|
2321
|
-
* @param note 订单备注内容
|
|
2322
|
-
*/
|
|
2323
|
-
)
|
|
2324
|
-
}, {
|
|
2325
|
-
key: "updateOrderNoteAsync",
|
|
2326
|
-
value: (function () {
|
|
2327
|
-
var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(note) {
|
|
2328
|
-
var _this$store$currentOr19, _this$store$currentOr20, oldNote, orderInPayment;
|
|
2329
|
-
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2330
|
-
while (1) switch (_context24.prev = _context24.next) {
|
|
2331
|
-
case 0:
|
|
2332
|
-
_context24.prev = 0;
|
|
2333
|
-
if (this.store.localOrderData) {
|
|
2334
|
-
_context24.next = 3;
|
|
2335
|
-
break;
|
|
2336
|
-
}
|
|
2337
|
-
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
|
|
2338
|
-
case 3:
|
|
2339
|
-
console.log('[Checkout] 更新订单备注:', {
|
|
2340
|
-
orderUuid: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.uuid,
|
|
2341
|
-
oldNote: this.store.localOrderData.shop_note,
|
|
2342
|
-
newNote: note
|
|
2343
|
-
});
|
|
2344
|
-
|
|
2345
|
-
// 更新备注
|
|
2346
|
-
oldNote = this.store.localOrderData.shop_note;
|
|
2347
|
-
this.store.localOrderData.shop_note = note;
|
|
2348
|
-
|
|
2349
|
-
// 如果有当前订单,也同步到Payment模块中的订单数据
|
|
2350
|
-
if (!this.store.currentOrder) {
|
|
2351
|
-
_context24.next = 17;
|
|
2352
|
-
break;
|
|
2353
|
-
}
|
|
2354
|
-
_context24.prev = 7;
|
|
2355
|
-
_context24.next = 10;
|
|
2356
|
-
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
2357
|
-
case 10:
|
|
2358
|
-
orderInPayment = _context24.sent;
|
|
2359
|
-
if (orderInPayment && orderInPayment.note !== undefined) {
|
|
2360
|
-
// 使用Payment模块的更新方法(如果有的话)
|
|
2361
|
-
// 这里可能需要根据Payment模块的实际API来调整
|
|
2362
|
-
console.log('[Checkout] 同步备注到Payment模块的订单数据中');
|
|
2363
|
-
}
|
|
2364
|
-
_context24.next = 17;
|
|
2365
|
-
break;
|
|
2366
|
-
case 14:
|
|
2367
|
-
_context24.prev = 14;
|
|
2368
|
-
_context24.t0 = _context24["catch"](7);
|
|
2369
|
-
console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context24.t0);
|
|
2370
|
-
case 17:
|
|
2371
|
-
_context24.next = 19;
|
|
2372
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
|
|
2373
|
-
orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid,
|
|
2374
|
-
oldNote: oldNote,
|
|
2375
|
-
newNote: note,
|
|
2376
|
-
timestamp: Date.now()
|
|
2377
|
-
});
|
|
2378
|
-
case 19:
|
|
2379
|
-
console.log('[Checkout] 订单备注更新成功:', {
|
|
2380
|
-
oldNote: oldNote,
|
|
2381
|
-
newNote: note
|
|
2382
|
-
});
|
|
2383
|
-
_context24.next = 28;
|
|
2384
|
-
break;
|
|
2385
|
-
case 22:
|
|
2386
|
-
_context24.prev = 22;
|
|
2387
|
-
_context24.t1 = _context24["catch"](0);
|
|
2388
|
-
console.error('[Checkout] 更新订单备注失败:', _context24.t1);
|
|
2389
|
-
_context24.next = 27;
|
|
2390
|
-
return this.handleError(_context24.t1, CheckoutErrorType.ValidationFailed);
|
|
2391
|
-
case 27:
|
|
2392
|
-
throw _context24.t1;
|
|
2393
|
-
case 28:
|
|
2394
|
-
case "end":
|
|
2395
|
-
return _context24.stop();
|
|
2396
|
-
}
|
|
2397
|
-
}, _callee24, this, [[0, 22], [7, 14]]);
|
|
2398
|
-
}));
|
|
2399
|
-
function updateOrderNoteAsync(_x21) {
|
|
2400
|
-
return _updateOrderNoteAsync.apply(this, arguments);
|
|
2401
|
-
}
|
|
2402
|
-
return updateOrderNoteAsync;
|
|
2403
|
-
}()
|
|
2404
|
-
/**
|
|
2405
|
-
* 处理错误
|
|
2406
|
-
*/
|
|
2407
|
-
)
|
|
2408
|
-
}, {
|
|
2409
|
-
key: "handleError",
|
|
2410
|
-
value: (function () {
|
|
2411
|
-
var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(error, type) {
|
|
2412
|
-
var checkoutError;
|
|
2413
|
-
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2414
|
-
while (1) switch (_context25.prev = _context25.next) {
|
|
2415
|
-
case 0:
|
|
2416
|
-
checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
|
|
2417
|
-
this.store.lastError = checkoutError;
|
|
2418
|
-
_context25.next = 4;
|
|
2419
|
-
return this.core.effects.emit("".concat(this.name, ":onError"), {
|
|
2420
|
-
error: checkoutError,
|
|
2421
|
-
context: {},
|
|
2422
|
-
timestamp: Date.now()
|
|
2423
|
-
});
|
|
2424
|
-
case 4:
|
|
2425
|
-
console.error('[Checkout] 错误:', checkoutError);
|
|
2426
|
-
case 5:
|
|
2427
|
-
case "end":
|
|
2428
|
-
return _context25.stop();
|
|
2429
|
-
}
|
|
2430
|
-
}, _callee25, this);
|
|
2431
|
-
}));
|
|
2432
|
-
function handleError(_x22, _x23) {
|
|
2433
|
-
return _handleError.apply(this, arguments);
|
|
2434
|
-
}
|
|
2435
|
-
return handleError;
|
|
2436
|
-
}()
|
|
2437
|
-
/**
|
|
2438
|
-
* 处理支付成功
|
|
2439
|
-
*/
|
|
2440
|
-
)
|
|
2441
|
-
}, {
|
|
2442
|
-
key: "handlePaymentSuccess",
|
|
2443
|
-
value: (function () {
|
|
2444
|
-
var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
|
|
2445
|
-
var _this$store$currentOr21;
|
|
2446
|
-
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2447
|
-
while (1) switch (_context26.prev = _context26.next) {
|
|
2448
|
-
case 0:
|
|
2449
|
-
_context26.next = 2;
|
|
2450
|
-
return this.updateStateAmountToRemaining();
|
|
2451
|
-
case 2:
|
|
2452
|
-
_context26.next = 4;
|
|
2453
|
-
return this.core.effects.emit("".concat(this.name, ":onPaymentSuccess"), {
|
|
2454
|
-
orderUuid: data.orderUuid,
|
|
2455
|
-
paymentMethodCode: '',
|
|
2456
|
-
amount: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.total_amount) || '0',
|
|
2457
|
-
timestamp: data.timestamp
|
|
2458
|
-
});
|
|
2459
|
-
case 4:
|
|
2460
|
-
_context26.next = 6;
|
|
2461
|
-
return this.completeCheckoutAsync();
|
|
2462
|
-
case 6:
|
|
2463
|
-
case "end":
|
|
2464
|
-
return _context26.stop();
|
|
2465
|
-
}
|
|
2466
|
-
}, _callee26, this);
|
|
2467
|
-
}));
|
|
2468
|
-
function handlePaymentSuccess(_x24) {
|
|
2469
|
-
return _handlePaymentSuccess.apply(this, arguments);
|
|
2470
|
-
}
|
|
2471
|
-
return handlePaymentSuccess;
|
|
2472
|
-
}()
|
|
2473
|
-
/**
|
|
2474
|
-
* 处理支付错误
|
|
2475
|
-
*/
|
|
2476
|
-
)
|
|
2477
|
-
}, {
|
|
2478
|
-
key: "handlePaymentError",
|
|
2479
|
-
value: (function () {
|
|
2480
|
-
var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(data) {
|
|
2481
|
-
var _this$store$currentOr22;
|
|
2482
|
-
var error;
|
|
2483
|
-
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
2484
|
-
while (1) switch (_context27.prev = _context27.next) {
|
|
2485
|
-
case 0:
|
|
2486
|
-
error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
|
|
2487
|
-
_context27.next = 3;
|
|
2488
|
-
return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
|
|
2489
|
-
case 3:
|
|
2490
|
-
_context27.next = 5;
|
|
2491
|
-
return this.core.effects.emit("".concat(this.name, ":onPaymentFailed"), {
|
|
2492
|
-
orderUuid: data.orderUuid,
|
|
2493
|
-
paymentMethodCode: '',
|
|
2494
|
-
amount: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.total_amount) || '0',
|
|
2495
|
-
timestamp: data.timestamp
|
|
2496
|
-
});
|
|
2497
|
-
case 5:
|
|
2498
|
-
case "end":
|
|
2499
|
-
return _context27.stop();
|
|
2500
|
-
}
|
|
2501
|
-
}, _callee27, this);
|
|
2502
|
-
}));
|
|
2503
|
-
function handlePaymentError(_x25) {
|
|
2504
|
-
return _handlePaymentError.apply(this, arguments);
|
|
2505
|
-
}
|
|
2506
|
-
return handlePaymentError;
|
|
2507
|
-
}()
|
|
2508
|
-
/**
|
|
2509
|
-
* 验证结账参数
|
|
2510
|
-
*/
|
|
2511
|
-
)
|
|
2512
|
-
}, {
|
|
2513
|
-
key: "validateCheckoutParams",
|
|
2514
|
-
value: function validateCheckoutParams(params) {
|
|
2515
|
-
return validateCheckoutData(params);
|
|
2516
|
-
}
|
|
2517
|
-
|
|
2518
|
-
/**
|
|
2519
|
-
* 处理现金支付项的找零逻辑
|
|
2520
|
-
*
|
|
2521
|
-
* @param paymentItem 原始支付项
|
|
2522
|
-
* @returns 处理后的支付项(包含找零信息)
|
|
2523
|
-
*/
|
|
2524
|
-
}, {
|
|
2525
|
-
key: "processCashPaymentItem",
|
|
2526
|
-
value: (function () {
|
|
2527
|
-
var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(paymentItem) {
|
|
2528
|
-
var cashPayment, remainingAmountStr, remainingAmount, cashAmount, changeAmount, processedPaymentItem;
|
|
2529
|
-
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
2530
|
-
while (1) switch (_context28.prev = _context28.next) {
|
|
2531
|
-
case 0:
|
|
2532
|
-
// 检查是否是现金支付
|
|
2533
|
-
cashPayment = isCashPayment(paymentItem.code, paymentItem.type);
|
|
2534
|
-
if (cashPayment) {
|
|
2535
|
-
_context28.next = 3;
|
|
2536
|
-
break;
|
|
2537
|
-
}
|
|
2538
|
-
return _context28.abrupt("return", paymentItem);
|
|
2539
|
-
case 3:
|
|
2540
|
-
_context28.prev = 3;
|
|
2541
|
-
_context28.next = 6;
|
|
2542
|
-
return this.calculateRemainingAmountAsync();
|
|
2543
|
-
case 6:
|
|
2544
|
-
remainingAmountStr = _context28.sent;
|
|
2545
|
-
remainingAmount = new Decimal(remainingAmountStr);
|
|
2546
|
-
cashAmount = new Decimal(String(paymentItem.amount)); // 如果现金金额小于等于剩余待付金额,无需找零
|
|
2547
|
-
if (!cashAmount.lte(remainingAmount)) {
|
|
2548
|
-
_context28.next = 11;
|
|
2549
|
-
break;
|
|
2550
|
-
}
|
|
2551
|
-
return _context28.abrupt("return", paymentItem);
|
|
2552
|
-
case 11:
|
|
2553
|
-
// 使用 Decimal.js 安全计算找零金额
|
|
2554
|
-
changeAmount = cashAmount.sub(remainingAmount); // 如果还有 rounding_amount 的配置,要判断是否和 changeAmount 相等
|
|
2555
|
-
if (!(Number(paymentItem.rounding_amount) > 0)) {
|
|
2556
|
-
_context28.next = 18;
|
|
2557
|
-
break;
|
|
2558
|
-
}
|
|
2559
|
-
if (!(Number(paymentItem.rounding_amount) === changeAmount.toNumber())) {
|
|
2560
|
-
_context28.next = 17;
|
|
2561
|
-
break;
|
|
2562
|
-
}
|
|
2563
|
-
return _context28.abrupt("return", paymentItem);
|
|
2564
|
-
case 17:
|
|
2565
|
-
// 如果不等于,则remainingAmount需要加上 rounding_amount,避免这里被改为未舍入金额
|
|
2566
|
-
remainingAmount = remainingAmount.add(new Decimal(paymentItem.rounding_amount || '0'));
|
|
2567
|
-
case 18:
|
|
2568
|
-
// 创建包含找零信息的支付项
|
|
2569
|
-
processedPaymentItem = _objectSpread(_objectSpread({}, paymentItem), {}, {
|
|
2570
|
-
amount: remainingAmount.toFixed(2),
|
|
2571
|
-
// 将 amount 设置为剩余待付金额,保留2位小数
|
|
2572
|
-
metadata: _objectSpread(_objectSpread({}, paymentItem.metadata), {}, {
|
|
2573
|
-
actual_paid_amount: cashAmount.toNumber(),
|
|
2574
|
-
// 实付金额
|
|
2575
|
-
change_given_amount: changeAmount.toNumber() // 找零金额
|
|
2576
|
-
})
|
|
2577
|
-
});
|
|
2578
|
-
this.logInfo('Cash payment with change processed', {
|
|
2579
|
-
originalAmount: cashAmount.toFixed(2),
|
|
2580
|
-
chargedAmount: remainingAmount.toFixed(2),
|
|
2581
|
-
changeAmount: changeAmount.toFixed(2),
|
|
2582
|
-
paymentCode: paymentItem.code,
|
|
2583
|
-
paymentType: paymentItem.type,
|
|
2584
|
-
// 额外的精度验证信息
|
|
2585
|
-
decimalPrecisionCheck: {
|
|
2586
|
-
cashAmountPrecise: cashAmount.toString(),
|
|
2587
|
-
remainingAmountPrecise: remainingAmount.toString(),
|
|
2588
|
-
changeAmountPrecise: changeAmount.toString()
|
|
2589
|
-
}
|
|
2590
|
-
});
|
|
2591
|
-
return _context28.abrupt("return", processedPaymentItem);
|
|
2592
|
-
case 23:
|
|
2593
|
-
_context28.prev = 23;
|
|
2594
|
-
_context28.t0 = _context28["catch"](3);
|
|
2595
|
-
this.logError('处理现金支付项时出错:', _context28.t0);
|
|
2596
|
-
// 出错时返回原始支付项,避免中断支付流程
|
|
2597
|
-
return _context28.abrupt("return", paymentItem);
|
|
2598
|
-
case 27:
|
|
2599
|
-
case "end":
|
|
2600
|
-
return _context28.stop();
|
|
2601
|
-
}
|
|
2602
|
-
}, _callee28, this, [[3, 23]]);
|
|
2603
|
-
}));
|
|
2604
|
-
function processCashPaymentItem(_x26) {
|
|
2605
|
-
return _processCashPaymentItem.apply(this, arguments);
|
|
2606
|
-
}
|
|
2607
|
-
return processCashPaymentItem;
|
|
2608
|
-
}()
|
|
2609
|
-
/**
|
|
2610
|
-
* 预加载支付方式(在初始化时调用)
|
|
2611
|
-
*/
|
|
2612
|
-
)
|
|
2613
|
-
}, {
|
|
2614
|
-
key: "preloadPaymentMethods",
|
|
2615
|
-
value: (function () {
|
|
2616
|
-
var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
2617
|
-
var methods;
|
|
2618
|
-
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
2619
|
-
while (1) switch (_context29.prev = _context29.next) {
|
|
2620
|
-
case 0:
|
|
2621
|
-
_context29.prev = 0;
|
|
2622
|
-
console.log('[Checkout] 预加载支付方式...');
|
|
2623
|
-
_context29.next = 4;
|
|
2624
|
-
return this.payment.getPayMethodListAsync();
|
|
2625
|
-
case 4:
|
|
2626
|
-
methods = _context29.sent;
|
|
2627
|
-
this.store.paymentMethods = methods;
|
|
2628
|
-
console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
|
|
2629
|
-
_context29.next = 13;
|
|
2630
|
-
break;
|
|
2631
|
-
case 9:
|
|
2632
|
-
_context29.prev = 9;
|
|
2633
|
-
_context29.t0 = _context29["catch"](0);
|
|
2634
|
-
console.error('[Checkout] 预加载支付方式失败:', _context29.t0);
|
|
2635
|
-
this.store.paymentMethods = [];
|
|
2636
|
-
case 13:
|
|
2637
|
-
case "end":
|
|
2638
|
-
return _context29.stop();
|
|
2639
|
-
}
|
|
2640
|
-
}, _callee29, this, [[0, 9]]);
|
|
2641
|
-
}));
|
|
2642
|
-
function preloadPaymentMethods() {
|
|
2643
|
-
return _preloadPaymentMethods.apply(this, arguments);
|
|
2644
|
-
}
|
|
2645
|
-
return preloadPaymentMethods;
|
|
2646
|
-
}()
|
|
2647
|
-
/**
|
|
2648
|
-
* 清理过期的已同步订单数据
|
|
2649
|
-
*
|
|
2650
|
-
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
2651
|
-
*/
|
|
2652
|
-
)
|
|
2653
|
-
}, {
|
|
2654
|
-
key: "cleanupExpiredOrdersAsync",
|
|
2655
|
-
value: (function () {
|
|
2656
|
-
var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
2657
|
-
var cleanupConfig, isCleanupEnabled, retentionDays, maxOrdersToDelete, allOrders, thresholdDate, deletedCount, ordersToDelete, _iterator, _step, order, _order$order_info, _order$order_info2, isSynced, orderCreatedAt, actualOrdersToDelete, _iterator2, _step2, orderInfo, summary, errorMessage;
|
|
2658
|
-
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
2659
|
-
while (1) switch (_context30.prev = _context30.next) {
|
|
2660
|
-
case 0:
|
|
2661
|
-
_context30.prev = 0;
|
|
2662
|
-
// 检查是否启用了清理功能
|
|
2663
|
-
cleanupConfig = this.otherParams.orderDataCleanup || {};
|
|
2664
|
-
isCleanupEnabled = cleanupConfig.enabled !== false; // 默认启用
|
|
2665
|
-
retentionDays = cleanupConfig.retentionDays || 7; // 默认保留7天
|
|
2666
|
-
maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100; // 默认最多删除100个订单
|
|
2667
|
-
if (isCleanupEnabled) {
|
|
2668
|
-
_context30.next = 8;
|
|
2669
|
-
break;
|
|
2670
|
-
}
|
|
2671
|
-
console.log('[Checkout] 订单数据清理功能已禁用');
|
|
2672
|
-
return _context30.abrupt("return");
|
|
2673
|
-
case 8:
|
|
2674
|
-
console.log("[Checkout] \u5F00\u59CB\u6E05\u7406\u8FC7\u671F\u8BA2\u5355\u6570\u636E\uFF08\u4FDD\u7559 ".concat(retentionDays, " \u5929\u5185\u7684\u6570\u636E\uFF09..."));
|
|
2675
|
-
|
|
2676
|
-
// 获取所有订单
|
|
2677
|
-
_context30.next = 11;
|
|
2678
|
-
return this.payment.getOrderListAsync();
|
|
2679
|
-
case 11:
|
|
2680
|
-
allOrders = _context30.sent;
|
|
2681
|
-
if (!(!allOrders || allOrders.length === 0)) {
|
|
2682
|
-
_context30.next = 15;
|
|
2683
|
-
break;
|
|
2684
|
-
}
|
|
2685
|
-
console.log('[Checkout] 没有找到需要清理的订单数据');
|
|
2686
|
-
return _context30.abrupt("return");
|
|
2687
|
-
case 15:
|
|
2688
|
-
thresholdDate = new Date();
|
|
2689
|
-
thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
|
|
2690
|
-
deletedCount = 0;
|
|
2691
|
-
ordersToDelete = [];
|
|
2692
|
-
_iterator = _createForOfIteratorHelper(allOrders);
|
|
2693
|
-
_context30.prev = 20;
|
|
2694
|
-
_iterator.s();
|
|
2695
|
-
case 22:
|
|
2696
|
-
if ((_step = _iterator.n()).done) {
|
|
2697
|
-
_context30.next = 41;
|
|
2698
|
-
break;
|
|
2699
|
-
}
|
|
2700
|
-
order = _step.value;
|
|
2701
|
-
_context30.prev = 24;
|
|
2702
|
-
// 检查订单是否已同步(订单ID不是虚拟ID)
|
|
2703
|
-
isSynced = order.order_id && !isVirtualOrderId(order.order_id);
|
|
2704
|
-
if (isSynced) {
|
|
2705
|
-
_context30.next = 28;
|
|
2706
|
-
break;
|
|
2707
|
-
}
|
|
2708
|
-
return _context30.abrupt("continue", 39);
|
|
2709
|
-
case 28:
|
|
2710
|
-
// 检查创建时间
|
|
2711
|
-
orderCreatedAt = null; // 尝试从 order_info.created_at 获取创建时间
|
|
2712
|
-
if ((_order$order_info = order.order_info) !== null && _order$order_info !== void 0 && _order$order_info.created_at) {
|
|
2713
|
-
orderCreatedAt = new Date(order.order_info.created_at);
|
|
2714
|
-
}
|
|
2715
|
-
// 如果没有,尝试从 order_info.original_order_data.created_at 获取
|
|
2716
|
-
else if ((_order$order_info2 = order.order_info) !== null && _order$order_info2 !== void 0 && (_order$order_info2 = _order$order_info2.original_order_data) !== null && _order$order_info2 !== void 0 && _order$order_info2.created_at) {
|
|
2717
|
-
orderCreatedAt = new Date(order.order_info.original_order_data.created_at);
|
|
2718
|
-
}
|
|
2719
|
-
|
|
2720
|
-
// 如果无法获取创建时间,跳过此订单
|
|
2721
|
-
if (!(!orderCreatedAt || isNaN(orderCreatedAt.getTime()))) {
|
|
2722
|
-
_context30.next = 32;
|
|
2723
|
-
break;
|
|
2724
|
-
}
|
|
2725
|
-
return _context30.abrupt("continue", 39);
|
|
2726
|
-
case 32:
|
|
2727
|
-
// 检查是否超过指定天数
|
|
2728
|
-
if (orderCreatedAt < thresholdDate) {
|
|
2729
|
-
ordersToDelete.push({
|
|
2730
|
-
uuid: order.uuid,
|
|
2731
|
-
orderId: order.order_id,
|
|
2732
|
-
createdAt: orderCreatedAt.toISOString(),
|
|
2733
|
-
daysSinceCreated: Math.floor((Date.now() - orderCreatedAt.getTime()) / (1000 * 60 * 60 * 24))
|
|
2734
|
-
});
|
|
2735
|
-
}
|
|
2736
|
-
_context30.next = 39;
|
|
2737
|
-
break;
|
|
2738
|
-
case 35:
|
|
2739
|
-
_context30.prev = 35;
|
|
2740
|
-
_context30.t0 = _context30["catch"](24);
|
|
2741
|
-
console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context30.t0);
|
|
2742
|
-
return _context30.abrupt("continue", 39);
|
|
2743
|
-
case 39:
|
|
2744
|
-
_context30.next = 22;
|
|
2745
|
-
break;
|
|
2746
|
-
case 41:
|
|
2747
|
-
_context30.next = 46;
|
|
2748
|
-
break;
|
|
2749
|
-
case 43:
|
|
2750
|
-
_context30.prev = 43;
|
|
2751
|
-
_context30.t1 = _context30["catch"](20);
|
|
2752
|
-
_iterator.e(_context30.t1);
|
|
2753
|
-
case 46:
|
|
2754
|
-
_context30.prev = 46;
|
|
2755
|
-
_iterator.f();
|
|
2756
|
-
return _context30.finish(46);
|
|
2757
|
-
case 49:
|
|
2758
|
-
// 按创建时间排序(最老的先删除)并限制删除数量
|
|
2759
|
-
ordersToDelete.sort(function (a, b) {
|
|
2760
|
-
return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
|
|
2761
|
-
});
|
|
2762
|
-
actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete); // 删除符合条件的订单
|
|
2763
|
-
_iterator2 = _createForOfIteratorHelper(actualOrdersToDelete);
|
|
2764
|
-
_context30.prev = 52;
|
|
2765
|
-
_iterator2.s();
|
|
2766
|
-
case 54:
|
|
2767
|
-
if ((_step2 = _iterator2.n()).done) {
|
|
2768
|
-
_context30.next = 68;
|
|
2769
|
-
break;
|
|
2770
|
-
}
|
|
2771
|
-
orderInfo = _step2.value;
|
|
2772
|
-
_context30.prev = 56;
|
|
2773
|
-
_context30.next = 59;
|
|
2774
|
-
return this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
2775
|
-
case 59:
|
|
2776
|
-
deletedCount++;
|
|
2777
|
-
console.log("[Checkout] \u5DF2\u5220\u9664\u8FC7\u671F\u8BA2\u5355: ".concat(orderInfo.orderId, " (").concat(orderInfo.daysSinceCreated, " \u5929\u524D\u521B\u5EFA)"));
|
|
2778
|
-
_context30.next = 66;
|
|
2779
|
-
break;
|
|
2780
|
-
case 63:
|
|
2781
|
-
_context30.prev = 63;
|
|
2782
|
-
_context30.t2 = _context30["catch"](56);
|
|
2783
|
-
console.error("[Checkout] \u5220\u9664\u8BA2\u5355 ".concat(orderInfo.uuid, " \u5931\u8D25:"), _context30.t2);
|
|
2784
|
-
case 66:
|
|
2785
|
-
_context30.next = 54;
|
|
2786
|
-
break;
|
|
2787
|
-
case 68:
|
|
2788
|
-
_context30.next = 73;
|
|
2789
|
-
break;
|
|
2790
|
-
case 70:
|
|
2791
|
-
_context30.prev = 70;
|
|
2792
|
-
_context30.t3 = _context30["catch"](52);
|
|
2793
|
-
_iterator2.e(_context30.t3);
|
|
2794
|
-
case 73:
|
|
2795
|
-
_context30.prev = 73;
|
|
2796
|
-
_iterator2.f();
|
|
2797
|
-
return _context30.finish(73);
|
|
2798
|
-
case 76:
|
|
2799
|
-
summary = {
|
|
2800
|
-
totalOrders: allOrders.length,
|
|
2801
|
-
expiredSyncedOrders: ordersToDelete.length,
|
|
2802
|
-
maxOrdersToDelete: maxOrdersToDelete,
|
|
2803
|
-
actualDeletedOrders: deletedCount,
|
|
2804
|
-
retentionDays: retentionDays,
|
|
2805
|
-
cleanupDate: new Date().toISOString(),
|
|
2806
|
-
thresholdDate: thresholdDate.toISOString(),
|
|
2807
|
-
skippedOrders: Math.max(0, ordersToDelete.length - maxOrdersToDelete)
|
|
2808
|
-
}; // 记录清理结果
|
|
2809
|
-
this.logInfo('Expired orders cleanup completed', summary);
|
|
2810
|
-
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
2811
|
-
console.log("[Checkout] \u8FC7\u671F\u8BA2\u5355\u6E05\u7406\u5B8C\u6210: \u603B\u8BA1 ".concat(allOrders.length, " \u4E2A\u8BA2\u5355\uFF0C\u53D1\u73B0 ").concat(ordersToDelete.length, " \u4E2A\u8FC7\u671F\u5DF2\u540C\u6B65\u8BA2\u5355\uFF0C\u5220\u9664\u4E86 ").concat(deletedCount, " \u4E2A\uFF08\u9650\u5236\u4E3A ").concat(maxOrdersToDelete, " \u4E2A\uFF09"));
|
|
2812
|
-
} else {
|
|
2813
|
-
console.log("[Checkout] \u8FC7\u671F\u8BA2\u5355\u6E05\u7406\u5B8C\u6210: \u603B\u8BA1 ".concat(allOrders.length, " \u4E2A\u8BA2\u5355\uFF0C\u5220\u9664\u4E86 ").concat(deletedCount, " \u4E2A\u8FC7\u671F\u5DF2\u540C\u6B65\u8BA2\u5355"));
|
|
2814
|
-
}
|
|
2815
|
-
_context30.next = 86;
|
|
2816
|
-
break;
|
|
2817
|
-
case 81:
|
|
2818
|
-
_context30.prev = 81;
|
|
2819
|
-
_context30.t4 = _context30["catch"](0);
|
|
2820
|
-
errorMessage = _context30.t4 instanceof Error ? _context30.t4.message : String(_context30.t4);
|
|
2821
|
-
console.error('[Checkout] 清理过期订单数据失败:', _context30.t4);
|
|
2822
|
-
this.logError('Expired orders cleanup failed', {
|
|
2823
|
-
error: errorMessage
|
|
2824
|
-
});
|
|
2825
|
-
case 86:
|
|
2826
|
-
case "end":
|
|
2827
|
-
return _context30.stop();
|
|
2828
|
-
}
|
|
2829
|
-
}, _callee30, this, [[0, 81], [20, 43, 46, 49], [24, 35], [52, 70, 73, 76], [56, 63]]);
|
|
2830
|
-
}));
|
|
2831
|
-
function cleanupExpiredOrdersAsync() {
|
|
2832
|
-
return _cleanupExpiredOrdersAsync.apply(this, arguments);
|
|
2833
|
-
}
|
|
2834
|
-
return cleanupExpiredOrdersAsync;
|
|
2835
|
-
}()
|
|
2836
|
-
/**
|
|
2837
|
-
* 清除计算缓存
|
|
2838
|
-
*/
|
|
2839
|
-
)
|
|
2840
|
-
}, {
|
|
2841
|
-
key: "clearCalculationCache",
|
|
2842
|
-
value: function clearCalculationCache() {
|
|
2843
|
-
this.calculationCache = {};
|
|
2844
|
-
}
|
|
2845
|
-
|
|
2846
|
-
/**
|
|
2847
|
-
* 批量获取订单数据(用于性能优化)
|
|
2848
|
-
* 一次性获取所有需要的数据,避免重复查询
|
|
2849
|
-
*/
|
|
2850
|
-
}, {
|
|
2851
|
-
key: "fetchOrderDataBatch",
|
|
2852
|
-
value: (function () {
|
|
2853
|
-
var _fetchOrderDataBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
|
|
2854
|
-
var orderUuid, now, cacheValid, _yield$Promise$all, _yield$Promise$all2, paymentItems, currentOrder;
|
|
2855
|
-
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
2856
|
-
while (1) switch (_context31.prev = _context31.next) {
|
|
2857
|
-
case 0:
|
|
2858
|
-
if (this.store.currentOrder) {
|
|
2859
|
-
_context31.next = 2;
|
|
2860
|
-
break;
|
|
2861
|
-
}
|
|
2862
|
-
return _context31.abrupt("return", {
|
|
2863
|
-
paymentItems: [],
|
|
2864
|
-
currentOrder: null
|
|
2865
|
-
});
|
|
2866
|
-
case 2:
|
|
2867
|
-
orderUuid = this.store.currentOrder.uuid; // 检查缓存是否有效(5秒内的缓存认为有效)
|
|
2868
|
-
now = Date.now();
|
|
2869
|
-
cacheValid = this.calculationCache.orderUuid === orderUuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5000;
|
|
2870
|
-
if (!(cacheValid && this.calculationCache.paymentItems && this.calculationCache.currentOrder)) {
|
|
2871
|
-
_context31.next = 7;
|
|
2872
|
-
break;
|
|
2873
|
-
}
|
|
2874
|
-
return _context31.abrupt("return", {
|
|
2875
|
-
paymentItems: this.calculationCache.paymentItems,
|
|
2876
|
-
currentOrder: this.calculationCache.currentOrder
|
|
2877
|
-
});
|
|
2878
|
-
case 7:
|
|
2879
|
-
_context31.next = 9;
|
|
2880
|
-
return Promise.all([this.payment.getPaymentItemsAsync(orderUuid, false), this.payment.getPaymentOrderByUuidAsync(orderUuid)]);
|
|
2881
|
-
case 9:
|
|
2882
|
-
_yield$Promise$all = _context31.sent;
|
|
2883
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2884
|
-
paymentItems = _yield$Promise$all2[0];
|
|
2885
|
-
currentOrder = _yield$Promise$all2[1];
|
|
2886
|
-
// 更新缓存
|
|
2887
|
-
this.calculationCache = {
|
|
2888
|
-
paymentItems: paymentItems,
|
|
2889
|
-
currentOrder: currentOrder,
|
|
2890
|
-
orderUuid: orderUuid,
|
|
2891
|
-
timestamp: now
|
|
2892
|
-
};
|
|
2893
|
-
return _context31.abrupt("return", {
|
|
2894
|
-
paymentItems: paymentItems,
|
|
2895
|
-
currentOrder: currentOrder
|
|
2896
|
-
});
|
|
2897
|
-
case 15:
|
|
2898
|
-
case "end":
|
|
2899
|
-
return _context31.stop();
|
|
2900
|
-
}
|
|
2901
|
-
}, _callee31, this);
|
|
2902
|
-
}));
|
|
2903
|
-
function fetchOrderDataBatch() {
|
|
2904
|
-
return _fetchOrderDataBatch.apply(this, arguments);
|
|
2905
|
-
}
|
|
2906
|
-
return fetchOrderDataBatch;
|
|
2907
|
-
}()
|
|
2908
|
-
/**
|
|
2909
|
-
* 从支付项数组计算已支付金额(纯计算,不查询数据库)
|
|
2910
|
-
*/
|
|
2911
|
-
)
|
|
2912
|
-
}, {
|
|
2913
|
-
key: "calculatePaidAmountFromItems",
|
|
2914
|
-
value: function calculatePaidAmountFromItems(payments) {
|
|
2915
|
-
// 使用 Decimal.js 进行安全的金额计算
|
|
2916
|
-
var paidAmount = payments.filter(function (payment) {
|
|
2917
|
-
return payment.status !== 'voided';
|
|
2918
|
-
}) // 只计算未撤销的支付项
|
|
2919
|
-
.reduce(function (sum, payment) {
|
|
2920
|
-
var amount = new Decimal(payment.amount || '0');
|
|
2921
|
-
var roundingAmount = new Decimal(payment.rounding_amount || '0');
|
|
2922
|
-
|
|
2923
|
-
// 使用 Decimal.js 计算实际支付有效金额:
|
|
2924
|
-
// 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
|
|
2925
|
-
// 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
|
|
2926
|
-
var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
2927
|
-
return sum.add(effectiveAmount);
|
|
2928
|
-
}, new Decimal(0));
|
|
2929
|
-
return paidAmount.toFixed(2);
|
|
2930
|
-
}
|
|
2931
|
-
|
|
2932
|
-
/**
|
|
2933
|
-
* 计算已支付金额(从 Payment 模块获取最新数据)
|
|
2934
|
-
*
|
|
2935
|
-
* 注意:此方法保持独立性,可以单独调用。
|
|
2936
|
-
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
2937
|
-
*/
|
|
2938
|
-
}, {
|
|
2939
|
-
key: "calculatePaidAmountAsync",
|
|
2940
|
-
value: (function () {
|
|
2941
|
-
var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
|
|
2942
|
-
var now, cacheValid, payments, result;
|
|
2943
|
-
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
2944
|
-
while (1) switch (_context32.prev = _context32.next) {
|
|
2945
|
-
case 0:
|
|
2946
|
-
if (this.store.currentOrder) {
|
|
2947
|
-
_context32.next = 3;
|
|
2948
|
-
break;
|
|
2949
|
-
}
|
|
2950
|
-
this.logWarning('[Checkout] calculatePaidAmountAsync: 没有当前订单');
|
|
2951
|
-
return _context32.abrupt("return", '0.00');
|
|
2952
|
-
case 3:
|
|
2953
|
-
_context32.prev = 3;
|
|
2954
|
-
// 检查是否有缓存的已支付金额
|
|
2955
|
-
now = Date.now();
|
|
2956
|
-
cacheValid = this.calculationCache.orderUuid === this.store.currentOrder.uuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5000 && this.calculationCache.paidAmount;
|
|
2957
|
-
if (!(cacheValid && this.calculationCache.paidAmount)) {
|
|
2958
|
-
_context32.next = 8;
|
|
2959
|
-
break;
|
|
2960
|
-
}
|
|
2961
|
-
return _context32.abrupt("return", this.calculationCache.paidAmount);
|
|
2962
|
-
case 8:
|
|
2963
|
-
_context32.next = 10;
|
|
2964
|
-
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
|
|
2965
|
-
);
|
|
2966
|
-
case 10:
|
|
2967
|
-
payments = _context32.sent;
|
|
2968
|
-
result = this.calculatePaidAmountFromItems(payments); // 更新缓存
|
|
2969
|
-
this.calculationCache.paidAmount = result;
|
|
2970
|
-
this.logInfo('calculatePaidAmountAsync: 计算结果 =', result);
|
|
2971
|
-
return _context32.abrupt("return", result);
|
|
2972
|
-
case 17:
|
|
2973
|
-
_context32.prev = 17;
|
|
2974
|
-
_context32.t0 = _context32["catch"](3);
|
|
2975
|
-
this.logError('calculatePaidAmountAsync 失败:', _context32.t0);
|
|
2976
|
-
return _context32.abrupt("return", '0.00');
|
|
2977
|
-
case 21:
|
|
2978
|
-
case "end":
|
|
2979
|
-
return _context32.stop();
|
|
2980
|
-
}
|
|
2981
|
-
}, _callee32, this, [[3, 17]]);
|
|
2982
|
-
}));
|
|
2983
|
-
function calculatePaidAmountAsync() {
|
|
2984
|
-
return _calculatePaidAmountAsync.apply(this, arguments);
|
|
2985
|
-
}
|
|
2986
|
-
return calculatePaidAmountAsync;
|
|
2987
|
-
}()
|
|
2988
|
-
/**
|
|
2989
|
-
* 从订单和支付项计算剩余金额(纯计算,不查询数据库)
|
|
2990
|
-
*/
|
|
2991
|
-
)
|
|
2992
|
-
}, {
|
|
2993
|
-
key: "calculateRemainingAmountFromData",
|
|
2994
|
-
value: function calculateRemainingAmountFromData(currentOrder, paidAmount) {
|
|
2995
|
-
// 使用 Decimal.js 进行安全的金额计算
|
|
2996
|
-
var totalAmount = new Decimal(currentOrder.total_amount || '0');
|
|
2997
|
-
|
|
2998
|
-
// 如果是定金订单,使用定金金额
|
|
2999
|
-
if (currentOrder.is_deposit && currentOrder.deposit_amount && Number(currentOrder.deposit_amount) > 0) {
|
|
3000
|
-
totalAmount = new Decimal(currentOrder.deposit_amount);
|
|
3001
|
-
}
|
|
3002
|
-
var paid = new Decimal(paidAmount);
|
|
3003
|
-
var remainingAmount = totalAmount.sub(paid);
|
|
3004
|
-
|
|
3005
|
-
// 确保剩余金额不为负数
|
|
3006
|
-
return Decimal.max(0, remainingAmount).toFixed(2);
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
/**
|
|
3010
|
-
* 从订单和支付项计算剩余总金额(纯计算,排除定金)
|
|
3011
|
-
*/
|
|
3012
|
-
}, {
|
|
3013
|
-
key: "calculateRemainingTotalAmountFromData",
|
|
3014
|
-
value: function calculateRemainingTotalAmountFromData(currentOrder, paidAmount) {
|
|
3015
|
-
// 始终使用订单总金额,不进行定金相关的计算
|
|
3016
|
-
var totalAmount = new Decimal(currentOrder.total_amount || '0');
|
|
3017
|
-
var paid = new Decimal(paidAmount);
|
|
3018
|
-
var remainingAmount = totalAmount.sub(paid);
|
|
3019
|
-
|
|
3020
|
-
// 确保剩余金额不为负数
|
|
3021
|
-
return Decimal.max(0, remainingAmount).toFixed(2);
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
/**
|
|
3025
|
-
* 计算剩余未支付金额(从 Payment 模块获取最新数据)
|
|
3026
|
-
*
|
|
3027
|
-
* 注意:此方法保持独立性,可以单独调用。
|
|
3028
|
-
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
3029
|
-
*/
|
|
3030
|
-
}, {
|
|
3031
|
-
key: "calculateRemainingAmountAsync",
|
|
3032
|
-
value: (function () {
|
|
3033
|
-
var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
3034
|
-
var _yield$this$fetchOrde, currentOrder, paidAmountStr, result;
|
|
3035
|
-
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
3036
|
-
while (1) switch (_context33.prev = _context33.next) {
|
|
3037
|
-
case 0:
|
|
3038
|
-
if (this.store.currentOrder) {
|
|
3039
|
-
_context33.next = 3;
|
|
3040
|
-
break;
|
|
3041
|
-
}
|
|
3042
|
-
this.logWarning('calculateRemainingAmountAsync: 没有当前订单');
|
|
3043
|
-
return _context33.abrupt("return", '0.00');
|
|
3044
|
-
case 3:
|
|
3045
|
-
_context33.next = 5;
|
|
3046
|
-
return this.fetchOrderDataBatch();
|
|
3047
|
-
case 5:
|
|
3048
|
-
_yield$this$fetchOrde = _context33.sent;
|
|
3049
|
-
currentOrder = _yield$this$fetchOrde.currentOrder;
|
|
3050
|
-
if (currentOrder) {
|
|
3051
|
-
_context33.next = 9;
|
|
3052
|
-
break;
|
|
3053
|
-
}
|
|
3054
|
-
return _context33.abrupt("return", '0.00');
|
|
3055
|
-
case 9:
|
|
3056
|
-
_context33.next = 11;
|
|
3057
|
-
return this.calculatePaidAmountAsync();
|
|
3058
|
-
case 11:
|
|
3059
|
-
paidAmountStr = _context33.sent;
|
|
3060
|
-
result = this.calculateRemainingAmountFromData(currentOrder, paidAmountStr);
|
|
3061
|
-
this.logInfo('calculateRemainingAmountAsync: 计算=', result);
|
|
3062
|
-
return _context33.abrupt("return", result);
|
|
3063
|
-
case 15:
|
|
3064
|
-
case "end":
|
|
3065
|
-
return _context33.stop();
|
|
3066
|
-
}
|
|
3067
|
-
}, _callee33, this);
|
|
3068
|
-
}));
|
|
3069
|
-
function calculateRemainingAmountAsync() {
|
|
3070
|
-
return _calculateRemainingAmountAsync.apply(this, arguments);
|
|
3071
|
-
}
|
|
3072
|
-
return calculateRemainingAmountAsync;
|
|
3073
|
-
}()
|
|
3074
|
-
/**
|
|
3075
|
-
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
3076
|
-
*
|
|
3077
|
-
* 注意:此方法保持独立性,可以单独调用。
|
|
3078
|
-
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
3079
|
-
*/
|
|
3080
|
-
)
|
|
3081
|
-
}, {
|
|
3082
|
-
key: "calculateRemainingTotalAmountAsync",
|
|
3083
|
-
value: (function () {
|
|
3084
|
-
var _calculateRemainingTotalAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
|
|
3085
|
-
var _yield$this$fetchOrde2, currentOrder, paidAmountStr, result;
|
|
3086
|
-
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
3087
|
-
while (1) switch (_context34.prev = _context34.next) {
|
|
3088
|
-
case 0:
|
|
3089
|
-
if (this.store.currentOrder) {
|
|
3090
|
-
_context34.next = 3;
|
|
3091
|
-
break;
|
|
3092
|
-
}
|
|
3093
|
-
this.logWarning('calculateRemainingTotalAmountAsync: 没有当前订单');
|
|
3094
|
-
return _context34.abrupt("return", '0.00');
|
|
3095
|
-
case 3:
|
|
3096
|
-
_context34.next = 5;
|
|
3097
|
-
return this.fetchOrderDataBatch();
|
|
3098
|
-
case 5:
|
|
3099
|
-
_yield$this$fetchOrde2 = _context34.sent;
|
|
3100
|
-
currentOrder = _yield$this$fetchOrde2.currentOrder;
|
|
3101
|
-
if (currentOrder) {
|
|
3102
|
-
_context34.next = 9;
|
|
3103
|
-
break;
|
|
3104
|
-
}
|
|
3105
|
-
return _context34.abrupt("return", '0.00');
|
|
3106
|
-
case 9:
|
|
3107
|
-
_context34.next = 11;
|
|
3108
|
-
return this.calculatePaidAmountAsync();
|
|
3109
|
-
case 11:
|
|
3110
|
-
paidAmountStr = _context34.sent;
|
|
3111
|
-
result = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmountStr);
|
|
3112
|
-
this.logInfo('calculateRemainingTotalAmountAsync: 计算=', result);
|
|
3113
|
-
return _context34.abrupt("return", result);
|
|
3114
|
-
case 15:
|
|
3115
|
-
case "end":
|
|
3116
|
-
return _context34.stop();
|
|
3117
|
-
}
|
|
3118
|
-
}, _callee34, this);
|
|
3119
|
-
}));
|
|
3120
|
-
function calculateRemainingTotalAmountAsync() {
|
|
3121
|
-
return _calculateRemainingTotalAmountAsync.apply(this, arguments);
|
|
3122
|
-
}
|
|
3123
|
-
return calculateRemainingTotalAmountAsync;
|
|
3124
|
-
}()
|
|
3125
|
-
/**
|
|
3126
|
-
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
3127
|
-
*/
|
|
3128
|
-
)
|
|
3129
|
-
}, {
|
|
3130
|
-
key: "updateBalanceDueAmount",
|
|
3131
|
-
value: (function () {
|
|
3132
|
-
var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
|
|
3133
|
-
var remainingAmount, remainingTotalAmount, currentBalanceDueAmount;
|
|
3134
|
-
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
3135
|
-
while (1) switch (_context35.prev = _context35.next) {
|
|
3136
|
-
case 0:
|
|
3137
|
-
_context35.prev = 0;
|
|
3138
|
-
_context35.next = 3;
|
|
3139
|
-
return this.calculateRemainingAmountAsync();
|
|
3140
|
-
case 3:
|
|
3141
|
-
remainingAmount = _context35.sent;
|
|
3142
|
-
_context35.next = 6;
|
|
3143
|
-
return this.calculateRemainingTotalAmountAsync();
|
|
3144
|
-
case 6:
|
|
3145
|
-
remainingTotalAmount = _context35.sent;
|
|
3146
|
-
currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
|
|
3147
|
-
if (!(remainingAmount !== currentBalanceDueAmount)) {
|
|
3148
|
-
_context35.next = 15;
|
|
3149
|
-
break;
|
|
3150
|
-
}
|
|
3151
|
-
this.store.balanceDueAmount = remainingAmount;
|
|
3152
|
-
|
|
3153
|
-
// 发出 balanceDueAmount 变更事件
|
|
3154
|
-
_context35.next = 12;
|
|
3155
|
-
return this.core.effects.emit("".concat(this.name, ":onBalanceDueAmountChanged"), {
|
|
3156
|
-
oldAmount: currentBalanceDueAmount,
|
|
3157
|
-
newAmount: remainingAmount,
|
|
3158
|
-
timestamp: Date.now(),
|
|
3159
|
-
totalAmount: remainingTotalAmount
|
|
3160
|
-
});
|
|
3161
|
-
case 12:
|
|
3162
|
-
this.logInfo('balanceDueAmount 已自动更新:', {
|
|
3163
|
-
oldAmount: currentBalanceDueAmount,
|
|
3164
|
-
newAmount: remainingAmount
|
|
3165
|
-
});
|
|
3166
|
-
_context35.next = 16;
|
|
3167
|
-
break;
|
|
3168
|
-
case 15:
|
|
3169
|
-
this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
|
|
3170
|
-
balanceDueAmount: currentBalanceDueAmount,
|
|
3171
|
-
remainingAmount: remainingAmount
|
|
3172
|
-
});
|
|
3173
|
-
case 16:
|
|
3174
|
-
_context35.next = 21;
|
|
3175
|
-
break;
|
|
3176
|
-
case 18:
|
|
3177
|
-
_context35.prev = 18;
|
|
3178
|
-
_context35.t0 = _context35["catch"](0);
|
|
3179
|
-
this.logError('更新 balanceDueAmount 失败:', _context35.t0);
|
|
3180
|
-
case 21:
|
|
3181
|
-
case "end":
|
|
3182
|
-
return _context35.stop();
|
|
3183
|
-
}
|
|
3184
|
-
}, _callee35, this, [[0, 18]]);
|
|
3185
|
-
}));
|
|
3186
|
-
function updateBalanceDueAmount() {
|
|
3187
|
-
return _updateBalanceDueAmount.apply(this, arguments);
|
|
3188
|
-
}
|
|
3189
|
-
return updateBalanceDueAmount;
|
|
3190
|
-
}()
|
|
3191
|
-
/**
|
|
3192
|
-
* 更新 stateAmount 为当前剩余未支付金额
|
|
3193
|
-
*
|
|
3194
|
-
* 优化版本:批量获取数据,避免重复查询数据库
|
|
3195
|
-
*/
|
|
3196
|
-
)
|
|
3197
|
-
}, {
|
|
3198
|
-
key: "updateStateAmountToRemaining",
|
|
3199
|
-
value: (function () {
|
|
3200
|
-
var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
|
|
3201
|
-
var _this5 = this;
|
|
3202
|
-
var checkOrder,
|
|
3203
|
-
_yield$this$fetchOrde3,
|
|
3204
|
-
paymentItems,
|
|
3205
|
-
_currentOrder3,
|
|
3206
|
-
paidAmount,
|
|
3207
|
-
needUpdateDepositStatus,
|
|
3208
|
-
depositPaidAmount,
|
|
3209
|
-
remainingAmount,
|
|
3210
|
-
remainingTotalAmount,
|
|
3211
|
-
currentStateAmount,
|
|
3212
|
-
currentBalanceDueAmount,
|
|
3213
|
-
hasStateChanged,
|
|
3214
|
-
_args36 = arguments;
|
|
3215
|
-
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
3216
|
-
while (1) switch (_context36.prev = _context36.next) {
|
|
3217
|
-
case 0:
|
|
3218
|
-
checkOrder = _args36.length > 0 && _args36[0] !== undefined ? _args36[0] : true;
|
|
3219
|
-
_context36.prev = 1;
|
|
3220
|
-
if (this.store.currentOrder) {
|
|
3221
|
-
_context36.next = 4;
|
|
3222
|
-
break;
|
|
3223
|
-
}
|
|
3224
|
-
return _context36.abrupt("return");
|
|
3225
|
-
case 4:
|
|
3226
|
-
console.time('updateStateAmountToRemaining');
|
|
3227
|
-
// 🚀 性能优化:一次性批量获取所有需要的数据
|
|
3228
|
-
_context36.next = 7;
|
|
3229
|
-
return this.fetchOrderDataBatch();
|
|
3230
|
-
case 7:
|
|
3231
|
-
_yield$this$fetchOrde3 = _context36.sent;
|
|
3232
|
-
paymentItems = _yield$this$fetchOrde3.paymentItems;
|
|
3233
|
-
_currentOrder3 = _yield$this$fetchOrde3.currentOrder;
|
|
3234
|
-
console.timeEnd('updateStateAmountToRemaining');
|
|
3235
|
-
if (_currentOrder3) {
|
|
3236
|
-
_context36.next = 14;
|
|
3237
|
-
break;
|
|
3238
|
-
}
|
|
3239
|
-
this.logWarning('updateStateAmountToRemaining: 未找到当前订单');
|
|
3240
|
-
return _context36.abrupt("return");
|
|
3241
|
-
case 14:
|
|
3242
|
-
// 🚀 性能优化:一次性计算所有金额(纯计算,不查询数据库)
|
|
3243
|
-
paidAmount = this.calculatePaidAmountFromItems(paymentItems); // 缓存已支付金额,供其他方法使用
|
|
3244
|
-
this.calculationCache.paidAmount = paidAmount;
|
|
3245
|
-
|
|
3246
|
-
// 检查定金支付状态,可能需要切换支付模式
|
|
3247
|
-
needUpdateDepositStatus = false;
|
|
3248
|
-
if (_currentOrder3.is_deposit === 1) {
|
|
3249
|
-
depositPaidAmount = paymentItems.filter(function (item) {
|
|
3250
|
-
return item.order_payment_type === 'deposit' && item.status !== 'voided';
|
|
3251
|
-
}).reduce(function (sum, item) {
|
|
3252
|
-
// 如果是 wallet,并且还没同步到后端,且此时还没有其他类型的支付项(现金,eftpos,标记支付),不计入已付金额
|
|
3253
|
-
// 如果有其他支付项了,代表此时处于马上要同步的状态,所以计入
|
|
3254
|
-
if (item.voucher_id && !item.isSynced && paymentItems.filter(function (item) {
|
|
3255
|
-
return !item.voucher_id;
|
|
3256
|
-
}).length === 0) {
|
|
3257
|
-
return sum;
|
|
3258
|
-
}
|
|
3259
|
-
var amount = new Decimal(item.amount || '0');
|
|
3260
|
-
var roundingAmount = new Decimal(item.rounding_amount || '0');
|
|
3261
|
-
return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
|
|
3262
|
-
}, new Decimal(0));
|
|
3263
|
-
if (depositPaidAmount.gte(_currentOrder3.deposit_amount || '0')) {
|
|
3264
|
-
needUpdateDepositStatus = true;
|
|
3265
|
-
// 更新缓存中的订单状态
|
|
3266
|
-
_currentOrder3.is_deposit = 0;
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3269
|
-
|
|
3270
|
-
// 计算剩余金额(使用缓存的数据)
|
|
3271
|
-
remainingAmount = this.calculateRemainingAmountFromData(_currentOrder3, paidAmount);
|
|
3272
|
-
remainingTotalAmount = this.calculateRemainingTotalAmountFromData(_currentOrder3, paidAmount);
|
|
3273
|
-
currentStateAmount = this.store.stateAmount;
|
|
3274
|
-
currentBalanceDueAmount = this.store.balanceDueAmount; // 批量更新状态,减少操作次数
|
|
3275
|
-
hasStateChanged = false; // 如果需要更新定金状态
|
|
3276
|
-
if (!needUpdateDepositStatus) {
|
|
3277
|
-
_context36.next = 28;
|
|
3278
|
-
break;
|
|
3279
|
-
}
|
|
3280
|
-
this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), {}, {
|
|
3281
|
-
is_deposit: 0
|
|
3282
|
-
});
|
|
3283
|
-
_context36.next = 27;
|
|
3284
|
-
return this.payment.updateOrderAsync(this.store.currentOrder.uuid, {
|
|
3285
|
-
is_deposit: 0
|
|
3286
|
-
});
|
|
3287
|
-
case 27:
|
|
3288
|
-
hasStateChanged = true;
|
|
3289
|
-
case 28:
|
|
3290
|
-
console.time('updateStateAmountToRemaining: remainingAmount');
|
|
3291
|
-
// 更新 stateAmount
|
|
3292
|
-
if (remainingAmount !== currentStateAmount) {
|
|
3293
|
-
this.store.stateAmount = remainingAmount;
|
|
3294
|
-
hasStateChanged = true;
|
|
3295
|
-
setTimeout(function () {
|
|
3296
|
-
// 发出 stateAmount 变更事件
|
|
3297
|
-
_this5.core.effects.emit("".concat(_this5.name, ":onStateAmountChanged"), {
|
|
3298
|
-
oldAmount: currentStateAmount,
|
|
3299
|
-
newAmount: remainingAmount,
|
|
3300
|
-
timestamp: Date.now(),
|
|
3301
|
-
totalAmount: remainingTotalAmount
|
|
3302
|
-
});
|
|
3303
|
-
}, 0);
|
|
3304
|
-
this.logInfo('stateAmount 已自动更新为剩余金额:', {
|
|
3305
|
-
oldAmount: currentStateAmount,
|
|
3306
|
-
newAmount: remainingAmount
|
|
3307
|
-
});
|
|
3308
|
-
}
|
|
3309
|
-
console.timeEnd('updateStateAmountToRemaining: remainingAmount');
|
|
3310
|
-
console.time('updateStateAmountToRemaining: updateStateAmountToRemaining');
|
|
3311
|
-
// 更新 balanceDueAmount
|
|
3312
|
-
if (remainingAmount !== currentBalanceDueAmount) {
|
|
3313
|
-
this.store.balanceDueAmount = remainingAmount;
|
|
3314
|
-
hasStateChanged = true;
|
|
3315
|
-
|
|
3316
|
-
// 发出 balanceDueAmount 变更事件
|
|
3317
|
-
setTimeout(function () {
|
|
3318
|
-
_this5.core.effects.emit("".concat(_this5.name, ":onBalanceDueAmountChanged"), {
|
|
3319
|
-
oldAmount: currentBalanceDueAmount,
|
|
3320
|
-
newAmount: remainingAmount,
|
|
3321
|
-
timestamp: Date.now(),
|
|
3322
|
-
totalAmount: remainingTotalAmount
|
|
3323
|
-
});
|
|
3324
|
-
}, 0);
|
|
3325
|
-
this.logInfo('balanceDueAmount 已自动更新:', {
|
|
3326
|
-
oldAmount: currentBalanceDueAmount,
|
|
3327
|
-
newAmount: remainingAmount
|
|
3328
|
-
});
|
|
3329
|
-
}
|
|
3330
|
-
console.timeEnd('updateStateAmountToRemaining: updateStateAmountToRemaining');
|
|
3331
|
-
if (!hasStateChanged) {
|
|
3332
|
-
this.logInfo('状态无需更新,当前值已是最新:', {
|
|
3333
|
-
stateAmount: currentStateAmount,
|
|
3334
|
-
remainingAmount: remainingAmount
|
|
3335
|
-
});
|
|
3336
|
-
}
|
|
3337
|
-
|
|
3338
|
-
// 检查订单支付完成(复用已获取的数据)
|
|
3339
|
-
if (!checkOrder) {
|
|
3340
|
-
_context36.next = 40;
|
|
3341
|
-
break;
|
|
3342
|
-
}
|
|
3343
|
-
_context36.next = 38;
|
|
3344
|
-
return this.checkOrderPaymentCompletionOptimized(paymentItems, remainingAmount);
|
|
3345
|
-
case 38:
|
|
3346
|
-
_context36.next = 41;
|
|
3347
|
-
break;
|
|
3348
|
-
case 40:
|
|
3349
|
-
this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
|
|
3350
|
-
case 41:
|
|
3351
|
-
_context36.next = 46;
|
|
3352
|
-
break;
|
|
3353
|
-
case 43:
|
|
3354
|
-
_context36.prev = 43;
|
|
3355
|
-
_context36.t0 = _context36["catch"](1);
|
|
3356
|
-
this.logError('更新 stateAmount 为剩余金额失败:', _context36.t0);
|
|
3357
|
-
case 46:
|
|
3358
|
-
case "end":
|
|
3359
|
-
return _context36.stop();
|
|
3360
|
-
}
|
|
3361
|
-
}, _callee36, this, [[1, 43]]);
|
|
3362
|
-
}));
|
|
3363
|
-
function updateStateAmountToRemaining() {
|
|
3364
|
-
return _updateStateAmountToRemaining.apply(this, arguments);
|
|
3365
|
-
}
|
|
3366
|
-
return updateStateAmountToRemaining;
|
|
3367
|
-
}()
|
|
3368
|
-
/**
|
|
3369
|
-
* 检查订单支付是否完成(优化版,复用已获取的数据)
|
|
3370
|
-
*
|
|
3371
|
-
* @param paymentItems 已获取的支付项数据
|
|
3372
|
-
* @param remainingAmount 已计算的剩余金额
|
|
3373
|
-
*/
|
|
3374
|
-
)
|
|
3375
|
-
}, {
|
|
3376
|
-
key: "checkOrderPaymentCompletionOptimized",
|
|
3377
|
-
value: (function () {
|
|
3378
|
-
var _checkOrderPaymentCompletionOptimized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paymentItems, remainingAmount) {
|
|
3379
|
-
var remainingValue, totalAmount, paidAmount, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
|
|
3380
|
-
return _regeneratorRuntime().wrap(function _callee37$(_context37) {
|
|
3381
|
-
while (1) switch (_context37.prev = _context37.next) {
|
|
3382
|
-
case 0:
|
|
3383
|
-
_context37.prev = 0;
|
|
3384
|
-
if (this.store.currentOrder) {
|
|
3385
|
-
_context37.next = 3;
|
|
3386
|
-
break;
|
|
3387
|
-
}
|
|
3388
|
-
return _context37.abrupt("return");
|
|
3389
|
-
case 3:
|
|
3390
|
-
remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
|
|
3391
|
-
if (!remainingValue.lte(0)) {
|
|
3392
|
-
_context37.next = 21;
|
|
3393
|
-
break;
|
|
3394
|
-
}
|
|
3395
|
-
totalAmount = this.store.currentOrder.total_amount;
|
|
3396
|
-
paidAmount = this.calculationCache.paidAmount || '0.00';
|
|
3397
|
-
this.logInfo('检测到订单支付完成:', {
|
|
3398
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3399
|
-
orderId: this.store.currentOrder.order_id,
|
|
3400
|
-
totalAmount: totalAmount,
|
|
3401
|
-
paidAmount: paidAmount,
|
|
3402
|
-
remainingAmount: remainingAmount,
|
|
3403
|
-
isOrderSynced: this.store.isOrderSynced
|
|
3404
|
-
});
|
|
3405
|
-
|
|
3406
|
-
// 检查自动同步条件(复用已获取的支付项数据)
|
|
3407
|
-
hasPaymentItems = paymentItems.length > 0;
|
|
3408
|
-
allPaymentsHaveVoucherId = hasPaymentItems && paymentItems.every(function (item) {
|
|
3409
|
-
return item.status !== 'voided' && item.voucher_id;
|
|
3410
|
-
});
|
|
3411
|
-
shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
3412
|
-
this.logInfo('自动同步订单条件检查:', {
|
|
3413
|
-
paymentCount: paymentItems.length,
|
|
3414
|
-
hasPaymentItems: hasPaymentItems,
|
|
3415
|
-
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
3416
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
3417
|
-
shouldAutoSync: shouldAutoSync,
|
|
3418
|
-
reason: shouldAutoSync ? '支付完成,需要同步最终支付状态' : '跳过同步',
|
|
3419
|
-
paymentItems: paymentItems.map(function (p) {
|
|
3420
|
-
return {
|
|
3421
|
-
uuid: p.uuid,
|
|
3422
|
-
code: p.code,
|
|
3423
|
-
amount: p.amount,
|
|
3424
|
-
rounding_amount: p.rounding_amount,
|
|
3425
|
-
effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? '0' : p.rounding_amount || '0'))).toFixed(2),
|
|
3426
|
-
voucher_id: p.voucher_id,
|
|
3427
|
-
status: p.status
|
|
3428
|
-
};
|
|
3429
|
-
})
|
|
3430
|
-
});
|
|
3431
|
-
if (!shouldAutoSync) {
|
|
3432
|
-
_context37.next = 18;
|
|
3433
|
-
break;
|
|
3434
|
-
}
|
|
3435
|
-
this.logInfo('满足自动同步条件,开始同步订单到后端...');
|
|
3436
|
-
_context37.next = 16;
|
|
3437
|
-
return this.syncOrderToBackendWithReturn(false);
|
|
3438
|
-
case 16:
|
|
3439
|
-
_context37.next = 19;
|
|
3440
|
-
break;
|
|
3441
|
-
case 18:
|
|
3442
|
-
if (!hasPaymentItems) {
|
|
3443
|
-
this.logInfo('没有支付项,跳过订单同步');
|
|
3444
|
-
} else if (allPaymentsHaveVoucherId) {
|
|
3445
|
-
this.logInfo('所有支付项均为代金券类型,跳过订单同步');
|
|
3446
|
-
}
|
|
3447
|
-
case 19:
|
|
3448
|
-
_context37.next = 21;
|
|
3449
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderPaymentCompleted"), {
|
|
3450
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3451
|
-
orderId: this.store.currentOrder.order_id,
|
|
3452
|
-
totalAmount: totalAmount,
|
|
3453
|
-
paidAmount: paidAmount,
|
|
3454
|
-
remainingAmount: remainingAmount,
|
|
3455
|
-
timestamp: Date.now()
|
|
3456
|
-
});
|
|
3457
|
-
case 21:
|
|
3458
|
-
_context37.next = 26;
|
|
3459
|
-
break;
|
|
3460
|
-
case 23:
|
|
3461
|
-
_context37.prev = 23;
|
|
3462
|
-
_context37.t0 = _context37["catch"](0);
|
|
3463
|
-
this.logError('检查订单支付完成状态失败:', _context37.t0);
|
|
3464
|
-
case 26:
|
|
3465
|
-
case "end":
|
|
3466
|
-
return _context37.stop();
|
|
3467
|
-
}
|
|
3468
|
-
}, _callee37, this, [[0, 23]]);
|
|
3469
|
-
}));
|
|
3470
|
-
function checkOrderPaymentCompletionOptimized(_x27, _x28) {
|
|
3471
|
-
return _checkOrderPaymentCompletionOptimized.apply(this, arguments);
|
|
3472
|
-
}
|
|
3473
|
-
return checkOrderPaymentCompletionOptimized;
|
|
3474
|
-
}()
|
|
3475
|
-
/**
|
|
3476
|
-
* 检查订单支付是否完成
|
|
3477
|
-
*
|
|
3478
|
-
* 当剩余待付款金额 <= 0 时,触发订单支付完成事件
|
|
3479
|
-
*
|
|
3480
|
-
* 注意:此方法保持独立性,可以单独调用。
|
|
3481
|
-
* 在 updateStateAmountToRemaining 中会使用优化版本。
|
|
3482
|
-
*/
|
|
3483
|
-
)
|
|
3484
|
-
}, {
|
|
3485
|
-
key: "checkOrderPaymentCompletion",
|
|
3486
|
-
value: (function () {
|
|
3487
|
-
var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
|
|
3488
|
-
var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
|
|
3489
|
-
return _regeneratorRuntime().wrap(function _callee38$(_context38) {
|
|
3490
|
-
while (1) switch (_context38.prev = _context38.next) {
|
|
3491
|
-
case 0:
|
|
3492
|
-
_context38.prev = 0;
|
|
3493
|
-
if (this.store.currentOrder) {
|
|
3494
|
-
_context38.next = 3;
|
|
3495
|
-
break;
|
|
3496
|
-
}
|
|
3497
|
-
return _context38.abrupt("return");
|
|
3498
|
-
case 3:
|
|
3499
|
-
_context38.next = 5;
|
|
3500
|
-
return this.calculateRemainingAmountAsync();
|
|
3501
|
-
case 5:
|
|
3502
|
-
remainingAmount = _context38.sent;
|
|
3503
|
-
remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
|
|
3504
|
-
if (!remainingValue.lte(0)) {
|
|
3505
|
-
_context38.next = 29;
|
|
3506
|
-
break;
|
|
3507
|
-
}
|
|
3508
|
-
totalAmount = this.store.currentOrder.total_amount;
|
|
3509
|
-
_context38.next = 11;
|
|
3510
|
-
return this.calculatePaidAmountAsync();
|
|
3511
|
-
case 11:
|
|
3512
|
-
paidAmount = _context38.sent;
|
|
3513
|
-
this.logInfo('检测到订单支付完成:', {
|
|
3514
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3515
|
-
orderId: this.store.currentOrder.order_id,
|
|
3516
|
-
totalAmount: totalAmount,
|
|
3517
|
-
paidAmount: paidAmount,
|
|
3518
|
-
remainingAmount: remainingAmount,
|
|
3519
|
-
isOrderSynced: this.store.isOrderSynced
|
|
3520
|
-
});
|
|
3521
|
-
|
|
3522
|
-
// 从 Payment 模块获取最新支付项,检查自动同步条件
|
|
3523
|
-
_context38.next = 15;
|
|
3524
|
-
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
|
|
3525
|
-
);
|
|
3526
|
-
case 15:
|
|
3527
|
-
currentPayments = _context38.sent;
|
|
3528
|
-
// 检查自动同步条件:
|
|
3529
|
-
// 1. 待付金额为 0 ✓ (已在上面检查)
|
|
3530
|
-
// 2. 需要有支付项
|
|
3531
|
-
// 3. 支付项不能全是带 voucher_id 的数据
|
|
3532
|
-
hasPaymentItems = currentPayments.length > 0;
|
|
3533
|
-
allPaymentsHaveVoucherId = hasPaymentItems && currentPayments.every(function (item) {
|
|
3534
|
-
return item.status !== 'voided' && item.voucher_id;
|
|
3535
|
-
}); // 判断是否需要自动同步订单
|
|
3536
|
-
// 条件:
|
|
3537
|
-
// 1. 有支付项
|
|
3538
|
-
// 2. 不全是代金券支付
|
|
3539
|
-
// 3. 订单未同步 OR (订单已同步但支付刚完成,需要同步最终支付状态)
|
|
3540
|
-
shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
3541
|
-
this.logInfo('自动同步订单条件检查:', {
|
|
3542
|
-
paymentCount: currentPayments.length,
|
|
3543
|
-
hasPaymentItems: hasPaymentItems,
|
|
3544
|
-
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
3545
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
3546
|
-
shouldAutoSync: shouldAutoSync,
|
|
3547
|
-
reason: shouldAutoSync ? '支付完成,需要同步最终支付状态' : '跳过同步',
|
|
3548
|
-
paymentItems: currentPayments.map(function (p) {
|
|
3549
|
-
return {
|
|
3550
|
-
uuid: p.uuid,
|
|
3551
|
-
code: p.code,
|
|
3552
|
-
amount: p.amount,
|
|
3553
|
-
rounding_amount: p.rounding_amount,
|
|
3554
|
-
effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? '0' : p.rounding_amount || '0'))).toFixed(2),
|
|
3555
|
-
voucher_id: p.voucher_id,
|
|
3556
|
-
status: p.status
|
|
3557
|
-
};
|
|
3558
|
-
})
|
|
3559
|
-
});
|
|
3560
|
-
if (!shouldAutoSync) {
|
|
3561
|
-
_context38.next = 26;
|
|
3562
|
-
break;
|
|
3563
|
-
}
|
|
3564
|
-
this.logInfo('满足自动同步条件,开始同步订单到后端...');
|
|
3565
|
-
_context38.next = 24;
|
|
3566
|
-
return this.syncOrderToBackendWithReturn(false);
|
|
3567
|
-
case 24:
|
|
3568
|
-
_context38.next = 27;
|
|
3569
|
-
break;
|
|
3570
|
-
case 26:
|
|
3571
|
-
if (!hasPaymentItems) {
|
|
3572
|
-
this.logInfo('没有支付项,跳过订单同步');
|
|
3573
|
-
} else if (allPaymentsHaveVoucherId) {
|
|
3574
|
-
this.logInfo('所有支付项均为代金券类型,跳过订单同步');
|
|
3575
|
-
}
|
|
3576
|
-
case 27:
|
|
3577
|
-
_context38.next = 29;
|
|
3578
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderPaymentCompleted"), {
|
|
3579
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3580
|
-
orderId: this.store.currentOrder.order_id,
|
|
3581
|
-
totalAmount: totalAmount,
|
|
3582
|
-
paidAmount: paidAmount,
|
|
3583
|
-
remainingAmount: remainingAmount,
|
|
3584
|
-
timestamp: Date.now()
|
|
3585
|
-
});
|
|
3586
|
-
case 29:
|
|
3587
|
-
_context38.next = 34;
|
|
3588
|
-
break;
|
|
3589
|
-
case 31:
|
|
3590
|
-
_context38.prev = 31;
|
|
3591
|
-
_context38.t0 = _context38["catch"](0);
|
|
3592
|
-
this.logError('检查订单支付完成状态失败:', _context38.t0);
|
|
3593
|
-
case 34:
|
|
3594
|
-
case "end":
|
|
3595
|
-
return _context38.stop();
|
|
3596
|
-
}
|
|
3597
|
-
}, _callee38, this, [[0, 31]]);
|
|
3598
|
-
}));
|
|
3599
|
-
function checkOrderPaymentCompletion() {
|
|
3600
|
-
return _checkOrderPaymentCompletion.apply(this, arguments);
|
|
3601
|
-
}
|
|
3602
|
-
return checkOrderPaymentCompletion;
|
|
3603
|
-
}()
|
|
3604
|
-
/**
|
|
3605
|
-
* 同步订单到后端并返回真实订单ID
|
|
3606
|
-
*
|
|
3607
|
-
* @param isManual 是否为手动同步,默认为 false
|
|
3608
|
-
* @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
|
|
3609
|
-
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
3610
|
-
*/
|
|
3611
|
-
)
|
|
3612
|
-
}, {
|
|
3613
|
-
key: "syncOrderToBackendWithReturn",
|
|
3614
|
-
value: (function () {
|
|
3615
|
-
var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
|
|
3616
|
-
var _this6 = this,
|
|
3617
|
-
_this$store$currentOr23,
|
|
3618
|
-
_this$store$currentOr24,
|
|
3619
|
-
_this$store$currentCu2,
|
|
3620
|
-
_this$store$currentOr25,
|
|
3621
|
-
_this$store$localOrde,
|
|
3622
|
-
_this$store$localOrde2,
|
|
3623
|
-
_checkoutResponse3,
|
|
3624
|
-
_checkoutResponse4;
|
|
3625
|
-
var isManual,
|
|
3626
|
-
customPaymentItems,
|
|
3627
|
-
currentOrderId,
|
|
3628
|
-
isUpdateOperation,
|
|
3629
|
-
paymentItems,
|
|
3630
|
-
processedPaymentItems,
|
|
3631
|
-
finalDepositAmount,
|
|
3632
|
-
manualDepositAmount,
|
|
3633
|
-
manualDepositValue,
|
|
3634
|
-
orderParams,
|
|
3635
|
-
startTime,
|
|
3636
|
-
checkoutResponse,
|
|
3637
|
-
submitSuccess,
|
|
3638
|
-
submitError,
|
|
3639
|
-
_checkoutResponse,
|
|
3640
|
-
_checkoutResponse2,
|
|
3641
|
-
responseStatus,
|
|
3642
|
-
isSuccessResponse,
|
|
3643
|
-
_checkoutResponse5,
|
|
3644
|
-
errorMessage,
|
|
3645
|
-
realOrderId,
|
|
3646
|
-
_checkoutResponse6,
|
|
3647
|
-
extractedOrderId,
|
|
3648
|
-
_checkoutResponse7,
|
|
3649
|
-
updatedOrder,
|
|
3650
|
-
beforeManualUpdate,
|
|
3651
|
-
syncedPaymentUuids,
|
|
3652
|
-
_iterator3,
|
|
3653
|
-
_step3,
|
|
3654
|
-
paymentUuid,
|
|
3655
|
-
_args39 = arguments;
|
|
3656
|
-
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
3657
|
-
while (1) switch (_context39.prev = _context39.next) {
|
|
3658
|
-
case 0:
|
|
3659
|
-
isManual = _args39.length > 0 && _args39[0] !== undefined ? _args39[0] : false;
|
|
3660
|
-
customPaymentItems = _args39.length > 1 ? _args39[1] : undefined;
|
|
3661
|
-
if (!(!this.store.localOrderData || !this.store.currentOrder)) {
|
|
3662
|
-
_context39.next = 4;
|
|
3663
|
-
break;
|
|
3664
|
-
}
|
|
3665
|
-
throw new Error('缺少必要的订单数据,无法同步到后端');
|
|
3666
|
-
case 4:
|
|
3667
|
-
this.logInfo('syncOrderToBackendWithReturn called', {
|
|
3668
|
-
isManual: isManual
|
|
3669
|
-
});
|
|
3670
|
-
currentOrderId = this.store.currentOrder.order_id;
|
|
3671
|
-
isUpdateOperation = this.store.isOrderSynced || !isVirtualOrderId(currentOrderId);
|
|
3672
|
-
this.logInfo("\u5F00\u59CB\u540C\u6B65\u8BA2\u5355\u5230\u540E\u7AEF...", {
|
|
3673
|
-
currentOrderId: currentOrderId,
|
|
3674
|
-
isVirtualId: isVirtualOrderId(currentOrderId || ''),
|
|
3675
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3676
|
-
isOrderSynced: this.store.isOrderSynced,
|
|
3677
|
-
isManual: isManual
|
|
3678
|
-
});
|
|
3679
|
-
|
|
3680
|
-
// 获取当前订单的支付项
|
|
3681
|
-
_context39.t0 = customPaymentItems;
|
|
3682
|
-
if (_context39.t0) {
|
|
3683
|
-
_context39.next = 13;
|
|
3684
|
-
break;
|
|
3685
|
-
}
|
|
3686
|
-
_context39.next = 12;
|
|
3687
|
-
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
3688
|
-
case 12:
|
|
3689
|
-
_context39.t0 = _context39.sent;
|
|
3690
|
-
case 13:
|
|
3691
|
-
paymentItems = _context39.t0;
|
|
3692
|
-
// 处理支付项数据,确保包含完整的 metadata
|
|
3693
|
-
processedPaymentItems = paymentItems.map(function (item) {
|
|
3694
|
-
var _item$metadata, _item$metadata2;
|
|
3695
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
3696
|
-
metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
|
|
3697
|
-
rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this6.otherParams.order_rounding_setting,
|
|
3698
|
-
shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this6.otherParams.shop_wallet_pass_id
|
|
3699
|
-
})
|
|
3700
|
-
});
|
|
3701
|
-
}); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
|
|
3702
|
-
manualDepositAmount = ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
|
|
3703
|
-
manualDepositValue = new Decimal(manualDepositAmount);
|
|
3704
|
-
if (manualDepositValue.gt(0)) {
|
|
3705
|
-
// 如果手动设置了定金金额且大于0,使用手动设置的值
|
|
3706
|
-
finalDepositAmount = manualDepositAmount;
|
|
3707
|
-
this.logInfo('使用手动设置的定金金额', {
|
|
3708
|
-
manualDepositAmount: manualDepositAmount,
|
|
3709
|
-
reason: '用户通过setDepositAmountAsync手动设置了定金金额'
|
|
3710
|
-
});
|
|
3711
|
-
} else {
|
|
3712
|
-
// 都为0,使用0
|
|
3713
|
-
finalDepositAmount = '0.00';
|
|
3714
|
-
this.logInfo('定金金额为0', {
|
|
3715
|
-
manualDepositAmount: manualDepositAmount,
|
|
3716
|
-
reason: '手动设置和计算值均为0'
|
|
3717
|
-
});
|
|
3718
|
-
}
|
|
3719
|
-
// 如果此时是普通支付状态,并且要同步的支付项里一个定金支付的都没有,则 is_deposit 和 deposit_amount 都置为 0
|
|
3720
|
-
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.every(function (item) {
|
|
3721
|
-
return item.order_payment_type !== 'deposit';
|
|
3722
|
-
})) {
|
|
3723
|
-
finalDepositAmount = '0.00';
|
|
3724
|
-
this.store.currentOrder.is_deposit = 0;
|
|
3725
|
-
}
|
|
3726
|
-
// 如果此时是普通支付,并且有普通支付项进来了,则提交给后端的 deposit_amount 只能是支付项里已经支付的order_payment_type = deposit 的金额
|
|
3727
|
-
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.some(function (item) {
|
|
3728
|
-
return item.order_payment_type === 'deposit';
|
|
3729
|
-
})) {
|
|
3730
|
-
finalDepositAmount = processedPaymentItems.filter(function (item) {
|
|
3731
|
-
return item.status !== 'voided' && item.order_payment_type === 'deposit';
|
|
3732
|
-
}).reduce(function (sum, item) {
|
|
3733
|
-
var amt = new Decimal(item.amount || '0');
|
|
3734
|
-
var rounding = new Decimal(item.rounding_amount || '0');
|
|
3735
|
-
return sum.plus(amt).sub(rounding);
|
|
3736
|
-
}, new Decimal(0)).toFixed(2);
|
|
3737
|
-
}
|
|
3738
|
-
// 如果当前是定金支付,并且定金额度已经大于等于了订单总计,则 finalDepositAmount 为实际付出去的定金金额
|
|
3739
|
-
if (this.store.currentOrder.is_deposit === 1 && new Decimal(finalDepositAmount).gte(new Decimal(this.store.currentOrder.total_amount))) {
|
|
3740
|
-
finalDepositAmount = processedPaymentItems.filter(function (item) {
|
|
3741
|
-
return item.status !== 'voided' && item.order_payment_type === 'deposit';
|
|
3742
|
-
}).reduce(function (sum, item) {
|
|
3743
|
-
var amt = new Decimal(item.amount || '0');
|
|
3744
|
-
var rounding = new Decimal(item.rounding_amount || '0');
|
|
3745
|
-
return sum.plus(amt).sub(rounding);
|
|
3746
|
-
}, new Decimal(0)).toFixed(2);
|
|
3747
|
-
}
|
|
3748
|
-
this.logInfo('定金金额确定结果', {
|
|
3749
|
-
depositPaymentItemsCount: processedPaymentItems.length,
|
|
3750
|
-
depositPaymentItems: processedPaymentItems.map(function (item) {
|
|
3751
|
-
return {
|
|
3752
|
-
uuid: item.uuid,
|
|
3753
|
-
code: item.code,
|
|
3754
|
-
amount: item.amount,
|
|
3755
|
-
rounding_amount: item.rounding_amount,
|
|
3756
|
-
order_payment_type: item.order_payment_type,
|
|
3757
|
-
status: item.status
|
|
3758
|
-
};
|
|
3759
|
-
}),
|
|
3760
|
-
manualDepositAmount: manualDepositAmount,
|
|
3761
|
-
finalDepositAmount: finalDepositAmount,
|
|
3762
|
-
isDeposit: ((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.is_deposit) || 0
|
|
3763
|
-
});
|
|
3764
|
-
|
|
3765
|
-
// 构造订单参数,直接使用 localOrderData 中已处理好的数据
|
|
3766
|
-
orderParams = _objectSpread(_objectSpread({}, this.store.localOrderData), {}, {
|
|
3767
|
-
type: this.store.localOrderData.type,
|
|
3768
|
-
platform: this.store.localOrderData.platform,
|
|
3769
|
-
payments: processedPaymentItems,
|
|
3770
|
-
// 使用处理过的支付项数据
|
|
3771
|
-
customer_id: (_this$store$currentCu2 = this.store.currentCustomer) === null || _this$store$currentCu2 === void 0 ? void 0 : _this$store$currentCu2.customer_id,
|
|
3772
|
-
// 添加客户ID
|
|
3773
|
-
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
3774
|
-
// core 有
|
|
3775
|
-
tax_title: this.otherParams.tax_title,
|
|
3776
|
-
// core 没有
|
|
3777
|
-
tax_rate: this.otherParams.tax_rate,
|
|
3778
|
-
// core 有
|
|
3779
|
-
tax_country_code: this.otherParams.tax_country_code,
|
|
3780
|
-
// core 没有
|
|
3781
|
-
currency_code: this.otherParams.currency_code,
|
|
3782
|
-
currency_symbol: this.otherParams.currency_symbol,
|
|
3783
|
-
currency_format: this.otherParams.currency_format,
|
|
3784
|
-
is_deposit: ((_this$store$currentOr25 = this.store.currentOrder) !== null && _this$store$currentOr25 !== void 0 && _this$store$currentOr25.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
3785
|
-
deposit_amount: finalDepositAmount,
|
|
3786
|
-
// 使用最终确定的定金金额(手动设置优先)
|
|
3787
|
-
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
3788
|
-
note: this.store.localOrderData.shop_note,
|
|
3789
|
-
bookings: (_this$store$localOrde = this.store.localOrderData.bookings) === null || _this$store$localOrde === void 0 ? void 0 : _this$store$localOrde.map(function (item) {
|
|
3790
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
3791
|
-
product: _objectSpread(_objectSpread({}, item.product), {}, {
|
|
3792
|
-
custom_deposit_data: undefined
|
|
3793
|
-
}),
|
|
3794
|
-
deposit: undefined
|
|
3795
|
-
});
|
|
3796
|
-
}),
|
|
3797
|
-
relation_products: (_this$store$localOrde2 = this.store.localOrderData.relation_products) === null || _this$store$localOrde2 === void 0 ? void 0 : _this$store$localOrde2.map(function (item) {
|
|
3798
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
3799
|
-
custom_deposit_data: undefined,
|
|
3800
|
-
deposit: undefined
|
|
3801
|
-
});
|
|
3802
|
-
})
|
|
3803
|
-
}); // 如果是更新操作,需要在参数中包含真实的订单ID
|
|
3804
|
-
if (isUpdateOperation) {
|
|
3805
|
-
// 如果当前订单ID是虚拟ID,但订单已同步过,可能存在数据不一致的问题
|
|
3806
|
-
if (isVirtualOrderId(currentOrderId)) {
|
|
3807
|
-
this.logWarning('尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性');
|
|
3808
|
-
} else {
|
|
3809
|
-
orderParams.order_id = currentOrderId;
|
|
3810
|
-
}
|
|
3811
|
-
}
|
|
3812
|
-
|
|
3813
|
-
// 发送下单接口请求开始事件
|
|
3814
|
-
startTime = Date.now();
|
|
3815
|
-
_context39.next = 27;
|
|
3816
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderSubmitStart"), {
|
|
3817
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3818
|
-
operation: isUpdateOperation ? 'update' : 'create',
|
|
3819
|
-
isManual: isManual,
|
|
3820
|
-
paymentItemCount: paymentItems.length,
|
|
3821
|
-
timestamp: startTime
|
|
3822
|
-
});
|
|
3823
|
-
case 27:
|
|
3824
|
-
submitSuccess = false;
|
|
3825
|
-
_context39.prev = 28;
|
|
3826
|
-
// 记录接口调用参数
|
|
3827
|
-
this.logInfo('Calling backend checkout API', _objectSpread({
|
|
3828
|
-
url: '/order/checkout',
|
|
3829
|
-
isManual: isManual
|
|
3830
|
-
}, orderParams));
|
|
3831
|
-
|
|
3832
|
-
// 调用 Order 模块的专用 createOrderByCheckout 方法
|
|
3833
|
-
_context39.next = 32;
|
|
3834
|
-
return this.order.createOrderByCheckout(orderParams);
|
|
3835
|
-
case 32:
|
|
3836
|
-
checkoutResponse = _context39.sent;
|
|
3837
|
-
submitSuccess = true;
|
|
3838
|
-
this.logInfo('下单接口调用成功', checkoutResponse);
|
|
3839
|
-
_context39.next = 45;
|
|
3840
|
-
break;
|
|
3841
|
-
case 37:
|
|
3842
|
-
_context39.prev = 37;
|
|
3843
|
-
_context39.t1 = _context39["catch"](28);
|
|
3844
|
-
submitSuccess = false;
|
|
3845
|
-
submitError = _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1);
|
|
3846
|
-
this.logError('下单接口调用失败:', submitError);
|
|
3847
|
-
|
|
3848
|
-
// 发送订单同步失败事件(网络错误或请求失败)
|
|
3849
|
-
_context39.next = 44;
|
|
3850
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
|
|
3851
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3852
|
-
operation: isUpdateOperation ? 'update' : 'create',
|
|
3853
|
-
isManual: isManual,
|
|
3854
|
-
error: submitError,
|
|
3855
|
-
errorType: 'network_error',
|
|
3856
|
-
duration: Date.now() - startTime,
|
|
3857
|
-
timestamp: Date.now()
|
|
3858
|
-
});
|
|
3859
|
-
case 44:
|
|
3860
|
-
throw _context39.t1;
|
|
3861
|
-
case 45:
|
|
3862
|
-
_context39.prev = 45;
|
|
3863
|
-
_context39.next = 48;
|
|
3864
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderSubmitEnd"), {
|
|
3865
|
-
success: submitSuccess,
|
|
3866
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3867
|
-
operation: isUpdateOperation ? 'update' : 'create',
|
|
3868
|
-
isManual: isManual,
|
|
3869
|
-
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,
|
|
3870
|
-
error: submitError,
|
|
3871
|
-
duration: Date.now() - startTime,
|
|
3872
|
-
timestamp: Date.now()
|
|
3873
|
-
});
|
|
3874
|
-
case 48:
|
|
3875
|
-
return _context39.finish(45);
|
|
3876
|
-
case 49:
|
|
3877
|
-
// 检查响应状态是否为成功状态
|
|
3878
|
-
responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
|
|
3879
|
-
isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
|
|
3880
|
-
if (isSuccessResponse) {
|
|
3881
|
-
_context39.next = 56;
|
|
3882
|
-
break;
|
|
3883
|
-
}
|
|
3884
|
-
errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
|
|
3885
|
-
_context39.next = 55;
|
|
3886
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
|
|
3887
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3888
|
-
operation: isUpdateOperation ? 'update' : 'create',
|
|
3889
|
-
isManual: isManual,
|
|
3890
|
-
error: errorMessage,
|
|
3891
|
-
errorType: 'api_error',
|
|
3892
|
-
response: checkoutResponse,
|
|
3893
|
-
duration: Date.now() - startTime,
|
|
3894
|
-
timestamp: Date.now()
|
|
3895
|
-
});
|
|
3896
|
-
case 55:
|
|
3897
|
-
throw new Error(errorMessage);
|
|
3898
|
-
case 56:
|
|
3899
|
-
if (!isUpdateOperation) {
|
|
3900
|
-
_context39.next = 60;
|
|
3901
|
-
break;
|
|
3902
|
-
}
|
|
3903
|
-
// 更新操作:使用现有的订单ID
|
|
3904
|
-
realOrderId = currentOrderId;
|
|
3905
|
-
_context39.next = 79;
|
|
3906
|
-
break;
|
|
3907
|
-
case 60:
|
|
3908
|
-
// 创建操作:从响应中提取新的订单ID
|
|
3909
|
-
extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
|
|
3910
|
-
if (!extractedOrderId) {
|
|
3911
|
-
extractedOrderId = (_checkoutResponse7 = checkoutResponse) === null || _checkoutResponse7 === void 0 ? void 0 : _checkoutResponse7.order_id;
|
|
3912
|
-
}
|
|
3913
|
-
|
|
3914
|
-
// 确保转换为字符串类型
|
|
3915
|
-
if (extractedOrderId !== undefined && extractedOrderId !== null) {
|
|
3916
|
-
extractedOrderId = String(extractedOrderId);
|
|
3917
|
-
}
|
|
3918
|
-
if (!extractedOrderId) {
|
|
3919
|
-
this.logError('后端返回的订单信息中未包含订单ID');
|
|
3920
|
-
}
|
|
3921
|
-
realOrderId = extractedOrderId;
|
|
3922
|
-
|
|
3923
|
-
// 替换虚拟订单ID为真实订单ID
|
|
3924
|
-
this.logInfo('准备替换订单ID:', {
|
|
3925
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
3926
|
-
oldOrderId: this.store.currentOrder.order_id,
|
|
3927
|
-
newOrderId: realOrderId
|
|
3928
|
-
});
|
|
3929
|
-
_context39.prev = 66;
|
|
3930
|
-
_context39.next = 69;
|
|
3931
|
-
return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
|
|
3932
|
-
case 69:
|
|
3933
|
-
updatedOrder = _context39.sent;
|
|
3934
|
-
this.logInfo('Payment模块替换订单ID结果:', {
|
|
3935
|
-
wasSuccessful: !!updatedOrder,
|
|
3936
|
-
returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
|
|
3937
|
-
expectedOrderId: realOrderId
|
|
3938
|
-
});
|
|
3939
|
-
if (updatedOrder) {
|
|
3940
|
-
this.logInfo('Payment模块返回的更新后订单:', {
|
|
3941
|
-
uuid: updatedOrder.uuid,
|
|
3942
|
-
orderId: updatedOrder.order_id,
|
|
3943
|
-
totalAmount: updatedOrder.total_amount
|
|
3944
|
-
});
|
|
3945
|
-
this.store.currentOrder = updatedOrder;
|
|
3946
|
-
this.logInfo('[Checkout] 订单ID替换成功,当前订单ID:', this.store.currentOrder.order_id);
|
|
3947
|
-
} else {
|
|
3948
|
-
this.logError('[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换');
|
|
3949
|
-
|
|
3950
|
-
// 如果替换失败,手动更新订单ID
|
|
3951
|
-
beforeManualUpdate = this.store.currentOrder.order_id;
|
|
3952
|
-
this.store.currentOrder.order_id = realOrderId;
|
|
3953
|
-
this.logInfo('手动设置订单ID:', {
|
|
3954
|
-
beforeReplacement: beforeManualUpdate,
|
|
3955
|
-
afterReplacement: this.store.currentOrder.order_id,
|
|
3956
|
-
目标ID: realOrderId
|
|
3957
|
-
});
|
|
3958
|
-
}
|
|
3959
|
-
_context39.next = 79;
|
|
3960
|
-
break;
|
|
3961
|
-
case 74:
|
|
3962
|
-
_context39.prev = 74;
|
|
3963
|
-
_context39.t2 = _context39["catch"](66);
|
|
3964
|
-
this.logError('调用Payment模块替换订单ID时发生错误:', _context39.t2);
|
|
3965
|
-
|
|
3966
|
-
// 发生错误时也进行手动替换
|
|
3967
|
-
this.store.currentOrder.order_id = realOrderId;
|
|
3968
|
-
this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
|
|
3969
|
-
case 79:
|
|
3970
|
-
_context39.prev = 79;
|
|
3971
|
-
syncedPaymentUuids = processedPaymentItems.filter(function (item) {
|
|
3972
|
-
return item.status !== 'voided';
|
|
3973
|
-
}).map(function (item) {
|
|
3974
|
-
return item.uuid;
|
|
3975
|
-
}).filter(Boolean);
|
|
3976
|
-
_iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
|
|
3977
|
-
_context39.prev = 82;
|
|
3978
|
-
_iterator3.s();
|
|
3979
|
-
case 84:
|
|
3980
|
-
if ((_step3 = _iterator3.n()).done) {
|
|
3981
|
-
_context39.next = 90;
|
|
3982
|
-
break;
|
|
3983
|
-
}
|
|
3984
|
-
paymentUuid = _step3.value;
|
|
3985
|
-
_context39.next = 88;
|
|
3986
|
-
return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
|
|
3987
|
-
isSynced: true,
|
|
3988
|
-
syncError: undefined
|
|
3989
|
-
});
|
|
3990
|
-
case 88:
|
|
3991
|
-
_context39.next = 84;
|
|
3992
|
-
break;
|
|
3993
|
-
case 90:
|
|
3994
|
-
_context39.next = 95;
|
|
3995
|
-
break;
|
|
3996
|
-
case 92:
|
|
3997
|
-
_context39.prev = 92;
|
|
3998
|
-
_context39.t3 = _context39["catch"](82);
|
|
3999
|
-
_iterator3.e(_context39.t3);
|
|
4000
|
-
case 95:
|
|
4001
|
-
_context39.prev = 95;
|
|
4002
|
-
_iterator3.f();
|
|
4003
|
-
return _context39.finish(95);
|
|
4004
|
-
case 98:
|
|
4005
|
-
_context39.next = 103;
|
|
4006
|
-
break;
|
|
4007
|
-
case 100:
|
|
4008
|
-
_context39.prev = 100;
|
|
4009
|
-
_context39.t4 = _context39["catch"](79);
|
|
4010
|
-
this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
|
|
4011
|
-
error: _context39.t4
|
|
4012
|
-
});
|
|
4013
|
-
case 103:
|
|
4014
|
-
// 标记订单已同步
|
|
4015
|
-
this.store.isOrderSynced = true;
|
|
4016
|
-
|
|
4017
|
-
// 🚀 清除计算缓存,订单已同步,数据可能已变更
|
|
4018
|
-
this.clearCalculationCache();
|
|
4019
|
-
|
|
4020
|
-
// 触发订单同步完成事件
|
|
4021
|
-
_context39.next = 107;
|
|
4022
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderSynced"), {
|
|
4023
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
4024
|
-
realOrderId: realOrderId,
|
|
4025
|
-
virtualOrderId: this.store.currentOrder.order_id,
|
|
4026
|
-
timestamp: Date.now(),
|
|
4027
|
-
isManual: isManual,
|
|
4028
|
-
response: checkoutResponse
|
|
4029
|
-
});
|
|
4030
|
-
case 107:
|
|
4031
|
-
return _context39.abrupt("return", {
|
|
4032
|
-
success: true,
|
|
4033
|
-
orderId: realOrderId,
|
|
4034
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
4035
|
-
response: checkoutResponse
|
|
4036
|
-
});
|
|
4037
|
-
case 108:
|
|
4038
|
-
case "end":
|
|
4039
|
-
return _context39.stop();
|
|
4040
|
-
}
|
|
4041
|
-
}, _callee39, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
|
|
4042
|
-
}));
|
|
4043
|
-
function syncOrderToBackendWithReturn() {
|
|
4044
|
-
return _syncOrderToBackendWithReturn.apply(this, arguments);
|
|
4045
|
-
}
|
|
4046
|
-
return syncOrderToBackendWithReturn;
|
|
4047
|
-
}())
|
|
4048
|
-
}, {
|
|
4049
|
-
key: "setOtherParams",
|
|
4050
|
-
value: function () {
|
|
4051
|
-
var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
|
|
4052
|
-
var _ref5,
|
|
4053
|
-
_ref5$cover,
|
|
4054
|
-
cover,
|
|
4055
|
-
_args40 = arguments;
|
|
4056
|
-
return _regeneratorRuntime().wrap(function _callee40$(_context40) {
|
|
4057
|
-
while (1) switch (_context40.prev = _context40.next) {
|
|
4058
|
-
case 0:
|
|
4059
|
-
_ref5 = _args40.length > 1 && _args40[1] !== undefined ? _args40[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
|
|
4060
|
-
if (cover) {
|
|
4061
|
-
this.otherParams = params;
|
|
4062
|
-
} else {
|
|
4063
|
-
this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
|
|
4064
|
-
}
|
|
4065
|
-
case 2:
|
|
4066
|
-
case "end":
|
|
4067
|
-
return _context40.stop();
|
|
4068
|
-
}
|
|
4069
|
-
}, _callee40, this);
|
|
4070
|
-
}));
|
|
4071
|
-
function setOtherParams(_x29) {
|
|
4072
|
-
return _setOtherParams.apply(this, arguments);
|
|
4073
|
-
}
|
|
4074
|
-
return setOtherParams;
|
|
4075
|
-
}()
|
|
4076
|
-
/**
|
|
4077
|
-
* 通过订单ID编辑订单备注
|
|
4078
|
-
*
|
|
4079
|
-
* 用于修改已同步到后端的订单备注,通常在支付成功后的弹窗中使用
|
|
4080
|
-
*
|
|
4081
|
-
* @param orderId 后端订单ID
|
|
4082
|
-
* @param note 新的订单备注
|
|
4083
|
-
* @returns 修改结果
|
|
4084
|
-
*/
|
|
4085
|
-
}, {
|
|
4086
|
-
key: "editOrderNoteByOrderIdAsync",
|
|
4087
|
-
value: (function () {
|
|
4088
|
-
var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(orderId, note) {
|
|
4089
|
-
var response, previousNote, errorMessage, _errorMessage;
|
|
4090
|
-
return _regeneratorRuntime().wrap(function _callee41$(_context41) {
|
|
4091
|
-
while (1) switch (_context41.prev = _context41.next) {
|
|
4092
|
-
case 0:
|
|
4093
|
-
this.logInfo('editOrderNoteByOrderIdAsync called', {
|
|
4094
|
-
orderId: orderId,
|
|
4095
|
-
note: note,
|
|
4096
|
-
noteLength: note.length
|
|
4097
|
-
});
|
|
4098
|
-
_context41.prev = 1;
|
|
4099
|
-
if (orderId) {
|
|
4100
|
-
_context41.next = 4;
|
|
4101
|
-
break;
|
|
4102
|
-
}
|
|
4103
|
-
return _context41.abrupt("return", {
|
|
4104
|
-
success: false,
|
|
4105
|
-
message: '订单ID不能为空',
|
|
4106
|
-
orderId: orderId
|
|
4107
|
-
});
|
|
4108
|
-
case 4:
|
|
4109
|
-
// 记录接口调用
|
|
4110
|
-
this.logInfo('Calling order note edit API', {
|
|
4111
|
-
url: "/order/order/".concat(orderId, "/note"),
|
|
4112
|
-
method: 'PUT',
|
|
4113
|
-
orderId: orderId,
|
|
4114
|
-
note: note,
|
|
4115
|
-
noteLength: note.length
|
|
4116
|
-
});
|
|
4117
|
-
|
|
4118
|
-
// 调用后端API修改订单备注
|
|
4119
|
-
_context41.next = 7;
|
|
4120
|
-
return this.request.put("/order/order/".concat(orderId, "/note"), {
|
|
4121
|
-
note: note
|
|
4122
|
-
});
|
|
4123
|
-
case 7:
|
|
4124
|
-
response = _context41.sent;
|
|
4125
|
-
this.logInfo('订单备注编辑响应:', {
|
|
4126
|
-
orderId: orderId,
|
|
4127
|
-
status: response.status,
|
|
4128
|
-
message: response.message,
|
|
4129
|
-
response: response
|
|
4130
|
-
});
|
|
4131
|
-
|
|
4132
|
-
// 检查响应状态
|
|
4133
|
-
if (!(response.status === true || response.status === 200)) {
|
|
4134
|
-
_context41.next = 18;
|
|
4135
|
-
break;
|
|
4136
|
-
}
|
|
4137
|
-
if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
|
|
4138
|
-
_context41.next = 15;
|
|
4139
|
-
break;
|
|
4140
|
-
}
|
|
4141
|
-
// 获取修改前的备注用于事件
|
|
4142
|
-
previousNote = this.getOrderNote(); // 更新本地订单数据中的备注
|
|
4143
|
-
if (this.store.localOrderData) {
|
|
4144
|
-
this.store.localOrderData.shop_note = note;
|
|
4145
|
-
}
|
|
4146
|
-
|
|
4147
|
-
// 触发订单备注变更事件
|
|
4148
|
-
_context41.next = 15;
|
|
4149
|
-
return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
|
|
4150
|
-
orderUuid: this.store.currentOrder.uuid,
|
|
4151
|
-
oldNote: previousNote,
|
|
4152
|
-
newNote: note,
|
|
4153
|
-
timestamp: Date.now()
|
|
4154
|
-
});
|
|
4155
|
-
case 15:
|
|
4156
|
-
return _context41.abrupt("return", {
|
|
4157
|
-
success: true,
|
|
4158
|
-
message: response.message || '订单备注修改成功',
|
|
4159
|
-
orderId: orderId
|
|
4160
|
-
});
|
|
4161
|
-
case 18:
|
|
4162
|
-
// API返回失败状态
|
|
4163
|
-
errorMessage = response.message || '订单备注修改失败';
|
|
4164
|
-
this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
|
|
4165
|
-
return _context41.abrupt("return", {
|
|
4166
|
-
success: false,
|
|
4167
|
-
message: errorMessage,
|
|
4168
|
-
orderId: orderId
|
|
4169
|
-
});
|
|
4170
|
-
case 21:
|
|
4171
|
-
_context41.next = 28;
|
|
4172
|
-
break;
|
|
4173
|
-
case 23:
|
|
4174
|
-
_context41.prev = 23;
|
|
4175
|
-
_context41.t0 = _context41["catch"](1);
|
|
4176
|
-
this.logError('编辑订单备注失败:', _context41.t0);
|
|
4177
|
-
_errorMessage = _context41.t0 instanceof Error ? _context41.t0.message : '网络错误或服务器异常';
|
|
4178
|
-
return _context41.abrupt("return", {
|
|
4179
|
-
success: false,
|
|
4180
|
-
message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
|
|
4181
|
-
orderId: orderId
|
|
4182
|
-
});
|
|
4183
|
-
case 28:
|
|
4184
|
-
case "end":
|
|
4185
|
-
return _context41.stop();
|
|
4186
|
-
}
|
|
4187
|
-
}, _callee41, this, [[1, 23]]);
|
|
4188
|
-
}));
|
|
4189
|
-
function editOrderNoteByOrderIdAsync(_x30, _x31) {
|
|
4190
|
-
return _editOrderNoteByOrderIdAsync.apply(this, arguments);
|
|
4191
|
-
}
|
|
4192
|
-
return editOrderNoteByOrderIdAsync;
|
|
4193
|
-
}()
|
|
4194
|
-
/**
|
|
4195
|
-
* 发送客户支付链接邮件
|
|
4196
|
-
*
|
|
4197
|
-
* 向指定邮箱发送订单支付提醒邮件
|
|
4198
|
-
*
|
|
4199
|
-
* @param params 发送参数
|
|
4200
|
-
* @returns 发送结果
|
|
4201
|
-
*/
|
|
4202
|
-
)
|
|
4203
|
-
}, {
|
|
4204
|
-
key: "sendCustomerPayLinkAsync",
|
|
4205
|
-
value: (function () {
|
|
4206
|
-
var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
|
|
4207
|
-
var _params$order_ids, _params$emails;
|
|
4208
|
-
var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
|
|
4209
|
-
return _regeneratorRuntime().wrap(function _callee42$(_context42) {
|
|
4210
|
-
while (1) switch (_context42.prev = _context42.next) {
|
|
4211
|
-
case 0:
|
|
4212
|
-
this.logInfo('sendCustomerPayLinkAsync called', {
|
|
4213
|
-
orderIds: params.order_ids,
|
|
4214
|
-
orderIdsCount: ((_params$order_ids = params.order_ids) === null || _params$order_ids === void 0 ? void 0 : _params$order_ids.length) || 0,
|
|
4215
|
-
emails: params.emails,
|
|
4216
|
-
emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
|
|
4217
|
-
notifyAction: params.notify_action || 'order_payment_reminder'
|
|
4218
|
-
});
|
|
4219
|
-
_context42.prev = 1;
|
|
4220
|
-
if (!(!params.order_ids || params.order_ids.length === 0)) {
|
|
4221
|
-
_context42.next = 4;
|
|
4222
|
-
break;
|
|
4223
|
-
}
|
|
4224
|
-
return _context42.abrupt("return", {
|
|
4225
|
-
success: false,
|
|
4226
|
-
message: '订单ID列表不能为空'
|
|
4227
|
-
});
|
|
4228
|
-
case 4:
|
|
4229
|
-
if (!(!params.emails || params.emails.length === 0)) {
|
|
4230
|
-
_context42.next = 6;
|
|
4231
|
-
break;
|
|
4232
|
-
}
|
|
4233
|
-
return _context42.abrupt("return", {
|
|
4234
|
-
success: false,
|
|
4235
|
-
message: '邮箱地址列表不能为空'
|
|
4236
|
-
});
|
|
4237
|
-
case 6:
|
|
4238
|
-
// 验证邮箱格式
|
|
4239
|
-
emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
4240
|
-
invalidEmails = params.emails.filter(function (email) {
|
|
4241
|
-
return !emailRegex.test(email);
|
|
4242
|
-
});
|
|
4243
|
-
if (!(invalidEmails.length > 0)) {
|
|
4244
|
-
_context42.next = 10;
|
|
4245
|
-
break;
|
|
4246
|
-
}
|
|
4247
|
-
return _context42.abrupt("return", {
|
|
4248
|
-
success: false,
|
|
4249
|
-
message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
|
|
4250
|
-
});
|
|
4251
|
-
case 10:
|
|
4252
|
-
// 构建请求参数
|
|
4253
|
-
requestBody = {
|
|
4254
|
-
order_ids: params.order_ids,
|
|
4255
|
-
notify_action: params.notify_action || 'order_payment_reminder',
|
|
4256
|
-
emails: params.emails
|
|
4257
|
-
}; // 记录接口调用
|
|
4258
|
-
this.logInfo('Calling batch email API', _objectSpread({
|
|
4259
|
-
url: '/order/batch-email'
|
|
4260
|
-
}, requestBody));
|
|
4261
|
-
|
|
4262
|
-
// 调用后端API发送邮件
|
|
4263
|
-
_context42.next = 14;
|
|
4264
|
-
return this.request.post('/order/batch-email', requestBody);
|
|
4265
|
-
case 14:
|
|
4266
|
-
response = _context42.sent;
|
|
4267
|
-
this.logInfo('支付链接邮件发送响应:', {
|
|
4268
|
-
status: response.status,
|
|
4269
|
-
message: response.message,
|
|
4270
|
-
data: response.data,
|
|
4271
|
-
response: response
|
|
4272
|
-
});
|
|
4273
|
-
|
|
4274
|
-
// 检查响应状态
|
|
4275
|
-
if (!(response.status === true || response.status === 200)) {
|
|
4276
|
-
_context42.next = 20;
|
|
4277
|
-
break;
|
|
4278
|
-
}
|
|
4279
|
-
return _context42.abrupt("return", {
|
|
4280
|
-
success: true,
|
|
4281
|
-
message: response.message || '支付链接邮件发送成功'
|
|
4282
|
-
});
|
|
4283
|
-
case 20:
|
|
4284
|
-
// API返回失败状态
|
|
4285
|
-
errorMessage = response.message || '支付链接邮件发送失败';
|
|
4286
|
-
console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
|
|
4287
|
-
return _context42.abrupt("return", {
|
|
4288
|
-
success: false,
|
|
4289
|
-
message: errorMessage
|
|
4290
|
-
});
|
|
4291
|
-
case 23:
|
|
4292
|
-
_context42.next = 30;
|
|
4293
|
-
break;
|
|
4294
|
-
case 25:
|
|
4295
|
-
_context42.prev = 25;
|
|
4296
|
-
_context42.t0 = _context42["catch"](1);
|
|
4297
|
-
this.logError('发送客户支付链接邮件失败:', _context42.t0);
|
|
4298
|
-
_errorMessage2 = _context42.t0 instanceof Error ? _context42.t0.message : '网络错误或服务器异常';
|
|
4299
|
-
return _context42.abrupt("return", {
|
|
4300
|
-
success: false,
|
|
4301
|
-
message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
|
|
4302
|
-
});
|
|
4303
|
-
case 30:
|
|
4304
|
-
case "end":
|
|
4305
|
-
return _context42.stop();
|
|
4306
|
-
}
|
|
4307
|
-
}, _callee42, this, [[1, 25]]);
|
|
4308
|
-
}));
|
|
4309
|
-
function sendCustomerPayLinkAsync(_x32) {
|
|
4310
|
-
return _sendCustomerPayLinkAsync.apply(this, arguments);
|
|
4311
|
-
}
|
|
4312
|
-
return sendCustomerPayLinkAsync;
|
|
4313
|
-
}()
|
|
4314
|
-
/**
|
|
4315
|
-
* 金额舍入
|
|
4316
|
-
*
|
|
4317
|
-
* @param amount 原始金额
|
|
4318
|
-
* @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
|
|
4319
|
-
*/
|
|
4320
|
-
)
|
|
4321
|
-
}, {
|
|
4322
|
-
key: "roundAmountAsync",
|
|
4323
|
-
value: (function () {
|
|
4324
|
-
var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(amount) {
|
|
4325
|
-
var _cashManualPayment$me, _this$otherParams$ord, _this$otherParams$ord2;
|
|
4326
|
-
var cashManualPayment, result;
|
|
4327
|
-
return _regeneratorRuntime().wrap(function _callee43$(_context43) {
|
|
4328
|
-
while (1) switch (_context43.prev = _context43.next) {
|
|
4329
|
-
case 0:
|
|
4330
|
-
// 检查 CASHMANUAL 的支付项是否开启了舍入,如果没开直接返回 amount
|
|
4331
|
-
cashManualPayment = this.store.paymentMethods.find(function (p) {
|
|
4332
|
-
return p.code === 'CASHMANUAL';
|
|
4333
|
-
});
|
|
4334
|
-
if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
|
|
4335
|
-
_context43.next = 3;
|
|
4336
|
-
break;
|
|
4337
|
-
}
|
|
4338
|
-
return _context43.abrupt("return", {
|
|
4339
|
-
originalAmount: amount.toString(),
|
|
4340
|
-
roundedAmount: amount.toString(),
|
|
4341
|
-
roundingDifference: '0.00'
|
|
4342
|
-
});
|
|
4343
|
-
case 3:
|
|
4344
|
-
_context43.next = 5;
|
|
4345
|
-
return this.payment.roundAmountAsync(amount, (_this$otherParams$ord = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord === void 0 ? void 0 : _this$otherParams$ord.interval, (_this$otherParams$ord2 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord2 === void 0 ? void 0 : _this$otherParams$ord2.type);
|
|
4346
|
-
case 5:
|
|
4347
|
-
result = _context43.sent;
|
|
4348
|
-
return _context43.abrupt("return", result);
|
|
4349
|
-
case 7:
|
|
4350
|
-
case "end":
|
|
4351
|
-
return _context43.stop();
|
|
4352
|
-
}
|
|
4353
|
-
}, _callee43, this);
|
|
4354
|
-
}));
|
|
4355
|
-
function roundAmountAsync(_x33) {
|
|
4356
|
-
return _roundAmountAsync.apply(this, arguments);
|
|
4357
|
-
}
|
|
4358
|
-
return roundAmountAsync;
|
|
4359
|
-
}())
|
|
4360
|
-
}, {
|
|
4361
|
-
key: "destroy",
|
|
4362
|
-
value: function () {
|
|
4363
|
-
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
|
|
4364
|
-
var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
|
|
4365
|
-
return _regeneratorRuntime().wrap(function _callee44$(_context44) {
|
|
4366
|
-
while (1) switch (_context44.prev = _context44.next) {
|
|
4367
|
-
case 0:
|
|
4368
|
-
// 清理钱包模块的所有缓存数据
|
|
4369
|
-
this.payment.wallet.clearAllCache();
|
|
4370
|
-
|
|
4371
|
-
// 清理事件监听
|
|
4372
|
-
this.core.effects.offByModuleDestroy(this.name);
|
|
4373
|
-
|
|
4374
|
-
// 销毁子模块
|
|
4375
|
-
_context44.next = 4;
|
|
4376
|
-
return (_this$order = this.order) === null || _this$order === void 0 || (_this$order$destroy = _this$order.destroy) === null || _this$order$destroy === void 0 ? void 0 : _this$order$destroy.call(_this$order);
|
|
4377
|
-
case 4:
|
|
4378
|
-
_context44.next = 6;
|
|
4379
|
-
return (_this$payment = this.payment) === null || _this$payment === void 0 || (_this$payment$destroy = _this$payment.destroy) === null || _this$payment$destroy === void 0 ? void 0 : _this$payment$destroy.call(_this$payment);
|
|
4380
|
-
case 6:
|
|
4381
|
-
// 取消注册模块
|
|
4382
|
-
this.core.unregisterModule(this);
|
|
4383
|
-
console.log('[Checkout] 已销毁');
|
|
4384
|
-
case 8:
|
|
4385
|
-
case "end":
|
|
4386
|
-
return _context44.stop();
|
|
4387
|
-
}
|
|
4388
|
-
}, _callee44, this);
|
|
4389
|
-
}));
|
|
4390
|
-
function destroy() {
|
|
4391
|
-
return _destroy.apply(this, arguments);
|
|
4392
|
-
}
|
|
4393
|
-
return destroy;
|
|
4394
|
-
}()
|
|
4395
|
-
/**
|
|
4396
|
-
* 重置 store 状态
|
|
4397
|
-
*
|
|
4398
|
-
* 在创建新订单前调用,确保状态完全干净
|
|
4399
|
-
*
|
|
4400
|
-
* 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
|
|
4401
|
-
*/
|
|
4402
|
-
}, {
|
|
4403
|
-
key: "resetStoreState",
|
|
4404
|
-
value: function resetStoreState() {
|
|
4405
|
-
var _this7 = this;
|
|
4406
|
-
try {
|
|
4407
|
-
var prevOrderInfo = this.store.currentOrder ? {
|
|
4408
|
-
uuid: this.store.currentOrder.uuid,
|
|
4409
|
-
orderId: this.store.currentOrder.order_id
|
|
4410
|
-
} : null;
|
|
4411
|
-
console.log('[Checkout] 重置 store 状态,准备创建新订单', prevOrderInfo);
|
|
4412
|
-
|
|
4413
|
-
// 重置订单相关的 store 状态(保留 paymentMethods,因为支付方式数据变更不频繁)
|
|
4414
|
-
this.store.currentOrder = undefined;
|
|
4415
|
-
this.store.localOrderData = undefined;
|
|
4416
|
-
this.store.cartSummary = undefined;
|
|
4417
|
-
this.store.stateAmount = '0.00';
|
|
4418
|
-
this.store.balanceDueAmount = '0.00';
|
|
4419
|
-
this.store.isOrderSynced = false;
|
|
4420
|
-
this.store.currentCustomer = undefined;
|
|
4421
|
-
this.store.lastError = undefined;
|
|
4422
|
-
|
|
4423
|
-
// 清空购物车项目
|
|
4424
|
-
this.store.cartItems = [];
|
|
4425
|
-
|
|
4426
|
-
// 清理钱包缓存(同步操作)
|
|
4427
|
-
this.payment.wallet.clearAllCache();
|
|
4428
|
-
|
|
4429
|
-
// 🚀 清除计算缓存
|
|
4430
|
-
this.clearCalculationCache();
|
|
4431
|
-
|
|
4432
|
-
// 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
|
|
4433
|
-
|
|
4434
|
-
console.log('[Checkout] Store 状态重置完成');
|
|
4435
|
-
|
|
4436
|
-
// 🚀 性能优化:异步触发订单清理事件(不阻塞主流程)
|
|
4437
|
-
// 使用 setTimeout 确保事件处理不会阻塞状态重置
|
|
4438
|
-
if (prevOrderInfo) {
|
|
4439
|
-
setTimeout(function () {
|
|
4440
|
-
_this7.core.effects.emit("".concat(_this7.name, ":onOrderCleared"), {
|
|
4441
|
-
previousOrder: prevOrderInfo,
|
|
4442
|
-
timestamp: Date.now()
|
|
4443
|
-
});
|
|
4444
|
-
}, 0);
|
|
4445
|
-
}
|
|
4446
|
-
} catch (error) {
|
|
4447
|
-
console.error('[Checkout] 重置 store 状态失败:', error);
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
}]);
|
|
4451
|
-
return CheckoutImpl;
|
|
4452
|
-
}(BaseModule);
|