@pisell/pisellos 0.0.568 → 0.10.1
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 +10 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -3
- package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
- package/dist/model/strategy/adapter/walletPass/example.js +26 -3
- package/dist/model/strategy/adapter/walletPass/index.js +5 -5
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +24 -96
- package/dist/model/strategy/strategy-example.js +19 -5
- package/dist/modules/BaseModule.d.ts +2 -2
- package/dist/modules/BaseModule.js +12 -14
- package/dist/modules/BookingContext/index.d.ts +48 -0
- package/dist/modules/BookingContext/index.js +566 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
- package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/dist/modules/BookingContext/utils/flexible.js +56 -0
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
- package/dist/modules/BookingContext/utils/index.d.ts +11 -0
- package/dist/modules/BookingContext/utils/index.js +11 -0
- package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/dist/modules/BookingContext/utils/noResource.js +77 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/dist/modules/BookingContext/utils/productExtend.js +339 -0
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
- package/dist/modules/BookingContext/utils/resources.js +486 -0
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
- package/dist/modules/Cart/index.js +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +27 -5
- package/dist/modules/Cart/utils/cartResource.js +0 -2
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Customer/index.d.ts +20 -0
- package/dist/modules/Customer/index.js +172 -83
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Date/index.js +5 -1
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +43 -30
- package/dist/modules/Discount/types.d.ts +1 -1
- package/dist/modules/OpenData/index.d.ts +8 -0
- package/dist/modules/OpenData/index.js +38 -16
- package/dist/modules/Order/index.d.ts +449 -24
- package/dist/modules/Order/index.js +5460 -574
- package/dist/modules/Order/types.d.ts +693 -88
- package/dist/modules/Order/types.js +68 -1
- package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
- package/dist/modules/Order/utils.d.ts +167 -18
- package/dist/modules/Order/utils.js +960 -165
- package/dist/modules/Payment/index.d.ts +10 -9
- package/dist/modules/Payment/index.js +573 -746
- package/dist/modules/Payment/types.d.ts +44 -24
- package/dist/modules/Payment/utils.d.ts +1 -1
- package/dist/modules/Payment/utils.js +4 -3
- package/dist/modules/Payment/walletpass.d.ts +0 -2
- package/dist/modules/Payment/walletpass.js +49 -33
- package/dist/modules/Product/types.d.ts +29 -7
- package/dist/modules/ProductList/index.d.ts +17 -13
- package/dist/modules/ProductList/index.js +182 -81
- package/dist/modules/ProductList/types.d.ts +16 -0
- package/dist/modules/Quotation/index.d.ts +22 -2
- package/dist/modules/Quotation/index.js +108 -42
- package/dist/modules/Quotation/types.d.ts +19 -0
- package/dist/modules/ResourcePlanner/index.d.ts +24 -0
- package/dist/modules/ResourcePlanner/index.js +181 -0
- package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
- package/dist/modules/ResourcePlanner/planner.js +1069 -0
- package/dist/modules/ResourcePlanner/types.d.ts +227 -0
- package/dist/modules/ResourcePlanner/types.js +1 -0
- package/dist/modules/Rules/index.d.ts +8 -10
- package/dist/modules/Rules/index.js +324 -513
- package/dist/modules/Rules/types.d.ts +14 -3
- package/dist/modules/SalesSummary/index.d.ts +23 -26
- package/dist/modules/SalesSummary/index.js +152 -46
- package/dist/modules/SalesSummary/types.d.ts +9 -1
- package/dist/modules/SalesSummary/utils.d.ts +3 -22
- package/dist/modules/SalesSummary/utils.js +804 -165
- package/dist/modules/Schedule/getDateIsInSchedule.js +14 -12
- package/dist/modules/Schedule/index.d.ts +18 -5
- package/dist/modules/Schedule/index.js +79 -24
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/Schedule/utils.js +1 -0
- package/dist/modules/Step/index.js +1 -0
- package/dist/modules/Summary/index.js +4 -3
- package/dist/modules/Summary/utils.js +22 -43
- package/dist/modules/SurchargeList/index.d.ts +18 -0
- package/dist/modules/SurchargeList/index.js +185 -0
- package/dist/modules/SurchargeList/types.d.ts +15 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +3 -0
- package/dist/modules/index.js +4 -1
- package/dist/plugins/app.d.ts +2 -0
- package/dist/plugins/request.d.ts +1 -0
- package/dist/plugins/request.js +4 -1
- package/dist/plugins/window.js +6 -2
- package/dist/server/index.d.ts +462 -8
- package/dist/server/index.js +6168 -680
- package/dist/server/modules/floor-plan/index.d.ts +39 -0
- package/dist/server/modules/floor-plan/index.js +595 -0
- package/dist/server/modules/floor-plan/types.d.ts +43 -0
- package/dist/server/modules/floor-plan/types.js +13 -0
- package/dist/server/modules/index.d.ts +7 -2
- package/dist/server/modules/index.js +6 -0
- package/dist/server/modules/menu/index.js +41 -32
- package/dist/server/modules/order/index.d.ts +207 -14
- package/dist/server/modules/order/index.js +2328 -379
- package/dist/server/modules/order/types.d.ts +76 -5
- package/dist/server/modules/order/types.js +14 -1
- package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
- package/dist/server/modules/order/utils/filterBookings.js +118 -11
- package/dist/server/modules/order/utils/filterOrders.js +242 -14
- package/dist/server/modules/payment/index.d.ts +28 -0
- package/dist/server/modules/payment/index.js +305 -0
- package/dist/server/modules/payment/types.d.ts +9 -0
- package/dist/server/modules/payment/types.js +1 -0
- package/dist/server/modules/products/index.d.ts +105 -14
- package/dist/server/modules/products/index.js +1416 -521
- package/dist/server/modules/products/types.d.ts +34 -1
- package/dist/server/modules/products/types.js +4 -0
- package/dist/server/modules/quotation/index.d.ts +39 -0
- package/dist/server/modules/quotation/index.js +298 -77
- package/dist/server/modules/resource/index.d.ts +2 -3
- package/dist/server/modules/resource/index.js +109 -86
- package/dist/server/modules/schedule/index.d.ts +6 -4
- package/dist/server/modules/schedule/index.js +145 -106
- package/dist/server/test.json +713 -0
- package/dist/server/types.d.ts +2 -0
- package/dist/server/utils/product.js +3 -2
- package/dist/server/utils/small-ticket.d.ts +71 -0
- package/dist/server/utils/small-ticket.js +963 -0
- package/dist/solution/BaseSales/index.d.ts +378 -0
- package/dist/solution/BaseSales/index.js +4009 -0
- package/dist/solution/BaseSales/types.d.ts +394 -0
- package/dist/solution/BaseSales/types.js +40 -0
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
- package/dist/solution/BaseSales/utils.d.ts +40 -0
- package/dist/solution/BaseSales/utils.js +263 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +60 -11
- package/dist/solution/BookingByStep/utils/capacity.js +11 -1
- package/dist/solution/BookingByStep/utils/resources.js +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
- package/dist/solution/BookingTicket/index.d.ts +393 -24
- package/dist/solution/BookingTicket/index.js +2508 -443
- package/dist/solution/BookingTicket/types.d.ts +191 -6
- package/dist/solution/BookingTicket/types.js +83 -10
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
- package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
- package/dist/solution/BookingTicket/utils/cartView.js +209 -0
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
- package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +42 -1
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +42 -28
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +30 -14
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
- package/dist/solution/BuyTickets/index.js +12 -9
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +275 -209
- package/dist/solution/Checkout/utils/index.js +20 -8
- package/dist/solution/RegisterAndLogin/config.js +2 -10
- package/dist/solution/RegisterAndLogin/index.js +76 -30
- package/dist/solution/Sales/index.d.ts +50 -5
- package/dist/solution/Sales/index.js +484 -92
- package/dist/solution/Sales/types.d.ts +26 -2
- package/dist/solution/ScanOrder/index.d.ts +27 -21
- package/dist/solution/ScanOrder/index.js +519 -444
- package/dist/solution/ScanOrder/types.d.ts +33 -11
- package/dist/solution/ScanOrder/types.js +4 -5
- package/dist/solution/ScanOrder/utils.d.ts +4 -1
- package/dist/solution/ScanOrder/utils.js +109 -34
- package/dist/solution/ShopDiscount/index.js +18 -19
- package/dist/solution/ShopDiscount/types.d.ts +4 -5
- package/dist/solution/ShopDiscount/utils.d.ts +0 -9
- package/dist/solution/ShopDiscount/utils.js +0 -9
- package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
- package/dist/solution/UnifiedBookingSales/index.js +1871 -0
- package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
- package/dist/solution/UnifiedBookingSales/types.js +11 -0
- package/dist/solution/VenueBooking/index.d.ts +32 -51
- package/dist/solution/VenueBooking/index.js +741 -808
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/dist/solution/VenueBooking/types.d.ts +1 -3
- package/dist/solution/VenueBooking/types.js +0 -1
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/dist/types/index.d.ts +12 -2
- package/dist/utils/task.js +18 -15
- package/dist/utils/watch.js +1 -0
- package/lib/apis/picoding.js +0 -2
- package/lib/core/index.js +132 -130
- package/lib/effects/index.js +57 -46
- package/lib/index.d.ts +0 -1
- package/lib/index.js +50 -92
- package/lib/model/index.js +21 -14
- package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
- package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
- package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
- package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
- package/lib/model/strategy/adapter/index.js +64 -100
- package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
- package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
- package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
- package/lib/model/strategy/adapter/itemRule/index.js +57 -83
- package/lib/model/strategy/adapter/itemRule/type.js +36 -97
- package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
- package/lib/model/strategy/adapter/promotion/evaluator.js +233 -382
- package/lib/model/strategy/adapter/promotion/examples.js +159 -139
- package/lib/model/strategy/adapter/promotion/index.js +0 -1
- package/lib/model/strategy/adapter/promotion/type.js +35 -199
- package/lib/model/strategy/adapter/type.js +16 -4
- package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
- package/lib/model/strategy/adapter/walletPass/example.js +190 -217
- package/lib/model/strategy/adapter/walletPass/index.js +51 -75
- package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
- package/lib/model/strategy/adapter/walletPass/type.js +16 -4
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
- package/lib/model/strategy/adapter/walletPass/utils.js +383 -676
- package/lib/model/strategy/engine.js +168 -270
- package/lib/model/strategy/index.js +34 -49
- package/lib/model/strategy/strategy-example.js +239 -243
- package/lib/model/strategy/type.js +40 -100
- package/lib/modules/Account/index.js +53 -39
- package/lib/modules/Account/types.js +33 -20
- package/lib/modules/AccountList/index.js +154 -116
- package/lib/modules/AccountList/types.js +31 -30
- package/lib/modules/AccountList/utils.js +30 -18
- package/lib/modules/BaseModule.d.ts +2 -2
- package/lib/modules/BaseModule.js +50 -29
- package/lib/modules/BookingContext/index.d.ts +48 -0
- package/lib/modules/BookingContext/index.js +368 -0
- package/lib/modules/BookingContext/types.d.ts +102 -0
- package/lib/modules/BookingContext/types.js +34 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +298 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +155 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +222 -0
- package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/lib/modules/BookingContext/utils/flexible.js +80 -0
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
- package/lib/modules/BookingContext/utils/index.d.ts +11 -0
- package/lib/modules/BookingContext/utils/index.js +43 -0
- package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/lib/modules/BookingContext/utils/noResource.js +90 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/lib/modules/BookingContext/utils/productExtend.js +283 -0
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
- package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
- package/lib/modules/BookingContext/utils/resources.js +377 -0
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
- package/lib/modules/Cart/index.js +124 -170
- package/lib/modules/Cart/types.js +51 -46
- package/lib/modules/Cart/utils/cartAccount.js +39 -40
- package/lib/modules/Cart/utils/cartDate.js +61 -56
- package/lib/modules/Cart/utils/cartDiscount.js +33 -28
- package/lib/modules/Cart/utils/cartNote.js +32 -27
- package/lib/modules/Cart/utils/cartProduct.js +261 -309
- package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
- package/lib/modules/Cart/utils/cartResource.js +78 -72
- package/lib/modules/Cart/utils/changePrice.js +59 -31
- package/lib/modules/Cart/utils/index.js +48 -106
- package/lib/modules/Customer/constants.js +34 -13
- package/lib/modules/Customer/index.d.ts +20 -0
- package/lib/modules/Customer/index.js +207 -217
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Customer/types.js +35 -38
- package/lib/modules/Date/index.js +115 -116
- package/lib/modules/Date/types.js +28 -16
- package/lib/modules/Date/utils.js +123 -174
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +133 -119
- package/lib/modules/Discount/types.d.ts +1 -1
- package/lib/modules/Discount/types.js +31 -9
- package/lib/modules/Guests/index.js +56 -30
- package/lib/modules/Guests/types.js +33 -23
- package/lib/modules/Holder/index.js +189 -209
- package/lib/modules/Holder/types.js +16 -4
- package/lib/modules/Holder/utils.js +49 -20
- package/lib/modules/OpenData/index.d.ts +8 -0
- package/lib/modules/OpenData/index.js +88 -63
- package/lib/modules/OpenData/types.js +16 -4
- package/lib/modules/OpenData/utils.js +78 -44
- package/lib/modules/Order/index.d.ts +449 -24
- package/lib/modules/Order/index.js +4184 -514
- package/lib/modules/Order/types.d.ts +693 -88
- package/lib/modules/Order/types.js +35 -24
- package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
- package/lib/modules/Order/utils.d.ts +167 -18
- package/lib/modules/Order/utils.js +1085 -414
- package/lib/modules/Payment/cash.js +33 -20
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
- package/lib/modules/Payment/eftpos.js +30 -16
- package/lib/modules/Payment/index.d.ts +10 -9
- package/lib/modules/Payment/index.js +402 -636
- package/lib/modules/Payment/mx51.js +0 -1
- package/lib/modules/Payment/types.d.ts +44 -24
- package/lib/modules/Payment/types.js +107 -216
- package/lib/modules/Payment/utils.d.ts +1 -1
- package/lib/modules/Payment/utils.js +50 -52
- package/lib/modules/Payment/walletpass.d.ts +0 -2
- package/lib/modules/Payment/walletpass.js +216 -221
- package/lib/modules/Product/index.js +46 -51
- package/lib/modules/Product/types.d.ts +29 -7
- package/lib/modules/Product/types.js +16 -4
- package/lib/modules/Product/utils.js +33 -32
- package/lib/modules/ProductList/index.d.ts +17 -13
- package/lib/modules/ProductList/index.js +161 -120
- package/lib/modules/ProductList/types.d.ts +16 -0
- package/lib/modules/ProductList/types.js +31 -9
- package/lib/modules/Quotation/index.d.ts +22 -2
- package/lib/modules/Quotation/index.js +154 -64
- package/lib/modules/Quotation/types.d.ts +19 -0
- package/lib/modules/Quotation/types.js +16 -4
- package/lib/modules/Resource/index.js +59 -27
- package/lib/modules/Resource/types.js +32 -22
- package/lib/modules/Resource/utils.js +38 -30
- package/lib/modules/ResourcePlanner/index.d.ts +24 -0
- package/lib/modules/ResourcePlanner/index.js +148 -0
- package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
- package/lib/modules/ResourcePlanner/planner.js +933 -0
- package/lib/modules/ResourcePlanner/types.d.ts +227 -0
- package/lib/modules/ResourcePlanner/types.js +17 -0
- package/lib/modules/Rules/index.d.ts +8 -10
- package/lib/modules/Rules/index.js +960 -1440
- package/lib/modules/Rules/types.d.ts +14 -3
- package/lib/modules/Rules/types.js +40 -17
- package/lib/modules/SalesSummary/index.d.ts +23 -26
- package/lib/modules/SalesSummary/index.js +134 -61
- package/lib/modules/SalesSummary/types.d.ts +9 -1
- package/lib/modules/SalesSummary/types.js +16 -4
- package/lib/modules/SalesSummary/utils.d.ts +3 -22
- package/lib/modules/SalesSummary/utils.js +814 -233
- package/lib/modules/ScanOrderLogger/index.js +79 -59
- package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
- package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
- package/lib/modules/ScanOrderLogger/types.js +16 -4
- package/lib/modules/Schedule/getDateIsInSchedule.js +169 -338
- package/lib/modules/Schedule/index.d.ts +18 -5
- package/lib/modules/Schedule/index.js +153 -104
- package/lib/modules/Schedule/type.js +16 -4
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/Schedule/types.js +16 -4
- package/lib/modules/Schedule/utils.js +291 -433
- package/lib/modules/Step/index.js +52 -40
- package/lib/modules/Step/tyeps.js +16 -4
- package/lib/modules/Summary/index.js +71 -66
- package/lib/modules/Summary/types.js +16 -4
- package/lib/modules/Summary/utils.js +418 -791
- package/lib/modules/SurchargeList/index.d.ts +18 -0
- package/lib/modules/SurchargeList/index.js +109 -0
- package/lib/modules/SurchargeList/types.d.ts +15 -0
- package/lib/modules/SurchargeList/types.js +17 -0
- package/lib/modules/index.d.ts +3 -0
- package/lib/modules/index.js +63 -212
- package/lib/plugins/app.d.ts +2 -0
- package/lib/plugins/app.js +16 -4
- package/lib/plugins/index.js +25 -36
- package/lib/plugins/request.d.ts +1 -0
- package/lib/plugins/request.js +126 -137
- package/lib/plugins/shopStore.js +16 -4
- package/lib/plugins/user.js +16 -4
- package/lib/plugins/window.js +179 -171
- package/lib/server/index.d.ts +462 -8
- package/lib/server/index.js +4520 -1162
- package/lib/server/modules/floor-plan/index.d.ts +39 -0
- package/lib/server/modules/floor-plan/index.js +327 -0
- package/lib/server/modules/floor-plan/types.d.ts +43 -0
- package/lib/server/modules/floor-plan/types.js +34 -0
- package/lib/server/modules/index.d.ts +7 -2
- package/lib/server/modules/index.js +67 -84
- package/lib/server/modules/menu/index.js +122 -146
- package/lib/server/modules/menu/types.js +31 -18
- package/lib/server/modules/order/index.d.ts +207 -14
- package/lib/server/modules/order/index.js +1543 -285
- package/lib/server/modules/order/types.d.ts +76 -5
- package/lib/server/modules/order/types.js +32 -107
- package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
- package/lib/server/modules/order/utils/filterBookings.js +259 -176
- package/lib/server/modules/order/utils/filterOrders.js +293 -94
- package/lib/server/modules/payment/index.d.ts +28 -0
- package/lib/server/modules/payment/index.js +192 -0
- package/lib/server/modules/payment/types.d.ts +9 -0
- package/lib/server/modules/payment/types.js +17 -0
- package/lib/server/modules/products/index.d.ts +105 -14
- package/lib/server/modules/products/index.js +850 -475
- package/lib/server/modules/products/types.d.ts +34 -1
- package/lib/server/modules/products/types.js +34 -41
- package/lib/server/modules/quotation/index.d.ts +39 -0
- package/lib/server/modules/quotation/index.js +254 -75
- package/lib/server/modules/quotation/types.js +31 -21
- package/lib/server/modules/resource/index.d.ts +2 -3
- package/lib/server/modules/resource/index.js +240 -243
- package/lib/server/modules/resource/types.js +33 -42
- package/lib/server/modules/schedule/index.d.ts +6 -4
- package/lib/server/modules/schedule/index.js +146 -147
- package/lib/server/modules/schedule/types.js +21 -14
- package/lib/server/modules/schedule/utils.js +163 -334
- package/lib/server/test.json +713 -0
- package/lib/server/types.d.ts +2 -0
- package/lib/server/types.js +16 -4
- package/lib/server/utils/index.js +23 -25
- package/lib/server/utils/product.js +140 -197
- package/lib/server/utils/schedule.js +41 -34
- package/lib/server/utils/small-ticket.d.ts +71 -0
- package/lib/server/utils/small-ticket.js +904 -0
- package/lib/server/utils/time.js +49 -40
- package/lib/solution/BaseSales/index.d.ts +378 -0
- package/lib/solution/BaseSales/index.js +2533 -0
- package/lib/solution/BaseSales/types.d.ts +394 -0
- package/lib/solution/BaseSales/types.js +43 -0
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +1004 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +289 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +256 -0
- package/lib/solution/BaseSales/utils.d.ts +40 -0
- package/lib/solution/BaseSales/utils.js +244 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1340 -1530
- package/lib/solution/BookingByStep/types.js +99 -40
- package/lib/solution/BookingByStep/utils/capacity.js +160 -192
- package/lib/solution/BookingByStep/utils/products.js +52 -42
- package/lib/solution/BookingByStep/utils/resources.js +330 -527
- package/lib/solution/BookingByStep/utils/stock.js +44 -65
- package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
- package/lib/solution/BookingTicket/index.d.ts +393 -24
- package/lib/solution/BookingTicket/index.js +1374 -184
- package/lib/solution/BookingTicket/types.d.ts +191 -6
- package/lib/solution/BookingTicket/types.js +79 -40
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -0
- package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
- package/lib/solution/BookingTicket/utils/cartView.js +184 -0
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +97 -64
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -82
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +109 -91
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
- package/lib/solution/BuyTickets/index.js +70 -67
- package/lib/solution/BuyTickets/types.js +38 -22
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +1169 -1463
- package/lib/solution/Checkout/types.js +61 -91
- package/lib/solution/Checkout/utils/index.js +156 -228
- package/lib/solution/PlaceOrder/index.js +0 -55
- package/lib/solution/RegisterAndLogin/config.js +462 -503
- package/lib/solution/RegisterAndLogin/index.js +630 -633
- package/lib/solution/RegisterAndLogin/types.js +76 -189
- package/lib/solution/RegisterAndLogin/utils.js +125 -183
- package/lib/solution/Sales/index.d.ts +50 -5
- package/lib/solution/Sales/index.js +498 -238
- package/lib/solution/Sales/types.d.ts +26 -2
- package/lib/solution/Sales/types.js +33 -27
- package/lib/solution/ScanOrder/index.d.ts +27 -21
- package/lib/solution/ScanOrder/index.js +936 -864
- package/lib/solution/ScanOrder/types.d.ts +33 -11
- package/lib/solution/ScanOrder/types.js +34 -34
- package/lib/solution/ScanOrder/utils.d.ts +4 -1
- package/lib/solution/ScanOrder/utils.js +422 -385
- package/lib/solution/ShopDiscount/index.js +233 -235
- package/lib/solution/ShopDiscount/types.d.ts +4 -5
- package/lib/solution/ShopDiscount/types.js +37 -15
- package/lib/solution/ShopDiscount/utils.d.ts +0 -9
- package/lib/solution/ShopDiscount/utils.js +172 -309
- package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
- package/lib/solution/UnifiedBookingSales/index.js +1076 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
- package/lib/solution/UnifiedBookingSales/types.js +33 -0
- package/lib/solution/VenueBooking/index.d.ts +32 -51
- package/lib/solution/VenueBooking/index.js +1008 -984
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/lib/solution/VenueBooking/types.d.ts +1 -3
- package/lib/solution/VenueBooking/types.js +39 -20
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
- package/lib/solution/VenueBooking/utils/resource.js +54 -31
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +109 -90
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
- package/lib/solution/VenueBooking/utils.js +67 -130
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +41 -102
- package/lib/store/createStore.js +29 -32
- package/lib/types/index.d.ts +12 -2
- package/lib/types/index.js +16 -4
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +47 -81
- package/package.json +2 -4
- package/dist/solution/Checkout/appointmentDemo.json +0 -1
- package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
- package/lib/solution/Checkout/appointmentDemo.json +0 -1
- package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
|
@@ -1,361 +1,346 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
8
18
|
};
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/solution/Checkout/index.ts
|
|
31
|
+
var Checkout_exports = {};
|
|
32
|
+
__export(Checkout_exports, {
|
|
33
|
+
CheckoutImpl: () => CheckoutImpl
|
|
25
34
|
});
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
defaultName = 'checkout';
|
|
38
|
-
defaultVersion = '1.0.0';
|
|
39
|
-
isSolution = true;
|
|
40
|
-
request;
|
|
41
|
-
store;
|
|
42
|
-
otherParams = {};
|
|
43
|
-
logger; // LoggerManager 实例
|
|
44
|
-
|
|
45
|
-
// 计算缓存(用于性能优化)
|
|
46
|
-
calculationCache = {};
|
|
47
|
-
|
|
48
|
-
// 同步订单到后端锁(按订单维度),防止短时间内重复触发导致同一订单多次同步
|
|
49
|
-
syncOrderToBackendInFlightByOrderKey = new Map();
|
|
50
|
-
|
|
51
|
-
// 直接挂载的模块
|
|
52
|
-
order;
|
|
53
|
-
payment;
|
|
35
|
+
module.exports = __toCommonJS(Checkout_exports);
|
|
36
|
+
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
38
|
+
var import_Order = require("../../modules/Order");
|
|
39
|
+
var import_Payment = require("../../modules/Payment");
|
|
40
|
+
var import_types = require("./types");
|
|
41
|
+
var import_types2 = require("../../modules/Payment/types");
|
|
42
|
+
var import_utils = require("./utils");
|
|
43
|
+
var import_utils2 = require("../../modules/Cart/utils");
|
|
44
|
+
__reExport(Checkout_exports, require("./types"), module.exports);
|
|
45
|
+
var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
54
46
|
constructor(name, version) {
|
|
55
|
-
super(name ||
|
|
47
|
+
super(name || "checkout", version || "1.0.0");
|
|
48
|
+
this.defaultName = "checkout";
|
|
49
|
+
this.defaultVersion = "1.0.0";
|
|
50
|
+
this.isSolution = true;
|
|
51
|
+
this.otherParams = {};
|
|
52
|
+
// LoggerManager 实例
|
|
53
|
+
// 计算缓存(用于性能优化)
|
|
54
|
+
this.calculationCache = {};
|
|
55
|
+
// 同步订单到后端锁(按订单维度),防止短时间内重复触发导致同一订单多次同步
|
|
56
|
+
this.syncOrderToBackendInFlightByOrderKey = /* @__PURE__ */ new Map();
|
|
56
57
|
}
|
|
57
58
|
async initialize(core, options) {
|
|
58
59
|
this.core = core;
|
|
59
60
|
this.otherParams = options.otherParams || {};
|
|
60
|
-
|
|
61
|
-
// 获取依赖的插件
|
|
62
|
-
this.request = core.getPlugin('request');
|
|
61
|
+
this.request = core.getPlugin("request");
|
|
63
62
|
if (!this.request) {
|
|
64
|
-
throw new Error(
|
|
63
|
+
throw new Error("Checkout 解决方案需要 request 插件支持");
|
|
65
64
|
}
|
|
66
|
-
|
|
67
|
-
// 获取 logger 实例
|
|
68
|
-
const appPlugin = core.getPlugin('app');
|
|
65
|
+
const appPlugin = core.getPlugin("app");
|
|
69
66
|
if (!appPlugin) {
|
|
70
|
-
throw new Error(
|
|
67
|
+
throw new Error("Checkout 解决方案需要 app 插件支持");
|
|
71
68
|
}
|
|
72
69
|
const app = appPlugin.getApp();
|
|
73
70
|
this.logger = app.logger;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.order = new _Order.OrderModule();
|
|
77
|
-
this.payment = new _Payment.PaymentModule();
|
|
78
|
-
|
|
79
|
-
// 初始化状态
|
|
71
|
+
this.order = new import_Order.OrderModule();
|
|
72
|
+
this.payment = new import_Payment.PaymentModule();
|
|
80
73
|
this.store = {
|
|
81
74
|
cartItems: [],
|
|
82
75
|
paymentMethods: [],
|
|
83
|
-
stateAmount:
|
|
84
|
-
balanceDueAmount:
|
|
85
|
-
cartSummary:
|
|
76
|
+
stateAmount: "0.00",
|
|
77
|
+
balanceDueAmount: "0.00",
|
|
78
|
+
cartSummary: void 0,
|
|
86
79
|
isOrderSynced: false,
|
|
87
|
-
currentCustomer:
|
|
80
|
+
currentCustomer: void 0
|
|
88
81
|
};
|
|
89
|
-
|
|
90
|
-
// 注册并初始化子模块
|
|
91
82
|
await this.initializeSubModules(core, options);
|
|
92
|
-
|
|
93
|
-
// 预加载支付方式(利用缓存机制)
|
|
94
|
-
await this.preloadPaymentMethods();
|
|
95
|
-
|
|
96
|
-
// 清理过期的已同步订单数据
|
|
97
|
-
await this.cleanupExpiredOrdersAsync();
|
|
83
|
+
console.log("[Checkout] 初始化完成");
|
|
98
84
|
await this.core.effects.emit(`${this.name}:onCheckoutInitialized`, {
|
|
99
85
|
timestamp: Date.now()
|
|
100
86
|
});
|
|
101
|
-
this.logInfo(
|
|
87
|
+
this.logInfo("CheckoutModule initialized successfully");
|
|
102
88
|
}
|
|
103
|
-
|
|
104
89
|
/**
|
|
105
90
|
* 记录信息日志
|
|
106
91
|
*/
|
|
107
92
|
logInfo(title, metadata) {
|
|
108
93
|
if (this.logger) {
|
|
109
94
|
this.logger.addLog({
|
|
110
|
-
type:
|
|
95
|
+
type: "info",
|
|
111
96
|
title: `[CheckoutModule] ${this.getCurrentOrderId()} ${title}`,
|
|
112
97
|
metadata: metadata || {}
|
|
113
98
|
});
|
|
114
99
|
}
|
|
115
100
|
}
|
|
116
|
-
|
|
117
101
|
/**
|
|
118
102
|
* 记录警告日志
|
|
119
103
|
*/
|
|
120
104
|
logWarning(title, metadata) {
|
|
121
105
|
if (this.logger) {
|
|
122
106
|
this.logger.addLog({
|
|
123
|
-
type:
|
|
107
|
+
type: "warning",
|
|
124
108
|
title: `[CheckoutModule] ${title}`,
|
|
125
109
|
metadata: metadata || {}
|
|
126
110
|
});
|
|
127
111
|
}
|
|
128
112
|
}
|
|
129
|
-
|
|
130
113
|
/**
|
|
131
114
|
* 记录错误日志
|
|
132
115
|
*/
|
|
133
116
|
logError(title, metadata) {
|
|
134
117
|
if (this.logger) {
|
|
135
118
|
this.logger.addLog({
|
|
136
|
-
type:
|
|
119
|
+
type: "error",
|
|
137
120
|
title: `[CheckoutModule] ${title}`,
|
|
138
121
|
metadata: metadata || {}
|
|
139
122
|
});
|
|
140
123
|
}
|
|
141
124
|
}
|
|
142
|
-
|
|
143
125
|
/**
|
|
144
126
|
* 初始化子模块
|
|
145
127
|
*/
|
|
146
128
|
async initializeSubModules(core, options) {
|
|
147
|
-
|
|
129
|
+
var _a, _b;
|
|
148
130
|
core.registerModule(this.order, {
|
|
149
|
-
store: options.store
|
|
150
|
-
otherParams: {
|
|
151
|
-
...this.otherParams,
|
|
152
|
-
fatherModule: this.name
|
|
153
|
-
}
|
|
131
|
+
store: ((_a = options.store) == null ? void 0 : _a.order) || {},
|
|
132
|
+
otherParams: { ...this.otherParams, fatherModule: this.name }
|
|
154
133
|
});
|
|
155
|
-
|
|
156
|
-
// 初始化支付模块
|
|
157
134
|
core.registerModule(this.payment, {
|
|
158
|
-
store: options.store
|
|
159
|
-
otherParams: {
|
|
160
|
-
...this.otherParams,
|
|
161
|
-
fatherModule: this.name
|
|
162
|
-
}
|
|
135
|
+
store: ((_b = options.store) == null ? void 0 : _b.payment) || {},
|
|
136
|
+
otherParams: { ...this.otherParams, fatherModule: this.name }
|
|
163
137
|
});
|
|
164
|
-
|
|
165
|
-
// 监听支付模块事件
|
|
166
138
|
this.setupPaymentEventListeners();
|
|
167
139
|
}
|
|
168
|
-
|
|
169
140
|
/**
|
|
170
141
|
* 设置支付模块事件监听
|
|
171
142
|
*/
|
|
172
143
|
setupPaymentEventListeners() {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (this.store.currentOrder
|
|
144
|
+
this.core.effects.on("payment:onPaymentSyncSuccess", async (data) => {
|
|
145
|
+
var _a;
|
|
146
|
+
if (((_a = this.store.currentOrder) == null ? void 0 : _a.uuid) === data.orderUuid) {
|
|
176
147
|
await this.handlePaymentSuccess(data);
|
|
177
148
|
}
|
|
178
149
|
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (this.store.currentOrder?.uuid === data.orderUuid) {
|
|
150
|
+
this.core.effects.on("payment:onPaymentSyncError", async (data) => {
|
|
151
|
+
var _a;
|
|
152
|
+
if (((_a = this.store.currentOrder) == null ? void 0 : _a.uuid) === data.orderUuid) {
|
|
183
153
|
await this.handlePaymentError(data);
|
|
184
154
|
}
|
|
185
155
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.core.effects.on(
|
|
194
|
-
|
|
195
|
-
|
|
156
|
+
this.core.effects.on(
|
|
157
|
+
import_types2.PaymentHooks.OnPaymentMethodsLoaded,
|
|
158
|
+
async (methods) => {
|
|
159
|
+
console.log("[Checkout] 收到支付方式加载完成事件:", methods.length);
|
|
160
|
+
this.store.paymentMethods = methods;
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
this.core.effects.on(
|
|
164
|
+
import_types2.PaymentHooks.OnPaymentMethodsChanged,
|
|
165
|
+
async (data) => {
|
|
166
|
+
console.log("[Checkout] 收到支付方式变更事件:", {
|
|
167
|
+
oldCount: data.oldMethods.length,
|
|
168
|
+
newCount: data.newMethods.length
|
|
169
|
+
});
|
|
170
|
+
this.store.paymentMethods = data.newMethods;
|
|
171
|
+
}
|
|
172
|
+
);
|
|
196
173
|
}
|
|
197
|
-
|
|
198
174
|
/**
|
|
199
175
|
* 初始化结账流程
|
|
200
176
|
*/
|
|
201
177
|
async initializeCheckoutAsync(params) {
|
|
202
|
-
|
|
203
|
-
|
|
178
|
+
var _a;
|
|
179
|
+
this.logInfo("initializeCheckoutAsync called", {
|
|
180
|
+
cartItemsCount: ((_a = params.cartItems) == null ? void 0 : _a.length) || 0,
|
|
204
181
|
orderType: params.orderType,
|
|
205
182
|
platform: params.platform
|
|
206
183
|
});
|
|
207
184
|
try {
|
|
208
|
-
// 验证参数
|
|
209
185
|
const validation = this.validateCheckoutParams(params);
|
|
210
186
|
if (!validation.valid) {
|
|
211
|
-
throw (0,
|
|
187
|
+
throw (0, import_utils.createCheckoutError)(
|
|
188
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
189
|
+
`参数验证失败: ${validation.errors.join(", ")}`
|
|
190
|
+
);
|
|
212
191
|
}
|
|
213
|
-
|
|
214
|
-
// 保存购物车数据
|
|
215
192
|
this.store.cartItems = params.cartItems;
|
|
193
|
+
console.log("[Checkout] 结账流程初始化完成");
|
|
216
194
|
} catch (error) {
|
|
217
|
-
await this.handleError(error,
|
|
195
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
218
196
|
throw error;
|
|
219
197
|
}
|
|
220
198
|
}
|
|
221
199
|
getHolderIdFromBooking(obj) {
|
|
222
|
-
|
|
223
|
-
|
|
200
|
+
var _a;
|
|
201
|
+
if (!obj)
|
|
202
|
+
return void 0;
|
|
203
|
+
let ret = obj.holder_id || ((_a = obj.holder) == null ? void 0 : _a.form_record);
|
|
224
204
|
if (Array.isArray(ret)) {
|
|
225
|
-
return ret.length > 0 ? Number(ret[0]) :
|
|
205
|
+
return ret.length > 0 ? Number(ret[0]) : void 0;
|
|
226
206
|
}
|
|
227
|
-
return Number(ret) ||
|
|
207
|
+
return Number(ret) || void 0;
|
|
228
208
|
}
|
|
229
209
|
getProductListByOrder() {
|
|
210
|
+
var _a, _b, _c, _d, _e;
|
|
230
211
|
if (!this.store.currentOrder) {
|
|
231
212
|
return [];
|
|
232
213
|
}
|
|
233
|
-
const getDiscountListAmount = list => {
|
|
214
|
+
const getDiscountListAmount = (list) => {
|
|
234
215
|
return list.reduce((pre, item) => {
|
|
235
216
|
return pre + (item.amount || 0);
|
|
236
217
|
}, 0);
|
|
237
218
|
};
|
|
238
|
-
const formatProduct = items => {
|
|
239
|
-
return items.map(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
219
|
+
const formatProduct = (items) => {
|
|
220
|
+
return items.map(
|
|
221
|
+
(item) => ({
|
|
222
|
+
product_id: item.product_id,
|
|
223
|
+
product_variant_id: item.product_variant_id,
|
|
224
|
+
quantity: item.num,
|
|
225
|
+
is_price_include_tax: item.is_price_include_tax,
|
|
226
|
+
// 商品是否含税:1;0
|
|
227
|
+
is_charge_tax: item.is_charge_tax ?? 0,
|
|
228
|
+
// 若商品不含税,计算得到的税费,单位(元)
|
|
229
|
+
tax_fee: item.tax_fee,
|
|
230
|
+
// 整个商品折扣后的总金额
|
|
231
|
+
selling_price: item.calculated_selling_price,
|
|
232
|
+
// 使用者id
|
|
233
|
+
holder_id: item.holder_id,
|
|
234
|
+
// 整个商品折扣前的总金额
|
|
235
|
+
original_price: item.calculated_original_price,
|
|
236
|
+
// 主商品折扣前金额,不包含套餐子商品
|
|
237
|
+
main_product_original_price: item.price,
|
|
238
|
+
// 主商品折扣后金额,不包含套餐子商品
|
|
239
|
+
main_product_selling_price: item.main_product_selling_price,
|
|
240
|
+
metadata: {
|
|
241
|
+
// 主商品+非原价(加减价)子商品税费
|
|
242
|
+
"main_product_attached_bundle_tax_fee": item.metadata.main_product_attached_bundle_tax_fee,
|
|
243
|
+
// 主商品+非原价(加减价)子商品附加费
|
|
244
|
+
"main_product_attached_bundle_surcharge_fee": item.metadata.main_product_attached_bundle_surcharge_fee,
|
|
245
|
+
// 可选,附加费均摊舍入金额
|
|
246
|
+
"surcharge_rounding_remainder": item.metadata.surcharge_rounding_remainder
|
|
247
|
+
},
|
|
248
|
+
product_bundle: (item.product_bundle || []).map((bundle) => {
|
|
249
|
+
return {
|
|
250
|
+
is_price_include_tax: item.is_price_include_tax,
|
|
251
|
+
bundle_id: bundle.bundle_id,
|
|
252
|
+
bundle_product_id: bundle.bundle_product_id,
|
|
253
|
+
bundle_variant_id: bundle.bundle_variant_id,
|
|
254
|
+
price_type: bundle.price_type,
|
|
255
|
+
price_type_ext: bundle.price_type_ext,
|
|
256
|
+
// 套餐子商品总价,不包含折扣金额
|
|
257
|
+
bundle_sum_price: bundle.bundle_sum_price,
|
|
258
|
+
// 套餐子商品折扣后金额
|
|
259
|
+
bundle_selling_price: bundle.bundle_selling_price,
|
|
260
|
+
num: bundle.num,
|
|
261
|
+
is_charge_tax: bundle.is_charge_tax,
|
|
262
|
+
tax_fee: bundle.tax_fee,
|
|
263
|
+
metadata: {
|
|
264
|
+
// 子商品单数量附加费
|
|
265
|
+
"surcharge_fee": bundle.metadata.surcharge_fee,
|
|
266
|
+
// 可选,附加费均摊舍入金额
|
|
267
|
+
"surcharge_rounding_remainder": bundle.metadata.surcharge_rounding_remainder
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
})
|
|
288
271
|
})
|
|
289
|
-
|
|
272
|
+
) || [];
|
|
290
273
|
};
|
|
291
|
-
const productList = formatProduct(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
274
|
+
const productList = formatProduct(
|
|
275
|
+
((_c = (_b = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data) == null ? void 0 : _b.bookings) == null ? void 0 : _c.map(
|
|
276
|
+
(item) => {
|
|
277
|
+
return {
|
|
278
|
+
...item.product,
|
|
279
|
+
holder_id: this.getHolderIdFromBooking(item)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
)) || []
|
|
283
|
+
);
|
|
284
|
+
const relationProducts = formatProduct(((_e = (_d = this.store.currentOrder.order_info) == null ? void 0 : _d.original_order_data) == null ? void 0 : _e.relation_products) || []);
|
|
298
285
|
return [...productList, ...relationProducts];
|
|
299
286
|
}
|
|
300
287
|
async initWalletData(params) {
|
|
301
|
-
|
|
288
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
289
|
+
this.logInfo("initWalletData called", {
|
|
302
290
|
params
|
|
303
291
|
});
|
|
304
292
|
try {
|
|
305
|
-
const amountInfo = this.store.currentOrder
|
|
293
|
+
const amountInfo = (_b = (_a = this.store.currentOrder) == null ? void 0 : _a.order_info) == null ? void 0 : _b.amount_breakdown;
|
|
306
294
|
if (!amountInfo) {
|
|
307
|
-
this.logInfo(
|
|
295
|
+
this.logInfo("initWalletData amountInfo not found", {
|
|
308
296
|
params
|
|
309
297
|
});
|
|
310
298
|
return;
|
|
311
299
|
}
|
|
312
|
-
// 准备钱包初始化的业务数据
|
|
313
300
|
const walletBusinessData = {
|
|
314
|
-
customer_id: this.store.currentCustomer
|
|
315
|
-
holder: this.store.currentOrder
|
|
301
|
+
customer_id: ((_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
|
|
302
|
+
holder: (_f = (_e = (_d = this.store.currentOrder) == null ? void 0 : _d.order_info) == null ? void 0 : _e.original_order_data) == null ? void 0 : _f.holder,
|
|
316
303
|
amountInfo: {
|
|
317
304
|
totalAmount: amountInfo.totalAmount,
|
|
318
305
|
subTotal: amountInfo.subTotal,
|
|
319
|
-
depositAmount: this.store.currentOrder
|
|
320
|
-
isDeposit: this.store.currentOrder
|
|
306
|
+
depositAmount: (_g = this.store.currentOrder) == null ? void 0 : _g.deposit_amount,
|
|
307
|
+
isDeposit: (_h = this.store.currentOrder) == null ? void 0 : _h.is_deposit
|
|
321
308
|
},
|
|
322
309
|
products: this.getProductListByOrder(),
|
|
323
310
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
324
311
|
// core 有
|
|
325
312
|
...params
|
|
326
313
|
};
|
|
327
|
-
// 判断订单是否已经同步,如果是则追加payment_order_id参数
|
|
328
314
|
if (this.store.isOrderSynced) {
|
|
329
|
-
walletBusinessData.payment_order_id = this.store.currentOrder
|
|
315
|
+
walletBusinessData.payment_order_id = (_i = this.store.currentOrder) == null ? void 0 : _i.order_id;
|
|
330
316
|
}
|
|
331
|
-
this.logInfo(
|
|
317
|
+
this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
|
|
332
318
|
walletBusinessData
|
|
333
319
|
});
|
|
334
|
-
await this.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
335
|
-
|
|
320
|
+
await this.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
321
|
+
walletBusinessData
|
|
322
|
+
);
|
|
323
|
+
this.logInfo("调用结束:initializeWalletDataFromBusinessAsync", {
|
|
336
324
|
walletBusinessData
|
|
337
325
|
});
|
|
338
|
-
|
|
339
|
-
// 因为上面是接口 这里最好检查一下还有没有 currentOrder 了,如果没有,则不触发事件
|
|
340
326
|
if (!this.store.currentOrder) {
|
|
341
327
|
return;
|
|
342
328
|
}
|
|
343
|
-
this.logInfo(
|
|
329
|
+
this.logInfo("initWalletData currentOrder found", {
|
|
344
330
|
currentOrder: this.store.currentOrder
|
|
345
331
|
});
|
|
346
|
-
// 触发钱包数据初始化完成事件
|
|
347
332
|
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
348
|
-
orderUuid: this.store.currentOrder
|
|
333
|
+
orderUuid: (_j = this.store.currentOrder) == null ? void 0 : _j.uuid,
|
|
349
334
|
customerId: walletBusinessData.customer_id,
|
|
350
335
|
walletBusinessData: {
|
|
351
336
|
customer_id: walletBusinessData.customer_id,
|
|
352
337
|
amountInfo: walletBusinessData.amountInfo,
|
|
353
|
-
order_wait_pay_amount: params
|
|
338
|
+
order_wait_pay_amount: params == null ? void 0 : params.order_wait_pay_amount
|
|
354
339
|
},
|
|
355
340
|
timestamp: Date.now()
|
|
356
341
|
});
|
|
357
342
|
} catch (error) {
|
|
358
|
-
this.logError(
|
|
343
|
+
this.logError("initWalletData error", {
|
|
359
344
|
error: error instanceof Error ? error.message : String(error)
|
|
360
345
|
});
|
|
361
346
|
throw error;
|
|
@@ -367,11 +352,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
367
352
|
protocols: [],
|
|
368
353
|
hasDeposit: false
|
|
369
354
|
};
|
|
370
|
-
bookings
|
|
355
|
+
bookings == null ? void 0 : bookings.forEach((item) => {
|
|
371
356
|
const total = item.product.calculated_selling_price;
|
|
372
|
-
const deposit = (0,
|
|
357
|
+
const deposit = (0, import_utils2.getProductDeposit)({
|
|
373
358
|
cartItem: {
|
|
374
|
-
total
|
|
359
|
+
total
|
|
375
360
|
},
|
|
376
361
|
product: item.product,
|
|
377
362
|
bundle: item.bundle,
|
|
@@ -379,14 +364,16 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
379
364
|
num: item.num
|
|
380
365
|
});
|
|
381
366
|
item.deposit = deposit;
|
|
382
|
-
if (deposit
|
|
383
|
-
summaryDeposit.protocols = summaryDeposit.protocols.concat(
|
|
384
|
-
|
|
367
|
+
if ((deposit == null ? void 0 : deposit.total) && Number(deposit.total) > 0) {
|
|
368
|
+
summaryDeposit.protocols = summaryDeposit.protocols.concat(
|
|
369
|
+
deposit.protocols
|
|
370
|
+
);
|
|
371
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).plus(deposit.total).toNumber();
|
|
385
372
|
summaryDeposit.hasDeposit = true;
|
|
386
373
|
}
|
|
387
374
|
});
|
|
388
|
-
relationProducts
|
|
389
|
-
const deposit = (0,
|
|
375
|
+
relationProducts == null ? void 0 : relationProducts.forEach((item) => {
|
|
376
|
+
const deposit = (0, import_utils2.getProductDeposit)({
|
|
390
377
|
cartItem: {
|
|
391
378
|
total: item.price * item.num
|
|
392
379
|
},
|
|
@@ -396,22 +383,20 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
396
383
|
num: item.num
|
|
397
384
|
});
|
|
398
385
|
item.deposit = deposit;
|
|
399
|
-
if (deposit
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
summaryDeposit.total = new _decimal.default(summaryDeposit.total).minus(discount.amount || 0).toNumber();
|
|
386
|
+
if ((deposit == null ? void 0 : deposit.total) && Number(deposit.total) > 0) {
|
|
387
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).plus(deposit.total).toNumber();
|
|
388
|
+
item.discount_list.forEach((discount) => {
|
|
389
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).minus(discount.amount || 0).toNumber();
|
|
404
390
|
});
|
|
405
|
-
summaryDeposit.protocols = summaryDeposit.protocols.concat(
|
|
391
|
+
summaryDeposit.protocols = summaryDeposit.protocols.concat(
|
|
392
|
+
deposit.protocols
|
|
393
|
+
);
|
|
406
394
|
summaryDeposit.hasDeposit = true;
|
|
407
395
|
}
|
|
408
396
|
});
|
|
409
|
-
|
|
410
|
-
// 将总金额四舍五入到两位小数
|
|
411
|
-
summaryDeposit.total = new _decimal.default(summaryDeposit.total).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
|
|
397
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
412
398
|
return summaryDeposit;
|
|
413
399
|
}
|
|
414
|
-
|
|
415
400
|
/**
|
|
416
401
|
* 创建本地订单 (前端模拟下单流程)
|
|
417
402
|
*
|
|
@@ -420,72 +405,60 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
420
405
|
* 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
|
|
421
406
|
*/
|
|
422
407
|
async createLocalOrderAsync(params) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
408
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
409
|
+
this.logInfo("createLocalOrderAsync called", {
|
|
410
|
+
orderDataType: (_a = params.orderData) == null ? void 0 : _a.type,
|
|
411
|
+
platform: (_b = params.orderData) == null ? void 0 : _b.platform,
|
|
412
|
+
bookingsCount: ((_d = (_c = params.orderData) == null ? void 0 : _c.bookings) == null ? void 0 : _d.length) || 0,
|
|
413
|
+
relationProductsCount: ((_f = (_e = params.orderData) == null ? void 0 : _e.relation_products) == null ? void 0 : _f.length) || 0,
|
|
414
|
+
customerId: (_g = params.orderData) == null ? void 0 : _g.customer_id,
|
|
429
415
|
autoPayment: params.autoPayment,
|
|
430
|
-
cartSummaryCount: params.cartSummary
|
|
416
|
+
cartSummaryCount: ((_h = params.cartSummary) == null ? void 0 : _h.length) || 0,
|
|
431
417
|
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
432
418
|
});
|
|
433
419
|
try {
|
|
434
|
-
// 🔧 修改:在创建新订单前,直接重置 store 状态(同步执行)
|
|
435
420
|
this.resetStoreState();
|
|
436
|
-
|
|
437
|
-
const validation = (0, _utils.validateLocalOrderData)(params.orderData);
|
|
421
|
+
const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
|
|
438
422
|
if (!validation.valid) {
|
|
439
|
-
throw (0,
|
|
423
|
+
throw (0, import_utils.createCheckoutError)(
|
|
424
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
425
|
+
`订单数据验证失败: ${validation.errors.join(", ")}`
|
|
426
|
+
);
|
|
440
427
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
params.orderData.
|
|
449
|
-
// 补充 created_at 时间 (YYYY-MM-DD hh:mm:ss 格式)
|
|
450
|
-
params.orderData.created_at = (0, _utils.formatDateTime)(new Date());
|
|
451
|
-
// 补充附加费信息
|
|
452
|
-
params.orderData.surcharge_fee = params.totalInfo?.total?.otherAmount;
|
|
453
|
-
params.orderData.surcharges = params.totalInfo?.total?.surcharge;
|
|
454
|
-
// 补充订单折扣信息
|
|
455
|
-
params.orderData.shop_discount = params.totalInfo?.total?.shopDiscount;
|
|
456
|
-
// 补充税费信息
|
|
457
|
-
params.orderData.tax_fee = params.totalInfo?.total?.tax;
|
|
458
|
-
|
|
459
|
-
// 保存原始订单数据和小计数据到状态中
|
|
428
|
+
const localOrderId = (0, import_utils.generateLocalOrderId)();
|
|
429
|
+
const amountInfo = (0, import_utils.extractAmountFromCartSummary)(params.cartSummary);
|
|
430
|
+
params.orderData.platform = "pos";
|
|
431
|
+
params.orderData.created_at = (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date());
|
|
432
|
+
params.orderData.surcharge_fee = (_j = (_i = params.totalInfo) == null ? void 0 : _i.total) == null ? void 0 : _j.otherAmount;
|
|
433
|
+
params.orderData.surcharges = (_l = (_k = params.totalInfo) == null ? void 0 : _k.total) == null ? void 0 : _l.surcharge;
|
|
434
|
+
params.orderData.shop_discount = (_n = (_m = params.totalInfo) == null ? void 0 : _m.total) == null ? void 0 : _n.shopDiscount;
|
|
435
|
+
params.orderData.tax_fee = (_p = (_o = params.totalInfo) == null ? void 0 : _o.total) == null ? void 0 : _p.tax;
|
|
460
436
|
this.store.localOrderData = params.orderData;
|
|
461
437
|
this.store.cartSummary = params.cartSummary;
|
|
462
|
-
|
|
463
|
-
// 提取并保存客户信息(如果有)
|
|
464
438
|
const customerInfo = {
|
|
465
439
|
customer_id: params.orderData.customer_id,
|
|
466
440
|
customer_name: params.orderData.customer_name
|
|
467
441
|
};
|
|
468
|
-
|
|
469
|
-
// 只有在有客户信息时才存储
|
|
470
442
|
if (customerInfo.customer_id || customerInfo.customer_name) {
|
|
471
443
|
this.store.currentCustomer = customerInfo;
|
|
444
|
+
console.log("[Checkout] 保存客户信息:", customerInfo);
|
|
472
445
|
} else {
|
|
473
|
-
this.store.currentCustomer =
|
|
446
|
+
this.store.currentCustomer = void 0;
|
|
447
|
+
console.log("[Checkout] 未提供客户信息");
|
|
474
448
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
// 创建支付订单对象
|
|
449
|
+
const isNeedDeposit = this.checkIsNeedDepositAsync(
|
|
450
|
+
params.orderData.bookings,
|
|
451
|
+
params.orderData.relation_products
|
|
452
|
+
);
|
|
480
453
|
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
481
454
|
order_id: localOrderId,
|
|
482
455
|
total_amount: amountInfo.totalAmount,
|
|
483
456
|
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
484
|
-
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() :
|
|
457
|
+
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : "0.00",
|
|
485
458
|
order_info: {
|
|
486
459
|
original_order_data: params.orderData,
|
|
487
460
|
cart_summary: params.cartSummary,
|
|
488
|
-
created_at: new Date().toISOString(),
|
|
461
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
489
462
|
platform: params.orderData.platform,
|
|
490
463
|
type: params.orderData.type,
|
|
491
464
|
schedule_date: params.orderData.schedule_date,
|
|
@@ -494,30 +467,21 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
494
467
|
}
|
|
495
468
|
});
|
|
496
469
|
this.store.currentOrder = paymentOrder;
|
|
497
|
-
|
|
498
|
-
// // 如果设置了自动支付,直接跳转到支付步骤
|
|
499
|
-
// if (params.autoPayment) {
|
|
500
|
-
// // 自动支付模式标记
|
|
501
|
-
// }
|
|
502
|
-
|
|
503
470
|
this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
504
471
|
order: paymentOrder,
|
|
505
472
|
timestamp: Date.now()
|
|
506
473
|
});
|
|
507
|
-
|
|
508
|
-
// 自动设置 stateAmount 为剩余未支付金额
|
|
509
|
-
// 🚀 性能监控:记录 updateStateAmountToRemaining 操作耗时
|
|
510
474
|
const updateAmountStartTime = Date.now();
|
|
511
475
|
await this.updateStateAmountToRemaining(false);
|
|
512
476
|
const updateAmountDuration = Date.now() - updateAmountStartTime;
|
|
513
|
-
this.logInfo(
|
|
514
|
-
operation:
|
|
477
|
+
this.logInfo("updateStateAmountToRemaining operation completed", {
|
|
478
|
+
operation: "updateStateAmountToRemaining",
|
|
515
479
|
orderUuid: paymentOrder.uuid,
|
|
516
480
|
orderId: paymentOrder.order_id,
|
|
517
481
|
duration: `${updateAmountDuration}ms`,
|
|
518
|
-
performance: updateAmountDuration > 200 ?
|
|
482
|
+
performance: updateAmountDuration > 200 ? "slow" : updateAmountDuration > 100 ? "medium" : "fast"
|
|
519
483
|
});
|
|
520
|
-
this.logInfo(
|
|
484
|
+
this.logInfo("本地订单创建成功:", {
|
|
521
485
|
localOrderId,
|
|
522
486
|
uuid: paymentOrder.uuid,
|
|
523
487
|
totalAmount: amountInfo.totalAmount,
|
|
@@ -528,8 +492,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
528
492
|
this.initWalletData();
|
|
529
493
|
return paymentOrder;
|
|
530
494
|
} catch (error) {
|
|
531
|
-
await this.handleError(
|
|
532
|
-
|
|
495
|
+
await this.handleError(
|
|
496
|
+
error,
|
|
497
|
+
import_types.CheckoutErrorType.OrderCreationFailed
|
|
498
|
+
);
|
|
499
|
+
this.logError("本地订单创建失败:", error);
|
|
533
500
|
this.core.effects.emit(`${this.name}:onOrderCreationFailed`, {
|
|
534
501
|
error: this.store.lastError,
|
|
535
502
|
timestamp: Date.now()
|
|
@@ -537,7 +504,6 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
537
504
|
throw error;
|
|
538
505
|
}
|
|
539
506
|
}
|
|
540
|
-
|
|
541
507
|
/**
|
|
542
508
|
* 更新本地订单(已同步后端的订单)并设置为当前订单
|
|
543
509
|
*
|
|
@@ -545,37 +511,31 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
545
511
|
* 会覆盖 order_info 与金额等字段,并重新计算待付金额,最后设置为 currentOrder。
|
|
546
512
|
*/
|
|
547
513
|
async updateLocalOrderAsync(params) {
|
|
514
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
548
515
|
this.payment.wallet.clearAllCache();
|
|
549
|
-
this.logInfo(
|
|
516
|
+
this.logInfo("updateLocalOrderAsync called", {
|
|
550
517
|
orderId: params.orderId,
|
|
551
|
-
orderDataType: params.orderData
|
|
552
|
-
bookingsCount: params.orderData
|
|
553
|
-
cartSummaryCount: params.cartSummary
|
|
518
|
+
orderDataType: (_a = params.orderData) == null ? void 0 : _a.type,
|
|
519
|
+
bookingsCount: ((_c = (_b = params.orderData) == null ? void 0 : _b.bookings) == null ? void 0 : _c.length) || 0,
|
|
520
|
+
cartSummaryCount: ((_d = params.cartSummary) == null ? void 0 : _d.length) || 0,
|
|
554
521
|
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
555
522
|
});
|
|
556
|
-
|
|
557
|
-
// 基础校验
|
|
558
|
-
const validation = (0, _utils.validateLocalOrderData)(params.orderData);
|
|
523
|
+
const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
|
|
559
524
|
if (!validation.valid) {
|
|
560
|
-
throw (0,
|
|
525
|
+
throw (0, import_utils.createCheckoutError)(
|
|
526
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
527
|
+
`订单数据验证失败: ${validation.errors.join(", ")}`
|
|
528
|
+
);
|
|
561
529
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
params.orderData.
|
|
568
|
-
params.orderData.
|
|
569
|
-
params.orderData.surcharge_fee = params.totalInfo?.total?.otherAmount;
|
|
570
|
-
params.orderData.surcharges = params.totalInfo?.total?.surcharge;
|
|
571
|
-
params.orderData.shop_discount = params.totalInfo?.total?.shopDiscount;
|
|
572
|
-
params.orderData.tax_fee = params.totalInfo?.total?.tax;
|
|
573
|
-
|
|
574
|
-
// 持久化原始数据
|
|
530
|
+
const amountInfo = (0, import_utils.extractAmountFromCartSummary)(params.cartSummary);
|
|
531
|
+
params.orderData.created_at = (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date());
|
|
532
|
+
params.orderData.platform = "pos";
|
|
533
|
+
params.orderData.surcharge_fee = (_f = (_e = params.totalInfo) == null ? void 0 : _e.total) == null ? void 0 : _f.otherAmount;
|
|
534
|
+
params.orderData.surcharges = (_h = (_g = params.totalInfo) == null ? void 0 : _g.total) == null ? void 0 : _h.surcharge;
|
|
535
|
+
params.orderData.shop_discount = (_j = (_i = params.totalInfo) == null ? void 0 : _i.total) == null ? void 0 : _j.shopDiscount;
|
|
536
|
+
params.orderData.tax_fee = (_l = (_k = params.totalInfo) == null ? void 0 : _k.total) == null ? void 0 : _l.tax;
|
|
575
537
|
this.store.localOrderData = params.orderData;
|
|
576
538
|
this.store.cartSummary = params.cartSummary;
|
|
577
|
-
|
|
578
|
-
// 同步客户信息
|
|
579
539
|
const customerInfo = {
|
|
580
540
|
customer_id: params.orderData.customer_id,
|
|
581
541
|
customer_name: params.orderData.customer_name
|
|
@@ -583,49 +543,43 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
583
543
|
if (customerInfo.customer_id || customerInfo.customer_name) {
|
|
584
544
|
this.store.currentCustomer = customerInfo;
|
|
585
545
|
} else {
|
|
586
|
-
this.store.currentCustomer =
|
|
546
|
+
this.store.currentCustomer = void 0;
|
|
587
547
|
}
|
|
588
|
-
|
|
589
|
-
// 保留原有支付项:通过 orderId 找到现有订单(按 id 或 order_id 匹配)
|
|
590
548
|
const allOrders = await this.payment.getOrderListAsync();
|
|
591
|
-
const existingOrder = allOrders.find(
|
|
549
|
+
const existingOrder = allOrders.find(
|
|
550
|
+
(o) => String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId)
|
|
551
|
+
);
|
|
592
552
|
if (existingOrder) {
|
|
593
|
-
// 🔧 新增: 如果传入了 existPayment,需要更新支付项列表
|
|
594
553
|
if (params.existPayment && params.existPayment.length > 0) {
|
|
595
|
-
this.logInfo(
|
|
554
|
+
this.logInfo("检测到云端支付项,将替换本地订单的支付项列表", {
|
|
596
555
|
orderId: params.orderId,
|
|
597
|
-
existingPaymentCount: existingOrder.payment
|
|
556
|
+
existingPaymentCount: ((_m = existingOrder.payment) == null ? void 0 : _m.length) || 0,
|
|
598
557
|
newPaymentCount: params.existPayment.length
|
|
599
558
|
});
|
|
600
|
-
|
|
601
|
-
// 标记订单已同步(因为支付项来自云端)
|
|
602
559
|
this.store.isOrderSynced = true;
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const currentTime = (0, _utils.formatDateTime)(new Date());
|
|
606
|
-
const formattedExistPayments = params.existPayment.map(payment => ({
|
|
560
|
+
const currentTime = (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date());
|
|
561
|
+
const formattedExistPayments = params.existPayment.map((payment) => ({
|
|
607
562
|
...payment,
|
|
608
563
|
isSynced: true,
|
|
609
564
|
// 标记为已同步
|
|
610
|
-
status: payment.status ||
|
|
565
|
+
status: payment.status || "active",
|
|
611
566
|
created_at: payment.created_at || currentTime,
|
|
612
567
|
updated_at: payment.updated_at || currentTime
|
|
613
568
|
}));
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
// 更新订单,替换支付项列表
|
|
569
|
+
const isNeedDeposit3 = this.checkIsNeedDepositAsync(
|
|
570
|
+
params.orderData.bookings,
|
|
571
|
+
params.orderData.relation_products
|
|
572
|
+
);
|
|
619
573
|
await this.payment.updateOrderAsync(existingOrder.uuid, {
|
|
620
574
|
total_amount: amountInfo.totalAmount,
|
|
621
|
-
is_deposit:
|
|
622
|
-
deposit_amount:
|
|
575
|
+
is_deposit: isNeedDeposit3.hasDeposit ? 1 : 0,
|
|
576
|
+
deposit_amount: isNeedDeposit3.total ? isNeedDeposit3.total.toString() : "0.00",
|
|
623
577
|
payment: formattedExistPayments,
|
|
624
578
|
// 🔧 替换支付项列表
|
|
625
579
|
order_info: {
|
|
626
580
|
original_order_data: params.orderData,
|
|
627
581
|
cart_summary: params.cartSummary,
|
|
628
|
-
created_at: new Date().toISOString(),
|
|
582
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
629
583
|
platform: params.orderData.platform,
|
|
630
584
|
type: params.orderData.type,
|
|
631
585
|
schedule_date: params.orderData.schedule_date,
|
|
@@ -633,68 +587,70 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
633
587
|
amount_breakdown: amountInfo
|
|
634
588
|
}
|
|
635
589
|
});
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
590
|
+
const updated2 = await this.payment.getPaymentOrderByUuidAsync(
|
|
591
|
+
existingOrder.uuid
|
|
592
|
+
);
|
|
593
|
+
if (!updated2)
|
|
594
|
+
throw (0, import_utils.createCheckoutError)(
|
|
595
|
+
import_types.CheckoutErrorType.UnknownError,
|
|
596
|
+
"订单更新失败"
|
|
597
|
+
);
|
|
598
|
+
this.store.currentOrder = updated2;
|
|
639
599
|
await this.updateStateAmountToRemaining(false);
|
|
640
|
-
this.logInfo(
|
|
600
|
+
this.logInfo("本地订单更新成功(已替换云端支付项):", {
|
|
641
601
|
orderId: params.orderId,
|
|
642
|
-
uuid:
|
|
643
|
-
payments:
|
|
644
|
-
totalAmount:
|
|
645
|
-
expectAmount:
|
|
602
|
+
uuid: updated2.uuid,
|
|
603
|
+
payments: ((_n = updated2.payment) == null ? void 0 : _n.length) || 0,
|
|
604
|
+
totalAmount: updated2.total_amount,
|
|
605
|
+
expectAmount: updated2.expect_amount,
|
|
646
606
|
isOrderSynced: true
|
|
647
607
|
});
|
|
648
|
-
|
|
649
|
-
// 事件通知
|
|
650
608
|
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
651
|
-
order:
|
|
609
|
+
order: updated2,
|
|
652
610
|
timestamp: Date.now()
|
|
653
611
|
});
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
let amt = new _decimal.default(p.amount || '0');
|
|
659
|
-
const rounding = new _decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || '0').abs();
|
|
612
|
+
const syncedPayments = updated2.payment.filter((p) => p.isSynced && p.status !== "voided");
|
|
613
|
+
const syncedAmount2 = syncedPayments.reduce((sum, p) => {
|
|
614
|
+
let amt = new import_decimal.default(p.amount || "0");
|
|
615
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
660
616
|
return sum.plus(amt).plus(rounding);
|
|
661
|
-
}, new
|
|
662
|
-
const
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
if (updated.is_deposit === 1) {
|
|
668
|
-
depositDiffAmount = new _decimal.default(updated.deposit_amount).minus(syncedAmount).toFixed(2);
|
|
617
|
+
}, new import_decimal.default(0));
|
|
618
|
+
const totalAmount2 = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
619
|
+
const remainingExpectAmount2 = import_decimal.default.max(0, totalAmount2.minus(syncedAmount2)).toFixed(2);
|
|
620
|
+
let depositDiffAmount2 = new import_decimal.default(0).toFixed(2);
|
|
621
|
+
if (updated2.is_deposit === 1) {
|
|
622
|
+
depositDiffAmount2 = new import_decimal.default(updated2.deposit_amount).minus(syncedAmount2).toFixed(2);
|
|
669
623
|
}
|
|
670
624
|
this.initWalletData({
|
|
671
|
-
order_wait_pay_amount: Number(
|
|
625
|
+
order_wait_pay_amount: Number(depositDiffAmount2) > 0 ? Number(depositDiffAmount2) : Number(remainingExpectAmount2)
|
|
672
626
|
});
|
|
673
|
-
return
|
|
627
|
+
return updated2;
|
|
674
628
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
629
|
+
const totalAmount = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
630
|
+
const activePayments = (existingOrder.payment || []).filter(
|
|
631
|
+
(p) => p.status !== "voided" && (!p.voucher_id || p.voucher_id && p.isSynced)
|
|
632
|
+
);
|
|
679
633
|
const paidAmount = activePayments.reduce((sum, p) => {
|
|
680
|
-
const amt = new
|
|
681
|
-
const rounding = new
|
|
634
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
635
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
682
636
|
return sum.plus(amt).plus(rounding);
|
|
683
|
-
}, new
|
|
684
|
-
const remaining =
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
637
|
+
}, new import_decimal.default(0));
|
|
638
|
+
const remaining = import_decimal.default.max(0, totalAmount.minus(paidAmount)).toFixed(
|
|
639
|
+
2
|
|
640
|
+
);
|
|
641
|
+
const isNeedDeposit2 = this.checkIsNeedDepositAsync(
|
|
642
|
+
params.orderData.bookings,
|
|
643
|
+
params.orderData.relation_products
|
|
644
|
+
);
|
|
689
645
|
await this.payment.updateOrderAsync(existingOrder.uuid, {
|
|
690
646
|
total_amount: amountInfo.totalAmount,
|
|
691
|
-
is_deposit:
|
|
692
|
-
deposit_amount:
|
|
647
|
+
is_deposit: isNeedDeposit2.hasDeposit ? 1 : 0,
|
|
648
|
+
deposit_amount: isNeedDeposit2.total ? isNeedDeposit2.total.toString() : "0.00",
|
|
693
649
|
expect_amount: remaining,
|
|
694
650
|
order_info: {
|
|
695
651
|
original_order_data: params.orderData,
|
|
696
652
|
cart_summary: params.cartSummary,
|
|
697
|
-
created_at: new Date().toISOString(),
|
|
653
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
698
654
|
platform: params.orderData.platform,
|
|
699
655
|
type: params.orderData.type,
|
|
700
656
|
schedule_date: params.orderData.schedule_date,
|
|
@@ -702,56 +658,59 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
702
658
|
amount_breakdown: amountInfo
|
|
703
659
|
}
|
|
704
660
|
});
|
|
705
|
-
const updated = await this.payment.getPaymentOrderByUuidAsync(
|
|
706
|
-
|
|
661
|
+
const updated = await this.payment.getPaymentOrderByUuidAsync(
|
|
662
|
+
existingOrder.uuid
|
|
663
|
+
);
|
|
664
|
+
if (!updated)
|
|
665
|
+
throw (0, import_utils.createCheckoutError)(
|
|
666
|
+
import_types.CheckoutErrorType.UnknownError,
|
|
667
|
+
"订单更新失败"
|
|
668
|
+
);
|
|
707
669
|
this.store.currentOrder = updated;
|
|
708
670
|
await this.updateStateAmountToRemaining(false);
|
|
709
|
-
this.logInfo(
|
|
671
|
+
this.logInfo("本地订单更新成功(保留支付项):", {
|
|
710
672
|
orderId: params.orderId,
|
|
711
673
|
uuid: updated.uuid,
|
|
712
|
-
payments: updated.payment
|
|
674
|
+
payments: ((_o = updated.payment) == null ? void 0 : _o.length) || 0,
|
|
713
675
|
totalAmount: updated.total_amount,
|
|
714
676
|
expectAmount: updated.expect_amount
|
|
715
677
|
});
|
|
716
|
-
|
|
717
|
-
// 事件通知(复用创建事件,便于上层监听刷新)
|
|
718
678
|
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
719
679
|
order: updated,
|
|
720
680
|
timestamp: Date.now()
|
|
721
681
|
});
|
|
722
|
-
|
|
723
|
-
// 需要减去已经同步给后端的支付过的钱
|
|
724
682
|
const syncedAmount = activePayments.reduce((sum, p) => {
|
|
725
|
-
const amt = new
|
|
726
|
-
const rounding = new
|
|
683
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
684
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
727
685
|
return sum.plus(amt).plus(rounding);
|
|
728
|
-
}, new
|
|
729
|
-
const remainingExpectAmount =
|
|
730
|
-
|
|
731
|
-
|
|
686
|
+
}, new import_decimal.default(0));
|
|
687
|
+
const remainingExpectAmount = import_decimal.default.max(0, totalAmount.minus(syncedAmount)).toFixed(
|
|
688
|
+
2
|
|
689
|
+
);
|
|
690
|
+
let depositDiffAmount = new import_decimal.default(0).toFixed(2);
|
|
732
691
|
if (updated.is_deposit === 1) {
|
|
733
|
-
depositDiffAmount = new
|
|
692
|
+
depositDiffAmount = new import_decimal.default(updated.deposit_amount).minus(syncedAmount).toFixed(2);
|
|
734
693
|
}
|
|
735
694
|
this.initWalletData({
|
|
736
695
|
order_wait_pay_amount: Number(depositDiffAmount) > 0 ? Number(depositDiffAmount) : Number(remainingExpectAmount)
|
|
737
696
|
});
|
|
738
697
|
return updated;
|
|
739
698
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
699
|
+
const isNeedDeposit = this.checkIsNeedDepositAsync(
|
|
700
|
+
params.orderData.bookings,
|
|
701
|
+
params.orderData.relation_products
|
|
702
|
+
);
|
|
744
703
|
const created = await this.payment.createPaymentOrderAsync({
|
|
745
704
|
order_id: String(params.orderId),
|
|
746
705
|
total_amount: amountInfo.totalAmount,
|
|
747
706
|
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
748
|
-
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() :
|
|
707
|
+
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : "0.00",
|
|
749
708
|
existPayment: params.existPayment,
|
|
750
709
|
// 🔧 新增: 传递云端支付项
|
|
751
710
|
order_info: {
|
|
752
711
|
original_order_data: params.orderData,
|
|
753
712
|
cart_summary: params.cartSummary,
|
|
754
|
-
created_at: new Date().toISOString(),
|
|
713
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
755
714
|
platform: params.orderData.platform,
|
|
756
715
|
type: params.orderData.type,
|
|
757
716
|
schedule_date: params.orderData.schedule_date,
|
|
@@ -760,20 +719,15 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
760
719
|
}
|
|
761
720
|
});
|
|
762
721
|
this.store.currentOrder = created;
|
|
763
|
-
|
|
764
|
-
// 🔧 新增: 如果有云端支付项,需要计算正确的待付金额
|
|
765
|
-
if (params.existPayment && params.existPayment.length > 0 || this.store.currentOrder?.order_id && !(0, _utils.isVirtualOrderId)(this.store.currentOrder?.order_id)) {
|
|
766
|
-
// 标记订单已同步(因为订单和支付项都来自云端)
|
|
722
|
+
if (params.existPayment && params.existPayment.length > 0 || ((_p = this.store.currentOrder) == null ? void 0 : _p.order_id) && !(0, import_utils.isVirtualOrderId)((_q = this.store.currentOrder) == null ? void 0 : _q.order_id)) {
|
|
767
723
|
this.store.isOrderSynced = true;
|
|
768
|
-
|
|
769
|
-
// 计算已同步的支付金额
|
|
770
|
-
const syncedPayments = created.payment.filter(p => p.isSynced && p.status !== 'voided');
|
|
724
|
+
const syncedPayments = created.payment.filter((p) => p.isSynced && p.status !== "voided");
|
|
771
725
|
const syncedAmount = syncedPayments.reduce((sum, p) => {
|
|
772
|
-
const amt = new
|
|
773
|
-
const rounding = new
|
|
726
|
+
const amt = new import_decimal.default(p.amount || "0");
|
|
727
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
774
728
|
return sum.plus(amt).plus(rounding);
|
|
775
|
-
}, new
|
|
776
|
-
this.logInfo(
|
|
729
|
+
}, new import_decimal.default(0));
|
|
730
|
+
this.logInfo("云端订单初始化钱包数据", {
|
|
777
731
|
orderId: params.orderId,
|
|
778
732
|
totalAmount: created.total_amount,
|
|
779
733
|
expectAmount: created.expect_amount,
|
|
@@ -781,60 +735,57 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
781
735
|
syncedPaymentCount: syncedPayments.length,
|
|
782
736
|
isOrderSynced: true
|
|
783
737
|
});
|
|
784
|
-
|
|
785
|
-
// 初始化钱包数据,使用系统计算的待付金额
|
|
786
738
|
this.initWalletData({
|
|
787
739
|
order_wait_pay_amount: Number(created.expect_amount)
|
|
788
740
|
});
|
|
789
741
|
} else {
|
|
790
|
-
// 没有云端支付项,正常初始化
|
|
791
742
|
this.initWalletData();
|
|
792
743
|
}
|
|
793
744
|
return created;
|
|
794
745
|
}
|
|
795
|
-
|
|
796
746
|
/**
|
|
797
747
|
* 完成结账
|
|
798
748
|
*/
|
|
799
749
|
async completeCheckoutAsync() {
|
|
800
750
|
try {
|
|
801
751
|
if (!this.store.currentOrder) {
|
|
802
|
-
throw (0,
|
|
752
|
+
throw (0, import_utils.createCheckoutError)(
|
|
753
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
754
|
+
"未找到当前订单"
|
|
755
|
+
);
|
|
803
756
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
if (!order || order.payment_status !==
|
|
808
|
-
throw (0,
|
|
757
|
+
const order = await this.payment.getPaymentOrderByUuidAsync(
|
|
758
|
+
this.store.currentOrder.uuid
|
|
759
|
+
);
|
|
760
|
+
if (!order || order.payment_status !== import_types2.PaymentStatus.Finished) {
|
|
761
|
+
throw (0, import_utils.createCheckoutError)(
|
|
762
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
763
|
+
"订单支付未完成,无法完成结账"
|
|
764
|
+
);
|
|
809
765
|
}
|
|
810
|
-
|
|
811
|
-
// 清理钱包模块的所有缓存数据
|
|
812
766
|
this.payment.wallet.clearAllCache();
|
|
813
767
|
await this.core.effects.emit(`${this.name}:onCheckoutCompleted`, {
|
|
814
768
|
orderId: order.id,
|
|
815
769
|
timestamp: Date.now()
|
|
816
770
|
});
|
|
817
|
-
|
|
771
|
+
console.log("[Checkout] 结账流程完成:", order.id);
|
|
818
772
|
this.resetStoreState();
|
|
819
773
|
return {
|
|
820
774
|
success: true,
|
|
821
775
|
orderId: String(order.id)
|
|
822
776
|
};
|
|
823
777
|
} catch (error) {
|
|
824
|
-
await this.handleError(error,
|
|
825
|
-
return {
|
|
826
|
-
success: false
|
|
827
|
-
};
|
|
778
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
779
|
+
return { success: false };
|
|
828
780
|
}
|
|
829
781
|
}
|
|
830
|
-
|
|
831
782
|
/**
|
|
832
783
|
* 获取订单原始数据
|
|
833
784
|
*/
|
|
834
785
|
getOrderOriginalData() {
|
|
835
|
-
|
|
786
|
+
var _a;
|
|
787
|
+
return (_a = this.store.currentOrder) == null ? void 0 : _a.order_info;
|
|
836
788
|
}
|
|
837
|
-
|
|
838
789
|
/**
|
|
839
790
|
* 获取当前订单基础信息
|
|
840
791
|
*
|
|
@@ -842,20 +793,15 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
842
793
|
*/
|
|
843
794
|
getCurrentOrderInfo() {
|
|
844
795
|
try {
|
|
845
|
-
const {
|
|
846
|
-
currentOrder,
|
|
847
|
-
cartItems,
|
|
848
|
-
localOrderData
|
|
849
|
-
} = this.store;
|
|
796
|
+
const { currentOrder, cartItems, localOrderData } = this.store;
|
|
850
797
|
if (!currentOrder) {
|
|
798
|
+
console.log("[Checkout] 当前没有活跃订单");
|
|
851
799
|
return null;
|
|
852
800
|
}
|
|
853
|
-
|
|
854
|
-
// 从本地订单数据或订单信息中提取基础信息
|
|
855
801
|
const orderInfo = currentOrder.order_info || {};
|
|
856
|
-
const createdAt = orderInfo.created_at || new Date().toISOString();
|
|
857
|
-
const orderType = localOrderData
|
|
858
|
-
const platform = localOrderData
|
|
802
|
+
const createdAt = orderInfo.created_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
803
|
+
const orderType = (localOrderData == null ? void 0 : localOrderData.type) || orderInfo.type || "virtual";
|
|
804
|
+
const platform = (localOrderData == null ? void 0 : localOrderData.platform) || orderInfo.platform || "pc";
|
|
859
805
|
const result = {
|
|
860
806
|
uuid: currentOrder.uuid,
|
|
861
807
|
orderId: currentOrder.order_id,
|
|
@@ -864,19 +810,18 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
864
810
|
paymentStatus: currentOrder.payment_status,
|
|
865
811
|
isDeposit: Boolean(currentOrder.is_deposit),
|
|
866
812
|
depositAmount: currentOrder.deposit_amount,
|
|
867
|
-
orderType
|
|
868
|
-
platform
|
|
813
|
+
orderType,
|
|
814
|
+
platform,
|
|
869
815
|
createdAt,
|
|
870
816
|
itemCount: cartItems.length,
|
|
871
817
|
hasLocalOrderData: Boolean(localOrderData)
|
|
872
818
|
};
|
|
873
819
|
return result;
|
|
874
820
|
} catch (error) {
|
|
875
|
-
console.error(
|
|
821
|
+
console.error("[Checkout] 获取当前订单基础信息失败:", error);
|
|
876
822
|
return null;
|
|
877
823
|
}
|
|
878
824
|
}
|
|
879
|
-
|
|
880
825
|
/**
|
|
881
826
|
* 获取当前订单的支付项
|
|
882
827
|
*
|
|
@@ -884,36 +829,32 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
884
829
|
*/
|
|
885
830
|
async getCurrentOrderPaymentItemsAsync() {
|
|
886
831
|
try {
|
|
887
|
-
const {
|
|
888
|
-
currentOrder
|
|
889
|
-
} = this.store;
|
|
832
|
+
const { currentOrder } = this.store;
|
|
890
833
|
if (!currentOrder) {
|
|
834
|
+
console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
|
|
891
835
|
return [];
|
|
892
836
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
837
|
+
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
838
|
+
currentOrder.uuid
|
|
839
|
+
);
|
|
896
840
|
return paymentItems;
|
|
897
841
|
} catch (error) {
|
|
898
|
-
console.error(
|
|
842
|
+
console.error("[Checkout] 获取当前订单支付项失败:", error);
|
|
899
843
|
return [];
|
|
900
844
|
}
|
|
901
845
|
}
|
|
902
|
-
|
|
903
846
|
/**
|
|
904
847
|
* 获取订单模块
|
|
905
848
|
*/
|
|
906
849
|
getOrderModule() {
|
|
907
850
|
return this.order;
|
|
908
851
|
}
|
|
909
|
-
|
|
910
852
|
/**
|
|
911
853
|
* 获取支付模块
|
|
912
854
|
*/
|
|
913
855
|
getPaymentModule() {
|
|
914
856
|
return this.payment;
|
|
915
857
|
}
|
|
916
|
-
|
|
917
858
|
/**
|
|
918
859
|
* 替换本地订单ID为真实订单ID
|
|
919
860
|
*
|
|
@@ -925,45 +866,43 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
925
866
|
async replaceLocalOrderIdAsync(newOrderId) {
|
|
926
867
|
try {
|
|
927
868
|
if (!this.store.currentOrder) {
|
|
928
|
-
console.warn(
|
|
869
|
+
console.warn("[Checkout] 没有当前订单,无法替换订单ID");
|
|
929
870
|
return null;
|
|
930
871
|
}
|
|
931
872
|
const previousOrder = this.store.currentOrder;
|
|
932
873
|
const latestPaymentStatus = previousOrder.payment_status;
|
|
933
|
-
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
874
|
+
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
875
|
+
previousOrder.uuid,
|
|
876
|
+
newOrderId
|
|
877
|
+
);
|
|
934
878
|
if (updatedOrder) {
|
|
935
|
-
// 🔧 重要:Payment.replaceOrderIdByUuidAsync 返回的是 DB 快照(只保证 order_id 变化)
|
|
936
|
-
// 这里需要合并到内存态,避免覆盖掉刚刚从后端拿到的 payment_status 等字段
|
|
937
879
|
this.store.currentOrder = {
|
|
938
880
|
...previousOrder,
|
|
939
881
|
...updatedOrder,
|
|
940
882
|
payment_status: latestPaymentStatus
|
|
941
883
|
};
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
// 触发订单更新事件
|
|
884
|
+
if (latestPaymentStatus)
|
|
885
|
+
await this.payment.updateOrderAsync(previousOrder.uuid, {
|
|
886
|
+
payment_status: latestPaymentStatus
|
|
887
|
+
});
|
|
949
888
|
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
950
889
|
order: updatedOrder,
|
|
951
890
|
timestamp: Date.now()
|
|
952
891
|
});
|
|
953
|
-
|
|
892
|
+
console.log("[Checkout] 本地订单ID替换成功:", {
|
|
893
|
+
uuid: updatedOrder.uuid,
|
|
894
|
+
newOrderId: updatedOrder.id
|
|
895
|
+
});
|
|
954
896
|
this.store.isOrderSynced = true;
|
|
955
|
-
|
|
956
|
-
// 订单ID替换后更新 stateAmount
|
|
957
897
|
await this.updateStateAmountToRemaining(false);
|
|
958
898
|
}
|
|
959
899
|
return updatedOrder;
|
|
960
900
|
} catch (error) {
|
|
961
|
-
console.error(
|
|
962
|
-
await this.handleError(error,
|
|
901
|
+
console.error("[Checkout] 替换订单ID失败:", error);
|
|
902
|
+
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
963
903
|
return null;
|
|
964
904
|
}
|
|
965
905
|
}
|
|
966
|
-
|
|
967
906
|
/**
|
|
968
907
|
* 设置自定义支付金额
|
|
969
908
|
*
|
|
@@ -973,40 +912,35 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
973
912
|
*/
|
|
974
913
|
async setStateAmountAsync(amount) {
|
|
975
914
|
try {
|
|
976
|
-
// 验证金额格式
|
|
977
915
|
const numAmount = parseFloat(amount);
|
|
978
916
|
if (isNaN(numAmount) || numAmount < 0) {
|
|
979
917
|
throw new Error(`无效的支付金额: ${amount}`);
|
|
980
918
|
}
|
|
981
919
|
const oldAmount = this.store.stateAmount;
|
|
982
920
|
const formattedAmount = numAmount.toFixed(2);
|
|
983
|
-
|
|
984
|
-
// 如果金额没有变化,直接返回
|
|
985
921
|
if (oldAmount === formattedAmount) {
|
|
986
922
|
return;
|
|
987
923
|
}
|
|
988
|
-
this.logInfo(
|
|
924
|
+
this.logInfo("[Checkout] 设置自定义支付金额:", {
|
|
989
925
|
oldAmount,
|
|
990
926
|
newAmount: formattedAmount
|
|
991
927
|
});
|
|
992
|
-
|
|
993
|
-
// 更新状态
|
|
994
928
|
this.store.stateAmount = formattedAmount;
|
|
995
|
-
|
|
996
|
-
// 触发金额变更事件
|
|
997
929
|
await this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
|
|
998
930
|
oldAmount,
|
|
999
931
|
newAmount: formattedAmount,
|
|
1000
932
|
timestamp: Date.now()
|
|
1001
933
|
});
|
|
1002
934
|
} catch (error) {
|
|
1003
|
-
const errorMessage = error instanceof Error ? error.message :
|
|
1004
|
-
console.error(
|
|
1005
|
-
await this.handleError(
|
|
935
|
+
const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
|
|
936
|
+
console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
|
|
937
|
+
await this.handleError(
|
|
938
|
+
new Error(errorMessage),
|
|
939
|
+
import_types.CheckoutErrorType.ValidationFailed
|
|
940
|
+
);
|
|
1006
941
|
throw error;
|
|
1007
942
|
}
|
|
1008
943
|
}
|
|
1009
|
-
|
|
1010
944
|
/**
|
|
1011
945
|
* 获取当前自定义支付金额
|
|
1012
946
|
*
|
|
@@ -1015,7 +949,6 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1015
949
|
getStateAmount() {
|
|
1016
950
|
return this.store.stateAmount;
|
|
1017
951
|
}
|
|
1018
|
-
|
|
1019
952
|
/**
|
|
1020
953
|
* 获取系统计算的待付金额(只读)
|
|
1021
954
|
*
|
|
@@ -1026,7 +959,6 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1026
959
|
getBalanceDueAmount() {
|
|
1027
960
|
return this.store.balanceDueAmount;
|
|
1028
961
|
}
|
|
1029
|
-
|
|
1030
962
|
/**
|
|
1031
963
|
* 获取购物车小计数据
|
|
1032
964
|
*
|
|
@@ -1036,20 +968,19 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1036
968
|
*/
|
|
1037
969
|
getCartSummary() {
|
|
1038
970
|
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
1039
|
-
console.warn(
|
|
971
|
+
console.warn("[Checkout] 没有可用的购物车小计数据");
|
|
1040
972
|
return null;
|
|
1041
973
|
}
|
|
1042
|
-
this.logInfo(
|
|
974
|
+
this.logInfo("获取购物车小计数据:", {
|
|
1043
975
|
itemCount: this.store.cartSummary.length,
|
|
1044
|
-
items: this.store.cartSummary.map(item => ({
|
|
976
|
+
items: this.store.cartSummary.map((item) => ({
|
|
1045
977
|
key: item.key,
|
|
1046
978
|
value: item.value,
|
|
1047
979
|
label: item.label
|
|
1048
980
|
}))
|
|
1049
981
|
});
|
|
1050
|
-
return [...this.store.cartSummary];
|
|
982
|
+
return [...this.store.cartSummary];
|
|
1051
983
|
}
|
|
1052
|
-
|
|
1053
984
|
/**
|
|
1054
985
|
* 获取支付方式列表
|
|
1055
986
|
*
|
|
@@ -1059,26 +990,25 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1059
990
|
* @returns 支付方式列表
|
|
1060
991
|
*/
|
|
1061
992
|
async getPaymentMethodsAsync() {
|
|
1062
|
-
// 优先使用 store 中的缓存数据
|
|
1063
993
|
if (this.store.paymentMethods && this.store.paymentMethods.length > 0) {
|
|
1064
|
-
this.logInfo(
|
|
994
|
+
this.logInfo(
|
|
995
|
+
`使用缓存的支付方式数据,共 ${this.store.paymentMethods.length} 种`
|
|
996
|
+
);
|
|
1065
997
|
return this.store.paymentMethods;
|
|
1066
998
|
}
|
|
1067
|
-
|
|
1068
|
-
// 如果缓存为空,调用 Payment 模块获取
|
|
1069
|
-
this.logInfo('store 中无缓存,从 Payment 模块获取支付方式...');
|
|
999
|
+
this.logInfo("store 中无缓存,从 Payment 模块获取支付方式...");
|
|
1070
1000
|
try {
|
|
1071
1001
|
const methods = await this.payment.getPayMethodListAsync();
|
|
1072
|
-
// 更新缓存
|
|
1073
1002
|
this.store.paymentMethods = methods;
|
|
1074
|
-
this.logInfo(
|
|
1003
|
+
this.logInfo(
|
|
1004
|
+
`从 Payment 模块获取到 ${methods.length} 种支付方式,已更新缓存`
|
|
1005
|
+
);
|
|
1075
1006
|
return methods;
|
|
1076
1007
|
} catch (error) {
|
|
1077
|
-
this.logError(
|
|
1008
|
+
this.logError("获取支付方式失败:", error);
|
|
1078
1009
|
return [];
|
|
1079
1010
|
}
|
|
1080
1011
|
}
|
|
1081
|
-
|
|
1082
1012
|
/**
|
|
1083
1013
|
* 为当前订单添加支付项
|
|
1084
1014
|
*
|
|
@@ -1088,16 +1018,14 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1088
1018
|
* @throws 当前没有活跃订单时抛出错误
|
|
1089
1019
|
*/
|
|
1090
1020
|
async addPaymentItemAsync(paymentItem, orderUuid) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
});
|
|
1095
|
-
const isEftposPayment = paymentItem.type?.toLowerCase() === 'eftpos' || paymentItem.code?.toUpperCase().includes('EFTPOS');
|
|
1021
|
+
var _a, _b, _c, _d, _e;
|
|
1022
|
+
this.logInfo("addPaymentItemAsync called", { paymentItem, orderUuid });
|
|
1023
|
+
const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
|
|
1096
1024
|
const shouldRepairFromIndexDb = !!orderUuid && isEftposPayment && (!this.store.currentOrder || this.store.currentOrder.uuid !== orderUuid);
|
|
1097
1025
|
if (shouldRepairFromIndexDb) {
|
|
1098
|
-
this.logError(
|
|
1026
|
+
this.logError("EFTPOS push payment repair triggered", {
|
|
1099
1027
|
orderUuid,
|
|
1100
|
-
currentOrderUuid: this.store.currentOrder
|
|
1028
|
+
currentOrderUuid: (_c = this.store.currentOrder) == null ? void 0 : _c.uuid,
|
|
1101
1029
|
paymentCode: paymentItem.code,
|
|
1102
1030
|
paymentType: paymentItem.type
|
|
1103
1031
|
});
|
|
@@ -1107,7 +1035,7 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1107
1035
|
paymentItem
|
|
1108
1036
|
});
|
|
1109
1037
|
} catch (error) {
|
|
1110
|
-
this.logError(
|
|
1038
|
+
this.logError("EFTPOS push payment repair failed", {
|
|
1111
1039
|
orderUuid,
|
|
1112
1040
|
error: error instanceof Error ? error.message : String(error)
|
|
1113
1041
|
});
|
|
@@ -1115,73 +1043,63 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1115
1043
|
return;
|
|
1116
1044
|
}
|
|
1117
1045
|
try {
|
|
1118
|
-
// 检查是否有当前订单
|
|
1119
1046
|
if (!this.store.currentOrder) {
|
|
1120
|
-
throw (0,
|
|
1047
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1048
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1049
|
+
"未找到当前订单,无法添加支付项"
|
|
1050
|
+
);
|
|
1121
1051
|
}
|
|
1122
|
-
|
|
1123
|
-
// 根据当前订单的定金状态设置订单支付类型
|
|
1124
|
-
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal';
|
|
1125
|
-
|
|
1126
|
-
// 处理现金支付的找零逻辑
|
|
1052
|
+
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
1127
1053
|
const processedPaymentItem = await this.processCashPaymentItem(paymentItem);
|
|
1128
|
-
|
|
1129
|
-
// 从 otherParams 获取 metadata 字段
|
|
1130
1054
|
const metadata = {
|
|
1131
1055
|
...processedPaymentItem.metadata,
|
|
1132
1056
|
rounding_rule: this.otherParams.order_rounding_setting,
|
|
1133
1057
|
shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
|
|
1134
1058
|
};
|
|
1135
|
-
|
|
1136
|
-
// 设置支付项的订单支付类型和 metadata
|
|
1137
1059
|
const paymentItemWithType = {
|
|
1138
1060
|
...processedPaymentItem,
|
|
1139
1061
|
order_payment_type: orderPaymentType,
|
|
1140
1062
|
metadata
|
|
1141
1063
|
};
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1064
|
+
await this.payment.addPaymentItemAsync(
|
|
1065
|
+
this.store.currentOrder.uuid,
|
|
1066
|
+
paymentItemWithType
|
|
1067
|
+
);
|
|
1068
|
+
this.logInfo("支付项添加成功");
|
|
1148
1069
|
this.clearCalculationCache();
|
|
1149
|
-
|
|
1150
|
-
// 支付项添加后,更新 stateAmount 为剩余未支付金额
|
|
1151
1070
|
await this.updateStateAmountToRemaining();
|
|
1152
|
-
|
|
1153
|
-
// 检查订单金额是否还有待付的,如果有才同步 EFTPOS 支付
|
|
1154
1071
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1155
1072
|
if (Number(remainingAmount) > 0) {
|
|
1156
|
-
this.logInfo(
|
|
1157
|
-
|
|
1158
|
-
const
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
this.logInfo('EFTPOS 支付检查:', {
|
|
1073
|
+
this.logInfo("订单金额还有待付的,同步 EFTPOS 支付");
|
|
1074
|
+
const isEftposPayment2 = ((_d = paymentItem.type) == null ? void 0 : _d.toLowerCase()) === "eftpos" || ((_e = paymentItem.code) == null ? void 0 : _e.toUpperCase().includes("EFTPOS"));
|
|
1075
|
+
const isCash = (0, import_utils.isCashPayment)(paymentItem);
|
|
1076
|
+
const isCustomePayment = paymentItem.type === "custom";
|
|
1077
|
+
this.logInfo("EFTPOS 支付检查:", {
|
|
1162
1078
|
paymentCode: paymentItem.code,
|
|
1163
1079
|
paymentType: paymentItem.type,
|
|
1164
|
-
isEftposPayment,
|
|
1080
|
+
isEftposPayment: isEftposPayment2,
|
|
1165
1081
|
currentOrderSynced: this.store.isOrderSynced
|
|
1166
1082
|
});
|
|
1167
|
-
if (
|
|
1168
|
-
this.logInfo(
|
|
1083
|
+
if (isEftposPayment2 || isCash || isCustomePayment) {
|
|
1084
|
+
this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
|
|
1169
1085
|
try {
|
|
1170
|
-
// EFTPOS 支付后的同步标记为手动同步,确保 OnOrderSynced 事件中 isManual = true
|
|
1171
1086
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1172
|
-
this.logInfo(
|
|
1087
|
+
this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
|
|
1173
1088
|
orderId: syncResult.orderId,
|
|
1174
1089
|
isOrderSynced: this.store.isOrderSynced,
|
|
1175
1090
|
backendResponse: syncResult.response
|
|
1176
1091
|
});
|
|
1177
1092
|
} catch (error) {
|
|
1178
|
-
this.logError(
|
|
1179
|
-
|
|
1180
|
-
|
|
1093
|
+
this.logError("EFTPOS 支付后订单同步失败:", error);
|
|
1094
|
+
await this.handleError(
|
|
1095
|
+
new Error(
|
|
1096
|
+
`EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
1097
|
+
),
|
|
1098
|
+
import_types.CheckoutErrorType.OrderCreationFailed
|
|
1099
|
+
);
|
|
1181
1100
|
}
|
|
1182
1101
|
}
|
|
1183
1102
|
}
|
|
1184
|
-
// 触发支付项添加事件(可以复用支付开始事件)
|
|
1185
1103
|
this.core.effects.emit(`${this.name}:onPaymentItemAdded`, {
|
|
1186
1104
|
orderUuid: this.store.currentOrder.uuid,
|
|
1187
1105
|
paymentMethodCode: paymentItem.code,
|
|
@@ -1190,12 +1108,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1190
1108
|
timestamp: Date.now()
|
|
1191
1109
|
});
|
|
1192
1110
|
} catch (error) {
|
|
1193
|
-
this.logError(
|
|
1194
|
-
await this.handleError(error,
|
|
1111
|
+
this.logError("添加支付项失败:", error);
|
|
1112
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1195
1113
|
throw error;
|
|
1196
1114
|
}
|
|
1197
1115
|
}
|
|
1198
|
-
|
|
1199
1116
|
/**
|
|
1200
1117
|
* 删除当前订单的支付项
|
|
1201
1118
|
*
|
|
@@ -1207,56 +1124,59 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1207
1124
|
*/
|
|
1208
1125
|
async deletePaymentItemAsync(paymentUuid) {
|
|
1209
1126
|
try {
|
|
1210
|
-
// 检查是否有当前订单
|
|
1211
1127
|
if (!this.store.currentOrder) {
|
|
1212
|
-
throw (0,
|
|
1128
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1129
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1130
|
+
"当前没有活跃订单,无法删除支付项"
|
|
1131
|
+
);
|
|
1213
1132
|
}
|
|
1214
|
-
this.logWarning(
|
|
1133
|
+
this.logWarning("开始删除支付项:", {
|
|
1215
1134
|
orderUuid: this.store.currentOrder.uuid,
|
|
1216
|
-
paymentUuid
|
|
1135
|
+
paymentUuid
|
|
1217
1136
|
});
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1137
|
+
const currentPayments = await this.payment.getPaymentItemsAsync(
|
|
1138
|
+
this.store.currentOrder.uuid,
|
|
1139
|
+
true
|
|
1140
|
+
// 包括已撤销的支付项,因为我们需要验证是否存在
|
|
1221
1141
|
);
|
|
1222
|
-
const paymentItem = currentPayments.find(p => p.uuid === paymentUuid);
|
|
1142
|
+
const paymentItem = currentPayments.find((p) => p.uuid === paymentUuid);
|
|
1223
1143
|
if (!paymentItem) {
|
|
1224
|
-
throw (0,
|
|
1144
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1145
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1146
|
+
`支付项不存在: ${paymentUuid}`
|
|
1147
|
+
);
|
|
1225
1148
|
}
|
|
1226
|
-
this.logInfo(
|
|
1149
|
+
this.logInfo("找到要删除的支付项:", {
|
|
1227
1150
|
uuid: paymentItem.uuid,
|
|
1228
1151
|
code: paymentItem.code,
|
|
1229
1152
|
amount: paymentItem.amount,
|
|
1230
1153
|
status: paymentItem.status
|
|
1231
1154
|
});
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1155
|
+
await this.payment.deletePaymentAsync(
|
|
1156
|
+
this.store.currentOrder.uuid,
|
|
1157
|
+
paymentUuid
|
|
1158
|
+
);
|
|
1159
|
+
this.logInfo("Payment支付项删除完成", paymentItem);
|
|
1238
1160
|
this.clearCalculationCache();
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1243
|
-
|
|
1161
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
1162
|
+
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1163
|
+
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
1164
|
+
this.store.currentOrder.uuid
|
|
1165
|
+
);
|
|
1244
1166
|
if (updatedOrder) {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1167
|
+
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1168
|
+
this.logWarning(
|
|
1169
|
+
"[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1170
|
+
{
|
|
1171
|
+
currentRealId: currentOrderId,
|
|
1172
|
+
retrievedVirtualId: updatedOrder.order_id
|
|
1173
|
+
}
|
|
1174
|
+
);
|
|
1175
|
+
updatedOrder.order_id = currentOrderId;
|
|
1252
1176
|
}
|
|
1253
1177
|
this.store.currentOrder = updatedOrder;
|
|
1254
1178
|
}
|
|
1255
|
-
|
|
1256
|
-
// 更新 stateAmount 为剩余未支付金额
|
|
1257
1179
|
await this.updateStateAmountToRemaining(false);
|
|
1258
|
-
|
|
1259
|
-
// 触发支付项删除事件
|
|
1260
1180
|
await this.core.effects.emit(`${this.name}:onPaymentStarted`, {
|
|
1261
1181
|
orderUuid: this.store.currentOrder.uuid,
|
|
1262
1182
|
paymentMethodCode: paymentItem.code,
|
|
@@ -1265,12 +1185,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1265
1185
|
timestamp: Date.now()
|
|
1266
1186
|
});
|
|
1267
1187
|
} catch (error) {
|
|
1268
|
-
this.logError(
|
|
1269
|
-
await this.handleError(error,
|
|
1188
|
+
this.logError("删除支付项失败:", error);
|
|
1189
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1270
1190
|
throw error;
|
|
1271
1191
|
}
|
|
1272
1192
|
}
|
|
1273
|
-
|
|
1274
1193
|
/**
|
|
1275
1194
|
* 批量更新当前订单的代金券支付项(覆盖更新)
|
|
1276
1195
|
*
|
|
@@ -1283,56 +1202,55 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1283
1202
|
*/
|
|
1284
1203
|
async updateVoucherPaymentItemsAsync(voucherPaymentItems) {
|
|
1285
1204
|
try {
|
|
1286
|
-
this.logInfo(
|
|
1205
|
+
this.logInfo("updateVoucherPaymentItemsAsync called:", {
|
|
1287
1206
|
voucherPaymentItems
|
|
1288
1207
|
});
|
|
1289
|
-
// 检查是否有当前订单
|
|
1290
1208
|
if (!this.store.currentOrder) {
|
|
1291
|
-
throw (0,
|
|
1209
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1210
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1211
|
+
"当前没有活跃订单,无法更新代金券支付项"
|
|
1212
|
+
);
|
|
1292
1213
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
if (!voucherPaymentItems || voucherPaymentItems
|
|
1297
|
-
const savedVoucherPaymentItems = paymentItems
|
|
1298
|
-
this.logInfo(
|
|
1214
|
+
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
1215
|
+
this.store.currentOrder.uuid
|
|
1216
|
+
);
|
|
1217
|
+
if (!voucherPaymentItems || (voucherPaymentItems == null ? void 0 : voucherPaymentItems.length) === 0) {
|
|
1218
|
+
const savedVoucherPaymentItems = (paymentItems == null ? void 0 : paymentItems.filter((item) => item.voucher_id && !item.isSynced)) || [];
|
|
1219
|
+
this.logInfo("未传入 voucher 且本地订单无 voucher 记录,阻断updateVoucherPaymentItemsAsync", {
|
|
1299
1220
|
voucherPaymentItems,
|
|
1300
1221
|
savedVoucherPaymentItems
|
|
1301
1222
|
});
|
|
1302
|
-
if (savedVoucherPaymentItems
|
|
1223
|
+
if ((savedVoucherPaymentItems == null ? void 0 : savedVoucherPaymentItems.length) === 0) {
|
|
1303
1224
|
this.updateStateAmountToRemaining(false);
|
|
1304
1225
|
return;
|
|
1305
1226
|
}
|
|
1306
1227
|
}
|
|
1307
|
-
const allPaymentItemsSynced = paymentItems.every(item => item.isSynced);
|
|
1228
|
+
const allPaymentItemsSynced = paymentItems.every((item) => item.isSynced);
|
|
1308
1229
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1309
|
-
const remainingValue = new
|
|
1230
|
+
const remainingValue = new import_decimal.default(remainingAmount);
|
|
1310
1231
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1311
1232
|
if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced) {
|
|
1312
|
-
this.logInfo(
|
|
1233
|
+
this.logInfo("订单已同步且支付完成,跳过清空代金券操作避免重复同步:", {
|
|
1313
1234
|
orderUuid: this.store.currentOrder.uuid,
|
|
1314
1235
|
orderId: this.store.currentOrder.order_id,
|
|
1315
1236
|
remainingAmount,
|
|
1316
1237
|
isOrderSynced,
|
|
1317
1238
|
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
1318
|
-
reason:
|
|
1239
|
+
reason: "Order synced and payment completed, skip clear vouchers to avoid duplicate sync"
|
|
1319
1240
|
});
|
|
1320
|
-
return;
|
|
1241
|
+
return;
|
|
1321
1242
|
}
|
|
1322
|
-
this.logInfo(
|
|
1243
|
+
this.logInfo("开始批量更新代金券支付项:", {
|
|
1323
1244
|
voucherPaymentItems
|
|
1324
1245
|
});
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal';
|
|
1328
|
-
|
|
1329
|
-
// 验证所有支付项都包含 voucher_id,并设置 order_payment_type 和 metadata
|
|
1330
|
-
const voucherPaymentItemsWithType = voucherPaymentItems.map(item => {
|
|
1246
|
+
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
1247
|
+
const voucherPaymentItemsWithType = voucherPaymentItems.map((item) => {
|
|
1331
1248
|
if (!item.voucher_id) {
|
|
1332
|
-
throw (0,
|
|
1249
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1250
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1251
|
+
`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`
|
|
1252
|
+
);
|
|
1333
1253
|
}
|
|
1334
|
-
|
|
1335
|
-
// 从 otherParams 获取 metadata 字段
|
|
1336
1254
|
const metadata = {
|
|
1337
1255
|
...item.metadata,
|
|
1338
1256
|
rounding_rule: this.otherParams.order_rounding_setting,
|
|
@@ -1344,49 +1262,43 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1344
1262
|
metadata
|
|
1345
1263
|
};
|
|
1346
1264
|
});
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1265
|
+
await this.payment.updateVoucherPaymentItemsAsync(
|
|
1266
|
+
this.store.currentOrder.uuid,
|
|
1267
|
+
voucherPaymentItemsWithType
|
|
1268
|
+
);
|
|
1352
1269
|
this.clearCalculationCache();
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1270
|
+
const currentOrderId = this.store.currentOrder.order_id;
|
|
1271
|
+
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
1272
|
+
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
1273
|
+
this.store.currentOrder.uuid
|
|
1274
|
+
);
|
|
1358
1275
|
if (updatedOrder) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1276
|
+
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1277
|
+
this.logWarning(
|
|
1278
|
+
"updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1279
|
+
{
|
|
1280
|
+
currentRealId: currentOrderId,
|
|
1281
|
+
retrievedVirtualId: updatedOrder.order_id
|
|
1282
|
+
}
|
|
1283
|
+
);
|
|
1284
|
+
updatedOrder.order_id = currentOrderId;
|
|
1366
1285
|
}
|
|
1367
1286
|
this.store.currentOrder = updatedOrder;
|
|
1368
1287
|
}
|
|
1369
|
-
|
|
1370
|
-
// 更新 stateAmount 为剩余未支付金额
|
|
1371
1288
|
await this.updateStateAmountToRemaining(false);
|
|
1372
|
-
|
|
1373
|
-
// 触发支付项更新事件
|
|
1374
1289
|
await this.core.effects.emit(`${this.name}:onPaymentStarted`, {
|
|
1375
1290
|
orderUuid: this.store.currentOrder.uuid,
|
|
1376
|
-
paymentMethodCode:
|
|
1291
|
+
paymentMethodCode: "VOUCHER_BATCH",
|
|
1377
1292
|
amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
|
|
1378
1293
|
timestamp: Date.now()
|
|
1379
1294
|
});
|
|
1380
|
-
this.logInfo(
|
|
1295
|
+
this.logInfo("代金券支付项批量更新成功");
|
|
1381
1296
|
} catch (error) {
|
|
1382
|
-
this.logInfo(
|
|
1383
|
-
|
|
1384
|
-
});
|
|
1385
|
-
await this.handleError(error, _types.CheckoutErrorType.PaymentFailed);
|
|
1297
|
+
this.logInfo("[Checkout] 批量更新代金券支付项失败:", { error });
|
|
1298
|
+
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1386
1299
|
throw error;
|
|
1387
1300
|
}
|
|
1388
1301
|
}
|
|
1389
|
-
|
|
1390
1302
|
/**
|
|
1391
1303
|
* 修改当前订单的定金状态
|
|
1392
1304
|
*
|
|
@@ -1397,77 +1309,62 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1397
1309
|
*/
|
|
1398
1310
|
async updateOrderDepositStatusAsync(isDeposit) {
|
|
1399
1311
|
try {
|
|
1400
|
-
// 验证参数
|
|
1401
1312
|
if (isDeposit !== 0 && isDeposit !== 1) {
|
|
1402
|
-
throw (0,
|
|
1313
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1314
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1315
|
+
"isDeposit 参数只能是 0(全款订单)或 1(定金订单)"
|
|
1316
|
+
);
|
|
1403
1317
|
}
|
|
1404
|
-
|
|
1405
|
-
// 检查是否有当前订单
|
|
1406
1318
|
if (!this.store.currentOrder) {
|
|
1407
|
-
throw (0,
|
|
1319
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1320
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1321
|
+
"未找到当前订单,无法修改定金状态"
|
|
1322
|
+
);
|
|
1408
1323
|
}
|
|
1409
1324
|
const newDepositValue = isDeposit;
|
|
1410
1325
|
const oldDepositValue = this.store.currentOrder.is_deposit;
|
|
1411
|
-
|
|
1412
|
-
// 如果状态没有变化,直接返回
|
|
1413
1326
|
if (oldDepositValue === newDepositValue) {
|
|
1327
|
+
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1414
1328
|
return;
|
|
1415
1329
|
}
|
|
1416
|
-
let deposit_amount = this.store.currentOrder.deposit_amount ||
|
|
1417
|
-
// 如果原来没有 deposit_amount,则默认把待付金额置为 deposit_amount
|
|
1330
|
+
let deposit_amount = this.store.currentOrder.deposit_amount || "0.00";
|
|
1418
1331
|
if (!deposit_amount || Number(deposit_amount) === 0) {
|
|
1419
1332
|
deposit_amount = this.store.currentOrder.expect_amount;
|
|
1420
1333
|
}
|
|
1421
|
-
|
|
1422
|
-
// 准备更新参数
|
|
1423
1334
|
const updateParams = {
|
|
1424
1335
|
is_deposit: newDepositValue,
|
|
1425
|
-
deposit_amount
|
|
1336
|
+
deposit_amount
|
|
1426
1337
|
};
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
// this.store.currentOrder.deposit_amount !== '0.00'
|
|
1432
|
-
// ) {
|
|
1433
|
-
// updateParams.deposit_amount = '0.00';
|
|
1434
|
-
// this.logInfo('订单从定金改为全款,清空定金金额');
|
|
1435
|
-
// }
|
|
1436
|
-
|
|
1437
|
-
// 调用 Payment 模块更新订单
|
|
1438
|
-
await this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
|
|
1439
|
-
|
|
1440
|
-
// 更新本地缓存的订单对象
|
|
1338
|
+
await this.payment.updateOrderAsync(
|
|
1339
|
+
this.store.currentOrder.uuid,
|
|
1340
|
+
updateParams
|
|
1341
|
+
);
|
|
1441
1342
|
this.store.currentOrder = {
|
|
1442
1343
|
...this.store.currentOrder,
|
|
1443
1344
|
...updateParams
|
|
1444
1345
|
};
|
|
1445
|
-
|
|
1446
|
-
// 同时更新本地订单数据(如果存在)
|
|
1447
1346
|
if (this.store.localOrderData) {
|
|
1448
1347
|
this.store.localOrderData.is_deposit = newDepositValue;
|
|
1449
1348
|
}
|
|
1450
|
-
|
|
1451
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1452
1349
|
this.clearCalculationCache();
|
|
1453
1350
|
this.updateStateAmountToRemaining(false);
|
|
1454
|
-
|
|
1455
|
-
// 触发订单更新事件
|
|
1456
1351
|
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
1457
1352
|
order: this.store.currentOrder,
|
|
1458
1353
|
timestamp: Date.now()
|
|
1459
1354
|
});
|
|
1460
|
-
this.logInfo(
|
|
1355
|
+
this.logInfo("订单定金状态更新成功:", {
|
|
1461
1356
|
isDeposit: newDepositValue,
|
|
1462
1357
|
depositAmount: this.store.currentOrder.deposit_amount
|
|
1463
1358
|
});
|
|
1464
1359
|
} catch (error) {
|
|
1465
|
-
this.logError(
|
|
1466
|
-
await this.handleError(
|
|
1360
|
+
this.logError("更新订单定金状态失败:", error);
|
|
1361
|
+
await this.handleError(
|
|
1362
|
+
error,
|
|
1363
|
+
import_types.CheckoutErrorType.ValidationFailed
|
|
1364
|
+
);
|
|
1467
1365
|
throw error;
|
|
1468
1366
|
}
|
|
1469
1367
|
}
|
|
1470
|
-
|
|
1471
1368
|
/**
|
|
1472
1369
|
* 手动设置当前订单的定金金额
|
|
1473
1370
|
*
|
|
@@ -1478,89 +1375,76 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1478
1375
|
* @throws 定金金额格式无效或超过订单总额时抛出错误
|
|
1479
1376
|
*/
|
|
1480
1377
|
async setDepositAmountAsync(depositAmount) {
|
|
1481
|
-
|
|
1378
|
+
var _a, _b;
|
|
1379
|
+
this.logInfo("setDepositAmountAsync called", {
|
|
1482
1380
|
depositAmount,
|
|
1483
1381
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1484
|
-
currentOrderId: this.store.currentOrder
|
|
1485
|
-
currentTotalAmount: this.store.currentOrder
|
|
1382
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
1383
|
+
currentTotalAmount: (_b = this.store.currentOrder) == null ? void 0 : _b.total_amount
|
|
1486
1384
|
});
|
|
1487
1385
|
try {
|
|
1488
|
-
|
|
1489
|
-
const depositValue = new _decimal.default(depositAmount);
|
|
1386
|
+
const depositValue = new import_decimal.default(depositAmount);
|
|
1490
1387
|
if (depositValue.isNaN() || depositValue.lt(0)) {
|
|
1491
|
-
throw (0,
|
|
1388
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1389
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1390
|
+
`无效的定金金额格式: ${depositAmount}`
|
|
1391
|
+
);
|
|
1492
1392
|
}
|
|
1493
|
-
|
|
1494
|
-
// 检查是否有当前订单
|
|
1495
1393
|
if (!this.store.currentOrder) {
|
|
1496
|
-
throw (0,
|
|
1394
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1395
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1396
|
+
"未找到当前订单,无法设置定金金额"
|
|
1397
|
+
);
|
|
1497
1398
|
}
|
|
1498
1399
|
const formattedDepositAmount = depositValue.toFixed(2);
|
|
1499
|
-
const oldDepositAmount = this.store.currentOrder.deposit_amount ||
|
|
1500
|
-
|
|
1501
|
-
// 如果定金金额没有变化,直接返回
|
|
1400
|
+
const oldDepositAmount = this.store.currentOrder.deposit_amount || "0.00";
|
|
1502
1401
|
if (formattedDepositAmount === oldDepositAmount) {
|
|
1503
|
-
this.logInfo(
|
|
1402
|
+
this.logInfo("定金金额无变化,跳过更新:", {
|
|
1504
1403
|
currentAmount: oldDepositAmount,
|
|
1505
1404
|
newAmount: formattedDepositAmount
|
|
1506
1405
|
});
|
|
1507
1406
|
return;
|
|
1508
1407
|
}
|
|
1509
|
-
this.logInfo(
|
|
1408
|
+
this.logInfo("开始设置订单定金金额:", {
|
|
1510
1409
|
orderUuid: this.store.currentOrder.uuid,
|
|
1511
1410
|
orderId: this.store.currentOrder.order_id,
|
|
1512
1411
|
oldDepositAmount,
|
|
1513
1412
|
newDepositAmount: formattedDepositAmount,
|
|
1514
1413
|
totalAmount: this.store.currentOrder.total_amount
|
|
1515
1414
|
});
|
|
1516
|
-
|
|
1517
|
-
// 准备更新参数
|
|
1518
1415
|
const updateParams = {
|
|
1519
1416
|
deposit_amount: formattedDepositAmount
|
|
1520
1417
|
};
|
|
1521
|
-
|
|
1522
|
-
// 如果设置的定金金额大于0,自动将订单标记为定金订单
|
|
1523
1418
|
if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
|
|
1524
1419
|
updateParams.is_deposit = 1;
|
|
1525
|
-
this.logInfo(
|
|
1526
|
-
}
|
|
1527
|
-
// 如果设置的定金金额为0,可以考虑将订单标记为全款订单
|
|
1528
|
-
else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
|
|
1420
|
+
this.logInfo("定金金额大于0,自动设置为定金订单");
|
|
1421
|
+
} else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
|
|
1529
1422
|
updateParams.is_deposit = 0;
|
|
1530
|
-
this.logInfo(
|
|
1423
|
+
this.logInfo("定金金额为0,自动设置为全款订单");
|
|
1531
1424
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
// 更新本地缓存的订单对象
|
|
1425
|
+
await this.payment.updateOrderAsync(
|
|
1426
|
+
this.store.currentOrder.uuid,
|
|
1427
|
+
updateParams
|
|
1428
|
+
);
|
|
1537
1429
|
this.store.currentOrder = {
|
|
1538
1430
|
...this.store.currentOrder,
|
|
1539
1431
|
...updateParams
|
|
1540
1432
|
};
|
|
1541
|
-
|
|
1542
|
-
// 同时更新本地订单数据(如果存在)
|
|
1543
1433
|
if (this.store.localOrderData) {
|
|
1544
|
-
|
|
1545
|
-
if ('deposit_amount' in this.store.localOrderData) {
|
|
1434
|
+
if ("deposit_amount" in this.store.localOrderData) {
|
|
1546
1435
|
this.store.localOrderData.deposit_amount = formattedDepositAmount;
|
|
1547
1436
|
}
|
|
1548
|
-
|
|
1549
|
-
if (updateParams.is_deposit !== undefined) {
|
|
1437
|
+
if (updateParams.is_deposit !== void 0) {
|
|
1550
1438
|
this.store.localOrderData.is_deposit = updateParams.is_deposit;
|
|
1551
1439
|
}
|
|
1552
1440
|
}
|
|
1553
|
-
|
|
1554
|
-
// 🚀 清除计算缓存,确保获取最新数据
|
|
1555
1441
|
this.clearCalculationCache();
|
|
1556
1442
|
this.updateStateAmountToRemaining(false);
|
|
1557
|
-
|
|
1558
|
-
// 触发订单更新事件
|
|
1559
1443
|
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
1560
1444
|
order: this.store.currentOrder,
|
|
1561
1445
|
timestamp: Date.now()
|
|
1562
1446
|
});
|
|
1563
|
-
this.logInfo(
|
|
1447
|
+
this.logInfo("订单定金金额设置成功:", {
|
|
1564
1448
|
orderUuid: this.store.currentOrder.uuid,
|
|
1565
1449
|
orderId: this.store.currentOrder.order_id,
|
|
1566
1450
|
oldDepositAmount,
|
|
@@ -1569,83 +1453,84 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1569
1453
|
totalAmount: this.store.currentOrder.total_amount
|
|
1570
1454
|
});
|
|
1571
1455
|
} catch (error) {
|
|
1572
|
-
this.logError(
|
|
1573
|
-
await this.handleError(
|
|
1456
|
+
this.logError("设置订单定金金额失败:", error);
|
|
1457
|
+
await this.handleError(
|
|
1458
|
+
error,
|
|
1459
|
+
import_types.CheckoutErrorType.ValidationFailed
|
|
1460
|
+
);
|
|
1574
1461
|
throw error;
|
|
1575
1462
|
}
|
|
1576
1463
|
}
|
|
1577
|
-
|
|
1578
1464
|
/**
|
|
1579
1465
|
* 手动同步订单到后端
|
|
1580
1466
|
*
|
|
1581
1467
|
* 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
|
|
1582
1468
|
*/
|
|
1583
1469
|
async manualSyncOrderAsync() {
|
|
1584
|
-
|
|
1470
|
+
var _a, _b, _c, _d, _e;
|
|
1471
|
+
console.log("manualSyncOrderAsync called");
|
|
1472
|
+
this.logInfo("manualSyncOrderAsync called", {
|
|
1585
1473
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1586
|
-
currentOrderId: this.store.currentOrder
|
|
1587
|
-
orderUuid: this.store.currentOrder
|
|
1588
|
-
totalAmount: this.store.currentOrder
|
|
1474
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
1475
|
+
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1476
|
+
totalAmount: (_c = this.store.currentOrder) == null ? void 0 : _c.total_amount,
|
|
1589
1477
|
isOrderSynced: this.store.isOrderSynced,
|
|
1590
|
-
isVirtualOrderId: this.store.currentOrder ? (0,
|
|
1478
|
+
isVirtualOrderId: this.store.currentOrder ? (0, import_utils.isVirtualOrderId)(this.store.currentOrder.order_id) : false
|
|
1591
1479
|
});
|
|
1592
1480
|
try {
|
|
1593
|
-
// 检查是否有当前订单
|
|
1594
1481
|
if (!this.store.currentOrder) {
|
|
1595
1482
|
return {
|
|
1596
1483
|
success: false,
|
|
1597
|
-
message:
|
|
1484
|
+
message: "当前没有活跃订单,无法同步"
|
|
1598
1485
|
};
|
|
1599
1486
|
}
|
|
1600
1487
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1601
1488
|
const oldOrderId = this.store.currentOrder.order_id;
|
|
1602
|
-
|
|
1603
|
-
// 检查订单是否已经同步
|
|
1604
1489
|
if (this.store.isOrderSynced) {
|
|
1605
|
-
this.logInfo(
|
|
1490
|
+
this.logInfo("订单已同步过,将执行更新操作");
|
|
1606
1491
|
}
|
|
1607
|
-
this.logInfo(
|
|
1608
|
-
orderUuid
|
|
1492
|
+
this.logInfo("开始手动同步订单到后端:", {
|
|
1493
|
+
orderUuid,
|
|
1609
1494
|
orderId: oldOrderId,
|
|
1610
1495
|
totalAmount: this.store.currentOrder.total_amount,
|
|
1611
1496
|
remainingAmount: await this.calculateRemainingAmountAsync()
|
|
1612
1497
|
});
|
|
1613
|
-
|
|
1498
|
+
console.time("manualSyncOrderAsync");
|
|
1614
1499
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1500
|
+
console.timeEnd("manualSyncOrderAsync");
|
|
1501
|
+
this.logInfo("手动同步订单完成:", {
|
|
1502
|
+
orderUuid,
|
|
1503
|
+
syncResult,
|
|
1504
|
+
oldOrderId,
|
|
1619
1505
|
realOrderId: syncResult.orderId,
|
|
1620
1506
|
isOrderSynced: this.store.isOrderSynced
|
|
1621
1507
|
});
|
|
1622
|
-
|
|
1623
|
-
// 🔍 关键验证:检查最终状态是否正确
|
|
1624
1508
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1625
|
-
const finalIsVirtual = (0,
|
|
1509
|
+
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId);
|
|
1626
1510
|
if (finalIsVirtual) {
|
|
1627
|
-
this.logError(
|
|
1511
|
+
this.logError("严重警告:手动同步完成后订单ID仍为虚拟ID!");
|
|
1628
1512
|
}
|
|
1629
1513
|
if (syncResult.orderId !== finalOrderId) {
|
|
1630
|
-
this.logError(
|
|
1514
|
+
this.logError(
|
|
1515
|
+
"[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
|
|
1516
|
+
);
|
|
1631
1517
|
}
|
|
1632
1518
|
let newRes = {
|
|
1633
1519
|
...syncResult,
|
|
1634
|
-
is_deposit: this.store.currentOrder
|
|
1520
|
+
is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0
|
|
1635
1521
|
};
|
|
1636
1522
|
await this.updateStateAmountToRemaining(false);
|
|
1637
1523
|
return newRes;
|
|
1638
1524
|
} catch (error) {
|
|
1639
|
-
this.logError(
|
|
1640
|
-
const errorMessage = error instanceof Error ? error.message :
|
|
1525
|
+
this.logError("手动同步订单失败:", error);
|
|
1526
|
+
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1641
1527
|
return {
|
|
1642
1528
|
success: false,
|
|
1643
1529
|
message: `订单同步失败: ${errorMessage}`,
|
|
1644
|
-
orderUuid: this.store.currentOrder
|
|
1530
|
+
orderUuid: (_e = this.store.currentOrder) == null ? void 0 : _e.uuid
|
|
1645
1531
|
};
|
|
1646
1532
|
}
|
|
1647
1533
|
}
|
|
1648
|
-
|
|
1649
1534
|
/**
|
|
1650
1535
|
* 获取当前订单备注
|
|
1651
1536
|
*
|
|
@@ -1653,11 +1538,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1653
1538
|
*/
|
|
1654
1539
|
getOrderNote() {
|
|
1655
1540
|
if (!this.store.localOrderData) {
|
|
1656
|
-
|
|
1541
|
+
console.log("[Checkout] 没有本地订单数据,无法获取备注");
|
|
1542
|
+
return "";
|
|
1657
1543
|
}
|
|
1658
|
-
return this.store.localOrderData.shop_note ||
|
|
1544
|
+
return this.store.localOrderData.shop_note || "";
|
|
1659
1545
|
}
|
|
1660
|
-
|
|
1661
1546
|
/**
|
|
1662
1547
|
* 获取当前订单ID
|
|
1663
1548
|
*
|
|
@@ -1669,21 +1554,24 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1669
1554
|
}
|
|
1670
1555
|
return this.store.currentOrder.order_id;
|
|
1671
1556
|
}
|
|
1672
|
-
|
|
1673
1557
|
/**
|
|
1674
1558
|
* 获取当前订单是否已同步到后端
|
|
1675
1559
|
*
|
|
1676
1560
|
* @returns 当前订单是否已同步状态,如果没有订单则返回false
|
|
1677
1561
|
*/
|
|
1678
1562
|
isCurrentOrderSynced() {
|
|
1679
|
-
// 如果没有当前订单,返回false
|
|
1680
1563
|
if (!this.store.currentOrder) {
|
|
1564
|
+
console.log("[Checkout] 没有当前订单,同步状态为false");
|
|
1681
1565
|
return false;
|
|
1682
1566
|
}
|
|
1683
1567
|
const syncStatus = this.store.isOrderSynced;
|
|
1568
|
+
console.log("[Checkout] 当前订单同步状态:", {
|
|
1569
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1570
|
+
orderId: this.store.currentOrder.order_id,
|
|
1571
|
+
isOrderSynced: syncStatus
|
|
1572
|
+
});
|
|
1684
1573
|
return syncStatus;
|
|
1685
1574
|
}
|
|
1686
|
-
|
|
1687
1575
|
/**
|
|
1688
1576
|
* 取消当前本地订单
|
|
1689
1577
|
*
|
|
@@ -1693,92 +1581,81 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1693
1581
|
* @returns 取消结果
|
|
1694
1582
|
*/
|
|
1695
1583
|
async cancelCurrentOrderAsync(cancelReason) {
|
|
1584
|
+
var _a, _b;
|
|
1696
1585
|
try {
|
|
1697
|
-
this.logInfo(
|
|
1586
|
+
this.logInfo("开始取消当前本地订单:", {
|
|
1698
1587
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1699
|
-
orderUuid: this.store.currentOrder
|
|
1700
|
-
orderId: this.store.currentOrder
|
|
1588
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1589
|
+
orderId: (_b = this.store.currentOrder) == null ? void 0 : _b.order_id,
|
|
1701
1590
|
isOrderSynced: this.store.isOrderSynced,
|
|
1702
|
-
cancelReason
|
|
1591
|
+
cancelReason
|
|
1703
1592
|
});
|
|
1704
|
-
|
|
1705
|
-
// 检查是否有当前订单
|
|
1706
1593
|
if (!this.store.currentOrder) {
|
|
1707
|
-
this.logInfo(
|
|
1594
|
+
this.logInfo("没有当前订单,无需取消");
|
|
1708
1595
|
return {
|
|
1709
1596
|
success: false,
|
|
1710
|
-
message:
|
|
1597
|
+
message: "没有当前订单可取消"
|
|
1711
1598
|
};
|
|
1712
1599
|
}
|
|
1713
1600
|
const currentOrderUuid = this.store.currentOrder.uuid;
|
|
1714
1601
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1715
1602
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1716
|
-
|
|
1717
|
-
// 检查订单是否已同步,已同步的订单不能取消
|
|
1718
1603
|
if (isOrderSynced) {
|
|
1719
|
-
this.logInfo(
|
|
1604
|
+
this.logInfo("订单已同步到后端,不能取消:", {
|
|
1720
1605
|
orderId: currentOrderId,
|
|
1721
1606
|
orderUuid: currentOrderUuid
|
|
1722
1607
|
});
|
|
1723
1608
|
return {
|
|
1724
1609
|
success: false,
|
|
1725
|
-
message:
|
|
1610
|
+
message: "订单已同步到后端,无法取消",
|
|
1726
1611
|
orderId: currentOrderId
|
|
1727
1612
|
};
|
|
1728
1613
|
}
|
|
1729
|
-
// 标记本地订单为已删除(不从 IndexDB 物理删除)
|
|
1730
1614
|
try {
|
|
1731
|
-
this.logInfo(
|
|
1615
|
+
this.logInfo("标记本地订单为已删除");
|
|
1732
1616
|
await this.payment.updateOrderAsync(currentOrderUuid, {
|
|
1733
|
-
payment_status:
|
|
1617
|
+
payment_status: import_types2.PaymentStatus.Voided
|
|
1734
1618
|
});
|
|
1735
|
-
this.logInfo(
|
|
1619
|
+
this.logInfo("本地订单删除标记成功");
|
|
1736
1620
|
} catch (error) {
|
|
1737
|
-
this.logWarning(
|
|
1621
|
+
this.logWarning("标记本地订单删除失败,但继续执行:", error);
|
|
1738
1622
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
this.
|
|
1742
|
-
this.store.
|
|
1743
|
-
this.store.
|
|
1744
|
-
this.store.stateAmount = '0.00';
|
|
1745
|
-
this.store.balanceDueAmount = '0.00';
|
|
1623
|
+
this.logInfo("清理订单相关状态");
|
|
1624
|
+
this.store.currentOrder = void 0;
|
|
1625
|
+
this.store.localOrderData = void 0;
|
|
1626
|
+
this.store.stateAmount = "0.00";
|
|
1627
|
+
this.store.balanceDueAmount = "0.00";
|
|
1746
1628
|
this.store.isOrderSynced = false;
|
|
1747
|
-
this.store.currentCustomer =
|
|
1748
|
-
|
|
1749
|
-
// 清理钱包缓存
|
|
1629
|
+
this.store.currentCustomer = void 0;
|
|
1750
1630
|
this.payment.wallet.clearAllCache();
|
|
1751
|
-
this.logInfo(
|
|
1752
|
-
|
|
1753
|
-
// 触发订单取消事件
|
|
1631
|
+
this.logInfo("订单状态清理完成,currentOrder已释放");
|
|
1754
1632
|
await this.core.effects.emit(`${this.name}:onOrderCancelled`, {
|
|
1755
1633
|
orderUuid: currentOrderUuid,
|
|
1756
1634
|
orderId: currentOrderId,
|
|
1757
|
-
cancelReason
|
|
1635
|
+
cancelReason,
|
|
1758
1636
|
wasSynced: false,
|
|
1759
1637
|
// 只有未同步订单可以被取消
|
|
1760
1638
|
timestamp: Date.now()
|
|
1761
1639
|
});
|
|
1762
|
-
this.logInfo(
|
|
1640
|
+
this.logInfo("本地订单取消完成:", {
|
|
1763
1641
|
orderUuid: currentOrderUuid,
|
|
1764
1642
|
orderId: currentOrderId,
|
|
1765
|
-
cancelReason
|
|
1643
|
+
cancelReason
|
|
1766
1644
|
});
|
|
1767
1645
|
return {
|
|
1768
1646
|
success: true,
|
|
1769
|
-
message:
|
|
1647
|
+
message: "本地订单已成功取消",
|
|
1770
1648
|
orderId: currentOrderId
|
|
1771
1649
|
};
|
|
1772
1650
|
} catch (error) {
|
|
1773
|
-
this.logError(
|
|
1774
|
-
const errorMessage = error instanceof Error ? error.message :
|
|
1651
|
+
this.logError("取消本地订单失败:", error);
|
|
1652
|
+
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
|
1775
1653
|
return {
|
|
1776
1654
|
success: false,
|
|
1777
1655
|
message: `取消订单失败: ${errorMessage}`
|
|
1778
1656
|
};
|
|
1779
1657
|
}
|
|
1780
1658
|
}
|
|
1781
|
-
|
|
1782
1659
|
/**
|
|
1783
1660
|
* 保存订单并稍后支付
|
|
1784
1661
|
*
|
|
@@ -1786,149 +1663,163 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1786
1663
|
* 适用于用户想要保存订单但稍后完成支付的场景
|
|
1787
1664
|
*/
|
|
1788
1665
|
async saveForLaterPaymentAsync() {
|
|
1666
|
+
var _a;
|
|
1789
1667
|
try {
|
|
1790
|
-
// 检查是否有当前订单
|
|
1791
1668
|
if (!this.store.currentOrder) {
|
|
1792
1669
|
return {
|
|
1793
1670
|
success: false,
|
|
1794
|
-
message:
|
|
1671
|
+
message: "当前没有活跃订单,无法保存"
|
|
1795
1672
|
};
|
|
1796
1673
|
}
|
|
1797
1674
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1798
1675
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1799
|
-
this.logInfo(
|
|
1800
|
-
orderUuid
|
|
1676
|
+
this.logInfo("开始保存订单并稍后支付:", {
|
|
1677
|
+
orderUuid,
|
|
1801
1678
|
orderId: currentOrderId,
|
|
1802
1679
|
totalAmount: this.store.currentOrder.total_amount
|
|
1803
1680
|
});
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
orderUuid: orderUuid,
|
|
1681
|
+
const allPaymentItems = await this.payment.getPaymentItemsAsync(
|
|
1682
|
+
this.store.currentOrder.uuid
|
|
1683
|
+
);
|
|
1684
|
+
const orderPaymentStatus = allPaymentItems.filter((item) => item.status !== "voided").length > 0 ? "partially_paid" : "payment_processing";
|
|
1685
|
+
const syncResult = await this.syncOrderToBackendWithReturn(
|
|
1686
|
+
true,
|
|
1687
|
+
allPaymentItems,
|
|
1688
|
+
orderPaymentStatus
|
|
1689
|
+
);
|
|
1690
|
+
this.logInfo("保存订单完成:", {
|
|
1691
|
+
orderUuid,
|
|
1816
1692
|
oldOrderId: currentOrderId,
|
|
1817
|
-
syncResult
|
|
1693
|
+
syncResult,
|
|
1818
1694
|
realOrderId: syncResult.orderId,
|
|
1819
1695
|
isOrderSynced: this.store.isOrderSynced,
|
|
1820
1696
|
filteredPaymentsCount: allPaymentItems.length
|
|
1821
1697
|
});
|
|
1822
1698
|
return {
|
|
1823
1699
|
success: true,
|
|
1824
|
-
message:
|
|
1700
|
+
message: "订单保存成功,可稍后继续支付",
|
|
1825
1701
|
orderId: syncResult.orderId,
|
|
1826
|
-
orderUuid
|
|
1702
|
+
orderUuid,
|
|
1827
1703
|
response: syncResult.response
|
|
1828
1704
|
};
|
|
1829
1705
|
} catch (error) {
|
|
1830
|
-
this.logError(
|
|
1831
|
-
const errorMessage = error instanceof Error ? error.message :
|
|
1706
|
+
this.logError("保存订单失败:", error);
|
|
1707
|
+
const errorMessage = error instanceof Error ? error.message : "保存失败";
|
|
1832
1708
|
return {
|
|
1833
1709
|
success: false,
|
|
1834
1710
|
message: `订单保存失败: ${errorMessage}`,
|
|
1835
|
-
orderUuid: this.store.currentOrder
|
|
1711
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
1836
1712
|
};
|
|
1837
1713
|
}
|
|
1838
1714
|
}
|
|
1839
|
-
|
|
1840
1715
|
/**
|
|
1841
1716
|
* 更新订单备注
|
|
1842
1717
|
*
|
|
1843
1718
|
* @param note 订单备注内容
|
|
1844
1719
|
*/
|
|
1845
1720
|
async updateOrderNoteAsync(note) {
|
|
1721
|
+
var _a, _b;
|
|
1846
1722
|
try {
|
|
1847
|
-
// 检查是否有本地订单数据
|
|
1848
1723
|
if (!this.store.localOrderData) {
|
|
1849
|
-
throw (0,
|
|
1724
|
+
throw (0, import_utils.createCheckoutError)(
|
|
1725
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
1726
|
+
"没有本地订单数据,无法更新备注"
|
|
1727
|
+
);
|
|
1850
1728
|
}
|
|
1851
|
-
|
|
1729
|
+
console.log("[Checkout] 更新订单备注:", {
|
|
1730
|
+
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1731
|
+
oldNote: this.store.localOrderData.shop_note,
|
|
1732
|
+
newNote: note
|
|
1733
|
+
});
|
|
1852
1734
|
const oldNote = this.store.localOrderData.shop_note;
|
|
1853
1735
|
this.store.localOrderData.shop_note = note;
|
|
1854
|
-
|
|
1855
|
-
// 如果有当前订单,也同步到Payment模块中的订单数据
|
|
1856
1736
|
if (this.store.currentOrder) {
|
|
1857
|
-
// 更新Payment模块中的订单数据(如果订单对象中有note字段)
|
|
1858
1737
|
try {
|
|
1859
|
-
const orderInPayment = await this.payment.getPaymentOrderByUuidAsync(
|
|
1860
|
-
|
|
1738
|
+
const orderInPayment = await this.payment.getPaymentOrderByUuidAsync(
|
|
1739
|
+
this.store.currentOrder.uuid
|
|
1740
|
+
);
|
|
1741
|
+
if (orderInPayment && orderInPayment.note !== void 0) {
|
|
1742
|
+
console.log("[Checkout] 同步备注到Payment模块的订单数据中");
|
|
1743
|
+
}
|
|
1861
1744
|
} catch (syncError) {
|
|
1862
|
-
console.warn(
|
|
1745
|
+
console.warn(
|
|
1746
|
+
"[Checkout] 同步备注到Payment模块失败,但本地更新成功:",
|
|
1747
|
+
syncError
|
|
1748
|
+
);
|
|
1863
1749
|
}
|
|
1864
1750
|
}
|
|
1865
|
-
|
|
1866
|
-
// 触发订单数据变更事件
|
|
1867
1751
|
await this.core.effects.emit(`${this.name}:onOrderNoteChanged`, {
|
|
1868
|
-
orderUuid: this.store.currentOrder
|
|
1752
|
+
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1869
1753
|
oldNote,
|
|
1870
1754
|
newNote: note,
|
|
1871
1755
|
timestamp: Date.now()
|
|
1872
1756
|
});
|
|
1757
|
+
console.log("[Checkout] 订单备注更新成功:", {
|
|
1758
|
+
oldNote,
|
|
1759
|
+
newNote: note
|
|
1760
|
+
});
|
|
1873
1761
|
} catch (error) {
|
|
1874
|
-
console.error(
|
|
1875
|
-
await this.handleError(
|
|
1762
|
+
console.error("[Checkout] 更新订单备注失败:", error);
|
|
1763
|
+
await this.handleError(
|
|
1764
|
+
error,
|
|
1765
|
+
import_types.CheckoutErrorType.ValidationFailed
|
|
1766
|
+
);
|
|
1876
1767
|
throw error;
|
|
1877
1768
|
}
|
|
1878
1769
|
}
|
|
1879
|
-
|
|
1880
1770
|
/**
|
|
1881
1771
|
* 处理错误
|
|
1882
1772
|
*/
|
|
1883
1773
|
async handleError(error, type) {
|
|
1884
|
-
const checkoutError = error instanceof Error &&
|
|
1774
|
+
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
1885
1775
|
this.store.lastError = checkoutError;
|
|
1886
1776
|
await this.core.effects.emit(`${this.name}:onError`, {
|
|
1887
1777
|
error: checkoutError,
|
|
1888
1778
|
context: {},
|
|
1889
1779
|
timestamp: Date.now()
|
|
1890
1780
|
});
|
|
1891
|
-
console.error(
|
|
1781
|
+
console.error("[Checkout] 错误:", checkoutError);
|
|
1892
1782
|
}
|
|
1893
|
-
|
|
1894
1783
|
/**
|
|
1895
1784
|
* 处理支付成功
|
|
1896
1785
|
*/
|
|
1897
1786
|
async handlePaymentSuccess(data) {
|
|
1898
|
-
|
|
1787
|
+
var _a;
|
|
1899
1788
|
await this.updateStateAmountToRemaining();
|
|
1900
1789
|
await this.core.effects.emit(`${this.name}:onPaymentSuccess`, {
|
|
1901
1790
|
orderUuid: data.orderUuid,
|
|
1902
|
-
paymentMethodCode:
|
|
1903
|
-
amount: this.store.currentOrder
|
|
1791
|
+
paymentMethodCode: "",
|
|
1792
|
+
amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
|
|
1904
1793
|
timestamp: data.timestamp
|
|
1905
1794
|
});
|
|
1906
|
-
|
|
1907
|
-
// 自动完成结账
|
|
1908
1795
|
await this.completeCheckoutAsync();
|
|
1909
1796
|
}
|
|
1910
|
-
|
|
1911
1797
|
/**
|
|
1912
1798
|
* 处理支付错误
|
|
1913
1799
|
*/
|
|
1914
1800
|
async handlePaymentError(data) {
|
|
1915
|
-
|
|
1916
|
-
|
|
1801
|
+
var _a;
|
|
1802
|
+
const error = (0, import_utils.createCheckoutError)(
|
|
1803
|
+
import_types.CheckoutErrorType.PaymentFailed,
|
|
1804
|
+
data.error || "支付同步失败"
|
|
1805
|
+
);
|
|
1806
|
+
await this.handleError(
|
|
1807
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
1808
|
+
import_types.CheckoutErrorType.PaymentFailed
|
|
1809
|
+
);
|
|
1917
1810
|
await this.core.effects.emit(`${this.name}:onPaymentFailed`, {
|
|
1918
1811
|
orderUuid: data.orderUuid,
|
|
1919
|
-
paymentMethodCode:
|
|
1920
|
-
amount: this.store.currentOrder
|
|
1812
|
+
paymentMethodCode: "",
|
|
1813
|
+
amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
|
|
1921
1814
|
timestamp: data.timestamp
|
|
1922
1815
|
});
|
|
1923
1816
|
}
|
|
1924
|
-
|
|
1925
1817
|
/**
|
|
1926
1818
|
* 验证结账参数
|
|
1927
1819
|
*/
|
|
1928
1820
|
validateCheckoutParams(params) {
|
|
1929
|
-
return (0,
|
|
1821
|
+
return (0, import_utils.validateCheckoutData)(params);
|
|
1930
1822
|
}
|
|
1931
|
-
|
|
1932
1823
|
/**
|
|
1933
1824
|
* 处理现金支付项的找零逻辑
|
|
1934
1825
|
*
|
|
@@ -1936,51 +1827,40 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1936
1827
|
* @returns 处理后的支付项(包含找零信息)
|
|
1937
1828
|
*/
|
|
1938
1829
|
async processCashPaymentItem(paymentItem) {
|
|
1939
|
-
|
|
1940
|
-
const cashPayment = (0, _utils.isCashPayment)(paymentItem);
|
|
1830
|
+
const cashPayment = (0, import_utils.isCashPayment)(paymentItem);
|
|
1941
1831
|
if (!cashPayment) {
|
|
1942
|
-
// 非现金支付,直接返回原始支付项
|
|
1943
1832
|
return paymentItem;
|
|
1944
1833
|
}
|
|
1945
1834
|
try {
|
|
1946
|
-
// 获取剩余待付金额
|
|
1947
1835
|
const remainingAmountStr = await this.calculateRemainingAmountAsync();
|
|
1948
|
-
|
|
1949
|
-
const cashAmount = new
|
|
1950
|
-
|
|
1951
|
-
// 如果现金金额小于等于剩余待付金额,无需找零
|
|
1836
|
+
const remainingAmount = new import_decimal.default(remainingAmountStr);
|
|
1837
|
+
const cashAmount = new import_decimal.default(String(paymentItem.amount));
|
|
1838
|
+
const roundingAmount = new import_decimal.default(String(paymentItem.rounding_amount || "0"));
|
|
1952
1839
|
if (cashAmount.lte(remainingAmount)) {
|
|
1953
1840
|
return paymentItem;
|
|
1954
1841
|
}
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
if (Number(paymentItem.rounding_amount) === changeAmount.toNumber()) {
|
|
1962
|
-
return paymentItem;
|
|
1963
|
-
} else {
|
|
1964
|
-
// 如果不等于,则remainingAmount需要加上 rounding_amount,避免这里被改为未舍入金额
|
|
1965
|
-
remainingAmount = remainingAmount.add(new _decimal.default(paymentItem.rounding_amount || '0'));
|
|
1966
|
-
}
|
|
1842
|
+
const chargeAmount = import_decimal.default.max(
|
|
1843
|
+
remainingAmount.add(roundingAmount),
|
|
1844
|
+
new import_decimal.default(0)
|
|
1845
|
+
);
|
|
1846
|
+
if (cashAmount.lte(chargeAmount)) {
|
|
1847
|
+
return paymentItem;
|
|
1967
1848
|
}
|
|
1968
|
-
|
|
1969
|
-
// 创建包含找零信息的支付项
|
|
1849
|
+
const changeAmount = cashAmount.sub(chargeAmount);
|
|
1970
1850
|
const processedPaymentItem = {
|
|
1971
1851
|
...paymentItem,
|
|
1972
|
-
amount:
|
|
1973
|
-
// 将 amount 设置为剩余待付金额,保留2位小数
|
|
1852
|
+
amount: chargeAmount.toFixed(2),
|
|
1974
1853
|
metadata: {
|
|
1975
1854
|
...paymentItem.metadata,
|
|
1976
1855
|
actual_paid_amount: cashAmount.toNumber(),
|
|
1977
|
-
|
|
1978
|
-
change_given_amount: changeAmount.toNumber() // 找零金额
|
|
1856
|
+
change_given_amount: changeAmount.toNumber()
|
|
1979
1857
|
}
|
|
1980
1858
|
};
|
|
1981
|
-
this.logInfo(
|
|
1859
|
+
this.logInfo("Cash payment with change processed", {
|
|
1982
1860
|
originalAmount: cashAmount.toFixed(2),
|
|
1983
|
-
|
|
1861
|
+
remainingAmount: remainingAmount.toFixed(2),
|
|
1862
|
+
roundingAmount: roundingAmount.toFixed(2),
|
|
1863
|
+
chargedAmount: chargeAmount.toFixed(2),
|
|
1984
1864
|
changeAmount: changeAmount.toFixed(2),
|
|
1985
1865
|
paymentCode: paymentItem.code,
|
|
1986
1866
|
paymentType: paymentItem.type,
|
|
@@ -1988,87 +1868,85 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
1988
1868
|
decimalPrecisionCheck: {
|
|
1989
1869
|
cashAmountPrecise: cashAmount.toString(),
|
|
1990
1870
|
remainingAmountPrecise: remainingAmount.toString(),
|
|
1871
|
+
roundingAmountPrecise: roundingAmount.toString(),
|
|
1872
|
+
chargeAmountPrecise: chargeAmount.toString(),
|
|
1991
1873
|
changeAmountPrecise: changeAmount.toString()
|
|
1992
1874
|
}
|
|
1993
1875
|
});
|
|
1994
1876
|
return processedPaymentItem;
|
|
1995
1877
|
} catch (error) {
|
|
1996
|
-
this.logError(
|
|
1997
|
-
// 出错时返回原始支付项,避免中断支付流程
|
|
1878
|
+
this.logError("处理现金支付项时出错:", error);
|
|
1998
1879
|
return paymentItem;
|
|
1999
1880
|
}
|
|
2000
1881
|
}
|
|
2001
|
-
|
|
2002
1882
|
/**
|
|
2003
1883
|
* 预加载支付方式(在初始化时调用)
|
|
2004
1884
|
*/
|
|
2005
1885
|
async preloadPaymentMethods() {
|
|
2006
1886
|
try {
|
|
1887
|
+
console.log("[Checkout] 预加载支付方式...");
|
|
2007
1888
|
const methods = await this.payment.getPayMethodListAsync();
|
|
2008
1889
|
this.store.paymentMethods = methods;
|
|
1890
|
+
console.log(`[Checkout] 预加载完成,共 ${methods.length} 种支付方式`);
|
|
2009
1891
|
} catch (error) {
|
|
2010
|
-
console.error(
|
|
1892
|
+
console.error("[Checkout] 预加载支付方式失败:", error);
|
|
2011
1893
|
this.store.paymentMethods = [];
|
|
2012
1894
|
}
|
|
2013
1895
|
}
|
|
2014
|
-
|
|
2015
1896
|
/**
|
|
2016
1897
|
* 清理过期的已同步订单数据
|
|
2017
1898
|
*
|
|
2018
1899
|
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
2019
1900
|
*/
|
|
1901
|
+
/** @deprecated */
|
|
2020
1902
|
async cleanupExpiredOrdersAsync() {
|
|
1903
|
+
var _a, _b, _c;
|
|
2021
1904
|
try {
|
|
2022
|
-
// 检查是否启用了清理功能
|
|
2023
1905
|
const cleanupConfig = this.otherParams.orderDataCleanup || {};
|
|
2024
|
-
const isCleanupEnabled = cleanupConfig.enabled !== false;
|
|
2025
|
-
const retentionDays = cleanupConfig.retentionDays || 7;
|
|
2026
|
-
const maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100;
|
|
2027
|
-
|
|
1906
|
+
const isCleanupEnabled = cleanupConfig.enabled !== false;
|
|
1907
|
+
const retentionDays = cleanupConfig.retentionDays || 7;
|
|
1908
|
+
const maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100;
|
|
2028
1909
|
if (!isCleanupEnabled) {
|
|
1910
|
+
console.log("[Checkout] 订单数据清理功能已禁用");
|
|
2029
1911
|
return;
|
|
2030
1912
|
}
|
|
2031
|
-
|
|
1913
|
+
console.log(
|
|
1914
|
+
`[Checkout] 开始清理过期订单数据(保留 ${retentionDays} 天内的数据)...`
|
|
1915
|
+
);
|
|
2032
1916
|
const allOrders = await this.payment.getOrderListAsync();
|
|
2033
1917
|
if (!allOrders || allOrders.length === 0) {
|
|
1918
|
+
console.log("[Checkout] 没有找到需要清理的订单数据");
|
|
2034
1919
|
return;
|
|
2035
1920
|
}
|
|
2036
|
-
const thresholdDate = new Date();
|
|
1921
|
+
const thresholdDate = /* @__PURE__ */ new Date();
|
|
2037
1922
|
thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
|
|
2038
1923
|
let deletedCount = 0;
|
|
2039
1924
|
const ordersToDelete = [];
|
|
2040
1925
|
for (const order of allOrders) {
|
|
2041
1926
|
try {
|
|
2042
|
-
|
|
2043
|
-
const isSynced = order.order_id && !(0, _utils.isVirtualOrderId)(order.order_id);
|
|
1927
|
+
const isSynced = order.order_id && !(0, import_utils.isVirtualOrderId)(order.order_id);
|
|
2044
1928
|
if (!isSynced) {
|
|
2045
|
-
continue;
|
|
1929
|
+
continue;
|
|
2046
1930
|
}
|
|
2047
|
-
|
|
2048
|
-
// 检查创建时间
|
|
2049
1931
|
let orderCreatedAt = null;
|
|
2050
|
-
|
|
2051
|
-
// 尝试从 order_info.created_at 获取创建时间
|
|
2052
|
-
if (order.order_info?.created_at) {
|
|
1932
|
+
if ((_a = order.order_info) == null ? void 0 : _a.created_at) {
|
|
2053
1933
|
orderCreatedAt = new Date(order.order_info.created_at);
|
|
1934
|
+
} else if ((_c = (_b = order.order_info) == null ? void 0 : _b.original_order_data) == null ? void 0 : _c.created_at) {
|
|
1935
|
+
orderCreatedAt = new Date(
|
|
1936
|
+
order.order_info.original_order_data.created_at
|
|
1937
|
+
);
|
|
2054
1938
|
}
|
|
2055
|
-
// 如果没有,尝试从 order_info.original_order_data.created_at 获取
|
|
2056
|
-
else if (order.order_info?.original_order_data?.created_at) {
|
|
2057
|
-
orderCreatedAt = new Date(order.order_info.original_order_data.created_at);
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
// 如果无法获取创建时间,跳过此订单
|
|
2061
1939
|
if (!orderCreatedAt || isNaN(orderCreatedAt.getTime())) {
|
|
2062
1940
|
continue;
|
|
2063
1941
|
}
|
|
2064
|
-
|
|
2065
|
-
// 检查是否超过指定天数
|
|
2066
1942
|
if (orderCreatedAt < thresholdDate) {
|
|
2067
1943
|
ordersToDelete.push({
|
|
2068
1944
|
uuid: order.uuid,
|
|
2069
1945
|
orderId: order.order_id,
|
|
2070
1946
|
createdAt: orderCreatedAt.toISOString(),
|
|
2071
|
-
daysSinceCreated: Math.floor(
|
|
1947
|
+
daysSinceCreated: Math.floor(
|
|
1948
|
+
(Date.now() - orderCreatedAt.getTime()) / (1e3 * 60 * 60 * 24)
|
|
1949
|
+
)
|
|
2072
1950
|
});
|
|
2073
1951
|
}
|
|
2074
1952
|
} catch (error) {
|
|
@@ -2076,16 +1954,17 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2076
1954
|
continue;
|
|
2077
1955
|
}
|
|
2078
1956
|
}
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
1957
|
+
ordersToDelete.sort(
|
|
1958
|
+
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
|
|
1959
|
+
);
|
|
2082
1960
|
const actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete);
|
|
2083
|
-
|
|
2084
|
-
// 删除符合条件的订单
|
|
2085
1961
|
for (const orderInfo of actualOrdersToDelete) {
|
|
2086
1962
|
try {
|
|
2087
1963
|
await this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
2088
1964
|
deletedCount++;
|
|
1965
|
+
console.log(
|
|
1966
|
+
`[Checkout] 已删除过期订单: ${orderInfo.orderId} (${orderInfo.daysSinceCreated} 天前创建)`
|
|
1967
|
+
);
|
|
2089
1968
|
} catch (error) {
|
|
2090
1969
|
console.error(`[Checkout] 删除订单 ${orderInfo.uuid} 失败:`, error);
|
|
2091
1970
|
}
|
|
@@ -2093,93 +1972,76 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2093
1972
|
const summary = {
|
|
2094
1973
|
totalOrders: allOrders.length,
|
|
2095
1974
|
expiredSyncedOrders: ordersToDelete.length,
|
|
2096
|
-
maxOrdersToDelete
|
|
1975
|
+
maxOrdersToDelete,
|
|
2097
1976
|
actualDeletedOrders: deletedCount,
|
|
2098
|
-
retentionDays
|
|
2099
|
-
cleanupDate: new Date().toISOString(),
|
|
1977
|
+
retentionDays,
|
|
1978
|
+
cleanupDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2100
1979
|
thresholdDate: thresholdDate.toISOString(),
|
|
2101
1980
|
skippedOrders: Math.max(0, ordersToDelete.length - maxOrdersToDelete)
|
|
2102
1981
|
};
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
1982
|
+
this.logInfo("Expired orders cleanup completed", summary);
|
|
1983
|
+
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
1984
|
+
console.log(
|
|
1985
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,发现 ${ordersToDelete.length} 个过期已同步订单,删除了 ${deletedCount} 个(限制为 ${maxOrdersToDelete} 个)`
|
|
1986
|
+
);
|
|
1987
|
+
} else {
|
|
1988
|
+
console.log(
|
|
1989
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,删除了 ${deletedCount} 个过期已同步订单`
|
|
1990
|
+
);
|
|
1991
|
+
}
|
|
2107
1992
|
} catch (error) {
|
|
2108
1993
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2109
|
-
console.error(
|
|
2110
|
-
this.logError(
|
|
2111
|
-
error: errorMessage
|
|
2112
|
-
});
|
|
1994
|
+
console.error("[Checkout] 清理过期订单数据失败:", error);
|
|
1995
|
+
this.logError("Expired orders cleanup failed", { error: errorMessage });
|
|
2113
1996
|
}
|
|
2114
1997
|
}
|
|
2115
|
-
|
|
2116
1998
|
/**
|
|
2117
1999
|
* 清除计算缓存
|
|
2118
2000
|
*/
|
|
2119
2001
|
clearCalculationCache() {
|
|
2120
2002
|
this.calculationCache = {};
|
|
2121
2003
|
}
|
|
2122
|
-
|
|
2123
2004
|
/**
|
|
2124
2005
|
* 批量获取订单数据(用于性能优化)
|
|
2125
2006
|
* 一次性获取所有需要的数据,避免重复查询
|
|
2126
2007
|
*/
|
|
2127
2008
|
async fetchOrderDataBatch() {
|
|
2128
2009
|
if (!this.store.currentOrder) {
|
|
2129
|
-
return {
|
|
2130
|
-
paymentItems: [],
|
|
2131
|
-
currentOrder: null
|
|
2132
|
-
};
|
|
2010
|
+
return { paymentItems: [], currentOrder: null };
|
|
2133
2011
|
}
|
|
2134
2012
|
const orderUuid = this.store.currentOrder.uuid;
|
|
2135
|
-
|
|
2136
|
-
// 检查缓存是否有效(5秒内的缓存认为有效)
|
|
2137
2013
|
const now = Date.now();
|
|
2138
|
-
const cacheValid = this.calculationCache.orderUuid === orderUuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp <
|
|
2014
|
+
const cacheValid = this.calculationCache.orderUuid === orderUuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5e3;
|
|
2139
2015
|
if (cacheValid && this.calculationCache.paymentItems && this.calculationCache.currentOrder) {
|
|
2140
|
-
// 使用缓存
|
|
2141
2016
|
return {
|
|
2142
2017
|
paymentItems: this.calculationCache.paymentItems,
|
|
2143
2018
|
currentOrder: this.calculationCache.currentOrder
|
|
2144
2019
|
};
|
|
2145
2020
|
}
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
// 更新缓存
|
|
2021
|
+
const [paymentItems, currentOrder] = await Promise.all([
|
|
2022
|
+
this.payment.getPaymentItemsAsync(orderUuid, false),
|
|
2023
|
+
this.payment.getPaymentOrderByUuidAsync(orderUuid)
|
|
2024
|
+
]);
|
|
2151
2025
|
this.calculationCache = {
|
|
2152
2026
|
paymentItems,
|
|
2153
2027
|
currentOrder,
|
|
2154
2028
|
orderUuid,
|
|
2155
2029
|
timestamp: now
|
|
2156
2030
|
};
|
|
2157
|
-
return {
|
|
2158
|
-
paymentItems,
|
|
2159
|
-
currentOrder
|
|
2160
|
-
};
|
|
2031
|
+
return { paymentItems, currentOrder };
|
|
2161
2032
|
}
|
|
2162
|
-
|
|
2163
2033
|
/**
|
|
2164
2034
|
* 从支付项数组计算已支付金额(纯计算,不查询数据库)
|
|
2165
2035
|
*/
|
|
2166
2036
|
calculatePaidAmountFromItems(payments) {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
// const amount = new Decimal(payment.amount || '0');
|
|
2171
|
-
// 计算有效支付金额:支付金额 + 抹零金额的绝对值
|
|
2172
|
-
// 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
|
|
2173
|
-
// 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
|
|
2174
|
-
// 例2:amount=15,rounding_amount=0.2,有效支付 14.8
|
|
2175
|
-
const paymentAmount = new _decimal.default(payment.amount || 0);
|
|
2176
|
-
const roundingAmount = new _decimal.default(payment.rounding_amount || 0);
|
|
2037
|
+
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
2038
|
+
const paymentAmount = new import_decimal.default(payment.amount || 0);
|
|
2039
|
+
const roundingAmount = new import_decimal.default(payment.rounding_amount || 0);
|
|
2177
2040
|
const effectiveAmount = paymentAmount.minus(roundingAmount);
|
|
2178
2041
|
return sum.add(effectiveAmount);
|
|
2179
|
-
}, new
|
|
2042
|
+
}, new import_decimal.default(0));
|
|
2180
2043
|
return paidAmount.toFixed(2);
|
|
2181
2044
|
}
|
|
2182
|
-
|
|
2183
2045
|
/**
|
|
2184
2046
|
* 计算已支付金额(从 Payment 模块获取最新数据)
|
|
2185
2047
|
*
|
|
@@ -2188,63 +2050,50 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2188
2050
|
*/
|
|
2189
2051
|
async calculatePaidAmountAsync() {
|
|
2190
2052
|
if (!this.store.currentOrder) {
|
|
2191
|
-
this.logWarning(
|
|
2192
|
-
return
|
|
2053
|
+
this.logWarning("[Checkout] calculatePaidAmountAsync: 没有当前订单");
|
|
2054
|
+
return "0.00";
|
|
2193
2055
|
}
|
|
2194
2056
|
try {
|
|
2195
|
-
// 检查是否有缓存的已支付金额
|
|
2196
2057
|
const now = Date.now();
|
|
2197
|
-
const cacheValid = this.calculationCache.orderUuid === this.store.currentOrder.uuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp <
|
|
2058
|
+
const cacheValid = this.calculationCache.orderUuid === this.store.currentOrder.uuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5e3 && this.calculationCache.paidAmount;
|
|
2198
2059
|
if (cacheValid && this.calculationCache.paidAmount) {
|
|
2199
2060
|
return this.calculationCache.paidAmount;
|
|
2200
2061
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2062
|
+
const payments = await this.payment.getPaymentItemsAsync(
|
|
2063
|
+
this.store.currentOrder.uuid,
|
|
2064
|
+
false
|
|
2065
|
+
// 不包括已撤销的支付项
|
|
2204
2066
|
);
|
|
2205
2067
|
const result = this.calculatePaidAmountFromItems(payments);
|
|
2206
|
-
|
|
2207
|
-
// 更新缓存
|
|
2208
2068
|
this.calculationCache.paidAmount = result;
|
|
2209
|
-
this.logInfo(
|
|
2069
|
+
this.logInfo("calculatePaidAmountAsync: 计算结果 =", result);
|
|
2210
2070
|
return result;
|
|
2211
2071
|
} catch (error) {
|
|
2212
|
-
this.logError(
|
|
2213
|
-
return
|
|
2072
|
+
this.logError("calculatePaidAmountAsync 失败:", error);
|
|
2073
|
+
return "0.00";
|
|
2214
2074
|
}
|
|
2215
2075
|
}
|
|
2216
|
-
|
|
2217
2076
|
/**
|
|
2218
2077
|
* 从订单和支付项计算剩余金额(纯计算,不查询数据库)
|
|
2219
2078
|
*/
|
|
2220
2079
|
calculateRemainingAmountFromData(currentOrder, paidAmount) {
|
|
2221
|
-
|
|
2222
|
-
let totalAmount = new _decimal.default(currentOrder.total_amount || '0');
|
|
2223
|
-
|
|
2224
|
-
// 如果是定金订单,使用定金金额
|
|
2080
|
+
let totalAmount = new import_decimal.default(currentOrder.total_amount || "0");
|
|
2225
2081
|
if (currentOrder.is_deposit && currentOrder.deposit_amount && Number(currentOrder.deposit_amount) > 0) {
|
|
2226
|
-
totalAmount = new
|
|
2082
|
+
totalAmount = new import_decimal.default(currentOrder.deposit_amount);
|
|
2227
2083
|
}
|
|
2228
|
-
const paid = new
|
|
2084
|
+
const paid = new import_decimal.default(paidAmount);
|
|
2229
2085
|
const remainingAmount = totalAmount.sub(paid);
|
|
2230
|
-
|
|
2231
|
-
// 确保剩余金额不为负数
|
|
2232
|
-
return _decimal.default.max(0, remainingAmount).toFixed(2);
|
|
2086
|
+
return import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
2233
2087
|
}
|
|
2234
|
-
|
|
2235
2088
|
/**
|
|
2236
2089
|
* 从订单和支付项计算剩余总金额(纯计算,排除定金)
|
|
2237
2090
|
*/
|
|
2238
2091
|
calculateRemainingTotalAmountFromData(currentOrder, paidAmount) {
|
|
2239
|
-
|
|
2240
|
-
const
|
|
2241
|
-
const paid = new _decimal.default(paidAmount);
|
|
2092
|
+
const totalAmount = new import_decimal.default(currentOrder.total_amount || "0");
|
|
2093
|
+
const paid = new import_decimal.default(paidAmount);
|
|
2242
2094
|
const remainingAmount = totalAmount.sub(paid);
|
|
2243
|
-
|
|
2244
|
-
// 确保剩余金额不为负数
|
|
2245
|
-
return _decimal.default.max(0, remainingAmount).toFixed(2);
|
|
2095
|
+
return import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
2246
2096
|
}
|
|
2247
|
-
|
|
2248
2097
|
/**
|
|
2249
2098
|
* 计算剩余未支付金额(从 Payment 模块获取最新数据)
|
|
2250
2099
|
*
|
|
@@ -2253,23 +2102,18 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2253
2102
|
*/
|
|
2254
2103
|
async calculateRemainingAmountAsync() {
|
|
2255
2104
|
if (!this.store.currentOrder) {
|
|
2256
|
-
this.logWarning(
|
|
2257
|
-
return
|
|
2105
|
+
this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
|
|
2106
|
+
return "0.00";
|
|
2258
2107
|
}
|
|
2259
|
-
|
|
2260
|
-
// 尝试使用批量获取的数据
|
|
2261
|
-
const {
|
|
2262
|
-
currentOrder
|
|
2263
|
-
} = await this.fetchOrderDataBatch();
|
|
2108
|
+
const { currentOrder } = await this.fetchOrderDataBatch();
|
|
2264
2109
|
if (!currentOrder) {
|
|
2265
|
-
return
|
|
2110
|
+
return "0.00";
|
|
2266
2111
|
}
|
|
2267
2112
|
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
2268
2113
|
const result = this.calculateRemainingAmountFromData(currentOrder, paidAmountStr);
|
|
2269
|
-
this.logInfo(
|
|
2114
|
+
this.logInfo("calculateRemainingAmountAsync: 计算=", result);
|
|
2270
2115
|
return result;
|
|
2271
2116
|
}
|
|
2272
|
-
|
|
2273
2117
|
/**
|
|
2274
2118
|
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
2275
2119
|
*
|
|
@@ -2278,23 +2122,18 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2278
2122
|
*/
|
|
2279
2123
|
async calculateRemainingTotalAmountAsync() {
|
|
2280
2124
|
if (!this.store.currentOrder) {
|
|
2281
|
-
this.logWarning(
|
|
2282
|
-
return
|
|
2125
|
+
this.logWarning("calculateRemainingTotalAmountAsync: 没有当前订单");
|
|
2126
|
+
return "0.00";
|
|
2283
2127
|
}
|
|
2284
|
-
|
|
2285
|
-
// 尝试使用批量获取的数据
|
|
2286
|
-
const {
|
|
2287
|
-
currentOrder
|
|
2288
|
-
} = await this.fetchOrderDataBatch();
|
|
2128
|
+
const { currentOrder } = await this.fetchOrderDataBatch();
|
|
2289
2129
|
if (!currentOrder) {
|
|
2290
|
-
return
|
|
2130
|
+
return "0.00";
|
|
2291
2131
|
}
|
|
2292
2132
|
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
2293
2133
|
const result = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmountStr);
|
|
2294
|
-
this.logInfo(
|
|
2134
|
+
this.logInfo("calculateRemainingTotalAmountAsync: 计算=", result);
|
|
2295
2135
|
return result;
|
|
2296
2136
|
}
|
|
2297
|
-
|
|
2298
2137
|
/**
|
|
2299
2138
|
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
2300
2139
|
*/
|
|
@@ -2303,33 +2142,28 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2303
2142
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2304
2143
|
const remainingTotalAmount = await this.calculateRemainingTotalAmountAsync();
|
|
2305
2144
|
const currentBalanceDueAmount = this.store.balanceDueAmount;
|
|
2306
|
-
|
|
2307
|
-
// 只有当剩余金额与当前 balanceDueAmount 不同时才更新
|
|
2308
2145
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
2309
2146
|
this.store.balanceDueAmount = remainingAmount;
|
|
2310
|
-
|
|
2311
|
-
// 发出 balanceDueAmount 变更事件
|
|
2312
2147
|
await this.core.effects.emit(`${this.name}:onBalanceDueAmountChanged`, {
|
|
2313
2148
|
oldAmount: currentBalanceDueAmount,
|
|
2314
2149
|
newAmount: remainingAmount,
|
|
2315
2150
|
timestamp: Date.now(),
|
|
2316
2151
|
totalAmount: remainingTotalAmount
|
|
2317
2152
|
});
|
|
2318
|
-
this.logInfo(
|
|
2153
|
+
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
2319
2154
|
oldAmount: currentBalanceDueAmount,
|
|
2320
2155
|
newAmount: remainingAmount
|
|
2321
2156
|
});
|
|
2322
2157
|
} else {
|
|
2323
|
-
this.logInfo(
|
|
2158
|
+
this.logInfo("balanceDueAmount 无需更新,当前值已是最新:", {
|
|
2324
2159
|
balanceDueAmount: currentBalanceDueAmount,
|
|
2325
|
-
remainingAmount
|
|
2160
|
+
remainingAmount
|
|
2326
2161
|
});
|
|
2327
2162
|
}
|
|
2328
2163
|
} catch (error) {
|
|
2329
|
-
this.logError(
|
|
2164
|
+
this.logError("更新 balanceDueAmount 失败:", error);
|
|
2330
2165
|
}
|
|
2331
2166
|
}
|
|
2332
|
-
|
|
2333
2167
|
/**
|
|
2334
2168
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
2335
2169
|
*
|
|
@@ -2340,51 +2174,37 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2340
2174
|
if (!this.store.currentOrder) {
|
|
2341
2175
|
return;
|
|
2342
2176
|
}
|
|
2343
|
-
|
|
2344
|
-
const {
|
|
2345
|
-
|
|
2346
|
-
currentOrder
|
|
2347
|
-
} = await this.fetchOrderDataBatch();
|
|
2177
|
+
console.time("updateStateAmountToRemaining");
|
|
2178
|
+
const { paymentItems, currentOrder } = await this.fetchOrderDataBatch();
|
|
2179
|
+
console.timeEnd("updateStateAmountToRemaining");
|
|
2348
2180
|
if (!currentOrder) {
|
|
2349
|
-
this.logWarning(
|
|
2181
|
+
this.logWarning("updateStateAmountToRemaining: 未找到当前订单");
|
|
2350
2182
|
return;
|
|
2351
2183
|
}
|
|
2352
|
-
// 🚀 性能优化:一次性计算所有金额(纯计算,不查询数据库)
|
|
2353
2184
|
const paidAmount = this.calculatePaidAmountFromItems(paymentItems);
|
|
2354
|
-
|
|
2355
|
-
// 缓存已支付金额,供其他方法使用
|
|
2356
2185
|
this.calculationCache.paidAmount = paidAmount;
|
|
2357
|
-
|
|
2358
|
-
// 检查定金支付状态,可能需要切换支付模式
|
|
2359
2186
|
let needUpdateDepositStatus = false;
|
|
2360
2187
|
if (currentOrder.is_deposit === 1) {
|
|
2361
|
-
const depositPaidAmount = paymentItems.filter(
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
if (item.voucher_id && !item.isSynced && paymentItems.filter(
|
|
2188
|
+
const depositPaidAmount = paymentItems.filter(
|
|
2189
|
+
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
2190
|
+
).reduce((sum, item) => {
|
|
2191
|
+
if (item.voucher_id && !item.isSynced && paymentItems.filter((item2) => !item2.voucher_id).length === 0) {
|
|
2365
2192
|
return sum;
|
|
2366
2193
|
}
|
|
2367
|
-
const amount = new
|
|
2368
|
-
const roundingAmount = new
|
|
2194
|
+
const amount = new import_decimal.default(item.amount || "0");
|
|
2195
|
+
const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
|
|
2369
2196
|
return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
|
|
2370
|
-
}, new
|
|
2371
|
-
if (depositPaidAmount.gte(currentOrder.deposit_amount ||
|
|
2197
|
+
}, new import_decimal.default(0));
|
|
2198
|
+
if (depositPaidAmount.gte(currentOrder.deposit_amount || "0")) {
|
|
2372
2199
|
needUpdateDepositStatus = true;
|
|
2373
|
-
// 更新缓存中的订单状态
|
|
2374
2200
|
currentOrder.is_deposit = 0;
|
|
2375
2201
|
}
|
|
2376
2202
|
}
|
|
2377
|
-
|
|
2378
|
-
// 计算剩余金额(使用缓存的数据)
|
|
2379
2203
|
const remainingAmount = this.calculateRemainingAmountFromData(currentOrder, paidAmount);
|
|
2380
2204
|
const remainingTotalAmount = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmount);
|
|
2381
2205
|
const currentStateAmount = this.store.stateAmount;
|
|
2382
2206
|
const currentBalanceDueAmount = this.store.balanceDueAmount;
|
|
2383
|
-
|
|
2384
|
-
// 批量更新状态,减少操作次数
|
|
2385
2207
|
let hasStateChanged = false;
|
|
2386
|
-
|
|
2387
|
-
// 如果需要更新定金状态
|
|
2388
2208
|
if (needUpdateDepositStatus) {
|
|
2389
2209
|
this.store.currentOrder = {
|
|
2390
2210
|
...this.store.currentOrder,
|
|
@@ -2395,12 +2215,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2395
2215
|
});
|
|
2396
2216
|
hasStateChanged = true;
|
|
2397
2217
|
}
|
|
2398
|
-
|
|
2218
|
+
console.time("updateStateAmountToRemaining: remainingAmount");
|
|
2399
2219
|
if (remainingAmount !== currentStateAmount) {
|
|
2400
2220
|
this.store.stateAmount = remainingAmount;
|
|
2401
2221
|
hasStateChanged = true;
|
|
2402
2222
|
setTimeout(() => {
|
|
2403
|
-
// 发出 stateAmount 变更事件
|
|
2404
2223
|
this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
|
|
2405
2224
|
oldAmount: currentStateAmount,
|
|
2406
2225
|
newAmount: remainingAmount,
|
|
@@ -2408,17 +2227,16 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2408
2227
|
totalAmount: remainingTotalAmount
|
|
2409
2228
|
});
|
|
2410
2229
|
}, 0);
|
|
2411
|
-
this.logInfo(
|
|
2230
|
+
this.logInfo("stateAmount 已自动更新为剩余金额:", {
|
|
2412
2231
|
oldAmount: currentStateAmount,
|
|
2413
2232
|
newAmount: remainingAmount
|
|
2414
2233
|
});
|
|
2415
2234
|
}
|
|
2416
|
-
|
|
2235
|
+
console.timeEnd("updateStateAmountToRemaining: remainingAmount");
|
|
2236
|
+
console.time("updateStateAmountToRemaining: updateStateAmountToRemaining");
|
|
2417
2237
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
2418
2238
|
this.store.balanceDueAmount = remainingAmount;
|
|
2419
2239
|
hasStateChanged = true;
|
|
2420
|
-
|
|
2421
|
-
// 发出 balanceDueAmount 变更事件
|
|
2422
2240
|
setTimeout(() => {
|
|
2423
2241
|
this.core.effects.emit(`${this.name}:onBalanceDueAmountChanged`, {
|
|
2424
2242
|
oldAmount: currentBalanceDueAmount,
|
|
@@ -2427,29 +2245,27 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2427
2245
|
totalAmount: remainingTotalAmount
|
|
2428
2246
|
});
|
|
2429
2247
|
}, 0);
|
|
2430
|
-
this.logInfo(
|
|
2248
|
+
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
2431
2249
|
oldAmount: currentBalanceDueAmount,
|
|
2432
2250
|
newAmount: remainingAmount
|
|
2433
2251
|
});
|
|
2434
2252
|
}
|
|
2253
|
+
console.timeEnd("updateStateAmountToRemaining: updateStateAmountToRemaining");
|
|
2435
2254
|
if (!hasStateChanged) {
|
|
2436
|
-
this.logInfo(
|
|
2255
|
+
this.logInfo("状态无需更新,当前值已是最新:", {
|
|
2437
2256
|
stateAmount: currentStateAmount,
|
|
2438
|
-
remainingAmount
|
|
2257
|
+
remainingAmount
|
|
2439
2258
|
});
|
|
2440
2259
|
}
|
|
2441
|
-
|
|
2442
|
-
// 检查订单支付完成(复用已获取的数据)
|
|
2443
2260
|
if (checkOrder) {
|
|
2444
2261
|
await this.checkOrderPaymentCompletionOptimized(paymentItems, remainingAmount);
|
|
2445
2262
|
} else {
|
|
2446
|
-
this.logInfo(
|
|
2263
|
+
this.logInfo("外部传入无需 checkOrder,不执行订单支付完成检测和同步");
|
|
2447
2264
|
}
|
|
2448
2265
|
} catch (error) {
|
|
2449
|
-
this.logError(
|
|
2266
|
+
this.logError("更新 stateAmount 为剩余金额失败:", error);
|
|
2450
2267
|
}
|
|
2451
2268
|
}
|
|
2452
|
-
|
|
2453
2269
|
/**
|
|
2454
2270
|
* 检查订单支付是否完成(优化版,复用已获取的数据)
|
|
2455
2271
|
*
|
|
@@ -2461,13 +2277,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2461
2277
|
if (!this.store.currentOrder) {
|
|
2462
2278
|
return;
|
|
2463
2279
|
}
|
|
2464
|
-
const remainingValue = new
|
|
2465
|
-
|
|
2466
|
-
// 当剩余金额小于等于0时,认为订单已完成支付
|
|
2280
|
+
const remainingValue = new import_decimal.default(remainingAmount);
|
|
2467
2281
|
if (remainingValue.lte(0)) {
|
|
2468
2282
|
const totalAmount = this.store.currentOrder.total_amount;
|
|
2469
|
-
const paidAmount = this.calculationCache.paidAmount ||
|
|
2470
|
-
this.logInfo(
|
|
2283
|
+
const paidAmount = this.calculationCache.paidAmount || "0.00";
|
|
2284
|
+
this.logInfo("检测到订单支付完成:", {
|
|
2471
2285
|
orderUuid: this.store.currentOrder.uuid,
|
|
2472
2286
|
orderId: this.store.currentOrder.order_id,
|
|
2473
2287
|
totalAmount,
|
|
@@ -2475,40 +2289,38 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2475
2289
|
remainingAmount,
|
|
2476
2290
|
isOrderSynced: this.store.isOrderSynced
|
|
2477
2291
|
});
|
|
2478
|
-
|
|
2479
|
-
// 检查自动同步条件(复用已获取的支付项数据)
|
|
2480
2292
|
const hasPaymentItems = paymentItems.length > 0;
|
|
2481
|
-
const allPaymentsHaveVoucherId = hasPaymentItems && paymentItems.every(
|
|
2293
|
+
const allPaymentsHaveVoucherId = hasPaymentItems && paymentItems.every(
|
|
2294
|
+
(item) => item.status !== "voided" && item.voucher_id
|
|
2295
|
+
);
|
|
2482
2296
|
const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
2483
|
-
this.logInfo(
|
|
2297
|
+
this.logInfo("自动同步订单条件检查:", {
|
|
2484
2298
|
paymentCount: paymentItems.length,
|
|
2485
2299
|
hasPaymentItems,
|
|
2486
2300
|
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
2487
2301
|
isOrderSynced: this.store.isOrderSynced,
|
|
2488
2302
|
shouldAutoSync,
|
|
2489
|
-
reason: shouldAutoSync ?
|
|
2490
|
-
paymentItems: paymentItems.map(p => ({
|
|
2303
|
+
reason: shouldAutoSync ? "支付完成,需要同步最终支付状态" : "跳过同步",
|
|
2304
|
+
paymentItems: paymentItems.map((p) => ({
|
|
2491
2305
|
uuid: p.uuid,
|
|
2492
2306
|
code: p.code,
|
|
2493
2307
|
amount: p.amount,
|
|
2494
2308
|
rounding_amount: p.rounding_amount,
|
|
2495
|
-
effective_amount: (parseFloat(p.amount ||
|
|
2309
|
+
effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? "0" : p.rounding_amount || "0"))).toFixed(2),
|
|
2496
2310
|
voucher_id: p.voucher_id,
|
|
2497
2311
|
status: p.status
|
|
2498
2312
|
}))
|
|
2499
2313
|
});
|
|
2500
2314
|
if (shouldAutoSync) {
|
|
2501
|
-
this.logInfo(
|
|
2315
|
+
this.logInfo("满足自动同步条件,开始同步订单到后端...");
|
|
2502
2316
|
await this.syncOrderToBackendWithReturn(false);
|
|
2503
2317
|
} else {
|
|
2504
2318
|
if (!hasPaymentItems) {
|
|
2505
|
-
this.logInfo(
|
|
2319
|
+
this.logInfo("没有支付项,跳过订单同步");
|
|
2506
2320
|
} else if (allPaymentsHaveVoucherId) {
|
|
2507
|
-
this.logInfo(
|
|
2321
|
+
this.logInfo("所有支付项均为代金券类型,跳过订单同步");
|
|
2508
2322
|
}
|
|
2509
2323
|
}
|
|
2510
|
-
|
|
2511
|
-
// 触发订单支付完成事件
|
|
2512
2324
|
await this.core.effects.emit(`${this.name}:onOrderPaymentCompleted`, {
|
|
2513
2325
|
orderUuid: this.store.currentOrder.uuid,
|
|
2514
2326
|
orderId: this.store.currentOrder.order_id,
|
|
@@ -2519,10 +2331,9 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2519
2331
|
});
|
|
2520
2332
|
}
|
|
2521
2333
|
} catch (error) {
|
|
2522
|
-
this.logError(
|
|
2334
|
+
this.logError("检查订单支付完成状态失败:", error);
|
|
2523
2335
|
}
|
|
2524
2336
|
}
|
|
2525
|
-
|
|
2526
2337
|
/**
|
|
2527
2338
|
* 检查订单支付是否完成
|
|
2528
2339
|
*
|
|
@@ -2537,13 +2348,11 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2537
2348
|
return;
|
|
2538
2349
|
}
|
|
2539
2350
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
2540
|
-
const remainingValue = new
|
|
2541
|
-
|
|
2542
|
-
// 当剩余金额小于等于0时,认为订单已完成支付
|
|
2351
|
+
const remainingValue = new import_decimal.default(remainingAmount);
|
|
2543
2352
|
if (remainingValue.lte(0)) {
|
|
2544
2353
|
const totalAmount = this.store.currentOrder.total_amount;
|
|
2545
2354
|
const paidAmount = await this.calculatePaidAmountAsync();
|
|
2546
|
-
this.logInfo(
|
|
2355
|
+
this.logInfo("检测到订单支付完成:", {
|
|
2547
2356
|
orderUuid: this.store.currentOrder.uuid,
|
|
2548
2357
|
orderId: this.store.currentOrder.order_id,
|
|
2549
2358
|
totalAmount,
|
|
@@ -2551,53 +2360,43 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2551
2360
|
remainingAmount,
|
|
2552
2361
|
isOrderSynced: this.store.isOrderSynced
|
|
2553
2362
|
});
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2363
|
+
const currentPayments = await this.payment.getPaymentItemsAsync(
|
|
2364
|
+
this.store.currentOrder.uuid,
|
|
2365
|
+
false
|
|
2366
|
+
// 不包括已撤销的支付项
|
|
2557
2367
|
);
|
|
2558
|
-
|
|
2559
|
-
// 检查自动同步条件:
|
|
2560
|
-
// 1. 待付金额为 0 ✓ (已在上面检查)
|
|
2561
|
-
// 2. 需要有支付项
|
|
2562
|
-
// 3. 支付项不能全是带 voucher_id 的数据
|
|
2563
2368
|
const hasPaymentItems = currentPayments.length > 0;
|
|
2564
|
-
const allPaymentsHaveVoucherId = hasPaymentItems && currentPayments.every(
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
// 条件:
|
|
2568
|
-
// 1. 有支付项
|
|
2569
|
-
// 2. 不全是代金券支付
|
|
2570
|
-
// 3. 订单未同步 OR (订单已同步但支付刚完成,需要同步最终支付状态)
|
|
2369
|
+
const allPaymentsHaveVoucherId = hasPaymentItems && currentPayments.every(
|
|
2370
|
+
(item) => item.status !== "voided" && item.voucher_id
|
|
2371
|
+
);
|
|
2571
2372
|
const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
2572
|
-
this.logInfo(
|
|
2373
|
+
this.logInfo("自动同步订单条件检查:", {
|
|
2573
2374
|
paymentCount: currentPayments.length,
|
|
2574
2375
|
hasPaymentItems,
|
|
2575
2376
|
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
2576
2377
|
isOrderSynced: this.store.isOrderSynced,
|
|
2577
2378
|
shouldAutoSync,
|
|
2578
|
-
reason: shouldAutoSync ?
|
|
2579
|
-
paymentItems: currentPayments.map(p => ({
|
|
2379
|
+
reason: shouldAutoSync ? "支付完成,需要同步最终支付状态" : "跳过同步",
|
|
2380
|
+
paymentItems: currentPayments.map((p) => ({
|
|
2580
2381
|
uuid: p.uuid,
|
|
2581
2382
|
code: p.code,
|
|
2582
2383
|
amount: p.amount,
|
|
2583
2384
|
rounding_amount: p.rounding_amount,
|
|
2584
|
-
effective_amount: (parseFloat(p.amount ||
|
|
2385
|
+
effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? "0" : p.rounding_amount || "0"))).toFixed(2),
|
|
2585
2386
|
voucher_id: p.voucher_id,
|
|
2586
2387
|
status: p.status
|
|
2587
2388
|
}))
|
|
2588
2389
|
});
|
|
2589
2390
|
if (shouldAutoSync) {
|
|
2590
|
-
this.logInfo(
|
|
2391
|
+
this.logInfo("满足自动同步条件,开始同步订单到后端...");
|
|
2591
2392
|
await this.syncOrderToBackendWithReturn(false);
|
|
2592
2393
|
} else {
|
|
2593
2394
|
if (!hasPaymentItems) {
|
|
2594
|
-
this.logInfo(
|
|
2395
|
+
this.logInfo("没有支付项,跳过订单同步");
|
|
2595
2396
|
} else if (allPaymentsHaveVoucherId) {
|
|
2596
|
-
this.logInfo(
|
|
2397
|
+
this.logInfo("所有支付项均为代金券类型,跳过订单同步");
|
|
2597
2398
|
}
|
|
2598
2399
|
}
|
|
2599
|
-
|
|
2600
|
-
// 触发订单支付完成事件
|
|
2601
2400
|
await this.core.effects.emit(`${this.name}:onOrderPaymentCompleted`, {
|
|
2602
2401
|
orderUuid: this.store.currentOrder.uuid,
|
|
2603
2402
|
orderId: this.store.currentOrder.order_id,
|
|
@@ -2608,23 +2407,20 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2608
2407
|
});
|
|
2609
2408
|
}
|
|
2610
2409
|
} catch (error) {
|
|
2611
|
-
this.logError(
|
|
2410
|
+
this.logError("检查订单支付完成状态失败:", error);
|
|
2612
2411
|
}
|
|
2613
2412
|
}
|
|
2614
2413
|
async repairEftposPaymentFromIndexDbAsync(params) {
|
|
2615
|
-
const {
|
|
2616
|
-
orderUuid,
|
|
2617
|
-
paymentItem
|
|
2618
|
-
} = params;
|
|
2414
|
+
const { orderUuid, paymentItem } = params;
|
|
2619
2415
|
const order = await this.payment.getPaymentOrderByUuidAsync(orderUuid);
|
|
2620
2416
|
if (!order) {
|
|
2621
|
-
this.logError(
|
|
2417
|
+
this.logError("EFTPOS repair failed: order not found in IndexDB", {
|
|
2622
2418
|
orderUuid,
|
|
2623
2419
|
paymentItem
|
|
2624
2420
|
});
|
|
2625
2421
|
return;
|
|
2626
2422
|
}
|
|
2627
|
-
const orderPaymentType = order.is_deposit === 1 ?
|
|
2423
|
+
const orderPaymentType = order.is_deposit === 1 ? "deposit" : "normal";
|
|
2628
2424
|
const processedPaymentItem = await this.processCashPaymentItem(paymentItem);
|
|
2629
2425
|
const metadata = {
|
|
2630
2426
|
...processedPaymentItem.metadata,
|
|
@@ -2637,79 +2433,81 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2637
2433
|
metadata
|
|
2638
2434
|
};
|
|
2639
2435
|
await this.payment.addPaymentItemAsync(orderUuid, paymentItemWithType);
|
|
2640
|
-
await this.syncOrderToBackendFromIndexDbAsync({
|
|
2641
|
-
orderUuid
|
|
2642
|
-
});
|
|
2436
|
+
await this.syncOrderToBackendFromIndexDbAsync({ orderUuid });
|
|
2643
2437
|
}
|
|
2644
2438
|
async syncOrderToBackendFromIndexDbAsync(params) {
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
} = params;
|
|
2439
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2440
|
+
const { orderUuid } = params;
|
|
2648
2441
|
const paymentOrder = await this.payment.getPaymentOrderByUuidAsync(orderUuid);
|
|
2649
2442
|
if (!paymentOrder) {
|
|
2650
|
-
this.logError(
|
|
2443
|
+
this.logError("EFTPOS repair sync failed: missing payment order", {
|
|
2651
2444
|
orderUuid
|
|
2652
2445
|
});
|
|
2653
|
-
return {
|
|
2654
|
-
success: false
|
|
2655
|
-
};
|
|
2446
|
+
return { success: false };
|
|
2656
2447
|
}
|
|
2657
|
-
const localOrderData = paymentOrder.order_info
|
|
2448
|
+
const localOrderData = ((_a = paymentOrder.order_info) == null ? void 0 : _a.original_order_data) || ((_b = paymentOrder.order_info) == null ? void 0 : _b.order_data);
|
|
2658
2449
|
if (!localOrderData) {
|
|
2659
|
-
this.logError(
|
|
2450
|
+
this.logError("EFTPOS repair sync failed: missing local order data", {
|
|
2660
2451
|
orderUuid,
|
|
2661
2452
|
orderInfoKeys: Object.keys(paymentOrder.order_info || {})
|
|
2662
2453
|
});
|
|
2663
|
-
return {
|
|
2664
|
-
success: false
|
|
2665
|
-
};
|
|
2454
|
+
return { success: false };
|
|
2666
2455
|
}
|
|
2667
2456
|
const paymentItems = await this.payment.getPaymentItemsAsync(orderUuid);
|
|
2668
|
-
const processedPaymentItems = paymentItems.map(item =>
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
...item
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2457
|
+
const processedPaymentItems = paymentItems.map((item) => {
|
|
2458
|
+
var _a2, _b2;
|
|
2459
|
+
return {
|
|
2460
|
+
...item,
|
|
2461
|
+
metadata: {
|
|
2462
|
+
...item.metadata,
|
|
2463
|
+
rounding_rule: ((_a2 = item.metadata) == null ? void 0 : _a2.rounding_rule) || this.otherParams.order_rounding_setting,
|
|
2464
|
+
shop_wallet_pass_id: ((_b2 = item.metadata) == null ? void 0 : _b2.shop_wallet_pass_id) || this.otherParams.shop_wallet_pass_id
|
|
2465
|
+
}
|
|
2466
|
+
};
|
|
2467
|
+
});
|
|
2676
2468
|
let finalDepositAmount;
|
|
2677
|
-
const manualDepositAmount = paymentOrder.deposit_amount ||
|
|
2678
|
-
const manualDepositValue = new
|
|
2469
|
+
const manualDepositAmount = paymentOrder.deposit_amount || "0.00";
|
|
2470
|
+
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
2679
2471
|
if (manualDepositValue.gt(0)) {
|
|
2680
2472
|
finalDepositAmount = manualDepositAmount;
|
|
2681
2473
|
} else {
|
|
2682
|
-
finalDepositAmount =
|
|
2474
|
+
finalDepositAmount = "0.00";
|
|
2683
2475
|
}
|
|
2684
|
-
if (paymentOrder.is_deposit === 0 && processedPaymentItems.every(item => item.order_payment_type !==
|
|
2685
|
-
finalDepositAmount =
|
|
2476
|
+
if (paymentOrder.is_deposit === 0 && processedPaymentItems.every((item) => item.order_payment_type !== "deposit")) {
|
|
2477
|
+
finalDepositAmount = "0.00";
|
|
2686
2478
|
}
|
|
2687
|
-
if (paymentOrder.is_deposit === 0 && processedPaymentItems.some(item => item.order_payment_type ===
|
|
2688
|
-
finalDepositAmount = processedPaymentItems.filter(
|
|
2689
|
-
|
|
2690
|
-
|
|
2479
|
+
if (paymentOrder.is_deposit === 0 && processedPaymentItems.some((item) => item.order_payment_type === "deposit")) {
|
|
2480
|
+
finalDepositAmount = processedPaymentItems.filter(
|
|
2481
|
+
(item) => item.status !== "voided" && item.order_payment_type === "deposit"
|
|
2482
|
+
).reduce((sum, item) => {
|
|
2483
|
+
const amountValue = new import_decimal.default(item.amount || "0");
|
|
2484
|
+
const roundingValue = new import_decimal.default(item.rounding_amount || "0");
|
|
2691
2485
|
return sum.plus(amountValue).sub(roundingValue);
|
|
2692
|
-
}, new
|
|
2693
|
-
}
|
|
2694
|
-
if (paymentOrder.is_deposit === 1 && new
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2486
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2487
|
+
}
|
|
2488
|
+
if (paymentOrder.is_deposit === 1 && new import_decimal.default(finalDepositAmount).gte(
|
|
2489
|
+
new import_decimal.default(paymentOrder.total_amount)
|
|
2490
|
+
)) {
|
|
2491
|
+
finalDepositAmount = processedPaymentItems.filter(
|
|
2492
|
+
(item) => item.status !== "voided" && item.order_payment_type === "deposit"
|
|
2493
|
+
).reduce((sum, item) => {
|
|
2494
|
+
const amountValue = new import_decimal.default(item.amount || "0");
|
|
2495
|
+
const roundingValue = new import_decimal.default(item.rounding_amount || "0");
|
|
2698
2496
|
return sum.plus(amountValue).sub(roundingValue);
|
|
2699
|
-
}, new
|
|
2497
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2700
2498
|
}
|
|
2701
2499
|
let orderPaymentStatus;
|
|
2702
|
-
const totalPaidAmount = processedPaymentItems.filter(item => item.status !==
|
|
2703
|
-
const amountValue = new
|
|
2704
|
-
const roundingValue = new
|
|
2500
|
+
const totalPaidAmount = processedPaymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => {
|
|
2501
|
+
const amountValue = new import_decimal.default(item.amount || "0");
|
|
2502
|
+
const roundingValue = new import_decimal.default(item.rounding_amount || "0");
|
|
2705
2503
|
return sum.plus(amountValue).sub(roundingValue);
|
|
2706
|
-
}, new
|
|
2707
|
-
if (totalPaidAmount.gte(new
|
|
2708
|
-
orderPaymentStatus =
|
|
2504
|
+
}, new import_decimal.default(0));
|
|
2505
|
+
if (totalPaidAmount.gte(new import_decimal.default(paymentOrder.total_amount))) {
|
|
2506
|
+
orderPaymentStatus = "paid";
|
|
2709
2507
|
} else if (totalPaidAmount.gt(0)) {
|
|
2710
|
-
orderPaymentStatus =
|
|
2508
|
+
orderPaymentStatus = "partially_paid";
|
|
2711
2509
|
} else {
|
|
2712
|
-
orderPaymentStatus =
|
|
2510
|
+
orderPaymentStatus = "unpaid";
|
|
2713
2511
|
}
|
|
2714
2512
|
const orderParams = {
|
|
2715
2513
|
...localOrderData,
|
|
@@ -2725,46 +2523,44 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2725
2523
|
currency_code: this.otherParams.currency_code,
|
|
2726
2524
|
currency_symbol: this.otherParams.currency_symbol,
|
|
2727
2525
|
currency_format: this.otherParams.currency_format,
|
|
2728
|
-
business_code: this.otherParams
|
|
2526
|
+
business_code: ((_c = this.otherParams) == null ? void 0 : _c.business_code) || void 0,
|
|
2729
2527
|
is_deposit: (paymentOrder.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
2730
2528
|
deposit_amount: finalDepositAmount,
|
|
2731
2529
|
product_tax_fee: localOrderData.tax_fee,
|
|
2732
2530
|
note: localOrderData.shop_note,
|
|
2733
|
-
bookings: localOrderData.bookings
|
|
2531
|
+
bookings: (_d = localOrderData.bookings) == null ? void 0 : _d.map((item) => {
|
|
2734
2532
|
return {
|
|
2735
2533
|
...item,
|
|
2736
2534
|
product: {
|
|
2737
2535
|
...item.product,
|
|
2738
|
-
custom_deposit_data:
|
|
2536
|
+
custom_deposit_data: void 0
|
|
2739
2537
|
},
|
|
2740
|
-
deposit:
|
|
2538
|
+
deposit: void 0
|
|
2741
2539
|
};
|
|
2742
2540
|
}),
|
|
2743
|
-
relation_products: localOrderData.relation_products
|
|
2541
|
+
relation_products: (_e = localOrderData.relation_products) == null ? void 0 : _e.map((item) => {
|
|
2744
2542
|
return {
|
|
2745
2543
|
...item,
|
|
2746
|
-
custom_deposit_data:
|
|
2747
|
-
deposit:
|
|
2544
|
+
custom_deposit_data: void 0,
|
|
2545
|
+
deposit: void 0
|
|
2748
2546
|
};
|
|
2749
2547
|
})
|
|
2750
2548
|
};
|
|
2751
2549
|
const currentOrderId = paymentOrder.order_id;
|
|
2752
|
-
const isUpdateOperation = currentOrderId && !(0,
|
|
2550
|
+
const isUpdateOperation = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
2753
2551
|
if (isUpdateOperation) {
|
|
2754
2552
|
orderParams.order_id = currentOrderId;
|
|
2755
2553
|
}
|
|
2756
|
-
this.logError(
|
|
2554
|
+
this.logError("EFTPOS repair sync start", {
|
|
2757
2555
|
orderUuid,
|
|
2758
2556
|
orderId: currentOrderId,
|
|
2759
2557
|
isUpdateOperation,
|
|
2760
2558
|
paymentItemCount: processedPaymentItems.length
|
|
2761
2559
|
});
|
|
2762
|
-
|
|
2763
|
-
// 发送下单接口请求开始事件
|
|
2764
2560
|
const startTime = Date.now();
|
|
2765
2561
|
await this.core.effects.emit(`${this.name}:onOrderSubmitStart`, {
|
|
2766
|
-
orderUuid
|
|
2767
|
-
operation: isUpdateOperation ?
|
|
2562
|
+
orderUuid,
|
|
2563
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
2768
2564
|
isManual: false,
|
|
2769
2565
|
paymentItemCount: processedPaymentItems.length,
|
|
2770
2566
|
timestamp: startTime
|
|
@@ -2773,85 +2569,80 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2773
2569
|
let submitSuccess = false;
|
|
2774
2570
|
let submitError;
|
|
2775
2571
|
try {
|
|
2776
|
-
this.logError(
|
|
2777
|
-
url:
|
|
2572
|
+
this.logError("EFTPOS repair calling backend checkout API", {
|
|
2573
|
+
url: "/order/checkout",
|
|
2778
2574
|
isManual: true,
|
|
2779
2575
|
...orderParams
|
|
2780
2576
|
});
|
|
2781
2577
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2782
2578
|
submitSuccess = true;
|
|
2783
2579
|
} catch (error) {
|
|
2784
|
-
this.logError(
|
|
2580
|
+
this.logError("EFTPOS repair checkout API failed", {
|
|
2785
2581
|
orderUuid,
|
|
2786
2582
|
error: error instanceof Error ? error.message : String(error)
|
|
2787
2583
|
});
|
|
2788
2584
|
submitError = error instanceof Error ? error.message : String(error);
|
|
2789
2585
|
throw error;
|
|
2790
2586
|
} finally {
|
|
2791
|
-
this.logError(
|
|
2587
|
+
this.logError("EFTPOS repair sync end", {
|
|
2792
2588
|
orderUuid,
|
|
2793
2589
|
orderId: currentOrderId,
|
|
2794
|
-
responseStatus: checkoutResponse
|
|
2590
|
+
responseStatus: checkoutResponse == null ? void 0 : checkoutResponse.status
|
|
2795
2591
|
});
|
|
2796
2592
|
this.core.effects.emit(`${this.name}:onOrderSubmitEnd`, {
|
|
2797
2593
|
success: submitSuccess,
|
|
2798
|
-
orderUuid
|
|
2799
|
-
operation: isUpdateOperation ?
|
|
2594
|
+
orderUuid,
|
|
2595
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
2800
2596
|
isManual: false,
|
|
2801
|
-
orderId: submitSuccess ? checkoutResponse
|
|
2597
|
+
orderId: submitSuccess ? ((_f = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _f.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2802
2598
|
error: submitError,
|
|
2803
2599
|
duration: Date.now() - startTime,
|
|
2804
2600
|
timestamp: Date.now()
|
|
2805
2601
|
});
|
|
2806
2602
|
}
|
|
2807
|
-
const responseStatus = checkoutResponse
|
|
2808
|
-
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus ===
|
|
2603
|
+
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2604
|
+
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
2809
2605
|
if (!isSuccessResponse) {
|
|
2810
|
-
const errorMessage = checkoutResponse
|
|
2811
|
-
this.logError(
|
|
2606
|
+
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
|
|
2607
|
+
this.logError("EFTPOS repair sync failed: api error", {
|
|
2812
2608
|
orderUuid,
|
|
2813
2609
|
errorMessage,
|
|
2814
2610
|
response: checkoutResponse
|
|
2815
2611
|
});
|
|
2816
|
-
return {
|
|
2817
|
-
success: false,
|
|
2818
|
-
response: checkoutResponse
|
|
2819
|
-
};
|
|
2612
|
+
return { success: false, response: checkoutResponse };
|
|
2820
2613
|
}
|
|
2821
2614
|
let realOrderId = currentOrderId;
|
|
2822
2615
|
if (!isUpdateOperation) {
|
|
2823
|
-
let extractedOrderId = checkoutResponse
|
|
2616
|
+
let extractedOrderId = (_g = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _g.order_id;
|
|
2824
2617
|
if (!extractedOrderId) {
|
|
2825
|
-
extractedOrderId = checkoutResponse
|
|
2618
|
+
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2826
2619
|
}
|
|
2827
|
-
if (extractedOrderId !==
|
|
2620
|
+
if (extractedOrderId !== void 0 && extractedOrderId !== null) {
|
|
2828
2621
|
extractedOrderId = String(extractedOrderId);
|
|
2829
2622
|
}
|
|
2830
2623
|
realOrderId = extractedOrderId;
|
|
2831
2624
|
if (realOrderId) {
|
|
2832
2625
|
await this.payment.replaceOrderIdByUuidAsync(orderUuid, realOrderId);
|
|
2833
2626
|
} else {
|
|
2834
|
-
this.logError(
|
|
2627
|
+
this.logError("EFTPOS repair missing order_id in response", {
|
|
2835
2628
|
orderUuid,
|
|
2836
2629
|
response: checkoutResponse
|
|
2837
2630
|
});
|
|
2838
2631
|
}
|
|
2839
2632
|
}
|
|
2840
|
-
const syncedPaymentUuids = processedPaymentItems.filter(item => item.status !==
|
|
2633
|
+
const syncedPaymentUuids = processedPaymentItems.filter((item) => item.status !== "voided").map((item) => item.uuid).filter(Boolean);
|
|
2841
2634
|
for (const paymentUuid of syncedPaymentUuids) {
|
|
2842
2635
|
await this.payment.updatePaymentAsync(orderUuid, paymentUuid, {
|
|
2843
2636
|
isSynced: true,
|
|
2844
|
-
syncError:
|
|
2637
|
+
syncError: void 0
|
|
2845
2638
|
});
|
|
2846
2639
|
}
|
|
2847
|
-
const latestPaymentStatus = checkoutResponse
|
|
2640
|
+
const latestPaymentStatus = ((_h = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _h.payment_status) || orderPaymentStatus;
|
|
2848
2641
|
await this.payment.updateOrderAsync(orderUuid, {
|
|
2849
2642
|
payment_status: latestPaymentStatus
|
|
2850
2643
|
});
|
|
2851
|
-
|
|
2852
|
-
// 触发订单同步完成事件
|
|
2853
2644
|
await this.core.effects.emit(`${this.name}:onOrderSynced`, {
|
|
2854
|
-
orderUuid
|
|
2645
|
+
orderUuid,
|
|
2855
2646
|
realOrderId,
|
|
2856
2647
|
virtualOrderId: orderUuid,
|
|
2857
2648
|
timestamp: Date.now(),
|
|
@@ -2865,7 +2656,6 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2865
2656
|
response: checkoutResponse
|
|
2866
2657
|
};
|
|
2867
2658
|
}
|
|
2868
|
-
|
|
2869
2659
|
/**
|
|
2870
2660
|
* 同步订单到后端并返回真实订单ID
|
|
2871
2661
|
*
|
|
@@ -2874,22 +2664,26 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2874
2664
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
2875
2665
|
*/
|
|
2876
2666
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems, paymentStatus) {
|
|
2667
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2877
2668
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2878
|
-
throw new Error(
|
|
2669
|
+
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2879
2670
|
}
|
|
2880
2671
|
const orderLockKey = this.store.currentOrder.uuid || this.store.currentOrder.order_id;
|
|
2881
2672
|
if (!orderLockKey) {
|
|
2882
|
-
throw new Error(
|
|
2673
|
+
throw new Error("缺少订单标识,无法同步到后端");
|
|
2883
2674
|
}
|
|
2884
2675
|
const existingInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
|
|
2885
2676
|
if (existingInFlight) {
|
|
2886
|
-
this.logInfo(
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2677
|
+
this.logInfo(
|
|
2678
|
+
"syncOrderToBackendWithReturn 触发锁:当前订单正在同步中,将等待当前同步结束",
|
|
2679
|
+
{
|
|
2680
|
+
orderLockKey,
|
|
2681
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
2682
|
+
orderId: this.store.currentOrder.order_id,
|
|
2683
|
+
isManual,
|
|
2684
|
+
hasCustomPaymentItems: !!customPaymentItems
|
|
2685
|
+
}
|
|
2686
|
+
);
|
|
2893
2687
|
return await existingInFlight;
|
|
2894
2688
|
}
|
|
2895
2689
|
let resolveInFlight;
|
|
@@ -2900,77 +2694,65 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2900
2694
|
});
|
|
2901
2695
|
this.syncOrderToBackendInFlightByOrderKey.set(orderLockKey, inFlightPromise);
|
|
2902
2696
|
try {
|
|
2903
|
-
this.logInfo(
|
|
2904
|
-
isManual
|
|
2905
|
-
});
|
|
2697
|
+
this.logInfo("syncOrderToBackendWithReturn called", { isManual });
|
|
2906
2698
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
2907
|
-
const isUpdateOperation = this.store.isOrderSynced || !(0,
|
|
2699
|
+
const isUpdateOperation = this.store.isOrderSynced || !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
2908
2700
|
this.logInfo(`开始同步订单到后端...`, {
|
|
2909
2701
|
currentOrderId,
|
|
2910
|
-
isVirtualId: (0,
|
|
2702
|
+
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2911
2703
|
orderUuid: this.store.currentOrder.uuid,
|
|
2912
2704
|
isOrderSynced: this.store.isOrderSynced,
|
|
2913
2705
|
isManual
|
|
2914
2706
|
});
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
}));
|
|
2928
|
-
|
|
2929
|
-
// 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
|
|
2707
|
+
const paymentItems = customPaymentItems || await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2708
|
+
const processedPaymentItems = paymentItems.map((item) => {
|
|
2709
|
+
var _a2, _b2;
|
|
2710
|
+
return {
|
|
2711
|
+
...item,
|
|
2712
|
+
metadata: {
|
|
2713
|
+
...item.metadata,
|
|
2714
|
+
rounding_rule: ((_a2 = item.metadata) == null ? void 0 : _a2.rounding_rule) || this.otherParams.order_rounding_setting,
|
|
2715
|
+
shop_wallet_pass_id: ((_b2 = item.metadata) == null ? void 0 : _b2.shop_wallet_pass_id) || this.otherParams.shop_wallet_pass_id
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2718
|
+
});
|
|
2930
2719
|
let finalDepositAmount;
|
|
2931
|
-
const manualDepositAmount = this.store.currentOrder
|
|
2932
|
-
|
|
2933
|
-
// 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
|
|
2934
|
-
const manualDepositValue = new _decimal.default(manualDepositAmount);
|
|
2720
|
+
const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
|
|
2721
|
+
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
2935
2722
|
if (manualDepositValue.gt(0)) {
|
|
2936
|
-
// 如果手动设置了定金金额且大于0,使用手动设置的值
|
|
2937
2723
|
finalDepositAmount = manualDepositAmount;
|
|
2938
|
-
this.logInfo(
|
|
2724
|
+
this.logInfo("使用手动设置的定金金额", {
|
|
2939
2725
|
manualDepositAmount,
|
|
2940
|
-
reason:
|
|
2726
|
+
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
2941
2727
|
});
|
|
2942
2728
|
} else {
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
this.logInfo('定金金额为0', {
|
|
2729
|
+
finalDepositAmount = "0.00";
|
|
2730
|
+
this.logInfo("定金金额为0", {
|
|
2946
2731
|
manualDepositAmount,
|
|
2947
|
-
reason:
|
|
2732
|
+
reason: "手动设置和计算值均为0"
|
|
2948
2733
|
});
|
|
2949
2734
|
}
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
finalDepositAmount = '0.00';
|
|
2735
|
+
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.every((item) => item.order_payment_type !== "deposit")) {
|
|
2736
|
+
finalDepositAmount = "0.00";
|
|
2953
2737
|
this.store.currentOrder.is_deposit = 0;
|
|
2954
2738
|
}
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
const
|
|
2959
|
-
const rounding = new _decimal.default(item.rounding_amount || '0');
|
|
2739
|
+
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.some((item) => item.order_payment_type === "deposit")) {
|
|
2740
|
+
finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
|
|
2741
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2742
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2960
2743
|
return sum.plus(amt).sub(rounding);
|
|
2961
|
-
}, new
|
|
2744
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2962
2745
|
}
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
const
|
|
2967
|
-
const rounding = new _decimal.default(item.rounding_amount || '0');
|
|
2746
|
+
if (this.store.currentOrder.is_deposit === 1 && new import_decimal.default(finalDepositAmount).gte(new import_decimal.default(this.store.currentOrder.total_amount))) {
|
|
2747
|
+
finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
|
|
2748
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2749
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2968
2750
|
return sum.plus(amt).sub(rounding);
|
|
2969
|
-
}, new
|
|
2751
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2970
2752
|
}
|
|
2971
|
-
this.logInfo(
|
|
2753
|
+
this.logInfo("定金金额确定结果", {
|
|
2972
2754
|
depositPaymentItemsCount: processedPaymentItems.length,
|
|
2973
|
-
depositPaymentItems: processedPaymentItems.map(item => ({
|
|
2755
|
+
depositPaymentItems: processedPaymentItems.map((item) => ({
|
|
2974
2756
|
uuid: item.uuid,
|
|
2975
2757
|
code: item.code,
|
|
2976
2758
|
amount: item.amount,
|
|
@@ -2980,32 +2762,23 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
2980
2762
|
})),
|
|
2981
2763
|
manualDepositAmount,
|
|
2982
2764
|
finalDepositAmount,
|
|
2983
|
-
isDeposit: this.store.currentOrder
|
|
2765
|
+
isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
|
|
2984
2766
|
});
|
|
2985
|
-
|
|
2986
|
-
// 计算订单状态,优先读取外面传递的,如果没有则根据订单支付数据来
|
|
2987
|
-
// paid 已全额付款
|
|
2988
|
-
// partially_paid 部分付款
|
|
2989
|
-
// unpaid 未支付(弃单状态)
|
|
2990
|
-
// payment_processing 待支付
|
|
2991
2767
|
let orderPaymentStatus = paymentStatus;
|
|
2992
2768
|
if (!orderPaymentStatus) {
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
const
|
|
2996
|
-
const rounding = new _decimal.default(item.rounding_amount || '0');
|
|
2769
|
+
const totalPaidAmount = processedPaymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => {
|
|
2770
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2771
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2997
2772
|
return sum.plus(amt).sub(rounding);
|
|
2998
|
-
}, new
|
|
2999
|
-
if (totalPaidAmount.gte(new
|
|
3000
|
-
orderPaymentStatus =
|
|
2773
|
+
}, new import_decimal.default(0));
|
|
2774
|
+
if (totalPaidAmount.gte(new import_decimal.default(this.store.currentOrder.total_amount))) {
|
|
2775
|
+
orderPaymentStatus = "paid";
|
|
3001
2776
|
} else if (totalPaidAmount.gt(0)) {
|
|
3002
|
-
orderPaymentStatus =
|
|
2777
|
+
orderPaymentStatus = "partially_paid";
|
|
3003
2778
|
} else {
|
|
3004
|
-
orderPaymentStatus =
|
|
2779
|
+
orderPaymentStatus = "unpaid";
|
|
3005
2780
|
}
|
|
3006
2781
|
}
|
|
3007
|
-
|
|
3008
|
-
// 构造订单参数,直接使用 localOrderData 中已处理好的数据
|
|
3009
2782
|
const orderParams = {
|
|
3010
2783
|
...this.store.localOrderData,
|
|
3011
2784
|
payment_status: orderPaymentStatus,
|
|
@@ -3013,7 +2786,7 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3013
2786
|
platform: this.store.localOrderData.platform,
|
|
3014
2787
|
payments: processedPaymentItems,
|
|
3015
2788
|
// 使用处理过的支付项数据
|
|
3016
|
-
customer_id: this.store.currentCustomer
|
|
2789
|
+
customer_id: (_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id,
|
|
3017
2790
|
// 添加客户ID
|
|
3018
2791
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
3019
2792
|
// core 有
|
|
@@ -3026,46 +2799,45 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3026
2799
|
currency_code: this.otherParams.currency_code,
|
|
3027
2800
|
currency_symbol: this.otherParams.currency_symbol,
|
|
3028
2801
|
currency_format: this.otherParams.currency_format,
|
|
3029
|
-
business_code: this.otherParams
|
|
3030
|
-
is_deposit: (this.store.currentOrder
|
|
2802
|
+
business_code: ((_d = this.otherParams) == null ? void 0 : _d.business_code) || void 0,
|
|
2803
|
+
is_deposit: (((_e = this.store.currentOrder) == null ? void 0 : _e.is_deposit) || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
3031
2804
|
deposit_amount: finalDepositAmount,
|
|
3032
2805
|
// 使用最终确定的定金金额(手动设置优先)
|
|
3033
2806
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
3034
2807
|
note: this.store.localOrderData.shop_note,
|
|
3035
|
-
bookings: this.store.localOrderData.bookings
|
|
2808
|
+
bookings: (_f = this.store.localOrderData.bookings) == null ? void 0 : _f.map((item) => {
|
|
3036
2809
|
return {
|
|
3037
2810
|
...item,
|
|
3038
2811
|
product: {
|
|
3039
2812
|
...item.product,
|
|
3040
|
-
custom_deposit_data:
|
|
2813
|
+
custom_deposit_data: void 0
|
|
3041
2814
|
},
|
|
3042
|
-
deposit:
|
|
2815
|
+
deposit: void 0
|
|
3043
2816
|
};
|
|
3044
2817
|
}),
|
|
3045
|
-
relation_products: this.store.localOrderData.relation_products
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
2818
|
+
relation_products: (_g = this.store.localOrderData.relation_products) == null ? void 0 : _g.map(
|
|
2819
|
+
(item) => {
|
|
2820
|
+
return {
|
|
2821
|
+
...item,
|
|
2822
|
+
custom_deposit_data: void 0,
|
|
2823
|
+
deposit: void 0
|
|
2824
|
+
};
|
|
2825
|
+
}
|
|
2826
|
+
)
|
|
3052
2827
|
};
|
|
3053
|
-
|
|
3054
|
-
// 如果是更新操作,需要在参数中包含真实的订单ID
|
|
3055
2828
|
if (isUpdateOperation) {
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
2829
|
+
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2830
|
+
this.logWarning(
|
|
2831
|
+
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2832
|
+
);
|
|
3059
2833
|
} else {
|
|
3060
2834
|
orderParams.order_id = currentOrderId;
|
|
3061
2835
|
}
|
|
3062
2836
|
}
|
|
3063
|
-
|
|
3064
|
-
// 发送下单接口请求开始事件
|
|
3065
2837
|
const startTime = Date.now();
|
|
3066
2838
|
await this.core.effects.emit(`${this.name}:onOrderSubmitStart`, {
|
|
3067
2839
|
orderUuid: this.store.currentOrder.uuid,
|
|
3068
|
-
operation: isUpdateOperation ?
|
|
2840
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
3069
2841
|
isManual,
|
|
3070
2842
|
paymentItemCount: paymentItems.length,
|
|
3071
2843
|
timestamp: startTime
|
|
@@ -3074,93 +2846,73 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3074
2846
|
let submitSuccess = false;
|
|
3075
2847
|
let submitError;
|
|
3076
2848
|
try {
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
url: '/order/checkout',
|
|
2849
|
+
this.logInfo("Calling backend checkout API", {
|
|
2850
|
+
url: "/order/checkout",
|
|
3080
2851
|
isManual,
|
|
3081
2852
|
...orderParams
|
|
3082
2853
|
});
|
|
3083
|
-
|
|
3084
|
-
// 调用 Order 模块的专用 createOrderByCheckout 方法
|
|
3085
2854
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
3086
2855
|
submitSuccess = true;
|
|
3087
2856
|
this.store.currentOrder.payment_status = checkoutResponse.data.payment_status;
|
|
3088
|
-
this.logInfo(
|
|
2857
|
+
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
3089
2858
|
} catch (error) {
|
|
3090
2859
|
submitSuccess = false;
|
|
3091
2860
|
submitError = error instanceof Error ? error.message : String(error);
|
|
3092
|
-
this.logError(
|
|
3093
|
-
|
|
3094
|
-
// 发送订单同步失败事件(网络错误或请求失败)
|
|
2861
|
+
this.logError("下单接口调用失败:", submitError);
|
|
3095
2862
|
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
3096
2863
|
orderUuid: this.store.currentOrder.uuid,
|
|
3097
|
-
operation: isUpdateOperation ?
|
|
2864
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
3098
2865
|
isManual,
|
|
3099
2866
|
error: submitError,
|
|
3100
|
-
errorType:
|
|
2867
|
+
errorType: "network_error",
|
|
3101
2868
|
duration: Date.now() - startTime,
|
|
3102
2869
|
timestamp: Date.now()
|
|
3103
2870
|
});
|
|
3104
|
-
throw error;
|
|
2871
|
+
throw error;
|
|
3105
2872
|
} finally {
|
|
3106
|
-
// 发送下单接口请求完成事件
|
|
3107
2873
|
await this.core.effects.emit(`${this.name}:onOrderSubmitEnd`, {
|
|
3108
2874
|
success: submitSuccess,
|
|
3109
2875
|
orderUuid: this.store.currentOrder.uuid,
|
|
3110
|
-
operation: isUpdateOperation ?
|
|
2876
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
3111
2877
|
isManual,
|
|
3112
|
-
orderId: submitSuccess ? checkoutResponse
|
|
2878
|
+
orderId: submitSuccess ? ((_h = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _h.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
3113
2879
|
error: submitError,
|
|
3114
2880
|
duration: Date.now() - startTime,
|
|
3115
2881
|
timestamp: Date.now()
|
|
3116
2882
|
});
|
|
3117
2883
|
}
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
const responseStatus = checkoutResponse?.status;
|
|
3121
|
-
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && checkoutResponse?.code === 200;
|
|
2884
|
+
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2885
|
+
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
3122
2886
|
if (!isSuccessResponse) {
|
|
3123
|
-
const errorMessage = checkoutResponse
|
|
3124
|
-
|
|
3125
|
-
// 发送订单同步失败事件
|
|
2887
|
+
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
|
|
3126
2888
|
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
3127
2889
|
orderUuid: this.store.currentOrder.uuid,
|
|
3128
|
-
operation: isUpdateOperation ?
|
|
2890
|
+
operation: isUpdateOperation ? "update" : "create",
|
|
3129
2891
|
isManual,
|
|
3130
2892
|
error: errorMessage,
|
|
3131
|
-
errorType:
|
|
2893
|
+
errorType: "api_error",
|
|
3132
2894
|
response: checkoutResponse,
|
|
3133
2895
|
duration: Date.now() - startTime,
|
|
3134
2896
|
timestamp: Date.now()
|
|
3135
2897
|
});
|
|
3136
|
-
|
|
3137
|
-
// 抛出错误,终止后续处理
|
|
3138
2898
|
throw new Error(errorMessage);
|
|
3139
2899
|
}
|
|
3140
2900
|
let realOrderId;
|
|
3141
2901
|
if (isUpdateOperation) {
|
|
3142
|
-
// 更新操作:使用现有的订单ID
|
|
3143
2902
|
realOrderId = currentOrderId;
|
|
3144
2903
|
} else {
|
|
3145
|
-
|
|
3146
|
-
let extractedOrderId = checkoutResponse?.data?.order_id;
|
|
3147
|
-
|
|
3148
|
-
// 如果data.order_id不存在,尝试直接从根级获取
|
|
2904
|
+
let extractedOrderId = (_i = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _i.order_id;
|
|
3149
2905
|
if (!extractedOrderId) {
|
|
3150
|
-
extractedOrderId = checkoutResponse
|
|
2906
|
+
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
3151
2907
|
}
|
|
3152
|
-
|
|
3153
|
-
// 确保转换为字符串类型
|
|
3154
|
-
if (extractedOrderId !== undefined && extractedOrderId !== null) {
|
|
2908
|
+
if (extractedOrderId !== void 0 && extractedOrderId !== null) {
|
|
3155
2909
|
extractedOrderId = String(extractedOrderId);
|
|
3156
2910
|
}
|
|
3157
2911
|
if (!extractedOrderId) {
|
|
3158
|
-
this.logError(
|
|
2912
|
+
this.logError("后端返回的订单信息中未包含订单ID");
|
|
3159
2913
|
}
|
|
3160
2914
|
realOrderId = extractedOrderId;
|
|
3161
|
-
|
|
3162
|
-
// 替换虚拟订单ID为真实订单ID
|
|
3163
|
-
this.logInfo('准备替换订单ID:', {
|
|
2915
|
+
this.logInfo("准备替换订单ID:", {
|
|
3164
2916
|
orderUuid: this.store.currentOrder.uuid,
|
|
3165
2917
|
oldOrderId: this.store.currentOrder.order_id,
|
|
3166
2918
|
newOrderId: realOrderId
|
|
@@ -3168,84 +2920,74 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3168
2920
|
try {
|
|
3169
2921
|
const latestPaymentStatus = this.store.currentOrder.payment_status;
|
|
3170
2922
|
const previousOrder = this.store.currentOrder;
|
|
3171
|
-
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
3172
|
-
|
|
2923
|
+
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
2924
|
+
previousOrder.uuid,
|
|
2925
|
+
realOrderId
|
|
2926
|
+
);
|
|
2927
|
+
this.logInfo("Payment模块替换订单ID结果:", {
|
|
3173
2928
|
wasSuccessful: !!updatedOrder,
|
|
3174
|
-
returnedOrderId: updatedOrder
|
|
2929
|
+
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
3175
2930
|
expectedOrderId: realOrderId
|
|
3176
2931
|
});
|
|
3177
2932
|
if (updatedOrder) {
|
|
3178
|
-
this.logInfo(
|
|
2933
|
+
this.logInfo("Payment模块返回的更新后订单:", {
|
|
3179
2934
|
uuid: updatedOrder.uuid,
|
|
3180
2935
|
orderId: updatedOrder.order_id,
|
|
3181
2936
|
totalAmount: updatedOrder.total_amount
|
|
3182
2937
|
});
|
|
3183
|
-
|
|
3184
|
-
// 🔧 合并 DB 快照到内存态,避免覆盖 payment_status(以及其它刚更新过的内存字段)
|
|
3185
2938
|
this.store.currentOrder = {
|
|
3186
2939
|
...previousOrder,
|
|
3187
2940
|
...updatedOrder,
|
|
3188
2941
|
payment_status: latestPaymentStatus
|
|
3189
2942
|
};
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
2943
|
+
if (latestPaymentStatus)
|
|
2944
|
+
await this.payment.updateOrderAsync(previousOrder.uuid, {
|
|
2945
|
+
payment_status: latestPaymentStatus
|
|
2946
|
+
});
|
|
2947
|
+
this.logInfo(
|
|
2948
|
+
"[Checkout] 订单ID替换成功,当前订单ID:",
|
|
2949
|
+
this.store.currentOrder.order_id
|
|
2950
|
+
);
|
|
3196
2951
|
} else {
|
|
3197
|
-
this.logError(
|
|
3198
|
-
|
|
3199
|
-
|
|
2952
|
+
this.logError(
|
|
2953
|
+
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2954
|
+
);
|
|
3200
2955
|
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
3201
2956
|
this.store.currentOrder.order_id = realOrderId;
|
|
3202
|
-
this.logInfo(
|
|
2957
|
+
this.logInfo("手动设置订单ID:", {
|
|
3203
2958
|
beforeReplacement: beforeManualUpdate,
|
|
3204
2959
|
afterReplacement: this.store.currentOrder.order_id,
|
|
3205
2960
|
目标ID: realOrderId
|
|
3206
2961
|
});
|
|
3207
2962
|
}
|
|
3208
2963
|
} catch (error) {
|
|
3209
|
-
this.logError(
|
|
3210
|
-
|
|
3211
|
-
// 发生错误时也进行手动替换
|
|
2964
|
+
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
3212
2965
|
this.store.currentOrder.order_id = realOrderId;
|
|
3213
|
-
this.logInfo(
|
|
2966
|
+
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
3214
2967
|
}
|
|
3215
2968
|
}
|
|
3216
|
-
|
|
3217
|
-
// 成功后:标记本次传递给后端的支付项为已同步
|
|
3218
2969
|
try {
|
|
3219
|
-
const syncedPaymentUuids = processedPaymentItems.filter(item => item.status !==
|
|
2970
|
+
const syncedPaymentUuids = processedPaymentItems.filter((item) => item.status !== "voided").map((item) => item.uuid).filter(Boolean);
|
|
3220
2971
|
for (const paymentUuid of syncedPaymentUuids) {
|
|
3221
|
-
await this.payment.updatePaymentAsync(
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
2972
|
+
await this.payment.updatePaymentAsync(
|
|
2973
|
+
this.store.currentOrder.uuid,
|
|
2974
|
+
paymentUuid,
|
|
2975
|
+
{ isSynced: true, syncError: void 0 }
|
|
2976
|
+
);
|
|
3225
2977
|
}
|
|
3226
2978
|
} catch (e) {
|
|
3227
|
-
this.logWarning(
|
|
3228
|
-
error: e
|
|
3229
|
-
});
|
|
2979
|
+
this.logWarning("标记支付项已同步失败(不阻塞主流程)", { error: e });
|
|
3230
2980
|
}
|
|
3231
|
-
|
|
3232
|
-
// 标记订单已同步
|
|
3233
2981
|
this.store.isOrderSynced = true;
|
|
3234
|
-
|
|
3235
|
-
// 🚀 清除计算缓存,订单已同步,数据可能已变更
|
|
3236
2982
|
this.clearCalculationCache();
|
|
3237
|
-
|
|
3238
|
-
// 触发订单同步完成事件
|
|
3239
2983
|
await this.core.effects.emit(`${this.name}:onOrderSynced`, {
|
|
3240
2984
|
orderUuid: this.store.currentOrder.uuid,
|
|
3241
2985
|
realOrderId,
|
|
3242
2986
|
virtualOrderId: this.store.currentOrder.order_id,
|
|
3243
2987
|
timestamp: Date.now(),
|
|
3244
|
-
isManual
|
|
2988
|
+
isManual,
|
|
3245
2989
|
response: checkoutResponse
|
|
3246
2990
|
});
|
|
3247
|
-
|
|
3248
|
-
// 返回同步结果
|
|
3249
2991
|
const result = {
|
|
3250
2992
|
success: true,
|
|
3251
2993
|
orderId: realOrderId,
|
|
@@ -3264,10 +3006,8 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3264
3006
|
}
|
|
3265
3007
|
}
|
|
3266
3008
|
}
|
|
3267
|
-
async setOtherParams(params, {
|
|
3268
|
-
|
|
3269
|
-
} = {}) {
|
|
3270
|
-
this.logInfo('setOtherParams called', {
|
|
3009
|
+
async setOtherParams(params, { cover = false } = {}) {
|
|
3010
|
+
this.logInfo("setOtherParams called", {
|
|
3271
3011
|
metadata: {
|
|
3272
3012
|
params,
|
|
3273
3013
|
cover
|
|
@@ -3276,13 +3016,9 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3276
3016
|
if (cover) {
|
|
3277
3017
|
this.otherParams = params;
|
|
3278
3018
|
} else {
|
|
3279
|
-
this.otherParams = {
|
|
3280
|
-
...this.otherParams,
|
|
3281
|
-
...params
|
|
3282
|
-
};
|
|
3019
|
+
this.otherParams = { ...this.otherParams, ...params };
|
|
3283
3020
|
}
|
|
3284
3021
|
}
|
|
3285
|
-
|
|
3286
3022
|
/**
|
|
3287
3023
|
* 通过订单ID编辑订单备注
|
|
3288
3024
|
*
|
|
@@ -3293,54 +3029,41 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3293
3029
|
* @returns 修改结果
|
|
3294
3030
|
*/
|
|
3295
3031
|
async editOrderNoteByOrderIdAsync(orderId, note) {
|
|
3296
|
-
this.logInfo(
|
|
3297
|
-
orderId
|
|
3298
|
-
note
|
|
3032
|
+
this.logInfo("editOrderNoteByOrderIdAsync called", {
|
|
3033
|
+
orderId,
|
|
3034
|
+
note,
|
|
3299
3035
|
noteLength: note.length
|
|
3300
3036
|
});
|
|
3301
3037
|
try {
|
|
3302
|
-
// 参数验证
|
|
3303
3038
|
if (!orderId) {
|
|
3304
3039
|
return {
|
|
3305
3040
|
success: false,
|
|
3306
|
-
message:
|
|
3307
|
-
orderId
|
|
3041
|
+
message: "订单ID不能为空",
|
|
3042
|
+
orderId
|
|
3308
3043
|
};
|
|
3309
3044
|
}
|
|
3310
|
-
|
|
3311
|
-
// 记录接口调用
|
|
3312
|
-
this.logInfo('Calling order note edit API', {
|
|
3045
|
+
this.logInfo("Calling order note edit API", {
|
|
3313
3046
|
url: `/order/order/${orderId}/note`,
|
|
3314
|
-
method:
|
|
3315
|
-
orderId
|
|
3316
|
-
note
|
|
3047
|
+
method: "PUT",
|
|
3048
|
+
orderId,
|
|
3049
|
+
note,
|
|
3317
3050
|
noteLength: note.length
|
|
3318
3051
|
});
|
|
3319
|
-
|
|
3320
|
-
// 调用后端API修改订单备注
|
|
3321
3052
|
const response = await this.request.put(`/order/order/${orderId}/note`, {
|
|
3322
|
-
note
|
|
3053
|
+
note
|
|
3323
3054
|
});
|
|
3324
|
-
this.logInfo(
|
|
3325
|
-
orderId
|
|
3055
|
+
this.logInfo("订单备注编辑响应:", {
|
|
3056
|
+
orderId,
|
|
3326
3057
|
status: response.status,
|
|
3327
3058
|
message: response.message,
|
|
3328
|
-
response
|
|
3059
|
+
response
|
|
3329
3060
|
});
|
|
3330
|
-
|
|
3331
|
-
// 检查响应状态
|
|
3332
3061
|
if (response.status === true || response.status === 200) {
|
|
3333
|
-
// 如果当前订单就是被修改的订单,同时更新本地状态
|
|
3334
3062
|
if (this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))) {
|
|
3335
|
-
// 获取修改前的备注用于事件
|
|
3336
3063
|
const previousNote = this.getOrderNote();
|
|
3337
|
-
|
|
3338
|
-
// 更新本地订单数据中的备注
|
|
3339
3064
|
if (this.store.localOrderData) {
|
|
3340
3065
|
this.store.localOrderData.shop_note = note;
|
|
3341
3066
|
}
|
|
3342
|
-
|
|
3343
|
-
// 触发订单备注变更事件
|
|
3344
3067
|
await this.core.effects.emit(`${this.name}:onOrderNoteChanged`, {
|
|
3345
3068
|
orderUuid: this.store.currentOrder.uuid,
|
|
3346
3069
|
oldNote: previousNote,
|
|
@@ -3350,30 +3073,28 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3350
3073
|
}
|
|
3351
3074
|
return {
|
|
3352
3075
|
success: true,
|
|
3353
|
-
message: response.message ||
|
|
3354
|
-
orderId
|
|
3076
|
+
message: response.message || "订单备注修改成功",
|
|
3077
|
+
orderId
|
|
3355
3078
|
};
|
|
3356
3079
|
} else {
|
|
3357
|
-
|
|
3358
|
-
const errorMessage = response.message || '订单备注修改失败';
|
|
3080
|
+
const errorMessage = response.message || "订单备注修改失败";
|
|
3359
3081
|
this.logError(`订单 ${orderId} 备注修改失败:`, errorMessage);
|
|
3360
3082
|
return {
|
|
3361
3083
|
success: false,
|
|
3362
3084
|
message: errorMessage,
|
|
3363
|
-
orderId
|
|
3085
|
+
orderId
|
|
3364
3086
|
};
|
|
3365
3087
|
}
|
|
3366
3088
|
} catch (error) {
|
|
3367
|
-
this.logError(
|
|
3368
|
-
const errorMessage = error instanceof Error ? error.message :
|
|
3089
|
+
this.logError("编辑订单备注失败:", error);
|
|
3090
|
+
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
3369
3091
|
return {
|
|
3370
3092
|
success: false,
|
|
3371
3093
|
message: `编辑订单备注失败: ${errorMessage}`,
|
|
3372
|
-
orderId
|
|
3094
|
+
orderId
|
|
3373
3095
|
};
|
|
3374
3096
|
}
|
|
3375
3097
|
}
|
|
3376
|
-
|
|
3377
3098
|
/**
|
|
3378
3099
|
* 发送客户支付链接邮件
|
|
3379
3100
|
*
|
|
@@ -3383,85 +3104,78 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3383
3104
|
* @returns 发送结果
|
|
3384
3105
|
*/
|
|
3385
3106
|
async sendCustomerPayLinkAsync(params) {
|
|
3386
|
-
|
|
3107
|
+
var _a, _b;
|
|
3108
|
+
this.logInfo("sendCustomerPayLinkAsync called", {
|
|
3387
3109
|
orderIds: params.order_ids,
|
|
3388
|
-
orderIdsCount: params.order_ids
|
|
3110
|
+
orderIdsCount: ((_a = params.order_ids) == null ? void 0 : _a.length) || 0,
|
|
3389
3111
|
emails: params.emails,
|
|
3390
|
-
emailsCount: params.emails
|
|
3391
|
-
notifyAction: params.notify_action ||
|
|
3112
|
+
emailsCount: ((_b = params.emails) == null ? void 0 : _b.length) || 0,
|
|
3113
|
+
notifyAction: params.notify_action || "order_payment_reminder"
|
|
3392
3114
|
});
|
|
3393
3115
|
try {
|
|
3394
|
-
// 参数验证
|
|
3395
3116
|
if (!params.order_ids || params.order_ids.length === 0) {
|
|
3396
3117
|
return {
|
|
3397
3118
|
success: false,
|
|
3398
|
-
message:
|
|
3119
|
+
message: "订单ID列表不能为空"
|
|
3399
3120
|
};
|
|
3400
3121
|
}
|
|
3401
3122
|
if (!params.emails || params.emails.length === 0) {
|
|
3402
3123
|
return {
|
|
3403
3124
|
success: false,
|
|
3404
|
-
message:
|
|
3125
|
+
message: "邮箱地址列表不能为空"
|
|
3405
3126
|
};
|
|
3406
3127
|
}
|
|
3407
|
-
|
|
3408
|
-
// 验证邮箱格式
|
|
3409
3128
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
3410
|
-
const invalidEmails = params.emails.filter(
|
|
3129
|
+
const invalidEmails = params.emails.filter(
|
|
3130
|
+
(email) => !emailRegex.test(email)
|
|
3131
|
+
);
|
|
3411
3132
|
if (invalidEmails.length > 0) {
|
|
3412
3133
|
return {
|
|
3413
3134
|
success: false,
|
|
3414
|
-
message: `邮箱格式无效: ${invalidEmails.join(
|
|
3135
|
+
message: `邮箱格式无效: ${invalidEmails.join(", ")}`
|
|
3415
3136
|
};
|
|
3416
3137
|
}
|
|
3417
|
-
|
|
3418
|
-
// 构建请求参数
|
|
3419
3138
|
const requestBody = {
|
|
3420
3139
|
order_ids: params.order_ids,
|
|
3421
|
-
notify_action: params.notify_action ||
|
|
3140
|
+
notify_action: params.notify_action || "order_payment_reminder",
|
|
3422
3141
|
emails: params.emails
|
|
3423
3142
|
};
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
this.logInfo('Calling batch email API', {
|
|
3427
|
-
url: '/order/batch-email',
|
|
3143
|
+
this.logInfo("Calling batch email API", {
|
|
3144
|
+
url: "/order/batch-email",
|
|
3428
3145
|
...requestBody
|
|
3429
3146
|
});
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3147
|
+
const response = await this.request.post(
|
|
3148
|
+
"/order/batch-email",
|
|
3149
|
+
requestBody
|
|
3150
|
+
);
|
|
3151
|
+
this.logInfo("支付链接邮件发送响应:", {
|
|
3434
3152
|
status: response.status,
|
|
3435
3153
|
message: response.message,
|
|
3436
3154
|
data: response.data,
|
|
3437
|
-
response
|
|
3155
|
+
response
|
|
3438
3156
|
});
|
|
3439
|
-
|
|
3440
|
-
// 检查响应状态
|
|
3441
3157
|
if (response.status === true || response.status === 200) {
|
|
3442
3158
|
return {
|
|
3443
3159
|
success: true,
|
|
3444
|
-
message: response.message ||
|
|
3160
|
+
message: response.message || "支付链接邮件发送成功"
|
|
3445
3161
|
};
|
|
3446
3162
|
} else {
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
|
|
3163
|
+
const errorMessage = response.message || "支付链接邮件发送失败";
|
|
3164
|
+
console.error("[Checkout] 支付链接邮件发送失败:", errorMessage);
|
|
3450
3165
|
return {
|
|
3451
3166
|
success: false,
|
|
3452
3167
|
message: errorMessage
|
|
3453
3168
|
};
|
|
3454
3169
|
}
|
|
3455
3170
|
} catch (error) {
|
|
3456
|
-
this.logError(
|
|
3457
|
-
const errorMessage = error instanceof Error ? error.message :
|
|
3171
|
+
this.logError("发送客户支付链接邮件失败:", error);
|
|
3172
|
+
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
3458
3173
|
return {
|
|
3459
3174
|
success: false,
|
|
3460
3175
|
message: `发送支付链接邮件失败: ${errorMessage}`
|
|
3461
3176
|
};
|
|
3462
3177
|
}
|
|
3463
3178
|
}
|
|
3464
|
-
|
|
3465
3179
|
/**
|
|
3466
3180
|
* 金额舍入
|
|
3467
3181
|
*
|
|
@@ -3469,33 +3183,31 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3469
3183
|
* @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
|
|
3470
3184
|
*/
|
|
3471
3185
|
async roundAmountAsync(amount) {
|
|
3472
|
-
|
|
3473
|
-
const cashManualPayment = this.store.paymentMethods.find(p => p.code ===
|
|
3474
|
-
if (!cashManualPayment
|
|
3186
|
+
var _a, _b, _c;
|
|
3187
|
+
const cashManualPayment = this.store.paymentMethods.find((p) => p.code === "CASHMANUAL");
|
|
3188
|
+
if (!((_a = cashManualPayment == null ? void 0 : cashManualPayment.metadata) == null ? void 0 : _a.order_rounding_switch)) {
|
|
3475
3189
|
return {
|
|
3476
3190
|
originalAmount: amount.toString(),
|
|
3477
3191
|
roundedAmount: amount.toString(),
|
|
3478
|
-
roundingDifference:
|
|
3192
|
+
roundingDifference: "0.00"
|
|
3479
3193
|
};
|
|
3480
3194
|
}
|
|
3481
|
-
const result = await this.payment.roundAmountAsync(
|
|
3195
|
+
const result = await this.payment.roundAmountAsync(
|
|
3196
|
+
amount,
|
|
3197
|
+
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.interval,
|
|
3198
|
+
(_c = this.otherParams.order_rounding_setting) == null ? void 0 : _c.type
|
|
3199
|
+
);
|
|
3482
3200
|
return result;
|
|
3483
3201
|
}
|
|
3484
3202
|
async destroy() {
|
|
3485
|
-
|
|
3203
|
+
var _a, _b, _c, _d;
|
|
3486
3204
|
this.payment.wallet.clearAllCache();
|
|
3487
|
-
|
|
3488
|
-
// 清理事件监听
|
|
3489
3205
|
this.core.effects.offByModuleDestroy(this.name);
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
await this.order?.destroy?.();
|
|
3493
|
-
await this.payment?.destroy?.();
|
|
3494
|
-
|
|
3495
|
-
// 取消注册模块
|
|
3206
|
+
await ((_b = (_a = this.order) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a));
|
|
3207
|
+
await ((_d = (_c = this.payment) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c));
|
|
3496
3208
|
this.core.unregisterModule(this);
|
|
3209
|
+
console.log("[Checkout] 已销毁");
|
|
3497
3210
|
}
|
|
3498
|
-
|
|
3499
3211
|
/**
|
|
3500
3212
|
* 重置 store 状态
|
|
3501
3213
|
*
|
|
@@ -3509,29 +3221,19 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3509
3221
|
uuid: this.store.currentOrder.uuid,
|
|
3510
3222
|
orderId: this.store.currentOrder.order_id
|
|
3511
3223
|
} : null;
|
|
3512
|
-
|
|
3513
|
-
this.store.currentOrder =
|
|
3514
|
-
this.store.localOrderData =
|
|
3515
|
-
this.store.cartSummary =
|
|
3516
|
-
this.store.stateAmount =
|
|
3517
|
-
this.store.balanceDueAmount =
|
|
3224
|
+
console.log("[Checkout] 重置 store 状态,准备创建新订单", prevOrderInfo);
|
|
3225
|
+
this.store.currentOrder = void 0;
|
|
3226
|
+
this.store.localOrderData = void 0;
|
|
3227
|
+
this.store.cartSummary = void 0;
|
|
3228
|
+
this.store.stateAmount = "0.00";
|
|
3229
|
+
this.store.balanceDueAmount = "0.00";
|
|
3518
3230
|
this.store.isOrderSynced = false;
|
|
3519
|
-
this.store.currentCustomer =
|
|
3520
|
-
this.store.lastError =
|
|
3521
|
-
|
|
3522
|
-
// 清空购物车项目
|
|
3231
|
+
this.store.currentCustomer = void 0;
|
|
3232
|
+
this.store.lastError = void 0;
|
|
3523
3233
|
this.store.cartItems = [];
|
|
3524
|
-
|
|
3525
|
-
// 清理钱包缓存(同步操作)
|
|
3526
3234
|
this.payment.wallet.clearAllCache();
|
|
3527
|
-
|
|
3528
|
-
// 🚀 清除计算缓存
|
|
3529
3235
|
this.clearCalculationCache();
|
|
3530
|
-
|
|
3531
|
-
// 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
|
|
3532
|
-
|
|
3533
|
-
// 🚀 性能优化:异步触发订单清理事件(不阻塞主流程)
|
|
3534
|
-
// 使用 setTimeout 确保事件处理不会阻塞状态重置
|
|
3236
|
+
console.log("[Checkout] Store 状态重置完成");
|
|
3535
3237
|
if (prevOrderInfo) {
|
|
3536
3238
|
setTimeout(() => {
|
|
3537
3239
|
this.core.effects.emit(`${this.name}:onOrderCleared`, {
|
|
@@ -3541,8 +3243,12 @@ class CheckoutImpl extends _BaseModule.BaseModule {
|
|
|
3541
3243
|
}, 0);
|
|
3542
3244
|
}
|
|
3543
3245
|
} catch (error) {
|
|
3544
|
-
console.error(
|
|
3246
|
+
console.error("[Checkout] 重置 store 状态失败:", error);
|
|
3545
3247
|
}
|
|
3546
3248
|
}
|
|
3547
|
-
}
|
|
3548
|
-
|
|
3249
|
+
};
|
|
3250
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3251
|
+
0 && (module.exports = {
|
|
3252
|
+
CheckoutImpl,
|
|
3253
|
+
...require("./types")
|
|
3254
|
+
});
|