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