@pisell/pisellos 0.10.15 → 0.10.17
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 +6 -9
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +2 -4
- package/dist/modules/OpenData/index.d.ts +5 -2
- package/dist/modules/OpenData/index.js +27 -14
- package/dist/modules/OpenData/types.d.ts +42 -0
- package/dist/modules/OpenData/types.js +7 -1
- package/dist/modules/OpenData/utils.d.ts +15 -1
- package/dist/modules/OpenData/utils.js +85 -0
- package/dist/modules/Order/index.d.ts +4 -2
- package/dist/modules/Order/index.js +131 -123
- package/dist/modules/Order/types.d.ts +8 -1
- package/dist/modules/Order/types.js +1 -0
- package/dist/modules/Order/utils.js +7 -1
- package/dist/modules/Payment/index.js +97 -162
- package/dist/modules/Product/types.d.ts +2 -0
- package/dist/modules/ProductList/index.js +96 -74
- package/dist/modules/Rules/index.js +12 -12
- package/dist/modules/SalesSummary/index.js +6 -4
- package/dist/modules/Schedule/index.js +0 -1
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +977 -641
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/order/index.d.ts +8 -0
- package/dist/server/modules/order/index.js +253 -219
- package/dist/server/modules/products/index.js +24 -42
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +27 -35
- package/dist/server/utils/product.js +0 -1
- package/dist/server/utils/small-ticket.d.ts +9 -1
- package/dist/server/utils/small-ticket.js +117 -43
- package/dist/solution/BaseSales/index.d.ts +7 -0
- package/dist/solution/BaseSales/index.js +350 -215
- package/dist/solution/BaseSales/types.d.ts +2 -0
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +7 -1
- package/dist/solution/BaseSales/utils.js +6 -3
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.d.ts +14 -19
- package/dist/solution/BookingTicket/index.js +553 -433
- package/dist/solution/BookingTicket/utils/addProductDecision.js +3 -1
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -252
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/Sales/index.d.ts +20 -4
- package/dist/solution/Sales/index.js +348 -75
- package/dist/solution/Sales/types.d.ts +10 -0
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ScanOrder/types.d.ts +2 -0
- package/dist/solution/ScanOrder/utils.js +6 -3
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
- package/dist/solution/UnifiedBookingSales/index.js +495 -422
- package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
- package/dist/solution/VenueBooking/index.js +45 -55
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +131 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +82 -49
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +209 -315
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
- package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
- package/lib/model/strategy/adapter/promotion/examples.js +222 -234
- package/lib/model/strategy/adapter/promotion/index.js +1 -51
- package/lib/model/strategy/adapter/promotion/type.js +243 -36
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +23 -42
- package/lib/modules/BookingContext/index.js +158 -136
- package/lib/modules/BookingContext/types.js +46 -32
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
- package/lib/modules/BookingContext/utils/flexible.js +38 -55
- package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
- package/lib/modules/BookingContext/utils/index.js +124 -41
- package/lib/modules/BookingContext/utils/noResource.js +58 -70
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
- package/lib/modules/BookingContext/utils/productExtend.js +202 -155
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
- package/lib/modules/BookingContext/utils/resources.js +209 -167
- package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
- package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +321 -251
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +70 -78
- package/lib/modules/Cart/utils/changePrice.js +22 -50
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +235 -172
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +133 -143
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.d.ts +5 -2
- package/lib/modules/OpenData/index.js +119 -78
- package/lib/modules/OpenData/types.d.ts +42 -0
- package/lib/modules/OpenData/types.js +12 -16
- package/lib/modules/OpenData/utils.d.ts +15 -1
- package/lib/modules/OpenData/utils.js +129 -78
- package/lib/modules/Order/index.d.ts +4 -2
- package/lib/modules/Order/index.js +1843 -2251
- package/lib/modules/Order/payment-utils.js +77 -120
- package/lib/modules/Order/types.d.ts +8 -1
- package/lib/modules/Order/types.js +88 -35
- package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
- package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
- package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
- package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
- package/lib/modules/Order/utils/virtualSettlement.js +120 -171
- package/lib/modules/Order/utils.js +834 -668
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +532 -399
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +230 -108
- package/lib/modules/Payment/utils.js +52 -51
- package/lib/modules/Payment/walletpass.js +485 -660
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.d.ts +2 -0
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +141 -161
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +66 -100
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/ResourcePlanner/index.js +25 -23
- package/lib/modules/ResourcePlanner/localClock.js +54 -119
- package/lib/modules/ResourcePlanner/planner.js +591 -772
- package/lib/modules/ResourcePlanner/types.js +10 -29
- package/lib/modules/Rules/index.js +1224 -963
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +80 -89
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +359 -442
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
- package/lib/modules/Schedule/index.js +100 -114
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -71
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +773 -418
- package/lib/modules/SurchargeList/index.js +46 -60
- package/lib/modules/SurchargeList/types.js +4 -16
- package/lib/modules/index.js +245 -63
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.d.ts +11 -0
- package/lib/server/index.js +3432 -2757
- package/lib/server/modules/floor-plan/index.js +102 -123
- package/lib/server/modules/floor-plan/types.js +15 -30
- package/lib/server/modules/index.js +106 -68
- package/lib/server/modules/menu/index.js +146 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.d.ts +8 -0
- package/lib/server/modules/order/index.js +781 -956
- package/lib/server/modules/order/types.js +122 -33
- package/lib/server/modules/order/utils/filterBookings.js +219 -194
- package/lib/server/modules/order/utils/filterOrders.js +118 -92
- package/lib/server/modules/payment/index.js +59 -83
- package/lib/server/modules/payment/types.js +4 -16
- package/lib/server/modules/products/index.js +575 -459
- package/lib/server/modules/products/types.js +44 -34
- package/lib/server/modules/quotation/index.js +137 -172
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +213 -184
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +135 -123
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/small-ticket.d.ts +9 -1
- package/lib/server/utils/small-ticket.js +565 -470
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BaseSales/index.d.ts +7 -0
- package/lib/solution/BaseSales/index.js +1385 -1503
- package/lib/solution/BaseSales/types.d.ts +2 -0
- package/lib/solution/BaseSales/types.js +42 -38
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
- package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +138 -180
- package/lib/solution/BaseSales/utils.js +161 -143
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingByStep/index.js +1527 -1340
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.d.ts +14 -19
- package/lib/solution/BookingTicket/index.js +663 -526
- package/lib/solution/BookingTicket/types.js +99 -77
- package/lib/solution/BookingTicket/utils/addProductDecision.js +229 -190
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
- package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
- package/lib/solution/BookingTicket/utils/cartView.js +114 -99
- package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
- package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +228 -156
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.d.ts +20 -4
- package/lib/solution/Sales/index.js +502 -330
- package/lib/solution/Sales/types.d.ts +10 -0
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +822 -852
- package/lib/solution/ScanOrder/types.d.ts +2 -0
- package/lib/solution/ScanOrder/types.js +33 -34
- package/lib/solution/ScanOrder/utils.js +412 -374
- package/lib/solution/ShopDiscount/index.js +226 -232
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +300 -172
- package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
- package/lib/solution/UnifiedBookingSales/index.js +1087 -1222
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
- package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
- package/lib/solution/UnifiedBookingSales/types.js +10 -32
- package/lib/solution/VenueBooking/index.js +811 -879
- package/lib/solution/VenueBooking/types.js +19 -39
- package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
- package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +124 -41
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/payment-number.js +26 -46
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,335 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
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;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
BaseSalesImpl: true
|
|
18
8
|
};
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__export(BaseSales_exports, {
|
|
33
|
-
BaseSalesImpl: () => BaseSalesImpl
|
|
9
|
+
exports.BaseSalesImpl = void 0;
|
|
10
|
+
var _BaseModule = require("../../modules/BaseModule");
|
|
11
|
+
var _types = require("./types");
|
|
12
|
+
Object.keys(_types).forEach(function (key) {
|
|
13
|
+
if (key === "default" || key === "__esModule") return;
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
15
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
16
|
+
Object.defineProperty(exports, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _types[key];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
34
22
|
});
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
product_voucher:
|
|
55
|
-
gift_card:
|
|
56
|
-
point_card:
|
|
23
|
+
var _Order = require("../../modules/Order");
|
|
24
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
25
|
+
var _lodashEs = require("lodash-es");
|
|
26
|
+
var _types2 = require("../BookingByStep/types");
|
|
27
|
+
var _utils = require("../../modules/Order/utils");
|
|
28
|
+
var _virtualSettlement = require("../../modules/Order/utils/virtualSettlement");
|
|
29
|
+
var _paymentUtils = require("../../modules/Order/payment-utils");
|
|
30
|
+
var _paymentNumber = require("../../utils/payment-number");
|
|
31
|
+
var _orderCollectionIdentity = require("../../modules/Order/utils/orderCollectionIdentity");
|
|
32
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
33
|
+
var _Quotation = require("../../modules/Quotation");
|
|
34
|
+
var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
|
|
35
|
+
var _quotationPrice = require("./utils/quotationPrice");
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
+
const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
|
|
38
|
+
const OS_FULFILLMENT_REF_MODE_FIELD = '_os_fulfillment_ref_mode';
|
|
39
|
+
const OS_INVOICE_LAYOUT_CONFIG_FIELD = '_os_invoice_layout_config';
|
|
40
|
+
const OS_INVOICE_TEMPLATE_SETTINGS_FIELD = '_os_invoice_template_settings';
|
|
41
|
+
const WALLET_PAYMENT_CODE_BY_TAG = {
|
|
42
|
+
product_voucher: 'PRODUCTVOUCHER',
|
|
43
|
+
gift_card: 'GIFTCARD',
|
|
44
|
+
point_card: 'POINTCARD'
|
|
57
45
|
};
|
|
58
46
|
function getSharedWalletAssetId(asset) {
|
|
59
|
-
return
|
|
47
|
+
return asset?.id ?? asset?.voucher_id ?? asset?.code;
|
|
60
48
|
}
|
|
61
49
|
function getSharedWalletAssetAmount(asset) {
|
|
62
|
-
const value =
|
|
50
|
+
const value = asset?.edit_current_amount ?? asset?._available_max_amount ?? (asset?.tag === 'point_card' ? asset?.recommended_usage_amount : asset?.available_max_amount) ?? asset?.actualDeduction ?? asset?.amount ?? 0;
|
|
63
51
|
const amount = Number(value);
|
|
64
52
|
return Number.isFinite(amount) && amount > 0 ? amount : 0;
|
|
65
53
|
}
|
|
66
54
|
function isRejectedSalesSubmitResult(result) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(_a = result == null ? void 0 : result.response) == null ? void 0 : _a.data,
|
|
72
|
-
(_b = result == null ? void 0 : result.response) == null ? void 0 : _b.body
|
|
73
|
-
];
|
|
74
|
-
return candidates.some((candidate) => {
|
|
75
|
-
if (!candidate || typeof candidate !== "object")
|
|
76
|
-
return false;
|
|
77
|
-
if (candidate.code !== void 0 && candidate.code !== 200 && candidate.code !== "200") {
|
|
55
|
+
const candidates = [result, result?.data, result?.response?.data, result?.response?.body];
|
|
56
|
+
return candidates.some(candidate => {
|
|
57
|
+
if (!candidate || typeof candidate !== 'object') return false;
|
|
58
|
+
if (candidate.code !== undefined && candidate.code !== 200 && candidate.code !== '200') {
|
|
78
59
|
return true;
|
|
79
60
|
}
|
|
80
61
|
const statusCode = Number(candidate.statusCode);
|
|
81
|
-
if (Number.isFinite(statusCode) && statusCode >= 400)
|
|
82
|
-
return true;
|
|
62
|
+
if (Number.isFinite(statusCode) && statusCode >= 400) return true;
|
|
83
63
|
if (candidate.status === false || candidate.success === false || candidate.result === false) {
|
|
84
64
|
return true;
|
|
85
65
|
}
|
|
86
|
-
return [
|
|
87
|
-
String(candidate.status || "").toLowerCase()
|
|
88
|
-
);
|
|
66
|
+
return ['failed', 'error'].includes(String(candidate.status || '').toLowerCase());
|
|
89
67
|
});
|
|
90
68
|
}
|
|
91
69
|
function getSalesSubmitErrorMessage(result, fallbackMessage) {
|
|
92
|
-
|
|
93
|
-
return (result == null ? void 0 : result.message) || (result == null ? void 0 : result.msg) || ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.message) || ((_b = result == null ? void 0 : result.data) == null ? void 0 : _b.msg) || fallbackMessage;
|
|
70
|
+
return result?.message || result?.msg || result?.data?.message || result?.data?.msg || fallbackMessage;
|
|
94
71
|
}
|
|
95
72
|
function toWalletFundValue(value) {
|
|
96
73
|
try {
|
|
97
|
-
return new
|
|
74
|
+
return new _decimal.default(value || 0).toDecimalPlaces(2).toFixed(2);
|
|
98
75
|
} catch {
|
|
99
|
-
return
|
|
76
|
+
return '0.00';
|
|
100
77
|
}
|
|
101
78
|
}
|
|
102
79
|
function subtractWalletFundValue(left, right) {
|
|
103
80
|
try {
|
|
104
|
-
return new
|
|
81
|
+
return new _decimal.default(left || 0).minus(right || 0).toDecimalPlaces(2).toFixed(2);
|
|
105
82
|
} catch {
|
|
106
|
-
return
|
|
83
|
+
return '0.00';
|
|
107
84
|
}
|
|
108
85
|
}
|
|
109
86
|
function getSharedWalletPassUseValue(params) {
|
|
110
|
-
const {
|
|
111
|
-
|
|
87
|
+
const {
|
|
88
|
+
asset,
|
|
89
|
+
amount,
|
|
90
|
+
paymentMethod
|
|
91
|
+
} = params;
|
|
92
|
+
const configuredValue = Number(asset?.wallet_pass_use_value);
|
|
112
93
|
if (Number.isFinite(configuredValue) && configuredValue > 0) {
|
|
113
94
|
return configuredValue;
|
|
114
95
|
}
|
|
115
|
-
const isPointCard =
|
|
116
|
-
const usageUnit = asset
|
|
117
|
-
if (isPointCard &&
|
|
118
|
-
return new
|
|
96
|
+
const isPointCard = asset?.tag === 'point_card' || paymentMethod.code === 'POINTCARD';
|
|
97
|
+
const usageUnit = asset?.wallet_pass_usage_unit;
|
|
98
|
+
if (isPointCard && usageUnit?.points && usageUnit?.price) {
|
|
99
|
+
return new _decimal.default(amount).div(usageUnit.price).mul(usageUnit.points).toDecimalPlaces(2, _decimal.default.ROUND_DOWN).toNumber();
|
|
119
100
|
}
|
|
120
101
|
return amount;
|
|
121
102
|
}
|
|
122
103
|
function buildSharedWalletFundRecord(params) {
|
|
123
|
-
const {
|
|
124
|
-
|
|
125
|
-
|
|
104
|
+
const {
|
|
105
|
+
asset,
|
|
106
|
+
amount,
|
|
107
|
+
paymentMethod
|
|
108
|
+
} = params;
|
|
109
|
+
const isPointCard = asset?.tag === 'point_card' || paymentMethod.code === 'POINTCARD';
|
|
110
|
+
const usingBeforeValue = asset?.balance_par_value ?? asset?.balance ?? asset?.using_before_value ?? 0;
|
|
126
111
|
const walletPassUseValue = getSharedWalletPassUseValue(params);
|
|
127
112
|
const usingValue = isPointCard ? walletPassUseValue : amount;
|
|
128
|
-
const walletPassName =
|
|
113
|
+
const walletPassName = asset?.wallet_pass_name || asset?.format_title || asset?.product_name || asset?.name || paymentMethod.name;
|
|
129
114
|
return {
|
|
130
|
-
voucher_id:
|
|
131
|
-
wallet_pass_name: walletPassName && typeof walletPassName ===
|
|
132
|
-
|
|
133
|
-
|
|
115
|
+
voucher_id: asset?.voucher_id ?? asset?.id,
|
|
116
|
+
wallet_pass_name: walletPassName && typeof walletPassName === 'object' ? walletPassName : {
|
|
117
|
+
default: walletPassName || ''
|
|
118
|
+
},
|
|
119
|
+
code: asset?.code || asset?.tag,
|
|
120
|
+
encoded: asset?.encoded,
|
|
134
121
|
using_before_value: toWalletFundValue(usingBeforeValue),
|
|
135
122
|
using_after_value: subtractWalletFundValue(usingBeforeValue, usingValue)
|
|
136
123
|
};
|
|
137
124
|
}
|
|
138
125
|
function isBaseSalesManualProductDiscountProduct(product) {
|
|
139
|
-
|
|
140
|
-
return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
|
|
126
|
+
return product?.metadata?.is_manual_discount === true || product?.metadata?.is_manual_discount === 1 || (product?.discount_list || []).some(item => item?.type === 'product');
|
|
141
127
|
}
|
|
142
128
|
function getBaseSalesProductUid(product) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (uid === void 0 || uid === null || uid === "")
|
|
146
|
-
return null;
|
|
129
|
+
const uid = product?.metadata?.unique_identification_number || product?.unique_identification_number;
|
|
130
|
+
if (uid === undefined || uid === null || uid === '') return null;
|
|
147
131
|
return String(uid);
|
|
148
132
|
}
|
|
149
133
|
function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
|
|
150
|
-
const previousByUid =
|
|
134
|
+
const previousByUid = new Map();
|
|
151
135
|
(previousProducts || []).forEach((product, index) => {
|
|
152
136
|
const uid = getBaseSalesProductUid(product);
|
|
153
|
-
if (uid)
|
|
154
|
-
previousByUid.set(uid, product);
|
|
137
|
+
if (uid) previousByUid.set(uid, product);
|
|
155
138
|
previousByUid.set(`__index__:${index}`, product);
|
|
156
139
|
});
|
|
157
140
|
return (nextProducts || []).map((product, index) => {
|
|
158
141
|
const uid = getBaseSalesProductUid(product);
|
|
159
|
-
const previous = (uid ? previousByUid.get(uid) :
|
|
142
|
+
const previous = (uid ? previousByUid.get(uid) : undefined) || previousByUid.get(`__index__:${index}`);
|
|
160
143
|
return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
|
|
161
144
|
});
|
|
162
145
|
}
|
|
163
146
|
function isBaseSalesHistoricalDiscountEntry(discount) {
|
|
164
|
-
return Boolean(
|
|
165
|
-
(discount == null ? void 0 : discount.isEditMode) || (discount == null ? void 0 : discount.isDisabled) || (discount == null ? void 0 : discount.order_discount_id) != null
|
|
166
|
-
);
|
|
147
|
+
return Boolean(discount?.isEditMode || discount?.isDisabled || discount?.order_discount_id != null);
|
|
167
148
|
}
|
|
168
149
|
function getBaseSalesUniqueArrayMetadataKey(key) {
|
|
169
|
-
if (key ===
|
|
170
|
-
return "unique_identification_number";
|
|
150
|
+
if (key === 'products' || key === 'bookings') return 'unique_identification_number';
|
|
171
151
|
return null;
|
|
172
152
|
}
|
|
173
|
-
|
|
174
|
-
product:
|
|
175
|
-
booking:
|
|
176
|
-
payment:
|
|
153
|
+
const BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
|
|
154
|
+
product: 'order_detail_id',
|
|
155
|
+
booking: 'schedule_event_id',
|
|
156
|
+
payment: 'order_payment_id'
|
|
177
157
|
};
|
|
178
158
|
function getBaseSalesOrderCollectionKind(key) {
|
|
179
|
-
if (key ===
|
|
180
|
-
|
|
181
|
-
if (key ===
|
|
182
|
-
return "booking";
|
|
183
|
-
if (key === "payments" || key === "payment")
|
|
184
|
-
return "payment";
|
|
159
|
+
if (key === 'products') return 'product';
|
|
160
|
+
if (key === 'bookings') return 'booking';
|
|
161
|
+
if (key === 'payments' || key === 'payment') return 'payment';
|
|
185
162
|
return null;
|
|
186
163
|
}
|
|
187
164
|
function isSameBaseSalesOrderRecord(left, right) {
|
|
188
|
-
if (!left || !right || typeof left !==
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
);
|
|
193
|
-
if (leftIdentities.size === 0)
|
|
194
|
-
return false;
|
|
195
|
-
return [right.order_id, right.id, right.external_sale_number, right.order_number].some(
|
|
196
|
-
(value) => value !== void 0 && value !== null && value !== "" && leftIdentities.has(String(value))
|
|
197
|
-
);
|
|
165
|
+
if (!left || !right || typeof left !== 'object' || typeof right !== 'object') return false;
|
|
166
|
+
const leftIdentities = new Set([left.order_id, left.id, left.external_sale_number, left.order_number].filter(value => value !== undefined && value !== null && value !== '').map(String));
|
|
167
|
+
if (leftIdentities.size === 0) return false;
|
|
168
|
+
return [right.order_id, right.id, right.external_sale_number, right.order_number].some(value => value !== undefined && value !== null && value !== '' && leftIdentities.has(String(value)));
|
|
198
169
|
}
|
|
199
170
|
function isBaseSalesBlankValue(value) {
|
|
200
|
-
return value ===
|
|
171
|
+
return value === undefined || value === null || value === '';
|
|
201
172
|
}
|
|
202
173
|
function mergeBaseSalesProductSnapshotFields(currentItem, loadedItem) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (isBaseSalesBlankValue(mergedItem.product_cover) && !isBaseSalesBlankValue(currentItem == null ? void 0 : currentItem.product_cover)) {
|
|
174
|
+
const mergedItem = (0, _lodashEs.cloneDeep)(loadedItem);
|
|
175
|
+
if (isBaseSalesBlankValue(mergedItem.product_cover) && !isBaseSalesBlankValue(currentItem?.product_cover)) {
|
|
206
176
|
mergedItem.product_cover = currentItem.product_cover;
|
|
207
177
|
}
|
|
208
|
-
const currentHolderConfig =
|
|
209
|
-
if ((
|
|
178
|
+
const currentHolderConfig = currentItem?.metadata?.holder_config;
|
|
179
|
+
if ((mergedItem.metadata?.holder_config === undefined || mergedItem.metadata?.holder_config === null) && currentHolderConfig !== undefined && currentHolderConfig !== null) {
|
|
210
180
|
mergedItem.metadata = {
|
|
211
|
-
...mergedItem.metadata || {},
|
|
181
|
+
...(mergedItem.metadata || {}),
|
|
212
182
|
holder_config: currentHolderConfig
|
|
213
183
|
};
|
|
214
184
|
}
|
|
215
185
|
return mergedItem;
|
|
216
186
|
}
|
|
217
187
|
function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps) {
|
|
218
|
-
const currentReferenceUid = (0,
|
|
219
|
-
const incomingReferenceUid = (0,
|
|
220
|
-
const identityMergedItem = (0,
|
|
221
|
-
|
|
222
|
-
currentItem,
|
|
223
|
-
incomingItem
|
|
224
|
-
);
|
|
225
|
-
const mergedUid = (0, import_orderCollectionIdentity.getOrderCollectionUid)(kind, identityMergedItem);
|
|
188
|
+
const currentReferenceUid = (0, _orderCollectionIdentity.getOrderCollectionReferenceUid)(kind, currentItem);
|
|
189
|
+
const incomingReferenceUid = (0, _orderCollectionIdentity.getOrderCollectionReferenceUid)(kind, incomingItem);
|
|
190
|
+
const identityMergedItem = (0, _orderCollectionIdentity.mergeOrderCollectionItems)(kind, currentItem, incomingItem);
|
|
191
|
+
const mergedUid = (0, _orderCollectionIdentity.getOrderCollectionUid)(kind, identityMergedItem);
|
|
226
192
|
if (mergedUid) {
|
|
227
|
-
for (const from of
|
|
228
|
-
if (!from || from === mergedUid)
|
|
229
|
-
continue;
|
|
193
|
+
for (const from of new Set([currentReferenceUid, incomingReferenceUid])) {
|
|
194
|
+
if (!from || from === mergedUid) continue;
|
|
230
195
|
uidRemaps.push({
|
|
231
196
|
kind,
|
|
232
197
|
from,
|
|
233
198
|
to: mergedUid,
|
|
234
|
-
persistentId: (0,
|
|
199
|
+
persistentId: (0, _orderCollectionIdentity.getOrderCollectionPersistentId)(kind, incomingItem) || (0, _orderCollectionIdentity.getOrderCollectionPersistentId)(kind, currentItem)
|
|
235
200
|
});
|
|
236
201
|
}
|
|
237
202
|
}
|
|
238
|
-
const mergedItem = mergedUid ? (0,
|
|
203
|
+
const mergedItem = mergedUid ? (0, _orderCollectionIdentity.setOrderCollectionUid)(kind, incomingItem, mergedUid) : (0, _lodashEs.cloneDeep)(incomingItem);
|
|
239
204
|
const persistentIdField = BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND[kind];
|
|
240
205
|
if (isBaseSalesBlankValue(mergedItem[persistentIdField]) && !isBaseSalesBlankValue(identityMergedItem[persistentIdField])) {
|
|
241
206
|
mergedItem[persistentIdField] = identityMergedItem[persistentIdField];
|
|
242
207
|
}
|
|
243
|
-
return kind ===
|
|
208
|
+
return kind === 'product' ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
|
|
244
209
|
}
|
|
245
210
|
function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
|
|
246
|
-
if (kind ===
|
|
247
|
-
return (0,
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
);
|
|
211
|
+
if (kind === 'payment') {
|
|
212
|
+
return (0, _paymentUtils.mergeOrderPaymentListsByIdentity)(currentValue, incomingValue, strategy === 'preserve-local' ? {
|
|
213
|
+
preserveUnmatchedExisting: true
|
|
214
|
+
} : {
|
|
215
|
+
preserveUnmatchedExistingWhen: payment => (0, _paymentUtils.isIdentifiedPendingOrderPayment)(payment) || !(0, _orderCollectionIdentity.getOrderCollectionPersistentId)('payment', payment)
|
|
216
|
+
});
|
|
254
217
|
}
|
|
255
|
-
const currentItems = (0,
|
|
218
|
+
const currentItems = (0, _orderCollectionIdentity.normalizeOrderCollection)(kind, currentValue, {
|
|
256
219
|
ensureUid: false
|
|
257
220
|
}).items;
|
|
258
|
-
const incomingItems = (0,
|
|
221
|
+
const incomingItems = (0, _orderCollectionIdentity.normalizeOrderCollection)(kind, incomingValue, {
|
|
259
222
|
ensureUid: false
|
|
260
223
|
}).items;
|
|
261
|
-
if (strategy ===
|
|
262
|
-
const
|
|
263
|
-
currentItems.forEach(
|
|
264
|
-
const incomingIndex =
|
|
265
|
-
(incomingItem) => (0, import_orderCollectionIdentity.isSameOrderCollectionItem)(kind, currentItem, incomingItem)
|
|
266
|
-
);
|
|
224
|
+
if (strategy === 'authoritative-incoming') {
|
|
225
|
+
const result = (0, _lodashEs.cloneDeep)(incomingItems);
|
|
226
|
+
currentItems.forEach(currentItem => {
|
|
227
|
+
const incomingIndex = result.findIndex(incomingItem => (0, _orderCollectionIdentity.isSameOrderCollectionItem)(kind, currentItem, incomingItem));
|
|
267
228
|
if (incomingIndex !== -1) {
|
|
268
|
-
|
|
269
|
-
kind,
|
|
270
|
-
currentItem,
|
|
271
|
-
result2[incomingIndex],
|
|
272
|
-
uidRemaps
|
|
273
|
-
);
|
|
229
|
+
result[incomingIndex] = mergeBaseSalesCollectionItem(kind, currentItem, result[incomingIndex], uidRemaps);
|
|
274
230
|
return;
|
|
275
231
|
}
|
|
276
|
-
|
|
277
|
-
|
|
232
|
+
|
|
233
|
+
// 完整服务端快照负责已落库行;仅保留尚未提交的本地新行。
|
|
234
|
+
if (!(0, _orderCollectionIdentity.getOrderCollectionPersistentId)(kind, currentItem)) {
|
|
235
|
+
result.push((0, _lodashEs.cloneDeep)(currentItem));
|
|
278
236
|
}
|
|
279
237
|
});
|
|
280
|
-
return
|
|
238
|
+
return result;
|
|
281
239
|
}
|
|
282
|
-
const result = (0,
|
|
283
|
-
incomingItems.forEach(
|
|
284
|
-
const currentIndex = result.findIndex(
|
|
285
|
-
(currentItem) => (0, import_orderCollectionIdentity.isSameOrderCollectionItem)(kind, currentItem, incomingItem)
|
|
286
|
-
);
|
|
240
|
+
const result = (0, _lodashEs.cloneDeep)(currentItems);
|
|
241
|
+
incomingItems.forEach(incomingItem => {
|
|
242
|
+
const currentIndex = result.findIndex(currentItem => (0, _orderCollectionIdentity.isSameOrderCollectionItem)(kind, currentItem, incomingItem));
|
|
287
243
|
if (currentIndex !== -1) {
|
|
288
|
-
result[currentIndex] = mergeBaseSalesCollectionItem(
|
|
289
|
-
kind,
|
|
290
|
-
result[currentIndex],
|
|
291
|
-
incomingItem,
|
|
292
|
-
uidRemaps
|
|
293
|
-
);
|
|
244
|
+
result[currentIndex] = mergeBaseSalesCollectionItem(kind, result[currentIndex], incomingItem, uidRemaps);
|
|
294
245
|
return;
|
|
295
246
|
}
|
|
296
|
-
result.push((0,
|
|
247
|
+
result.push((0, _lodashEs.cloneDeep)(incomingItem));
|
|
297
248
|
});
|
|
298
249
|
return result;
|
|
299
250
|
}
|
|
300
251
|
function normalizeBaseSalesRecordCollections(sourceRecord, options) {
|
|
301
|
-
const normalizedRecord = (0,
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
).order;
|
|
252
|
+
const normalizedRecord = (0, _orderCollectionIdentity.normalizeOrderCollections)((0, _lodashEs.cloneDeep)(sourceRecord || {}), options).order;
|
|
253
|
+
|
|
254
|
+
// 兼容旧调用方偶尔使用的单数 payment 字段。
|
|
305
255
|
if (Array.isArray(normalizedRecord.payment)) {
|
|
306
|
-
normalizedRecord.payment = (0,
|
|
307
|
-
"payment",
|
|
308
|
-
normalizedRecord.payment,
|
|
309
|
-
options
|
|
310
|
-
).items;
|
|
256
|
+
normalizedRecord.payment = (0, _orderCollectionIdentity.normalizeOrderCollection)('payment', normalizedRecord.payment, options).items;
|
|
311
257
|
}
|
|
312
258
|
return normalizedRecord;
|
|
313
259
|
}
|
|
314
260
|
function getBaseSalesMetadataUid(item, metadataKey) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (uid === void 0 || uid === null || uid === "")
|
|
318
|
-
return null;
|
|
261
|
+
const uid = item?.metadata?.[metadataKey] ?? item?.[metadataKey];
|
|
262
|
+
if (uid === undefined || uid === null || uid === '') return null;
|
|
319
263
|
return String(uid);
|
|
320
264
|
}
|
|
321
265
|
function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
|
|
322
266
|
const result = [];
|
|
323
|
-
const indexByUid =
|
|
324
|
-
const appendOrReplaceByUid =
|
|
325
|
-
const clonedItem = (0,
|
|
267
|
+
const indexByUid = new Map();
|
|
268
|
+
const appendOrReplaceByUid = item => {
|
|
269
|
+
const clonedItem = (0, _lodashEs.cloneDeep)(item);
|
|
326
270
|
const uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
|
|
327
271
|
if (!uid) {
|
|
328
272
|
result.push(clonedItem);
|
|
329
273
|
return;
|
|
330
274
|
}
|
|
331
275
|
const existingIndex = indexByUid.get(uid);
|
|
332
|
-
if (existingIndex !==
|
|
276
|
+
if (existingIndex !== undefined) {
|
|
333
277
|
result[existingIndex] = clonedItem;
|
|
334
278
|
return;
|
|
335
279
|
}
|
|
@@ -341,130 +285,142 @@ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
|
|
|
341
285
|
return result;
|
|
342
286
|
}
|
|
343
287
|
function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
|
|
344
|
-
const normalizedLoadedRecord = normalizeBaseSalesRecordCollections(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
);
|
|
288
|
+
const normalizedLoadedRecord = normalizeBaseSalesRecordCollections(loadedRecord || {}, {
|
|
289
|
+
ensureUid: false
|
|
290
|
+
});
|
|
348
291
|
if (!currentTempOrder) {
|
|
349
292
|
return normalizeBaseSalesRecordCollections(normalizedLoadedRecord);
|
|
350
293
|
}
|
|
351
|
-
const normalizedCurrentTempOrder = normalizeBaseSalesRecordCollections(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
);
|
|
294
|
+
const normalizedCurrentTempOrder = normalizeBaseSalesRecordCollections(currentTempOrder, {
|
|
295
|
+
ensureUid: false
|
|
296
|
+
});
|
|
355
297
|
const uidRemaps = [];
|
|
356
|
-
const mergedRecord = (0,
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
strategy,
|
|
367
|
-
uidRemaps
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
|
|
371
|
-
if (key === "payments" || key === "payment") {
|
|
372
|
-
return (0, import_payment_utils.mergeOrderPaymentListsByIdentity)(currentValue, loadedValue, {
|
|
373
|
-
preserveUnmatchedExisting: true
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
|
|
377
|
-
if (metadataKey) {
|
|
378
|
-
return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
|
|
379
|
-
}
|
|
380
|
-
return [
|
|
381
|
-
...(0, import_lodash_es.cloneDeep)(currentValue),
|
|
382
|
-
...(0, import_lodash_es.cloneDeep)(loadedValue)
|
|
383
|
-
];
|
|
298
|
+
const mergedRecord = (0, _lodashEs.mergeWith)(normalizedCurrentTempOrder, normalizedLoadedRecord, (currentValue, loadedValue, key) => {
|
|
299
|
+
const collectionKind = getBaseSalesOrderCollectionKind(key);
|
|
300
|
+
if (collectionKind && Array.isArray(loadedValue)) {
|
|
301
|
+
return mergeBaseSalesOrderCollection(collectionKind, Array.isArray(currentValue) ? currentValue : [], loadedValue, strategy, uidRemaps);
|
|
302
|
+
}
|
|
303
|
+
if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
|
|
304
|
+
if (key === 'payments' || key === 'payment') {
|
|
305
|
+
return (0, _paymentUtils.mergeOrderPaymentListsByIdentity)(currentValue, loadedValue, {
|
|
306
|
+
preserveUnmatchedExisting: true
|
|
307
|
+
});
|
|
384
308
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return (0, import_lodash_es.cloneDeep)(currentValue);
|
|
309
|
+
const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
|
|
310
|
+
if (metadataKey) {
|
|
311
|
+
return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
|
|
389
312
|
}
|
|
390
|
-
return
|
|
313
|
+
return [...(0, _lodashEs.cloneDeep)(currentValue), ...(0, _lodashEs.cloneDeep)(loadedValue)];
|
|
314
|
+
}
|
|
315
|
+
if (Array.isArray(loadedValue)) return (0, _lodashEs.cloneDeep)(loadedValue);
|
|
316
|
+
if (Array.isArray(currentValue) && loadedValue === undefined) {
|
|
317
|
+
return (0, _lodashEs.cloneDeep)(currentValue);
|
|
391
318
|
}
|
|
392
|
-
|
|
319
|
+
return undefined;
|
|
320
|
+
});
|
|
393
321
|
delete mergedRecord.request_unique_idempotency_token;
|
|
394
|
-
return normalizeBaseSalesRecordCollections(
|
|
395
|
-
(0, import_orderCollectionIdentity.applyOrderCollectionUidRemaps)(mergedRecord, uidRemaps)
|
|
396
|
-
);
|
|
322
|
+
return normalizeBaseSalesRecordCollections((0, _orderCollectionIdentity.applyOrderCollectionUidRemaps)(mergedRecord, uidRemaps));
|
|
397
323
|
}
|
|
398
324
|
function filterPendingPaymentsFromLoadedSalesDetail(sourceRecord) {
|
|
399
|
-
if (!sourceRecord || typeof sourceRecord !==
|
|
400
|
-
|
|
401
|
-
|
|
325
|
+
if (!sourceRecord || typeof sourceRecord !== 'object') return sourceRecord;
|
|
326
|
+
const record = {
|
|
327
|
+
...sourceRecord
|
|
328
|
+
};
|
|
402
329
|
if (Array.isArray(sourceRecord.payments)) {
|
|
403
|
-
record.payments = sourceRecord.payments.filter(
|
|
330
|
+
record.payments = sourceRecord.payments.filter(payment => !(0, _paymentUtils.isPendingOrderPayment)(payment));
|
|
404
331
|
}
|
|
332
|
+
// 兼容少量历史详情数据使用的单数 payment 字段。
|
|
405
333
|
if (Array.isArray(sourceRecord.payment)) {
|
|
406
|
-
record.payment = sourceRecord.payment.filter(
|
|
334
|
+
record.payment = sourceRecord.payment.filter(payment => !(0, _paymentUtils.isPendingOrderPayment)(payment));
|
|
407
335
|
}
|
|
408
336
|
return record;
|
|
409
337
|
}
|
|
410
|
-
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* merge hydrate 不会统一给所有商品补 saved 标记,因此先只标记远端已保存商品。
|
|
341
|
+
* 当前 tempOrder 中尚未提交的本地商品会在 merge 后继续保持 current item 语义。
|
|
342
|
+
*/
|
|
343
|
+
function markLoadedSalesDetailProductsAsSaved(sourceRecord) {
|
|
344
|
+
if (!sourceRecord || typeof sourceRecord !== 'object') return sourceRecord;
|
|
345
|
+
if (!Array.isArray(sourceRecord.products)) return sourceRecord;
|
|
346
|
+
return {
|
|
347
|
+
...sourceRecord,
|
|
348
|
+
products: sourceRecord.products.map(product => ({
|
|
349
|
+
...(product || {}),
|
|
350
|
+
metadata: {
|
|
351
|
+
...(product?.metadata && typeof product.metadata === 'object' ? product.metadata : {}),
|
|
352
|
+
is_edit_for_runtime: true
|
|
353
|
+
}
|
|
354
|
+
}))
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
358
|
+
defaultName = 'baseSales';
|
|
359
|
+
defaultVersion = '1.0.0';
|
|
360
|
+
isSolution = true;
|
|
361
|
+
initializeOptions = {};
|
|
362
|
+
logger; // LoggerManager 实例
|
|
363
|
+
appPlugin;
|
|
364
|
+
store = {
|
|
365
|
+
order: undefined
|
|
366
|
+
};
|
|
367
|
+
otherParams = {};
|
|
368
|
+
cacheId;
|
|
369
|
+
/**
|
|
370
|
+
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
371
|
+
* 未设置时,支付编号仍按原逻辑实时读取设备信息。
|
|
372
|
+
*/
|
|
373
|
+
paymentNumberDevicePrefix = null;
|
|
374
|
+
/**
|
|
375
|
+
* window / request 暴露为 public:现存外部工具(如 BookingTicket Scan)通过
|
|
376
|
+
* `solution.window` / `solution.request` 直接访问插件,保持原有契约不破坏。
|
|
377
|
+
*/
|
|
378
|
+
window;
|
|
379
|
+
request;
|
|
380
|
+
|
|
381
|
+
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
382
|
+
currentSalesDetail = null;
|
|
383
|
+
discountConfigCacheKey = null;
|
|
384
|
+
hasManualDiscountSelection = false;
|
|
385
|
+
reusedSharedSubModuleNames = new Set();
|
|
386
|
+
paymentMethodsCache = [];
|
|
387
|
+
queuedAutoPaymentSync = false;
|
|
388
|
+
autoPaymentSyncFlushing = false;
|
|
389
|
+
autoPaymentSyncTimer = null;
|
|
390
|
+
salesDetailLoadInFlightCount = 0;
|
|
391
|
+
salesDetailLoadSequence = 0;
|
|
392
|
+
walletAssetsRefreshSequence = 0;
|
|
393
|
+
salesDetailHydrateQueue = Promise.resolve();
|
|
394
|
+
serverOrderChangeUnsubscribe = null;
|
|
395
|
+
serverOrderChangeHydrateInFlight = null;
|
|
396
|
+
queuedServerOrderChanges = [];
|
|
397
|
+
serverOrderChangeSyncEnabled = false;
|
|
411
398
|
constructor(name, version) {
|
|
412
399
|
super(name, version);
|
|
413
|
-
this.defaultName = "baseSales";
|
|
414
|
-
this.defaultVersion = "1.0.0";
|
|
415
|
-
this.isSolution = true;
|
|
416
|
-
this.initializeOptions = {};
|
|
417
|
-
this.store = {
|
|
418
|
-
order: void 0
|
|
419
|
-
};
|
|
420
|
-
this.otherParams = {};
|
|
421
|
-
/**
|
|
422
|
-
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
423
|
-
* 未设置时,支付编号仍按原逻辑实时读取设备信息。
|
|
424
|
-
*/
|
|
425
|
-
this.paymentNumberDevicePrefix = null;
|
|
426
|
-
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
427
|
-
this.currentSalesDetail = null;
|
|
428
|
-
this.discountConfigCacheKey = null;
|
|
429
|
-
this.hasManualDiscountSelection = false;
|
|
430
|
-
this.reusedSharedSubModuleNames = /* @__PURE__ */ new Set();
|
|
431
|
-
this.paymentMethodsCache = [];
|
|
432
|
-
this.queuedAutoPaymentSync = false;
|
|
433
|
-
this.autoPaymentSyncFlushing = false;
|
|
434
|
-
this.autoPaymentSyncTimer = null;
|
|
435
|
-
this.salesDetailLoadInFlightCount = 0;
|
|
436
|
-
this.salesDetailLoadSequence = 0;
|
|
437
|
-
this.walletAssetsRefreshSequence = 0;
|
|
438
|
-
this.salesDetailHydrateQueue = Promise.resolve();
|
|
439
|
-
this.serverOrderChangeUnsubscribe = null;
|
|
440
|
-
this.serverOrderChangeHydrateInFlight = null;
|
|
441
|
-
this.queuedServerOrderChanges = [];
|
|
442
|
-
this.serverOrderChangeSyncEnabled = false;
|
|
443
400
|
}
|
|
401
|
+
|
|
444
402
|
/**
|
|
445
403
|
* 子类可覆盖此方法以追加/收敛要注册的子模块。
|
|
446
404
|
* 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation。
|
|
447
405
|
*/
|
|
448
406
|
getRegisteredModuleNames() {
|
|
449
|
-
return [
|
|
407
|
+
return ['products', 'order', 'salesSummary', 'schedule', 'payment', 'quotation'];
|
|
450
408
|
}
|
|
451
409
|
getReusableSharedSubModule(moduleName) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return null;
|
|
455
|
-
return ((_b = (_a = this.core) == null ? void 0 : _a.getModule) == null ? void 0 : _b.call(_a, moduleName)) || null;
|
|
410
|
+
if (moduleName !== 'schedule' && moduleName !== 'quotation') return null;
|
|
411
|
+
return this.core?.getModule?.(moduleName) || null;
|
|
456
412
|
}
|
|
457
413
|
isScheduleListLoaded(scheduleModule) {
|
|
458
|
-
if (!scheduleModule)
|
|
459
|
-
|
|
460
|
-
if (typeof scheduleModule.isScheduleListLoaded === "function") {
|
|
414
|
+
if (!scheduleModule) return false;
|
|
415
|
+
if (typeof scheduleModule.isScheduleListLoaded === 'function') {
|
|
461
416
|
return scheduleModule.isScheduleListLoaded();
|
|
462
417
|
}
|
|
463
|
-
if (typeof scheduleModule.getScheduleList ===
|
|
418
|
+
if (typeof scheduleModule.getScheduleList === 'function') {
|
|
464
419
|
return Array.isArray(scheduleModule.getScheduleList());
|
|
465
420
|
}
|
|
466
421
|
return false;
|
|
467
422
|
}
|
|
423
|
+
|
|
468
424
|
/**
|
|
469
425
|
* 记录信息日志
|
|
470
426
|
*/
|
|
@@ -472,12 +428,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
472
428
|
if (this.logger) {
|
|
473
429
|
const tempOrder = this.getTempOrder();
|
|
474
430
|
this.logger.addLog({
|
|
475
|
-
type:
|
|
476
|
-
title: `[BaseSales] ${tempOrder
|
|
431
|
+
type: 'info',
|
|
432
|
+
title: `[BaseSales] ${tempOrder?.order_id} ${tempOrder?.external_sale_number} ${title}`,
|
|
477
433
|
metadata: metadata || {}
|
|
478
434
|
});
|
|
479
435
|
}
|
|
480
436
|
}
|
|
437
|
+
|
|
481
438
|
/**
|
|
482
439
|
* 记录警告日志
|
|
483
440
|
*/
|
|
@@ -485,12 +442,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
485
442
|
if (this.logger) {
|
|
486
443
|
const tempOrder = this.getTempOrder();
|
|
487
444
|
this.logger.addLog({
|
|
488
|
-
type:
|
|
489
|
-
title: `[BaseSales] ${tempOrder
|
|
445
|
+
type: 'warning',
|
|
446
|
+
title: `[BaseSales] ${tempOrder?.order_id} ${tempOrder?.external_sale_number} ${title}`,
|
|
490
447
|
metadata: metadata || {}
|
|
491
448
|
});
|
|
492
449
|
}
|
|
493
450
|
}
|
|
451
|
+
|
|
494
452
|
/**
|
|
495
453
|
* 记录错误日志
|
|
496
454
|
*/
|
|
@@ -498,31 +456,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
498
456
|
if (this.logger) {
|
|
499
457
|
const tempOrder = this.getTempOrder();
|
|
500
458
|
this.logger.addLog({
|
|
501
|
-
type:
|
|
502
|
-
title: `[BaseSales] ${tempOrder
|
|
459
|
+
type: 'error',
|
|
460
|
+
title: `[BaseSales] ${tempOrder?.order_id} ${tempOrder?.external_sale_number} ${title}`,
|
|
503
461
|
metadata: metadata || {}
|
|
504
462
|
});
|
|
505
463
|
}
|
|
506
464
|
}
|
|
507
465
|
isCurrentSalesOrderRecord(order) {
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
currentTempOrder,
|
|
512
|
-
this.currentSalesDetail
|
|
513
|
-
].filter(Boolean);
|
|
514
|
-
return currentRecords.some((record) => isSameBaseSalesOrderRecord(record, order));
|
|
466
|
+
const currentTempOrder = this.store.order?.getTempOrder?.();
|
|
467
|
+
const currentRecords = [currentTempOrder, this.currentSalesDetail].filter(Boolean);
|
|
468
|
+
return currentRecords.some(record => isSameBaseSalesOrderRecord(record, order));
|
|
515
469
|
}
|
|
516
470
|
setServerOrderChangeSyncEnabled(enabled) {
|
|
517
471
|
this.serverOrderChangeSyncEnabled = enabled;
|
|
518
|
-
if (!enabled)
|
|
519
|
-
this.queuedServerOrderChanges = [];
|
|
472
|
+
if (!enabled) this.queuedServerOrderChanges = [];
|
|
520
473
|
}
|
|
521
474
|
queueLatestServerOrderChange(order) {
|
|
522
|
-
const snapshot = (0,
|
|
523
|
-
const existingIndex = this.queuedServerOrderChanges.findIndex(
|
|
524
|
-
(queued) => isSameBaseSalesOrderRecord(queued, snapshot)
|
|
525
|
-
);
|
|
475
|
+
const snapshot = (0, _lodashEs.cloneDeep)(order);
|
|
476
|
+
const existingIndex = this.queuedServerOrderChanges.findIndex(queued => isSameBaseSalesOrderRecord(queued, snapshot));
|
|
526
477
|
if (existingIndex >= 0) {
|
|
527
478
|
this.queuedServerOrderChanges[existingIndex] = snapshot;
|
|
528
479
|
return;
|
|
@@ -530,46 +481,40 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
530
481
|
this.queuedServerOrderChanges.push(snapshot);
|
|
531
482
|
}
|
|
532
483
|
async drainQueuedServerOrderChanges() {
|
|
533
|
-
if (!this.serverOrderChangeSyncEnabled || this.salesDetailLoadInFlightCount > 0 || this.serverOrderChangeHydrateInFlight || this.queuedServerOrderChanges.length === 0)
|
|
534
|
-
return;
|
|
484
|
+
if (!this.serverOrderChangeSyncEnabled || this.salesDetailLoadInFlightCount > 0 || this.serverOrderChangeHydrateInFlight || this.queuedServerOrderChanges.length === 0) return;
|
|
535
485
|
const changedOrders = this.queuedServerOrderChanges;
|
|
536
486
|
this.queuedServerOrderChanges = [];
|
|
537
|
-
await this.syncCurrentSalesDetailFromServerOrderChange({
|
|
487
|
+
await this.syncCurrentSalesDetailFromServerOrderChange({
|
|
488
|
+
changedOrders
|
|
489
|
+
});
|
|
538
490
|
}
|
|
539
491
|
async syncCurrentSalesDetailFromServerOrderChange(payload) {
|
|
540
|
-
const changedOrders = Array.isArray(payload) ? payload : Array.isArray(payload
|
|
541
|
-
if (!this.serverOrderChangeSyncEnabled)
|
|
542
|
-
|
|
492
|
+
const changedOrders = Array.isArray(payload) ? payload : Array.isArray(payload?.changedOrders) ? payload.changedOrders : payload?.data && typeof payload.data === 'object' ? [payload.data] : [];
|
|
493
|
+
if (!this.serverOrderChangeSyncEnabled) return;
|
|
494
|
+
|
|
495
|
+
// 显式详情加载期间 current 可能仍是上一单,先按订单身份 latest-only 缓存;
|
|
496
|
+
// load 完成后再用新的 current 过滤,避免恰好到达的最新支付快照丢失。
|
|
543
497
|
if (this.salesDetailLoadInFlightCount > 0) {
|
|
544
|
-
changedOrders.forEach(
|
|
545
|
-
(order) => this.queueLatestServerOrderChange(order)
|
|
546
|
-
);
|
|
498
|
+
changedOrders.forEach(order => this.queueLatestServerOrderChange(order));
|
|
547
499
|
return;
|
|
548
500
|
}
|
|
549
|
-
const changedOrder = changedOrders.find(
|
|
550
|
-
|
|
551
|
-
);
|
|
552
|
-
if (!changedOrder)
|
|
553
|
-
return;
|
|
501
|
+
const changedOrder = changedOrders.find(order => this.isCurrentSalesOrderRecord(order));
|
|
502
|
+
if (!changedOrder) return;
|
|
554
503
|
if (this.serverOrderChangeHydrateInFlight) {
|
|
555
504
|
this.queueLatestServerOrderChange(changedOrder);
|
|
556
505
|
return;
|
|
557
506
|
}
|
|
558
|
-
if (!this.store.order)
|
|
559
|
-
return;
|
|
507
|
+
if (!this.store.order) return;
|
|
560
508
|
this.serverOrderChangeHydrateInFlight = (async () => {
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
const record = mergeSalesDetailRecordWithTempOrder(
|
|
564
|
-
currentTempOrder,
|
|
565
|
-
changedOrder,
|
|
566
|
-
"authoritative-incoming"
|
|
567
|
-
);
|
|
509
|
+
const currentTempOrder = this.store.order.getTempOrder?.();
|
|
510
|
+
const record = mergeSalesDetailRecordWithTempOrder(currentTempOrder, changedOrder, 'authoritative-incoming');
|
|
568
511
|
const sales = await this.store.order.hydrateTempOrderFromRecord(record, {
|
|
569
512
|
recalcOnHydrate: false
|
|
570
513
|
});
|
|
571
514
|
this.currentSalesDetail = sales;
|
|
572
|
-
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, {
|
|
515
|
+
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, {
|
|
516
|
+
sales
|
|
517
|
+
});
|
|
573
518
|
})();
|
|
574
519
|
try {
|
|
575
520
|
await this.serverOrderChangeHydrateInFlight;
|
|
@@ -579,72 +524,81 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
579
524
|
}
|
|
580
525
|
}
|
|
581
526
|
registerServerOrderChangeSync() {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
return
|
|
587
|
-
|
|
588
|
-
return this.syncCurrentSalesDetailFromServerOrderChange(payload).catch((error) => {
|
|
589
|
-
this.logError("sync sales detail from server order change failed", {
|
|
527
|
+
this.serverOrderChangeUnsubscribe?.();
|
|
528
|
+
const effects = this.core?.effects;
|
|
529
|
+
if (!effects || typeof effects.on !== 'function') return;
|
|
530
|
+
this.serverOrderChangeUnsubscribe = effects.on(SERVER_ORDER_CHANGED_EVENT, payload => {
|
|
531
|
+
return this.syncCurrentSalesDetailFromServerOrderChange(payload).catch(error => {
|
|
532
|
+
this.logError('sync sales detail from server order change failed', {
|
|
590
533
|
error: error instanceof Error ? error.message : String(error)
|
|
591
534
|
});
|
|
592
535
|
});
|
|
593
536
|
});
|
|
594
537
|
}
|
|
595
|
-
async hydrateLatestLoadedSalesDetail(record, loadSequence,
|
|
538
|
+
async hydrateLatestLoadedSalesDetail(record, loadSequence, options) {
|
|
596
539
|
let hydratedSales = null;
|
|
597
540
|
let skippedBeforeHydrate = false;
|
|
598
541
|
const hydrateTask = async () => {
|
|
542
|
+
// 网络返回顺序可能倒置;只有当前最新显式加载可以进入共享 tempOrder。
|
|
599
543
|
if (loadSequence !== this.salesDetailLoadSequence) {
|
|
600
544
|
skippedBeforeHydrate = true;
|
|
601
545
|
return;
|
|
602
546
|
}
|
|
603
|
-
if (!this.store.order)
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
547
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
548
|
+
let hydrateOptions = {
|
|
549
|
+
recalcOnHydrate: false
|
|
550
|
+
};
|
|
551
|
+
if (options?.hydrateSource === 'sessionStorage') {
|
|
552
|
+
hydrateOptions = {
|
|
553
|
+
recalcOnHydrate: true,
|
|
554
|
+
source: 'sessionStorage'
|
|
555
|
+
};
|
|
556
|
+
} else if (options?.merge) {
|
|
557
|
+
hydrateOptions = {
|
|
558
|
+
recalcOnHydrate: true,
|
|
559
|
+
source: 'mergedSalesDetail'
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
const sales = await this.store.order.hydrateTempOrderFromRecord(record, hydrateOptions);
|
|
609
563
|
hydratedSales = sales;
|
|
610
|
-
|
|
611
|
-
|
|
564
|
+
|
|
565
|
+
// hydrate 期间可能又发起了更新请求;后续任务已串行排队,将负责最终状态。
|
|
566
|
+
if (loadSequence !== this.salesDetailLoadSequence) return;
|
|
612
567
|
this.currentSalesDetail = sales;
|
|
613
|
-
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, {
|
|
568
|
+
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, {
|
|
569
|
+
sales
|
|
570
|
+
});
|
|
614
571
|
};
|
|
615
572
|
const queuedTask = this.salesDetailHydrateQueue.then(hydrateTask, hydrateTask);
|
|
616
|
-
this.salesDetailHydrateQueue = queuedTask.then(
|
|
617
|
-
() => void 0,
|
|
618
|
-
() => void 0
|
|
619
|
-
);
|
|
573
|
+
this.salesDetailHydrateQueue = queuedTask.then(() => undefined, () => undefined);
|
|
620
574
|
await queuedTask;
|
|
621
|
-
if (skippedBeforeHydrate)
|
|
622
|
-
return record;
|
|
575
|
+
if (skippedBeforeHydrate) return record;
|
|
623
576
|
return hydratedSales || this.currentSalesDetail || record;
|
|
624
577
|
}
|
|
625
578
|
hydrateOrderPaymentNames(payments) {
|
|
626
|
-
if (!payments.length)
|
|
627
|
-
return [];
|
|
579
|
+
if (!payments.length) return [];
|
|
628
580
|
if (!this.paymentMethodsCache.length) {
|
|
629
|
-
return payments.map(
|
|
581
|
+
return payments.map(payment => ({
|
|
582
|
+
...payment
|
|
583
|
+
}));
|
|
630
584
|
}
|
|
631
|
-
const paymentMethodById =
|
|
632
|
-
const paymentMethodByCode =
|
|
633
|
-
this.paymentMethodsCache.forEach(
|
|
634
|
-
if (
|
|
585
|
+
const paymentMethodById = new Map();
|
|
586
|
+
const paymentMethodByCode = new Map();
|
|
587
|
+
this.paymentMethodsCache.forEach(method => {
|
|
588
|
+
if (method?.id !== undefined && method?.id !== null) {
|
|
635
589
|
paymentMethodById.set(String(method.id), method);
|
|
636
590
|
}
|
|
637
|
-
if (method
|
|
591
|
+
if (method?.code) {
|
|
638
592
|
paymentMethodByCode.set(String(method.code), method);
|
|
639
593
|
}
|
|
640
594
|
});
|
|
641
|
-
return payments.map(
|
|
642
|
-
const nextPayment = {
|
|
643
|
-
|
|
644
|
-
|
|
595
|
+
return payments.map(payment => {
|
|
596
|
+
const nextPayment = {
|
|
597
|
+
...payment
|
|
598
|
+
};
|
|
599
|
+
if (nextPayment.name) return nextPayment;
|
|
645
600
|
const paymentMethod = paymentMethodById.get(String(nextPayment.custom_payment_id)) || paymentMethodByCode.get(String(nextPayment.code));
|
|
646
|
-
if (!
|
|
647
|
-
return nextPayment;
|
|
601
|
+
if (!paymentMethod?.name) return nextPayment;
|
|
648
602
|
return {
|
|
649
603
|
...nextPayment,
|
|
650
604
|
name: paymentMethod.name
|
|
@@ -655,68 +609,58 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
655
609
|
return this.store.payment;
|
|
656
610
|
}
|
|
657
611
|
getCurrentOrderCustomerId() {
|
|
658
|
-
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
if (customerId === null || customerId === void 0)
|
|
662
|
-
return void 0;
|
|
612
|
+
const tempOrder = this.store.order?.getTempOrder?.();
|
|
613
|
+
const customerId = tempOrder?.customer_id;
|
|
614
|
+
if (customerId === null || customerId === undefined) return undefined;
|
|
663
615
|
return customerId;
|
|
664
616
|
}
|
|
665
617
|
normalizePriceContextCustomerId(customerId) {
|
|
666
|
-
if (customerId ===
|
|
667
|
-
return null;
|
|
618
|
+
if (customerId === undefined || customerId === null || customerId === '') return null;
|
|
668
619
|
return String(customerId);
|
|
669
620
|
}
|
|
670
621
|
applyQuotationScheduleResolver(quotation) {
|
|
671
622
|
const scheduleModule = this.store.schedule;
|
|
672
|
-
if (!scheduleModule)
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
const scheduleList = typeof scheduleModule.getScheduleList === "function" ? scheduleModule.getScheduleList() : [];
|
|
623
|
+
if (!scheduleModule) return;
|
|
624
|
+
const scheduleById = new Map();
|
|
625
|
+
const scheduleList = typeof scheduleModule.getScheduleList === 'function' ? scheduleModule.getScheduleList() : [];
|
|
676
626
|
if (Array.isArray(scheduleList)) {
|
|
677
|
-
scheduleList.forEach(
|
|
678
|
-
if (
|
|
627
|
+
scheduleList.forEach(schedule => {
|
|
628
|
+
if (schedule?.id !== undefined && schedule?.id !== null) {
|
|
679
629
|
scheduleById.set(String(schedule.id), schedule);
|
|
680
630
|
}
|
|
681
631
|
});
|
|
682
632
|
}
|
|
683
|
-
quotation.setScheduleResolver(
|
|
684
|
-
var _a, _b;
|
|
633
|
+
quotation.setScheduleResolver(id => {
|
|
685
634
|
const scheduleId = String(id);
|
|
686
|
-
if (scheduleById.has(scheduleId))
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
if (schedules[0])
|
|
690
|
-
scheduleById.set(scheduleId, schedules[0]);
|
|
635
|
+
if (scheduleById.has(scheduleId)) return scheduleById.get(scheduleId);
|
|
636
|
+
const schedules = scheduleModule.getScheduleListByIds?.([id]) || scheduleModule.getScheduleByIds?.([id]) || [];
|
|
637
|
+
if (schedules[0]) scheduleById.set(scheduleId, schedules[0]);
|
|
691
638
|
return schedules[0];
|
|
692
639
|
});
|
|
693
640
|
}
|
|
694
641
|
async loadQuotationForPriceQuery(params) {
|
|
695
|
-
|
|
696
|
-
if (!params.quotation)
|
|
697
|
-
return;
|
|
642
|
+
if (!params.quotation) return;
|
|
698
643
|
this.applyQuotationScheduleResolver(params.quotation);
|
|
699
644
|
await params.quotation.loadQuotations({
|
|
700
|
-
channel: params.channel ||
|
|
645
|
+
channel: params.channel || this.otherParams?.channel,
|
|
701
646
|
customer_id: params.customer_id
|
|
702
647
|
});
|
|
703
648
|
}
|
|
704
649
|
getPriceQueryProductId(product) {
|
|
705
|
-
const productId = Number(
|
|
706
|
-
if (!Number.isFinite(productId))
|
|
707
|
-
return null;
|
|
650
|
+
const productId = Number(product?.product_id ?? product?.id);
|
|
651
|
+
if (!Number.isFinite(productId)) return null;
|
|
708
652
|
return productId;
|
|
709
653
|
}
|
|
654
|
+
|
|
710
655
|
/**
|
|
711
656
|
* Change Time / customer reprice 必须沿用商品列表的渠道口径。
|
|
712
657
|
* SalesSdk Provider 通常将渠道存为 platform,因此不能只读取 otherParams.channel。
|
|
713
658
|
*/
|
|
714
659
|
getPriceQueryChannel(channel) {
|
|
715
|
-
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
return void 0;
|
|
660
|
+
const strategyContext = this.otherParams?.strategy_context && typeof this.otherParams.strategy_context === 'object' ? this.otherParams.strategy_context : {};
|
|
661
|
+
const value = channel ?? strategyContext.channel ?? this.otherParams?.channel ?? this.otherParams?.platform;
|
|
662
|
+
if (value === undefined || value === null || String(value).trim() === '') {
|
|
663
|
+
return undefined;
|
|
720
664
|
}
|
|
721
665
|
return String(value).trim();
|
|
722
666
|
}
|
|
@@ -725,14 +669,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
725
669
|
* application_code 仅作为接口兼容字段,不能替代 channel / business_code。
|
|
726
670
|
*/
|
|
727
671
|
getPriceQueryStrategyContext(channel) {
|
|
728
|
-
|
|
729
|
-
const
|
|
730
|
-
|
|
672
|
+
const inherited = this.otherParams?.strategy_context && typeof this.otherParams.strategy_context === 'object' ? this.otherParams.strategy_context : {};
|
|
673
|
+
const strategyContext = {
|
|
674
|
+
...inherited
|
|
675
|
+
};
|
|
731
676
|
const resolvedChannel = this.getPriceQueryChannel(channel);
|
|
732
|
-
const businessCode = strategyContext.business_code ??
|
|
733
|
-
if (resolvedChannel)
|
|
734
|
-
|
|
735
|
-
if (businessCode !== void 0 && businessCode !== null && String(businessCode).trim() !== "") {
|
|
677
|
+
const businessCode = strategyContext.business_code ?? this.otherParams?.businessCode ?? this.otherParams?.business_code;
|
|
678
|
+
if (resolvedChannel) strategyContext.channel = resolvedChannel;
|
|
679
|
+
if (businessCode !== undefined && businessCode !== null && String(businessCode).trim() !== '') {
|
|
736
680
|
strategyContext.business_code = String(businessCode).trim();
|
|
737
681
|
}
|
|
738
682
|
const availableWalletIds = this.getAvailableWalletIds();
|
|
@@ -741,11 +685,12 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
741
685
|
}
|
|
742
686
|
return strategyContext;
|
|
743
687
|
}
|
|
688
|
+
|
|
744
689
|
/**
|
|
745
690
|
* 子类可在商品重报价前准备客户维度的策略上下文,例如等待 Wallet/优惠资产加载。
|
|
746
691
|
*/
|
|
747
|
-
async prepareProductPriceQueryContext(_customerId) {
|
|
748
|
-
|
|
692
|
+
async prepareProductPriceQueryContext(_customerId) {}
|
|
693
|
+
|
|
749
694
|
/**
|
|
750
695
|
* 默认保留 BaseSales 的 legacy quotation 行为;已由 /product/query 统一完成
|
|
751
696
|
* 智能定价与报价合并的业务可在子类中覆盖,避免二次覆盖权威价格。
|
|
@@ -755,69 +700,64 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
755
700
|
}
|
|
756
701
|
getPriceQuerySchedule(params) {
|
|
757
702
|
const booking = params.booking || {};
|
|
758
|
-
if (typeof booking.start_date ===
|
|
703
|
+
if (typeof booking.start_date === 'string' && booking.start_date.trim()) {
|
|
759
704
|
const scheduleDate = booking.start_date.trim();
|
|
760
|
-
const startTime = typeof booking.start_time ===
|
|
761
|
-
const datetime = (0,
|
|
705
|
+
const startTime = typeof booking.start_time === 'string' && booking.start_time.trim() ? booking.start_time.trim() : '00:00:00';
|
|
706
|
+
const datetime = (0, _dayjs.default)(`${scheduleDate} ${startTime}`);
|
|
762
707
|
return {
|
|
763
708
|
schedule_date: scheduleDate,
|
|
764
|
-
schedule_datetime: datetime.isValid() ? datetime.format(
|
|
709
|
+
schedule_datetime: datetime.isValid() ? datetime.format('YYYY-MM-DD HH:mm:ss') : `${scheduleDate} ${startTime}`
|
|
765
710
|
};
|
|
766
711
|
}
|
|
767
|
-
if (typeof params.datetime ===
|
|
768
|
-
const datetime = (0,
|
|
712
|
+
if (typeof params.datetime === 'string' && params.datetime.trim()) {
|
|
713
|
+
const datetime = (0, _dayjs.default)(params.datetime.trim());
|
|
769
714
|
if (datetime.isValid()) {
|
|
770
715
|
return {
|
|
771
|
-
schedule_date: datetime.format(
|
|
772
|
-
schedule_datetime: datetime.format(
|
|
716
|
+
schedule_date: datetime.format('YYYY-MM-DD'),
|
|
717
|
+
schedule_datetime: datetime.format('YYYY-MM-DD HH:mm:ss')
|
|
773
718
|
};
|
|
774
719
|
}
|
|
775
720
|
}
|
|
776
|
-
const now = (0,
|
|
721
|
+
const now = (0, _dayjs.default)();
|
|
777
722
|
return {
|
|
778
|
-
schedule_date: now.format(
|
|
779
|
-
schedule_datetime: now.format(
|
|
723
|
+
schedule_date: now.format('YYYY-MM-DD'),
|
|
724
|
+
schedule_datetime: now.format('YYYY-MM-DD HH:mm:ss')
|
|
780
725
|
};
|
|
781
726
|
}
|
|
782
727
|
async loadProductsForPriceQuery(params) {
|
|
783
|
-
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
));
|
|
787
|
-
const productsById = /* @__PURE__ */ new Map();
|
|
788
|
-
if (!ids.length || !this.request)
|
|
789
|
-
return productsById;
|
|
728
|
+
const ids = Array.from(new Set(params.ids.filter(id => Number.isFinite(id))));
|
|
729
|
+
const productsById = new Map();
|
|
730
|
+
if (!ids.length || !this.request) return productsById;
|
|
790
731
|
const channel = this.getPriceQueryChannel(params.channel);
|
|
791
732
|
const strategyContext = this.getPriceQueryStrategyContext(channel);
|
|
792
733
|
try {
|
|
793
|
-
const response = await this.request.post(
|
|
734
|
+
const response = await this.request.post('/product/query', {
|
|
794
735
|
ids,
|
|
795
736
|
open_quotation: 1,
|
|
796
737
|
open_bundle: 1,
|
|
797
|
-
status:
|
|
738
|
+
status: 'published',
|
|
798
739
|
num: 1,
|
|
799
740
|
skip: 1,
|
|
800
741
|
customer_id: params.customerId,
|
|
801
742
|
schedule_date: params.schedule.schedule_date,
|
|
802
743
|
schedule_datetime: params.schedule.schedule_datetime,
|
|
803
744
|
application_code: channel,
|
|
804
|
-
...Object.keys(strategyContext).length ? {
|
|
745
|
+
...(Object.keys(strategyContext).length ? {
|
|
746
|
+
strategy_context: strategyContext
|
|
747
|
+
} : {})
|
|
805
748
|
}, {
|
|
806
749
|
osServer: true,
|
|
807
|
-
customToast: () => {
|
|
808
|
-
}
|
|
750
|
+
customToast: () => {}
|
|
809
751
|
});
|
|
810
|
-
const list =
|
|
811
|
-
if (!Array.isArray(list))
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (Number.isFinite(productId))
|
|
816
|
-
productsById.set(productId, item);
|
|
752
|
+
const list = response?.data?.list || response?.list || [];
|
|
753
|
+
if (!Array.isArray(list)) return productsById;
|
|
754
|
+
list.forEach(item => {
|
|
755
|
+
const productId = Number(item?.id ?? item?.product_id);
|
|
756
|
+
if (Number.isFinite(productId)) productsById.set(productId, item);
|
|
817
757
|
});
|
|
818
758
|
return productsById;
|
|
819
759
|
} catch (error) {
|
|
820
|
-
this.logWarning(
|
|
760
|
+
this.logWarning('loadProductsForPriceQuery: 商品批量重查失败,使用入参 fallback', {
|
|
821
761
|
ids,
|
|
822
762
|
error: error instanceof Error ? error.message : String(error)
|
|
823
763
|
});
|
|
@@ -827,8 +767,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
827
767
|
async loadProductForPriceQuery(params, customerId) {
|
|
828
768
|
const product = params.product || {};
|
|
829
769
|
const productId = this.getPriceQueryProductId(product);
|
|
830
|
-
if (productId === null || !this.request)
|
|
831
|
-
return null;
|
|
770
|
+
if (productId === null || !this.request) return null;
|
|
832
771
|
const schedule = this.getPriceQuerySchedule(params);
|
|
833
772
|
const productsById = await this.loadProductsForPriceQuery({
|
|
834
773
|
ids: [productId],
|
|
@@ -839,34 +778,30 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
839
778
|
return productsById.get(productId) || null;
|
|
840
779
|
}
|
|
841
780
|
getAuthoritativeBundleItems(product) {
|
|
842
|
-
if (Array.isArray(product
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
return items.map((item) => ({
|
|
781
|
+
if (Array.isArray(product?.product_bundle)) return product.product_bundle;
|
|
782
|
+
const groups = Array.isArray(product?.bundle_group) ? product.bundle_group : Array.isArray(product?.bundleGroup) ? product.bundleGroup : [];
|
|
783
|
+
return groups.flatMap(group => {
|
|
784
|
+
const items = Array.isArray(group?.bundle_item) ? group.bundle_item : Array.isArray(group?.bundleItem) ? group.bundleItem : [];
|
|
785
|
+
return items.map(item => ({
|
|
848
786
|
...item,
|
|
849
|
-
group_id:
|
|
850
|
-
bundle_group_id:
|
|
787
|
+
group_id: item?.group_id ?? group?.id,
|
|
788
|
+
bundle_group_id: item?.bundle_group_id ?? item?.group_id ?? group?.id
|
|
851
789
|
}));
|
|
852
790
|
});
|
|
853
791
|
}
|
|
854
792
|
findAuthoritativeBundleItem(bundle, candidates) {
|
|
855
793
|
const bundleId = bundle.bundle_id ?? bundle.id;
|
|
856
794
|
if (bundleId != null) {
|
|
857
|
-
const matchedById = candidates.find(
|
|
858
|
-
if (matchedById)
|
|
859
|
-
return matchedById;
|
|
795
|
+
const matchedById = candidates.find(item => String(item?.bundle_id ?? item?.id) === String(bundleId));
|
|
796
|
+
if (matchedById) return matchedById;
|
|
860
797
|
}
|
|
861
798
|
const productId = bundle.bundle_product_id ?? bundle._bundle_product_id;
|
|
862
799
|
const groupId = bundle.bundle_group_id ?? bundle.group_id;
|
|
863
|
-
return candidates.find(
|
|
864
|
-
const itemProductId =
|
|
865
|
-
const itemGroupId =
|
|
866
|
-
if (productId == null || String(itemProductId) !== String(productId))
|
|
867
|
-
|
|
868
|
-
if (groupId == null)
|
|
869
|
-
return true;
|
|
800
|
+
return candidates.find(item => {
|
|
801
|
+
const itemProductId = item?.bundle_product_id ?? item?._bundle_product_id;
|
|
802
|
+
const itemGroupId = item?.bundle_group_id ?? item?.group_id;
|
|
803
|
+
if (productId == null || String(itemProductId) !== String(productId)) return false;
|
|
804
|
+
if (groupId == null) return true;
|
|
870
805
|
return String(itemGroupId) === String(groupId);
|
|
871
806
|
}) || null;
|
|
872
807
|
}
|
|
@@ -874,21 +809,19 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
874
809
|
return bundle.price ?? bundle.bundle_selling_price ?? bundle.custom_price ?? bundle.product_price ?? bundle.base_price;
|
|
875
810
|
}
|
|
876
811
|
mergeProductForPriceQuery(product, authoritativeProduct) {
|
|
877
|
-
if (!authoritativeProduct)
|
|
878
|
-
return product;
|
|
812
|
+
if (!authoritativeProduct) return product;
|
|
879
813
|
const selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
880
814
|
const authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
|
|
881
|
-
const productBundle = selectedBundles.map(
|
|
815
|
+
const productBundle = selectedBundles.map(bundle => {
|
|
882
816
|
const authoritativeBundle = this.findAuthoritativeBundleItem(bundle, authoritativeBundles);
|
|
883
|
-
const unitPrice = authoritativeBundle ? this.getAuthoritativeBundleUnitPrice(authoritativeBundle) :
|
|
884
|
-
if (unitPrice ===
|
|
885
|
-
return bundle;
|
|
817
|
+
const unitPrice = authoritativeBundle ? this.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
|
|
818
|
+
if (unitPrice === undefined || unitPrice === null || unitPrice === '') return bundle;
|
|
886
819
|
return {
|
|
887
820
|
...bundle,
|
|
888
821
|
price: unitPrice,
|
|
889
822
|
bundle_selling_price: unitPrice,
|
|
890
|
-
base_price:
|
|
891
|
-
product_price:
|
|
823
|
+
base_price: authoritativeBundle?.base_price ?? bundle.base_price,
|
|
824
|
+
product_price: authoritativeBundle?.product_price ?? bundle.product_price
|
|
892
825
|
};
|
|
893
826
|
});
|
|
894
827
|
return {
|
|
@@ -900,9 +833,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
900
833
|
num: product.num ?? product.quantity ?? authoritativeProduct.num,
|
|
901
834
|
quantity: product.quantity ?? product.num ?? authoritativeProduct.quantity,
|
|
902
835
|
product_sku: (() => {
|
|
903
|
-
const authoritativeSku = (0,
|
|
904
|
-
const productSku = (0,
|
|
905
|
-
const hasProductSku = product.product_sku && typeof product.product_sku ===
|
|
836
|
+
const authoritativeSku = (0, _utils.ensureProductSku)(authoritativeProduct);
|
|
837
|
+
const productSku = (0, _utils.ensureProductSku)(product);
|
|
838
|
+
const hasProductSku = product.product_sku && typeof product.product_sku === 'object';
|
|
906
839
|
return {
|
|
907
840
|
...authoritativeSku,
|
|
908
841
|
...productSku,
|
|
@@ -914,30 +847,97 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
914
847
|
};
|
|
915
848
|
}
|
|
916
849
|
getSubmitOrderSalesChannel() {
|
|
917
|
-
|
|
918
|
-
return (_a = this.otherParams) == null ? void 0 : _a.channel;
|
|
850
|
+
return this.otherParams?.channel;
|
|
919
851
|
}
|
|
852
|
+
|
|
853
|
+
/** Subclasses with target-scoped OpenData override this guard before reusing the cache. */
|
|
854
|
+
isInvoiceOpenDataCacheCurrent() {
|
|
855
|
+
return true;
|
|
856
|
+
}
|
|
857
|
+
getFulfillmentRefModeConfigs() {
|
|
858
|
+
const candidates = [this.otherParams?.openData, this.otherParams?.dineInConfig, this.store?.openData?.getOpenData?.()];
|
|
859
|
+
return candidates.filter(candidate => candidate && typeof candidate === 'object' && !Array.isArray(candidate));
|
|
860
|
+
}
|
|
861
|
+
getFulfillmentRefMode() {
|
|
862
|
+
for (const config of this.getFulfillmentRefModeConfigs()) {
|
|
863
|
+
const mode = config['fulfillment.fulfillment_ref_mode'];
|
|
864
|
+
if (mode === undefined || mode === null) continue;
|
|
865
|
+
const normalized = String(mode).trim();
|
|
866
|
+
if (normalized) return normalized;
|
|
867
|
+
}
|
|
868
|
+
return undefined;
|
|
869
|
+
}
|
|
870
|
+
getCachedInvoiceLayoutConfig() {
|
|
871
|
+
const openDataModule = this.store?.openData;
|
|
872
|
+
if (typeof openDataModule?.getInvoiceLayoutConfig !== 'function') return undefined;
|
|
873
|
+
if (!this.isInvoiceOpenDataCacheCurrent()) return undefined;
|
|
874
|
+
try {
|
|
875
|
+
return openDataModule.getInvoiceLayoutConfig();
|
|
876
|
+
} catch (error) {
|
|
877
|
+
this.logWarning('读取 Invoice OpenData 布局失败,提交时不注入布局配置', {
|
|
878
|
+
error: error instanceof Error ? error.message : String(error)
|
|
879
|
+
});
|
|
880
|
+
return undefined;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
getCachedInvoiceTemplateSettings() {
|
|
884
|
+
const openDataModule = this.store?.openData;
|
|
885
|
+
if (typeof openDataModule?.getInvoiceTemplateSettings !== 'function') return undefined;
|
|
886
|
+
if (!this.isInvoiceOpenDataCacheCurrent()) return undefined;
|
|
887
|
+
try {
|
|
888
|
+
return openDataModule.getInvoiceTemplateSettings();
|
|
889
|
+
} catch (error) {
|
|
890
|
+
this.logWarning('读取 Invoice OpenData 模板配置失败,提交时不注入模板配置', {
|
|
891
|
+
error: error instanceof Error ? error.message : String(error)
|
|
892
|
+
});
|
|
893
|
+
return undefined;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
buildSubmitPayloadEnhancerWithOpenDataConfig(enhancePayload) {
|
|
897
|
+
const fulfillmentRefMode = this.getFulfillmentRefMode();
|
|
898
|
+
const invoiceLayoutConfig = this.getCachedInvoiceLayoutConfig();
|
|
899
|
+
const invoiceTemplateSettings = this.getCachedInvoiceTemplateSettings();
|
|
900
|
+
if (!fulfillmentRefMode && !invoiceLayoutConfig && !invoiceTemplateSettings) {
|
|
901
|
+
return enhancePayload;
|
|
902
|
+
}
|
|
903
|
+
return (payload, ctx) => {
|
|
904
|
+
const enhancedPayload = enhancePayload ? enhancePayload(payload, ctx) : payload;
|
|
905
|
+
return {
|
|
906
|
+
...enhancedPayload,
|
|
907
|
+
...(fulfillmentRefMode ? {
|
|
908
|
+
[OS_FULFILLMENT_REF_MODE_FIELD]: fulfillmentRefMode
|
|
909
|
+
} : {}),
|
|
910
|
+
...(invoiceLayoutConfig ? {
|
|
911
|
+
[OS_INVOICE_LAYOUT_CONFIG_FIELD]: (0, _lodashEs.cloneDeep)(invoiceLayoutConfig)
|
|
912
|
+
} : {}),
|
|
913
|
+
...(invoiceTemplateSettings ? {
|
|
914
|
+
[OS_INVOICE_TEMPLATE_SETTINGS_FIELD]: (0, _lodashEs.cloneDeep)(invoiceTemplateSettings)
|
|
915
|
+
} : {})
|
|
916
|
+
};
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
|
|
920
920
|
/**
|
|
921
921
|
* 工厂入口:根据子模块名实例化对应模块。
|
|
922
922
|
* 默认使用 BookingByStep 公共 `createModule`。子类若需引入额外类型(如 customer),
|
|
923
923
|
* 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
|
|
924
924
|
*/
|
|
925
925
|
createSubModule(moduleName) {
|
|
926
|
-
if (moduleName ===
|
|
927
|
-
return new
|
|
926
|
+
if (moduleName === 'quotation') {
|
|
927
|
+
return new _Quotation.QuotationModule(`${this.name}_quotation`);
|
|
928
928
|
}
|
|
929
|
-
return (0,
|
|
929
|
+
return (0, _types2.createModule)(moduleName, this.name);
|
|
930
930
|
}
|
|
931
931
|
getSubModuleHooks(moduleName) {
|
|
932
|
-
var _a, _b;
|
|
933
932
|
const optionHooks = this.initializeOptions.hooks || {};
|
|
934
933
|
const otherHooks = this.otherParams.hooks || {};
|
|
935
|
-
if (moduleName ===
|
|
934
|
+
if (moduleName === 'order') {
|
|
936
935
|
const directOrderHooks = optionHooks;
|
|
937
|
-
return optionHooks.order ||
|
|
936
|
+
return optionHooks.order || this.otherParams.order?.hooks || otherHooks.order || (directOrderHooks.onBeforeMergeProductToOrder ? directOrderHooks : undefined);
|
|
938
937
|
}
|
|
939
|
-
return optionHooks[moduleName] ||
|
|
938
|
+
return optionHooks[moduleName] || this.otherParams[moduleName]?.hooks || otherHooks[moduleName];
|
|
940
939
|
}
|
|
940
|
+
|
|
941
941
|
/**
|
|
942
942
|
* 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
|
|
943
943
|
*
|
|
@@ -960,30 +960,32 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
960
960
|
cacheId: this.cacheId
|
|
961
961
|
};
|
|
962
962
|
}
|
|
963
|
+
|
|
963
964
|
/**
|
|
964
965
|
* 将父级 otherParams 的变更显式同步给已注册的子模块。
|
|
965
966
|
*
|
|
966
967
|
* @example
|
|
967
968
|
* await this.syncOtherParamsToSubModules({ channel: 'pos' });
|
|
968
969
|
*/
|
|
969
|
-
async syncOtherParamsToSubModules(changedParams, {
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
})
|
|
985
|
-
);
|
|
970
|
+
async syncOtherParamsToSubModules(changedParams, {
|
|
971
|
+
cover = false
|
|
972
|
+
} = {}) {
|
|
973
|
+
await Promise.all(Object.entries(this.store).map(async ([moduleName, subModule]) => {
|
|
974
|
+
if (this.reusedSharedSubModuleNames.has(moduleName)) {
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
const targetModule = subModule;
|
|
978
|
+
if (!targetModule || typeof targetModule.updateOtherParams !== 'function') {
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
const nextSubModuleOtherParams = this.buildSubModuleOtherParams(moduleName);
|
|
982
|
+
await targetModule.updateOtherParams(nextSubModuleOtherParams, {
|
|
983
|
+
changedParams,
|
|
984
|
+
cover
|
|
985
|
+
});
|
|
986
|
+
}));
|
|
986
987
|
}
|
|
988
|
+
|
|
987
989
|
/**
|
|
988
990
|
* 读取 sessionStorage[this.name][cacheId],作为子模块 initialState 的来源。
|
|
989
991
|
* sessionStorage 损坏时静默忽略,按空状态注册。
|
|
@@ -995,8 +997,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
995
997
|
}
|
|
996
998
|
try {
|
|
997
999
|
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
998
|
-
if (!sessionData)
|
|
999
|
-
return {};
|
|
1000
|
+
if (!sessionData) return {};
|
|
1000
1001
|
const data = JSON.parse(sessionData);
|
|
1001
1002
|
return data && data[cacheId] || {};
|
|
1002
1003
|
} catch {
|
|
@@ -1004,65 +1005,60 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1004
1005
|
}
|
|
1005
1006
|
}
|
|
1006
1007
|
getAppData(key) {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
if (typeof getData === "function")
|
|
1010
|
-
return getData(key);
|
|
1008
|
+
const getData = this.appPlugin.getData?.();
|
|
1009
|
+
if (typeof getData === 'function') return getData(key);
|
|
1011
1010
|
const app = this.appPlugin.getApp();
|
|
1012
|
-
const coreData =
|
|
1013
|
-
return coreData
|
|
1011
|
+
const coreData = app?.models?.getStore?.().getDataByModel?.('core', 'core');
|
|
1012
|
+
return coreData?.[key];
|
|
1014
1013
|
}
|
|
1014
|
+
|
|
1015
1015
|
/**
|
|
1016
1016
|
* 复用业务解决方案初始化时已解析的支付设备短号。
|
|
1017
1017
|
* 空值会清除缓存,使后续支付恢复实时读取设备信息的兼容路径。
|
|
1018
1018
|
*/
|
|
1019
1019
|
setPaymentNumberDevicePrefix(prefix) {
|
|
1020
|
-
const normalized = String(prefix ??
|
|
1020
|
+
const normalized = String(prefix ?? '').trim();
|
|
1021
1021
|
this.paymentNumberDevicePrefix = normalized || null;
|
|
1022
1022
|
}
|
|
1023
1023
|
getPaymentNumberDevicePrefixSync() {
|
|
1024
|
-
if (!this.appPlugin)
|
|
1025
|
-
|
|
1026
|
-
return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)((key) => this.getAppData(key));
|
|
1024
|
+
if (!this.appPlugin) return 'LOCAL';
|
|
1025
|
+
return (0, _paymentNumber.resolvePaymentNumberDevicePrefixFromDeviceId)(key => this.getAppData(key));
|
|
1027
1026
|
}
|
|
1028
1027
|
getPaymentNumberDevicePrefixAsync() {
|
|
1029
|
-
if (!this.appPlugin)
|
|
1030
|
-
return Promise.resolve("LOCAL");
|
|
1028
|
+
if (!this.appPlugin) return Promise.resolve('LOCAL');
|
|
1031
1029
|
if (this.paymentNumberDevicePrefix) {
|
|
1032
1030
|
return Promise.resolve(this.paymentNumberDevicePrefix);
|
|
1033
1031
|
}
|
|
1034
|
-
return (0,
|
|
1032
|
+
return (0, _paymentNumber.resolvePaymentNumberDevicePrefix)(key => this.getAppData(key));
|
|
1035
1033
|
}
|
|
1036
1034
|
isMultiCurrencySettlementEnabled() {
|
|
1037
|
-
|
|
1038
|
-
return ((_a = this.otherParams) == null ? void 0 : _a.enableMultiCurrencySettlement) === true;
|
|
1035
|
+
return this.otherParams?.enableMultiCurrencySettlement === true;
|
|
1039
1036
|
}
|
|
1040
1037
|
isActiveVirtualSettlementOrder(tempOrder) {
|
|
1041
|
-
return this.isMultiCurrencySettlementEnabled() && (0,
|
|
1038
|
+
return this.isMultiCurrencySettlementEnabled() && (0, _virtualSettlement.isVirtualSettlementOrder)(tempOrder);
|
|
1042
1039
|
}
|
|
1043
1040
|
isHistoricalVirtualSettlementOrder(tempOrder) {
|
|
1044
|
-
|
|
1045
|
-
return ((_b = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_type) === "virtual_currency";
|
|
1041
|
+
return tempOrder?.metadata?.currency_settlement_config?.settlement_type === 'virtual_currency';
|
|
1046
1042
|
}
|
|
1047
1043
|
syncAppDataToTempOrder(tempOrder) {
|
|
1048
|
-
|
|
1049
|
-
const
|
|
1050
|
-
const
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1044
|
+
const isPriceIncludeTax = this.getAppData('is_price_include_tax');
|
|
1045
|
+
const taxCountryCode = this.getAppData('tax_country_code');
|
|
1046
|
+
const currencyCode = this.getAppData('shop_currency_code');
|
|
1047
|
+
const currencySymbol = this.getAppData('shop_symbol');
|
|
1048
|
+
// 历史虚拟币订单不依赖交易开关;普通 POS 不从商品行残留快照推断订单币种。
|
|
1053
1049
|
const isHistoricalVirtualSettlement = this.isHistoricalVirtualSettlementOrder(tempOrder);
|
|
1054
1050
|
const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder) || isHistoricalVirtualSettlement;
|
|
1055
1051
|
const shouldManageLegalCurrencySnapshot = this.isMultiCurrencySettlementEnabled() || isHistoricalVirtualSettlement;
|
|
1056
1052
|
let isChanged = false;
|
|
1057
|
-
if (isPriceIncludeTax !==
|
|
1053
|
+
if (isPriceIncludeTax !== undefined) {
|
|
1058
1054
|
const nextIsPriceIncludeTax = Number(isPriceIncludeTax);
|
|
1059
1055
|
if ((nextIsPriceIncludeTax === 0 || nextIsPriceIncludeTax === 1) && tempOrder.is_price_include_tax !== nextIsPriceIncludeTax) {
|
|
1060
1056
|
tempOrder.is_price_include_tax = nextIsPriceIncludeTax;
|
|
1061
1057
|
isChanged = true;
|
|
1062
1058
|
}
|
|
1063
1059
|
}
|
|
1064
|
-
if (taxCountryCode !==
|
|
1065
|
-
const nextTaxCountryCode = String(taxCountryCode ||
|
|
1060
|
+
if (taxCountryCode !== undefined) {
|
|
1061
|
+
const nextTaxCountryCode = String(taxCountryCode || '');
|
|
1066
1062
|
if (tempOrder.tax_country_code !== nextTaxCountryCode) {
|
|
1067
1063
|
tempOrder.tax_country_code = nextTaxCountryCode;
|
|
1068
1064
|
isChanged = true;
|
|
@@ -1071,30 +1067,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1071
1067
|
tempOrder.metadata = tempOrder.metadata || {};
|
|
1072
1068
|
if (shouldManageLegalCurrencySnapshot) {
|
|
1073
1069
|
const legalCurrencySnapshot = {
|
|
1074
|
-
currency_code: String(
|
|
1075
|
-
|
|
1076
|
-
)
|
|
1077
|
-
currency_symbol: String(
|
|
1078
|
-
currencySymbol ?? ((_b = tempOrder.metadata.legal_currency_snapshot) == null ? void 0 : _b.currency_symbol) ?? tempOrder.currency_symbol ?? ""
|
|
1079
|
-
),
|
|
1080
|
-
currency_format: String(
|
|
1081
|
-
((_c = tempOrder.metadata.legal_currency_snapshot) == null ? void 0 : _c.currency_format) || (isVirtualSettlement ? "symbol_first" : tempOrder.currency_format) || "symbol_first"
|
|
1082
|
-
)
|
|
1070
|
+
currency_code: String(currencyCode ?? tempOrder.metadata.legal_currency_snapshot?.currency_code ?? tempOrder.currency_code ?? ''),
|
|
1071
|
+
currency_symbol: String(currencySymbol ?? tempOrder.metadata.legal_currency_snapshot?.currency_symbol ?? tempOrder.currency_symbol ?? ''),
|
|
1072
|
+
currency_format: String(tempOrder.metadata.legal_currency_snapshot?.currency_format || (isVirtualSettlement ? 'symbol_first' : tempOrder.currency_format) || 'symbol_first')
|
|
1083
1073
|
};
|
|
1084
1074
|
if (JSON.stringify(tempOrder.metadata.legal_currency_snapshot || {}) !== JSON.stringify(legalCurrencySnapshot)) {
|
|
1085
1075
|
tempOrder.metadata.legal_currency_snapshot = legalCurrencySnapshot;
|
|
1086
1076
|
isChanged = true;
|
|
1087
1077
|
}
|
|
1088
1078
|
}
|
|
1089
|
-
if (!isVirtualSettlement && currencyCode !==
|
|
1090
|
-
const nextCurrencyCode = String(currencyCode ||
|
|
1079
|
+
if (!isVirtualSettlement && currencyCode !== undefined) {
|
|
1080
|
+
const nextCurrencyCode = String(currencyCode || '');
|
|
1091
1081
|
if (tempOrder.currency_code !== nextCurrencyCode) {
|
|
1092
1082
|
tempOrder.currency_code = nextCurrencyCode;
|
|
1093
1083
|
isChanged = true;
|
|
1094
1084
|
}
|
|
1095
1085
|
}
|
|
1096
|
-
if (!isVirtualSettlement && currencySymbol !==
|
|
1097
|
-
const nextCurrencySymbol = String(currencySymbol ||
|
|
1086
|
+
if (!isVirtualSettlement && currencySymbol !== undefined) {
|
|
1087
|
+
const nextCurrencySymbol = String(currencySymbol || '');
|
|
1098
1088
|
if (tempOrder.currency_symbol !== nextCurrencySymbol) {
|
|
1099
1089
|
tempOrder.currency_symbol = nextCurrencySymbol;
|
|
1100
1090
|
isChanged = true;
|
|
@@ -1103,23 +1093,26 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1103
1093
|
return isChanged;
|
|
1104
1094
|
}
|
|
1105
1095
|
async initialize(core, options = {}) {
|
|
1106
|
-
var _a, _b, _c, _d;
|
|
1107
1096
|
this.core = core;
|
|
1108
1097
|
this.initializeOptions = options || {};
|
|
1109
1098
|
this.paymentNumberDevicePrefix = null;
|
|
1099
|
+
// this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
|
|
1110
1100
|
this.otherParams = options.otherParams || {};
|
|
1111
|
-
this.cacheId =
|
|
1101
|
+
this.cacheId = this.otherParams?.cacheId;
|
|
1112
1102
|
this.reusedSharedSubModuleNames.clear();
|
|
1113
|
-
this.window = core.getPlugin(
|
|
1114
|
-
this.request = core.getPlugin(
|
|
1115
|
-
|
|
1103
|
+
this.window = core.getPlugin('window');
|
|
1104
|
+
this.request = core.getPlugin('request');
|
|
1105
|
+
|
|
1106
|
+
// 获取 logger 实例
|
|
1107
|
+
this.appPlugin = core.getPlugin('app');
|
|
1116
1108
|
if (!this.appPlugin) {
|
|
1109
|
+
// throw new Error('Checkout 解决方案需要 app 插件支持');
|
|
1117
1110
|
}
|
|
1118
|
-
const app =
|
|
1119
|
-
this.logger = app
|
|
1111
|
+
const app = this.appPlugin?.getApp?.();
|
|
1112
|
+
this.logger = app?.logger;
|
|
1120
1113
|
const targetCacheData = this.readSessionCacheData();
|
|
1121
1114
|
const moduleNames = this.getRegisteredModuleNames();
|
|
1122
|
-
moduleNames.forEach(
|
|
1115
|
+
moduleNames.forEach(step => {
|
|
1123
1116
|
const reusedModule = this.getReusableSharedSubModule(step);
|
|
1124
1117
|
if (reusedModule) {
|
|
1125
1118
|
this.store[step] = reusedModule;
|
|
@@ -1133,32 +1126,30 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1133
1126
|
const hooks = this.getSubModuleHooks(step);
|
|
1134
1127
|
this.store[step] = targetModule;
|
|
1135
1128
|
this.core.registerModule(targetModule, {
|
|
1136
|
-
initialState: this.shouldUseSessionStorageForSubModule(step) ?
|
|
1137
|
-
...hooks ? {
|
|
1129
|
+
initialState: this.shouldUseSessionStorageForSubModule(step) ? targetCacheData?.[targetModule.name] || {} : {},
|
|
1130
|
+
...(hooks ? {
|
|
1131
|
+
hooks
|
|
1132
|
+
} : {}),
|
|
1138
1133
|
otherParams: this.buildSubModuleOtherParams(step)
|
|
1139
1134
|
});
|
|
1140
1135
|
});
|
|
1141
1136
|
if (this.store.schedule && !this.isScheduleListLoaded(this.store.schedule)) {
|
|
1142
1137
|
await this.store.schedule.loadAllSchedule();
|
|
1143
1138
|
}
|
|
1144
|
-
if (this.store.order && typeof
|
|
1145
|
-
this.store.order.setEnableTempOrderPersist(
|
|
1146
|
-
this.otherParams.enableTempOrderPersist
|
|
1147
|
-
);
|
|
1139
|
+
if (this.store.order && typeof this.otherParams?.enableTempOrderPersist === 'boolean') {
|
|
1140
|
+
this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
|
|
1148
1141
|
}
|
|
1149
1142
|
await this.getPaymentMethodsAsync();
|
|
1150
1143
|
this.registerServerOrderChangeSync();
|
|
1151
1144
|
this.core.effects.emit(`${this.name}:onInited`, {});
|
|
1152
1145
|
}
|
|
1153
1146
|
async destroy() {
|
|
1154
|
-
|
|
1155
|
-
(_a = this.serverOrderChangeUnsubscribe) == null ? void 0 : _a.call(this);
|
|
1147
|
+
this.serverOrderChangeUnsubscribe?.();
|
|
1156
1148
|
this.serverOrderChangeUnsubscribe = null;
|
|
1157
|
-
Object.keys(this.store).forEach(
|
|
1158
|
-
if (this.reusedSharedSubModuleNames.has(key))
|
|
1159
|
-
return;
|
|
1149
|
+
Object.keys(this.store).forEach(key => {
|
|
1150
|
+
if (this.reusedSharedSubModuleNames.has(key)) return;
|
|
1160
1151
|
const sub = this.store[key];
|
|
1161
|
-
if (sub && typeof sub.destroy ===
|
|
1152
|
+
if (sub && typeof sub.destroy === 'function') {
|
|
1162
1153
|
try {
|
|
1163
1154
|
sub.destroy();
|
|
1164
1155
|
} catch (error) {
|
|
@@ -1174,6 +1165,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1174
1165
|
await this.core.effects.emit(`${this.name}:onDestroy`, {});
|
|
1175
1166
|
super.destroy();
|
|
1176
1167
|
}
|
|
1168
|
+
|
|
1177
1169
|
/**
|
|
1178
1170
|
* 加载销售订单到统一 tempOrder 工作区。
|
|
1179
1171
|
* 统一通过 OrderModule 的 sales detail lookup 加载订单详情。
|
|
@@ -1182,149 +1174,136 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1182
1174
|
* (比如把 `sales.customer` 写入 CustomerModule、emit 业务 hook 等)。
|
|
1183
1175
|
*/
|
|
1184
1176
|
async loadSalesDetail(orderIdOrParams) {
|
|
1185
|
-
if (!this.store.order)
|
|
1186
|
-
throw new Error("order 模块未初始化");
|
|
1177
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1187
1178
|
const loadSequence = ++this.salesDetailLoadSequence;
|
|
1188
1179
|
this.salesDetailLoadInFlightCount += 1;
|
|
1189
1180
|
try {
|
|
1190
|
-
const params = typeof orderIdOrParams ===
|
|
1181
|
+
const params = typeof orderIdOrParams === 'object' ? orderIdOrParams : {
|
|
1182
|
+
orderId: orderIdOrParams
|
|
1183
|
+
};
|
|
1191
1184
|
const externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
|
|
1192
1185
|
const preloadedSalesDetail = params.preloadedSalesDetail;
|
|
1193
|
-
const lookup = params.orderId ?? externalSaleNumber ?? params.orderNumber ??
|
|
1194
|
-
if (!preloadedSalesDetail && (lookup ===
|
|
1195
|
-
throw new Error(
|
|
1186
|
+
const lookup = params.orderId ?? externalSaleNumber ?? params.orderNumber ?? preloadedSalesDetail?.order_id ?? preloadedSalesDetail?.external_sale_number ?? preloadedSalesDetail?.order_number;
|
|
1187
|
+
if (!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === '')) {
|
|
1188
|
+
throw new Error('加载销售详情需要 orderId、externalSaleNumber 或 orderNumber');
|
|
1196
1189
|
}
|
|
1197
|
-
|
|
1190
|
+
// GlobalSearch 等调用方已拿到完整详情时,直接进入查询成功后的 hydrate 流程,避免按 id 二次请求。
|
|
1191
|
+
const loadedRecord = preloadedSalesDetail ?? (await this.store.order.getSalesOrderByLookup({
|
|
1198
1192
|
lookup,
|
|
1199
1193
|
forceRemote: params.forceRemote
|
|
1200
|
-
});
|
|
1194
|
+
}));
|
|
1201
1195
|
if (!preloadedSalesDetail && (!loadedRecord || loadedRecord.code !== 200)) {
|
|
1202
1196
|
const message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || `加载销售详情失败: ${lookup}`;
|
|
1203
1197
|
throw new Error(message);
|
|
1204
1198
|
}
|
|
1205
1199
|
const loadedSalesDetail = preloadedSalesDetail ?? loadedRecord.data;
|
|
1206
|
-
|
|
1200
|
+
// payment_pending 只存在于本地;远端详情需过滤,但会话快照必须完整恢复。
|
|
1201
|
+
const shouldFilterPendingPayments = params.hydrateSource !== 'sessionStorage';
|
|
1207
1202
|
const remoteRecord = shouldFilterPendingPayments ? filterPendingPaymentsFromLoadedSalesDetail(loadedSalesDetail) : loadedSalesDetail;
|
|
1203
|
+
const mergeSourceRecord = params.merge ? markLoadedSalesDetailProductsAsSaved(remoteRecord) : remoteRecord;
|
|
1208
1204
|
const currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
|
|
1209
|
-
const mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(
|
|
1210
|
-
currentTempOrder,
|
|
1211
|
-
remoteRecord,
|
|
1212
|
-
"preserve-local"
|
|
1213
|
-
) : remoteRecord;
|
|
1205
|
+
const mergedRecord = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, mergeSourceRecord, 'preserve-local') : mergeSourceRecord;
|
|
1214
1206
|
const record = shouldFilterPendingPayments ? filterPendingPaymentsFromLoadedSalesDetail(mergedRecord) : mergedRecord;
|
|
1215
|
-
return await this.hydrateLatestLoadedSalesDetail(
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
);
|
|
1207
|
+
return await this.hydrateLatestLoadedSalesDetail(record, loadSequence, {
|
|
1208
|
+
hydrateSource: params.hydrateSource,
|
|
1209
|
+
merge: params.merge
|
|
1210
|
+
});
|
|
1220
1211
|
} finally {
|
|
1221
|
-
this.salesDetailLoadInFlightCount = Math.max(
|
|
1222
|
-
0,
|
|
1223
|
-
this.salesDetailLoadInFlightCount - 1
|
|
1224
|
-
);
|
|
1212
|
+
this.salesDetailLoadInFlightCount = Math.max(0, this.salesDetailLoadInFlightCount - 1);
|
|
1225
1213
|
if (this.salesDetailLoadInFlightCount === 0) {
|
|
1226
1214
|
try {
|
|
1227
1215
|
await this.drainQueuedServerOrderChanges();
|
|
1228
1216
|
} catch (error) {
|
|
1229
|
-
this.logError(
|
|
1217
|
+
this.logError('drain queued server order changes failed', {
|
|
1230
1218
|
error: error instanceof Error ? error.message : String(error)
|
|
1231
1219
|
});
|
|
1232
1220
|
}
|
|
1233
1221
|
}
|
|
1234
1222
|
}
|
|
1235
1223
|
}
|
|
1224
|
+
|
|
1236
1225
|
/** 获取当前已加载的销售详情(只读快照)。未加载过则返回 null。 */
|
|
1237
1226
|
getSalesOrder() {
|
|
1238
1227
|
return this.currentSalesDetail;
|
|
1239
1228
|
}
|
|
1229
|
+
|
|
1240
1230
|
/** 获取销售详情顶部业务字段(订单号/状态/金额等通用字段集合)。 */
|
|
1241
1231
|
getOrderHeader() {
|
|
1242
|
-
if (!this.currentSalesDetail)
|
|
1243
|
-
return null;
|
|
1232
|
+
if (!this.currentSalesDetail) return null;
|
|
1244
1233
|
return this.currentSalesDetail.header || this.currentSalesDetail;
|
|
1245
1234
|
}
|
|
1235
|
+
|
|
1246
1236
|
/** 获取所有 booking(含 root + children),按服务端原始顺序输出。 */
|
|
1247
1237
|
getBookings() {
|
|
1248
|
-
|
|
1249
|
-
return ((_a = this.currentSalesDetail) == null ? void 0 : _a.bookings) || [];
|
|
1238
|
+
return this.currentSalesDetail?.bookings || [];
|
|
1250
1239
|
}
|
|
1240
|
+
|
|
1251
1241
|
/** 获取根 booking(is_next === 0 / is_root === 1),多个时取第一个。 */
|
|
1252
1242
|
getRootBooking() {
|
|
1253
|
-
if (!this.currentSalesDetail)
|
|
1254
|
-
|
|
1255
|
-
if (this.currentSalesDetail.rootBooking)
|
|
1256
|
-
return this.currentSalesDetail.rootBooking;
|
|
1243
|
+
if (!this.currentSalesDetail) return null;
|
|
1244
|
+
if (this.currentSalesDetail.rootBooking) return this.currentSalesDetail.rootBooking;
|
|
1257
1245
|
const bookings = this.currentSalesDetail.bookings || [];
|
|
1258
|
-
return bookings.find(
|
|
1259
|
-
const parentId = booking
|
|
1260
|
-
return parentId === 0 || parentId === null || parentId ===
|
|
1246
|
+
return bookings.find(booking => {
|
|
1247
|
+
const parentId = booking?.parent_id;
|
|
1248
|
+
return parentId === 0 || parentId === null || parentId === undefined;
|
|
1261
1249
|
}) || null;
|
|
1262
1250
|
}
|
|
1251
|
+
|
|
1263
1252
|
/** 按 product_uid 反查 booking 列表(用于商品行 ↔ booking 映射)。 */
|
|
1264
1253
|
getChildBookingsByProductUid(productUid) {
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
return
|
|
1271
|
-
return (this.currentSalesDetail.bookings || []).filter((booking) => {
|
|
1272
|
-
var _a2;
|
|
1273
|
-
const uid = (booking == null ? void 0 : booking.product_uid) || ((_a2 = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a2.product_uid);
|
|
1274
|
-
return String(uid || "") === String(productUid);
|
|
1254
|
+
if (!this.currentSalesDetail || !productUid) return [];
|
|
1255
|
+
const indexed = this.currentSalesDetail.bookingsByProductUid?.[productUid];
|
|
1256
|
+
if (indexed) return indexed;
|
|
1257
|
+
return (this.currentSalesDetail.bookings || []).filter(booking => {
|
|
1258
|
+
const uid = booking?.product_uid || booking?.metadata?.product_uid;
|
|
1259
|
+
return String(uid || '') === String(productUid);
|
|
1275
1260
|
});
|
|
1276
1261
|
}
|
|
1262
|
+
|
|
1277
1263
|
/** 获取支付列表(已支付/退款等明细)。 */
|
|
1278
1264
|
getPayments() {
|
|
1279
|
-
|
|
1280
|
-
return ((_a = this.currentSalesDetail) == null ? void 0 : _a.payments) || [];
|
|
1265
|
+
return this.currentSalesDetail?.payments || [];
|
|
1281
1266
|
}
|
|
1267
|
+
|
|
1282
1268
|
/** 获取附加费用(运费/服务费/税费等)。 */
|
|
1283
1269
|
getSurcharges() {
|
|
1284
|
-
|
|
1285
|
-
return ((_a = this.currentSalesDetail) == null ? void 0 : _a.surcharges) || [];
|
|
1270
|
+
return this.currentSalesDetail?.surcharges || [];
|
|
1286
1271
|
}
|
|
1287
1272
|
getTempOrder() {
|
|
1288
|
-
|
|
1289
|
-
const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
|
|
1273
|
+
const result = this.store.order?.getTempOrder() || null;
|
|
1290
1274
|
return result;
|
|
1291
1275
|
}
|
|
1292
1276
|
async replaceTempOrder(tempOrder, options) {
|
|
1293
|
-
if (!this.store.order)
|
|
1294
|
-
throw new Error("order 模块未初始化");
|
|
1277
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1295
1278
|
const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder, options);
|
|
1296
|
-
await this.effectsEmit(
|
|
1279
|
+
await this.effectsEmit('onTempOrderReplaced', {
|
|
1280
|
+
tempOrder: nextTempOrder
|
|
1281
|
+
});
|
|
1297
1282
|
return nextTempOrder;
|
|
1298
1283
|
}
|
|
1299
1284
|
getOrderIdentity() {
|
|
1300
|
-
if (!this.store.order)
|
|
1301
|
-
return null;
|
|
1285
|
+
if (!this.store.order) return null;
|
|
1302
1286
|
return this.store.order.getOrderIdentity();
|
|
1303
1287
|
}
|
|
1304
1288
|
getOrderSnapshot() {
|
|
1305
|
-
if (!this.store.order)
|
|
1306
|
-
return null;
|
|
1289
|
+
if (!this.store.order) return null;
|
|
1307
1290
|
return this.store.order.getOrderSnapshot();
|
|
1308
1291
|
}
|
|
1309
1292
|
getOrderSyncState() {
|
|
1310
|
-
if (!this.store.order)
|
|
1311
|
-
return "local";
|
|
1293
|
+
if (!this.store.order) return 'local';
|
|
1312
1294
|
return this.store.order.getOrderSyncState();
|
|
1313
1295
|
}
|
|
1314
1296
|
getOrderAmountSnapshot() {
|
|
1315
|
-
if (!this.store.order)
|
|
1316
|
-
return null;
|
|
1297
|
+
if (!this.store.order) return null;
|
|
1317
1298
|
return this.store.order.getOrderAmountSnapshot();
|
|
1318
1299
|
}
|
|
1319
1300
|
getTempOrderNote() {
|
|
1320
|
-
if (!this.store.order)
|
|
1321
|
-
return "";
|
|
1301
|
+
if (!this.store.order) return '';
|
|
1322
1302
|
return this.store.order.getTempOrderNote();
|
|
1323
1303
|
}
|
|
1324
1304
|
updateTempOrderNote(note, sync = false) {
|
|
1325
1305
|
try {
|
|
1326
|
-
if (!this.store.order)
|
|
1327
|
-
throw new Error("order 模块未初始化");
|
|
1306
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1328
1307
|
const result = this.store.order.updateTempOrderNote(note, sync);
|
|
1329
1308
|
return result;
|
|
1330
1309
|
} catch (error) {
|
|
@@ -1332,47 +1311,42 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1332
1311
|
}
|
|
1333
1312
|
}
|
|
1334
1313
|
updateRemoteOrderNote(orderId, note) {
|
|
1335
|
-
if (!this.store.order)
|
|
1336
|
-
throw new Error("order 模块未初始化");
|
|
1314
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1337
1315
|
this.store.order.syncTempOrderNoteToRemote(orderId, note);
|
|
1338
1316
|
}
|
|
1339
1317
|
updateTempOrderShopDiscount(amount) {
|
|
1340
|
-
if (!this.store.order)
|
|
1341
|
-
throw new Error("order 模块未初始化");
|
|
1318
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1342
1319
|
return this.store.order.updateTempOrderShopDiscount(amount);
|
|
1343
1320
|
}
|
|
1344
1321
|
updateTempOrderDepositAmount(amount) {
|
|
1345
|
-
if (!this.store.order)
|
|
1346
|
-
throw new Error("order 模块未初始化");
|
|
1322
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1347
1323
|
return this.store.order.updateTempOrderDepositAmount(amount);
|
|
1348
1324
|
}
|
|
1349
1325
|
updateTempOrderContactsInfo(contactsInfo) {
|
|
1350
|
-
if (!this.store.order)
|
|
1351
|
-
throw new Error("order 模块未初始化");
|
|
1326
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1352
1327
|
return this.store.order.updateTempOrderContactsInfo(contactsInfo);
|
|
1353
1328
|
}
|
|
1329
|
+
|
|
1354
1330
|
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
1355
1331
|
setEnableTempOrderPersist(enabled) {
|
|
1356
|
-
if (!this.store.order)
|
|
1357
|
-
throw new Error("order 模块未初始化");
|
|
1332
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1358
1333
|
this.store.order.setEnableTempOrderPersist(enabled);
|
|
1359
1334
|
}
|
|
1335
|
+
|
|
1360
1336
|
/** 是否允许 saveDraft 写入 IndexedDB 草稿。 */
|
|
1361
1337
|
isTempOrderPersistEnabled() {
|
|
1362
|
-
if (!this.store.order)
|
|
1363
|
-
return false;
|
|
1338
|
+
if (!this.store.order) return false;
|
|
1364
1339
|
return this.store.order.isTempOrderPersistEnabled();
|
|
1365
1340
|
}
|
|
1366
1341
|
ensureTempOrder() {
|
|
1367
|
-
if (!this.store.order)
|
|
1368
|
-
throw new Error("order 模块未初始化");
|
|
1342
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1369
1343
|
return this.store.order.ensureTempOrder();
|
|
1370
1344
|
}
|
|
1345
|
+
|
|
1371
1346
|
// 主动创建临时订单;若已存在则直接返回已有订单
|
|
1372
1347
|
async addNewOrder() {
|
|
1373
1348
|
try {
|
|
1374
|
-
if (!this.store.order)
|
|
1375
|
-
throw new Error("order 模块未初始化");
|
|
1349
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1376
1350
|
const tempOrder = await this.store.order.addNewOrder();
|
|
1377
1351
|
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
1378
1352
|
this.store.order.persistTempOrder();
|
|
@@ -1384,29 +1358,31 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1384
1358
|
}
|
|
1385
1359
|
}
|
|
1386
1360
|
async saveDraft() {
|
|
1387
|
-
if (!this.store.order)
|
|
1388
|
-
throw new Error("order 模块未初始化");
|
|
1361
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1389
1362
|
return this.store.order.saveDraft();
|
|
1390
1363
|
}
|
|
1364
|
+
|
|
1391
1365
|
// 重置 tempOrder 与与上一单强相关的运行态(resource/entryPaxNumber/enabledReservationRuleProducts),
|
|
1392
1366
|
// 适用于从支付页通过 react-router 跳回继续下单时清理残留数据
|
|
1393
1367
|
async restoreOrder() {
|
|
1394
|
-
var _a;
|
|
1395
1368
|
try {
|
|
1396
1369
|
if (!this.store.order) {
|
|
1397
|
-
throw new Error(
|
|
1370
|
+
throw new Error('scanOrder 解决方案需要 order 模块支持');
|
|
1398
1371
|
}
|
|
1372
|
+
// this.store.resource = null;
|
|
1399
1373
|
const tempOrder = this.store.order.restoreOrder();
|
|
1400
1374
|
this.currentSalesDetail = null;
|
|
1401
1375
|
this.discountConfigCacheKey = null;
|
|
1402
1376
|
this.hasManualDiscountSelection = false;
|
|
1403
|
-
const wallet =
|
|
1377
|
+
const wallet = this.store.payment?.wallet;
|
|
1404
1378
|
if (wallet) {
|
|
1405
1379
|
this.walletAssetsRefreshSequence += 1;
|
|
1406
1380
|
wallet.clearAllCache();
|
|
1407
1381
|
await this.publishWalletAssetsState(wallet.getWalletAssetsState());
|
|
1408
1382
|
}
|
|
1409
|
-
await this.effectsEmit(
|
|
1383
|
+
await this.effectsEmit('onTempOrderReplaced', {
|
|
1384
|
+
tempOrder
|
|
1385
|
+
});
|
|
1410
1386
|
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
1411
1387
|
this.store.order.persistTempOrder();
|
|
1412
1388
|
await this.store.order.saveDraft();
|
|
@@ -1416,14 +1392,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1416
1392
|
throw error;
|
|
1417
1393
|
}
|
|
1418
1394
|
}
|
|
1395
|
+
|
|
1419
1396
|
/**
|
|
1420
1397
|
* 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
|
|
1421
1398
|
* 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
|
|
1422
1399
|
*/
|
|
1423
1400
|
async clearOrderCartLines() {
|
|
1424
1401
|
try {
|
|
1425
|
-
if (!this.store.order)
|
|
1426
|
-
throw new Error("order 模块未初始化");
|
|
1402
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1427
1403
|
const tempOrder = await this.store.order.clearOrderCartLines();
|
|
1428
1404
|
if (this.currentSalesDetail) {
|
|
1429
1405
|
this.currentSalesDetail = {
|
|
@@ -1435,7 +1411,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1435
1411
|
discount_list: []
|
|
1436
1412
|
};
|
|
1437
1413
|
}
|
|
1438
|
-
await this.effectsEmit(
|
|
1414
|
+
await this.effectsEmit('onTempOrderReplaced', {
|
|
1415
|
+
tempOrder
|
|
1416
|
+
});
|
|
1439
1417
|
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
1440
1418
|
this.store.order.persistTempOrder();
|
|
1441
1419
|
await this.store.order.saveDraft();
|
|
@@ -1445,10 +1423,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1445
1423
|
throw error;
|
|
1446
1424
|
}
|
|
1447
1425
|
}
|
|
1426
|
+
|
|
1448
1427
|
/** 切换法币 / WalletPass 单位时清空商品、折扣与支付状态,保留客户。 */
|
|
1449
1428
|
async clearOrderForSettlementSwitch() {
|
|
1450
|
-
if (!this.store.order)
|
|
1451
|
-
throw new Error("order 模块未初始化");
|
|
1429
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1452
1430
|
const tempOrder = await this.store.order.clearOrderForSettlementSwitch();
|
|
1453
1431
|
if (this.currentSalesDetail) {
|
|
1454
1432
|
this.currentSalesDetail = {
|
|
@@ -1464,15 +1442,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1464
1442
|
return tempOrder;
|
|
1465
1443
|
}
|
|
1466
1444
|
getOrderProducts() {
|
|
1467
|
-
if (!this.store.order)
|
|
1468
|
-
throw new Error("order 模块未初始化");
|
|
1445
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1469
1446
|
const products = this.store.order.getOrderProducts();
|
|
1470
1447
|
return products;
|
|
1471
1448
|
}
|
|
1472
1449
|
async getSummary() {
|
|
1473
1450
|
try {
|
|
1474
|
-
if (!this.store.order)
|
|
1475
|
-
throw new Error("order 模块未初始化");
|
|
1451
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1476
1452
|
const summary = await this.store.order.getOrderSummary();
|
|
1477
1453
|
return summary;
|
|
1478
1454
|
} catch (error) {
|
|
@@ -1481,21 +1457,18 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1481
1457
|
}
|
|
1482
1458
|
getHistoricalProductDiscountList(products) {
|
|
1483
1459
|
const historyDiscountList = [];
|
|
1484
|
-
products.forEach(
|
|
1485
|
-
if (!this.isPersistedOrderProduct(item))
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
const discountId = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
|
|
1490
|
-
if (!discountId || !["good_pass", "discount_card"].includes(discount.type))
|
|
1491
|
-
return;
|
|
1460
|
+
products.forEach(item => {
|
|
1461
|
+
if (!this.isPersistedOrderProduct(item)) return;
|
|
1462
|
+
(item.discount_list || []).forEach(discount => {
|
|
1463
|
+
const discountId = discount.discount?.resource_id || discount.id;
|
|
1464
|
+
if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
|
|
1492
1465
|
const quantity = item.quantity || item.num || item.product_quantity || 1;
|
|
1493
|
-
const savedAmount = new
|
|
1494
|
-
const index = historyDiscountList.findIndex(
|
|
1466
|
+
const savedAmount = new _decimal.default(discount.amount || 0).times(quantity).plus(discount?.metadata?.product_discount_difference || 0);
|
|
1467
|
+
const index = historyDiscountList.findIndex(n => n.id === discountId);
|
|
1495
1468
|
if (index !== -1) {
|
|
1496
1469
|
historyDiscountList[index] = {
|
|
1497
1470
|
...historyDiscountList[index],
|
|
1498
|
-
amount: new
|
|
1471
|
+
amount: new _decimal.default(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
|
|
1499
1472
|
savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
|
|
1500
1473
|
};
|
|
1501
1474
|
return;
|
|
@@ -1504,15 +1477,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1504
1477
|
...discount,
|
|
1505
1478
|
id: discountId,
|
|
1506
1479
|
tag: discount.tag || discount.type,
|
|
1507
|
-
name: discount.name ||
|
|
1508
|
-
format_title:
|
|
1480
|
+
name: discount.name || discount.discount?.title?.auto,
|
|
1481
|
+
format_title: discount.discount?.title || discount.format_title,
|
|
1509
1482
|
isEditMode: true,
|
|
1510
1483
|
limited_relation_product_data: {},
|
|
1511
1484
|
savedAmount: savedAmount.toNumber(),
|
|
1512
1485
|
isAvailable: true,
|
|
1513
1486
|
isDisabled: true,
|
|
1514
1487
|
isSelected: true,
|
|
1515
|
-
product_id:
|
|
1488
|
+
product_id: discount.discount?.product_id || discount.product_id
|
|
1516
1489
|
});
|
|
1517
1490
|
});
|
|
1518
1491
|
});
|
|
@@ -1520,57 +1493,49 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1520
1493
|
}
|
|
1521
1494
|
isPersistedOrderProduct(product) {
|
|
1522
1495
|
const orderDetailId = product.order_detail_id ?? product.orderDetailId;
|
|
1523
|
-
if (orderDetailId !==
|
|
1496
|
+
if (orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '') {
|
|
1524
1497
|
return true;
|
|
1525
1498
|
}
|
|
1526
1499
|
const bookingId = product.booking_id ?? product.bookingId;
|
|
1527
|
-
return bookingId !==
|
|
1500
|
+
return bookingId !== undefined && bookingId !== null && bookingId !== '';
|
|
1528
1501
|
}
|
|
1529
1502
|
mergeHistoricalDiscountList(discountList, products) {
|
|
1530
1503
|
const historyDiscountList = this.getHistoricalProductDiscountList(products);
|
|
1531
|
-
const historyIds = new Set(historyDiscountList.map(
|
|
1532
|
-
return [
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
return true;
|
|
1537
|
-
return !isBaseSalesHistoricalDiscountEntry(discount);
|
|
1538
|
-
})
|
|
1539
|
-
];
|
|
1504
|
+
const historyIds = new Set(historyDiscountList.map(discount => discount.id));
|
|
1505
|
+
return [...historyDiscountList, ...(discountList || []).filter(discount => {
|
|
1506
|
+
if (!historyIds.has(discount.id)) return true;
|
|
1507
|
+
return !isBaseSalesHistoricalDiscountEntry(discount);
|
|
1508
|
+
})];
|
|
1540
1509
|
}
|
|
1541
1510
|
shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
|
|
1542
|
-
if (params.discountAction !==
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
return
|
|
1555
|
-
|
|
1556
|
-
|
|
1511
|
+
if (params.discountAction !== 'edit') return false;
|
|
1512
|
+
if (!params.products.length) return false;
|
|
1513
|
+
const hasDraftProduct = params.products.some(product => !this.isPersistedOrderProduct(product));
|
|
1514
|
+
if (hasDraftProduct) return false;
|
|
1515
|
+
|
|
1516
|
+
// 编辑详情 hydrate 时,商品行上的历史券卡会被还原为 isEditMode=true、
|
|
1517
|
+
// isSelected=true 的只读记录。它们表示“该折扣已在原订单结算”,不是用户在
|
|
1518
|
+
// 当前编辑会话中新做的选择,不能据此放行刚从 prepare/config 拉回来的折扣。
|
|
1519
|
+
// 否则后续 Rules.calcDiscount 会把没有 isManualSelect 标记的可用 runtime 卡
|
|
1520
|
+
// 当作自动候选,再次写入 tempOrder。这里只识别非 isEditMode 的 runtime 状态;
|
|
1521
|
+
// 新建单、编辑态新增商品以及用户本次明确选择/取消折扣的原有流程保持不变。
|
|
1522
|
+
const hasRuntimeDiscountSelection = params.currentDiscountList.some(discount => !discount.isEditMode && (discount.isSelected || discount.isManualSelect));
|
|
1523
|
+
if (hasRuntimeDiscountSelection) return false;
|
|
1524
|
+
|
|
1525
|
+
// nextDiscountList 已经合并了历史只读折扣与本次获取的 runtime 折扣,
|
|
1526
|
+
// 因此这里同样必须排除 isEditMode;只有 runtime 条目已有明确选择状态时,
|
|
1527
|
+
// 才允许继续进入折扣重算。
|
|
1528
|
+
return !params.nextDiscountList.some(discount => !discount.isEditMode && (discount.isSelected || discount.isManualSelect));
|
|
1557
1529
|
}
|
|
1558
1530
|
mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
|
|
1559
|
-
if (!currentDiscountList.length)
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
currentDiscountMap.set(
|
|
1564
|
-
`${discount.id}:${isBaseSalesHistoricalDiscountEntry(discount) ? "historical" : "runtime"}`,
|
|
1565
|
-
discount
|
|
1566
|
-
);
|
|
1531
|
+
if (!currentDiscountList.length) return discountList;
|
|
1532
|
+
const currentDiscountMap = new Map();
|
|
1533
|
+
currentDiscountList.forEach(discount => {
|
|
1534
|
+
currentDiscountMap.set(`${discount.id}:${isBaseSalesHistoricalDiscountEntry(discount) ? 'historical' : 'runtime'}`, discount);
|
|
1567
1535
|
});
|
|
1568
|
-
return discountList.map(
|
|
1569
|
-
const currentDiscount = currentDiscountMap.get(
|
|
1570
|
-
|
|
1571
|
-
);
|
|
1572
|
-
if (!currentDiscount)
|
|
1573
|
-
return discount;
|
|
1536
|
+
return discountList.map(discount => {
|
|
1537
|
+
const currentDiscount = currentDiscountMap.get(`${discount.id}:${isBaseSalesHistoricalDiscountEntry(discount) ? 'historical' : 'runtime'}`);
|
|
1538
|
+
if (!currentDiscount) return discount;
|
|
1574
1539
|
if (currentDiscount.isManualSelect) {
|
|
1575
1540
|
return {
|
|
1576
1541
|
...discount,
|
|
@@ -1589,46 +1554,38 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1589
1554
|
});
|
|
1590
1555
|
}
|
|
1591
1556
|
async loadDiscountConfig(params) {
|
|
1592
|
-
|
|
1593
|
-
if (!this.store.order)
|
|
1594
|
-
throw new Error("order 模块未初始化");
|
|
1557
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1595
1558
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1596
1559
|
const orderStore = this.store.order.store || {};
|
|
1597
1560
|
const discountModule = orderStore.discount;
|
|
1598
1561
|
const rulesModule = orderStore.rules;
|
|
1599
|
-
const orderId = tempOrder.order_id ||
|
|
1600
|
-
const customerId = Number(
|
|
1601
|
-
|
|
1602
|
-
);
|
|
1603
|
-
const
|
|
1604
|
-
const
|
|
1605
|
-
const
|
|
1606
|
-
const discountAction = (params == null ? void 0 : params.action) || (orderId ? "edit" : "create");
|
|
1607
|
-
const discountConfigCacheKey = [
|
|
1608
|
-
customerId,
|
|
1609
|
-
discountAction,
|
|
1610
|
-
Number(orderId) || 0
|
|
1611
|
-
].join(":");
|
|
1562
|
+
const orderId = tempOrder.order_id || this.getOrderIdentity?.()?.orderId;
|
|
1563
|
+
const customerId = Number(params?.customerId || tempOrder.customer_id || tempOrder.customer?.id || tempOrder._extend?.customerSnapshot?.id || tempOrder._extend?.customerSnapshot?.customer_id || 0);
|
|
1564
|
+
const currentDiscountList = discountModule?.getDiscountList?.() || [];
|
|
1565
|
+
const originalDiscountList = discountModule?.getOriginalDiscountList?.() || [];
|
|
1566
|
+
const hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some(discount => discount.isManualSelect);
|
|
1567
|
+
const discountAction = params?.action || (orderId ? 'edit' : 'create');
|
|
1568
|
+
const discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
|
|
1612
1569
|
let preparedDiscountList = [];
|
|
1613
1570
|
if (customerId && customerId !== 1) {
|
|
1614
|
-
if (!
|
|
1571
|
+
if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
|
|
1615
1572
|
preparedDiscountList = originalDiscountList;
|
|
1616
1573
|
} else {
|
|
1617
1574
|
preparedDiscountList = await this.store.order.loadDiscountConfig({
|
|
1618
1575
|
customerId,
|
|
1619
1576
|
action: discountAction,
|
|
1620
|
-
orderId: Number(orderId) ||
|
|
1577
|
+
orderId: Number(orderId) || undefined,
|
|
1621
1578
|
apply: false
|
|
1622
1579
|
});
|
|
1623
1580
|
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
1624
|
-
await
|
|
1581
|
+
await discountModule?.setOriginalDiscountList?.(preparedDiscountList);
|
|
1625
1582
|
}
|
|
1626
1583
|
}
|
|
1627
1584
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
1628
|
-
await
|
|
1629
|
-
await
|
|
1585
|
+
await discountModule?.setOriginalDiscountList?.([]);
|
|
1586
|
+
await discountModule?.setDiscountList?.([]);
|
|
1630
1587
|
tempOrder.discount_list = [];
|
|
1631
|
-
tempOrder.shop_discount =
|
|
1588
|
+
tempOrder.shop_discount = '0.00';
|
|
1632
1589
|
return {
|
|
1633
1590
|
productList: tempOrder.products || [],
|
|
1634
1591
|
discountList: [],
|
|
@@ -1644,15 +1601,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1644
1601
|
virtualCurrencyList: this.store.order.getVirtualCurrencyList()
|
|
1645
1602
|
};
|
|
1646
1603
|
}
|
|
1647
|
-
let nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
);
|
|
1651
|
-
nextDiscountList = this.mergeCurrentDiscountSelectionState(
|
|
1652
|
-
nextDiscountList,
|
|
1653
|
-
currentDiscountList
|
|
1654
|
-
);
|
|
1655
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1604
|
+
let nextDiscountList = this.mergeHistoricalDiscountList(preparedDiscountList || discountModule?.getDiscountList?.() || [], tempOrder.products || []);
|
|
1605
|
+
nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
|
|
1606
|
+
await discountModule?.setDiscountList(nextDiscountList);
|
|
1656
1607
|
const shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
|
|
1657
1608
|
discountAction,
|
|
1658
1609
|
products: tempOrder.products || [],
|
|
@@ -1660,9 +1611,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1660
1611
|
nextDiscountList
|
|
1661
1612
|
});
|
|
1662
1613
|
if (shouldSkipAutoApplyFetchedDiscounts) {
|
|
1663
|
-
const
|
|
1614
|
+
const summary = await this.store.order.recalculateSummary({
|
|
1615
|
+
createIfMissing: true
|
|
1616
|
+
});
|
|
1664
1617
|
this.store.order.persistTempOrder();
|
|
1665
|
-
await this.effectsEmit(
|
|
1618
|
+
await this.effectsEmit('onDiscountApplied', {
|
|
1666
1619
|
productList: tempOrder.products || [],
|
|
1667
1620
|
discountList: nextDiscountList,
|
|
1668
1621
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
@@ -1676,56 +1629,50 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1676
1629
|
};
|
|
1677
1630
|
}
|
|
1678
1631
|
if (rulesModule) {
|
|
1679
|
-
const orderTotalAmount = Number(
|
|
1680
|
-
console.log("[BaseSales.applyDiscountConfig.calcDiscount]");
|
|
1632
|
+
const orderTotalAmount = Number(orderStore.summary?.total_amount || 0);
|
|
1681
1633
|
const result = rulesModule.calcDiscount({
|
|
1682
1634
|
productList: tempOrder.products,
|
|
1683
1635
|
discountList: nextDiscountList,
|
|
1684
1636
|
holders: [],
|
|
1685
|
-
isFormSubject:
|
|
1637
|
+
isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
|
|
1686
1638
|
orderTotalAmount
|
|
1687
|
-
}) || {
|
|
1639
|
+
}) || {
|
|
1640
|
+
productList: tempOrder.products,
|
|
1641
|
+
discountList: nextDiscountList
|
|
1642
|
+
};
|
|
1688
1643
|
if (result.productList) {
|
|
1689
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1690
|
-
tempOrder.products,
|
|
1691
|
-
result.productList
|
|
1692
|
-
);
|
|
1644
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1693
1645
|
}
|
|
1694
1646
|
for (const product of tempOrder.products || []) {
|
|
1695
|
-
const productUid =
|
|
1696
|
-
const runtimeOrigin = productUid ?
|
|
1697
|
-
if (
|
|
1698
|
-
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
);
|
|
1703
|
-
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
|
|
1704
|
-
const sourcePrice = ((_s = product.metadata) == null ? void 0 : _s.source_product_price) ?? (((_t = product.metadata) == null ? void 0 : _t.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
|
|
1705
|
-
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1706
|
-
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1647
|
+
const productUid = product.metadata?.unique_identification_number;
|
|
1648
|
+
const runtimeOrigin = productUid ? tempOrder._extend?.productsByUid?.[productUid]?.origin : undefined;
|
|
1649
|
+
if (runtimeOrigin?.isManualDiscount || isBaseSalesManualProductDiscountProduct(product)) continue;
|
|
1650
|
+
const totalPerUnitDiscount = (product.discount_list || []).reduce((sum, pd) => sum + Number(pd.amount || 0), 0);
|
|
1651
|
+
const optionSum = (0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(product));
|
|
1652
|
+
const sourcePrice = product.metadata?.source_product_price ?? (product.metadata?.main_product_original_price != null ? new _decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? '0');
|
|
1653
|
+
const newSourceSellingPrice = new _decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1654
|
+
const newMainSellingPrice = new _decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1707
1655
|
if (product.metadata) {
|
|
1708
1656
|
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
1709
1657
|
product.metadata.price_schema_version = 2;
|
|
1710
1658
|
}
|
|
1711
|
-
product.selling_price = (0,
|
|
1659
|
+
product.selling_price = (0, _utils.composeLinePrice)({
|
|
1712
1660
|
mainPrice: newMainSellingPrice,
|
|
1713
1661
|
bundle: product.product_bundle
|
|
1714
1662
|
});
|
|
1715
1663
|
}
|
|
1716
1664
|
if (result.discountList) {
|
|
1717
|
-
nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
);
|
|
1721
|
-
import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1722
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1723
|
-
tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
|
|
1665
|
+
nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
|
|
1666
|
+
_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1667
|
+
await discountModule?.setDiscountList(nextDiscountList);
|
|
1668
|
+
tempOrder.discount_list = nextDiscountList.filter(discount => discount.isSelected);
|
|
1724
1669
|
}
|
|
1725
1670
|
}
|
|
1726
|
-
const summary = await this.store.order.recalculateSummary({
|
|
1671
|
+
const summary = await this.store.order.recalculateSummary({
|
|
1672
|
+
createIfMissing: true
|
|
1673
|
+
});
|
|
1727
1674
|
this.store.order.persistTempOrder();
|
|
1728
|
-
await this.effectsEmit(
|
|
1675
|
+
await this.effectsEmit('onDiscountApplied', {
|
|
1729
1676
|
productList: tempOrder.products || [],
|
|
1730
1677
|
discountList: nextDiscountList,
|
|
1731
1678
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
@@ -1739,109 +1686,91 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1739
1686
|
};
|
|
1740
1687
|
}
|
|
1741
1688
|
getAvailableWalletIds() {
|
|
1742
|
-
|
|
1743
|
-
if (!((_a = this.store.order) == null ? void 0 : _a.getAvailableWalletIds))
|
|
1744
|
-
return [];
|
|
1689
|
+
if (!this.store.order?.getAvailableWalletIds) return [];
|
|
1745
1690
|
return this.store.order.getAvailableWalletIds();
|
|
1746
1691
|
}
|
|
1747
1692
|
getVirtualCurrencyList() {
|
|
1748
|
-
|
|
1749
|
-
if (!((_a = this.store.order) == null ? void 0 : _a.getVirtualCurrencyList))
|
|
1750
|
-
return [];
|
|
1693
|
+
if (!this.store.order?.getVirtualCurrencyList) return [];
|
|
1751
1694
|
return this.store.order.getVirtualCurrencyList();
|
|
1752
1695
|
}
|
|
1753
1696
|
async bestDiscount(cb) {
|
|
1754
|
-
|
|
1755
|
-
if (!this.store.order)
|
|
1756
|
-
throw new Error("order 模块未初始化");
|
|
1697
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1757
1698
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1758
1699
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
1759
|
-
const
|
|
1700
|
+
const result = {
|
|
1760
1701
|
productList: tempOrder.products || [],
|
|
1761
1702
|
discountList: []
|
|
1762
1703
|
};
|
|
1763
|
-
cb
|
|
1764
|
-
return
|
|
1704
|
+
cb?.(result);
|
|
1705
|
+
return result;
|
|
1765
1706
|
}
|
|
1766
1707
|
const orderStore = this.store.order.store || {};
|
|
1767
1708
|
const discountModule = orderStore.discount;
|
|
1768
1709
|
const rulesModule = orderStore.rules;
|
|
1769
|
-
const originalDiscountList =
|
|
1770
|
-
const currentDiscountList =
|
|
1771
|
-
let nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1772
|
-
originalDiscountList || [],
|
|
1773
|
-
tempOrder.products || []
|
|
1774
|
-
);
|
|
1710
|
+
const originalDiscountList = discountModule?.getOriginalDiscountList?.() || this.getDiscountList();
|
|
1711
|
+
const currentDiscountList = discountModule?.getDiscountList?.() || [];
|
|
1712
|
+
let nextDiscountList = this.mergeHistoricalDiscountList(originalDiscountList || [], tempOrder.products || []);
|
|
1775
1713
|
let result = {
|
|
1776
1714
|
productList: tempOrder.products || [],
|
|
1777
1715
|
discountList: nextDiscountList
|
|
1778
1716
|
};
|
|
1779
|
-
await
|
|
1717
|
+
await discountModule?.setDiscountList(nextDiscountList);
|
|
1780
1718
|
if (rulesModule) {
|
|
1781
|
-
const orderTotalAmount = Number(
|
|
1782
|
-
console.log("[BaseSales.bestDiscount.calcDiscount]");
|
|
1719
|
+
const orderTotalAmount = Number(orderStore.summary?.total_amount || 0);
|
|
1783
1720
|
result = rulesModule.calcDiscount({
|
|
1784
1721
|
productList: tempOrder.products,
|
|
1785
1722
|
discountList: nextDiscountList,
|
|
1786
1723
|
holders: [],
|
|
1787
|
-
isFormSubject:
|
|
1724
|
+
isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
|
|
1788
1725
|
orderTotalAmount
|
|
1789
1726
|
}) || result;
|
|
1790
1727
|
if (result.productList) {
|
|
1791
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1792
|
-
tempOrder.products,
|
|
1793
|
-
result.productList
|
|
1794
|
-
);
|
|
1728
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1795
1729
|
}
|
|
1796
1730
|
if (result.discountList) {
|
|
1797
|
-
nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
);
|
|
1801
|
-
import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1802
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1803
|
-
tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
|
|
1731
|
+
nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
|
|
1732
|
+
_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1733
|
+
await discountModule?.setDiscountList(nextDiscountList);
|
|
1734
|
+
tempOrder.discount_list = nextDiscountList.filter(discount => discount.isSelected);
|
|
1804
1735
|
result = {
|
|
1805
1736
|
productList: tempOrder.products,
|
|
1806
1737
|
discountList: nextDiscountList
|
|
1807
1738
|
};
|
|
1808
1739
|
}
|
|
1809
1740
|
}
|
|
1810
|
-
await this.store.order.recalculateSummary({
|
|
1741
|
+
await this.store.order.recalculateSummary({
|
|
1742
|
+
createIfMissing: true
|
|
1743
|
+
});
|
|
1811
1744
|
this.store.order.persistTempOrder();
|
|
1812
|
-
await this.effectsEmit(
|
|
1745
|
+
await this.effectsEmit('onDiscountApplied', {
|
|
1813
1746
|
productList: tempOrder.products || [],
|
|
1814
1747
|
discountList: nextDiscountList,
|
|
1815
1748
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
1816
1749
|
tempOrder
|
|
1817
1750
|
});
|
|
1818
|
-
cb
|
|
1751
|
+
cb?.(result);
|
|
1819
1752
|
return result;
|
|
1820
1753
|
}
|
|
1821
1754
|
getDiscountList() {
|
|
1822
|
-
if (!this.store.order)
|
|
1823
|
-
return [];
|
|
1755
|
+
if (!this.store.order) return [];
|
|
1824
1756
|
return this.store.order.getDiscountList();
|
|
1825
1757
|
}
|
|
1758
|
+
|
|
1826
1759
|
/** 读取 Discount 模块原始券列表(未经过 bookingTime 等过滤)。 */
|
|
1827
1760
|
getOriginalDiscountList() {
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
const discountModule = (_a = this.store.order.store) == null ? void 0 : _a.discount;
|
|
1832
|
-
return ((_b = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
|
|
1761
|
+
if (!this.store.order) return [];
|
|
1762
|
+
const discountModule = this.store.order.store?.discount;
|
|
1763
|
+
return discountModule?.getOriginalDiscountList?.() || [];
|
|
1833
1764
|
}
|
|
1765
|
+
|
|
1834
1766
|
/**
|
|
1835
1767
|
* 同步写入 Discount 模块的 discountList / originalDiscountList。
|
|
1836
1768
|
* 供 Holder 补全等场景在 OS store 层更新 machinecode holder 字段。
|
|
1837
1769
|
*/
|
|
1838
1770
|
async replaceDiscountStoreLists(params) {
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
const discountModule = (_a = this.store.order.store) == null ? void 0 : _a.discount;
|
|
1843
|
-
if (!discountModule)
|
|
1844
|
-
return;
|
|
1771
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1772
|
+
const discountModule = this.store.order.store?.discount;
|
|
1773
|
+
if (!discountModule) return;
|
|
1845
1774
|
if (params.originalDiscountList) {
|
|
1846
1775
|
await discountModule.setOriginalDiscountList(params.originalDiscountList);
|
|
1847
1776
|
}
|
|
@@ -1849,14 +1778,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1849
1778
|
}
|
|
1850
1779
|
async scanPromotionCode(code, customerId) {
|
|
1851
1780
|
try {
|
|
1852
|
-
if (!this.store.order)
|
|
1853
|
-
throw new Error("order 模块未初始化");
|
|
1781
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1854
1782
|
const raw = await this.store.order.scanCode(code, customerId);
|
|
1855
1783
|
if (raw.isAvailable) {
|
|
1856
|
-
await this.store.order.recalculateSummary({
|
|
1784
|
+
await this.store.order.recalculateSummary({
|
|
1785
|
+
createIfMissing: true
|
|
1786
|
+
});
|
|
1857
1787
|
this.store.order.persistTempOrder();
|
|
1858
1788
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1859
|
-
await this.effectsEmit(
|
|
1789
|
+
await this.effectsEmit('onDiscountApplied', {
|
|
1860
1790
|
productList: tempOrder.products || [],
|
|
1861
1791
|
discountList: this.store.order.getDiscountList(),
|
|
1862
1792
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
@@ -1865,7 +1795,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1865
1795
|
}
|
|
1866
1796
|
return {
|
|
1867
1797
|
isAvailable: raw.isAvailable,
|
|
1868
|
-
...raw.isAccepted !==
|
|
1798
|
+
...(raw.isAccepted !== undefined ? {
|
|
1799
|
+
isAccepted: raw.isAccepted
|
|
1800
|
+
} : {}),
|
|
1869
1801
|
type: raw.type,
|
|
1870
1802
|
unavailableReason: raw.unavailableReason,
|
|
1871
1803
|
scannedDiscountList: raw.scannedDiscountList
|
|
@@ -1874,64 +1806,57 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1874
1806
|
throw error;
|
|
1875
1807
|
}
|
|
1876
1808
|
}
|
|
1809
|
+
|
|
1877
1810
|
// TODO 需要优化,这段逻辑太长了,里面应该有些历史遗留问题
|
|
1878
1811
|
async setDiscountSelected(params) {
|
|
1879
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1880
1812
|
try {
|
|
1881
|
-
if (!this.store.order)
|
|
1882
|
-
throw new Error("order 模块未初始化");
|
|
1813
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1883
1814
|
const currentOrder = this.store.order.ensureTempOrder();
|
|
1884
1815
|
if (this.isActiveVirtualSettlementOrder(currentOrder)) {
|
|
1885
1816
|
currentOrder.discount_list = [];
|
|
1886
|
-
currentOrder.shop_discount =
|
|
1887
|
-
await
|
|
1888
|
-
await this.store.order.recalculateSummary({
|
|
1817
|
+
currentOrder.shop_discount = '0.00';
|
|
1818
|
+
await this.store.order.store?.discount?.setDiscountList?.([]);
|
|
1819
|
+
await this.store.order.recalculateSummary({
|
|
1820
|
+
createIfMissing: true
|
|
1821
|
+
});
|
|
1889
1822
|
this.store.order.persistTempOrder();
|
|
1890
1823
|
return;
|
|
1891
1824
|
}
|
|
1892
1825
|
const list = this.store.order.getDiscountList();
|
|
1893
|
-
const updated = list.map(
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
} : d
|
|
1899
|
-
);
|
|
1826
|
+
const updated = list.map(d => d.id === params.discountId && !isBaseSalesHistoricalDiscountEntry(d) ? {
|
|
1827
|
+
...d,
|
|
1828
|
+
isSelected: params.isSelected,
|
|
1829
|
+
isManualSelect: !params.isSelected
|
|
1830
|
+
} : d);
|
|
1900
1831
|
this.hasManualDiscountSelection = true;
|
|
1901
1832
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1902
1833
|
const orderStore = this.store.order.store || {};
|
|
1903
1834
|
const discountModule = orderStore.discount;
|
|
1904
1835
|
const rulesModule = orderStore.rules;
|
|
1905
1836
|
let nextDiscountList = updated;
|
|
1906
|
-
await
|
|
1837
|
+
await discountModule?.setDiscountList(updated);
|
|
1907
1838
|
if (rulesModule) {
|
|
1908
|
-
const orderTotalAmount = Number(
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
)
|
|
1923
|
-
|
|
1924
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1925
|
-
tempOrder.products,
|
|
1926
|
-
result.productList
|
|
1927
|
-
);
|
|
1839
|
+
const orderTotalAmount = Number(orderStore.summary?.total_amount || 0);
|
|
1840
|
+
const result = rulesModule.calcDiscount({
|
|
1841
|
+
productList: tempOrder.products,
|
|
1842
|
+
discountList: updated,
|
|
1843
|
+
holders: [],
|
|
1844
|
+
isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
|
|
1845
|
+
orderTotalAmount
|
|
1846
|
+
}, {
|
|
1847
|
+
discountId: params.discountId,
|
|
1848
|
+
isSelected: params.isSelected
|
|
1849
|
+
}) || {
|
|
1850
|
+
productList: tempOrder.products,
|
|
1851
|
+
discountList: updated
|
|
1852
|
+
};
|
|
1853
|
+
if (result?.productList) {
|
|
1854
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1928
1855
|
}
|
|
1929
|
-
if (result
|
|
1856
|
+
if (result?.discountList) {
|
|
1930
1857
|
nextDiscountList = result.discountList;
|
|
1931
1858
|
if (!params.isSelected) {
|
|
1932
|
-
const beforeSelectedIds = new Set(
|
|
1933
|
-
updated.filter((d) => d.isSelected).map((d) => d.id)
|
|
1934
|
-
);
|
|
1859
|
+
const beforeSelectedIds = new Set(updated.filter(d => d.isSelected).map(d => d.id));
|
|
1935
1860
|
for (const d of nextDiscountList) {
|
|
1936
1861
|
if (d.isSelected && !beforeSelectedIds.has(d.id)) {
|
|
1937
1862
|
d.isSelected = false;
|
|
@@ -1942,58 +1867,57 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1942
1867
|
}
|
|
1943
1868
|
}
|
|
1944
1869
|
}
|
|
1945
|
-
const selectedResourceIds = new Set(
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
const filterSelectedDiscountDetails = (discountList) => (discountList || []).filter((pd) => {
|
|
1949
|
-
var _a2;
|
|
1950
|
-
const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
|
|
1870
|
+
const selectedResourceIds = new Set(nextDiscountList.filter(d => d.isSelected).map(d => d.id));
|
|
1871
|
+
const filterSelectedDiscountDetails = discountList => (discountList || []).filter(pd => {
|
|
1872
|
+
const rid = pd.discount?.resource_id ?? pd.id;
|
|
1951
1873
|
return rid != null && selectedResourceIds.has(rid);
|
|
1952
1874
|
});
|
|
1953
1875
|
for (const product of tempOrder.products) {
|
|
1954
|
-
const productUid =
|
|
1955
|
-
const runtimeOrigin = productUid ?
|
|
1956
|
-
if (
|
|
1957
|
-
continue;
|
|
1876
|
+
const productUid = product.metadata?.unique_identification_number;
|
|
1877
|
+
const runtimeOrigin = productUid ? tempOrder._extend?.productsByUid?.[productUid]?.origin : undefined;
|
|
1878
|
+
if (runtimeOrigin?.isManualDiscount || isBaseSalesManualProductDiscountProduct(product)) continue;
|
|
1958
1879
|
product.discount_list = filterSelectedDiscountDetails(product.discount_list);
|
|
1959
1880
|
if (Array.isArray(product.product_bundle)) {
|
|
1960
|
-
product.product_bundle = product.product_bundle.map(
|
|
1961
|
-
const nextBundleDiscountList = filterSelectedDiscountDetails(bundle
|
|
1881
|
+
product.product_bundle = product.product_bundle.map(bundle => {
|
|
1882
|
+
const nextBundleDiscountList = filterSelectedDiscountDetails(bundle?.discount_list);
|
|
1962
1883
|
const shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
|
|
1963
|
-
const restoredBundlePrice =
|
|
1884
|
+
const restoredBundlePrice = bundle?.original_price ?? bundle?.product_price ?? bundle?.price;
|
|
1964
1885
|
return {
|
|
1965
1886
|
...bundle,
|
|
1966
|
-
...shouldRestoreBundlePrice ? {
|
|
1887
|
+
...(shouldRestoreBundlePrice ? {
|
|
1967
1888
|
price: restoredBundlePrice,
|
|
1968
1889
|
bundle_selling_price: restoredBundlePrice
|
|
1969
|
-
} : {},
|
|
1890
|
+
} : {}),
|
|
1970
1891
|
discount_list: nextBundleDiscountList
|
|
1971
1892
|
};
|
|
1972
1893
|
});
|
|
1973
1894
|
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
);
|
|
1978
|
-
|
|
1979
|
-
const
|
|
1980
|
-
const
|
|
1981
|
-
const
|
|
1895
|
+
|
|
1896
|
+
// 券作用于 source(不含 option、不含 bundle);算出新 source 折后价后补回 options
|
|
1897
|
+
// 写入含 option 的 main_product_selling_price,再合成 composite 回写 selling_price。
|
|
1898
|
+
const totalPerUnitDiscount = (product.discount_list || []).reduce((sum, pd) => sum + (pd.amount || 0), 0);
|
|
1899
|
+
// TODO 这块逻辑需要拿掉
|
|
1900
|
+
const optionSum = (0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(product));
|
|
1901
|
+
const sourcePrice = product.metadata?.source_product_price ?? (product.metadata?.main_product_original_price != null ? new _decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? '0');
|
|
1902
|
+
const newSourceSellingPrice = new _decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1903
|
+
const newMainSellingPrice = new _decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1982
1904
|
if (product.metadata) {
|
|
1983
1905
|
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
1984
1906
|
product.metadata.price_schema_version = 2;
|
|
1985
1907
|
}
|
|
1986
|
-
product.selling_price = (0,
|
|
1908
|
+
product.selling_price = (0, _utils.composeLinePrice)({
|
|
1987
1909
|
mainPrice: newMainSellingPrice,
|
|
1988
1910
|
bundle: product.product_bundle
|
|
1989
1911
|
});
|
|
1990
1912
|
}
|
|
1991
|
-
|
|
1992
|
-
await
|
|
1993
|
-
tempOrder.discount_list = (nextDiscountList || []).filter(
|
|
1994
|
-
await this.store.order.recalculateSummary({
|
|
1913
|
+
_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1914
|
+
await discountModule?.setDiscountList(nextDiscountList);
|
|
1915
|
+
tempOrder.discount_list = (nextDiscountList || []).filter(d => d.isSelected);
|
|
1916
|
+
await this.store.order.recalculateSummary({
|
|
1917
|
+
createIfMissing: true
|
|
1918
|
+
});
|
|
1995
1919
|
this.store.order.persistTempOrder();
|
|
1996
|
-
this.effectsEmit(
|
|
1920
|
+
this.effectsEmit('onDiscountApplied', {
|
|
1997
1921
|
productList: tempOrder.products,
|
|
1998
1922
|
discountList: nextDiscountList,
|
|
1999
1923
|
selectedDiscountList: tempOrder.discount_list,
|
|
@@ -2005,32 +1929,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2005
1929
|
}
|
|
2006
1930
|
async applyDiscountCalculationResult(result) {
|
|
2007
1931
|
try {
|
|
2008
|
-
if (!this.store.order)
|
|
2009
|
-
|
|
2010
|
-
if (!result)
|
|
2011
|
-
return;
|
|
1932
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1933
|
+
if (!result) return;
|
|
2012
1934
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
2013
1935
|
const orderStore = this.store.order.store || {};
|
|
2014
1936
|
const discountModule = orderStore.discount;
|
|
2015
1937
|
if (result.productList) {
|
|
2016
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
2017
|
-
tempOrder.products,
|
|
2018
|
-
result.productList
|
|
2019
|
-
);
|
|
1938
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
2020
1939
|
}
|
|
2021
1940
|
if (result.discountList) {
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
);
|
|
2030
|
-
}
|
|
2031
|
-
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1941
|
+
_Order.OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
|
|
1942
|
+
await discountModule?.setDiscountList(result.discountList);
|
|
1943
|
+
tempOrder.discount_list = result.discountList.filter(discount => discount.isSelected);
|
|
1944
|
+
}
|
|
1945
|
+
await this.store.order.recalculateSummary({
|
|
1946
|
+
createIfMissing: true
|
|
1947
|
+
});
|
|
2032
1948
|
this.store.order.persistTempOrder();
|
|
2033
|
-
await this.effectsEmit(
|
|
1949
|
+
await this.effectsEmit('onDiscountApplied', {
|
|
2034
1950
|
productList: tempOrder.products || [],
|
|
2035
1951
|
discountList: result.discountList || [],
|
|
2036
1952
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
@@ -2041,41 +1957,35 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2041
1957
|
}
|
|
2042
1958
|
}
|
|
2043
1959
|
async submitScanOrder(params) {
|
|
1960
|
+
// Deprecated compatibility alias. New BaseSales callers should use submitSalesOrder.
|
|
2044
1961
|
return this.submitSalesOrder(params);
|
|
2045
1962
|
}
|
|
2046
1963
|
async buildVirtualSettlementSubmitData() {
|
|
2047
|
-
|
|
2048
|
-
if (!this.store.order)
|
|
2049
|
-
return null;
|
|
1964
|
+
if (!this.store.order) return null;
|
|
2050
1965
|
const tempOrder = this.store.order.getTempOrder();
|
|
2051
|
-
if (!this.isActiveVirtualSettlementOrder(tempOrder))
|
|
2052
|
-
|
|
2053
|
-
const
|
|
2054
|
-
const currencyProductId = Number(
|
|
2055
|
-
((_c = (_b = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_ids) == null ? void 0 : _c[0]) ?? (snapshot == null ? void 0 : snapshot.currency_product_id)
|
|
2056
|
-
);
|
|
1966
|
+
if (!this.isActiveVirtualSettlementOrder(tempOrder)) return null;
|
|
1967
|
+
const snapshot = (0, _virtualSettlement.getTempOrderSettlementSnapshot)(tempOrder);
|
|
1968
|
+
const currencyProductId = Number(tempOrder?.metadata?.currency_settlement_config?.settlement_ids?.[0] ?? snapshot?.currency_product_id);
|
|
2057
1969
|
if (!snapshot || !Number.isFinite(currencyProductId) || currencyProductId <= 0) {
|
|
2058
|
-
throw new Error(
|
|
1970
|
+
throw new Error('Virtual currency settlement configuration is invalid.');
|
|
2059
1971
|
}
|
|
2060
|
-
const summary = await this.store.order.recalculateSummary({
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
).toDecimalPlaces(2);
|
|
2064
|
-
const customerId = Number(
|
|
1972
|
+
const summary = await this.store.order.recalculateSummary({
|
|
1973
|
+
createIfMissing: true
|
|
1974
|
+
});
|
|
1975
|
+
const amount = new _decimal.default(summary?.total_amount || 0).toDecimalPlaces(2);
|
|
1976
|
+
const customerId = Number(tempOrder?.customer_id || 0);
|
|
2065
1977
|
if (amount.gt(0) && customerId > 0 && customerId !== 1) {
|
|
2066
1978
|
await this.store.order.loadDiscountConfig({
|
|
2067
1979
|
customerId,
|
|
2068
|
-
action:
|
|
2069
|
-
orderId: Number(tempOrder
|
|
1980
|
+
action: tempOrder?.order_id ? 'edit' : 'create',
|
|
1981
|
+
orderId: Number(tempOrder?.order_id) || undefined,
|
|
2070
1982
|
apply: false
|
|
2071
1983
|
});
|
|
2072
1984
|
}
|
|
2073
|
-
const asset = this.store.order.getVirtualCurrencyList().find(
|
|
2074
|
-
|
|
2075
|
-
);
|
|
2076
|
-
const
|
|
2077
|
-
const currencySymbol = String((tempOrder == null ? void 0 : tempOrder.currency_symbol) || "");
|
|
2078
|
-
const currencyFormat = String((tempOrder == null ? void 0 : tempOrder.currency_format) || "symbol_first");
|
|
1985
|
+
const asset = this.store.order.getVirtualCurrencyList().find(item => Number(item?.product_id) === currencyProductId);
|
|
1986
|
+
const currencyCode = String(tempOrder?.currency_code || '');
|
|
1987
|
+
const currencySymbol = String(tempOrder?.currency_symbol || '');
|
|
1988
|
+
const currencyFormat = String(tempOrder?.currency_format || 'symbol_first');
|
|
2079
1989
|
if (amount.lte(0)) {
|
|
2080
1990
|
return {
|
|
2081
1991
|
payments: [],
|
|
@@ -2087,34 +1997,35 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2087
1997
|
};
|
|
2088
1998
|
}
|
|
2089
1999
|
if (!asset) {
|
|
2090
|
-
throw new Error(
|
|
2000
|
+
throw new Error('No matching virtual currency card is available.');
|
|
2091
2001
|
}
|
|
2092
|
-
const balance = new
|
|
2002
|
+
const balance = new _decimal.default(asset.balance || 0);
|
|
2093
2003
|
if (balance.lt(amount)) {
|
|
2094
|
-
throw new Error(
|
|
2004
|
+
throw new Error('Insufficient virtual currency balance.');
|
|
2095
2005
|
}
|
|
2096
2006
|
const amountText = amount.toFixed(2);
|
|
2097
|
-
const paymentNumber = `LOCAL_${(0,
|
|
2007
|
+
const paymentNumber = `LOCAL_${(0, _utils.createUuidV4)()}`;
|
|
2098
2008
|
let payment;
|
|
2099
2009
|
if (this.store.order.isOnlineStorePlatform()) {
|
|
2100
2010
|
payment = {
|
|
2101
2011
|
payment_number: paymentNumber,
|
|
2102
2012
|
amount: amount.toNumber(),
|
|
2103
2013
|
metadata: {
|
|
2104
|
-
unique_payment_number: (0,
|
|
2014
|
+
unique_payment_number: (0, _utils.createUuidV4)()
|
|
2105
2015
|
},
|
|
2106
2016
|
tag: asset.tag,
|
|
2107
2017
|
voucher_id: asset.id,
|
|
2108
|
-
wallet_pass_usage_unit: {
|
|
2018
|
+
wallet_pass_usage_unit: {
|
|
2019
|
+
price: 1,
|
|
2020
|
+
points: 1
|
|
2021
|
+
},
|
|
2109
2022
|
wallet_pass_use_value: amountText
|
|
2110
2023
|
};
|
|
2111
2024
|
} else {
|
|
2112
2025
|
const paymentMethods = await this.getPaymentMethodsAsync();
|
|
2113
|
-
const paymentMethod = paymentMethods.find(
|
|
2114
|
-
(method) => String(method.code || "").toUpperCase() === "PRODUCTVOUCHER"
|
|
2115
|
-
);
|
|
2026
|
+
const paymentMethod = paymentMethods.find(method => String(method.code || '').toUpperCase() === 'PRODUCTVOUCHER');
|
|
2116
2027
|
if (!paymentMethod) {
|
|
2117
|
-
throw new Error(
|
|
2028
|
+
throw new Error('PRODUCTVOUCHER payment method is unavailable.');
|
|
2118
2029
|
}
|
|
2119
2030
|
payment = {
|
|
2120
2031
|
payment_number: paymentNumber,
|
|
@@ -2124,10 +2035,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2124
2035
|
custom_payment_id: paymentMethod.id,
|
|
2125
2036
|
custom_payment_type: paymentMethod.custom_payment_type ?? paymentMethod.type,
|
|
2126
2037
|
name: paymentMethod.name,
|
|
2127
|
-
type:
|
|
2038
|
+
type: 'normal',
|
|
2128
2039
|
voucher_id: asset.id,
|
|
2129
|
-
order_payment_type:
|
|
2130
|
-
wallet_pass_usage_unit: {
|
|
2040
|
+
order_payment_type: 'normal',
|
|
2041
|
+
wallet_pass_usage_unit: {
|
|
2042
|
+
price: 1,
|
|
2043
|
+
points: 1
|
|
2044
|
+
},
|
|
2131
2045
|
wallet_pass_use_value: amountText,
|
|
2132
2046
|
metadata: {}
|
|
2133
2047
|
};
|
|
@@ -2141,6 +2055,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2141
2055
|
currencyFormat
|
|
2142
2056
|
};
|
|
2143
2057
|
}
|
|
2058
|
+
|
|
2144
2059
|
/**
|
|
2145
2060
|
* 提交当前 Sales 订单。
|
|
2146
2061
|
*
|
|
@@ -2148,114 +2063,138 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2148
2063
|
* payments 会交给 OrderModule 统一映射为 Sales 协议支付项。
|
|
2149
2064
|
*/
|
|
2150
2065
|
async submitSalesOrder(params) {
|
|
2151
|
-
var _a, _b, _c, _d;
|
|
2152
2066
|
if (!this.store.order) {
|
|
2153
|
-
throw new Error(
|
|
2067
|
+
throw new Error('BaseSales 解决方案需要 order 模块支持');
|
|
2154
2068
|
}
|
|
2155
2069
|
const virtualSettlement = await this.buildVirtualSettlementSubmitData();
|
|
2156
|
-
|
|
2157
|
-
const
|
|
2070
|
+
// this.store.order.persistTempOrder();
|
|
2071
|
+
const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
|
|
2072
|
+
const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
|
|
2073
|
+
const virtualSettlementEnhancePayload = virtualSettlement ? (payload, ctx) => {
|
|
2074
|
+
const callerPayload = params?.enhancePayload ? params.enhancePayload(payload, ctx) : payload;
|
|
2075
|
+
const currencySettlementConfig = callerPayload.metadata?.currency_settlement_config || {};
|
|
2076
|
+
return {
|
|
2077
|
+
...callerPayload,
|
|
2078
|
+
metadata: {
|
|
2079
|
+
...(callerPayload.metadata || {}),
|
|
2080
|
+
currency_settlement_config: {
|
|
2081
|
+
...currencySettlementConfig,
|
|
2082
|
+
settlement_type: 'virtual_currency',
|
|
2083
|
+
settlement_ids: [virtualSettlement.currencyProductId],
|
|
2084
|
+
currency_display_snapshot: (0, _lodashEs.cloneDeep)(currencySettlementConfig.currency_display_snapshot ?? (0, _virtualSettlement.buildCurrencyDisplaySnapshot)(virtualSettlement.snapshot))
|
|
2085
|
+
}
|
|
2086
|
+
},
|
|
2087
|
+
currency_code: virtualSettlement.currencyCode,
|
|
2088
|
+
currency_symbol: virtualSettlement.currencySymbol,
|
|
2089
|
+
currency_format: virtualSettlement.currencyFormat
|
|
2090
|
+
};
|
|
2091
|
+
} : params?.enhancePayload;
|
|
2092
|
+
const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(virtualSettlementEnhancePayload);
|
|
2158
2093
|
const submitParams = {
|
|
2159
2094
|
cacheId: this.cacheId,
|
|
2160
|
-
platform:
|
|
2161
|
-
businessCode:
|
|
2095
|
+
platform: this.otherParams?.platform,
|
|
2096
|
+
businessCode: this.otherParams?.businessCode || this.otherParams?.business_code,
|
|
2162
2097
|
channel: this.getSubmitOrderSalesChannel(),
|
|
2163
|
-
type:
|
|
2098
|
+
type: this.otherParams?.type,
|
|
2164
2099
|
request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
|
|
2165
|
-
...virtualSettlement ? {
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2100
|
+
...(virtualSettlement ? {
|
|
2101
|
+
payments: virtualSettlement.payments
|
|
2102
|
+
} : params?.payments !== undefined ? {
|
|
2103
|
+
payments: params.payments
|
|
2104
|
+
} : {}),
|
|
2105
|
+
...(inferredPaymentStatus !== undefined ? {
|
|
2106
|
+
paymentStatus: inferredPaymentStatus
|
|
2107
|
+
} : {}),
|
|
2108
|
+
...(smallTicketDataFlag !== undefined ? {
|
|
2109
|
+
smallTicketDataFlag
|
|
2110
|
+
} : {}),
|
|
2111
|
+
...(virtualSettlement ? {
|
|
2169
2112
|
confirmPendingVoucherPayments: false
|
|
2170
|
-
} :
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
return {
|
|
2177
|
-
...callerPayload,
|
|
2178
|
-
metadata: {
|
|
2179
|
-
...callerPayload.metadata || {},
|
|
2180
|
-
currency_settlement_config: {
|
|
2181
|
-
...currencySettlementConfig,
|
|
2182
|
-
settlement_type: "virtual_currency",
|
|
2183
|
-
settlement_ids: [virtualSettlement.currencyProductId],
|
|
2184
|
-
currency_display_snapshot: (0, import_lodash_es.cloneDeep)(
|
|
2185
|
-
currencySettlementConfig.currency_display_snapshot ?? (0, import_virtualSettlement.buildCurrencyDisplaySnapshot)(virtualSettlement.snapshot)
|
|
2186
|
-
)
|
|
2187
|
-
}
|
|
2188
|
-
},
|
|
2189
|
-
currency_code: virtualSettlement.currencyCode,
|
|
2190
|
-
currency_symbol: virtualSettlement.currencySymbol,
|
|
2191
|
-
currency_format: virtualSettlement.currencyFormat
|
|
2192
|
-
};
|
|
2193
|
-
}
|
|
2194
|
-
} : (params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
2113
|
+
} : params?.confirmPendingVoucherPayments !== undefined ? {
|
|
2114
|
+
confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
|
|
2115
|
+
} : {}),
|
|
2116
|
+
...(enhancePayload !== undefined ? {
|
|
2117
|
+
enhancePayload
|
|
2118
|
+
} : {})
|
|
2195
2119
|
};
|
|
2196
2120
|
return this.shouldUseCheckoutSyncTask() ? this.store.order.submitTempOrder(submitParams) : this.store.order.submitTempOrderAsync(submitParams);
|
|
2197
2121
|
}
|
|
2198
2122
|
async saveSalesOrderDraft(params) {
|
|
2199
|
-
var _a, _b, _c, _d;
|
|
2200
2123
|
if (!this.store.order) {
|
|
2201
|
-
throw new Error(
|
|
2124
|
+
throw new Error('BaseSales 解决方案需要 order 模块支持');
|
|
2202
2125
|
}
|
|
2203
2126
|
return this.store.order.saveTempOrderAsDraft({
|
|
2204
2127
|
cacheId: this.cacheId,
|
|
2205
|
-
platform:
|
|
2206
|
-
businessCode:
|
|
2207
|
-
channel:
|
|
2208
|
-
type:
|
|
2209
|
-
...(params
|
|
2128
|
+
platform: params?.platform ?? this.otherParams?.platform,
|
|
2129
|
+
businessCode: params?.businessCode || this.otherParams?.businessCode || this.otherParams?.business_code,
|
|
2130
|
+
channel: params?.channel ?? this.getSubmitOrderSalesChannel(),
|
|
2131
|
+
type: params?.type ?? this.otherParams?.type,
|
|
2132
|
+
...(params?.enhancePayload !== undefined ? {
|
|
2133
|
+
enhancePayload: params.enhancePayload
|
|
2134
|
+
} : {})
|
|
2210
2135
|
});
|
|
2211
2136
|
}
|
|
2212
2137
|
async submitTempOrderAsync(params) {
|
|
2213
|
-
var _a, _b, _c, _d;
|
|
2214
2138
|
if (!this.store.order) {
|
|
2215
|
-
throw new Error(
|
|
2139
|
+
throw new Error('BaseSales 解决方案需要 order 模块支持');
|
|
2216
2140
|
}
|
|
2217
|
-
const inferredPaymentStatus = this.getSubmitPaymentStatus(params
|
|
2218
|
-
const smallTicketDataFlag =
|
|
2141
|
+
const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
|
|
2142
|
+
const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
|
|
2143
|
+
const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params?.enhancePayload);
|
|
2219
2144
|
const submitParams = {
|
|
2220
2145
|
cacheId: this.cacheId,
|
|
2221
|
-
platform:
|
|
2222
|
-
businessCode:
|
|
2146
|
+
platform: this.otherParams?.platform,
|
|
2147
|
+
businessCode: this.otherParams?.businessCode || this.otherParams?.business_code,
|
|
2223
2148
|
channel: this.getSubmitOrderSalesChannel(),
|
|
2224
|
-
type:
|
|
2149
|
+
type: this.otherParams?.type,
|
|
2225
2150
|
request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
|
|
2226
|
-
...(params
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
...(
|
|
2230
|
-
|
|
2151
|
+
...(params?.payments !== undefined ? {
|
|
2152
|
+
payments: params.payments
|
|
2153
|
+
} : {}),
|
|
2154
|
+
...(inferredPaymentStatus !== undefined ? {
|
|
2155
|
+
paymentStatus: inferredPaymentStatus
|
|
2156
|
+
} : {}),
|
|
2157
|
+
...(smallTicketDataFlag !== undefined ? {
|
|
2158
|
+
smallTicketDataFlag
|
|
2159
|
+
} : {}),
|
|
2160
|
+
...(params?.confirmPendingVoucherPayments !== undefined ? {
|
|
2161
|
+
confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
|
|
2162
|
+
} : {}),
|
|
2163
|
+
...(enhancePayload !== undefined ? {
|
|
2164
|
+
enhancePayload
|
|
2165
|
+
} : {})
|
|
2231
2166
|
};
|
|
2232
2167
|
return this.store.order.submitTempOrderAsync(submitParams);
|
|
2233
2168
|
}
|
|
2169
|
+
|
|
2234
2170
|
/**
|
|
2235
2171
|
* 默认保持 WebPOS 的本地待同步订单模式;需要云端确认后才算成功的渠道可覆盖此策略。
|
|
2236
2172
|
* otherParams.checkoutSyncTaskEnabled 优先,便于同一 solution 按入口恢复旧行为。
|
|
2237
2173
|
*/
|
|
2238
2174
|
shouldUseCheckoutSyncTask() {
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
return typeof configured === "boolean" ? configured : true;
|
|
2175
|
+
const configured = this.otherParams?.checkoutSyncTaskEnabled;
|
|
2176
|
+
return typeof configured === 'boolean' ? configured : true;
|
|
2242
2177
|
}
|
|
2178
|
+
|
|
2243
2179
|
/** 可由特定 solution 为真实 checkout 补充默认收据数据请求。 */
|
|
2244
2180
|
getDefaultCheckoutSmallTicketDataFlag() {
|
|
2245
|
-
return
|
|
2181
|
+
return undefined;
|
|
2246
2182
|
}
|
|
2247
2183
|
async printLocalOrderReceipt(lookup) {
|
|
2248
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2249
2184
|
if (!this.store.order) {
|
|
2250
|
-
throw new Error(
|
|
2185
|
+
throw new Error('BaseSales 解决方案需要 order 模块支持');
|
|
2251
2186
|
}
|
|
2252
|
-
const hasLookup = lookup !==
|
|
2253
|
-
const lookupPayload = typeof lookup ===
|
|
2187
|
+
const hasLookup = lookup !== undefined && lookup !== null && lookup !== '';
|
|
2188
|
+
const lookupPayload = typeof lookup === 'number' ? {
|
|
2189
|
+
order_id: lookup
|
|
2190
|
+
} : {
|
|
2191
|
+
external_sale_number: lookup
|
|
2192
|
+
};
|
|
2254
2193
|
const context = {
|
|
2255
|
-
platform:
|
|
2256
|
-
businessCode:
|
|
2194
|
+
platform: this.otherParams?.platform,
|
|
2195
|
+
businessCode: this.otherParams?.businessCode || this.otherParams?.business_code,
|
|
2257
2196
|
channel: this.getSubmitOrderSalesChannel(),
|
|
2258
|
-
type:
|
|
2197
|
+
type: this.otherParams?.type
|
|
2259
2198
|
};
|
|
2260
2199
|
const payload = hasLookup ? {
|
|
2261
2200
|
...lookupPayload,
|
|
@@ -2272,48 +2211,61 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2272
2211
|
channel: context.channel,
|
|
2273
2212
|
type: context.type
|
|
2274
2213
|
});
|
|
2275
|
-
const
|
|
2214
|
+
const invoiceLayoutConfig = this.getCachedInvoiceLayoutConfig();
|
|
2215
|
+
const invoiceTemplateSettings = this.getCachedInvoiceTemplateSettings();
|
|
2216
|
+
const printPayload = {
|
|
2217
|
+
...payload,
|
|
2218
|
+
...(invoiceLayoutConfig ? {
|
|
2219
|
+
invoice: (0, _lodashEs.cloneDeep)(invoiceLayoutConfig)
|
|
2220
|
+
} : {}),
|
|
2221
|
+
...(invoiceTemplateSettings ? {
|
|
2222
|
+
template_settings: (0, _lodashEs.cloneDeep)(invoiceTemplateSettings)
|
|
2223
|
+
} : {})
|
|
2224
|
+
};
|
|
2225
|
+
const response = await this.request.post('/local/print-order', printPayload, {
|
|
2276
2226
|
osServer: true,
|
|
2277
|
-
customToast: () => {
|
|
2278
|
-
}
|
|
2227
|
+
customToast: () => {}
|
|
2279
2228
|
});
|
|
2280
2229
|
if (!hasLookup) {
|
|
2281
|
-
await
|
|
2230
|
+
await this.store.order.applyLocalPrintOrderNumbers?.(response?.data?.order);
|
|
2282
2231
|
}
|
|
2283
2232
|
return response;
|
|
2284
2233
|
}
|
|
2285
2234
|
getSubmitPaymentStatus(paymentStatus) {
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
const amountSnapshot = (_b = (_a = this.store.order) == null ? void 0 : _a.getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
|
|
2290
|
-
if (!amountSnapshot)
|
|
2291
|
-
return void 0;
|
|
2235
|
+
if (paymentStatus !== undefined) return paymentStatus;
|
|
2236
|
+
const amountSnapshot = this.store.order?.getOrderAmountSnapshot?.();
|
|
2237
|
+
if (!amountSnapshot) return undefined;
|
|
2292
2238
|
try {
|
|
2293
|
-
return new
|
|
2239
|
+
return new _decimal.default(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
|
|
2294
2240
|
} catch {
|
|
2295
|
-
return
|
|
2241
|
+
return undefined;
|
|
2296
2242
|
}
|
|
2297
2243
|
}
|
|
2298
2244
|
async syncPaymentsToOrder(params) {
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
throw new Error("order 模块未初始化");
|
|
2302
|
-
const businessCode = params.businessCode ?? ((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.business_code);
|
|
2245
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2246
|
+
const businessCode = params.businessCode ?? this.otherParams?.businessCode ?? this.otherParams?.business_code;
|
|
2303
2247
|
const channel = params.channel ?? this.getSubmitOrderSalesChannel();
|
|
2248
|
+
const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params.enhancePayload);
|
|
2304
2249
|
const syncParams = {
|
|
2305
2250
|
...params,
|
|
2306
2251
|
checkoutSyncTaskEnabled: this.shouldUseCheckoutSyncTask(),
|
|
2307
|
-
...businessCode !==
|
|
2308
|
-
|
|
2252
|
+
...(businessCode !== undefined ? {
|
|
2253
|
+
businessCode
|
|
2254
|
+
} : {}),
|
|
2255
|
+
...(channel !== undefined ? {
|
|
2256
|
+
channel
|
|
2257
|
+
} : {}),
|
|
2258
|
+
...(enhancePayload !== undefined ? {
|
|
2259
|
+
enhancePayload
|
|
2260
|
+
} : {})
|
|
2309
2261
|
};
|
|
2310
2262
|
const syncState = this.store.order.getOrderSyncState();
|
|
2311
|
-
if (params.submitWhenPaid && syncState ===
|
|
2263
|
+
if (params.submitWhenPaid && syncState === 'submitting') {
|
|
2312
2264
|
this.queueLatestAutoPaymentSync();
|
|
2313
2265
|
return this.store.order.syncPaymentsToOrder(syncParams);
|
|
2314
2266
|
}
|
|
2315
2267
|
const payments = params.payments || [];
|
|
2316
|
-
await this.effectsEmit(
|
|
2268
|
+
await this.effectsEmit(_types.BaseSalesHookNames.onPaymentSyncStart, {
|
|
2317
2269
|
payments,
|
|
2318
2270
|
params: syncParams,
|
|
2319
2271
|
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
@@ -2338,14 +2290,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2338
2290
|
depositAmount: syncResult.depositAmount,
|
|
2339
2291
|
orderExpectedAmount: syncResult.orderExpectedAmount
|
|
2340
2292
|
};
|
|
2341
|
-
await this.effectsEmit(
|
|
2293
|
+
await this.effectsEmit(_types.BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
|
|
2342
2294
|
if (syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid) {
|
|
2343
|
-
await this.effectsEmit(
|
|
2295
|
+
await this.effectsEmit(_types.BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
|
|
2344
2296
|
}
|
|
2345
2297
|
this.scheduleQueuedAutoPaymentSyncFlush(0);
|
|
2346
2298
|
return syncResult;
|
|
2347
2299
|
} catch (error) {
|
|
2348
|
-
await this.effectsEmit(
|
|
2300
|
+
await this.effectsEmit(_types.BaseSalesHookNames.onPaymentSyncEnd, {
|
|
2349
2301
|
ok: false,
|
|
2350
2302
|
error,
|
|
2351
2303
|
payments: this.store.order.getOrderPayments(),
|
|
@@ -2357,46 +2309,41 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2357
2309
|
throw error;
|
|
2358
2310
|
}
|
|
2359
2311
|
}
|
|
2312
|
+
|
|
2360
2313
|
/** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
|
|
2361
2314
|
getOrderPayments() {
|
|
2362
|
-
if (!this.store.order)
|
|
2363
|
-
return [];
|
|
2315
|
+
if (!this.store.order) return [];
|
|
2364
2316
|
const payments = this.store.order.getOrderPayments();
|
|
2365
2317
|
return this.hydrateOrderPaymentNames(payments);
|
|
2366
2318
|
}
|
|
2319
|
+
|
|
2367
2320
|
/** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
|
|
2368
2321
|
setOrderPayments(payments) {
|
|
2369
|
-
if (!this.store.order)
|
|
2370
|
-
throw new Error("order 模块未初始化");
|
|
2322
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2371
2323
|
return this.store.order.setOrderPayments(payments);
|
|
2372
2324
|
}
|
|
2373
2325
|
getPaymentStatusForSync(payments) {
|
|
2374
2326
|
const order = this.store.order;
|
|
2375
|
-
if (!order)
|
|
2376
|
-
throw new Error("order 模块未初始化");
|
|
2327
|
+
if (!order) throw new Error('order 模块未初始化');
|
|
2377
2328
|
const completion = order.getPaymentCompletion(payments);
|
|
2378
|
-
return completion.isOrderFullyPaid ?
|
|
2329
|
+
return completion.isOrderFullyPaid ? 'paid' : 'partially_paid';
|
|
2379
2330
|
}
|
|
2380
2331
|
queueLatestAutoPaymentSync() {
|
|
2381
2332
|
this.queuedAutoPaymentSync = true;
|
|
2382
2333
|
this.scheduleQueuedAutoPaymentSyncFlush();
|
|
2383
2334
|
}
|
|
2384
2335
|
scheduleQueuedAutoPaymentSyncFlush(delay = 100) {
|
|
2385
|
-
if (!this.queuedAutoPaymentSync)
|
|
2386
|
-
|
|
2387
|
-
if (this.autoPaymentSyncTimer)
|
|
2388
|
-
return;
|
|
2336
|
+
if (!this.queuedAutoPaymentSync) return;
|
|
2337
|
+
if (this.autoPaymentSyncTimer) return;
|
|
2389
2338
|
this.autoPaymentSyncTimer = setTimeout(() => {
|
|
2390
2339
|
this.autoPaymentSyncTimer = null;
|
|
2391
2340
|
void this.flushQueuedAutoPaymentSync();
|
|
2392
2341
|
}, delay);
|
|
2393
2342
|
}
|
|
2394
2343
|
async flushQueuedAutoPaymentSync() {
|
|
2395
|
-
if (!this.store.order)
|
|
2396
|
-
|
|
2397
|
-
if (
|
|
2398
|
-
return;
|
|
2399
|
-
if (this.store.order.getOrderSyncState() === "submitting") {
|
|
2344
|
+
if (!this.store.order) return;
|
|
2345
|
+
if (!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing) return;
|
|
2346
|
+
if (this.store.order.getOrderSyncState() === 'submitting') {
|
|
2400
2347
|
this.scheduleQueuedAutoPaymentSyncFlush();
|
|
2401
2348
|
return;
|
|
2402
2349
|
}
|
|
@@ -2405,8 +2352,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2405
2352
|
while (this.queuedAutoPaymentSync) {
|
|
2406
2353
|
this.queuedAutoPaymentSync = false;
|
|
2407
2354
|
const payments = this.store.order.getOrderPayments();
|
|
2408
|
-
if (!payments.length)
|
|
2409
|
-
continue;
|
|
2355
|
+
if (!payments.length) continue;
|
|
2410
2356
|
await this.syncPaymentsToOrder({
|
|
2411
2357
|
payments,
|
|
2412
2358
|
paymentStatus: this.getPaymentStatusForSync(payments),
|
|
@@ -2415,7 +2361,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2415
2361
|
});
|
|
2416
2362
|
}
|
|
2417
2363
|
} catch (error) {
|
|
2418
|
-
this.logError(
|
|
2364
|
+
this.logError('queued auto sync payments failed', {
|
|
2419
2365
|
error: error instanceof Error ? error.message : String(error)
|
|
2420
2366
|
});
|
|
2421
2367
|
} finally {
|
|
@@ -2425,69 +2371,64 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2425
2371
|
}
|
|
2426
2372
|
}
|
|
2427
2373
|
}
|
|
2374
|
+
|
|
2428
2375
|
/**
|
|
2429
2376
|
* 同步兼容入口。无法等待 IoT 短号时,按调用当下的 device_id 或 LOCAL 生成。
|
|
2430
2377
|
*/
|
|
2431
2378
|
addOrderPayment(payment) {
|
|
2432
|
-
const hasPaymentNumber = String(
|
|
2433
|
-
|
|
2434
|
-
).trim() !== "";
|
|
2435
|
-
return this.addOrderPaymentWithDevicePrefix(
|
|
2436
|
-
payment,
|
|
2437
|
-
hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
|
|
2438
|
-
);
|
|
2379
|
+
const hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
|
|
2380
|
+
return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
|
|
2439
2381
|
}
|
|
2382
|
+
|
|
2440
2383
|
/**
|
|
2441
2384
|
* 创建新支付项时优先使用业务解决方案初始化阶段缓存的设备短号;
|
|
2442
2385
|
* 未缓存的通用 BaseSales 保持实时读取设备信息的兼容语义。
|
|
2443
2386
|
*/
|
|
2444
2387
|
async addOrderPaymentAsync(payment) {
|
|
2445
2388
|
const paymentRecord = payment;
|
|
2446
|
-
const hasPaymentNumber = String(paymentRecord.payment_number ||
|
|
2447
|
-
const devicePrefix = hasPaymentNumber ?
|
|
2389
|
+
const hasPaymentNumber = String(paymentRecord.payment_number || '').trim() !== '';
|
|
2390
|
+
const devicePrefix = hasPaymentNumber ? 'LOCAL' : await this.getPaymentNumberDevicePrefixAsync();
|
|
2448
2391
|
return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
|
|
2449
2392
|
}
|
|
2450
2393
|
addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
|
|
2451
|
-
|
|
2452
|
-
if (!this.store.order)
|
|
2453
|
-
throw new Error("order 模块未初始化");
|
|
2394
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2454
2395
|
const paymentRecord = payment;
|
|
2455
|
-
const paymentAmount = new
|
|
2396
|
+
const paymentAmount = new _decimal.default(paymentRecord.amount || 0);
|
|
2456
2397
|
if (paymentAmount.isZero()) {
|
|
2457
|
-
this.logWarning(
|
|
2398
|
+
this.logWarning('addOrderPayment: 支付金额为 0,跳过添加支付项', {
|
|
2458
2399
|
payment: paymentRecord
|
|
2459
2400
|
});
|
|
2460
2401
|
return this.store.order.getOrderPayments();
|
|
2461
2402
|
}
|
|
2462
|
-
const metadata = paymentRecord.metadata && typeof paymentRecord.metadata ===
|
|
2463
|
-
|
|
2464
|
-
|
|
2403
|
+
const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === 'object' ? {
|
|
2404
|
+
...paymentRecord.metadata
|
|
2405
|
+
} : {};
|
|
2406
|
+
const shopWalletPassId = this.otherParams?.shop_wallet_pass_id;
|
|
2407
|
+
if (shopWalletPassId !== undefined && shopWalletPassId !== null) {
|
|
2465
2408
|
metadata.shop_wallet_pass_id = shopWalletPassId;
|
|
2466
2409
|
}
|
|
2467
|
-
const normalizedPaymentRecord = (0,
|
|
2468
|
-
|
|
2469
|
-
devicePrefix,
|
|
2470
|
-
import_utils.createUuidV4
|
|
2471
|
-
);
|
|
2472
|
-
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
2410
|
+
const normalizedPaymentRecord = (0, _paymentUtils.ensureOrderPaymentNumber)(paymentRecord, devicePrefix, _utils.createUuidV4);
|
|
2411
|
+
const paymentTimestamp = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
2473
2412
|
const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
|
|
2474
2413
|
const createdAt = paymentRecord.created_at ?? paymentTimestamp;
|
|
2475
|
-
const serviceCharge = paymentRecord.service_charge && typeof paymentRecord.service_charge ===
|
|
2476
|
-
const calculatedServiceFee = serviceCharge ? new
|
|
2414
|
+
const serviceCharge = paymentRecord.service_charge && typeof paymentRecord.service_charge === 'object' ? paymentRecord.service_charge : null;
|
|
2415
|
+
const calculatedServiceFee = serviceCharge ? new _decimal.default(paymentRecord.origin_amount ?? paymentRecord.amount ?? 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
|
|
2477
2416
|
const payments = this.store.order.addOrderPayment({
|
|
2478
2417
|
...normalizedPaymentRecord,
|
|
2479
|
-
...calculatedServiceFee !==
|
|
2418
|
+
...(calculatedServiceFee !== undefined ? {
|
|
2419
|
+
service_fee: calculatedServiceFee
|
|
2420
|
+
} : {}),
|
|
2480
2421
|
metadata,
|
|
2481
2422
|
payment_time: paymentTime,
|
|
2482
2423
|
created_at: createdAt
|
|
2483
2424
|
});
|
|
2484
|
-
if (paymentRecord.status ===
|
|
2425
|
+
if (paymentRecord.status === 'payment_pending') {
|
|
2485
2426
|
return payments;
|
|
2486
2427
|
}
|
|
2487
2428
|
const amountSnapshot = this.store.order.getOrderAmountSnapshot();
|
|
2488
2429
|
const syncState = this.store.order.getOrderSyncState();
|
|
2489
2430
|
if (amountSnapshot) {
|
|
2490
|
-
if (syncState ===
|
|
2431
|
+
if (syncState === 'submitting') {
|
|
2491
2432
|
this.queueLatestAutoPaymentSync();
|
|
2492
2433
|
return payments;
|
|
2493
2434
|
}
|
|
@@ -2496,31 +2437,26 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2496
2437
|
paymentStatus: this.getPaymentStatusForSync(payments),
|
|
2497
2438
|
submitWhenPaid: true,
|
|
2498
2439
|
smallTicketDataFlag: 1
|
|
2499
|
-
}).catch(
|
|
2500
|
-
this.logError(
|
|
2440
|
+
}).catch(error => {
|
|
2441
|
+
this.logError('auto sync payments failed', {
|
|
2501
2442
|
error: error instanceof Error ? error.message : String(error)
|
|
2502
2443
|
});
|
|
2503
2444
|
});
|
|
2504
2445
|
}
|
|
2505
2446
|
return payments;
|
|
2506
2447
|
}
|
|
2448
|
+
|
|
2507
2449
|
/** 更新当前订单中的指定支付项。 */
|
|
2508
2450
|
async updateOrderPayment(paymentIdentity, updates, options = {}) {
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
const
|
|
2513
|
-
|
|
2514
|
-
this.store.order.getOrderPayments(),
|
|
2515
|
-
paymentIdentity,
|
|
2516
|
-
matchMode
|
|
2517
|
-
);
|
|
2518
|
-
const previousPayment = previousMatch == null ? void 0 : previousMatch.payment;
|
|
2519
|
-
if ((previousPayment == null ? void 0 : previousPayment.status) === "paid" && !options.applyUpdatesWhenPaid) {
|
|
2451
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2452
|
+
const matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
|
|
2453
|
+
const previousMatch = (0, _paymentUtils.resolveOrderPaymentIdentity)(this.store.order.getOrderPayments(), paymentIdentity, matchMode);
|
|
2454
|
+
const previousPayment = previousMatch?.payment;
|
|
2455
|
+
if (previousPayment?.status === 'paid' && !options.applyUpdatesWhenPaid) {
|
|
2520
2456
|
const currentPayments = this.store.order.getOrderPayments();
|
|
2521
|
-
let
|
|
2457
|
+
let syncResult;
|
|
2522
2458
|
if (options.submitWhenPaid && options.forceSubmitIfPaid) {
|
|
2523
|
-
|
|
2459
|
+
syncResult = await this.syncPaymentsToOrder({
|
|
2524
2460
|
payments: currentPayments,
|
|
2525
2461
|
paymentStatus: this.getPaymentStatusForSync(currentPayments),
|
|
2526
2462
|
submitWhenPaid: true,
|
|
@@ -2531,8 +2467,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2531
2467
|
updated: false,
|
|
2532
2468
|
payment: previousPayment,
|
|
2533
2469
|
payments: currentPayments,
|
|
2534
|
-
summary:
|
|
2535
|
-
...
|
|
2470
|
+
summary: this.store.order.getOrderAmountSnapshot()?.summary || null,
|
|
2471
|
+
...(syncResult !== undefined ? {
|
|
2472
|
+
syncResult
|
|
2473
|
+
} : {})
|
|
2536
2474
|
};
|
|
2537
2475
|
}
|
|
2538
2476
|
const result = await this.store.order.updateOrderPayment(paymentIdentity, updates, {
|
|
@@ -2545,18 +2483,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2545
2483
|
draftResult = await this.saveSalesOrderDraft();
|
|
2546
2484
|
} catch (error) {
|
|
2547
2485
|
draftError = error;
|
|
2548
|
-
this.logError(
|
|
2486
|
+
this.logError('updateOrderPayment: 保存支付草稿失败', {
|
|
2549
2487
|
paymentIdentity,
|
|
2550
2488
|
error: error instanceof Error ? error.message : String(error)
|
|
2551
2489
|
});
|
|
2552
|
-
if (!options.submitWhenPaid)
|
|
2553
|
-
throw error;
|
|
2490
|
+
if (!options.submitWhenPaid) throw error;
|
|
2554
2491
|
}
|
|
2555
2492
|
}
|
|
2556
|
-
const becamePaid =
|
|
2557
|
-
const shouldSubmit = Boolean(
|
|
2558
|
-
options.submitWhenPaid && ((_c = result.payment) == null ? void 0 : _c.status) === "paid" && (becamePaid || options.forceSubmitIfPaid)
|
|
2559
|
-
);
|
|
2493
|
+
const becamePaid = previousPayment?.status !== 'paid' && result.payment?.status === 'paid';
|
|
2494
|
+
const shouldSubmit = Boolean(options.submitWhenPaid && result.payment?.status === 'paid' && (becamePaid || options.forceSubmitIfPaid));
|
|
2560
2495
|
let syncResult;
|
|
2561
2496
|
if (shouldSubmit) {
|
|
2562
2497
|
syncResult = await this.syncPaymentsToOrder({
|
|
@@ -2568,60 +2503,62 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2568
2503
|
}
|
|
2569
2504
|
return {
|
|
2570
2505
|
...result,
|
|
2571
|
-
...draftResult !==
|
|
2572
|
-
|
|
2573
|
-
|
|
2506
|
+
...(draftResult !== undefined ? {
|
|
2507
|
+
draftResult
|
|
2508
|
+
} : {}),
|
|
2509
|
+
...(draftError !== undefined ? {
|
|
2510
|
+
draftError
|
|
2511
|
+
} : {}),
|
|
2512
|
+
...(syncResult !== undefined ? {
|
|
2513
|
+
syncResult
|
|
2514
|
+
} : {})
|
|
2574
2515
|
};
|
|
2575
2516
|
}
|
|
2517
|
+
|
|
2576
2518
|
/** 删除当前订单中的指定支付项。 */
|
|
2577
2519
|
deleteOrderPayment(paymentIdentity) {
|
|
2578
|
-
if (!this.store.order)
|
|
2579
|
-
throw new Error("order 模块未初始化");
|
|
2520
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2580
2521
|
return this.store.order.deleteOrderPayment(paymentIdentity);
|
|
2581
2522
|
}
|
|
2523
|
+
|
|
2582
2524
|
/** 覆盖 wallet pass 支付项,同时保留普通支付项。 */
|
|
2583
2525
|
updateVoucherOrderPayments(payments, options) {
|
|
2584
|
-
if (!this.store.order)
|
|
2585
|
-
throw new Error("order 模块未初始化");
|
|
2526
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2586
2527
|
return this.store.order.updateVoucherOrderPayments(payments, options);
|
|
2587
2528
|
}
|
|
2588
2529
|
async updateVoucherOrderPaymentsAsync(payments, options) {
|
|
2589
|
-
if (!this.store.order)
|
|
2590
|
-
throw new Error("order 模块未初始化");
|
|
2530
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2591
2531
|
return this.store.order.updateVoucherOrderPaymentsAsync(payments, options);
|
|
2592
2532
|
}
|
|
2593
2533
|
confirmPendingVoucherPayments() {
|
|
2594
|
-
if (!this.store.order)
|
|
2595
|
-
throw new Error("order 模块未初始化");
|
|
2534
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2596
2535
|
const payments = this.store.order.confirmPendingVoucherPayments();
|
|
2597
2536
|
if (this.store.payment) {
|
|
2598
2537
|
const committed = this.getCommittedWalletAssets();
|
|
2599
|
-
const state = this.store.payment.wallet.setCommittedWalletAssets(
|
|
2600
|
-
committed.ids,
|
|
2601
|
-
committed.assets
|
|
2602
|
-
);
|
|
2538
|
+
const state = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
2603
2539
|
void this.publishWalletAssetsState(state);
|
|
2604
2540
|
}
|
|
2605
2541
|
return payments;
|
|
2606
2542
|
}
|
|
2607
2543
|
discardPendingVoucherPayments() {
|
|
2608
|
-
if (!this.store.order)
|
|
2609
|
-
throw new Error("order 模块未初始化");
|
|
2544
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2610
2545
|
return this.store.order.discardPendingVoucherPayments();
|
|
2611
2546
|
}
|
|
2612
2547
|
getWalletProductList() {
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
const
|
|
2548
|
+
const tempOrder = this.store.order?.getTempOrder();
|
|
2549
|
+
if (!tempOrder?.products?.length) return [];
|
|
2550
|
+
// 过滤出有 product_id的商品来,如果没有代表他是自定义商品,不需要参与 wallet
|
|
2551
|
+
// debugger
|
|
2552
|
+
// const products = tempOrder?.products?.filter(n => n.product_id)
|
|
2553
|
+
|
|
2554
|
+
const walletProducts = tempOrder?.products.map(product => {
|
|
2618
2555
|
const metadata = product.metadata || {};
|
|
2619
2556
|
const rawHolderId = product.holder_id ?? metadata.holder_id;
|
|
2620
2557
|
const holderIdValue = Array.isArray(rawHolderId) ? rawHolderId[0] : rawHolderId;
|
|
2621
|
-
const holder_id = Number.isInteger(Number(holderIdValue)) ? Number(holderIdValue) :
|
|
2558
|
+
const holder_id = Number.isInteger(Number(holderIdValue)) ? Number(holderIdValue) : undefined;
|
|
2622
2559
|
return {
|
|
2623
2560
|
product_id: product.product_id || 0,
|
|
2624
|
-
product_variant_id: String(product.product_variant_id ??
|
|
2561
|
+
product_variant_id: String(product.product_variant_id ?? ''),
|
|
2625
2562
|
quantity: product.num || 1,
|
|
2626
2563
|
is_price_include_tax: tempOrder.is_price_include_tax,
|
|
2627
2564
|
is_charge_tax: product.is_charge_tax ?? 0,
|
|
@@ -2637,7 +2574,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2637
2574
|
main_product_attached_bundle_surcharge_fee: metadata.main_product_attached_bundle_surcharge_fee,
|
|
2638
2575
|
surcharge_rounding_remainder: metadata.surcharge_rounding_remainder
|
|
2639
2576
|
},
|
|
2640
|
-
product_bundle: (product.product_bundle || []).map(
|
|
2577
|
+
product_bundle: (product.product_bundle || []).map(bundle => {
|
|
2641
2578
|
const bundleMetadata = bundle.metadata || {};
|
|
2642
2579
|
return {
|
|
2643
2580
|
is_price_include_tax: tempOrder.is_price_include_tax,
|
|
@@ -2664,14 +2601,12 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2664
2601
|
return walletProducts;
|
|
2665
2602
|
}
|
|
2666
2603
|
buildWalletInitBusinessData(params) {
|
|
2667
|
-
|
|
2668
|
-
const
|
|
2669
|
-
const
|
|
2670
|
-
|
|
2671
|
-
if (!tempOrder || !amount)
|
|
2672
|
-
return null;
|
|
2604
|
+
const snapshot = this.store.order?.getOrderSnapshot();
|
|
2605
|
+
const tempOrder = snapshot?.tempOrder;
|
|
2606
|
+
const amount = snapshot?.amount;
|
|
2607
|
+
if (!tempOrder || !amount) return null;
|
|
2673
2608
|
return {
|
|
2674
|
-
customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) :
|
|
2609
|
+
customer_id: tempOrder.customer_id ? Number(tempOrder.customer_id) : undefined,
|
|
2675
2610
|
holder: tempOrder.holder,
|
|
2676
2611
|
amountInfo: {
|
|
2677
2612
|
totalAmount: amount.totalAmount,
|
|
@@ -2680,17 +2615,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2680
2615
|
isDeposit: tempOrder.is_deposit
|
|
2681
2616
|
},
|
|
2682
2617
|
products: this.getWalletProductList(),
|
|
2683
|
-
order_wait_pay_amount:
|
|
2618
|
+
order_wait_pay_amount: params?.order_wait_pay_amount ?? Number(amount.amountGap || 0),
|
|
2684
2619
|
is_price_include_tax: tempOrder.is_price_include_tax ?? this.otherParams.is_price_include_tax ?? 1,
|
|
2685
|
-
...snapshot.identity.orderId ? {
|
|
2620
|
+
...(snapshot.identity.orderId ? {
|
|
2621
|
+
payment_order_id: String(snapshot.identity.orderId)
|
|
2622
|
+
} : {})
|
|
2686
2623
|
};
|
|
2687
2624
|
}
|
|
2688
2625
|
async initWalletData(params) {
|
|
2689
|
-
|
|
2690
|
-
if (!this.store.
|
|
2691
|
-
throw new Error("order 模块未初始化");
|
|
2692
|
-
if (!this.store.payment)
|
|
2693
|
-
throw new Error("payment 模块未初始化");
|
|
2626
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2627
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2694
2628
|
const snapshot = this.store.order.getOrderSnapshot();
|
|
2695
2629
|
const walletBusinessData = this.buildWalletInitBusinessData(params);
|
|
2696
2630
|
if (!walletBusinessData) {
|
|
@@ -2702,11 +2636,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2702
2636
|
products: []
|
|
2703
2637
|
};
|
|
2704
2638
|
}
|
|
2705
|
-
const result = await this.store.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
2706
|
-
walletBusinessData
|
|
2707
|
-
);
|
|
2639
|
+
const result = await this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
|
|
2708
2640
|
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
2709
|
-
orderId:
|
|
2641
|
+
orderId: snapshot?.identity?.orderId,
|
|
2710
2642
|
customerId: walletBusinessData.customer_id,
|
|
2711
2643
|
walletBusinessData: {
|
|
2712
2644
|
customer_id: walletBusinessData.customer_id,
|
|
@@ -2718,26 +2650,22 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2718
2650
|
return result;
|
|
2719
2651
|
}
|
|
2720
2652
|
getCommittedWalletAssets() {
|
|
2721
|
-
|
|
2722
|
-
const
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
if (voucherId === void 0 || voucherId === null || voucherId === 0) {
|
|
2653
|
+
const payments = this.store.order?.getOrderPayments?.() || [];
|
|
2654
|
+
const committed = payments.filter(payment => {
|
|
2655
|
+
const voucherId = payment?.voucher_id;
|
|
2656
|
+
if (voucherId === undefined || voucherId === null || voucherId === 0) {
|
|
2726
2657
|
return false;
|
|
2727
2658
|
}
|
|
2728
|
-
return
|
|
2659
|
+
return payment?.status === 'paid' || payment?.isSynced === true || payment?.order_payment_id !== undefined && payment?.order_payment_id !== null && payment?.order_payment_id !== '';
|
|
2729
2660
|
});
|
|
2730
2661
|
return {
|
|
2731
|
-
ids: committed.map(
|
|
2732
|
-
assets: committed.map(
|
|
2733
|
-
|
|
2734
|
-
const fundRecord = (payment == null ? void 0 : payment.fund_record) || {};
|
|
2662
|
+
ids: committed.map(payment => payment.voucher_id),
|
|
2663
|
+
assets: committed.map(payment => {
|
|
2664
|
+
const fundRecord = payment?.fund_record || {};
|
|
2735
2665
|
const walletPassName = fundRecord.wallet_pass_name;
|
|
2736
|
-
const title = walletPassName && typeof walletPassName ===
|
|
2737
|
-
const code = String(
|
|
2738
|
-
const tag =
|
|
2739
|
-
([, paymentCode]) => paymentCode === code
|
|
2740
|
-
)) == null ? void 0 : _a2[0]) || fundRecord.tag;
|
|
2666
|
+
const title = walletPassName && typeof walletPassName === 'object' ? walletPassName.default || Object.values(walletPassName)[0] : walletPassName;
|
|
2667
|
+
const code = String(payment?.code || '').toUpperCase();
|
|
2668
|
+
const tag = Object.entries(WALLET_PAYMENT_CODE_BY_TAG).find(([, paymentCode]) => paymentCode === code)?.[0] || fundRecord.tag;
|
|
2741
2669
|
return {
|
|
2742
2670
|
id: payment.voucher_id,
|
|
2743
2671
|
voucher_id: payment.voucher_id,
|
|
@@ -2755,34 +2683,25 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2755
2683
|
};
|
|
2756
2684
|
}
|
|
2757
2685
|
async publishWalletAssetsState(state) {
|
|
2758
|
-
await this.effectsEmit(
|
|
2686
|
+
await this.effectsEmit(_types.BaseSalesHookNames.onWalletAssetsStateChanged, {
|
|
2759
2687
|
state
|
|
2760
2688
|
});
|
|
2761
2689
|
return state;
|
|
2762
2690
|
}
|
|
2763
2691
|
async syncSelectedWalletAssets(state) {
|
|
2764
2692
|
if (!this.store.order || !this.store.payment) {
|
|
2765
|
-
throw new Error(
|
|
2693
|
+
throw new Error('订单或支付模块未初始化');
|
|
2766
2694
|
}
|
|
2767
2695
|
let paymentMethods = this.getPaymentMethods();
|
|
2768
2696
|
if (!paymentMethods.length && state.selectedItems.length) {
|
|
2769
2697
|
paymentMethods = await this.getPaymentMethodsAsync();
|
|
2770
2698
|
}
|
|
2771
|
-
const methodByCode = new Map(
|
|
2772
|
-
|
|
2773
|
-
);
|
|
2774
|
-
const
|
|
2775
|
-
state.selectedItems
|
|
2776
|
-
);
|
|
2777
|
-
const selectedAssetById = new Map(
|
|
2778
|
-
state.selectedItems.map((asset) => [
|
|
2779
|
-
String(getSharedWalletAssetId(asset)),
|
|
2780
|
-
asset
|
|
2781
|
-
])
|
|
2782
|
-
);
|
|
2783
|
-
const voucherPayments = preparePayments.flatMap((item) => {
|
|
2699
|
+
const methodByCode = new Map(paymentMethods.map(method => [String(method.code || '').toUpperCase(), method]));
|
|
2700
|
+
const preparePayments = this.store.payment.wallet.formatWalletPassList2PreparePayments(state.selectedItems);
|
|
2701
|
+
const selectedAssetById = new Map(state.selectedItems.map(asset => [String(getSharedWalletAssetId(asset)), asset]));
|
|
2702
|
+
const voucherPayments = preparePayments.flatMap(item => {
|
|
2784
2703
|
const asset = selectedAssetById.get(String(item.voucher_id));
|
|
2785
|
-
const paymentCode = WALLET_PAYMENT_CODE_BY_TAG[String(item.tag ||
|
|
2704
|
+
const paymentCode = WALLET_PAYMENT_CODE_BY_TAG[String(item.tag || asset?.tag || '')] || String(item.tag || asset?.tag || '').toUpperCase();
|
|
2786
2705
|
const paymentMethod = methodByCode.get(paymentCode);
|
|
2787
2706
|
const formattedAmount = Number(item.amount);
|
|
2788
2707
|
const amount = Number.isFinite(formattedAmount) && formattedAmount > 0 ? formattedAmount : getSharedWalletAssetAmount(asset);
|
|
@@ -2794,105 +2713,105 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2794
2713
|
amount,
|
|
2795
2714
|
paymentMethod
|
|
2796
2715
|
});
|
|
2797
|
-
return [
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
}
|
|
2813
|
-
];
|
|
2716
|
+
return [{
|
|
2717
|
+
amount: amount.toFixed(2),
|
|
2718
|
+
code: paymentMethod.code,
|
|
2719
|
+
custom_payment_id: paymentMethod.id,
|
|
2720
|
+
name: paymentMethod.name,
|
|
2721
|
+
type: paymentMethod.type,
|
|
2722
|
+
voucher_id: item.voucher_id,
|
|
2723
|
+
wallet_pass_usage_unit: item.wallet_pass_usage_unit,
|
|
2724
|
+
wallet_pass_use_value: walletPassUseValue,
|
|
2725
|
+
fund_record: buildSharedWalletFundRecord({
|
|
2726
|
+
asset,
|
|
2727
|
+
amount,
|
|
2728
|
+
paymentMethod
|
|
2729
|
+
})
|
|
2730
|
+
}];
|
|
2814
2731
|
});
|
|
2815
2732
|
const payments = this.updateVoucherOrderPayments(voucherPayments, {
|
|
2816
|
-
status:
|
|
2733
|
+
status: 'payment_pending'
|
|
2734
|
+
});
|
|
2735
|
+
await this.store.order.recalculateSummary({
|
|
2736
|
+
createIfMissing: true
|
|
2817
2737
|
});
|
|
2818
|
-
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
2819
2738
|
return payments;
|
|
2820
2739
|
}
|
|
2740
|
+
|
|
2821
2741
|
/** 读取购物车与 Shared Checkout 共用的钱包资产状态。 */
|
|
2822
2742
|
getWalletAssetsState() {
|
|
2823
|
-
if (!this.store.payment)
|
|
2824
|
-
throw new Error("payment 模块未初始化");
|
|
2743
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2825
2744
|
return this.store.payment.wallet.getWalletAssetsState();
|
|
2826
2745
|
}
|
|
2746
|
+
|
|
2827
2747
|
/** 导出 Shared Checkout 跨运行时恢复所需的钱包状态与搜索缓存。 */
|
|
2828
2748
|
exportWalletAssetsSnapshot() {
|
|
2829
|
-
if (!this.store.payment)
|
|
2830
|
-
throw new Error("payment 模块未初始化");
|
|
2749
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2831
2750
|
return this.store.payment.wallet.exportWalletAssetsSnapshot();
|
|
2832
2751
|
}
|
|
2752
|
+
|
|
2833
2753
|
/** 配置仅影响 Wallet Assets,不改变 Promotion/Voucher 选择流程。 */
|
|
2834
2754
|
configureWalletAssetsBehavior(options) {
|
|
2835
|
-
if (!this.store.payment)
|
|
2836
|
-
throw new Error("payment 模块未初始化");
|
|
2755
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2837
2756
|
this.store.payment.wallet.configureWalletAssetsBehavior(options);
|
|
2838
2757
|
}
|
|
2758
|
+
|
|
2839
2759
|
/**
|
|
2840
2760
|
* 恢复 Shared Checkout 钱包快照,并把选择重新同步为订单 pending payment。
|
|
2841
2761
|
*/
|
|
2842
2762
|
async importWalletAssetsSnapshot(snapshot) {
|
|
2843
|
-
if (!this.store.payment)
|
|
2844
|
-
throw new Error("payment 模块未初始化");
|
|
2763
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2845
2764
|
const state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
|
|
2846
2765
|
await this.syncSelectedWalletAssets(state);
|
|
2847
2766
|
return this.publishWalletAssetsState(state);
|
|
2848
2767
|
}
|
|
2768
|
+
|
|
2849
2769
|
/**
|
|
2850
2770
|
* 基于当前订单快照刷新钱包资产。商品变化保留并重验选择;客户变化强制清空。
|
|
2851
2771
|
*/
|
|
2852
2772
|
async refreshWalletAssets(params) {
|
|
2853
|
-
if (!this.store.order)
|
|
2854
|
-
|
|
2855
|
-
if (!this.store.payment)
|
|
2856
|
-
throw new Error("payment 模块未初始化");
|
|
2773
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2774
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2857
2775
|
const refreshSequence = ++this.walletAssetsRefreshSequence;
|
|
2858
2776
|
const wallet = this.store.payment.wallet;
|
|
2859
2777
|
const businessData = this.buildWalletInitBusinessData(params);
|
|
2860
2778
|
if (!businessData) {
|
|
2861
2779
|
wallet.clearAllCache();
|
|
2862
2780
|
const emptyState = wallet.getWalletAssetsState();
|
|
2863
|
-
this.updateVoucherOrderPayments([], {
|
|
2781
|
+
this.updateVoucherOrderPayments([], {
|
|
2782
|
+
status: 'payment_pending'
|
|
2783
|
+
});
|
|
2864
2784
|
return this.publishWalletAssetsState(emptyState);
|
|
2865
2785
|
}
|
|
2866
2786
|
const previousState = wallet.getWalletAssetsState();
|
|
2867
|
-
const hasPreviousWalletContext = previousState.status !==
|
|
2868
|
-
const customerChanged = hasPreviousWalletContext && String(previousState.customerId ??
|
|
2787
|
+
const hasPreviousWalletContext = previousState.status !== 'idle' || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== undefined;
|
|
2788
|
+
const customerChanged = hasPreviousWalletContext && String(previousState.customerId ?? '') !== String(businessData.customer_id ?? '');
|
|
2869
2789
|
if (customerChanged) {
|
|
2870
2790
|
const clearedState = wallet.clearWalletAssetSelection();
|
|
2871
|
-
this.updateVoucherOrderPayments([], {
|
|
2791
|
+
this.updateVoucherOrderPayments([], {
|
|
2792
|
+
status: 'payment_pending'
|
|
2793
|
+
});
|
|
2872
2794
|
await this.publishWalletAssetsState(clearedState);
|
|
2873
2795
|
}
|
|
2874
|
-
const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
preserveSelection: (params == null ? void 0 : params.preserveSelection) !== false && !customerChanged
|
|
2878
|
-
}
|
|
2879
|
-
);
|
|
2796
|
+
const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
|
|
2797
|
+
preserveSelection: params?.preserveSelection !== false && !customerChanged
|
|
2798
|
+
});
|
|
2880
2799
|
await this.publishWalletAssetsState(wallet.getWalletAssetsState());
|
|
2881
2800
|
let state = await refreshTask;
|
|
2882
2801
|
if (refreshSequence !== this.walletAssetsRefreshSequence) {
|
|
2883
2802
|
return wallet.getWalletAssetsState();
|
|
2884
2803
|
}
|
|
2885
|
-
if (state.status !==
|
|
2804
|
+
if (state.status !== 'error') {
|
|
2886
2805
|
const committed = this.getCommittedWalletAssets();
|
|
2887
2806
|
state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
2888
2807
|
}
|
|
2889
2808
|
await this.syncSelectedWalletAssets(state);
|
|
2890
2809
|
return this.publishWalletAssetsState(state);
|
|
2891
2810
|
}
|
|
2811
|
+
|
|
2892
2812
|
/** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */
|
|
2893
2813
|
async selectWalletAsset(params) {
|
|
2894
|
-
if (!this.store.payment)
|
|
2895
|
-
throw new Error("payment 模块未初始化");
|
|
2814
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2896
2815
|
const state = this.store.payment.wallet.selectWalletAsset(params.assetId, {
|
|
2897
2816
|
selected: params.selected,
|
|
2898
2817
|
source: params.source
|
|
@@ -2900,41 +2819,40 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2900
2819
|
await this.syncSelectedWalletAssets(state);
|
|
2901
2820
|
return this.publishWalletAssetsState(state);
|
|
2902
2821
|
}
|
|
2822
|
+
|
|
2903
2823
|
/** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
|
|
2904
2824
|
async updateWalletAssetAmount(params) {
|
|
2905
|
-
if (!this.store.payment)
|
|
2906
|
-
|
|
2907
|
-
const state = this.store.payment.wallet.updateWalletAssetAmount(
|
|
2908
|
-
params.assetId,
|
|
2909
|
-
params.amount
|
|
2910
|
-
);
|
|
2825
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2826
|
+
const state = this.store.payment.wallet.updateWalletAssetAmount(params.assetId, params.amount);
|
|
2911
2827
|
await this.syncSelectedWalletAssets(state);
|
|
2912
2828
|
return this.publishWalletAssetsState(state);
|
|
2913
2829
|
}
|
|
2830
|
+
|
|
2914
2831
|
/** 扫码精确查券;仅可用资产会被自动选中。 */
|
|
2915
2832
|
async scanWalletAsset(code) {
|
|
2916
|
-
if (!this.store.payment)
|
|
2917
|
-
throw new Error("payment 模块未初始化");
|
|
2833
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2918
2834
|
const wallet = this.store.payment.wallet;
|
|
2835
|
+
// 扫码可能早于后台 Wallet 刷新,搜索参数必须以当前订单为准。
|
|
2919
2836
|
const businessData = this.buildWalletInitBusinessData();
|
|
2920
2837
|
if (businessData) {
|
|
2921
2838
|
wallet.generateWalletParams(businessData);
|
|
2922
2839
|
}
|
|
2923
2840
|
const result = await wallet.scanWalletAssetAsync(code);
|
|
2924
|
-
if (result.type ===
|
|
2841
|
+
if (result.type === 'normalCode') {
|
|
2925
2842
|
await this.syncSelectedWalletAssets(result.state);
|
|
2926
2843
|
await this.publishWalletAssetsState(result.state);
|
|
2927
2844
|
}
|
|
2928
2845
|
return result;
|
|
2929
2846
|
}
|
|
2847
|
+
|
|
2930
2848
|
/** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */
|
|
2931
2849
|
async clearWalletAssetSelection() {
|
|
2932
|
-
if (!this.store.payment)
|
|
2933
|
-
throw new Error("payment 模块未初始化");
|
|
2850
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2934
2851
|
const state = this.store.payment.wallet.clearWalletAssetSelection();
|
|
2935
2852
|
await this.syncSelectedWalletAssets(state);
|
|
2936
2853
|
return this.publishWalletAssetsState(state);
|
|
2937
2854
|
}
|
|
2855
|
+
|
|
2938
2856
|
/**
|
|
2939
2857
|
* 更新当前订单客户字段。
|
|
2940
2858
|
*
|
|
@@ -2942,46 +2860,50 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2942
2860
|
* 调用方通过 onCustomerChange 回调完成。
|
|
2943
2861
|
*/
|
|
2944
2862
|
updateOrderCustomer(customer) {
|
|
2945
|
-
if (!this.store.order)
|
|
2946
|
-
throw new Error("order 模块未初始化");
|
|
2863
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2947
2864
|
const result = this.store.order.updateTempOrderCustomer(customer);
|
|
2948
|
-
this.store.order.recalculateSummary({
|
|
2865
|
+
this.store.order.recalculateSummary({
|
|
2866
|
+
createIfMissing: true
|
|
2867
|
+
});
|
|
2949
2868
|
this.store.order.persistTempOrder();
|
|
2950
2869
|
return result;
|
|
2951
2870
|
}
|
|
2871
|
+
|
|
2952
2872
|
/** 获取可用支付方式列表,供 PaymentModal 渲染支付选项。 */
|
|
2953
2873
|
async getPaymentMethodsAsync() {
|
|
2874
|
+
// if (this.store.payment) {
|
|
2875
|
+
// return this.store.payment.getPayMethodListAsync();
|
|
2876
|
+
// }
|
|
2954
2877
|
try {
|
|
2955
|
-
const response = await this.request.get(
|
|
2878
|
+
const response = await this.request.get('/pay/custom-payment/all', {
|
|
2956
2879
|
filterPaymentMethods: true
|
|
2957
2880
|
}, {
|
|
2958
2881
|
osServer: true
|
|
2959
2882
|
});
|
|
2960
|
-
const paymentMethods =
|
|
2883
|
+
const paymentMethods = response?.data || [];
|
|
2961
2884
|
this.paymentMethodsCache = Array.isArray(paymentMethods) ? [...paymentMethods] : [];
|
|
2962
2885
|
return this.getPaymentMethods();
|
|
2963
2886
|
} catch (error) {
|
|
2964
|
-
this.logWarning(
|
|
2887
|
+
this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
|
|
2965
2888
|
error: error instanceof Error ? error.message : String(error)
|
|
2966
2889
|
});
|
|
2967
2890
|
return this.getPaymentMethods();
|
|
2968
2891
|
}
|
|
2969
2892
|
}
|
|
2893
|
+
|
|
2970
2894
|
/** 同步读取初始化时缓存的支付方式列表。 */
|
|
2971
2895
|
getPaymentMethods() {
|
|
2972
2896
|
return [...this.paymentMethodsCache];
|
|
2973
2897
|
}
|
|
2974
2898
|
findCashPaymentMethod(paymentMethods) {
|
|
2975
|
-
return paymentMethods.find(
|
|
2976
|
-
const identifiers = [method
|
|
2977
|
-
|
|
2978
|
-
);
|
|
2979
|
-
return identifiers.includes("CASHMANUAL") && (method == null ? void 0 : method.enabled) !== false && (method == null ? void 0 : method.enable) !== false;
|
|
2899
|
+
return paymentMethods.find(method => {
|
|
2900
|
+
const identifiers = [method?.code, method?.type, method?.tag].map(value => String(value || '').toUpperCase());
|
|
2901
|
+
return identifiers.includes('CASHMANUAL') && method?.enabled !== false && method?.enable !== false;
|
|
2980
2902
|
});
|
|
2981
2903
|
}
|
|
2982
|
-
getPendingWalletPaymentAmount(payments =
|
|
2904
|
+
getPendingWalletPaymentAmount(payments = this.store.order?.getOrderPayments?.() || []) {
|
|
2983
2905
|
return payments.reduce((total, payment) => {
|
|
2984
|
-
if (
|
|
2906
|
+
if (payment?.status !== 'payment_pending' || payment?.voucher_id === undefined || Number(payment.voucher_id) === 0) {
|
|
2985
2907
|
return total;
|
|
2986
2908
|
}
|
|
2987
2909
|
try {
|
|
@@ -2989,26 +2911,22 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2989
2911
|
} catch {
|
|
2990
2912
|
return total;
|
|
2991
2913
|
}
|
|
2992
|
-
}, new
|
|
2914
|
+
}, new _decimal.default(0));
|
|
2993
2915
|
}
|
|
2916
|
+
|
|
2994
2917
|
/** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
|
|
2995
2918
|
async getCashPaymentConfig() {
|
|
2996
|
-
|
|
2997
|
-
if (!this.store.payment)
|
|
2998
|
-
throw new Error("payment 模块未初始化");
|
|
2919
|
+
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
2999
2920
|
let paymentMethods = this.getPaymentMethods();
|
|
3000
2921
|
let paymentMethod = this.findCashPaymentMethod(paymentMethods);
|
|
3001
2922
|
if (!paymentMethod) {
|
|
3002
2923
|
paymentMethods = await this.getPaymentMethodsAsync();
|
|
3003
2924
|
paymentMethod = this.findCashPaymentMethod(paymentMethods);
|
|
3004
2925
|
}
|
|
3005
|
-
const amountSnapshot =
|
|
2926
|
+
const amountSnapshot = this.store.order?.getOrderAmountSnapshot?.();
|
|
3006
2927
|
const pendingWalletAmount = this.getPendingWalletPaymentAmount();
|
|
3007
|
-
const amountDue =
|
|
3008
|
-
|
|
3009
|
-
0
|
|
3010
|
-
).toDecimalPlaces(2).toNumber();
|
|
3011
|
-
const currency = ((_e = (_d = (_c = this.store.order) == null ? void 0 : _c.getTempOrder) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.currency_code) || ((_f = this.otherParams) == null ? void 0 : _f.currency) || "USD";
|
|
2928
|
+
const amountDue = _decimal.default.max(new _decimal.default(amountSnapshot?.amountGap || 0).minus(pendingWalletAmount), 0).toDecimalPlaces(2).toNumber();
|
|
2929
|
+
const currency = this.store.order?.getTempOrder?.()?.currency_code || this.otherParams?.currency || 'USD';
|
|
3012
2930
|
const recommendedAmounts = amountDue > 0 ? this.store.payment.cash.getRecommendedAmount(amountDue, currency) : [];
|
|
3013
2931
|
return {
|
|
3014
2932
|
available: Boolean(paymentMethod && amountDue > 0),
|
|
@@ -3017,6 +2935,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3017
2935
|
recommendedAmounts
|
|
3018
2936
|
};
|
|
3019
2937
|
}
|
|
2938
|
+
|
|
3020
2939
|
/**
|
|
3021
2940
|
* 确认足额覆盖订单的 pending Wallet 支付并提交订单。
|
|
3022
2941
|
*
|
|
@@ -3024,23 +2943,18 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3024
2943
|
* 才同步 Wallet committed 状态。失败时恢复调用前 payments,允许用户重试。
|
|
3025
2944
|
*/
|
|
3026
2945
|
async confirmWalletPayment() {
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
throw new Error("order 模块未初始化");
|
|
3030
|
-
const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
|
|
2946
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2947
|
+
const beforePayments = (0, _lodashEs.cloneDeep)(this.store.order.getOrderPayments());
|
|
3031
2948
|
const pendingWalletAmount = this.getPendingWalletPaymentAmount(beforePayments);
|
|
3032
2949
|
if (pendingWalletAmount.lte(0)) {
|
|
3033
|
-
throw new Error(
|
|
2950
|
+
throw new Error('当前订单没有待确认的 Wallet 支付');
|
|
3034
2951
|
}
|
|
3035
|
-
const amountSnapshot =
|
|
3036
|
-
const effectiveAmountDue =
|
|
3037
|
-
new import_decimal.default((amountSnapshot == null ? void 0 : amountSnapshot.amountGap) || 0).minus(pendingWalletAmount),
|
|
3038
|
-
0
|
|
3039
|
-
);
|
|
2952
|
+
const amountSnapshot = this.store.order.getOrderAmountSnapshot?.();
|
|
2953
|
+
const effectiveAmountDue = _decimal.default.max(new _decimal.default(amountSnapshot?.amountGap || 0).minus(pendingWalletAmount), 0);
|
|
3040
2954
|
if (effectiveAmountDue.gt(0.01)) {
|
|
3041
|
-
throw new Error(
|
|
2955
|
+
throw new Error('Wallet 支付尚未覆盖全部待支付金额');
|
|
3042
2956
|
}
|
|
3043
|
-
const beforePaymentStatus =
|
|
2957
|
+
const beforePaymentStatus = this.store.order.getTempOrder()?.payment_status;
|
|
3044
2958
|
let submitResult;
|
|
3045
2959
|
try {
|
|
3046
2960
|
submitResult = await this.submitSalesOrder({
|
|
@@ -3048,80 +2962,74 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3048
2962
|
confirmPendingVoucherPayments: true
|
|
3049
2963
|
});
|
|
3050
2964
|
if (isRejectedSalesSubmitResult(submitResult)) {
|
|
3051
|
-
throw new Error(
|
|
3052
|
-
getSalesSubmitErrorMessage(submitResult, "Wallet 支付确认失败")
|
|
3053
|
-
);
|
|
2965
|
+
throw new Error(getSalesSubmitErrorMessage(submitResult, 'Wallet 支付确认失败'));
|
|
3054
2966
|
}
|
|
3055
2967
|
} catch (error) {
|
|
3056
2968
|
this.store.order.setOrderPayments(beforePayments);
|
|
3057
2969
|
const restoredTempOrder = this.store.order.getTempOrder();
|
|
3058
|
-
if (restoredTempOrder && beforePaymentStatus !==
|
|
2970
|
+
if (restoredTempOrder && beforePaymentStatus !== undefined) {
|
|
3059
2971
|
restoredTempOrder.payment_status = beforePaymentStatus;
|
|
3060
2972
|
this.store.order.persistTempOrder();
|
|
3061
2973
|
}
|
|
3062
|
-
await this.store.order.recalculateSummary({
|
|
2974
|
+
await this.store.order.recalculateSummary({
|
|
2975
|
+
createIfMissing: true
|
|
2976
|
+
});
|
|
3063
2977
|
throw error;
|
|
3064
2978
|
}
|
|
3065
2979
|
if (this.store.payment) {
|
|
3066
2980
|
try {
|
|
3067
2981
|
const committed = this.getCommittedWalletAssets();
|
|
3068
|
-
const walletState = this.store.payment.wallet.setCommittedWalletAssets(
|
|
3069
|
-
committed.ids,
|
|
3070
|
-
committed.assets
|
|
3071
|
-
);
|
|
2982
|
+
const walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
3072
2983
|
await this.publishWalletAssetsState(walletState);
|
|
3073
2984
|
} catch (error) {
|
|
3074
|
-
this.logWarning(
|
|
2985
|
+
this.logWarning('confirmWalletPayment: Wallet committed 状态同步失败', {
|
|
3075
2986
|
error: error instanceof Error ? error.message : String(error)
|
|
3076
2987
|
});
|
|
3077
2988
|
}
|
|
3078
2989
|
}
|
|
3079
|
-
const latestAmountSnapshot =
|
|
2990
|
+
const latestAmountSnapshot = this.store.order.getOrderAmountSnapshot?.();
|
|
3080
2991
|
return {
|
|
3081
2992
|
submitResult,
|
|
3082
2993
|
payments: this.store.order.getOrderPayments(),
|
|
3083
|
-
isOrderFullyPaid: new
|
|
3084
|
-
(latestAmountSnapshot == null ? void 0 : latestAmountSnapshot.amountGap) || 0
|
|
3085
|
-
).lte(0)
|
|
2994
|
+
isOrderFullyPaid: new _decimal.default(latestAmountSnapshot?.amountGap || 0).lte(0)
|
|
3086
2995
|
};
|
|
3087
2996
|
}
|
|
2997
|
+
|
|
3088
2998
|
/**
|
|
3089
2999
|
* 购物车现金直付:写入现金记录并等待支付同步完成。
|
|
3090
3000
|
* 同步失败会恢复调用前 payments(包含 Wallet pending 状态)。
|
|
3091
3001
|
*/
|
|
3092
3002
|
async payCash(params) {
|
|
3093
|
-
|
|
3094
|
-
if (!this.store.order)
|
|
3095
|
-
throw new Error("order 模块未初始化");
|
|
3003
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3096
3004
|
const amount = Number(params.amount || 0);
|
|
3097
3005
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
3098
|
-
throw new Error(
|
|
3006
|
+
throw new Error('现金支付金额必须大于 0');
|
|
3099
3007
|
}
|
|
3100
3008
|
const config = await this.getCashPaymentConfig();
|
|
3101
3009
|
const paymentMethod = config.paymentMethod;
|
|
3102
|
-
if (!paymentMethod)
|
|
3103
|
-
|
|
3104
|
-
if (config.amountDue <= 0)
|
|
3105
|
-
throw new Error("当前订单没有待支付金额");
|
|
3010
|
+
if (!paymentMethod) throw new Error('未找到可用的 CASHMANUAL 支付方式');
|
|
3011
|
+
if (config.amountDue <= 0) throw new Error('当前订单没有待支付金额');
|
|
3106
3012
|
const roundingAmount = Number(params.roundingAmount || 0);
|
|
3107
|
-
const effectivePaymentAmount = new
|
|
3108
|
-
if (effectivePaymentAmount.gt(new
|
|
3109
|
-
throw new Error(
|
|
3110
|
-
}
|
|
3111
|
-
const beforePayments = (0,
|
|
3112
|
-
const beforePaymentStatus =
|
|
3113
|
-
const uniquePaymentNumber = (0,
|
|
3114
|
-
const paymentTimestamp = (0,
|
|
3013
|
+
const effectivePaymentAmount = new _decimal.default(amount).minus(roundingAmount);
|
|
3014
|
+
if (effectivePaymentAmount.gt(new _decimal.default(config.amountDue).plus(0.01))) {
|
|
3015
|
+
throw new Error('现金支付金额超过当前待支付金额');
|
|
3016
|
+
}
|
|
3017
|
+
const beforePayments = (0, _lodashEs.cloneDeep)(this.store.order.getOrderPayments());
|
|
3018
|
+
const beforePaymentStatus = this.store.order.getTempOrder()?.payment_status;
|
|
3019
|
+
const uniquePaymentNumber = (0, _utils.createUuidV4)();
|
|
3020
|
+
const paymentTimestamp = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
3115
3021
|
const actualPaidAmount = Number(params.actualPaidAmount ?? amount);
|
|
3116
3022
|
const changeAmount = Number(params.changeAmount || 0);
|
|
3117
|
-
const shopWalletPassId =
|
|
3023
|
+
const shopWalletPassId = this.otherParams?.shop_wallet_pass_id;
|
|
3118
3024
|
if (!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount) {
|
|
3119
|
-
throw new Error(
|
|
3025
|
+
throw new Error('顾客实收现金不能小于支付金额');
|
|
3120
3026
|
}
|
|
3121
|
-
|
|
3122
|
-
module:
|
|
3123
|
-
key:
|
|
3124
|
-
data: {
|
|
3027
|
+
this.window?.interaction?.utils?.postMessageToApp?.({
|
|
3028
|
+
module: 'till',
|
|
3029
|
+
key: 'open_till',
|
|
3030
|
+
data: {
|
|
3031
|
+
type: 'cash'
|
|
3032
|
+
}
|
|
3125
3033
|
});
|
|
3126
3034
|
const payments = this.store.order.addOrderPayment({
|
|
3127
3035
|
amount: amount.toFixed(2),
|
|
@@ -3133,19 +3041,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3133
3041
|
rounding_amount: roundingAmount.toFixed(2),
|
|
3134
3042
|
metadata: {
|
|
3135
3043
|
unique_payment_number: uniquePaymentNumber,
|
|
3136
|
-
...shopWalletPassId !==
|
|
3044
|
+
...(shopWalletPassId !== undefined && shopWalletPassId !== null ? {
|
|
3045
|
+
shop_wallet_pass_id: shopWalletPassId
|
|
3046
|
+
} : {}),
|
|
3137
3047
|
actual_paid_amount: Number.isFinite(actualPaidAmount) ? actualPaidAmount : amount,
|
|
3138
3048
|
change_given_amount: Number.isFinite(changeAmount) ? changeAmount : 0
|
|
3139
3049
|
},
|
|
3140
3050
|
payment_time: paymentTimestamp,
|
|
3141
3051
|
created_at: paymentTimestamp
|
|
3142
3052
|
});
|
|
3143
|
-
const payment = payments.find(
|
|
3144
|
-
(item) => {
|
|
3145
|
-
var _a2;
|
|
3146
|
-
return ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.unique_payment_number) === uniquePaymentNumber;
|
|
3147
|
-
}
|
|
3148
|
-
);
|
|
3053
|
+
const payment = payments.find(item => item?.metadata?.unique_payment_number === uniquePaymentNumber);
|
|
3149
3054
|
try {
|
|
3150
3055
|
const syncResult = await this.syncPaymentsToOrder({
|
|
3151
3056
|
payments,
|
|
@@ -3154,35 +3059,33 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3154
3059
|
confirmPendingVoucherPayments: true
|
|
3155
3060
|
});
|
|
3156
3061
|
if (isRejectedSalesSubmitResult(syncResult.submitResult)) {
|
|
3157
|
-
throw new Error(
|
|
3158
|
-
getSalesSubmitErrorMessage(syncResult.submitResult, "订单提交失败")
|
|
3159
|
-
);
|
|
3062
|
+
throw new Error(getSalesSubmitErrorMessage(syncResult.submitResult, '订单提交失败'));
|
|
3160
3063
|
}
|
|
3161
3064
|
if (this.store.payment) {
|
|
3162
3065
|
const committed = this.getCommittedWalletAssets();
|
|
3163
|
-
const walletState = this.store.payment.wallet.setCommittedWalletAssets(
|
|
3164
|
-
committed.ids,
|
|
3165
|
-
committed.assets
|
|
3166
|
-
);
|
|
3066
|
+
const walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
3167
3067
|
await this.publishWalletAssetsState(walletState);
|
|
3168
3068
|
}
|
|
3169
3069
|
return {
|
|
3170
3070
|
payment: payment || {},
|
|
3171
3071
|
payments: this.store.order.getOrderPayments(),
|
|
3172
|
-
syncResult,
|
|
3072
|
+
syncResult: syncResult,
|
|
3173
3073
|
isOrderFullyPaid: syncResult.isOrderFullyPaid
|
|
3174
3074
|
};
|
|
3175
3075
|
} catch (error) {
|
|
3176
3076
|
this.store.order.setOrderPayments(beforePayments);
|
|
3177
3077
|
const restoredTempOrder = this.store.order.getTempOrder();
|
|
3178
|
-
if (restoredTempOrder && beforePaymentStatus !==
|
|
3078
|
+
if (restoredTempOrder && beforePaymentStatus !== undefined) {
|
|
3179
3079
|
restoredTempOrder.payment_status = beforePaymentStatus;
|
|
3180
3080
|
this.store.order.persistTempOrder();
|
|
3181
3081
|
}
|
|
3182
|
-
await this.store.order.recalculateSummary({
|
|
3082
|
+
await this.store.order.recalculateSummary({
|
|
3083
|
+
createIfMissing: true
|
|
3084
|
+
});
|
|
3183
3085
|
throw error;
|
|
3184
3086
|
}
|
|
3185
3087
|
}
|
|
3088
|
+
|
|
3186
3089
|
/**
|
|
3187
3090
|
* 提交一次已由支付设备确认成功的非 Wallet 支付。
|
|
3188
3091
|
*
|
|
@@ -3191,19 +3094,17 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3191
3094
|
* 调用前的 payments 与 payment_status,便于 UI 安全解锁并重试。
|
|
3192
3095
|
*/
|
|
3193
3096
|
async commitPaymentMethodPayment(params) {
|
|
3194
|
-
|
|
3195
|
-
if (!this.store.order)
|
|
3196
|
-
throw new Error("order 模块未初始化");
|
|
3097
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3197
3098
|
const amount = Number(params.amount || 0);
|
|
3198
3099
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
3199
|
-
throw new Error(
|
|
3100
|
+
throw new Error('支付金额必须大于 0');
|
|
3200
3101
|
}
|
|
3201
3102
|
let paymentMethods = this.getPaymentMethods();
|
|
3202
3103
|
const findPaymentMethod = () => {
|
|
3203
|
-
const methodCode = String(params.paymentMethodCode ||
|
|
3204
|
-
return paymentMethods.find(
|
|
3205
|
-
const idMatched = params.paymentMethodId !==
|
|
3206
|
-
const codeMatched = Boolean(methodCode) && String(method.code ||
|
|
3104
|
+
const methodCode = String(params.paymentMethodCode || '').toUpperCase();
|
|
3105
|
+
return paymentMethods.find(method => {
|
|
3106
|
+
const idMatched = params.paymentMethodId !== undefined && String(method.id) === String(params.paymentMethodId);
|
|
3107
|
+
const codeMatched = Boolean(methodCode) && String(method.code || '').toUpperCase() === methodCode;
|
|
3207
3108
|
return (idMatched || codeMatched) && method.enabled !== false && method.enable !== false;
|
|
3208
3109
|
});
|
|
3209
3110
|
};
|
|
@@ -3213,54 +3114,49 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3213
3114
|
paymentMethod = findPaymentMethod();
|
|
3214
3115
|
}
|
|
3215
3116
|
if (!paymentMethod) {
|
|
3216
|
-
throw new Error(
|
|
3217
|
-
`未找到可用的支付方式:${params.paymentMethodCode || params.paymentMethodId || ""}`
|
|
3218
|
-
);
|
|
3117
|
+
throw new Error(`未找到可用的支付方式:${params.paymentMethodCode || params.paymentMethodId || ''}`);
|
|
3219
3118
|
}
|
|
3220
|
-
const amountSnapshot =
|
|
3119
|
+
const amountSnapshot = this.store.order.getOrderAmountSnapshot?.();
|
|
3221
3120
|
const pendingWalletAmount = this.getPendingWalletPaymentAmount();
|
|
3222
|
-
const amountDue =
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
}
|
|
3231
|
-
const beforePayments = (0, import_lodash_es.cloneDeep)(this.store.order.getOrderPayments());
|
|
3232
|
-
const beforePaymentStatus = (_c = this.store.order.getTempOrder()) == null ? void 0 : _c.payment_status;
|
|
3233
|
-
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
3121
|
+
const amountDue = _decimal.default.max(new _decimal.default(amountSnapshot?.amountGap || 0).minus(pendingWalletAmount), 0);
|
|
3122
|
+
if (amountDue.lte(0)) throw new Error('当前订单没有待支付金额');
|
|
3123
|
+
if (new _decimal.default(amount).gt(amountDue.plus(0.01))) {
|
|
3124
|
+
throw new Error('支付金额超过当前待支付金额');
|
|
3125
|
+
}
|
|
3126
|
+
const beforePayments = (0, _lodashEs.cloneDeep)(this.store.order.getOrderPayments());
|
|
3127
|
+
const beforePaymentStatus = this.store.order.getTempOrder()?.payment_status;
|
|
3128
|
+
const paymentTimestamp = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
3234
3129
|
const metadata = {
|
|
3235
|
-
...params.metadata || {},
|
|
3236
|
-
unique_payment_number:
|
|
3130
|
+
...(params.metadata || {}),
|
|
3131
|
+
unique_payment_number: params.metadata?.unique_payment_number || (0, _utils.createUuidV4)()
|
|
3237
3132
|
};
|
|
3238
3133
|
const serviceCharge = params.serviceCharge ? {
|
|
3239
3134
|
amount: String(params.serviceCharge.amount || 0),
|
|
3240
3135
|
percentage: String(params.serviceCharge.percentage || 0)
|
|
3241
|
-
} :
|
|
3242
|
-
const serviceFee = serviceCharge ? new
|
|
3136
|
+
} : undefined;
|
|
3137
|
+
const serviceFee = serviceCharge ? new _decimal.default(params.originAmount ?? amount).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
|
|
3243
3138
|
const payments = this.store.order.addOrderPayment({
|
|
3244
|
-
...params.paymentData || {},
|
|
3139
|
+
...(params.paymentData || {}),
|
|
3245
3140
|
amount: amount.toFixed(2),
|
|
3246
|
-
...params.originAmount !==
|
|
3141
|
+
...(params.originAmount !== undefined ? {
|
|
3142
|
+
origin_amount: Number(params.originAmount).toFixed(2)
|
|
3143
|
+
} : {}),
|
|
3247
3144
|
code: paymentMethod.code,
|
|
3248
3145
|
custom_payment_id: paymentMethod.id,
|
|
3249
3146
|
name: paymentMethod.name,
|
|
3250
3147
|
custom_payment_type: paymentMethod.type,
|
|
3251
3148
|
voucher_id: 0,
|
|
3252
|
-
...serviceCharge ? {
|
|
3253
|
-
|
|
3149
|
+
...(serviceCharge ? {
|
|
3150
|
+
service_charge: serviceCharge
|
|
3151
|
+
} : {}),
|
|
3152
|
+
...(serviceFee !== undefined ? {
|
|
3153
|
+
service_fee: serviceFee
|
|
3154
|
+
} : {}),
|
|
3254
3155
|
metadata,
|
|
3255
3156
|
payment_time: paymentTimestamp,
|
|
3256
3157
|
created_at: paymentTimestamp
|
|
3257
3158
|
});
|
|
3258
|
-
const payment = payments.find(
|
|
3259
|
-
(item) => {
|
|
3260
|
-
var _a2;
|
|
3261
|
-
return ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.unique_payment_number) === metadata.unique_payment_number;
|
|
3262
|
-
}
|
|
3263
|
-
);
|
|
3159
|
+
const payment = payments.find(item => item?.metadata?.unique_payment_number === metadata.unique_payment_number);
|
|
3264
3160
|
try {
|
|
3265
3161
|
const syncResult = await this.syncPaymentsToOrder({
|
|
3266
3162
|
payments,
|
|
@@ -3269,35 +3165,33 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3269
3165
|
confirmPendingVoucherPayments: true
|
|
3270
3166
|
});
|
|
3271
3167
|
if (isRejectedSalesSubmitResult(syncResult.submitResult)) {
|
|
3272
|
-
throw new Error(
|
|
3273
|
-
getSalesSubmitErrorMessage(syncResult.submitResult, "订单提交失败")
|
|
3274
|
-
);
|
|
3168
|
+
throw new Error(getSalesSubmitErrorMessage(syncResult.submitResult, '订单提交失败'));
|
|
3275
3169
|
}
|
|
3276
3170
|
if (this.store.payment) {
|
|
3277
3171
|
const committed = this.getCommittedWalletAssets();
|
|
3278
|
-
const walletState = this.store.payment.wallet.setCommittedWalletAssets(
|
|
3279
|
-
committed.ids,
|
|
3280
|
-
committed.assets
|
|
3281
|
-
);
|
|
3172
|
+
const walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
3282
3173
|
await this.publishWalletAssetsState(walletState);
|
|
3283
3174
|
}
|
|
3284
3175
|
return {
|
|
3285
3176
|
payment: payment || {},
|
|
3286
3177
|
payments: this.store.order.getOrderPayments(),
|
|
3287
|
-
syncResult,
|
|
3178
|
+
syncResult: syncResult,
|
|
3288
3179
|
isOrderFullyPaid: syncResult.isOrderFullyPaid
|
|
3289
3180
|
};
|
|
3290
3181
|
} catch (error) {
|
|
3291
3182
|
this.store.order.setOrderPayments(beforePayments);
|
|
3292
3183
|
const restoredTempOrder = this.store.order.getTempOrder();
|
|
3293
|
-
if (restoredTempOrder && beforePaymentStatus !==
|
|
3184
|
+
if (restoredTempOrder && beforePaymentStatus !== undefined) {
|
|
3294
3185
|
restoredTempOrder.payment_status = beforePaymentStatus;
|
|
3295
3186
|
this.store.order.persistTempOrder();
|
|
3296
3187
|
}
|
|
3297
|
-
await this.store.order.recalculateSummary({
|
|
3188
|
+
await this.store.order.recalculateSummary({
|
|
3189
|
+
createIfMissing: true
|
|
3190
|
+
});
|
|
3298
3191
|
throw error;
|
|
3299
3192
|
}
|
|
3300
3193
|
}
|
|
3194
|
+
|
|
3301
3195
|
/**
|
|
3302
3196
|
* 按当前店铺的现金舍入配置计算金额,供现金支付 UI 使用。
|
|
3303
3197
|
*
|
|
@@ -3305,27 +3199,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3305
3199
|
* otherParams.order_rounding_setting,金额算法统一由 PaymentModule 维护。
|
|
3306
3200
|
*/
|
|
3307
3201
|
async roundAmount(params) {
|
|
3308
|
-
var _a, _b, _c;
|
|
3309
3202
|
const amount = params.amount;
|
|
3310
|
-
const cashManualPayment = this.paymentMethodsCache.find(
|
|
3311
|
-
|
|
3312
|
-
);
|
|
3313
|
-
if (!((_a = cashManualPayment == null ? void 0 : cashManualPayment.metadata) == null ? void 0 : _a.order_rounding_switch)) {
|
|
3203
|
+
const cashManualPayment = this.paymentMethodsCache.find(paymentMethod => paymentMethod.code === 'CASHMANUAL');
|
|
3204
|
+
if (!cashManualPayment?.metadata?.order_rounding_switch) {
|
|
3314
3205
|
return {
|
|
3315
3206
|
originalAmount: amount.toString(),
|
|
3316
3207
|
roundedAmount: amount.toString(),
|
|
3317
|
-
roundingDifference:
|
|
3208
|
+
roundingDifference: '0.00'
|
|
3318
3209
|
};
|
|
3319
3210
|
}
|
|
3320
3211
|
if (!this.payment) {
|
|
3321
|
-
throw new Error(
|
|
3212
|
+
throw new Error('payment 模块未初始化');
|
|
3322
3213
|
}
|
|
3323
|
-
return this.payment.roundAmountAsync(
|
|
3324
|
-
amount,
|
|
3325
|
-
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.interval,
|
|
3326
|
-
(_c = this.otherParams.order_rounding_setting) == null ? void 0 : _c.type
|
|
3327
|
-
);
|
|
3214
|
+
return this.payment.roundAmountAsync(amount, this.otherParams.order_rounding_setting?.interval, this.otherParams.order_rounding_setting?.type);
|
|
3328
3215
|
}
|
|
3216
|
+
|
|
3329
3217
|
/**
|
|
3330
3218
|
* 发送支付链接。
|
|
3331
3219
|
*
|
|
@@ -3333,17 +3221,15 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3333
3221
|
* 只有成功拿到远端 order_id 后才调用 OrderModule 发送邮件。
|
|
3334
3222
|
*/
|
|
3335
3223
|
async sendCustomerPayLink(params) {
|
|
3336
|
-
|
|
3337
|
-
if (!this.store.order)
|
|
3338
|
-
throw new Error("order 模块未初始化");
|
|
3224
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3339
3225
|
let orderIds = params.order_ids || params.orderIds || [];
|
|
3340
3226
|
if (!orderIds.length || params.submitBeforeSend) {
|
|
3341
3227
|
const submitResult = await this.submitSalesOrder({
|
|
3342
3228
|
smallTicketDataFlag: 1
|
|
3343
3229
|
});
|
|
3344
|
-
const orderId =
|
|
3230
|
+
const orderId = submitResult?.data?.order_id ?? submitResult?.order_id ?? submitResult?.data?.id ?? submitResult?.id;
|
|
3345
3231
|
if (!orderId) {
|
|
3346
|
-
throw new Error(
|
|
3232
|
+
throw new Error('本地订单提交云端失败,无法发送支付链接');
|
|
3347
3233
|
}
|
|
3348
3234
|
orderIds = [orderId];
|
|
3349
3235
|
}
|
|
@@ -3354,7 +3240,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3354
3240
|
});
|
|
3355
3241
|
}
|
|
3356
3242
|
transformBaseProductToOrderProduct(params) {
|
|
3357
|
-
return (0,
|
|
3243
|
+
return (0, _transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
|
|
3358
3244
|
}
|
|
3359
3245
|
async calculateProductBookingPrice(params) {
|
|
3360
3246
|
const quotation = this.store.quotation;
|
|
@@ -3367,36 +3253,34 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3367
3253
|
customer_id: customerId,
|
|
3368
3254
|
channel: params.channel
|
|
3369
3255
|
});
|
|
3370
|
-
return (0,
|
|
3256
|
+
return (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
3371
3257
|
...params,
|
|
3372
3258
|
product,
|
|
3373
|
-
fallback_price: authoritativeProduct ?
|
|
3259
|
+
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
3374
3260
|
customer_id: customerId,
|
|
3375
|
-
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ?
|
|
3261
|
+
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
|
|
3376
3262
|
});
|
|
3377
3263
|
}
|
|
3378
3264
|
getQuotationCustomerScopeInfo() {
|
|
3379
3265
|
const quotation = this.store.quotation;
|
|
3380
|
-
if (quotation && typeof quotation.getQuotationCustomerScopeInfo ===
|
|
3266
|
+
if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
|
|
3381
3267
|
return quotation.getQuotationCustomerScopeInfo();
|
|
3382
3268
|
}
|
|
3383
|
-
const list = typeof
|
|
3384
|
-
const customerById =
|
|
3385
|
-
const quotationScopes = (Array.isArray(list) ? list : []).filter(
|
|
3386
|
-
const localSeen =
|
|
3387
|
-
const customers = item.customer.filter(
|
|
3388
|
-
const customerId = this.normalizePriceContextCustomerId(customer
|
|
3389
|
-
if (!customerId || localSeen.has(customerId))
|
|
3390
|
-
return false;
|
|
3269
|
+
const list = typeof quotation?.getQuotationList === 'function' ? quotation.getQuotationList() : [];
|
|
3270
|
+
const customerById = new Map();
|
|
3271
|
+
const quotationScopes = (Array.isArray(list) ? list : []).filter(item => Array.isArray(item?.customer) && item.customer.length > 0).map(item => {
|
|
3272
|
+
const localSeen = new Set();
|
|
3273
|
+
const customers = item.customer.filter(customer => {
|
|
3274
|
+
const customerId = this.normalizePriceContextCustomerId(customer?.id);
|
|
3275
|
+
if (!customerId || localSeen.has(customerId)) return false;
|
|
3391
3276
|
localSeen.add(customerId);
|
|
3392
|
-
if (!customerById.has(customerId))
|
|
3393
|
-
customerById.set(customerId, customer);
|
|
3277
|
+
if (!customerById.has(customerId)) customerById.set(customerId, customer);
|
|
3394
3278
|
return true;
|
|
3395
3279
|
});
|
|
3396
3280
|
return {
|
|
3397
3281
|
quotationId: item.id,
|
|
3398
3282
|
quotationName: item.name,
|
|
3399
|
-
customerIds: customers.map(
|
|
3283
|
+
customerIds: customers.map(customer => String(customer.id)),
|
|
3400
3284
|
customers
|
|
3401
3285
|
};
|
|
3402
3286
|
});
|
|
@@ -3410,9 +3294,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3410
3294
|
};
|
|
3411
3295
|
}
|
|
3412
3296
|
hasSmartPricingStrategies() {
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
if (!evaluator || typeof evaluator.getStrategyConfigs !== "function") {
|
|
3297
|
+
const evaluator = this.core?.context?.dataVariantEvaluator;
|
|
3298
|
+
if (!evaluator || typeof evaluator.getStrategyConfigs !== 'function') {
|
|
3416
3299
|
return false;
|
|
3417
3300
|
}
|
|
3418
3301
|
const configs = evaluator.getStrategyConfigs();
|
|
@@ -3420,7 +3303,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3420
3303
|
}
|
|
3421
3304
|
shouldRecalculateProductBookingPricesForContextChange(params) {
|
|
3422
3305
|
const scopeInfo = this.getQuotationCustomerScopeInfo();
|
|
3423
|
-
const scopedCustomerIds = new Set(scopeInfo.customerIds.map(
|
|
3306
|
+
const scopedCustomerIds = new Set(scopeInfo.customerIds.map(id => String(id)));
|
|
3424
3307
|
const previousCustomerId = this.normalizePriceContextCustomerId(params.previousCustomerId);
|
|
3425
3308
|
const nextCustomerId = this.normalizePriceContextCustomerId(params.nextCustomerId);
|
|
3426
3309
|
if (this.hasSmartPricingStrategies()) {
|
|
@@ -3441,78 +3324,73 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3441
3324
|
return shouldRecalculate;
|
|
3442
3325
|
}
|
|
3443
3326
|
async calculateProductBookingPrices(paramsList) {
|
|
3444
|
-
|
|
3445
|
-
if (!paramsList.length)
|
|
3446
|
-
return [];
|
|
3327
|
+
if (!paramsList.length) return [];
|
|
3447
3328
|
const quotation = this.store.quotation;
|
|
3448
|
-
const customerId =
|
|
3329
|
+
const customerId = paramsList[0]?.customer_id ?? this.getCurrentOrderCustomerId();
|
|
3449
3330
|
await this.prepareProductPriceQueryContext(customerId);
|
|
3450
|
-
const productMapsByGroup =
|
|
3451
|
-
const groups =
|
|
3452
|
-
paramsList.forEach(
|
|
3453
|
-
var _a2;
|
|
3331
|
+
const productMapsByGroup = new Map();
|
|
3332
|
+
const groups = new Map();
|
|
3333
|
+
paramsList.forEach(params => {
|
|
3454
3334
|
const product = params.product || {};
|
|
3455
3335
|
const productId = this.getPriceQueryProductId(product);
|
|
3456
|
-
if (productId === null)
|
|
3457
|
-
return;
|
|
3336
|
+
if (productId === null) return;
|
|
3458
3337
|
const schedule = this.getPriceQuerySchedule(params);
|
|
3459
|
-
const channel = params.channel ||
|
|
3460
|
-
const groupKey = [
|
|
3461
|
-
schedule.schedule_date,
|
|
3462
|
-
schedule.schedule_datetime,
|
|
3463
|
-
channel || ""
|
|
3464
|
-
].join("|");
|
|
3338
|
+
const channel = params.channel || this.otherParams?.channel;
|
|
3339
|
+
const groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
|
|
3465
3340
|
const group = groups.get(groupKey) || {
|
|
3466
|
-
ids:
|
|
3341
|
+
ids: new Set(),
|
|
3467
3342
|
schedule,
|
|
3468
3343
|
channel
|
|
3469
3344
|
};
|
|
3470
3345
|
group.ids.add(productId);
|
|
3471
3346
|
groups.set(groupKey, group);
|
|
3472
3347
|
});
|
|
3473
|
-
await Promise.all(
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
})
|
|
3483
|
-
);
|
|
3348
|
+
await Promise.all(Array.from(groups.entries()).map(async ([groupKey, group]) => {
|
|
3349
|
+
const productsById = await this.loadProductsForPriceQuery({
|
|
3350
|
+
ids: Array.from(group.ids),
|
|
3351
|
+
schedule: group.schedule,
|
|
3352
|
+
customerId,
|
|
3353
|
+
channel: group.channel
|
|
3354
|
+
});
|
|
3355
|
+
productMapsByGroup.set(groupKey, productsById);
|
|
3356
|
+
}));
|
|
3484
3357
|
await this.loadQuotationForPriceQuery({
|
|
3485
3358
|
quotation,
|
|
3486
3359
|
customer_id: customerId,
|
|
3487
|
-
channel:
|
|
3360
|
+
channel: paramsList[0]?.channel
|
|
3488
3361
|
});
|
|
3489
|
-
return paramsList.map(
|
|
3490
|
-
var _a2, _b2;
|
|
3362
|
+
return paramsList.map(params => {
|
|
3491
3363
|
const productInput = params.product || {};
|
|
3492
3364
|
const productId = this.getPriceQueryProductId(productInput);
|
|
3493
3365
|
const schedule = this.getPriceQuerySchedule(params);
|
|
3494
|
-
const channel = params.channel ||
|
|
3495
|
-
const groupKey = [
|
|
3496
|
-
|
|
3497
|
-
schedule.schedule_datetime,
|
|
3498
|
-
channel || ""
|
|
3499
|
-
].join("|");
|
|
3500
|
-
const authoritativeProduct = productId === null ? null : ((_b2 = productMapsByGroup.get(groupKey)) == null ? void 0 : _b2.get(productId)) || null;
|
|
3366
|
+
const channel = params.channel || this.otherParams?.channel;
|
|
3367
|
+
const groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
|
|
3368
|
+
const authoritativeProduct = productId === null ? null : productMapsByGroup.get(groupKey)?.get(productId) || null;
|
|
3501
3369
|
const product = this.mergeProductForPriceQuery(productInput, authoritativeProduct);
|
|
3502
|
-
return (0,
|
|
3370
|
+
return (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
3503
3371
|
...params,
|
|
3504
3372
|
product,
|
|
3505
|
-
fallback_price: authoritativeProduct ?
|
|
3373
|
+
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
3506
3374
|
customer_id: customerId,
|
|
3507
|
-
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ?
|
|
3375
|
+
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
|
|
3508
3376
|
});
|
|
3509
3377
|
});
|
|
3510
3378
|
}
|
|
3511
3379
|
async addProductToOrder(product, booking, options) {
|
|
3512
3380
|
try {
|
|
3513
|
-
if (!this.store.order)
|
|
3514
|
-
throw new Error("order 模块未初始化");
|
|
3381
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3515
3382
|
const products = await this.store.order.addProductToOrder(product, booking, options);
|
|
3383
|
+
// // 需要叠加
|
|
3384
|
+
// if (this.hooks.onAddProductOverlay) {
|
|
3385
|
+
// const res = this.hooks.onAddProductOverlay(是否叠加, product)
|
|
3386
|
+
// if (!res) {
|
|
3387
|
+
// 单独添加商品
|
|
3388
|
+
// } else {
|
|
3389
|
+
// 叠加
|
|
3390
|
+
// }
|
|
3391
|
+
// } else {
|
|
3392
|
+
// 叠加
|
|
3393
|
+
// }
|
|
3516
3394
|
return products;
|
|
3517
3395
|
} catch (error) {
|
|
3518
3396
|
throw error;
|
|
@@ -3520,8 +3398,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3520
3398
|
}
|
|
3521
3399
|
async updateOrderProduct(params) {
|
|
3522
3400
|
try {
|
|
3523
|
-
if (!this.store.order)
|
|
3524
|
-
throw new Error("order 模块未初始化");
|
|
3401
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3525
3402
|
const products = await this.store.order.updateOrderProduct(params);
|
|
3526
3403
|
return products;
|
|
3527
3404
|
} catch (error) {
|
|
@@ -3530,8 +3407,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3530
3407
|
}
|
|
3531
3408
|
async updateOrderProducts(paramsList) {
|
|
3532
3409
|
try {
|
|
3533
|
-
if (!this.store.order)
|
|
3534
|
-
throw new Error("order 模块未初始化");
|
|
3410
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3535
3411
|
const products = await this.store.order.updateOrderProducts(paramsList);
|
|
3536
3412
|
return products;
|
|
3537
3413
|
} catch (error) {
|
|
@@ -3540,8 +3416,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3540
3416
|
}
|
|
3541
3417
|
async updateOrderProductQuantity(params) {
|
|
3542
3418
|
try {
|
|
3543
|
-
if (!this.store.order)
|
|
3544
|
-
throw new Error("order 模块未初始化");
|
|
3419
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3545
3420
|
const products = await this.store.order.updateOrderProductQuantity(params);
|
|
3546
3421
|
return products;
|
|
3547
3422
|
} catch (error) {
|
|
@@ -3550,13 +3425,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3550
3425
|
}
|
|
3551
3426
|
updateOrderBooking(params) {
|
|
3552
3427
|
try {
|
|
3553
|
-
if (!this.store.order)
|
|
3554
|
-
throw new Error("order 模块未初始化");
|
|
3428
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3555
3429
|
return this.store.order.updateOrderBooking(params);
|
|
3556
3430
|
} catch (error) {
|
|
3557
3431
|
throw error;
|
|
3558
3432
|
}
|
|
3559
3433
|
}
|
|
3434
|
+
|
|
3560
3435
|
/**
|
|
3561
3436
|
* 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
|
|
3562
3437
|
* 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
|
|
@@ -3566,22 +3441,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3566
3441
|
const params = {
|
|
3567
3442
|
product_id: identity.product_id,
|
|
3568
3443
|
product_variant_id: identity.product_variant_id,
|
|
3569
|
-
updates: {
|
|
3444
|
+
updates: {
|
|
3445
|
+
note: String(note || '')
|
|
3446
|
+
}
|
|
3570
3447
|
};
|
|
3571
|
-
if (identity.unique_identification_number !==
|
|
3448
|
+
if (identity.unique_identification_number !== undefined) {
|
|
3572
3449
|
params.unique_identification_number = identity.unique_identification_number;
|
|
3573
3450
|
}
|
|
3574
|
-
if (identity.product_sku !==
|
|
3451
|
+
if (identity.product_sku !== undefined) {
|
|
3575
3452
|
params.product_sku = identity.product_sku;
|
|
3576
3453
|
}
|
|
3577
|
-
if (identity.product_bundle !==
|
|
3578
|
-
params.product_bundle = identity.product_bundle;
|
|
3454
|
+
if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
|
|
3579
3455
|
const products = await this.updateOrderProduct(params);
|
|
3580
3456
|
return products;
|
|
3581
3457
|
} catch (error) {
|
|
3582
3458
|
throw error;
|
|
3583
3459
|
}
|
|
3584
3460
|
}
|
|
3461
|
+
|
|
3585
3462
|
/**
|
|
3586
3463
|
* 批量删除购物车行,末尾仅一次促销重算。
|
|
3587
3464
|
*
|
|
@@ -3590,8 +3467,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3590
3467
|
*/
|
|
3591
3468
|
async removeProductsFromOrder(identities, options) {
|
|
3592
3469
|
try {
|
|
3593
|
-
if (!this.store.order)
|
|
3594
|
-
throw new Error("order 模块未初始化");
|
|
3470
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3595
3471
|
return await this.store.order.removeProductsFromOrder(identities, options);
|
|
3596
3472
|
} catch (error) {
|
|
3597
3473
|
throw error;
|
|
@@ -3600,7 +3476,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3600
3476
|
async removeProductFromOrder(identity, options) {
|
|
3601
3477
|
return this.removeProductsFromOrder([identity], options);
|
|
3602
3478
|
}
|
|
3479
|
+
|
|
3603
3480
|
// ─── 促销/赠品 透传(迁移自 booking usePromotion) ────────────────
|
|
3481
|
+
|
|
3604
3482
|
/**
|
|
3605
3483
|
* 注入促销评估器到底层 OrderModule。
|
|
3606
3484
|
*
|
|
@@ -3608,10 +3486,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3608
3486
|
* solution.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
|
|
3609
3487
|
*/
|
|
3610
3488
|
setPromotionEvaluator(evaluator) {
|
|
3611
|
-
if (!this.store.order)
|
|
3612
|
-
throw new Error("order 模块未初始化");
|
|
3489
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3613
3490
|
this.store.order.setPromotionEvaluator(evaluator);
|
|
3614
3491
|
}
|
|
3492
|
+
|
|
3615
3493
|
/**
|
|
3616
3494
|
* 注入赠品选择 resolver。UI 层(SalesSdk)通过 bridge 提供。
|
|
3617
3495
|
*
|
|
@@ -3619,10 +3497,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3619
3497
|
* solution.setGiftSelectResolver(async (ctx) => bridge.request(ctx));
|
|
3620
3498
|
*/
|
|
3621
3499
|
setGiftSelectResolver(resolver) {
|
|
3622
|
-
if (!this.store.order)
|
|
3623
|
-
throw new Error("order 模块未初始化");
|
|
3500
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3624
3501
|
this.store.order.setGiftSelectResolver(resolver);
|
|
3625
3502
|
}
|
|
3503
|
+
|
|
3626
3504
|
/**
|
|
3627
3505
|
* 为商品目录追加促销标签,供 SalesSdkProductProvider 等商品列表入口复用。
|
|
3628
3506
|
*
|
|
@@ -3630,40 +3508,40 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3630
3508
|
* const products = solution.appendPromotionTags(catalogProducts);
|
|
3631
3509
|
*/
|
|
3632
3510
|
appendPromotionTags(products) {
|
|
3633
|
-
if (!this.store.order)
|
|
3634
|
-
throw new Error("order 模块未初始化");
|
|
3511
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3635
3512
|
return this.store.order.appendPromotionTags(products);
|
|
3636
3513
|
}
|
|
3514
|
+
|
|
3637
3515
|
/**
|
|
3638
3516
|
* 主动触发一次促销应用(一般写路径会自动触发,少数场景如客户切换后可手动调)。
|
|
3639
3517
|
*/
|
|
3640
3518
|
async applyPromotion() {
|
|
3641
|
-
if (!this.store.order)
|
|
3642
|
-
throw new Error("order 模块未初始化");
|
|
3519
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3643
3520
|
await this.store.order.applyPromotion();
|
|
3644
3521
|
}
|
|
3522
|
+
|
|
3645
3523
|
/** 最近一次促销计算输出的未满足提示。 */
|
|
3646
3524
|
getUnfulfilledPromotions() {
|
|
3647
|
-
|
|
3648
|
-
return ((_a = this.store.order) == null ? void 0 : _a.getUnfulfilledPromotions()) || [];
|
|
3525
|
+
return this.store.order?.getUnfulfilledPromotions() || [];
|
|
3649
3526
|
}
|
|
3527
|
+
|
|
3650
3528
|
/** 最近一次促销计算输出的赠品操作 diff。 */
|
|
3651
3529
|
getLastGiftActions() {
|
|
3652
|
-
|
|
3653
|
-
return ((_a = this.store.order) == null ? void 0 : _a.getLastGiftActions()) || null;
|
|
3530
|
+
return this.store.order?.getLastGiftActions() || null;
|
|
3654
3531
|
}
|
|
3532
|
+
|
|
3655
3533
|
// 获取商品列表
|
|
3656
3534
|
// TODO 需要跟 webpos 内的对齐一下
|
|
3657
3535
|
async getProductList() {
|
|
3658
|
-
|
|
3659
|
-
const menu_list_ids =
|
|
3536
|
+
// 可以直接通过配置里的 menu 读取
|
|
3537
|
+
const menu_list_ids = this.otherParams?.dineInConfig?.['menu.associated_menus'].map(n => Number(n.value)) || [];
|
|
3660
3538
|
try {
|
|
3661
|
-
const res = await
|
|
3539
|
+
const res = await this.store.products?.loadProducts({
|
|
3662
3540
|
menu_list_ids,
|
|
3663
3541
|
cacheId: this.cacheId,
|
|
3664
|
-
schedule_date: (0,
|
|
3665
|
-
schedule_datetime: (0,
|
|
3666
|
-
})
|
|
3542
|
+
schedule_date: (0, _dayjs.default)().format('YYYY-MM-DD'),
|
|
3543
|
+
schedule_datetime: (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss')
|
|
3544
|
+
});
|
|
3667
3545
|
return res;
|
|
3668
3546
|
} catch (error) {
|
|
3669
3547
|
throw error;
|
|
@@ -3672,19 +3550,23 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
3672
3550
|
getOtherParams() {
|
|
3673
3551
|
return this.otherParams;
|
|
3674
3552
|
}
|
|
3675
|
-
async setOtherParams(params, {
|
|
3676
|
-
|
|
3553
|
+
async setOtherParams(params, {
|
|
3554
|
+
cover = false
|
|
3555
|
+
} = {}) {
|
|
3677
3556
|
if (cover) {
|
|
3678
|
-
this.otherParams = {
|
|
3557
|
+
this.otherParams = {
|
|
3558
|
+
...params
|
|
3559
|
+
};
|
|
3679
3560
|
} else {
|
|
3680
|
-
this.otherParams = {
|
|
3561
|
+
this.otherParams = {
|
|
3562
|
+
...this.otherParams,
|
|
3563
|
+
...params
|
|
3564
|
+
};
|
|
3681
3565
|
}
|
|
3682
|
-
this.cacheId =
|
|
3683
|
-
await this.syncOtherParamsToSubModules(params, {
|
|
3566
|
+
this.cacheId = this.otherParams?.cacheId;
|
|
3567
|
+
await this.syncOtherParamsToSubModules(params, {
|
|
3568
|
+
cover
|
|
3569
|
+
});
|
|
3684
3570
|
}
|
|
3685
|
-
}
|
|
3686
|
-
|
|
3687
|
-
0 && (module.exports = {
|
|
3688
|
-
BaseSalesImpl,
|
|
3689
|
-
...require("./types")
|
|
3690
|
-
});
|
|
3571
|
+
}
|
|
3572
|
+
exports.BaseSalesImpl = BaseSalesImpl;
|