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