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