@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,110 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
PaymentModule: true
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
8
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/modules/Payment/index.ts
|
|
21
|
+
var Payment_exports = {};
|
|
22
|
+
__export(Payment_exports, {
|
|
23
|
+
PaymentModule: () => PaymentModule,
|
|
24
|
+
generateRequestUniqueId: () => generateRequestUniqueId
|
|
24
25
|
});
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
module.exports = __toCommonJS(Payment_exports);
|
|
27
|
+
var import_BaseModule = require("../BaseModule");
|
|
28
|
+
var import_types = require("./types");
|
|
29
|
+
var import_utils = require("../Cart/utils");
|
|
30
|
+
var import_cash = require("./cash");
|
|
31
|
+
var import_eftpos = require("./eftpos");
|
|
32
|
+
var import_walletpass = require("./walletpass");
|
|
33
|
+
var import_decimal = require("decimal.js");
|
|
34
|
+
__reExport(Payment_exports, require("./types"), module.exports);
|
|
33
35
|
function formatAmount(amount) {
|
|
34
36
|
try {
|
|
35
|
-
const decimal = new
|
|
37
|
+
const decimal = new import_decimal.Decimal(amount);
|
|
36
38
|
return decimal.toFixed(2);
|
|
37
39
|
} catch (error) {
|
|
38
40
|
console.warn(`[PaymentModule] 金额格式化失败: ${amount},使用默认值 0.00`);
|
|
39
|
-
return
|
|
41
|
+
return "0.00";
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 格式化日期时间为字符串
|
|
45
|
-
* 格式: YYYY-MM-DD HH:mm:ss
|
|
46
|
-
* 示例: 2025-12-10 16:14:50
|
|
47
|
-
*/
|
|
48
44
|
function formatDateTime(date) {
|
|
49
45
|
const year = date.getFullYear();
|
|
50
|
-
const month = String(date.getMonth() + 1).padStart(2,
|
|
51
|
-
const day = String(date.getDate()).padStart(2,
|
|
52
|
-
const hours = String(date.getHours()).padStart(2,
|
|
53
|
-
const minutes = String(date.getMinutes()).padStart(2,
|
|
54
|
-
const seconds = String(date.getSeconds()).padStart(2,
|
|
46
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
47
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
48
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
49
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
50
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
55
51
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 生成请求唯一ID
|
|
60
|
-
* 格式: 年月日时分秒毫秒+4位随机数
|
|
61
|
-
* 示例: 20241201143025123456
|
|
62
|
-
*/
|
|
63
53
|
function generateRequestUniqueId() {
|
|
64
|
-
const now = new Date();
|
|
54
|
+
const now = /* @__PURE__ */ new Date();
|
|
65
55
|
const year = now.getFullYear();
|
|
66
|
-
const month = String(now.getMonth() + 1).padStart(2,
|
|
67
|
-
const day = String(now.getDate()).padStart(2,
|
|
68
|
-
const hour = String(now.getHours()).padStart(2,
|
|
69
|
-
const minute = String(now.getMinutes()).padStart(2,
|
|
70
|
-
const second = String(now.getSeconds()).padStart(2,
|
|
71
|
-
const millisecond = String(now.getMilliseconds()).padStart(3,
|
|
72
|
-
const randomDigits = Math.floor(Math.random() *
|
|
73
|
-
|
|
56
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
57
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
58
|
+
const hour = String(now.getHours()).padStart(2, "0");
|
|
59
|
+
const minute = String(now.getMinutes()).padStart(2, "0");
|
|
60
|
+
const second = String(now.getSeconds()).padStart(2, "0");
|
|
61
|
+
const millisecond = String(now.getMilliseconds()).padStart(3, "0");
|
|
62
|
+
const randomDigits = Math.floor(Math.random() * 9e3) + 1e3;
|
|
74
63
|
return `${year}${month}${day}${hour}${minute}${second}${millisecond}${randomDigits}`;
|
|
75
64
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
defaultVersion = '1.0.0';
|
|
85
|
-
request;
|
|
86
|
-
app; // App instance
|
|
87
|
-
store;
|
|
88
|
-
window; // WindowPlugin 实例
|
|
89
|
-
dbManager; // IndexDBManager 实例
|
|
90
|
-
logger; // LoggerManager 实例
|
|
91
|
-
voucherUpdateLockByOrderUuid = new Map();
|
|
92
|
-
otherParams = {};
|
|
93
|
-
|
|
94
|
-
// 支付方式实例
|
|
95
|
-
cash;
|
|
96
|
-
eftpos;
|
|
97
|
-
wallet;
|
|
65
|
+
function normalizeCustomPaymentId(paymentItem) {
|
|
66
|
+
const rawId = paymentItem.custom_payment_id ?? paymentItem.id ?? 0;
|
|
67
|
+
const parsedId = Number(rawId);
|
|
68
|
+
if (!Number.isFinite(parsedId))
|
|
69
|
+
return 0;
|
|
70
|
+
return parsedId;
|
|
71
|
+
}
|
|
72
|
+
var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
98
73
|
constructor(name, version) {
|
|
99
74
|
super(name || "payment", version);
|
|
100
|
-
|
|
101
|
-
this.
|
|
102
|
-
|
|
103
|
-
this.
|
|
75
|
+
this.defaultName = "pay";
|
|
76
|
+
this.defaultVersion = "1.0.0";
|
|
77
|
+
// LoggerManager 实例
|
|
78
|
+
this.voucherUpdateLockByOrderUuid = /* @__PURE__ */ new Map();
|
|
79
|
+
this.otherParams = {};
|
|
80
|
+
this.cash = new import_cash.CashPaymentImpl(this);
|
|
81
|
+
this.eftpos = new import_eftpos.EftposPaymentImpl(this);
|
|
82
|
+
this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
|
|
104
83
|
}
|
|
105
84
|
runVoucherUpdateLocked(orderUuid, task) {
|
|
106
85
|
const previous = this.voucherUpdateLockByOrderUuid.get(orderUuid) || Promise.resolve();
|
|
107
|
-
const next = previous.catch(() =>
|
|
86
|
+
const next = previous.catch(() => void 0).then(task).finally(() => {
|
|
108
87
|
if (this.voucherUpdateLockByOrderUuid.get(orderUuid) === next) {
|
|
109
88
|
this.voucherUpdateLockByOrderUuid.delete(orderUuid);
|
|
110
89
|
}
|
|
@@ -113,21 +92,18 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
113
92
|
return next;
|
|
114
93
|
}
|
|
115
94
|
normalizeVoucherPaymentItems(voucherPaymentItems) {
|
|
116
|
-
const normalized = new Map();
|
|
95
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
117
96
|
for (const item of voucherPaymentItems || []) {
|
|
118
|
-
if (!item
|
|
97
|
+
if (!(item == null ? void 0 : item.voucher_id)) {
|
|
119
98
|
throw new Error(`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`);
|
|
120
99
|
}
|
|
121
|
-
const orderPaymentType = item.order_payment_type ||
|
|
100
|
+
const orderPaymentType = item.order_payment_type || "normal";
|
|
122
101
|
const key = `${item.voucher_id}|${orderPaymentType}`;
|
|
123
|
-
normalized.set(key, {
|
|
124
|
-
...item,
|
|
125
|
-
order_payment_type: orderPaymentType
|
|
126
|
-
});
|
|
102
|
+
normalized.set(key, { ...item, order_payment_type: orderPaymentType });
|
|
127
103
|
}
|
|
128
104
|
return {
|
|
129
105
|
items: Array.from(normalized.values()),
|
|
130
|
-
originalCount: voucherPaymentItems
|
|
106
|
+
originalCount: (voucherPaymentItems == null ? void 0 : voucherPaymentItems.length) || 0,
|
|
131
107
|
normalizedCount: normalized.size
|
|
132
108
|
};
|
|
133
109
|
}
|
|
@@ -135,37 +111,38 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
135
111
|
this.core = core;
|
|
136
112
|
this.store = options.store;
|
|
137
113
|
this.otherParams = options.otherParams || {};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.
|
|
141
|
-
const appPlugin = core.getPlugin('app');
|
|
142
|
-
this.window = core.getPlugin('window');
|
|
114
|
+
this.request = core.getPlugin("request");
|
|
115
|
+
const appPlugin = core.getPlugin("app");
|
|
116
|
+
this.window = core.getPlugin("window");
|
|
143
117
|
if (!this.request) {
|
|
144
|
-
throw new Error(
|
|
118
|
+
throw new Error("支付模块需要 request 插件支持");
|
|
145
119
|
}
|
|
146
120
|
if (!appPlugin) {
|
|
147
|
-
throw new Error(
|
|
121
|
+
throw new Error("支付模块需要 app 插件支持");
|
|
148
122
|
}
|
|
149
123
|
this.app = appPlugin.getApp();
|
|
150
124
|
this.dbManager = this.app.dbManager;
|
|
151
125
|
this.logger = this.app.logger;
|
|
152
|
-
|
|
153
|
-
// 确保支付模块所需的对象存储已创建
|
|
154
|
-
await this.ensurePaymentTables();
|
|
155
126
|
this.registerNetworkHandlers();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
127
|
+
console.log("[PaymentModule] 初始化完成");
|
|
128
|
+
this.logInfo("PaymentModule initialized successfully");
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 更新父级解决方案透传的运行态参数,主要用于日志父模块等上下文。
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* paymentModule.updateOtherParams({ fatherModule: 'bookingTicket' });
|
|
135
|
+
*/
|
|
136
|
+
updateOtherParams(params) {
|
|
137
|
+
this.otherParams = params || {};
|
|
161
138
|
}
|
|
162
|
-
|
|
163
139
|
/**
|
|
164
140
|
* 记录信息日志
|
|
165
141
|
*/
|
|
166
142
|
logInfo(title, metadata) {
|
|
167
|
-
|
|
168
|
-
|
|
143
|
+
var _a, _b;
|
|
144
|
+
if ((_a = this.otherParams) == null ? void 0 : _a.fatherModule) {
|
|
145
|
+
const fatherModule = this.core.getModule((_b = this.otherParams) == null ? void 0 : _b.fatherModule);
|
|
169
146
|
if (fatherModule) {
|
|
170
147
|
fatherModule.logInfo(`${title}`, metadata);
|
|
171
148
|
return;
|
|
@@ -173,33 +150,31 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
173
150
|
}
|
|
174
151
|
if (this.logger) {
|
|
175
152
|
this.logger.addLog({
|
|
176
|
-
type:
|
|
153
|
+
type: "info",
|
|
177
154
|
title: `[PaymentModule] ${title}`,
|
|
178
155
|
metadata: metadata || {}
|
|
179
156
|
});
|
|
180
157
|
}
|
|
181
158
|
}
|
|
182
|
-
|
|
183
159
|
/**
|
|
184
160
|
* 记录警告日志
|
|
185
161
|
*/
|
|
186
162
|
logWarning(title, metadata) {
|
|
187
163
|
if (this.logger) {
|
|
188
164
|
this.logger.addLog({
|
|
189
|
-
type:
|
|
165
|
+
type: "warning",
|
|
190
166
|
title: `[PaymentModule] ${title}`,
|
|
191
167
|
metadata: metadata || {}
|
|
192
168
|
});
|
|
193
169
|
}
|
|
194
170
|
}
|
|
195
|
-
|
|
196
171
|
/**
|
|
197
172
|
* 记录错误日志
|
|
198
173
|
*/
|
|
199
174
|
logError(title, error, metadata) {
|
|
200
175
|
if (this.logger) {
|
|
201
176
|
this.logger.addLog({
|
|
202
|
-
type:
|
|
177
|
+
type: "error",
|
|
203
178
|
title: `[PaymentModule] ${title}`,
|
|
204
179
|
metadata: {
|
|
205
180
|
error: error ? {
|
|
@@ -207,295 +182,128 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
207
182
|
stack: error.stack,
|
|
208
183
|
code: error.code,
|
|
209
184
|
...error
|
|
210
|
-
} :
|
|
211
|
-
...
|
|
185
|
+
} : void 0,
|
|
186
|
+
...metadata || {}
|
|
212
187
|
}
|
|
213
188
|
});
|
|
214
189
|
}
|
|
215
190
|
}
|
|
216
|
-
|
|
217
191
|
/**
|
|
218
192
|
* 记录调试日志
|
|
219
193
|
*/
|
|
220
194
|
logDebug(title, metadata) {
|
|
221
195
|
if (this.logger) {
|
|
222
196
|
this.logger.addLog({
|
|
223
|
-
type:
|
|
197
|
+
type: "debug",
|
|
224
198
|
title: `[PaymentModule] ${title}`,
|
|
225
199
|
metadata: metadata || {}
|
|
226
200
|
});
|
|
227
201
|
}
|
|
228
202
|
}
|
|
229
|
-
|
|
230
203
|
/**
|
|
231
204
|
* 网络恢复以后,尝试执行队列
|
|
232
205
|
*
|
|
233
206
|
*/
|
|
234
207
|
registerNetworkHandlers() {
|
|
235
|
-
const network = this.app.plugins.get(
|
|
236
|
-
this.logInfo(
|
|
237
|
-
network
|
|
238
|
-
|
|
208
|
+
const network = this.app.plugins.get("network");
|
|
209
|
+
this.logInfo("Registering network status listener");
|
|
210
|
+
network == null ? void 0 : network.addListener("networkStatusChange", async (status) => {
|
|
211
|
+
console.log("网络状态:", status.connected);
|
|
212
|
+
this.logInfo("Network status changed", {
|
|
239
213
|
connected: status.connected,
|
|
240
214
|
previousStatus: status.previousStatus
|
|
241
215
|
});
|
|
242
216
|
if (status.connected) {
|
|
243
|
-
this.logInfo(
|
|
244
|
-
// 网络恢复时的处理逻辑可以在这里添加
|
|
217
|
+
this.logInfo("Network reconnected");
|
|
245
218
|
}
|
|
246
219
|
});
|
|
247
220
|
}
|
|
248
|
-
async filterPayMethods(payMethods) {
|
|
249
|
-
// 1. 筛选 status === 1 && disable === 0的数据
|
|
250
|
-
// 2. 检查列表里是否有 code=WALLET_PASS的数据,如果没有,则列表里如果有 PRODUCTVOUCHER 、 GIFTCARD 、 POINTCARD 则删除他们
|
|
251
|
-
// 如果有 code = WALLET_PASS的数据,则列表里PRODUCTVOUCHER 、 GIFTCARD 、 POINTCARD 的channel_application 指向 WALLET_PASS 的 channel_application
|
|
252
|
-
payMethods = payMethods.filter(method => method.status === 1 && method.disable === 0);
|
|
253
|
-
const walletPassMethod = payMethods.find(method => method.code === 'WALLET_PASS');
|
|
254
|
-
if (walletPassMethod) {
|
|
255
|
-
payMethods.forEach(method => {
|
|
256
|
-
if (method.code === 'PRODUCTVOUCHER' || method.code === 'GIFTCARD' || method.code === 'POINTCARD') {
|
|
257
|
-
method.channel_application = walletPassMethod.channel_application;
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
} else {
|
|
261
|
-
payMethods = payMethods.filter(method => method.code !== 'PRODUCTVOUCHER' && method.code !== 'GIFTCARD' && method.code !== 'POINTCARD');
|
|
262
|
-
}
|
|
263
|
-
return payMethods;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
221
|
/**
|
|
267
222
|
* 获取支付方式列表
|
|
268
223
|
*/
|
|
269
224
|
async getPayMethodListAsync() {
|
|
270
|
-
this.logInfo(
|
|
225
|
+
this.logInfo("Starting getPayMethodListAsync");
|
|
271
226
|
try {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// 如果有缓存,先返回缓存数据
|
|
281
|
-
const hasCache = cachedMethods.length > 0;
|
|
282
|
-
if (hasCache) {
|
|
283
|
-
// 后台异步获取最新数据
|
|
284
|
-
this.refreshPaymentMethodsInBackground(cachedMethods);
|
|
285
|
-
return cachedMethods;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// 没有缓存时,直接从服务器获取
|
|
289
|
-
const response = await this.request.get('/pay/custom-payment/all');
|
|
290
|
-
response.data = this.filterPayMethods(response.data);
|
|
291
|
-
const payMethods = response.data || [];
|
|
292
|
-
|
|
293
|
-
// 尝试缓存到 IndexDB
|
|
294
|
-
try {
|
|
295
|
-
for (const method of payMethods) {
|
|
296
|
-
await this.dbManager.update('pay_method', method);
|
|
297
|
-
}
|
|
298
|
-
} catch (dbError) {
|
|
299
|
-
console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
|
|
300
|
-
}
|
|
301
|
-
await this.core.effects.emit(`${this.name}:onPaymentMethodsLoaded`, payMethods);
|
|
302
|
-
this.logInfo('getPayMethodListAsync completed successfully', {
|
|
227
|
+
const response = await this.request.get("/pay/custom-payment/all", {
|
|
228
|
+
filterPaymentMethods: true
|
|
229
|
+
}, {
|
|
230
|
+
osServer: true
|
|
231
|
+
});
|
|
232
|
+
const payMethods = (response == null ? void 0 : response.data) || response || [];
|
|
233
|
+
this.logInfo("getPayMethodListAsync completed successfully", {
|
|
303
234
|
payMethods
|
|
304
235
|
});
|
|
305
236
|
return payMethods;
|
|
306
237
|
} catch (error) {
|
|
307
|
-
console.error(
|
|
308
|
-
this.logError(
|
|
309
|
-
// 如果所有操作都失败,返回空数组
|
|
238
|
+
console.error("[PaymentModule] 获取支付方式列表失败", error);
|
|
239
|
+
this.logError("getPayMethodListAsync failed", error);
|
|
310
240
|
return [];
|
|
311
241
|
}
|
|
312
242
|
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* 后台刷新支付方式列表
|
|
316
|
-
*/
|
|
317
|
-
async refreshPaymentMethodsInBackground(cachedMethods) {
|
|
318
|
-
this.logInfo('Starting refreshPaymentMethodsInBackground', {
|
|
319
|
-
cachedMethodsCount: cachedMethods.length
|
|
320
|
-
});
|
|
321
|
-
try {
|
|
322
|
-
// 从服务器获取最新数据
|
|
323
|
-
const response = await this.request.get('/pay/custom-payment/all');
|
|
324
|
-
response.data = this.filterPayMethods(response.data);
|
|
325
|
-
const newPayMethods = response.data || [];
|
|
326
|
-
|
|
327
|
-
// 检查是否有变化
|
|
328
|
-
const hasChanges = this.hasPaymentMethodsChanged(cachedMethods, newPayMethods);
|
|
329
|
-
if (hasChanges) {
|
|
330
|
-
this.logInfo('Payment methods updated in background', {
|
|
331
|
-
oldCount: cachedMethods.length,
|
|
332
|
-
newCount: newPayMethods.length
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
// 更新缓存
|
|
336
|
-
try {
|
|
337
|
-
// 先清除旧数据
|
|
338
|
-
for (const method of cachedMethods) {
|
|
339
|
-
await this.dbManager.delete('pay_method', method.id);
|
|
340
|
-
}
|
|
341
|
-
// 添加新数据
|
|
342
|
-
for (const method of newPayMethods) {
|
|
343
|
-
await this.dbManager.update('pay_method', method);
|
|
344
|
-
}
|
|
345
|
-
} catch (dbError) {
|
|
346
|
-
console.warn('[PaymentModule] 无法更新支付方式缓存', dbError);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// 通知外部支付方式已变化
|
|
350
|
-
const eventData = {
|
|
351
|
-
oldMethods: cachedMethods,
|
|
352
|
-
newMethods: newPayMethods
|
|
353
|
-
};
|
|
354
|
-
await this.core.effects.emit(`${this.name}:onPaymentMethodsChanged`, eventData);
|
|
355
|
-
} else {}
|
|
356
|
-
} catch (error) {
|
|
357
|
-
console.error('[PaymentModule] 后台刷新支付方式失败', error);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* 检查支付方式列表是否有变化
|
|
363
|
-
*/
|
|
364
|
-
hasPaymentMethodsChanged(oldMethods, newMethods) {
|
|
365
|
-
if (oldMethods.length !== newMethods.length) {
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// 创建旧数据的 Map 便于查找
|
|
370
|
-
const oldMethodsMap = new Map(oldMethods.map(method => [method.id, method]));
|
|
371
|
-
|
|
372
|
-
// 检查每个新方法是否与旧方法相同
|
|
373
|
-
for (const newMethod of newMethods) {
|
|
374
|
-
const oldMethod = oldMethodsMap.get(newMethod.id);
|
|
375
|
-
if (!oldMethod) {
|
|
376
|
-
return true; // 新增方法
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// 检查关键字段是否有变化
|
|
380
|
-
if (oldMethod.code !== newMethod.code || oldMethod.name !== newMethod.name || oldMethod.type !== newMethod.type || oldMethod.description !== newMethod.description || oldMethod.status !== newMethod.status || oldMethod.disable !== newMethod.disable || oldMethod.is_surcharge !== newMethod.is_surcharge || oldMethod.fixed !== newMethod.fixed || oldMethod.percentage !== newMethod.percentage || oldMethod.enabled !== newMethod.enabled || JSON.stringify(oldMethod.channel_application || []) !== JSON.stringify(newMethod.channel_application || []) || JSON.stringify(oldMethod.companies || []) !== JSON.stringify(newMethod.companies || []) || JSON.stringify(oldMethod.metadata || {}) !== JSON.stringify(newMethod.metadata || {})) {
|
|
381
|
-
return true; // 方法属性有变化
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
243
|
/**
|
|
388
244
|
* 获取订单列表
|
|
389
245
|
*/
|
|
246
|
+
/** @deprecated */
|
|
390
247
|
async getOrderListAsync() {
|
|
391
248
|
try {
|
|
392
|
-
return await this.dbManager.getAll(
|
|
249
|
+
return await this.dbManager.getAll("order");
|
|
393
250
|
} catch (error) {
|
|
394
|
-
console.error(
|
|
251
|
+
console.error("[PaymentModule] 获取订单列表失败", error);
|
|
395
252
|
return [];
|
|
396
253
|
}
|
|
397
254
|
}
|
|
398
|
-
|
|
399
255
|
/**
|
|
400
256
|
* 根据订单UUID获取支付订单(新方法)
|
|
401
257
|
*/
|
|
402
258
|
async getPaymentOrderByUuidAsync(orderUuid) {
|
|
403
259
|
try {
|
|
404
|
-
return await this.dbManager.get(
|
|
260
|
+
return await this.dbManager.get("order", orderUuid, true);
|
|
405
261
|
} catch (error) {
|
|
406
|
-
console.error(
|
|
262
|
+
console.error("[PaymentModule] 获取支付订单失败", error);
|
|
407
263
|
return null;
|
|
408
264
|
}
|
|
409
265
|
}
|
|
410
|
-
|
|
411
266
|
/**
|
|
412
267
|
* 创建支付订单(新方法,专注支付数据)
|
|
413
268
|
*/
|
|
414
269
|
async createPaymentOrderAsync(params) {
|
|
415
|
-
this.logInfo(
|
|
270
|
+
this.logInfo("Starting createPaymentOrderAsync", {
|
|
416
271
|
orderId: params.order_id,
|
|
417
272
|
totalAmount: params.total_amount
|
|
418
273
|
});
|
|
419
274
|
try {
|
|
420
|
-
// 检测是否有重复的 order_id
|
|
421
|
-
// console.time('createLocalOrderAsync: getExistingOrder')
|
|
422
|
-
// const existingOrder = await this.dbManager.get('order', params.order_id);
|
|
423
|
-
// const existingOrders = await this.dbManager.getAll('order');
|
|
424
|
-
// const existingOrder = existingOrders.find(
|
|
425
|
-
// (order: PaymentOrder) => String(order.id) === String(params.order_id),
|
|
426
|
-
// );
|
|
427
|
-
|
|
428
|
-
// this.logInfo('createPaymentOrderAsync existingOrder', {
|
|
429
|
-
// existingOrder
|
|
430
|
-
// });
|
|
431
|
-
// console.timeEnd('createLocalOrderAsync: getExistingOrder')
|
|
432
|
-
// const existingOrder = existingOrders.find(
|
|
433
|
-
// (order: PaymentOrder) => String(order.id) === String(params.order_id),
|
|
434
|
-
// );
|
|
435
|
-
|
|
436
|
-
// if (existingOrder) {
|
|
437
|
-
// // 如果存在相同 order_id 的订单,更新该订单信息
|
|
438
|
-
// this.logInfo(
|
|
439
|
-
// `createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`,
|
|
440
|
-
// );
|
|
441
|
-
|
|
442
|
-
// // const originalOrder = { ...existingOrder };
|
|
443
|
-
// existingOrder.order_info = params.order_info;
|
|
444
|
-
// existingOrder.total_amount = params.total_amount;
|
|
445
|
-
// existingOrder.is_deposit = params.is_deposit || 0;
|
|
446
|
-
// existingOrder.deposit_amount = params.deposit_amount || '0.00';
|
|
447
|
-
|
|
448
|
-
// // 重新计算待付金额
|
|
449
|
-
// this.recalculateOrderAmount(existingOrder);
|
|
450
|
-
|
|
451
|
-
// // 更新到数据库
|
|
452
|
-
// await this.dbManager.update('order', existingOrder);
|
|
453
|
-
|
|
454
|
-
// // 触发更新事件
|
|
455
|
-
// this.core.effects.emit(
|
|
456
|
-
// `${this.name}:onOrderUpdated`,
|
|
457
|
-
// existingOrder,
|
|
458
|
-
// );
|
|
459
|
-
|
|
460
|
-
// return existingOrder;
|
|
461
|
-
// } else {
|
|
462
|
-
// 创建新的支付订单
|
|
463
275
|
const newOrder = {
|
|
464
|
-
uuid: (0,
|
|
276
|
+
uuid: (0, import_utils.getUniqueId)("pay_order_"),
|
|
465
277
|
id: params.order_id,
|
|
466
278
|
order_id: params.order_id,
|
|
467
279
|
order_info: params.order_info,
|
|
468
|
-
payment_status:
|
|
280
|
+
payment_status: import_types.PaymentStatus.Processing,
|
|
469
281
|
payment: [],
|
|
470
282
|
adjust_offline_payments: [],
|
|
471
283
|
total_amount: params.total_amount,
|
|
472
284
|
expect_amount: params.total_amount,
|
|
473
|
-
tax_fee:
|
|
285
|
+
tax_fee: "0.00",
|
|
474
286
|
is_deposit: params.is_deposit || 0,
|
|
475
|
-
deposit_amount: params.deposit_amount ||
|
|
287
|
+
deposit_amount: params.deposit_amount || "0.00"
|
|
476
288
|
};
|
|
477
|
-
|
|
478
|
-
// 🔧 新增: 处理云端已存在的支付项
|
|
479
289
|
if (params.existPayment && params.existPayment.length > 0) {
|
|
480
|
-
const currentTime = formatDateTime(new Date());
|
|
481
|
-
newOrder.payment = params.existPayment.map(payment => ({
|
|
290
|
+
const currentTime = formatDateTime(/* @__PURE__ */ new Date());
|
|
291
|
+
newOrder.payment = params.existPayment.map((payment) => ({
|
|
482
292
|
...payment,
|
|
483
293
|
isSynced: true,
|
|
484
294
|
// 标记为已同步
|
|
485
|
-
status: payment.status ||
|
|
295
|
+
status: payment.status || "active",
|
|
486
296
|
// 如果云端支付项已有时间戳,则保留;否则使用当前时间
|
|
487
297
|
created_at: payment.created_at || currentTime,
|
|
488
298
|
updated_at: payment.updated_at || currentTime
|
|
489
299
|
}));
|
|
490
|
-
|
|
491
|
-
// 重新计算待付金额
|
|
492
300
|
this.recalculateOrderAmount(newOrder);
|
|
493
|
-
this.logInfo(
|
|
301
|
+
this.logInfo("创建订单时包含云端支付项", {
|
|
494
302
|
orderId: params.order_id,
|
|
495
303
|
existPaymentCount: params.existPayment.length,
|
|
496
304
|
totalAmount: newOrder.total_amount,
|
|
497
305
|
expectAmount: newOrder.expect_amount,
|
|
498
|
-
paymentDetails: params.existPayment.map(p => ({
|
|
306
|
+
paymentDetails: params.existPayment.map((p) => ({
|
|
499
307
|
uuid: p.uuid,
|
|
500
308
|
code: p.code,
|
|
501
309
|
amount: p.amount,
|
|
@@ -505,75 +313,67 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
505
313
|
}))
|
|
506
314
|
});
|
|
507
315
|
}
|
|
508
|
-
|
|
509
|
-
// 🚀 性能监控:记录数据库添加操作耗时
|
|
510
316
|
const dbAddStartTime = Date.now();
|
|
511
|
-
await this.dbManager.add(
|
|
317
|
+
await this.dbManager.add("order", newOrder, true);
|
|
512
318
|
const dbAddDuration = Date.now() - dbAddStartTime;
|
|
513
|
-
this.logInfo(
|
|
514
|
-
operation:
|
|
515
|
-
table:
|
|
319
|
+
this.logInfo("Database add operation completed", {
|
|
320
|
+
operation: "dbManager.add",
|
|
321
|
+
table: "order",
|
|
516
322
|
orderUuid: newOrder.uuid,
|
|
517
323
|
orderId: newOrder.order_id,
|
|
518
324
|
duration: `${dbAddDuration}ms`,
|
|
519
|
-
performance: dbAddDuration > 100 ?
|
|
325
|
+
performance: dbAddDuration > 100 ? "slow" : dbAddDuration > 50 ? "medium" : "fast"
|
|
520
326
|
});
|
|
521
327
|
setTimeout(() => {
|
|
522
328
|
this.core.effects.emit(`${this.name}:onOrderAdded`, newOrder);
|
|
523
329
|
}, 0);
|
|
524
330
|
return newOrder;
|
|
525
|
-
// }
|
|
526
331
|
} catch (error) {
|
|
527
|
-
console.error(
|
|
528
|
-
this.logError(
|
|
332
|
+
console.error("[PaymentModule] 创建支付订单失败", error);
|
|
333
|
+
this.logError("createPaymentOrderAsync failed", error, {
|
|
529
334
|
orderId: params.order_id
|
|
530
335
|
});
|
|
531
336
|
throw error;
|
|
532
337
|
}
|
|
533
338
|
}
|
|
534
|
-
|
|
535
339
|
/**
|
|
536
340
|
* 删除支付订单(新方法)
|
|
537
341
|
*/
|
|
538
342
|
async deletePaymentOrderAsync(orderUuid) {
|
|
539
343
|
try {
|
|
540
|
-
const order = await this.dbManager.get(
|
|
344
|
+
const order = await this.dbManager.get("order", orderUuid);
|
|
541
345
|
if (order) {
|
|
542
|
-
await this.dbManager.delete(
|
|
346
|
+
await this.dbManager.delete("order", orderUuid);
|
|
543
347
|
await this.core.effects.emit(`${this.name}:onOrderDeleted`, order);
|
|
348
|
+
console.log("[PaymentModule] 支付订单删除成功:", orderUuid);
|
|
544
349
|
}
|
|
545
350
|
} catch (error) {
|
|
546
|
-
console.error(
|
|
351
|
+
console.error("[PaymentModule] 删除支付订单失败", error);
|
|
547
352
|
throw error;
|
|
548
353
|
}
|
|
549
354
|
}
|
|
550
|
-
|
|
551
355
|
/**
|
|
552
356
|
* 更新订单
|
|
553
357
|
*/
|
|
554
358
|
async updateOrderAsync(orderUuid, params) {
|
|
555
359
|
try {
|
|
556
|
-
const order = await this.dbManager.get(
|
|
360
|
+
const order = await this.dbManager.get("order", orderUuid);
|
|
557
361
|
if (order) {
|
|
558
|
-
const updatedOrder = {
|
|
559
|
-
...order,
|
|
560
|
-
...params
|
|
561
|
-
};
|
|
362
|
+
const updatedOrder = { ...order, ...params };
|
|
562
363
|
this.recalculateOrderAmount(updatedOrder);
|
|
563
|
-
await this.dbManager.update(
|
|
364
|
+
await this.dbManager.update("order", updatedOrder);
|
|
564
365
|
await this.core.effects.emit(`${this.name}:onOrderUpdated`, updatedOrder);
|
|
565
366
|
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
566
|
-
action:
|
|
367
|
+
action: "update",
|
|
567
368
|
order: updatedOrder,
|
|
568
369
|
originalOrder: order
|
|
569
370
|
});
|
|
570
371
|
}
|
|
571
372
|
} catch (error) {
|
|
572
|
-
console.error(
|
|
373
|
+
console.error("[PaymentModule] 更新订单失败", error);
|
|
573
374
|
throw error;
|
|
574
375
|
}
|
|
575
376
|
}
|
|
576
|
-
|
|
577
377
|
/**
|
|
578
378
|
* 基于UUID替换订单ID
|
|
579
379
|
*
|
|
@@ -585,35 +385,28 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
585
385
|
* @returns 更新后的订单对象,如果订单不存在则返回null
|
|
586
386
|
*/
|
|
587
387
|
async replaceOrderIdByUuidAsync(orderUuid, newOrderId) {
|
|
588
|
-
this.logInfo(
|
|
388
|
+
this.logInfo("Starting replaceOrderIdByUuidAsync", {
|
|
589
389
|
orderUuid,
|
|
590
390
|
newOrderId
|
|
591
391
|
});
|
|
592
392
|
try {
|
|
593
|
-
|
|
594
|
-
const existingOrder = await this.dbManager.get('order', orderUuid);
|
|
393
|
+
const existingOrder = await this.dbManager.get("order", orderUuid);
|
|
595
394
|
if (!existingOrder) {
|
|
596
|
-
this.logWarning(
|
|
597
|
-
orderUuid
|
|
598
|
-
});
|
|
395
|
+
this.logWarning("Order not found for UUID replacement", { orderUuid });
|
|
599
396
|
return null;
|
|
600
397
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
398
|
+
const allOrders = await this.dbManager.getAll("order");
|
|
399
|
+
const duplicateOrder = allOrders.find(
|
|
400
|
+
(order) => String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid
|
|
401
|
+
);
|
|
605
402
|
if (duplicateOrder) {
|
|
606
|
-
this.logWarning(
|
|
403
|
+
this.logWarning("New order ID already exists", {
|
|
607
404
|
newOrderId,
|
|
608
405
|
existingOrderUuid: duplicateOrder.uuid
|
|
609
406
|
});
|
|
610
407
|
throw new Error(`订单ID ${newOrderId} 已存在`);
|
|
611
408
|
}
|
|
612
|
-
|
|
613
|
-
// 保存原始订单ID用于日志
|
|
614
409
|
const originalOrderId = existingOrder.id;
|
|
615
|
-
|
|
616
|
-
// 更新订单ID
|
|
617
410
|
const updatedOrder = {
|
|
618
411
|
...existingOrder,
|
|
619
412
|
id: newOrderId,
|
|
@@ -624,17 +417,13 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
624
417
|
order_id: newOrderId,
|
|
625
418
|
// 保留原始本地订单ID作为参考
|
|
626
419
|
original_local_order_id: originalOrderId,
|
|
627
|
-
updated_at: new Date().toISOString()
|
|
420
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
628
421
|
}
|
|
629
422
|
};
|
|
630
|
-
|
|
631
|
-
// 更新到数据库
|
|
632
|
-
await this.dbManager.update('order', updatedOrder);
|
|
633
|
-
|
|
634
|
-
// 触发事件
|
|
423
|
+
await this.dbManager.update("order", updatedOrder);
|
|
635
424
|
await this.core.effects.emit(`${this.name}:onOrderUpdated`, updatedOrder);
|
|
636
425
|
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
637
|
-
action:
|
|
426
|
+
action: "order_id_replaced",
|
|
638
427
|
order: updatedOrder,
|
|
639
428
|
originalOrder: existingOrder,
|
|
640
429
|
metadata: {
|
|
@@ -642,22 +431,22 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
642
431
|
newOrderId
|
|
643
432
|
}
|
|
644
433
|
});
|
|
645
|
-
this.logInfo(
|
|
434
|
+
this.logInfo("Order ID replacement completed successfully", {
|
|
646
435
|
orderUuid,
|
|
647
436
|
originalOrderId,
|
|
648
437
|
newOrderId
|
|
649
438
|
});
|
|
439
|
+
console.log(`[PaymentModule] 订单ID替换成功: ${originalOrderId} → ${newOrderId}`);
|
|
650
440
|
return updatedOrder;
|
|
651
441
|
} catch (error) {
|
|
652
|
-
console.error(
|
|
653
|
-
this.logError(
|
|
442
|
+
console.error("[PaymentModule] 替换订单ID失败", error);
|
|
443
|
+
this.logError("replaceOrderIdByUuidAsync failed", error, {
|
|
654
444
|
orderUuid,
|
|
655
445
|
newOrderId
|
|
656
446
|
});
|
|
657
447
|
throw error;
|
|
658
448
|
}
|
|
659
449
|
}
|
|
660
|
-
|
|
661
450
|
/**
|
|
662
451
|
* 获取支付项(新方法)
|
|
663
452
|
*
|
|
@@ -667,18 +456,15 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
667
456
|
*/
|
|
668
457
|
async getPaymentItemsAsync(orderUuid, includeVoided = false) {
|
|
669
458
|
if (!orderUuid) {
|
|
670
|
-
throw new Error(
|
|
459
|
+
throw new Error("orderUuid is required");
|
|
671
460
|
}
|
|
672
461
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
673
|
-
const allPayments = order
|
|
462
|
+
const allPayments = (order == null ? void 0 : order.payment) || [];
|
|
674
463
|
if (includeVoided) {
|
|
675
464
|
return allPayments;
|
|
676
465
|
}
|
|
677
|
-
|
|
678
|
-
// 默认只返回活跃的支付项
|
|
679
|
-
return allPayments.filter(payment => payment.status !== 'voided');
|
|
466
|
+
return allPayments.filter((payment) => payment.status !== "voided");
|
|
680
467
|
}
|
|
681
|
-
|
|
682
468
|
/**
|
|
683
469
|
* 获取所有支付项(包括已撤销的)
|
|
684
470
|
*
|
|
@@ -688,51 +474,47 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
688
474
|
async getAllPaymentItemsAsync(orderUuid) {
|
|
689
475
|
return this.getPaymentItemsAsync(orderUuid, true);
|
|
690
476
|
}
|
|
691
|
-
|
|
692
477
|
/**
|
|
693
478
|
* 为某个订单添加支付项(新方法)
|
|
694
479
|
*/
|
|
695
480
|
async addPaymentItemAsync(orderUuid, paymentItem) {
|
|
696
|
-
|
|
481
|
+
var _a, _b, _c, _d;
|
|
482
|
+
this.logInfo("Starting addPaymentItemAsync", {
|
|
697
483
|
orderUuid,
|
|
698
484
|
paymentAmount: paymentItem.amount,
|
|
699
485
|
paymentCode: paymentItem.code,
|
|
700
486
|
orderPaymentType: paymentItem.order_payment_type
|
|
701
487
|
});
|
|
702
488
|
try {
|
|
703
|
-
this.logInfo(
|
|
489
|
+
this.logInfo("准备获取订单", {
|
|
704
490
|
orderUuid
|
|
705
491
|
});
|
|
706
492
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
707
|
-
this.logInfo(
|
|
493
|
+
this.logInfo("获取订单信息成功", {
|
|
708
494
|
orderUuid,
|
|
709
495
|
order
|
|
710
496
|
});
|
|
711
497
|
if (!order) {
|
|
712
498
|
throw new Error(`Order not found: ${orderUuid}`);
|
|
713
499
|
}
|
|
714
|
-
|
|
715
|
-
// 🔒 支付锁检查:如果订单待付金额已经为0,不允许继续添加支付项
|
|
716
|
-
const expectAmount = new _decimal.Decimal(order.expect_amount);
|
|
500
|
+
const expectAmount = new import_decimal.Decimal(order.expect_amount);
|
|
717
501
|
const paidDepositAmount = order.payment.reduce((sum, payment) => {
|
|
718
|
-
if (payment.order_payment_type ===
|
|
719
|
-
return sum.plus(new
|
|
502
|
+
if (payment.order_payment_type === "deposit" && payment.status !== "voided") {
|
|
503
|
+
return sum.plus(new import_decimal.Decimal(payment.amount));
|
|
720
504
|
}
|
|
721
505
|
return sum;
|
|
722
|
-
}, new
|
|
723
|
-
const expectedDepositAmount = new
|
|
724
|
-
|
|
725
|
-
// 有一种特殊情况,订单金额为 0,但是定金金额>0,且此时是定金状态的,允许添加支付项
|
|
506
|
+
}, new import_decimal.Decimal(0));
|
|
507
|
+
const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
|
|
726
508
|
if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
|
|
727
509
|
const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
|
|
728
|
-
console.warn(
|
|
510
|
+
console.warn("[PaymentModule] Payment lock triggered:", {
|
|
729
511
|
orderUuid,
|
|
730
512
|
expectAmount: order.expect_amount,
|
|
731
513
|
attemptedPaymentAmount: paymentItem.amount,
|
|
732
514
|
attemptedPaymentCode: paymentItem.code,
|
|
733
|
-
reason:
|
|
515
|
+
reason: "Order already fully paid"
|
|
734
516
|
});
|
|
735
|
-
this.logError(
|
|
517
|
+
this.logError("addPaymentItemAsync blocked by payment lock", new Error(warningMessage), {
|
|
736
518
|
orderUuid,
|
|
737
519
|
expectAmount: order.expect_amount,
|
|
738
520
|
paymentItem
|
|
@@ -740,134 +522,129 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
740
522
|
throw new Error(warningMessage);
|
|
741
523
|
}
|
|
742
524
|
let paymentUuid;
|
|
743
|
-
if (paymentItem.metadata
|
|
525
|
+
if ((_a = paymentItem.metadata) == null ? void 0 : _a.unique_payment_number) {
|
|
744
526
|
paymentUuid = paymentItem.metadata.unique_payment_number;
|
|
745
527
|
} else {
|
|
746
|
-
paymentUuid = (0,
|
|
528
|
+
paymentUuid = (0, import_utils.getUniqueId)("payment_");
|
|
747
529
|
}
|
|
748
|
-
const currentTime = formatDateTime(new Date());
|
|
530
|
+
const currentTime = formatDateTime(/* @__PURE__ */ new Date());
|
|
749
531
|
const newPaymentItem = {
|
|
750
532
|
uuid: paymentUuid,
|
|
751
|
-
custom_payment_id: paymentItem
|
|
533
|
+
custom_payment_id: normalizeCustomPaymentId(paymentItem),
|
|
752
534
|
name: paymentItem.name,
|
|
753
535
|
code: paymentItem.code,
|
|
754
536
|
type: paymentItem.type,
|
|
755
537
|
amount: formatAmount(paymentItem.amount),
|
|
756
|
-
voucher_id: paymentItem.voucher_id ||
|
|
757
|
-
|
|
538
|
+
voucher_id: paymentItem.voucher_id || "",
|
|
539
|
+
wallet_pass_usage_unit: paymentItem.wallet_pass_usage_unit,
|
|
540
|
+
wallet_pass_use_value: paymentItem.wallet_pass_use_value,
|
|
541
|
+
rounding_amount: paymentItem.rounding_amount || "0.00",
|
|
758
542
|
service_charge: paymentItem.service_charge,
|
|
759
|
-
status:
|
|
543
|
+
status: "active",
|
|
760
544
|
// 新支付项默认为活跃状态
|
|
761
|
-
order_payment_type: paymentItem.order_payment_type ||
|
|
545
|
+
order_payment_type: paymentItem.order_payment_type || "normal",
|
|
762
546
|
// 默认为正常支付
|
|
763
547
|
created_at: currentTime,
|
|
764
548
|
// 创建时间
|
|
765
549
|
updated_at: currentTime,
|
|
766
550
|
// 更新时间
|
|
767
|
-
wallet_pass_usage_unit: paymentItem?.wallet_pass_usage_unit,
|
|
768
|
-
wallet_pass_use_value: paymentItem?.wallet_pass_use_value,
|
|
769
551
|
metadata: {
|
|
770
552
|
...paymentItem.metadata,
|
|
771
553
|
// 保留传入的所有 metadata 字段
|
|
772
|
-
unique_payment_number: paymentUuid
|
|
554
|
+
unique_payment_number: paymentUuid
|
|
555
|
+
// 设置唯一支付号为支付项的 uuid
|
|
773
556
|
}
|
|
774
557
|
};
|
|
775
558
|
order.payment.push(newPaymentItem);
|
|
776
559
|
this.recalculateOrderAmount(order);
|
|
777
|
-
this.logInfo(
|
|
560
|
+
this.logInfo("开始更新订单支付项", {
|
|
778
561
|
orderUuid,
|
|
779
562
|
order
|
|
780
563
|
});
|
|
781
|
-
await this.dbManager.update(
|
|
782
|
-
this.logInfo(
|
|
564
|
+
await this.dbManager.update("order", order, true);
|
|
565
|
+
this.logInfo("更新订单支付项完成", {
|
|
783
566
|
orderUuid
|
|
784
567
|
});
|
|
785
568
|
this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
786
569
|
orderUuid,
|
|
787
570
|
payment: newPaymentItem
|
|
788
571
|
});
|
|
789
|
-
this.logInfo(
|
|
572
|
+
this.logInfo("addPaymentItemAsync completed successfully", {
|
|
790
573
|
orderUuid,
|
|
791
574
|
paymentUuid: newPaymentItem.uuid,
|
|
792
|
-
uniquePaymentNumber: newPaymentItem.metadata
|
|
575
|
+
uniquePaymentNumber: (_b = newPaymentItem.metadata) == null ? void 0 : _b.unique_payment_number,
|
|
793
576
|
newExpectAmount: order.expect_amount,
|
|
794
577
|
paymentAmount: newPaymentItem.amount,
|
|
795
578
|
paymentCode: newPaymentItem.code,
|
|
796
579
|
orderPaymentType: newPaymentItem.order_payment_type,
|
|
797
580
|
metadataFields: Object.keys(newPaymentItem.metadata || {}),
|
|
798
581
|
// 现金支付找零信息
|
|
799
|
-
actualPaidAmount: newPaymentItem.metadata
|
|
800
|
-
changeGivenAmount: newPaymentItem.metadata
|
|
582
|
+
actualPaidAmount: (_c = newPaymentItem.metadata) == null ? void 0 : _c.actual_paid_amount,
|
|
583
|
+
changeGivenAmount: (_d = newPaymentItem.metadata) == null ? void 0 : _d.change_given_amount
|
|
801
584
|
});
|
|
802
585
|
} catch (error) {
|
|
803
|
-
console.error(
|
|
804
|
-
this.logError(
|
|
586
|
+
console.error("[PaymentModule] 添加支付项失败", error);
|
|
587
|
+
this.logError("addPaymentItemAsync failed", error, {
|
|
805
588
|
orderUuid,
|
|
806
589
|
paymentItem
|
|
807
590
|
});
|
|
808
591
|
throw error;
|
|
809
592
|
}
|
|
810
593
|
}
|
|
811
|
-
|
|
812
594
|
/**
|
|
813
595
|
* 删除一个支付项 - 标记删除而非物理删除
|
|
814
596
|
*/
|
|
815
597
|
async deletePaymentAsync(orderUuid, paymentUuid) {
|
|
816
|
-
this.logInfo(
|
|
817
|
-
orderUuid,
|
|
818
|
-
paymentUuid
|
|
819
|
-
});
|
|
598
|
+
this.logInfo("Starting deletePaymentAsync (mark as voided)", { orderUuid, paymentUuid });
|
|
820
599
|
try {
|
|
821
|
-
const order = await this.dbManager.get(
|
|
600
|
+
const order = await this.dbManager.get("order", orderUuid);
|
|
822
601
|
if (!order) {
|
|
823
|
-
throw new Error(
|
|
602
|
+
throw new Error("订单不存在");
|
|
824
603
|
}
|
|
825
|
-
const paymentItem = order.payment.find(
|
|
604
|
+
const paymentItem = order.payment.find(
|
|
605
|
+
(payment) => payment.uuid === paymentUuid
|
|
606
|
+
);
|
|
826
607
|
if (!paymentItem) {
|
|
827
608
|
throw new Error(`支付项不存在: ${paymentUuid}`);
|
|
828
609
|
}
|
|
829
|
-
|
|
830
|
-
// 检查是否已经被删除(撤销)
|
|
831
|
-
if (paymentItem.status === 'voided') {
|
|
610
|
+
if (paymentItem.status === "voided") {
|
|
832
611
|
console.warn(`[PaymentModule] 支付项 ${paymentUuid} 已经被删除,跳过操作`);
|
|
833
612
|
return;
|
|
834
613
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
paymentItem.
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
614
|
+
paymentItem.status = "voided";
|
|
615
|
+
paymentItem.origin_amount = paymentItem.amount;
|
|
616
|
+
paymentItem.amount = "0.00";
|
|
617
|
+
console.log(`[PaymentModule] 支付项标记为删除:`, {
|
|
618
|
+
uuid: paymentItem.uuid,
|
|
619
|
+
originalAmount: paymentItem.origin_amount,
|
|
620
|
+
status: paymentItem.status
|
|
621
|
+
});
|
|
842
622
|
this.recalculateOrderAmount(order);
|
|
843
|
-
|
|
844
|
-
// 更新到 IndexDB
|
|
845
|
-
await this.dbManager.update('order', order);
|
|
623
|
+
await this.dbManager.update("order", order);
|
|
846
624
|
await this.core.effects.emit(`${this.name}:onPaymentDeleted`, {
|
|
847
625
|
order,
|
|
848
|
-
paymentItem
|
|
626
|
+
paymentItem
|
|
849
627
|
});
|
|
850
628
|
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
851
|
-
action:
|
|
629
|
+
action: "payment_delete",
|
|
852
630
|
order,
|
|
853
|
-
paymentItem
|
|
631
|
+
paymentItem
|
|
854
632
|
});
|
|
855
|
-
this.logInfo(
|
|
633
|
+
this.logInfo("deletePaymentAsync completed successfully (marked as voided)", {
|
|
856
634
|
orderUuid,
|
|
857
635
|
paymentUuid,
|
|
858
636
|
originalAmount: paymentItem.origin_amount,
|
|
859
637
|
newExpectAmount: order.expect_amount
|
|
860
638
|
});
|
|
861
639
|
} catch (error) {
|
|
862
|
-
console.error(
|
|
863
|
-
this.logError(
|
|
640
|
+
console.error("[PaymentModule] 删除支付项失败", error);
|
|
641
|
+
this.logError("deletePaymentAsync failed", error, {
|
|
864
642
|
orderUuid,
|
|
865
643
|
paymentUuid
|
|
866
644
|
});
|
|
867
645
|
throw error;
|
|
868
646
|
}
|
|
869
647
|
}
|
|
870
|
-
|
|
871
648
|
/**
|
|
872
649
|
* 批量更新代金券类支付项(覆盖更新)
|
|
873
650
|
*
|
|
@@ -876,16 +653,12 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
876
653
|
*/
|
|
877
654
|
async updateVoucherPaymentItemsAsync(orderUuid, voucherPaymentItems) {
|
|
878
655
|
return this.runVoucherUpdateLocked(orderUuid, async () => {
|
|
879
|
-
const {
|
|
880
|
-
|
|
881
|
-
originalCount,
|
|
882
|
-
normalizedCount
|
|
883
|
-
} = this.normalizeVoucherPaymentItems(voucherPaymentItems);
|
|
884
|
-
this.logInfo('Starting updateVoucherPaymentItemsAsync', {
|
|
656
|
+
const { items: normalizedVoucherItems, originalCount, normalizedCount } = this.normalizeVoucherPaymentItems(voucherPaymentItems);
|
|
657
|
+
this.logInfo("Starting updateVoucherPaymentItemsAsync", {
|
|
885
658
|
orderUuid,
|
|
886
659
|
originalVoucherCount: originalCount,
|
|
887
660
|
normalizedVoucherCount: normalizedCount,
|
|
888
|
-
voucherItems: normalizedVoucherItems.map(item => ({
|
|
661
|
+
voucherItems: normalizedVoucherItems.map((item) => ({
|
|
889
662
|
code: item.code,
|
|
890
663
|
amount: item.amount,
|
|
891
664
|
voucher_id: item.voucher_id,
|
|
@@ -893,7 +666,7 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
893
666
|
}))
|
|
894
667
|
});
|
|
895
668
|
if (originalCount !== normalizedCount) {
|
|
896
|
-
console.warn(
|
|
669
|
+
console.warn("[PaymentModule] voucherPaymentItems detected duplicates (deduped by voucher_id + order_payment_type)", {
|
|
897
670
|
orderUuid,
|
|
898
671
|
originalCount,
|
|
899
672
|
normalizedCount
|
|
@@ -904,52 +677,72 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
904
677
|
if (!order) {
|
|
905
678
|
throw new Error(`订单不存在: ${orderUuid}`);
|
|
906
679
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
680
|
+
const existingVoucherItems = order.payment.filter(
|
|
681
|
+
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
682
|
+
);
|
|
683
|
+
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
684
|
+
orderUuid,
|
|
685
|
+
existingVoucherCount: existingVoucherItems.length,
|
|
686
|
+
existingItems: existingVoucherItems.map((item) => ({
|
|
687
|
+
uuid: item.uuid,
|
|
688
|
+
code: item.code,
|
|
689
|
+
amount: item.amount,
|
|
690
|
+
voucher_id: item.voucher_id,
|
|
691
|
+
isSynced: item.isSynced
|
|
692
|
+
}))
|
|
693
|
+
});
|
|
912
694
|
for (const voucherItem of existingVoucherItems) {
|
|
695
|
+
console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
|
|
913
696
|
await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
914
697
|
}
|
|
915
|
-
|
|
916
|
-
// 3. 添加新的代金券支付项(幂等:如果已存在同 voucher_id + order_payment_type 的 active 项则跳过)
|
|
917
698
|
const orderAfterDelete = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
918
699
|
if (!orderAfterDelete) {
|
|
919
700
|
throw new Error(`订单不存在: ${orderUuid}`);
|
|
920
701
|
}
|
|
921
|
-
const existingActiveVoucherKeys = new Set(
|
|
702
|
+
const existingActiveVoucherKeys = new Set(
|
|
703
|
+
orderAfterDelete.payment.filter((p) => p.voucher_id && p.status !== "voided" && !p.isSynced).map((p) => `${p.voucher_id}|${p.order_payment_type || "normal"}`)
|
|
704
|
+
);
|
|
705
|
+
console.log("[PaymentModule] 添加新的代金券支付项:", {
|
|
706
|
+
orderUuid,
|
|
707
|
+
newItemCount: normalizedVoucherItems.length
|
|
708
|
+
});
|
|
922
709
|
for (const voucherItem of normalizedVoucherItems) {
|
|
923
|
-
const orderPaymentType = voucherItem.order_payment_type ||
|
|
710
|
+
const orderPaymentType = voucherItem.order_payment_type || "normal";
|
|
924
711
|
const key = `${voucherItem.voucher_id}|${orderPaymentType}`;
|
|
925
712
|
if (existingActiveVoucherKeys.has(key)) {
|
|
926
|
-
console.warn(
|
|
713
|
+
console.warn("[PaymentModule] Skip adding voucher payment item because it already exists (active)", {
|
|
927
714
|
orderUuid,
|
|
928
715
|
voucher_id: voucherItem.voucher_id,
|
|
929
716
|
order_payment_type: orderPaymentType
|
|
930
717
|
});
|
|
931
718
|
continue;
|
|
932
719
|
}
|
|
720
|
+
console.log(`[PaymentModule] 添加代金券支付项:`, {
|
|
721
|
+
...voucherItem,
|
|
722
|
+
code: voucherItem.code,
|
|
723
|
+
amount: voucherItem.amount,
|
|
724
|
+
voucher_id: voucherItem.voucher_id,
|
|
725
|
+
order_payment_type: orderPaymentType
|
|
726
|
+
});
|
|
933
727
|
await this.addPaymentItemAsync(orderUuid, voucherItem);
|
|
934
728
|
existingActiveVoucherKeys.add(key);
|
|
935
729
|
}
|
|
936
|
-
|
|
937
|
-
// 4. 触发支付项更新事件
|
|
938
730
|
const updatedOrder = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
939
731
|
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
940
732
|
orderUuid,
|
|
941
733
|
order: updatedOrder,
|
|
942
|
-
payment: null
|
|
734
|
+
payment: null
|
|
735
|
+
// 批量操作不提供单个支付项
|
|
943
736
|
});
|
|
944
|
-
this.logInfo(
|
|
737
|
+
this.logInfo("updateVoucherPaymentItemsAsync completed successfully", {
|
|
945
738
|
orderUuid,
|
|
946
739
|
removedVoucherCount: existingVoucherItems.length,
|
|
947
740
|
addedVoucherCount: normalizedVoucherItems.length,
|
|
948
|
-
finalExpectAmount: updatedOrder
|
|
741
|
+
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
949
742
|
});
|
|
950
743
|
} catch (error) {
|
|
951
|
-
console.error(
|
|
952
|
-
this.logError(
|
|
744
|
+
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
745
|
+
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
953
746
|
orderUuid,
|
|
954
747
|
voucherPaymentItems
|
|
955
748
|
});
|
|
@@ -957,94 +750,79 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
957
750
|
}
|
|
958
751
|
});
|
|
959
752
|
}
|
|
960
|
-
|
|
961
753
|
/**
|
|
962
754
|
* 更新一个支付项
|
|
963
755
|
*/
|
|
964
756
|
async updatePaymentAsync(orderUuid, paymentUuid, params) {
|
|
965
757
|
try {
|
|
966
|
-
const order = await this.dbManager.get(
|
|
758
|
+
const order = await this.dbManager.get("order", orderUuid);
|
|
967
759
|
if (!order) {
|
|
968
|
-
throw new Error(
|
|
760
|
+
throw new Error("订单不存在");
|
|
969
761
|
}
|
|
970
|
-
const paymentItem = order.payment.find(
|
|
762
|
+
const paymentItem = order.payment.find(
|
|
763
|
+
(payment) => payment.uuid === paymentUuid
|
|
764
|
+
);
|
|
971
765
|
if (paymentItem) {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
...params
|
|
975
|
-
};
|
|
976
|
-
if ('amount' in formattedParams && formattedParams.amount !== undefined) {
|
|
766
|
+
const formattedParams = { ...params };
|
|
767
|
+
if ("amount" in formattedParams && formattedParams.amount !== void 0) {
|
|
977
768
|
formattedParams.amount = formatAmount(formattedParams.amount);
|
|
978
769
|
}
|
|
979
770
|
Object.assign(paymentItem, formattedParams);
|
|
980
|
-
|
|
981
|
-
// 重新计算待付金额
|
|
982
771
|
this.recalculateOrderAmount(order);
|
|
983
|
-
|
|
984
|
-
// 更新到 IndexDB
|
|
985
|
-
await this.dbManager.update('order', order);
|
|
772
|
+
await this.dbManager.update("order", order);
|
|
986
773
|
await this.core.effects.emit(`${this.name}:onPaymentUpdated`, {
|
|
987
774
|
order,
|
|
988
775
|
paymentItem
|
|
989
776
|
});
|
|
990
777
|
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
991
|
-
action:
|
|
778
|
+
action: "payment_update",
|
|
992
779
|
order,
|
|
993
780
|
paymentItem
|
|
994
781
|
});
|
|
995
782
|
}
|
|
996
783
|
} catch (error) {
|
|
997
|
-
console.error(
|
|
784
|
+
console.error("[PaymentModule] 更新支付项失败", error);
|
|
998
785
|
throw error;
|
|
999
786
|
}
|
|
1000
787
|
}
|
|
1001
|
-
|
|
1002
788
|
/**
|
|
1003
789
|
* 提交支付
|
|
1004
790
|
*/
|
|
1005
791
|
async submitPayAsync(orderUuid) {
|
|
1006
|
-
this.logInfo(
|
|
1007
|
-
orderUuid
|
|
1008
|
-
});
|
|
792
|
+
this.logInfo("Starting submitPayAsync", { orderUuid });
|
|
1009
793
|
try {
|
|
1010
794
|
let orderToSubmit;
|
|
1011
795
|
if (orderUuid) {
|
|
1012
|
-
const order = await this.dbManager.get(
|
|
796
|
+
const order = await this.dbManager.get("order", orderUuid);
|
|
1013
797
|
orderToSubmit = order ? [order] : [];
|
|
1014
798
|
} else {
|
|
1015
|
-
const allOrders = await this.dbManager.getAll(
|
|
1016
|
-
|
|
1017
|
-
|
|
799
|
+
const allOrders = await this.dbManager.getAll("order");
|
|
800
|
+
orderToSubmit = allOrders.filter(
|
|
801
|
+
(order) => order.payment_status === import_types.PaymentStatus.Processing || order.payment_status === import_types.PaymentStatus.PartiallyPaid
|
|
802
|
+
);
|
|
1018
803
|
}
|
|
1019
804
|
for (const order of orderToSubmit) {
|
|
1020
805
|
await this.submitSingleOrderPayment(order);
|
|
1021
806
|
}
|
|
1022
|
-
const result = {
|
|
1023
|
-
|
|
1024
|
-
};
|
|
1025
|
-
this.logInfo('submitPayAsync completed', {
|
|
807
|
+
const result = { status: "success" };
|
|
808
|
+
this.logInfo("submitPayAsync completed", {
|
|
1026
809
|
result: result.status,
|
|
1027
810
|
processedOrdersCount: orderToSubmit.length
|
|
1028
811
|
});
|
|
1029
812
|
return result;
|
|
1030
813
|
} catch (error) {
|
|
1031
|
-
console.error(
|
|
1032
|
-
this.logError(
|
|
1033
|
-
|
|
1034
|
-
});
|
|
1035
|
-
return {
|
|
1036
|
-
status: 'failed'
|
|
1037
|
-
};
|
|
814
|
+
console.error("[PaymentModule] 提交支付失败", error);
|
|
815
|
+
this.logError("submitPayAsync failed", error, { orderUuid });
|
|
816
|
+
return { status: "failed" };
|
|
1038
817
|
}
|
|
1039
818
|
}
|
|
1040
|
-
|
|
1041
819
|
/**
|
|
1042
820
|
* 提交单个订单的支付(推送到任务队列)
|
|
1043
821
|
*/
|
|
1044
822
|
async submitSingleOrderPayment(order) {
|
|
1045
823
|
try {
|
|
1046
824
|
const paymentData = {
|
|
1047
|
-
payments: order.payment.map(payment => ({
|
|
825
|
+
payments: order.payment.map((payment) => ({
|
|
1048
826
|
uuid: payment.uuid,
|
|
1049
827
|
amount: payment.amount,
|
|
1050
828
|
code: payment.code,
|
|
@@ -1056,41 +834,37 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
1056
834
|
rounding_amount: payment.rounding_amount,
|
|
1057
835
|
service_charge: payment.service_charge
|
|
1058
836
|
})),
|
|
1059
|
-
payment_status:
|
|
837
|
+
payment_status: "pending"
|
|
1060
838
|
};
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
// 根据支付金额判断订单状态
|
|
839
|
+
const totalPaidAmount = paymentData.payments.reduce(
|
|
840
|
+
(sum, payment) => sum.plus(payment.amount),
|
|
841
|
+
new import_decimal.Decimal(0)
|
|
842
|
+
);
|
|
843
|
+
const orderTotalAmount = new import_decimal.Decimal(order.total_amount);
|
|
1067
844
|
if (totalPaidAmount.gte(orderTotalAmount)) {
|
|
1068
|
-
|
|
1069
|
-
|
|
845
|
+
order.payment_status = import_types.PaymentStatus.Finished;
|
|
846
|
+
console.log(
|
|
847
|
+
`[PaymentModule] 订单 ${order.uuid} 支付完成,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
848
|
+
);
|
|
1070
849
|
} else {
|
|
1071
|
-
|
|
1072
|
-
|
|
850
|
+
order.payment_status = import_types.PaymentStatus.PartiallyPaid;
|
|
851
|
+
console.log(
|
|
852
|
+
`[PaymentModule] 订单 ${order.uuid} 部分支付,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
853
|
+
);
|
|
1073
854
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
paymentData.payment_status = order.payment_status === _types.PaymentStatus.Finished ? 'paid' : 'partially_paid';
|
|
1077
|
-
|
|
1078
|
-
// 更新订单状态到数据库
|
|
1079
|
-
await this.dbManager.update('order', order);
|
|
1080
|
-
|
|
1081
|
-
// 检查支付列表是否为空
|
|
855
|
+
paymentData.payment_status = order.payment_status === import_types.PaymentStatus.Finished ? "paid" : "partially_paid";
|
|
856
|
+
await this.dbManager.update("order", order);
|
|
1082
857
|
if (paymentData.payments.length === 0) {
|
|
1083
|
-
|
|
858
|
+
console.log(`[PaymentModule] 订单 ${order.uuid} 支付列表为空,跳过支付处理`);
|
|
859
|
+
this.logWarning("Empty payment list", {
|
|
1084
860
|
orderUuid: order.uuid,
|
|
1085
861
|
orderId: order.order_id
|
|
1086
862
|
});
|
|
1087
863
|
return;
|
|
1088
864
|
}
|
|
1089
|
-
|
|
1090
|
-
// 触发支付提交事件
|
|
1091
865
|
await this.core.effects.emit(`${this.name}:onPaymentSubmitted`, order);
|
|
1092
866
|
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
1093
|
-
action:
|
|
867
|
+
action: "submit",
|
|
1094
868
|
order
|
|
1095
869
|
});
|
|
1096
870
|
} catch (error) {
|
|
@@ -1098,163 +872,170 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
1098
872
|
throw error;
|
|
1099
873
|
}
|
|
1100
874
|
}
|
|
1101
|
-
|
|
1102
875
|
/**
|
|
1103
876
|
* 获取订单剩余待付金额
|
|
1104
877
|
*/
|
|
1105
878
|
async getRemainingOrderAmountAsync(orderUuid) {
|
|
1106
879
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1107
880
|
if (!order) {
|
|
1108
|
-
throw new Error(
|
|
881
|
+
throw new Error("订单不存在");
|
|
1109
882
|
}
|
|
1110
|
-
return new
|
|
883
|
+
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
1111
884
|
}
|
|
1112
|
-
|
|
1113
885
|
/**
|
|
1114
886
|
* 在比如现金支付界面的地方,用户输入了一个金额,在下方显示剩余多少金额,通过此方法获取
|
|
1115
887
|
*/
|
|
1116
888
|
async getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid) {
|
|
1117
889
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1118
890
|
if (!order) {
|
|
1119
|
-
throw new Error(
|
|
891
|
+
throw new Error("订单不存在");
|
|
1120
892
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
if (inputAmount === null || inputAmount === undefined) {
|
|
1124
|
-
// 如果输入为空,返回原始的待付金额
|
|
1125
|
-
return new _decimal.Decimal(order.expect_amount).toNumber();
|
|
893
|
+
if (inputAmount === null || inputAmount === void 0) {
|
|
894
|
+
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
1126
895
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
if (inputAmount.trim() === '') {
|
|
1131
|
-
// 如果输入为空字符串,返回原始的待付金额
|
|
1132
|
-
return new _decimal.Decimal(order.expect_amount).toNumber();
|
|
896
|
+
if (typeof inputAmount === "string") {
|
|
897
|
+
if (inputAmount.trim() === "") {
|
|
898
|
+
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
1133
899
|
}
|
|
1134
900
|
}
|
|
1135
|
-
|
|
1136
|
-
// 处理数字类型的输入
|
|
1137
|
-
if (typeof inputAmount === 'number') {
|
|
901
|
+
if (typeof inputAmount === "number") {
|
|
1138
902
|
if (isNaN(inputAmount) || !isFinite(inputAmount)) {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
903
|
+
console.warn(
|
|
904
|
+
`[PaymentModule] 输入金额不是有效数字: ${inputAmount},返回原始待付金额`
|
|
905
|
+
);
|
|
906
|
+
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
1142
907
|
}
|
|
1143
908
|
}
|
|
1144
909
|
try {
|
|
1145
|
-
const inputDecimal = new
|
|
1146
|
-
return new
|
|
910
|
+
const inputDecimal = new import_decimal.Decimal(inputAmount);
|
|
911
|
+
return new import_decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
|
|
1147
912
|
} catch (error) {
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
913
|
+
console.warn(
|
|
914
|
+
`[PaymentModule] 输入金额格式无效: ${inputAmount},返回原始待付金额`
|
|
915
|
+
);
|
|
916
|
+
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
1151
917
|
}
|
|
1152
918
|
}
|
|
1153
|
-
|
|
1154
919
|
/**
|
|
1155
920
|
* 重新计算订单金额
|
|
1156
921
|
*/
|
|
1157
922
|
recalculateOrderAmount(order) {
|
|
1158
|
-
const totalAmount = new
|
|
1159
|
-
const paidAmount = order.payment.reduce(
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
923
|
+
const totalAmount = new import_decimal.Decimal(order.total_amount);
|
|
924
|
+
const paidAmount = order.payment.reduce(
|
|
925
|
+
(sum, payment) => {
|
|
926
|
+
try {
|
|
927
|
+
if (payment.status === "voided") {
|
|
928
|
+
return sum;
|
|
929
|
+
}
|
|
930
|
+
const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
|
|
931
|
+
const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
|
|
932
|
+
const effectiveAmount = paymentAmount.minus(roundingAmount);
|
|
933
|
+
return sum.plus(effectiveAmount);
|
|
934
|
+
} catch (error) {
|
|
935
|
+
console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
|
|
1163
936
|
return sum;
|
|
1164
937
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
938
|
+
},
|
|
939
|
+
new import_decimal.Decimal(0)
|
|
940
|
+
);
|
|
941
|
+
const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
|
|
942
|
+
order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
|
|
943
|
+
console.log(`[PaymentModule] 重新计算订单金额:`, {
|
|
944
|
+
orderUuid: order.uuid,
|
|
945
|
+
totalAmount: order.total_amount,
|
|
946
|
+
effectivePaidAmount: paidAmount.toFixed(2),
|
|
947
|
+
remainingAmount: order.expect_amount,
|
|
948
|
+
activePayments: order.payment.filter((p) => p.status !== "voided").length,
|
|
949
|
+
voidedPayments: order.payment.filter((p) => p.status === "voided").length,
|
|
950
|
+
paymentDetails: order.payment.filter((p) => p.status !== "voided").map((p) => ({
|
|
951
|
+
code: p.code,
|
|
952
|
+
amount: p.amount,
|
|
953
|
+
rounding_amount: p.rounding_amount || "0.00",
|
|
954
|
+
effective_amount: new import_decimal.Decimal(p.amount || 0).minus(new import_decimal.Decimal(p.rounding_amount || 0)).toFixed(2)
|
|
955
|
+
})),
|
|
956
|
+
说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
957
|
+
});
|
|
1182
958
|
}
|
|
1183
|
-
|
|
1184
959
|
/**
|
|
1185
960
|
* 获取现金支付方式
|
|
1186
961
|
*/
|
|
1187
962
|
async getCashPaymentMethod() {
|
|
1188
963
|
try {
|
|
1189
|
-
const payMethods = await this.dbManager.getAll(
|
|
1190
|
-
return payMethods.find(
|
|
964
|
+
const payMethods = await this.dbManager.getAll("pay_method");
|
|
965
|
+
return payMethods.find(
|
|
966
|
+
(method) => method.code === import_types.PaymentMethodType.Cash
|
|
967
|
+
) || null;
|
|
1191
968
|
} catch (error) {
|
|
1192
|
-
console.error(
|
|
969
|
+
console.error("[PaymentModule] 获取现金支付方式失败", error);
|
|
1193
970
|
return null;
|
|
1194
971
|
}
|
|
1195
972
|
}
|
|
1196
|
-
|
|
1197
973
|
/**
|
|
1198
974
|
* 获取Eftpos支付方式
|
|
1199
975
|
*/
|
|
1200
976
|
async getEftposPaymentMethod() {
|
|
1201
977
|
try {
|
|
1202
|
-
const payMethods = await this.dbManager.getAll(
|
|
1203
|
-
return payMethods.find(
|
|
978
|
+
const payMethods = await this.dbManager.getAll("pay_method");
|
|
979
|
+
return payMethods.find(
|
|
980
|
+
(method) => method.code === import_types.PaymentMethodType.Eftpos
|
|
981
|
+
) || null;
|
|
1204
982
|
} catch (error) {
|
|
1205
|
-
console.error(
|
|
983
|
+
console.error("[PaymentModule] 获取Eftpos支付方式失败", error);
|
|
1206
984
|
return null;
|
|
1207
985
|
}
|
|
1208
986
|
}
|
|
1209
|
-
|
|
1210
987
|
/**
|
|
1211
988
|
* 获取钱包支付方式
|
|
1212
989
|
*/
|
|
1213
990
|
async getWalletPaymentMethod() {
|
|
1214
991
|
try {
|
|
1215
|
-
const payMethods = await this.dbManager.getAll(
|
|
1216
|
-
return payMethods.find(
|
|
992
|
+
const payMethods = await this.dbManager.getAll("pay_method");
|
|
993
|
+
return payMethods.find(
|
|
994
|
+
(method) => method.code === import_types.PaymentMethodType.Wallet
|
|
995
|
+
) || null;
|
|
1217
996
|
} catch (error) {
|
|
1218
|
-
console.error(
|
|
997
|
+
console.error("[PaymentModule] 获取钱包支付方式失败", error);
|
|
1219
998
|
return null;
|
|
1220
999
|
}
|
|
1221
1000
|
}
|
|
1222
|
-
|
|
1223
1001
|
/**
|
|
1224
1002
|
* 确保支付模块所需的数据库表已创建
|
|
1225
1003
|
*/
|
|
1004
|
+
/** @deprecated */
|
|
1226
1005
|
async ensurePaymentTables() {
|
|
1227
1006
|
try {
|
|
1228
|
-
|
|
1229
|
-
await this.dbManager.getAll('pay_method');
|
|
1007
|
+
await this.dbManager.getAll("pay_method");
|
|
1230
1008
|
} catch (error) {
|
|
1231
|
-
console.warn(
|
|
1009
|
+
console.warn(
|
|
1010
|
+
"[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:"
|
|
1011
|
+
);
|
|
1232
1012
|
console.warn('{ name: "pay_method", keyPath: "id" }');
|
|
1233
1013
|
}
|
|
1234
1014
|
try {
|
|
1235
|
-
|
|
1236
|
-
await this.dbManager.getAll('order');
|
|
1015
|
+
await this.dbManager.getAll("order");
|
|
1237
1016
|
} catch (error) {
|
|
1238
|
-
console.warn(
|
|
1017
|
+
console.warn(
|
|
1018
|
+
"[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:"
|
|
1019
|
+
);
|
|
1239
1020
|
console.warn('{ name: "order", keyPath: "uuid" }');
|
|
1240
1021
|
}
|
|
1241
1022
|
}
|
|
1242
|
-
|
|
1243
1023
|
/**
|
|
1244
1024
|
* 获取部分支付的订单
|
|
1245
1025
|
*/
|
|
1026
|
+
/** @deprecated */
|
|
1246
1027
|
async getPartiallyPaidOrdersAsync() {
|
|
1247
1028
|
try {
|
|
1248
|
-
const allOrders = await this.dbManager.getAll(
|
|
1249
|
-
return allOrders.filter(
|
|
1029
|
+
const allOrders = await this.dbManager.getAll("order");
|
|
1030
|
+
return allOrders.filter(
|
|
1031
|
+
(order) => order.payment_status === import_types.PaymentStatus.PartiallyPaid
|
|
1032
|
+
);
|
|
1250
1033
|
} catch (error) {
|
|
1251
|
-
console.error(
|
|
1034
|
+
console.error("[PaymentModule] 获取部分支付订单失败", error);
|
|
1252
1035
|
return [];
|
|
1253
1036
|
}
|
|
1254
1037
|
}
|
|
1255
|
-
|
|
1256
1038
|
// === 新的 API 方法实现 ===
|
|
1257
|
-
|
|
1258
1039
|
/**
|
|
1259
1040
|
* 智能金额舍入
|
|
1260
1041
|
*
|
|
@@ -1267,78 +1048,63 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
1267
1048
|
*/
|
|
1268
1049
|
async roundAmountAsync(originalAmount, interval, rule) {
|
|
1269
1050
|
try {
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
const roundingInterval = new _decimal.Decimal(interval);
|
|
1051
|
+
const amount = new import_decimal.Decimal(originalAmount);
|
|
1052
|
+
const roundingInterval = new import_decimal.Decimal(interval);
|
|
1273
1053
|
if (roundingInterval.lte(0)) {
|
|
1274
|
-
throw new Error(
|
|
1054
|
+
throw new Error("舍入间隔必须大于 0");
|
|
1275
1055
|
}
|
|
1276
|
-
|
|
1277
|
-
// 支持的舍入间隔
|
|
1278
1056
|
const supportedIntervals = [0.05, 0.1, 0.5, 1];
|
|
1279
1057
|
const intervalValue = roundingInterval.toNumber();
|
|
1280
1058
|
if (!supportedIntervals.includes(intervalValue)) {
|
|
1281
|
-
console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(
|
|
1059
|
+
console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(", ")}`);
|
|
1282
1060
|
}
|
|
1283
|
-
|
|
1284
|
-
// 计算基础值:x / interval
|
|
1285
1061
|
const baseValue = amount.div(roundingInterval);
|
|
1062
|
+
console.log(`[PaymentModule] 舍入计算 - 原始金额: ${amount.toString()}, 间隔: ${intervalValue}, 基础值: ${baseValue.toString()}, 规则: ${rule}`);
|
|
1286
1063
|
let roundedValue;
|
|
1287
|
-
|
|
1288
|
-
// 根据舍入规则处理
|
|
1289
1064
|
switch (rule) {
|
|
1290
|
-
case
|
|
1291
|
-
case
|
|
1292
|
-
// 标准舍入(中点向上)
|
|
1065
|
+
case import_types.RoundingRule.Standard:
|
|
1066
|
+
case "standard":
|
|
1293
1067
|
roundedValue = this.standardRound(baseValue, true);
|
|
1294
1068
|
break;
|
|
1295
|
-
case
|
|
1296
|
-
case
|
|
1297
|
-
// 标准舍入(中点向下)
|
|
1069
|
+
case import_types.RoundingRule.StandardDown:
|
|
1070
|
+
case "standard_down":
|
|
1298
1071
|
roundedValue = this.standardRound(baseValue, false);
|
|
1299
1072
|
break;
|
|
1300
|
-
case
|
|
1301
|
-
case
|
|
1302
|
-
// 总是向上舍入
|
|
1073
|
+
case import_types.RoundingRule.AlwaysUp:
|
|
1074
|
+
case "always_up":
|
|
1303
1075
|
roundedValue = baseValue.ceil();
|
|
1304
1076
|
break;
|
|
1305
|
-
case
|
|
1306
|
-
case
|
|
1307
|
-
// 总是向下舍入
|
|
1077
|
+
case import_types.RoundingRule.AlwaysDown:
|
|
1078
|
+
case "always_down":
|
|
1308
1079
|
roundedValue = baseValue.floor();
|
|
1309
1080
|
break;
|
|
1310
1081
|
default:
|
|
1311
1082
|
throw new Error(`不支持的舍入规则: ${rule}`);
|
|
1312
1083
|
}
|
|
1313
|
-
|
|
1314
|
-
// 计算最终金额:roundedValue * interval
|
|
1315
1084
|
const finalAmount = roundedValue.mul(roundingInterval);
|
|
1316
1085
|
const originalAmountStr = amount.toFixed(2);
|
|
1317
|
-
|
|
1318
|
-
// 如果最终金额是 0 元,则不采用舍入金额,返回原始金额
|
|
1319
1086
|
if (finalAmount.eq(0)) {
|
|
1087
|
+
console.log(`[PaymentModule] 最终金额为0,返回原始金额: ${originalAmountStr}`);
|
|
1320
1088
|
return {
|
|
1321
1089
|
originalAmount: originalAmountStr,
|
|
1322
1090
|
roundedAmount: originalAmountStr,
|
|
1323
|
-
roundingDifference:
|
|
1091
|
+
roundingDifference: "0.00"
|
|
1324
1092
|
};
|
|
1325
1093
|
}
|
|
1326
1094
|
const roundedAmountStr = finalAmount.toFixed(2);
|
|
1327
|
-
|
|
1328
|
-
// 计算舍入差额
|
|
1329
1095
|
const roundingDifference = finalAmount.sub(amount);
|
|
1330
1096
|
const roundingDifferenceStr = roundingDifference.toFixed(2);
|
|
1097
|
+
console.log(`[PaymentModule] 舍入结果 - 原始金额: ${originalAmountStr}, 舍入后金额: ${roundedAmountStr}, 舍入差额: ${roundingDifferenceStr}`);
|
|
1331
1098
|
return {
|
|
1332
1099
|
originalAmount: originalAmountStr,
|
|
1333
1100
|
roundedAmount: roundedAmountStr,
|
|
1334
1101
|
roundingDifference: roundingDifferenceStr
|
|
1335
1102
|
};
|
|
1336
1103
|
} catch (error) {
|
|
1337
|
-
console.error(
|
|
1104
|
+
console.error("[PaymentModule] 金额舍入失败:", error);
|
|
1338
1105
|
throw new Error(`金额舍入失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
1339
1106
|
}
|
|
1340
1107
|
}
|
|
1341
|
-
|
|
1342
1108
|
/**
|
|
1343
1109
|
* 标准舍入处理(处理中点情况)
|
|
1344
1110
|
*
|
|
@@ -1349,18 +1115,18 @@ class PaymentModule extends _BaseModule.BaseModule {
|
|
|
1349
1115
|
standardRound(value, midpointUp) {
|
|
1350
1116
|
const floorValue = value.floor();
|
|
1351
1117
|
const fractionalPart = value.minus(floorValue);
|
|
1352
|
-
|
|
1353
|
-
// 检查是否是中点(小数部分 = 0.5)
|
|
1354
1118
|
if (fractionalPart.eq(0.5)) {
|
|
1355
|
-
// 中点情况,根据规则决定
|
|
1356
1119
|
return midpointUp ? floorValue.plus(1) : floorValue;
|
|
1357
1120
|
} else if (fractionalPart.gt(0.5)) {
|
|
1358
|
-
// 大于中点,向上舍入
|
|
1359
1121
|
return floorValue.plus(1);
|
|
1360
1122
|
} else {
|
|
1361
|
-
// 小于中点,向下舍入
|
|
1362
1123
|
return floorValue;
|
|
1363
1124
|
}
|
|
1364
1125
|
}
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1126
|
+
};
|
|
1127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1128
|
+
0 && (module.exports = {
|
|
1129
|
+
PaymentModule,
|
|
1130
|
+
generateRequestUniqueId,
|
|
1131
|
+
...require("./types")
|
|
1132
|
+
});
|