@pisell/pisellos 2.2.243 → 2.2.244
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/model/strategy/adapter/promotion/evaluator.js +2 -3
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +4 -7
- package/dist/modules/Cart/utils/cartProduct.js +3 -24
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Customer/index.d.ts +0 -20
- package/dist/modules/Customer/index.js +83 -172
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.js +3 -4
- package/dist/modules/Discount/types.d.ts +0 -1
- package/dist/modules/OpenData/index.d.ts +0 -8
- package/dist/modules/OpenData/index.js +17 -37
- package/dist/modules/Order/index.d.ts +18 -268
- package/dist/modules/Order/index.js +757 -3306
- package/dist/modules/Order/types.d.ts +31 -279
- package/dist/modules/Order/types.js +0 -38
- package/dist/modules/Order/utils.d.ts +5 -147
- package/dist/modules/Order/utils.js +103 -746
- package/dist/modules/Payment/index.d.ts +13 -10
- package/dist/modules/Payment/index.js +837 -467
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/utils.js +1 -2
- package/dist/modules/Payment/walletpass.js +7 -14
- package/dist/modules/ProductList/index.d.ts +12 -16
- package/dist/modules/ProductList/index.js +59 -133
- package/dist/modules/ProductList/types.d.ts +0 -14
- package/dist/modules/Quotation/index.d.ts +1 -0
- package/dist/modules/Quotation/index.js +22 -25
- package/dist/modules/Rules/index.d.ts +0 -4
- package/dist/modules/Rules/index.js +69 -93
- package/dist/modules/Rules/types.d.ts +0 -1
- package/dist/modules/SalesSummary/index.d.ts +25 -8
- package/dist/modules/SalesSummary/index.js +35 -86
- package/dist/modules/SalesSummary/types.d.ts +1 -4
- package/dist/modules/SalesSummary/utils.d.ts +25 -2
- package/dist/modules/SalesSummary/utils.js +162 -794
- package/dist/modules/Schedule/index.d.ts +0 -7
- package/dist/modules/Schedule/index.js +2 -24
- package/dist/modules/Summary/index.js +3 -4
- package/dist/modules/index.d.ts +0 -2
- package/dist/modules/index.js +1 -3
- package/dist/plugins/request.d.ts +0 -1
- package/dist/server/index.d.ts +1 -204
- package/dist/server/index.js +928 -3658
- package/dist/server/modules/index.d.ts +0 -2
- package/dist/server/modules/index.js +0 -2
- package/dist/server/modules/order/index.d.ts +4 -120
- package/dist/server/modules/order/index.js +483 -1779
- package/dist/server/modules/order/types.d.ts +3 -32
- package/dist/server/modules/order/types.js +0 -8
- package/dist/server/modules/order/utils/filterBookings.js +3 -26
- package/dist/server/modules/order/utils/filterOrders.js +8 -23
- package/dist/server/modules/products/index.d.ts +7 -34
- package/dist/server/modules/products/index.js +317 -631
- package/dist/server/modules/resource/index.d.ts +0 -2
- package/dist/server/modules/resource/index.js +3 -29
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +88 -111
- package/dist/solution/BaseSales/index.d.ts +9 -131
- package/dist/solution/BaseSales/index.js +447 -1944
- package/dist/solution/BaseSales/types.d.ts +6 -76
- package/dist/solution/BaseSales/types.js +4 -5
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -105
- package/dist/solution/BaseSales/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils.js +21 -62
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +10 -270
- package/dist/solution/BookingTicket/index.js +237 -1772
- package/dist/solution/BookingTicket/types.d.ts +1 -118
- package/dist/solution/BookingTicket/types.js +2 -41
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
- package/dist/solution/BookingTicket/utils/bookingStatus.js +0 -70
- package/dist/solution/BookingTicket/utils/cartView.d.ts +1 -9
- package/dist/solution/BookingTicket/utils/cartView.js +7 -94
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -5
- package/dist/solution/BookingTicket/utils/scan/index.js +8 -20
- package/dist/solution/Checkout/appointmentDemo.json +1 -0
- package/dist/solution/Checkout/index.d.ts +0 -1
- package/dist/solution/Checkout/index.js +9 -10
- package/dist/solution/RegisterAndLogin/config.js +10 -2
- package/dist/solution/ScanOrder/index.d.ts +3 -9
- package/dist/solution/ScanOrder/index.js +134 -241
- package/dist/solution/ScanOrder/types.d.ts +5 -9
- package/dist/solution/ScanOrder/types.js +3 -2
- package/dist/solution/ScanOrder/utils.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +22 -84
- package/dist/solution/VenueBooking/index.d.ts +2 -5
- package/dist/solution/VenueBooking/index.js +59 -110
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +2 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/dist/types/index.d.ts +0 -10
- package/lib/model/strategy/adapter/promotion/evaluator.js +1 -2
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/model/strategy/adapter/walletPass/utils.js +2 -3
- package/lib/modules/Cart/utils/cartProduct.js +3 -20
- package/lib/modules/Cart/utils/changePrice.js +20 -12
- package/lib/modules/Customer/index.d.ts +0 -20
- package/lib/modules/Customer/index.js +11 -64
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.js +1 -5
- package/lib/modules/Discount/types.d.ts +0 -1
- package/lib/modules/OpenData/index.d.ts +0 -8
- package/lib/modules/OpenData/index.js +5 -19
- package/lib/modules/Order/index.d.ts +18 -268
- package/lib/modules/Order/index.js +344 -2149
- package/lib/modules/Order/types.d.ts +31 -279
- package/lib/modules/Order/types.js +0 -1
- package/lib/modules/Order/utils.d.ts +5 -147
- package/lib/modules/Order/utils.js +46 -614
- package/lib/modules/Payment/index.d.ts +13 -10
- package/lib/modules/Payment/index.js +150 -18
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Payment/utils.js +1 -2
- package/lib/modules/Payment/walletpass.js +3 -7
- package/lib/modules/ProductList/index.d.ts +12 -16
- package/lib/modules/ProductList/index.js +4 -41
- package/lib/modules/ProductList/types.d.ts +0 -14
- package/lib/modules/Quotation/index.d.ts +1 -0
- package/lib/modules/Quotation/index.js +16 -19
- package/lib/modules/Rules/index.d.ts +0 -4
- package/lib/modules/Rules/index.js +120 -136
- package/lib/modules/Rules/types.d.ts +0 -1
- package/lib/modules/SalesSummary/index.d.ts +25 -8
- package/lib/modules/SalesSummary/index.js +4 -30
- package/lib/modules/SalesSummary/types.d.ts +1 -4
- package/lib/modules/SalesSummary/utils.d.ts +25 -2
- package/lib/modules/SalesSummary/utils.js +91 -645
- package/lib/modules/Schedule/index.d.ts +0 -7
- package/lib/modules/Schedule/index.js +1 -17
- package/lib/modules/Summary/index.js +4 -5
- package/lib/modules/index.d.ts +0 -2
- package/lib/modules/index.js +1 -5
- package/lib/plugins/request.d.ts +0 -1
- package/lib/server/index.d.ts +1 -204
- package/lib/server/index.js +57 -1888
- package/lib/server/modules/index.d.ts +0 -2
- package/lib/server/modules/index.js +0 -3
- package/lib/server/modules/order/index.d.ts +4 -120
- package/lib/server/modules/order/index.js +142 -919
- package/lib/server/modules/order/types.d.ts +3 -32
- package/lib/server/modules/order/utils/filterBookings.js +5 -24
- package/lib/server/modules/order/utils/filterOrders.js +6 -15
- package/lib/server/modules/products/index.d.ts +7 -34
- package/lib/server/modules/products/index.js +54 -189
- package/lib/server/modules/resource/index.d.ts +0 -2
- package/lib/server/modules/resource/index.js +3 -27
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +40 -47
- package/lib/solution/BaseSales/index.d.ts +9 -131
- package/lib/solution/BaseSales/index.js +63 -1106
- package/lib/solution/BaseSales/types.d.ts +6 -76
- package/lib/solution/BaseSales/types.js +1 -3
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +18 -106
- package/lib/solution/BaseSales/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils.js +10 -54
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +10 -270
- package/lib/solution/BookingTicket/index.js +29 -922
- package/lib/solution/BookingTicket/types.d.ts +1 -118
- package/lib/solution/BookingTicket/types.js +0 -11
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
- package/lib/solution/BookingTicket/utils/bookingStatus.js +2 -44
- package/lib/solution/BookingTicket/utils/cartView.d.ts +1 -9
- package/lib/solution/BookingTicket/utils/cartView.js +6 -61
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -5
- package/lib/solution/BookingTicket/utils/scan/index.js +3 -17
- package/lib/solution/Checkout/appointmentDemo.json +1 -0
- package/lib/solution/Checkout/index.d.ts +0 -1
- package/lib/solution/Checkout/index.js +2 -1
- package/lib/solution/RegisterAndLogin/config.js +10 -2
- package/lib/solution/ScanOrder/index.d.ts +3 -9
- package/lib/solution/ScanOrder/index.js +70 -153
- package/lib/solution/ScanOrder/types.d.ts +5 -9
- package/lib/solution/ScanOrder/utils.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +17 -83
- package/lib/solution/VenueBooking/index.d.ts +2 -5
- package/lib/solution/VenueBooking/index.js +17 -54
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +2 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/lib/types/index.d.ts +0 -10
- package/package.json +1 -1
- package/dist/modules/BookingContext/index.d.ts +0 -48
- package/dist/modules/BookingContext/index.js +0 -566
- package/dist/modules/BookingContext/types.d.ts +0 -102
- package/dist/modules/BookingContext/types.js +0 -51
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -284
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -145
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -218
- package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/dist/modules/BookingContext/utils/flexible.js +0 -56
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
- package/dist/modules/BookingContext/utils/index.d.ts +0 -11
- package/dist/modules/BookingContext/utils/index.js +0 -11
- package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/dist/modules/BookingContext/utils/noResource.js +0 -77
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +0 -36
- package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/dist/modules/BookingContext/utils/productExtend.js +0 -339
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
- package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
- package/dist/modules/BookingContext/utils/resources.js +0 -486
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/dist/modules/Order/utils/manualProductDiscount.js +0 -210
- package/dist/modules/SurchargeList/index.d.ts +0 -16
- package/dist/modules/SurchargeList/index.js +0 -162
- package/dist/modules/SurchargeList/types.d.ts +0 -11
- package/dist/modules/SurchargeList/types.js +0 -1
- package/dist/server/modules/payment/index.d.ts +0 -28
- package/dist/server/modules/payment/index.js +0 -305
- package/dist/server/modules/payment/types.d.ts +0 -9
- package/dist/server/modules/payment/types.js +0 -1
- package/dist/server/test.json +0 -713
- package/dist/server/utils/small-ticket.d.ts +0 -71
- package/dist/server/utils/small-ticket.js +0 -830
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
- package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1438
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
- package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +0 -95
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +0 -123
- package/dist/solution/BookingTicket/utils/exampleData.js +0 -183
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -438
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -399
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -56
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +0 -150
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +0 -78
- package/lib/modules/BookingContext/index.d.ts +0 -48
- package/lib/modules/BookingContext/index.js +0 -368
- package/lib/modules/BookingContext/types.d.ts +0 -102
- package/lib/modules/BookingContext/types.js +0 -34
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -276
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -151
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -201
- package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/lib/modules/BookingContext/utils/flexible.js +0 -80
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
- package/lib/modules/BookingContext/utils/index.d.ts +0 -11
- package/lib/modules/BookingContext/utils/index.js +0 -43
- package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/lib/modules/BookingContext/utils/noResource.js +0 -90
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +0 -56
- package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/lib/modules/BookingContext/utils/productExtend.js +0 -283
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
- package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
- package/lib/modules/BookingContext/utils/resources.js +0 -377
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/lib/modules/Order/utils/manualProductDiscount.js +0 -206
- package/lib/modules/SurchargeList/index.d.ts +0 -16
- package/lib/modules/SurchargeList/index.js +0 -89
- package/lib/modules/SurchargeList/types.d.ts +0 -11
- package/lib/modules/SurchargeList/types.js +0 -17
- package/lib/server/modules/payment/index.d.ts +0 -28
- package/lib/server/modules/payment/index.js +0 -192
- package/lib/server/modules/payment/types.d.ts +0 -9
- package/lib/server/modules/payment/types.js +0 -17
- package/lib/server/test.json +0 -713
- package/lib/server/utils/small-ticket.d.ts +0 -71
- package/lib/server/utils/small-ticket.js +0 -781
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
- package/lib/solution/BaseSales/utils/cartPromotion.js +0 -992
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
- package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +0 -125
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +0 -123
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -254
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -168
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -51
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +0 -127
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +0 -85
|
@@ -34,106 +34,13 @@ __export(BaseSales_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(BaseSales_exports);
|
|
36
36
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
|
-
var import_types = require("./types");
|
|
38
37
|
var import_Order = require("../../modules/Order");
|
|
39
38
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
|
-
var
|
|
41
|
-
var import_types2 = require("../BookingByStep/types");
|
|
39
|
+
var import_types = require("../BookingByStep/types");
|
|
42
40
|
var import_utils = require("../../modules/Order/utils");
|
|
43
41
|
var import_dayjs = __toESM(require("dayjs"));
|
|
44
42
|
__reExport(BaseSales_exports, require("./types"), module.exports);
|
|
45
|
-
var import_Quotation = require("../../modules/Quotation");
|
|
46
43
|
var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
|
|
47
|
-
var import_quotationPrice = require("./utils/quotationPrice");
|
|
48
|
-
function isBaseSalesManualProductDiscountProduct(product) {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
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");
|
|
51
|
-
}
|
|
52
|
-
function getBaseSalesProductUid(product) {
|
|
53
|
-
var _a;
|
|
54
|
-
const uid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
|
|
55
|
-
if (uid === void 0 || uid === null || uid === "")
|
|
56
|
-
return null;
|
|
57
|
-
return String(uid);
|
|
58
|
-
}
|
|
59
|
-
function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
|
|
60
|
-
const previousByUid = /* @__PURE__ */ new Map();
|
|
61
|
-
(previousProducts || []).forEach((product, index) => {
|
|
62
|
-
const uid = getBaseSalesProductUid(product);
|
|
63
|
-
if (uid)
|
|
64
|
-
previousByUid.set(uid, product);
|
|
65
|
-
previousByUid.set(`__index__:${index}`, product);
|
|
66
|
-
});
|
|
67
|
-
return (nextProducts || []).map((product, index) => {
|
|
68
|
-
const uid = getBaseSalesProductUid(product);
|
|
69
|
-
const previous = (uid ? previousByUid.get(uid) : void 0) || previousByUid.get(`__index__:${index}`);
|
|
70
|
-
return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function getBaseSalesUniqueArrayMetadataKey(key) {
|
|
74
|
-
if (key === "products" || key === "bookings")
|
|
75
|
-
return "unique_identification_number";
|
|
76
|
-
if (key === "payments" || key === "payment")
|
|
77
|
-
return "unique_payment_number";
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
function getBaseSalesMetadataUid(item, metadataKey) {
|
|
81
|
-
var _a;
|
|
82
|
-
const uid = ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a[metadataKey]) ?? (item == null ? void 0 : item[metadataKey]);
|
|
83
|
-
if (uid === void 0 || uid === null || uid === "")
|
|
84
|
-
return null;
|
|
85
|
-
return String(uid);
|
|
86
|
-
}
|
|
87
|
-
function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
|
|
88
|
-
const result = [];
|
|
89
|
-
const indexByUid = /* @__PURE__ */ new Map();
|
|
90
|
-
const appendOrReplaceByUid = (item) => {
|
|
91
|
-
const clonedItem = (0, import_lodash_es.cloneDeep)(item);
|
|
92
|
-
const uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
|
|
93
|
-
if (!uid) {
|
|
94
|
-
result.push(clonedItem);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const existingIndex = indexByUid.get(uid);
|
|
98
|
-
if (existingIndex !== void 0) {
|
|
99
|
-
result[existingIndex] = clonedItem;
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
indexByUid.set(uid, result.length);
|
|
103
|
-
result.push(clonedItem);
|
|
104
|
-
};
|
|
105
|
-
currentValue.forEach(appendOrReplaceByUid);
|
|
106
|
-
loadedValue.forEach(appendOrReplaceByUid);
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
|
|
110
|
-
if (!currentTempOrder)
|
|
111
|
-
return loadedRecord;
|
|
112
|
-
const mergedRecord = (0, import_lodash_es.mergeWith)(
|
|
113
|
-
(0, import_lodash_es.cloneDeep)(currentTempOrder),
|
|
114
|
-
(0, import_lodash_es.cloneDeep)(loadedRecord || {}),
|
|
115
|
-
(currentValue, loadedValue, key) => {
|
|
116
|
-
if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
|
|
117
|
-
const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
|
|
118
|
-
if (metadataKey) {
|
|
119
|
-
return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
|
|
120
|
-
}
|
|
121
|
-
return [
|
|
122
|
-
...(0, import_lodash_es.cloneDeep)(currentValue),
|
|
123
|
-
...(0, import_lodash_es.cloneDeep)(loadedValue)
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
if (Array.isArray(loadedValue))
|
|
127
|
-
return (0, import_lodash_es.cloneDeep)(loadedValue);
|
|
128
|
-
if (Array.isArray(currentValue) && loadedValue === void 0) {
|
|
129
|
-
return (0, import_lodash_es.cloneDeep)(currentValue);
|
|
130
|
-
}
|
|
131
|
-
return void 0;
|
|
132
|
-
}
|
|
133
|
-
);
|
|
134
|
-
delete mergedRecord.request_unique_idempotency_token;
|
|
135
|
-
return mergedRecord;
|
|
136
|
-
}
|
|
137
44
|
var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
138
45
|
constructor(name, version) {
|
|
139
46
|
super(name, version);
|
|
@@ -141,22 +48,20 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
141
48
|
this.defaultVersion = "1.0.0";
|
|
142
49
|
this.isSolution = true;
|
|
143
50
|
this.initializeOptions = {};
|
|
51
|
+
// LoggerManager 实例
|
|
144
52
|
this.store = {
|
|
145
53
|
order: void 0
|
|
146
54
|
};
|
|
147
55
|
this.otherParams = {};
|
|
148
56
|
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
149
57
|
this.currentSalesDetail = null;
|
|
150
|
-
this.discountConfigCacheKey = null;
|
|
151
|
-
this.hasManualDiscountSelection = false;
|
|
152
|
-
this.paymentMethodsCache = [];
|
|
153
58
|
}
|
|
154
59
|
/**
|
|
155
60
|
* 子类可覆盖此方法以追加/收敛要注册的子模块。
|
|
156
|
-
* 默认包含通用销售模块:products / order / salesSummary / schedule / payment
|
|
61
|
+
* 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
|
|
157
62
|
*/
|
|
158
63
|
getRegisteredModuleNames() {
|
|
159
|
-
return ["products", "order", "salesSummary", "schedule", "payment"
|
|
64
|
+
return ["products", "order", "salesSummary", "schedule", "payment"];
|
|
160
65
|
}
|
|
161
66
|
/**
|
|
162
67
|
* 记录信息日志
|
|
@@ -197,223 +102,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
197
102
|
});
|
|
198
103
|
}
|
|
199
104
|
}
|
|
200
|
-
hydrateOrderPaymentNames(payments) {
|
|
201
|
-
if (!payments.length)
|
|
202
|
-
return [];
|
|
203
|
-
if (!this.paymentMethodsCache.length) {
|
|
204
|
-
return payments.map((payment) => ({ ...payment }));
|
|
205
|
-
}
|
|
206
|
-
const paymentMethodById = /* @__PURE__ */ new Map();
|
|
207
|
-
const paymentMethodByCode = /* @__PURE__ */ new Map();
|
|
208
|
-
this.paymentMethodsCache.forEach((method) => {
|
|
209
|
-
if ((method == null ? void 0 : method.id) !== void 0 && (method == null ? void 0 : method.id) !== null) {
|
|
210
|
-
paymentMethodById.set(String(method.id), method);
|
|
211
|
-
}
|
|
212
|
-
if (method == null ? void 0 : method.code) {
|
|
213
|
-
paymentMethodByCode.set(String(method.code), method);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
return payments.map((payment) => {
|
|
217
|
-
const nextPayment = { ...payment };
|
|
218
|
-
if (nextPayment.name)
|
|
219
|
-
return nextPayment;
|
|
220
|
-
const paymentMethod = paymentMethodById.get(String(nextPayment.custom_payment_id)) || paymentMethodByCode.get(String(nextPayment.code));
|
|
221
|
-
if (!(paymentMethod == null ? void 0 : paymentMethod.name))
|
|
222
|
-
return nextPayment;
|
|
223
|
-
return {
|
|
224
|
-
...nextPayment,
|
|
225
|
-
name: paymentMethod.name
|
|
226
|
-
};
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
105
|
get payment() {
|
|
230
106
|
return this.store.payment;
|
|
231
107
|
}
|
|
232
|
-
getCurrentOrderCustomerId() {
|
|
233
|
-
var _a, _b;
|
|
234
|
-
const tempOrder = (_b = (_a = this.store.order) == null ? void 0 : _a.getTempOrder) == null ? void 0 : _b.call(_a);
|
|
235
|
-
const customerId = tempOrder == null ? void 0 : tempOrder.customer_id;
|
|
236
|
-
if (customerId === null || customerId === void 0)
|
|
237
|
-
return void 0;
|
|
238
|
-
return customerId;
|
|
239
|
-
}
|
|
240
|
-
applyQuotationScheduleResolver(quotation) {
|
|
241
|
-
const scheduleModule = this.store.schedule;
|
|
242
|
-
if (!scheduleModule)
|
|
243
|
-
return;
|
|
244
|
-
quotation.setScheduleResolver((id) => {
|
|
245
|
-
var _a;
|
|
246
|
-
const schedules = ((_a = scheduleModule.getScheduleListByIds) == null ? void 0 : _a.call(scheduleModule, [id])) || [];
|
|
247
|
-
return schedules[0];
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
async loadQuotationForPriceQuery(params) {
|
|
251
|
-
var _a;
|
|
252
|
-
if (!params.quotation)
|
|
253
|
-
return;
|
|
254
|
-
this.applyQuotationScheduleResolver(params.quotation);
|
|
255
|
-
await params.quotation.loadQuotations({
|
|
256
|
-
channel: params.channel || ((_a = this.otherParams) == null ? void 0 : _a.channel),
|
|
257
|
-
customer_id: params.customer_id
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
getPriceQueryProductId(product) {
|
|
261
|
-
const productId = Number((product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id));
|
|
262
|
-
if (!Number.isFinite(productId))
|
|
263
|
-
return null;
|
|
264
|
-
return productId;
|
|
265
|
-
}
|
|
266
|
-
getPriceQuerySchedule(params) {
|
|
267
|
-
const booking = params.booking || {};
|
|
268
|
-
if (typeof booking.start_date === "string" && booking.start_date.trim()) {
|
|
269
|
-
const scheduleDate = booking.start_date.trim();
|
|
270
|
-
const startTime = typeof booking.start_time === "string" && booking.start_time.trim() ? booking.start_time.trim() : "00:00:00";
|
|
271
|
-
const datetime = (0, import_dayjs.default)(`${scheduleDate} ${startTime}`);
|
|
272
|
-
return {
|
|
273
|
-
schedule_date: scheduleDate,
|
|
274
|
-
schedule_datetime: datetime.isValid() ? datetime.format("YYYY-MM-DD HH:mm:ss") : `${scheduleDate} ${startTime}`
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (typeof params.datetime === "string" && params.datetime.trim()) {
|
|
278
|
-
const datetime = (0, import_dayjs.default)(params.datetime.trim());
|
|
279
|
-
if (datetime.isValid()) {
|
|
280
|
-
return {
|
|
281
|
-
schedule_date: datetime.format("YYYY-MM-DD"),
|
|
282
|
-
schedule_datetime: datetime.format("YYYY-MM-DD HH:mm:ss")
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
const now = (0, import_dayjs.default)();
|
|
287
|
-
return {
|
|
288
|
-
schedule_date: now.format("YYYY-MM-DD"),
|
|
289
|
-
schedule_datetime: now.format("YYYY-MM-DD HH:mm:ss")
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
async loadProductForPriceQuery(params, customerId) {
|
|
293
|
-
var _a, _b;
|
|
294
|
-
const product = params.product || {};
|
|
295
|
-
const productId = this.getPriceQueryProductId(product);
|
|
296
|
-
if (productId === null || !this.request)
|
|
297
|
-
return null;
|
|
298
|
-
const schedule = this.getPriceQuerySchedule(params);
|
|
299
|
-
try {
|
|
300
|
-
const response = await this.request.post("/product/query", {
|
|
301
|
-
ids: [productId],
|
|
302
|
-
open_quotation: 1,
|
|
303
|
-
open_bundle: 1,
|
|
304
|
-
status: "published",
|
|
305
|
-
num: 1,
|
|
306
|
-
skip: 1,
|
|
307
|
-
customer_id: customerId,
|
|
308
|
-
schedule_date: schedule.schedule_date,
|
|
309
|
-
schedule_datetime: schedule.schedule_datetime,
|
|
310
|
-
application_code: params.channel || ((_a = this.otherParams) == null ? void 0 : _a.channel)
|
|
311
|
-
}, {
|
|
312
|
-
osServer: true,
|
|
313
|
-
customToast: () => {
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
const list = ((_b = response == null ? void 0 : response.data) == null ? void 0 : _b.list) || (response == null ? void 0 : response.list) || [];
|
|
317
|
-
if (!Array.isArray(list))
|
|
318
|
-
return null;
|
|
319
|
-
return list.find((item) => Number((item == null ? void 0 : item.id) ?? (item == null ? void 0 : item.product_id)) === productId) || null;
|
|
320
|
-
} catch (error) {
|
|
321
|
-
this.logWarning("loadProductForPriceQuery: 商品重查失败,使用入参 fallback", {
|
|
322
|
-
productId,
|
|
323
|
-
error: error instanceof Error ? error.message : String(error)
|
|
324
|
-
});
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
getAuthoritativeBundleItems(product) {
|
|
329
|
-
if (Array.isArray(product == null ? void 0 : product.product_bundle))
|
|
330
|
-
return product.product_bundle;
|
|
331
|
-
const groups = Array.isArray(product == null ? void 0 : product.bundle_group) ? product.bundle_group : Array.isArray(product == null ? void 0 : product.bundleGroup) ? product.bundleGroup : [];
|
|
332
|
-
return groups.flatMap((group) => {
|
|
333
|
-
const items = Array.isArray(group == null ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group == null ? void 0 : group.bundleItem) ? group.bundleItem : [];
|
|
334
|
-
return items.map((item) => ({
|
|
335
|
-
...item,
|
|
336
|
-
group_id: (item == null ? void 0 : item.group_id) ?? (group == null ? void 0 : group.id),
|
|
337
|
-
bundle_group_id: (item == null ? void 0 : item.bundle_group_id) ?? (item == null ? void 0 : item.group_id) ?? (group == null ? void 0 : group.id)
|
|
338
|
-
}));
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
findAuthoritativeBundleItem(bundle, candidates) {
|
|
342
|
-
const bundleId = bundle.bundle_id ?? bundle.id;
|
|
343
|
-
if (bundleId != null) {
|
|
344
|
-
const matchedById = candidates.find((item) => String((item == null ? void 0 : item.bundle_id) ?? (item == null ? void 0 : item.id)) === String(bundleId));
|
|
345
|
-
if (matchedById)
|
|
346
|
-
return matchedById;
|
|
347
|
-
}
|
|
348
|
-
const productId = bundle.bundle_product_id ?? bundle._bundle_product_id;
|
|
349
|
-
const groupId = bundle.bundle_group_id ?? bundle.group_id;
|
|
350
|
-
return candidates.find((item) => {
|
|
351
|
-
const itemProductId = (item == null ? void 0 : item.bundle_product_id) ?? (item == null ? void 0 : item._bundle_product_id);
|
|
352
|
-
const itemGroupId = (item == null ? void 0 : item.bundle_group_id) ?? (item == null ? void 0 : item.group_id);
|
|
353
|
-
if (productId == null || String(itemProductId) !== String(productId))
|
|
354
|
-
return false;
|
|
355
|
-
if (groupId == null)
|
|
356
|
-
return true;
|
|
357
|
-
return String(itemGroupId) === String(groupId);
|
|
358
|
-
}) || null;
|
|
359
|
-
}
|
|
360
|
-
getAuthoritativeBundleUnitPrice(bundle) {
|
|
361
|
-
return bundle.price ?? bundle.bundle_selling_price ?? bundle.custom_price ?? bundle.product_price ?? bundle.base_price;
|
|
362
|
-
}
|
|
363
|
-
mergeProductForPriceQuery(product, authoritativeProduct) {
|
|
364
|
-
if (!authoritativeProduct)
|
|
365
|
-
return product;
|
|
366
|
-
const selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
367
|
-
const authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
|
|
368
|
-
const productBundle = selectedBundles.map((bundle) => {
|
|
369
|
-
const authoritativeBundle = this.findAuthoritativeBundleItem(bundle, authoritativeBundles);
|
|
370
|
-
const unitPrice = authoritativeBundle ? this.getAuthoritativeBundleUnitPrice(authoritativeBundle) : void 0;
|
|
371
|
-
if (unitPrice === void 0 || unitPrice === null || unitPrice === "")
|
|
372
|
-
return bundle;
|
|
373
|
-
return {
|
|
374
|
-
...bundle,
|
|
375
|
-
price: unitPrice,
|
|
376
|
-
bundle_selling_price: unitPrice,
|
|
377
|
-
base_price: (authoritativeBundle == null ? void 0 : authoritativeBundle.base_price) ?? bundle.base_price,
|
|
378
|
-
product_price: (authoritativeBundle == null ? void 0 : authoritativeBundle.product_price) ?? bundle.product_price
|
|
379
|
-
};
|
|
380
|
-
});
|
|
381
|
-
return {
|
|
382
|
-
...product,
|
|
383
|
-
...authoritativeProduct,
|
|
384
|
-
id: product.id ?? authoritativeProduct.id,
|
|
385
|
-
product_id: product.product_id ?? authoritativeProduct.product_id ?? authoritativeProduct.id,
|
|
386
|
-
product_variant_id: product.product_variant_id ?? authoritativeProduct.product_variant_id ?? 0,
|
|
387
|
-
num: product.num ?? product.quantity ?? authoritativeProduct.num,
|
|
388
|
-
quantity: product.quantity ?? product.num ?? authoritativeProduct.quantity,
|
|
389
|
-
product_sku: (() => {
|
|
390
|
-
const authoritativeSku = (0, import_utils.ensureProductSku)(authoritativeProduct);
|
|
391
|
-
const productSku = (0, import_utils.ensureProductSku)(product);
|
|
392
|
-
const hasProductSku = product.product_sku && typeof product.product_sku === "object";
|
|
393
|
-
return {
|
|
394
|
-
...authoritativeSku,
|
|
395
|
-
...productSku,
|
|
396
|
-
option: hasProductSku ? productSku.option : authoritativeSku.option
|
|
397
|
-
};
|
|
398
|
-
})(),
|
|
399
|
-
product_bundle: productBundle,
|
|
400
|
-
metadata: product.metadata ?? authoritativeProduct.metadata
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
getSubmitOrderSalesChannel() {
|
|
404
|
-
var _a;
|
|
405
|
-
return (_a = this.otherParams) == null ? void 0 : _a.channel;
|
|
406
|
-
}
|
|
407
108
|
/**
|
|
408
109
|
* 工厂入口:根据子模块名实例化对应模块。
|
|
409
110
|
* 默认使用 BookingByStep 公共 `createModule`。子类若需引入额外类型(如 customer),
|
|
410
111
|
* 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
|
|
411
112
|
*/
|
|
412
113
|
createSubModule(moduleName) {
|
|
413
|
-
|
|
414
|
-
return new import_Quotation.QuotationModule(`${this.name}_quotation`);
|
|
415
|
-
}
|
|
416
|
-
return (0, import_types2.createModule)(moduleName, this.name);
|
|
114
|
+
return (0, import_types.createModule)(moduleName, this.name);
|
|
417
115
|
}
|
|
418
116
|
getSubModuleHooks(moduleName) {
|
|
419
117
|
var _a, _b;
|
|
@@ -425,43 +123,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
425
123
|
}
|
|
426
124
|
return optionHooks[moduleName] || ((_b = this.otherParams[moduleName]) == null ? void 0 : _b.hooks) || otherHooks[moduleName];
|
|
427
125
|
}
|
|
428
|
-
/**
|
|
429
|
-
* 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
|
|
430
|
-
*
|
|
431
|
-
* @example
|
|
432
|
-
* const params = this.buildSubModuleOtherParams();
|
|
433
|
-
* this.core.registerModule(orderModule, { otherParams: params });
|
|
434
|
-
*/
|
|
435
|
-
buildSubModuleOtherParams() {
|
|
436
|
-
return {
|
|
437
|
-
...this.otherParams,
|
|
438
|
-
salesSummaryModuleName: `${this.name}_salesSummary`,
|
|
439
|
-
fatherModule: this.name,
|
|
440
|
-
openCache: this.cacheId ? true : false,
|
|
441
|
-
cacheId: this.cacheId
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* 将父级 otherParams 的变更显式同步给已注册的子模块。
|
|
446
|
-
*
|
|
447
|
-
* @example
|
|
448
|
-
* await this.syncOtherParamsToSubModules({ channel: 'pos' });
|
|
449
|
-
*/
|
|
450
|
-
async syncOtherParamsToSubModules(changedParams, { cover = false } = {}) {
|
|
451
|
-
const nextSubModuleOtherParams = this.buildSubModuleOtherParams();
|
|
452
|
-
await Promise.all(
|
|
453
|
-
Object.values(this.store).map(async (subModule) => {
|
|
454
|
-
const targetModule = subModule;
|
|
455
|
-
if (!targetModule || typeof targetModule.updateOtherParams !== "function") {
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
await targetModule.updateOtherParams(nextSubModuleOtherParams, {
|
|
459
|
-
changedParams,
|
|
460
|
-
cover
|
|
461
|
-
});
|
|
462
|
-
})
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
126
|
/**
|
|
466
127
|
* 读取 sessionStorage[this.name][cacheId],作为子模块 initialState 的来源。
|
|
467
128
|
* sessionStorage 损坏时静默忽略,按空状态注册。
|
|
@@ -479,64 +140,19 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
479
140
|
return {};
|
|
480
141
|
}
|
|
481
142
|
}
|
|
482
|
-
getAppData(key) {
|
|
483
|
-
var _a, _b, _c, _d, _e, _f;
|
|
484
|
-
const getData = (_b = (_a = this.appPlugin).getData) == null ? void 0 : _b.call(_a);
|
|
485
|
-
if (typeof getData === "function")
|
|
486
|
-
return getData(key);
|
|
487
|
-
const app = this.appPlugin.getApp();
|
|
488
|
-
const coreData = (_f = (_d = (_c = app == null ? void 0 : app.models) == null ? void 0 : _c.getStore) == null ? void 0 : (_e = _d.call(_c)).getDataByModel) == null ? void 0 : _f.call(_e, "core", "core");
|
|
489
|
-
return coreData == null ? void 0 : coreData[key];
|
|
490
|
-
}
|
|
491
|
-
syncAppDataToTempOrder(tempOrder) {
|
|
492
|
-
const isPriceIncludeTax = this.getAppData("is_price_include_tax");
|
|
493
|
-
const taxCountryCode = this.getAppData("tax_country_code");
|
|
494
|
-
const currencyCode = this.getAppData("shop_currency_code");
|
|
495
|
-
const currencySymbol = this.getAppData("shop_symbol");
|
|
496
|
-
let isChanged = false;
|
|
497
|
-
if (isPriceIncludeTax !== void 0) {
|
|
498
|
-
const nextIsPriceIncludeTax = Number(isPriceIncludeTax);
|
|
499
|
-
if ((nextIsPriceIncludeTax === 0 || nextIsPriceIncludeTax === 1) && tempOrder.is_price_include_tax !== nextIsPriceIncludeTax) {
|
|
500
|
-
tempOrder.is_price_include_tax = nextIsPriceIncludeTax;
|
|
501
|
-
isChanged = true;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
if (taxCountryCode !== void 0) {
|
|
505
|
-
const nextTaxCountryCode = String(taxCountryCode || "");
|
|
506
|
-
if (tempOrder.tax_country_code !== nextTaxCountryCode) {
|
|
507
|
-
tempOrder.tax_country_code = nextTaxCountryCode;
|
|
508
|
-
isChanged = true;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
if (currencyCode !== void 0) {
|
|
512
|
-
const nextCurrencyCode = String(currencyCode || "");
|
|
513
|
-
if (tempOrder.currency_code !== nextCurrencyCode) {
|
|
514
|
-
tempOrder.currency_code = nextCurrencyCode;
|
|
515
|
-
isChanged = true;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (currencySymbol !== void 0) {
|
|
519
|
-
const nextCurrencySymbol = String(currencySymbol || "");
|
|
520
|
-
if (tempOrder.currency_symbol !== nextCurrencySymbol) {
|
|
521
|
-
tempOrder.currency_symbol = nextCurrencySymbol;
|
|
522
|
-
isChanged = true;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
return isChanged;
|
|
526
|
-
}
|
|
527
143
|
async initialize(core, options = {}) {
|
|
528
|
-
var _a
|
|
144
|
+
var _a;
|
|
529
145
|
this.core = core;
|
|
530
146
|
this.initializeOptions = options || {};
|
|
531
147
|
this.otherParams = options.otherParams || {};
|
|
532
148
|
this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
|
|
533
149
|
this.window = core.getPlugin("window");
|
|
534
150
|
this.request = core.getPlugin("request");
|
|
535
|
-
|
|
536
|
-
if (!
|
|
151
|
+
const appPlugin = core.getPlugin("app");
|
|
152
|
+
if (!appPlugin) {
|
|
537
153
|
throw new Error("Checkout 解决方案需要 app 插件支持");
|
|
538
154
|
}
|
|
539
|
-
const app =
|
|
155
|
+
const app = appPlugin.getApp();
|
|
540
156
|
this.logger = app.logger;
|
|
541
157
|
const targetCacheData = this.readSessionCacheData();
|
|
542
158
|
const moduleNames = this.getRegisteredModuleNames();
|
|
@@ -550,18 +166,18 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
550
166
|
this.core.registerModule(targetModule, {
|
|
551
167
|
initialState: (targetCacheData == null ? void 0 : targetCacheData[targetModule.name]) || {},
|
|
552
168
|
...hooks ? { hooks } : {},
|
|
553
|
-
otherParams:
|
|
169
|
+
otherParams: {
|
|
170
|
+
...this.otherParams,
|
|
171
|
+
salesSummaryModuleName: `${this.name}_salesSummary`,
|
|
172
|
+
fatherModule: this.name,
|
|
173
|
+
openCache: this.cacheId ? true : false,
|
|
174
|
+
cacheId: this.cacheId
|
|
175
|
+
}
|
|
554
176
|
});
|
|
555
177
|
});
|
|
556
178
|
if (this.store.schedule) {
|
|
557
179
|
await this.store.schedule.loadAllSchedule();
|
|
558
180
|
}
|
|
559
|
-
if (this.store.order && typeof ((_b = this.otherParams) == null ? void 0 : _b.enableTempOrderPersist) === "boolean") {
|
|
560
|
-
this.store.order.setEnableTempOrderPersist(
|
|
561
|
-
this.otherParams.enableTempOrderPersist
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
await this.getPaymentMethodsAsync();
|
|
565
181
|
this.core.effects.emit(`${this.name}:onInited`, {});
|
|
566
182
|
}
|
|
567
183
|
async destroy() {
|
|
@@ -581,7 +197,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
581
197
|
}
|
|
582
198
|
/**
|
|
583
199
|
* 加载销售订单到统一 tempOrder 工作区。
|
|
584
|
-
*
|
|
200
|
+
* 有 app.sqlite 时优先读取本地记录;本地未命中或 forceRemote=true 时再拉云端。
|
|
585
201
|
*
|
|
586
202
|
* 子类可在 `super.loadSalesDetail` 之后基于返回的 `sales` 做业务侧装配
|
|
587
203
|
* (比如把 `sales.customer` 写入 CustomerModule、emit 业务 hook 等)。
|
|
@@ -591,21 +207,25 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
591
207
|
throw new Error("order 模块未初始化");
|
|
592
208
|
const params = typeof orderIdOrParams === "object" ? orderIdOrParams : { orderId: orderIdOrParams };
|
|
593
209
|
const externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
210
|
+
if (!params.forceRemote) {
|
|
211
|
+
const localRecord = params.orderId !== void 0 ? await this.store.order.getLocalOrderByOrderId(params.orderId) : externalSaleNumber ? await this.store.order.getLocalOrderByExternalSaleNumber(externalSaleNumber) : params.orderNumber ? await this.store.order.getLocalOrderByOrderNumber(params.orderNumber) : null;
|
|
212
|
+
if (localRecord) {
|
|
213
|
+
const sales2 = await this.store.order.hydrateTempOrderFromRecord(localRecord, { recalcOnHydrate: false });
|
|
214
|
+
this.currentSalesDetail = sales2;
|
|
215
|
+
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, { sales: sales2 });
|
|
216
|
+
return sales2;
|
|
217
|
+
}
|
|
597
218
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
219
|
+
if (params.orderId === void 0 || params.orderId === null) {
|
|
220
|
+
throw new Error("加载销售详情需要 orderId,或本地库中存在对应 externalSaleNumber/orderNumber");
|
|
221
|
+
}
|
|
222
|
+
const res = await this.store.order.getOrderInfoByRemote(Number(params.orderId));
|
|
602
223
|
if (!res || res.code !== 200) {
|
|
603
|
-
const message = res && (res.message || res.msg) || `加载销售详情失败: ${
|
|
224
|
+
const message = res && (res.message || res.msg) || `加载销售详情失败: ${params.orderId}`;
|
|
604
225
|
throw new Error(message);
|
|
605
226
|
}
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
const sales = await this.store.order.hydrateTempOrderFromRecord(record, { recalcOnHydrate: false });
|
|
227
|
+
const sales = await this.store.order.hydrateTempOrderFromRecord(res.data, { recalcOnHydrate: false });
|
|
228
|
+
await this.store.order.saveDraft();
|
|
609
229
|
this.currentSalesDetail = sales;
|
|
610
230
|
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, { sales });
|
|
611
231
|
return sales;
|
|
@@ -666,13 +286,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
666
286
|
const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
|
|
667
287
|
return result;
|
|
668
288
|
}
|
|
669
|
-
async replaceTempOrder(tempOrder) {
|
|
670
|
-
if (!this.store.order)
|
|
671
|
-
throw new Error("order 模块未初始化");
|
|
672
|
-
const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder);
|
|
673
|
-
await this.effectsEmit("onTempOrderReplaced", { tempOrder: nextTempOrder });
|
|
674
|
-
return nextTempOrder;
|
|
675
|
-
}
|
|
676
289
|
getOrderIdentity() {
|
|
677
290
|
if (!this.store.order)
|
|
678
291
|
return null;
|
|
@@ -698,21 +311,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
698
311
|
return "";
|
|
699
312
|
return this.store.order.getTempOrderNote();
|
|
700
313
|
}
|
|
701
|
-
updateTempOrderNote(note
|
|
314
|
+
updateTempOrderNote(note) {
|
|
702
315
|
try {
|
|
703
316
|
if (!this.store.order)
|
|
704
317
|
throw new Error("order 模块未初始化");
|
|
705
|
-
const result = this.store.order.updateTempOrderNote(note
|
|
318
|
+
const result = this.store.order.updateTempOrderNote(note);
|
|
706
319
|
return result;
|
|
707
320
|
} catch (error) {
|
|
708
321
|
throw error;
|
|
709
322
|
}
|
|
710
323
|
}
|
|
711
|
-
updateRemoteOrderNote(orderId, note) {
|
|
712
|
-
if (!this.store.order)
|
|
713
|
-
throw new Error("order 模块未初始化");
|
|
714
|
-
this.store.order.syncTempOrderNoteToRemote(orderId, note);
|
|
715
|
-
}
|
|
716
324
|
updateTempOrderShopDiscount(amount) {
|
|
717
325
|
if (!this.store.order)
|
|
718
326
|
throw new Error("order 模块未初始化");
|
|
@@ -723,18 +331,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
723
331
|
throw new Error("order 模块未初始化");
|
|
724
332
|
return this.store.order.updateTempOrderContactsInfo(contactsInfo);
|
|
725
333
|
}
|
|
726
|
-
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
727
|
-
setEnableTempOrderPersist(enabled) {
|
|
728
|
-
if (!this.store.order)
|
|
729
|
-
throw new Error("order 模块未初始化");
|
|
730
|
-
this.store.order.setEnableTempOrderPersist(enabled);
|
|
731
|
-
}
|
|
732
|
-
/** 是否允许 saveDraft 写入 IndexedDB 草稿。 */
|
|
733
|
-
isTempOrderPersistEnabled() {
|
|
734
|
-
if (!this.store.order)
|
|
735
|
-
return false;
|
|
736
|
-
return this.store.order.isTempOrderPersistEnabled();
|
|
737
|
-
}
|
|
738
334
|
ensureTempOrder() {
|
|
739
335
|
if (!this.store.order)
|
|
740
336
|
throw new Error("order 模块未初始化");
|
|
@@ -746,10 +342,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
746
342
|
if (!this.store.order)
|
|
747
343
|
throw new Error("order 模块未初始化");
|
|
748
344
|
const tempOrder = await this.store.order.addNewOrder();
|
|
749
|
-
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
750
|
-
this.store.order.persistTempOrder();
|
|
751
|
-
await this.store.order.saveDraft();
|
|
752
|
-
}
|
|
753
345
|
return tempOrder;
|
|
754
346
|
} catch (error) {
|
|
755
347
|
throw error;
|
|
@@ -768,43 +360,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
768
360
|
throw new Error("scanOrder 解决方案需要 order 模块支持");
|
|
769
361
|
}
|
|
770
362
|
const tempOrder = this.store.order.restoreOrder();
|
|
771
|
-
this.currentSalesDetail = null;
|
|
772
|
-
this.discountConfigCacheKey = null;
|
|
773
|
-
this.hasManualDiscountSelection = false;
|
|
774
|
-
await this.effectsEmit("onTempOrderReplaced", { tempOrder });
|
|
775
|
-
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
776
|
-
this.store.order.persistTempOrder();
|
|
777
|
-
await this.store.order.saveDraft();
|
|
778
|
-
}
|
|
779
|
-
return tempOrder;
|
|
780
|
-
} catch (error) {
|
|
781
|
-
throw error;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
|
|
786
|
-
* 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
|
|
787
|
-
*/
|
|
788
|
-
async clearOrderCartLines() {
|
|
789
|
-
try {
|
|
790
|
-
if (!this.store.order)
|
|
791
|
-
throw new Error("order 模块未初始化");
|
|
792
|
-
const tempOrder = await this.store.order.clearOrderCartLines();
|
|
793
|
-
if (this.currentSalesDetail) {
|
|
794
|
-
this.currentSalesDetail = {
|
|
795
|
-
...this.currentSalesDetail,
|
|
796
|
-
products: [],
|
|
797
|
-
bookings: [],
|
|
798
|
-
rootBooking: null,
|
|
799
|
-
bookingsByProductUid: {},
|
|
800
|
-
discount_list: []
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
await this.effectsEmit("onTempOrderReplaced", { tempOrder });
|
|
804
|
-
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
805
|
-
this.store.order.persistTempOrder();
|
|
806
|
-
await this.store.order.saveDraft();
|
|
807
|
-
}
|
|
808
363
|
return tempOrder;
|
|
809
364
|
} catch (error) {
|
|
810
365
|
throw error;
|
|
@@ -826,289 +381,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
826
381
|
throw error;
|
|
827
382
|
}
|
|
828
383
|
}
|
|
829
|
-
getHistoricalProductDiscountList(products) {
|
|
830
|
-
const historyDiscountList = [];
|
|
831
|
-
products.forEach((item) => {
|
|
832
|
-
if (!this.isPersistedOrderProduct(item))
|
|
833
|
-
return;
|
|
834
|
-
(item.discount_list || []).forEach((discount) => {
|
|
835
|
-
var _a, _b, _c, _d, _e, _f;
|
|
836
|
-
const discountId = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
|
|
837
|
-
if (!discountId || !["good_pass", "discount_card"].includes(discount.type))
|
|
838
|
-
return;
|
|
839
|
-
const quantity = item.quantity || item.num || item.product_quantity || 1;
|
|
840
|
-
const savedAmount = new import_decimal.default(discount.amount || 0).times(quantity).plus(((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0);
|
|
841
|
-
const index = historyDiscountList.findIndex((n) => n.id === discountId);
|
|
842
|
-
if (index !== -1) {
|
|
843
|
-
historyDiscountList[index] = {
|
|
844
|
-
...historyDiscountList[index],
|
|
845
|
-
amount: new import_decimal.default(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
|
|
846
|
-
savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
|
|
847
|
-
};
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
historyDiscountList.push({
|
|
851
|
-
...discount,
|
|
852
|
-
id: discountId,
|
|
853
|
-
tag: discount.tag || discount.type,
|
|
854
|
-
name: discount.name || ((_d = (_c = discount.discount) == null ? void 0 : _c.title) == null ? void 0 : _d.auto),
|
|
855
|
-
format_title: ((_e = discount.discount) == null ? void 0 : _e.title) || discount.format_title,
|
|
856
|
-
isEditMode: true,
|
|
857
|
-
limited_relation_product_data: {},
|
|
858
|
-
savedAmount: savedAmount.toNumber(),
|
|
859
|
-
isAvailable: true,
|
|
860
|
-
isDisabled: true,
|
|
861
|
-
isSelected: true,
|
|
862
|
-
product_id: ((_f = discount.discount) == null ? void 0 : _f.product_id) || discount.product_id
|
|
863
|
-
});
|
|
864
|
-
});
|
|
865
|
-
});
|
|
866
|
-
return historyDiscountList;
|
|
867
|
-
}
|
|
868
|
-
isPersistedOrderProduct(product) {
|
|
869
|
-
const orderDetailId = product.order_detail_id ?? product.orderDetailId;
|
|
870
|
-
if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
|
|
871
|
-
return true;
|
|
872
|
-
}
|
|
873
|
-
const bookingId = product.booking_id ?? product.bookingId;
|
|
874
|
-
return bookingId !== void 0 && bookingId !== null && bookingId !== "";
|
|
875
|
-
}
|
|
876
|
-
mergeHistoricalDiscountList(discountList, products) {
|
|
877
|
-
const historyDiscountList = this.getHistoricalProductDiscountList(products);
|
|
878
|
-
const historyIds = new Set(historyDiscountList.map((discount) => discount.id));
|
|
879
|
-
return [
|
|
880
|
-
...historyDiscountList,
|
|
881
|
-
...(discountList || []).filter((discount) => !historyIds.has(discount.id))
|
|
882
|
-
];
|
|
883
|
-
}
|
|
884
|
-
shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
|
|
885
|
-
if (params.discountAction !== "edit")
|
|
886
|
-
return false;
|
|
887
|
-
if (!params.products.length)
|
|
888
|
-
return false;
|
|
889
|
-
const hasDraftProduct = params.products.some((product) => !this.isPersistedOrderProduct(product));
|
|
890
|
-
if (hasDraftProduct)
|
|
891
|
-
return false;
|
|
892
|
-
const hasSelectedDiscount = params.currentDiscountList.some(
|
|
893
|
-
(discount) => discount.isSelected || discount.isEditMode || discount.isManualSelect
|
|
894
|
-
);
|
|
895
|
-
if (hasSelectedDiscount)
|
|
896
|
-
return false;
|
|
897
|
-
return !params.nextDiscountList.some(
|
|
898
|
-
(discount) => discount.isSelected || discount.isEditMode || discount.isManualSelect
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
|
|
902
|
-
if (!currentDiscountList.length)
|
|
903
|
-
return discountList;
|
|
904
|
-
const currentDiscountMap = new Map(
|
|
905
|
-
currentDiscountList.map((discount) => [discount.id, discount])
|
|
906
|
-
);
|
|
907
|
-
return discountList.map((discount) => {
|
|
908
|
-
const currentDiscount = currentDiscountMap.get(discount.id);
|
|
909
|
-
if (!currentDiscount)
|
|
910
|
-
return discount;
|
|
911
|
-
if (currentDiscount.isManualSelect) {
|
|
912
|
-
return {
|
|
913
|
-
...discount,
|
|
914
|
-
isSelected: false,
|
|
915
|
-
isManualSelect: true
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
if (currentDiscount.isSelected) {
|
|
919
|
-
return {
|
|
920
|
-
...discount,
|
|
921
|
-
isSelected: true,
|
|
922
|
-
isManualSelect: false
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
return discount;
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
async loadDiscountConfig(params) {
|
|
929
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
930
|
-
if (!this.store.order)
|
|
931
|
-
throw new Error("order 模块未初始化");
|
|
932
|
-
const tempOrder = this.store.order.ensureTempOrder();
|
|
933
|
-
const orderStore = this.store.order.store || {};
|
|
934
|
-
const discountModule = orderStore.discount;
|
|
935
|
-
const rulesModule = orderStore.rules;
|
|
936
|
-
const orderId = tempOrder.order_id || ((_b = (_a = this.getOrderIdentity) == null ? void 0 : _a.call(this)) == null ? void 0 : _b.orderId);
|
|
937
|
-
const customerId = Number(
|
|
938
|
-
(params == null ? void 0 : params.customerId) || tempOrder.customer_id || ((_c = tempOrder.customer) == null ? void 0 : _c.id) || ((_e = (_d = tempOrder._extend) == null ? void 0 : _d.customerSnapshot) == null ? void 0 : _e.id) || ((_g = (_f = tempOrder._extend) == null ? void 0 : _f.customerSnapshot) == null ? void 0 : _g.customer_id) || 0
|
|
939
|
-
);
|
|
940
|
-
const currentDiscountList = ((_h = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _h.call(discountModule)) || [];
|
|
941
|
-
const originalDiscountList = ((_i = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _i.call(discountModule)) || [];
|
|
942
|
-
const hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some((discount) => discount.isManualSelect);
|
|
943
|
-
const discountAction = (params == null ? void 0 : params.action) || (orderId ? "edit" : "create");
|
|
944
|
-
const discountConfigCacheKey = [
|
|
945
|
-
customerId,
|
|
946
|
-
discountAction,
|
|
947
|
-
Number(orderId) || 0
|
|
948
|
-
].join(":");
|
|
949
|
-
let preparedDiscountList = [];
|
|
950
|
-
if (customerId && customerId !== 1) {
|
|
951
|
-
if (this.discountConfigCacheKey === discountConfigCacheKey) {
|
|
952
|
-
preparedDiscountList = originalDiscountList;
|
|
953
|
-
} else {
|
|
954
|
-
preparedDiscountList = await this.store.order.loadDiscountConfig({
|
|
955
|
-
customerId,
|
|
956
|
-
action: discountAction,
|
|
957
|
-
orderId: Number(orderId) || void 0,
|
|
958
|
-
apply: false
|
|
959
|
-
});
|
|
960
|
-
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
961
|
-
await ((_j = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _j.call(discountModule, preparedDiscountList));
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
if (hasManualDiscountSelection && currentDiscountList.length) {
|
|
965
|
-
return {
|
|
966
|
-
productList: tempOrder.products || [],
|
|
967
|
-
discountList: currentDiscountList
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
let nextDiscountList = this.mergeHistoricalDiscountList(
|
|
971
|
-
preparedDiscountList || ((_k = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _k.call(discountModule)) || [],
|
|
972
|
-
tempOrder.products || []
|
|
973
|
-
);
|
|
974
|
-
nextDiscountList = this.mergeCurrentDiscountSelectionState(
|
|
975
|
-
nextDiscountList,
|
|
976
|
-
currentDiscountList
|
|
977
|
-
);
|
|
978
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
979
|
-
const shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
|
|
980
|
-
discountAction,
|
|
981
|
-
products: tempOrder.products || [],
|
|
982
|
-
currentDiscountList,
|
|
983
|
-
nextDiscountList
|
|
984
|
-
});
|
|
985
|
-
if (shouldSkipAutoApplyFetchedDiscounts) {
|
|
986
|
-
const summary2 = await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
987
|
-
this.store.order.persistTempOrder();
|
|
988
|
-
await this.effectsEmit("onDiscountApplied", {
|
|
989
|
-
productList: tempOrder.products || [],
|
|
990
|
-
discountList: nextDiscountList,
|
|
991
|
-
selectedDiscountList: tempOrder.discount_list || [],
|
|
992
|
-
tempOrder
|
|
993
|
-
});
|
|
994
|
-
return {
|
|
995
|
-
productList: tempOrder.products || [],
|
|
996
|
-
discountList: nextDiscountList
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
if (rulesModule) {
|
|
1000
|
-
const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
1001
|
-
const result = rulesModule.calcDiscount({
|
|
1002
|
-
productList: tempOrder.products,
|
|
1003
|
-
discountList: nextDiscountList,
|
|
1004
|
-
holders,
|
|
1005
|
-
isFormSubject: !!((_m = tempOrder.holder) == null ? void 0 : _m.type) && tempOrder.holder.type === "form",
|
|
1006
|
-
orderTotalAmount: Number(((_n = orderStore.summary) == null ? void 0 : _n.total_amount) || 0)
|
|
1007
|
-
}) || { productList: tempOrder.products, discountList: nextDiscountList };
|
|
1008
|
-
if (result.productList) {
|
|
1009
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1010
|
-
tempOrder.products,
|
|
1011
|
-
result.productList
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
for (const product of tempOrder.products || []) {
|
|
1015
|
-
const productUid = (_o = product.metadata) == null ? void 0 : _o.unique_identification_number;
|
|
1016
|
-
const runtimeOrigin = productUid ? (_r = (_q = (_p = tempOrder._extend) == null ? void 0 : _p.productsByUid) == null ? void 0 : _q[productUid]) == null ? void 0 : _r.origin : void 0;
|
|
1017
|
-
if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
|
|
1018
|
-
continue;
|
|
1019
|
-
const totalPerUnitDiscount = (product.discount_list || []).reduce(
|
|
1020
|
-
(sum, pd) => sum + Number(pd.amount || 0),
|
|
1021
|
-
0
|
|
1022
|
-
);
|
|
1023
|
-
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
|
|
1024
|
-
const sourcePrice = ((_s = product.metadata) == null ? void 0 : _s.source_product_price) ?? (((_t = product.metadata) == null ? void 0 : _t.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
|
|
1025
|
-
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1026
|
-
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1027
|
-
if (product.metadata) {
|
|
1028
|
-
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
1029
|
-
product.metadata.price_schema_version = 2;
|
|
1030
|
-
}
|
|
1031
|
-
product.selling_price = (0, import_utils.composeLinePrice)({
|
|
1032
|
-
mainPrice: newMainSellingPrice,
|
|
1033
|
-
bundle: product.product_bundle
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
if (result.discountList) {
|
|
1037
|
-
nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1038
|
-
result.discountList,
|
|
1039
|
-
tempOrder.products || []
|
|
1040
|
-
);
|
|
1041
|
-
import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1042
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1043
|
-
tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
const summary = await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1047
|
-
this.store.order.persistTempOrder();
|
|
1048
|
-
await this.effectsEmit("onDiscountApplied", {
|
|
1049
|
-
productList: tempOrder.products || [],
|
|
1050
|
-
discountList: nextDiscountList,
|
|
1051
|
-
selectedDiscountList: tempOrder.discount_list || [],
|
|
1052
|
-
tempOrder
|
|
1053
|
-
});
|
|
1054
|
-
return {
|
|
1055
|
-
productList: tempOrder.products || [],
|
|
1056
|
-
discountList: nextDiscountList
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
async bestDiscount(cb) {
|
|
1060
|
-
var _a, _b, _c, _d, _e;
|
|
1061
|
-
if (!this.store.order)
|
|
1062
|
-
throw new Error("order 模块未初始化");
|
|
1063
|
-
const tempOrder = this.store.order.ensureTempOrder();
|
|
1064
|
-
const orderStore = this.store.order.store || {};
|
|
1065
|
-
const discountModule = orderStore.discount;
|
|
1066
|
-
const rulesModule = orderStore.rules;
|
|
1067
|
-
const originalDiscountList = ((_a = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _a.call(discountModule)) || this.getDiscountList();
|
|
1068
|
-
const currentDiscountList = ((_b = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
|
|
1069
|
-
let nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1070
|
-
originalDiscountList || [],
|
|
1071
|
-
tempOrder.products || []
|
|
1072
|
-
);
|
|
1073
|
-
let result = {
|
|
1074
|
-
productList: tempOrder.products || [],
|
|
1075
|
-
discountList: nextDiscountList
|
|
1076
|
-
};
|
|
1077
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1078
|
-
if (rulesModule) {
|
|
1079
|
-
const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
1080
|
-
result = rulesModule.calcDiscount({
|
|
1081
|
-
productList: tempOrder.products,
|
|
1082
|
-
discountList: nextDiscountList,
|
|
1083
|
-
holders,
|
|
1084
|
-
isFormSubject: !!((_d = tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form",
|
|
1085
|
-
orderTotalAmount: Number(((_e = orderStore.summary) == null ? void 0 : _e.total_amount) || 0)
|
|
1086
|
-
}) || result;
|
|
1087
|
-
if (result.productList) {
|
|
1088
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1089
|
-
tempOrder.products,
|
|
1090
|
-
result.productList
|
|
1091
|
-
);
|
|
1092
|
-
}
|
|
1093
|
-
if (result.discountList) {
|
|
1094
|
-
nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1095
|
-
result.discountList,
|
|
1096
|
-
tempOrder.products || []
|
|
1097
|
-
);
|
|
1098
|
-
import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1099
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1100
|
-
tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
|
|
1101
|
-
result = {
|
|
1102
|
-
productList: tempOrder.products,
|
|
1103
|
-
discountList: nextDiscountList
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1108
|
-
this.store.order.persistTempOrder();
|
|
1109
|
-
cb == null ? void 0 : cb(result);
|
|
1110
|
-
return result;
|
|
1111
|
-
}
|
|
1112
384
|
getDiscountList() {
|
|
1113
385
|
if (!this.store.order)
|
|
1114
386
|
return [];
|
|
@@ -1134,7 +406,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1134
406
|
}
|
|
1135
407
|
// TODO 需要优化,这段逻辑太长了,里面应该有些历史遗留问题
|
|
1136
408
|
async setDiscountSelected(params) {
|
|
1137
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
409
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1138
410
|
try {
|
|
1139
411
|
if (!this.store.order)
|
|
1140
412
|
throw new Error("order 模块未初始化");
|
|
@@ -1146,7 +418,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1146
418
|
isManualSelect: !params.isSelected
|
|
1147
419
|
} : d
|
|
1148
420
|
);
|
|
1149
|
-
this.hasManualDiscountSelection = true;
|
|
1150
421
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1151
422
|
const orderStore = this.store.order.store || {};
|
|
1152
423
|
const discountModule = orderStore.discount;
|
|
@@ -1168,10 +439,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1168
439
|
}
|
|
1169
440
|
) || { productList: tempOrder.products, discountList: updated };
|
|
1170
441
|
if (result == null ? void 0 : result.productList) {
|
|
1171
|
-
tempOrder.products =
|
|
1172
|
-
tempOrder.products,
|
|
1173
|
-
result.productList
|
|
1174
|
-
);
|
|
442
|
+
tempOrder.products = result.productList;
|
|
1175
443
|
}
|
|
1176
444
|
if (result == null ? void 0 : result.discountList) {
|
|
1177
445
|
nextDiscountList = result.discountList;
|
|
@@ -1182,7 +450,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1182
450
|
for (const d of nextDiscountList) {
|
|
1183
451
|
if (d.isSelected && !beforeSelectedIds.has(d.id)) {
|
|
1184
452
|
d.isSelected = false;
|
|
1185
|
-
d.isManualSelect = true;
|
|
1186
453
|
}
|
|
1187
454
|
}
|
|
1188
455
|
}
|
|
@@ -1194,7 +461,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1194
461
|
for (const product of tempOrder.products) {
|
|
1195
462
|
const productUid = (_c = product.metadata) == null ? void 0 : _c.unique_identification_number;
|
|
1196
463
|
const runtimeOrigin = productUid ? (_f = (_e = (_d = tempOrder._extend) == null ? void 0 : _d.productsByUid) == null ? void 0 : _e[productUid]) == null ? void 0 : _f.origin : void 0;
|
|
1197
|
-
if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) ||
|
|
464
|
+
if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || ((_g = product.metadata) == null ? void 0 : _g.is_manual_discount))
|
|
1198
465
|
continue;
|
|
1199
466
|
product.discount_list = (product.discount_list || []).filter((pd) => {
|
|
1200
467
|
var _a2;
|
|
@@ -1205,8 +472,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1205
472
|
(sum, pd) => sum + (pd.amount || 0),
|
|
1206
473
|
0
|
|
1207
474
|
);
|
|
1208
|
-
const optionSum = (0, import_utils.sumOptionUnitPrice)(
|
|
1209
|
-
const sourcePrice = ((
|
|
475
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
|
|
476
|
+
const sourcePrice = ((_h = product.metadata) == null ? void 0 : _h.source_product_price) ?? (((_i = product.metadata) == null ? void 0 : _i.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");
|
|
1210
477
|
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1211
478
|
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1212
479
|
if (product.metadata) {
|
|
@@ -1223,43 +490,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1223
490
|
tempOrder.discount_list = (nextDiscountList || []).filter((d) => d.isSelected);
|
|
1224
491
|
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1225
492
|
this.store.order.persistTempOrder();
|
|
1226
|
-
this.effectsEmit("onDiscountApplied", {
|
|
1227
|
-
productList: tempOrder.products,
|
|
1228
|
-
discountList: nextDiscountList,
|
|
1229
|
-
selectedDiscountList: tempOrder.discount_list,
|
|
1230
|
-
tempOrder
|
|
1231
|
-
});
|
|
1232
|
-
} catch (error) {
|
|
1233
|
-
throw error;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
async applyDiscountCalculationResult(result) {
|
|
1237
|
-
try {
|
|
1238
|
-
if (!this.store.order)
|
|
1239
|
-
throw new Error("order 模块未初始化");
|
|
1240
|
-
if (!result)
|
|
1241
|
-
return;
|
|
1242
|
-
const tempOrder = this.store.order.ensureTempOrder();
|
|
1243
|
-
const orderStore = this.store.order.store || {};
|
|
1244
|
-
const discountModule = orderStore.discount;
|
|
1245
|
-
if (result.productList) {
|
|
1246
|
-
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1247
|
-
tempOrder.products,
|
|
1248
|
-
result.productList
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
if (result.discountList) {
|
|
1252
|
-
import_Order.OrderModule.populateSavedAmounts(
|
|
1253
|
-
tempOrder.products,
|
|
1254
|
-
result.discountList
|
|
1255
|
-
);
|
|
1256
|
-
await (discountModule == null ? void 0 : discountModule.setDiscountList(result.discountList));
|
|
1257
|
-
tempOrder.discount_list = result.discountList.filter(
|
|
1258
|
-
(discount) => discount.isSelected
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1262
|
-
this.store.order.persistTempOrder();
|
|
1263
493
|
} catch (error) {
|
|
1264
494
|
throw error;
|
|
1265
495
|
}
|
|
@@ -1278,142 +508,30 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1278
508
|
if (!this.store.order) {
|
|
1279
509
|
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1280
510
|
}
|
|
1281
|
-
|
|
511
|
+
this.store.order.persistTempOrder();
|
|
1282
512
|
const submitParams = {
|
|
1283
513
|
cacheId: this.cacheId,
|
|
1284
514
|
platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
|
|
1285
|
-
businessCode: (
|
|
1286
|
-
channel: this.
|
|
515
|
+
businessCode: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
|
|
516
|
+
channel: (_c = this.otherParams) == null ? void 0 : _c.channel,
|
|
1287
517
|
type: (_d = this.otherParams) == null ? void 0 : _d.type,
|
|
1288
|
-
request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
|
|
1289
518
|
...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
|
|
1290
|
-
...
|
|
519
|
+
...(params == null ? void 0 : params.paymentStatus) !== void 0 ? { paymentStatus: params.paymentStatus } : {},
|
|
1291
520
|
...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
|
|
1292
521
|
...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
1293
522
|
};
|
|
1294
523
|
return this.store.order.submitTempOrder(submitParams);
|
|
1295
524
|
}
|
|
1296
|
-
async submitTempOrderAsync(params) {
|
|
1297
|
-
var _a, _b, _c, _d;
|
|
1298
|
-
if (!this.store.order) {
|
|
1299
|
-
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1300
|
-
}
|
|
1301
|
-
const inferredPaymentStatus = this.getSubmitPaymentStatus(params == null ? void 0 : params.paymentStatus);
|
|
1302
|
-
const submitParams = {
|
|
1303
|
-
cacheId: this.cacheId,
|
|
1304
|
-
platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
|
|
1305
|
-
businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1306
|
-
channel: this.getSubmitOrderSalesChannel(),
|
|
1307
|
-
type: (_d = this.otherParams) == null ? void 0 : _d.type,
|
|
1308
|
-
...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
|
|
1309
|
-
...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
|
|
1310
|
-
...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
|
|
1311
|
-
...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
1312
|
-
};
|
|
1313
|
-
return this.store.order.submitTempOrderAsync(submitParams);
|
|
1314
|
-
}
|
|
1315
|
-
async printLocalOrderReceipt(lookup) {
|
|
1316
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1317
|
-
if (!this.store.order) {
|
|
1318
|
-
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1319
|
-
}
|
|
1320
|
-
const hasLookup = lookup !== void 0 && lookup !== null && lookup !== "";
|
|
1321
|
-
const lookupPayload = typeof lookup === "number" ? { order_id: lookup } : { external_sale_number: lookup };
|
|
1322
|
-
const context = {
|
|
1323
|
-
platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
|
|
1324
|
-
businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1325
|
-
channel: this.getSubmitOrderSalesChannel(),
|
|
1326
|
-
type: (_d = this.otherParams) == null ? void 0 : _d.type
|
|
1327
|
-
};
|
|
1328
|
-
const payload = hasLookup ? {
|
|
1329
|
-
...lookupPayload,
|
|
1330
|
-
lookup_order_from_db: 1,
|
|
1331
|
-
small_ticket_data_flag: 1,
|
|
1332
|
-
platform: context.platform,
|
|
1333
|
-
business_code: context.businessCode,
|
|
1334
|
-
order_sales_channel: context.channel,
|
|
1335
|
-
type: context.type
|
|
1336
|
-
} : this.store.order.buildCurrentSubmitPayloadForLocalPrint({
|
|
1337
|
-
cacheId: this.cacheId,
|
|
1338
|
-
platform: context.platform,
|
|
1339
|
-
businessCode: context.businessCode,
|
|
1340
|
-
channel: context.channel,
|
|
1341
|
-
type: context.type
|
|
1342
|
-
});
|
|
1343
|
-
const response = await this.request.post("/local/print-order", payload, {
|
|
1344
|
-
osServer: true,
|
|
1345
|
-
customToast: () => {
|
|
1346
|
-
}
|
|
1347
|
-
});
|
|
1348
|
-
if (!hasLookup) {
|
|
1349
|
-
await ((_g = (_f = this.store.order).applyLocalPrintOrderNumbers) == null ? void 0 : _g.call(_f, (_e = response == null ? void 0 : response.data) == null ? void 0 : _e.order));
|
|
1350
|
-
}
|
|
1351
|
-
return response;
|
|
1352
|
-
}
|
|
1353
|
-
getSubmitPaymentStatus(paymentStatus) {
|
|
1354
|
-
var _a, _b;
|
|
1355
|
-
if (paymentStatus !== void 0)
|
|
1356
|
-
return paymentStatus;
|
|
1357
|
-
const amountSnapshot = (_b = (_a = this.store.order) == null ? void 0 : _a.getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
|
|
1358
|
-
if (!amountSnapshot)
|
|
1359
|
-
return void 0;
|
|
1360
|
-
try {
|
|
1361
|
-
return new import_decimal.default(amountSnapshot.amountGap || 0).lte(0) ? "paid" : void 0;
|
|
1362
|
-
} catch {
|
|
1363
|
-
return void 0;
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
525
|
async syncPaymentsToOrder(params) {
|
|
1367
|
-
var _a, _b;
|
|
1368
526
|
if (!this.store.order)
|
|
1369
527
|
throw new Error("order 模块未初始化");
|
|
1370
|
-
|
|
1371
|
-
const channel = params.channel ?? this.getSubmitOrderSalesChannel();
|
|
1372
|
-
const syncParams = {
|
|
1373
|
-
...params,
|
|
1374
|
-
...businessCode !== void 0 ? { businessCode } : {},
|
|
1375
|
-
...channel !== void 0 ? { channel } : {}
|
|
1376
|
-
};
|
|
1377
|
-
const syncState = this.store.order.getOrderSyncState();
|
|
1378
|
-
if (params.submitWhenPaid && syncState === "submitting") {
|
|
1379
|
-
return this.store.order.syncPaymentsToOrder(syncParams);
|
|
1380
|
-
}
|
|
1381
|
-
const payments = params.payments || [];
|
|
1382
|
-
await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncStart, {
|
|
1383
|
-
payments,
|
|
1384
|
-
params: syncParams,
|
|
1385
|
-
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
1386
|
-
orderSnapshot: this.store.order.getOrderSnapshot()
|
|
1387
|
-
});
|
|
1388
|
-
try {
|
|
1389
|
-
const syncResult = await this.store.order.syncPaymentsToOrder(syncParams);
|
|
1390
|
-
await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
|
|
1391
|
-
ok: true,
|
|
1392
|
-
syncResult,
|
|
1393
|
-
payments: this.store.order.getOrderPayments(),
|
|
1394
|
-
params: syncParams,
|
|
1395
|
-
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
1396
|
-
orderSnapshot: this.store.order.getOrderSnapshot()
|
|
1397
|
-
});
|
|
1398
|
-
return syncResult;
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
|
|
1401
|
-
ok: false,
|
|
1402
|
-
error,
|
|
1403
|
-
payments: this.store.order.getOrderPayments(),
|
|
1404
|
-
params: syncParams,
|
|
1405
|
-
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
1406
|
-
orderSnapshot: this.store.order.getOrderSnapshot()
|
|
1407
|
-
});
|
|
1408
|
-
throw error;
|
|
1409
|
-
}
|
|
528
|
+
return this.store.order.syncPaymentsToOrder(params);
|
|
1410
529
|
}
|
|
1411
530
|
/** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
|
|
1412
531
|
getOrderPayments() {
|
|
1413
532
|
if (!this.store.order)
|
|
1414
533
|
return [];
|
|
1415
|
-
|
|
1416
|
-
return this.hydrateOrderPaymentNames(payments);
|
|
534
|
+
return this.store.order.getOrderPayments();
|
|
1417
535
|
}
|
|
1418
536
|
/** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
|
|
1419
537
|
setOrderPayments(payments) {
|
|
@@ -1423,51 +541,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1423
541
|
}
|
|
1424
542
|
/** 追加单个支付项到当前订单。 */
|
|
1425
543
|
addOrderPayment(payment) {
|
|
1426
|
-
var _a;
|
|
1427
544
|
if (!this.store.order)
|
|
1428
545
|
throw new Error("order 模块未初始化");
|
|
1429
|
-
|
|
1430
|
-
const paymentAmount = new import_decimal.default(paymentRecord.amount || 0);
|
|
1431
|
-
if (paymentAmount.isZero()) {
|
|
1432
|
-
this.logWarning("addOrderPayment: 支付金额为 0,跳过添加支付项", {
|
|
1433
|
-
payment: paymentRecord
|
|
1434
|
-
});
|
|
1435
|
-
return this.store.order.getOrderPayments();
|
|
1436
|
-
}
|
|
1437
|
-
const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
|
|
1438
|
-
const shopWalletPassId = (_a = this.otherParams) == null ? void 0 : _a.shop_wallet_pass_id;
|
|
1439
|
-
if (shopWalletPassId !== void 0 && shopWalletPassId !== null) {
|
|
1440
|
-
metadata.shop_wallet_pass_id = shopWalletPassId;
|
|
1441
|
-
}
|
|
1442
|
-
if (!metadata.unique_payment_number) {
|
|
1443
|
-
metadata.unique_payment_number = (0, import_utils.createUuidV4)();
|
|
1444
|
-
}
|
|
1445
|
-
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
1446
|
-
const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
|
|
1447
|
-
const createdAt = paymentRecord.created_at ?? paymentTimestamp;
|
|
1448
|
-
const payments = this.store.order.addOrderPayment({
|
|
1449
|
-
...paymentRecord,
|
|
1450
|
-
metadata,
|
|
1451
|
-
payment_time: paymentTime,
|
|
1452
|
-
created_at: createdAt
|
|
1453
|
-
});
|
|
1454
|
-
const amountSnapshot = this.store.order.getOrderAmountSnapshot();
|
|
1455
|
-
const syncState = this.store.order.getOrderSyncState();
|
|
1456
|
-
if (amountSnapshot && syncState !== "submitting") {
|
|
1457
|
-
const paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? "paid" : "partially_paid";
|
|
1458
|
-
void this.syncPaymentsToOrder({
|
|
1459
|
-
payments,
|
|
1460
|
-
paymentStatus,
|
|
1461
|
-
submitWhenPaid: true,
|
|
1462
|
-
smallTicketDataFlag: 1
|
|
1463
|
-
}).catch((error) => {
|
|
1464
|
-
this.logError("auto sync payments failed", {
|
|
1465
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1466
|
-
});
|
|
1467
|
-
});
|
|
1468
|
-
} else {
|
|
1469
|
-
}
|
|
1470
|
-
return payments;
|
|
546
|
+
return this.store.order.addOrderPayment(payment);
|
|
1471
547
|
}
|
|
1472
548
|
/** 更新当前订单中的指定支付项。 */
|
|
1473
549
|
updateOrderPayment(paymentIdentity, updates) {
|
|
@@ -1488,12 +564,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1488
564
|
return this.store.order.updateVoucherOrderPayments(payments);
|
|
1489
565
|
}
|
|
1490
566
|
getWalletProductList() {
|
|
1491
|
-
var _a, _b
|
|
567
|
+
var _a, _b;
|
|
1492
568
|
const tempOrder = (_a = this.store.order) == null ? void 0 : _a.getTempOrder();
|
|
1493
569
|
if (!((_b = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _b.length))
|
|
1494
570
|
return [];
|
|
1495
|
-
|
|
1496
|
-
const walletProducts = products.map((product) => {
|
|
571
|
+
return tempOrder.products.map((product) => {
|
|
1497
572
|
const metadata = product.metadata || {};
|
|
1498
573
|
return {
|
|
1499
574
|
product_id: product.product_id,
|
|
@@ -1503,7 +578,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1503
578
|
is_charge_tax: product.is_charge_tax ?? 0,
|
|
1504
579
|
tax_fee: product.tax_fee,
|
|
1505
580
|
selling_price: Number(product.selling_price || 0),
|
|
1506
|
-
discount_list: product.discount_list || [],
|
|
1507
581
|
holder_id: product.holder_id ?? metadata.holder_id,
|
|
1508
582
|
original_price: product.original_price,
|
|
1509
583
|
main_product_original_price: metadata.main_product_original_price ?? product.original_price,
|
|
@@ -1517,10 +591,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1517
591
|
const bundleMetadata = bundle.metadata || {};
|
|
1518
592
|
return {
|
|
1519
593
|
is_price_include_tax: tempOrder.is_price_include_tax,
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
bundle_product_id: bundle.bundle_product_id ?? bundle._bundle_product_id,
|
|
1523
|
-
bundle_group_id: bundle.bundle_group_id ?? bundle.group_id,
|
|
594
|
+
bundle_id: bundle.bundle_id,
|
|
595
|
+
bundle_product_id: bundle.bundle_product_id,
|
|
1524
596
|
bundle_variant_id: bundle.bundle_variant_id,
|
|
1525
597
|
price_type: bundle.price_type,
|
|
1526
598
|
price_type_ext: bundle.price_type_ext,
|
|
@@ -1537,7 +609,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1537
609
|
})
|
|
1538
610
|
};
|
|
1539
611
|
});
|
|
1540
|
-
return walletProducts;
|
|
1541
612
|
}
|
|
1542
613
|
async initWalletData(params) {
|
|
1543
614
|
if (!this.store.order)
|
|
@@ -1601,25 +672,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1601
672
|
}
|
|
1602
673
|
/** 获取可用支付方式列表,供 PaymentModal 渲染支付选项。 */
|
|
1603
674
|
async getPaymentMethodsAsync() {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
filterPaymentMethods: true
|
|
1607
|
-
}, {
|
|
1608
|
-
osServer: true
|
|
1609
|
-
});
|
|
1610
|
-
const paymentMethods = (response == null ? void 0 : response.data) || [];
|
|
1611
|
-
this.paymentMethodsCache = Array.isArray(paymentMethods) ? [...paymentMethods] : [];
|
|
1612
|
-
return this.getPaymentMethods();
|
|
1613
|
-
} catch (error) {
|
|
1614
|
-
this.logWarning("getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表", {
|
|
1615
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1616
|
-
});
|
|
1617
|
-
return this.getPaymentMethods();
|
|
675
|
+
if (this.store.payment) {
|
|
676
|
+
return this.store.payment.getPayMethodListAsync();
|
|
1618
677
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
getPaymentMethods() {
|
|
1622
|
-
return [...this.paymentMethodsCache];
|
|
678
|
+
const response = await this.request.get("/pay/custom-payment/all");
|
|
679
|
+
return (response == null ? void 0 : response.data) || [];
|
|
1623
680
|
}
|
|
1624
681
|
/** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
|
|
1625
682
|
roundAmount(params) {
|
|
@@ -1674,24 +731,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1674
731
|
transformBaseProductToOrderProduct(params) {
|
|
1675
732
|
return (0, import_transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
|
|
1676
733
|
}
|
|
1677
|
-
async calculateProductBookingPrice(params) {
|
|
1678
|
-
const quotation = this.store.quotation;
|
|
1679
|
-
const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
|
|
1680
|
-
const authoritativeProduct = await this.loadProductForPriceQuery(params, customerId);
|
|
1681
|
-
const product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
|
|
1682
|
-
await this.loadQuotationForPriceQuery({
|
|
1683
|
-
quotation,
|
|
1684
|
-
customer_id: customerId,
|
|
1685
|
-
channel: params.channel
|
|
1686
|
-
});
|
|
1687
|
-
return (0, import_quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
1688
|
-
...params,
|
|
1689
|
-
product,
|
|
1690
|
-
fallback_price: authoritativeProduct ? void 0 : params.fallback_price,
|
|
1691
|
-
customer_id: customerId,
|
|
1692
|
-
quotation
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
734
|
async addProductToOrder(product, booking) {
|
|
1696
735
|
try {
|
|
1697
736
|
if (!this.store.order)
|
|
@@ -1702,35 +741,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1702
741
|
throw error;
|
|
1703
742
|
}
|
|
1704
743
|
}
|
|
1705
|
-
async
|
|
1706
|
-
try {
|
|
1707
|
-
if (!this.store.order)
|
|
1708
|
-
throw new Error("order 模块未初始化");
|
|
1709
|
-
const products = await this.store.order.updateOrderProduct(params);
|
|
1710
|
-
return products;
|
|
1711
|
-
} catch (error) {
|
|
1712
|
-
throw error;
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
async updateOrderProductQuantity(params) {
|
|
744
|
+
async updateProductInOrder(params) {
|
|
1716
745
|
try {
|
|
1717
746
|
if (!this.store.order)
|
|
1718
747
|
throw new Error("order 模块未初始化");
|
|
1719
|
-
const products = await this.store.order.
|
|
748
|
+
const products = await this.store.order.updateProductInOrder(params);
|
|
1720
749
|
return products;
|
|
1721
750
|
} catch (error) {
|
|
1722
751
|
throw error;
|
|
1723
752
|
}
|
|
1724
753
|
}
|
|
1725
|
-
updateOrderBooking(params) {
|
|
1726
|
-
try {
|
|
1727
|
-
if (!this.store.order)
|
|
1728
|
-
throw new Error("order 模块未初始化");
|
|
1729
|
-
return this.store.order.updateOrderBooking(params);
|
|
1730
|
-
} catch (error) {
|
|
1731
|
-
throw error;
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
754
|
/**
|
|
1735
755
|
* 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
|
|
1736
756
|
* 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
|
|
@@ -1745,87 +765,27 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1745
765
|
if (identity.unique_identification_number !== void 0) {
|
|
1746
766
|
params.unique_identification_number = identity.unique_identification_number;
|
|
1747
767
|
}
|
|
1748
|
-
if (identity.
|
|
1749
|
-
params.
|
|
768
|
+
if (identity.product_option_item !== void 0) {
|
|
769
|
+
params.product_option_item = identity.product_option_item;
|
|
1750
770
|
}
|
|
1751
771
|
if (identity.product_bundle !== void 0)
|
|
1752
772
|
params.product_bundle = identity.product_bundle;
|
|
1753
|
-
const products = await this.
|
|
773
|
+
const products = await this.updateProductInOrder(params);
|
|
1754
774
|
return products;
|
|
1755
775
|
} catch (error) {
|
|
1756
776
|
throw error;
|
|
1757
777
|
}
|
|
1758
778
|
}
|
|
1759
|
-
|
|
1760
|
-
* 批量删除购物车行,末尾仅一次促销重算。
|
|
1761
|
-
*
|
|
1762
|
-
* @example
|
|
1763
|
-
* await baseSales.removeProductsFromOrder([identityA, identityB]);
|
|
1764
|
-
*/
|
|
1765
|
-
async removeProductsFromOrder(identities) {
|
|
779
|
+
async removeProductFromOrder(identity) {
|
|
1766
780
|
try {
|
|
1767
781
|
if (!this.store.order)
|
|
1768
782
|
throw new Error("order 模块未初始化");
|
|
1769
|
-
|
|
783
|
+
const products = await this.store.order.removeProductFromOrder(identity);
|
|
784
|
+
return products;
|
|
1770
785
|
} catch (error) {
|
|
1771
786
|
throw error;
|
|
1772
787
|
}
|
|
1773
788
|
}
|
|
1774
|
-
async removeProductFromOrder(identity) {
|
|
1775
|
-
return this.removeProductsFromOrder([identity]);
|
|
1776
|
-
}
|
|
1777
|
-
// ─── 促销/赠品 透传(迁移自 booking usePromotion) ────────────────
|
|
1778
|
-
/**
|
|
1779
|
-
* 注入促销评估器到底层 OrderModule。
|
|
1780
|
-
*
|
|
1781
|
-
* @example
|
|
1782
|
-
* solution.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
|
|
1783
|
-
*/
|
|
1784
|
-
setPromotionEvaluator(evaluator) {
|
|
1785
|
-
if (!this.store.order)
|
|
1786
|
-
throw new Error("order 模块未初始化");
|
|
1787
|
-
this.store.order.setPromotionEvaluator(evaluator);
|
|
1788
|
-
}
|
|
1789
|
-
/**
|
|
1790
|
-
* 注入赠品选择 resolver。UI 层(SalesSdk)通过 bridge 提供。
|
|
1791
|
-
*
|
|
1792
|
-
* @example
|
|
1793
|
-
* solution.setGiftSelectResolver(async (ctx) => bridge.request(ctx));
|
|
1794
|
-
*/
|
|
1795
|
-
setGiftSelectResolver(resolver) {
|
|
1796
|
-
if (!this.store.order)
|
|
1797
|
-
throw new Error("order 模块未初始化");
|
|
1798
|
-
this.store.order.setGiftSelectResolver(resolver);
|
|
1799
|
-
}
|
|
1800
|
-
/**
|
|
1801
|
-
* 为商品目录追加促销标签,供 SalesSdkProductProvider 等商品列表入口复用。
|
|
1802
|
-
*
|
|
1803
|
-
* @example
|
|
1804
|
-
* const products = solution.appendPromotionTags(catalogProducts);
|
|
1805
|
-
*/
|
|
1806
|
-
appendPromotionTags(products) {
|
|
1807
|
-
if (!this.store.order)
|
|
1808
|
-
throw new Error("order 模块未初始化");
|
|
1809
|
-
return this.store.order.appendPromotionTags(products);
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* 主动触发一次促销应用(一般写路径会自动触发,少数场景如客户切换后可手动调)。
|
|
1813
|
-
*/
|
|
1814
|
-
async applyPromotion() {
|
|
1815
|
-
if (!this.store.order)
|
|
1816
|
-
throw new Error("order 模块未初始化");
|
|
1817
|
-
await this.store.order.applyPromotion();
|
|
1818
|
-
}
|
|
1819
|
-
/** 最近一次促销计算输出的未满足提示。 */
|
|
1820
|
-
getUnfulfilledPromotions() {
|
|
1821
|
-
var _a;
|
|
1822
|
-
return ((_a = this.store.order) == null ? void 0 : _a.getUnfulfilledPromotions()) || [];
|
|
1823
|
-
}
|
|
1824
|
-
/** 最近一次促销计算输出的赠品操作 diff。 */
|
|
1825
|
-
getLastGiftActions() {
|
|
1826
|
-
var _a;
|
|
1827
|
-
return ((_a = this.store.order) == null ? void 0 : _a.getLastGiftActions()) || null;
|
|
1828
|
-
}
|
|
1829
789
|
// 获取商品列表
|
|
1830
790
|
// TODO 需要跟 webpos 内的对齐一下
|
|
1831
791
|
async getProductList() {
|
|
@@ -1847,14 +807,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1847
807
|
return this.otherParams;
|
|
1848
808
|
}
|
|
1849
809
|
async setOtherParams(params, { cover = false } = {}) {
|
|
1850
|
-
var _a;
|
|
1851
810
|
if (cover) {
|
|
1852
|
-
this.otherParams =
|
|
811
|
+
this.otherParams = params;
|
|
1853
812
|
} else {
|
|
1854
813
|
this.otherParams = { ...this.otherParams, ...params };
|
|
1855
814
|
}
|
|
1856
|
-
this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
|
|
1857
|
-
await this.syncOtherParamsToSubModules(params, { cover });
|
|
1858
815
|
}
|
|
1859
816
|
};
|
|
1860
817
|
// Annotate the CommonJS export names for ESM import in node:
|