@pisell/pisellos 2.2.244 → 2.2.246
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 +3 -2
- package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
- package/dist/modules/BookingContext/index.d.ts +48 -0
- package/dist/modules/BookingContext/index.js +566 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +284 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +148 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +218 -0
- package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/dist/modules/BookingContext/utils/flexible.js +56 -0
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
- package/dist/modules/BookingContext/utils/index.d.ts +11 -0
- package/dist/modules/BookingContext/utils/index.js +11 -0
- package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/dist/modules/BookingContext/utils/noResource.js +77 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/dist/modules/BookingContext/utils/productExtend.js +339 -0
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
- package/dist/modules/BookingContext/utils/resources.js +486 -0
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
- package/dist/modules/Cart/utils/cartProduct.js +24 -3
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Customer/index.d.ts +20 -0
- package/dist/modules/Customer/index.js +172 -83
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +1 -1
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +1 -0
- package/dist/modules/OpenData/index.d.ts +8 -0
- package/dist/modules/OpenData/index.js +37 -17
- package/dist/modules/Order/index.d.ts +277 -18
- package/dist/modules/Order/index.js +3581 -779
- package/dist/modules/Order/types.d.ts +286 -31
- package/dist/modules/Order/types.js +38 -0
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
- package/dist/modules/Order/utils.d.ts +147 -5
- package/dist/modules/Order/utils.js +750 -104
- package/dist/modules/Payment/index.d.ts +10 -13
- package/dist/modules/Payment/index.js +467 -837
- package/dist/modules/Payment/types.d.ts +2 -0
- package/dist/modules/Payment/utils.js +2 -1
- package/dist/modules/Payment/walletpass.js +41 -25
- package/dist/modules/ProductList/index.d.ts +16 -12
- package/dist/modules/ProductList/index.js +133 -59
- package/dist/modules/ProductList/types.d.ts +14 -0
- package/dist/modules/Quotation/index.d.ts +0 -1
- package/dist/modules/Quotation/index.js +25 -22
- package/dist/modules/Rules/index.d.ts +4 -0
- package/dist/modules/Rules/index.js +97 -70
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/SalesSummary/index.d.ts +8 -25
- package/dist/modules/SalesSummary/index.js +86 -35
- package/dist/modules/SalesSummary/types.d.ts +4 -1
- package/dist/modules/SalesSummary/utils.d.ts +2 -25
- package/dist/modules/SalesSummary/utils.js +794 -162
- package/dist/modules/Schedule/index.d.ts +7 -0
- package/dist/modules/Schedule/index.js +24 -2
- package/dist/modules/Summary/index.js +4 -3
- package/dist/modules/SurchargeList/index.d.ts +16 -0
- package/dist/modules/SurchargeList/index.js +162 -0
- package/dist/modules/SurchargeList/types.d.ts +11 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +3 -1
- package/dist/plugins/request.d.ts +1 -0
- package/dist/server/index.d.ts +204 -1
- package/dist/server/index.js +3654 -922
- package/dist/server/modules/index.d.ts +2 -0
- package/dist/server/modules/index.js +2 -0
- package/dist/server/modules/order/index.d.ts +120 -3
- package/dist/server/modules/order/index.js +1762 -448
- package/dist/server/modules/order/types.d.ts +32 -3
- package/dist/server/modules/order/types.js +8 -0
- package/dist/server/modules/order/utils/filterBookings.js +26 -3
- package/dist/server/modules/order/utils/filterOrders.js +23 -8
- package/dist/server/modules/payment/index.d.ts +28 -0
- package/dist/server/modules/payment/index.js +305 -0
- package/dist/server/modules/payment/types.d.ts +9 -0
- package/dist/server/modules/payment/types.js +1 -0
- package/dist/server/modules/products/index.d.ts +34 -7
- package/dist/server/modules/products/index.js +631 -317
- package/dist/server/modules/resource/index.d.ts +2 -0
- package/dist/server/modules/resource/index.js +29 -3
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +111 -88
- package/dist/server/test.json +713 -0
- package/dist/server/utils/small-ticket.d.ts +71 -0
- package/dist/server/utils/small-ticket.js +840 -0
- package/dist/solution/BaseSales/index.d.ts +133 -10
- package/dist/solution/BaseSales/index.js +1950 -447
- package/dist/solution/BaseSales/types.d.ts +82 -6
- package/dist/solution/BaseSales/types.js +5 -4
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +1438 -0
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +105 -24
- package/dist/solution/BaseSales/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils.js +62 -21
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +271 -11
- package/dist/solution/BookingTicket/index.js +1777 -242
- package/dist/solution/BookingTicket/types.d.ts +118 -1
- package/dist/solution/BookingTicket/types.js +41 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +70 -0
- package/dist/solution/BookingTicket/utils/cartView.d.ts +9 -1
- package/dist/solution/BookingTicket/utils/cartView.js +94 -7
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +10 -9
- package/dist/solution/RegisterAndLogin/config.js +2 -10
- package/dist/solution/ScanOrder/index.d.ts +9 -3
- package/dist/solution/ScanOrder/index.js +241 -134
- package/dist/solution/ScanOrder/types.d.ts +9 -5
- package/dist/solution/ScanOrder/types.js +2 -3
- package/dist/solution/ScanOrder/utils.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +84 -22
- package/dist/solution/VenueBooking/index.d.ts +5 -2
- package/dist/solution/VenueBooking/index.js +110 -59
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/dist/types/index.d.ts +10 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +2 -1
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
- package/lib/modules/BookingContext/index.d.ts +48 -0
- package/lib/modules/BookingContext/index.js +368 -0
- package/lib/modules/BookingContext/types.d.ts +102 -0
- package/lib/modules/BookingContext/types.js +34 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +276 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +154 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +201 -0
- package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/lib/modules/BookingContext/utils/flexible.js +80 -0
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
- package/lib/modules/BookingContext/utils/index.d.ts +11 -0
- package/lib/modules/BookingContext/utils/index.js +43 -0
- package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/lib/modules/BookingContext/utils/noResource.js +90 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/lib/modules/BookingContext/utils/productExtend.js +283 -0
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
- package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
- package/lib/modules/BookingContext/utils/resources.js +377 -0
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
- package/lib/modules/Cart/utils/cartProduct.js +20 -3
- package/lib/modules/Cart/utils/changePrice.js +12 -20
- package/lib/modules/Customer/index.d.ts +20 -0
- package/lib/modules/Customer/index.js +64 -11
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +1 -1
- package/lib/modules/Discount/index.js +9 -1
- package/lib/modules/Discount/types.d.ts +1 -0
- package/lib/modules/OpenData/index.d.ts +8 -0
- package/lib/modules/OpenData/index.js +19 -5
- package/lib/modules/Order/index.d.ts +277 -18
- package/lib/modules/Order/index.js +2317 -337
- package/lib/modules/Order/types.d.ts +286 -31
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
- package/lib/modules/Order/utils.d.ts +147 -5
- package/lib/modules/Order/utils.js +615 -46
- package/lib/modules/Payment/index.d.ts +10 -13
- package/lib/modules/Payment/index.js +18 -150
- package/lib/modules/Payment/types.d.ts +2 -0
- package/lib/modules/Payment/utils.js +2 -1
- package/lib/modules/Payment/walletpass.js +16 -3
- package/lib/modules/ProductList/index.d.ts +16 -12
- package/lib/modules/ProductList/index.js +41 -4
- package/lib/modules/ProductList/types.d.ts +14 -0
- package/lib/modules/Quotation/index.d.ts +0 -1
- package/lib/modules/Quotation/index.js +19 -16
- package/lib/modules/Rules/index.d.ts +4 -0
- package/lib/modules/Rules/index.js +137 -120
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/SalesSummary/index.d.ts +8 -25
- package/lib/modules/SalesSummary/index.js +30 -4
- package/lib/modules/SalesSummary/types.d.ts +4 -1
- package/lib/modules/SalesSummary/utils.d.ts +2 -25
- package/lib/modules/SalesSummary/utils.js +645 -91
- package/lib/modules/Schedule/index.d.ts +7 -0
- package/lib/modules/Schedule/index.js +17 -1
- package/lib/modules/Summary/index.js +5 -4
- package/lib/modules/SurchargeList/index.d.ts +16 -0
- package/lib/modules/SurchargeList/index.js +89 -0
- package/lib/modules/SurchargeList/types.d.ts +11 -0
- package/lib/modules/SurchargeList/types.js +17 -0
- package/lib/modules/index.d.ts +2 -0
- package/lib/modules/index.js +5 -1
- package/lib/plugins/request.d.ts +1 -0
- package/lib/server/index.d.ts +204 -1
- package/lib/server/index.js +1891 -59
- package/lib/server/modules/index.d.ts +2 -0
- package/lib/server/modules/index.js +3 -0
- package/lib/server/modules/order/index.d.ts +120 -3
- package/lib/server/modules/order/index.js +887 -94
- package/lib/server/modules/order/types.d.ts +32 -3
- package/lib/server/modules/order/utils/filterBookings.js +24 -5
- package/lib/server/modules/order/utils/filterOrders.js +15 -6
- package/lib/server/modules/payment/index.d.ts +28 -0
- package/lib/server/modules/payment/index.js +192 -0
- package/lib/server/modules/payment/types.d.ts +9 -0
- package/lib/server/modules/payment/types.js +17 -0
- package/lib/server/modules/products/index.d.ts +34 -7
- package/lib/server/modules/products/index.js +189 -54
- package/lib/server/modules/resource/index.d.ts +2 -0
- package/lib/server/modules/resource/index.js +27 -3
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +47 -40
- package/lib/server/test.json +713 -0
- package/lib/server/utils/small-ticket.d.ts +71 -0
- package/lib/server/utils/small-ticket.js +800 -0
- package/lib/solution/BaseSales/index.d.ts +133 -10
- package/lib/solution/BaseSales/index.js +1111 -63
- package/lib/solution/BaseSales/types.d.ts +82 -6
- package/lib/solution/BaseSales/types.js +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +992 -0
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +106 -18
- package/lib/solution/BaseSales/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils.js +54 -10
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +271 -11
- package/lib/solution/BookingTicket/index.js +922 -29
- package/lib/solution/BookingTicket/types.d.ts +118 -1
- package/lib/solution/BookingTicket/types.js +11 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +44 -2
- package/lib/solution/BookingTicket/utils/cartView.d.ts +9 -1
- package/lib/solution/BookingTicket/utils/cartView.js +61 -6
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +1 -2
- package/lib/solution/RegisterAndLogin/config.js +2 -10
- package/lib/solution/ScanOrder/index.d.ts +9 -3
- package/lib/solution/ScanOrder/index.js +153 -70
- package/lib/solution/ScanOrder/types.d.ts +9 -5
- package/lib/solution/ScanOrder/utils.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +83 -17
- package/lib/solution/VenueBooking/index.d.ts +5 -2
- package/lib/solution/VenueBooking/index.js +54 -17
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/lib/types/index.d.ts +10 -0
- package/package.json +1 -1
- package/dist/solution/Checkout/appointmentDemo.json +0 -1
- package/lib/solution/Checkout/appointmentDemo.json +0 -1
|
@@ -34,13 +34,106 @@ __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");
|
|
37
38
|
var import_Order = require("../../modules/Order");
|
|
38
39
|
var import_decimal = __toESM(require("decimal.js"));
|
|
39
|
-
var
|
|
40
|
+
var import_lodash_es = require("lodash-es");
|
|
41
|
+
var import_types2 = require("../BookingByStep/types");
|
|
40
42
|
var import_utils = require("../../modules/Order/utils");
|
|
41
43
|
var import_dayjs = __toESM(require("dayjs"));
|
|
42
44
|
__reExport(BaseSales_exports, require("./types"), module.exports);
|
|
45
|
+
var import_Quotation = require("../../modules/Quotation");
|
|
43
46
|
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
|
+
}
|
|
44
137
|
var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
45
138
|
constructor(name, version) {
|
|
46
139
|
super(name, version);
|
|
@@ -48,20 +141,22 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
48
141
|
this.defaultVersion = "1.0.0";
|
|
49
142
|
this.isSolution = true;
|
|
50
143
|
this.initializeOptions = {};
|
|
51
|
-
// LoggerManager 实例
|
|
52
144
|
this.store = {
|
|
53
145
|
order: void 0
|
|
54
146
|
};
|
|
55
147
|
this.otherParams = {};
|
|
56
148
|
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
57
149
|
this.currentSalesDetail = null;
|
|
150
|
+
this.discountConfigCacheKey = null;
|
|
151
|
+
this.hasManualDiscountSelection = false;
|
|
152
|
+
this.paymentMethodsCache = [];
|
|
58
153
|
}
|
|
59
154
|
/**
|
|
60
155
|
* 子类可覆盖此方法以追加/收敛要注册的子模块。
|
|
61
|
-
* 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
|
|
156
|
+
* 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation。
|
|
62
157
|
*/
|
|
63
158
|
getRegisteredModuleNames() {
|
|
64
|
-
return ["products", "order", "salesSummary", "schedule", "payment"];
|
|
159
|
+
return ["products", "order", "salesSummary", "schedule", "payment", "quotation"];
|
|
65
160
|
}
|
|
66
161
|
/**
|
|
67
162
|
* 记录信息日志
|
|
@@ -102,16 +197,223 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
102
197
|
});
|
|
103
198
|
}
|
|
104
199
|
}
|
|
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
|
+
}
|
|
105
229
|
get payment() {
|
|
106
230
|
return this.store.payment;
|
|
107
231
|
}
|
|
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
|
+
}
|
|
108
407
|
/**
|
|
109
408
|
* 工厂入口:根据子模块名实例化对应模块。
|
|
110
409
|
* 默认使用 BookingByStep 公共 `createModule`。子类若需引入额外类型(如 customer),
|
|
111
410
|
* 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
|
|
112
411
|
*/
|
|
113
412
|
createSubModule(moduleName) {
|
|
114
|
-
|
|
413
|
+
if (moduleName === "quotation") {
|
|
414
|
+
return new import_Quotation.QuotationModule(`${this.name}_quotation`);
|
|
415
|
+
}
|
|
416
|
+
return (0, import_types2.createModule)(moduleName, this.name);
|
|
115
417
|
}
|
|
116
418
|
getSubModuleHooks(moduleName) {
|
|
117
419
|
var _a, _b;
|
|
@@ -123,6 +425,43 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
123
425
|
}
|
|
124
426
|
return optionHooks[moduleName] || ((_b = this.otherParams[moduleName]) == null ? void 0 : _b.hooks) || otherHooks[moduleName];
|
|
125
427
|
}
|
|
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
|
+
}
|
|
126
465
|
/**
|
|
127
466
|
* 读取 sessionStorage[this.name][cacheId],作为子模块 initialState 的来源。
|
|
128
467
|
* sessionStorage 损坏时静默忽略,按空状态注册。
|
|
@@ -140,19 +479,64 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
140
479
|
return {};
|
|
141
480
|
}
|
|
142
481
|
}
|
|
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
|
+
}
|
|
143
527
|
async initialize(core, options = {}) {
|
|
144
|
-
var _a;
|
|
528
|
+
var _a, _b;
|
|
145
529
|
this.core = core;
|
|
146
530
|
this.initializeOptions = options || {};
|
|
147
531
|
this.otherParams = options.otherParams || {};
|
|
148
532
|
this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
|
|
149
533
|
this.window = core.getPlugin("window");
|
|
150
534
|
this.request = core.getPlugin("request");
|
|
151
|
-
|
|
152
|
-
if (!appPlugin) {
|
|
535
|
+
this.appPlugin = core.getPlugin("app");
|
|
536
|
+
if (!this.appPlugin) {
|
|
153
537
|
throw new Error("Checkout 解决方案需要 app 插件支持");
|
|
154
538
|
}
|
|
155
|
-
const app = appPlugin.getApp();
|
|
539
|
+
const app = this.appPlugin.getApp();
|
|
156
540
|
this.logger = app.logger;
|
|
157
541
|
const targetCacheData = this.readSessionCacheData();
|
|
158
542
|
const moduleNames = this.getRegisteredModuleNames();
|
|
@@ -166,18 +550,18 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
166
550
|
this.core.registerModule(targetModule, {
|
|
167
551
|
initialState: (targetCacheData == null ? void 0 : targetCacheData[targetModule.name]) || {},
|
|
168
552
|
...hooks ? { hooks } : {},
|
|
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
|
-
}
|
|
553
|
+
otherParams: this.buildSubModuleOtherParams()
|
|
176
554
|
});
|
|
177
555
|
});
|
|
178
556
|
if (this.store.schedule) {
|
|
179
557
|
await this.store.schedule.loadAllSchedule();
|
|
180
558
|
}
|
|
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();
|
|
181
565
|
this.core.effects.emit(`${this.name}:onInited`, {});
|
|
182
566
|
}
|
|
183
567
|
async destroy() {
|
|
@@ -197,7 +581,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
197
581
|
}
|
|
198
582
|
/**
|
|
199
583
|
* 加载销售订单到统一 tempOrder 工作区。
|
|
200
|
-
*
|
|
584
|
+
* 统一通过 OrderModule 的 sales detail lookup 加载订单详情。
|
|
201
585
|
*
|
|
202
586
|
* 子类可在 `super.loadSalesDetail` 之后基于返回的 `sales` 做业务侧装配
|
|
203
587
|
* (比如把 `sales.customer` 写入 CustomerModule、emit 业务 hook 等)。
|
|
@@ -207,25 +591,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
207
591
|
throw new Error("order 模块未初始化");
|
|
208
592
|
const params = typeof orderIdOrParams === "object" ? orderIdOrParams : { orderId: orderIdOrParams };
|
|
209
593
|
const externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (params.orderId === void 0 || params.orderId === null) {
|
|
220
|
-
throw new Error("加载销售详情需要 orderId,或本地库中存在对应 externalSaleNumber/orderNumber");
|
|
594
|
+
const lookup = params.orderId ?? externalSaleNumber ?? params.orderNumber;
|
|
595
|
+
if (lookup === void 0 || lookup === null || lookup === "") {
|
|
596
|
+
throw new Error("加载销售详情需要 orderId、externalSaleNumber 或 orderNumber");
|
|
221
597
|
}
|
|
222
|
-
const res = await this.store.order.
|
|
598
|
+
const res = await this.store.order.getSalesOrderByLookup({
|
|
599
|
+
lookup,
|
|
600
|
+
forceRemote: params.forceRemote
|
|
601
|
+
});
|
|
223
602
|
if (!res || res.code !== 200) {
|
|
224
|
-
const message = res && (res.message || res.msg) || `加载销售详情失败: ${
|
|
603
|
+
const message = res && (res.message || res.msg) || `加载销售详情失败: ${lookup}`;
|
|
225
604
|
throw new Error(message);
|
|
226
605
|
}
|
|
227
|
-
const
|
|
228
|
-
|
|
606
|
+
const currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
|
|
607
|
+
const record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, res.data) : res.data;
|
|
608
|
+
const sales = await this.store.order.hydrateTempOrderFromRecord(record, { recalcOnHydrate: false });
|
|
229
609
|
this.currentSalesDetail = sales;
|
|
230
610
|
await this.core.effects.emit(`${this.name}:onSalesOrderLoaded`, { sales });
|
|
231
611
|
return sales;
|
|
@@ -286,6 +666,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
286
666
|
const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
|
|
287
667
|
return result;
|
|
288
668
|
}
|
|
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
|
+
}
|
|
289
676
|
getOrderIdentity() {
|
|
290
677
|
if (!this.store.order)
|
|
291
678
|
return null;
|
|
@@ -311,26 +698,48 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
311
698
|
return "";
|
|
312
699
|
return this.store.order.getTempOrderNote();
|
|
313
700
|
}
|
|
314
|
-
updateTempOrderNote(note) {
|
|
701
|
+
updateTempOrderNote(note, sync = false) {
|
|
315
702
|
try {
|
|
316
703
|
if (!this.store.order)
|
|
317
704
|
throw new Error("order 模块未初始化");
|
|
318
|
-
const result = this.store.order.updateTempOrderNote(note);
|
|
705
|
+
const result = this.store.order.updateTempOrderNote(note, sync);
|
|
319
706
|
return result;
|
|
320
707
|
} catch (error) {
|
|
321
708
|
throw error;
|
|
322
709
|
}
|
|
323
710
|
}
|
|
711
|
+
updateRemoteOrderNote(orderId, note) {
|
|
712
|
+
if (!this.store.order)
|
|
713
|
+
throw new Error("order 模块未初始化");
|
|
714
|
+
this.store.order.syncTempOrderNoteToRemote(orderId, note);
|
|
715
|
+
}
|
|
324
716
|
updateTempOrderShopDiscount(amount) {
|
|
325
717
|
if (!this.store.order)
|
|
326
718
|
throw new Error("order 模块未初始化");
|
|
327
719
|
return this.store.order.updateTempOrderShopDiscount(amount);
|
|
328
720
|
}
|
|
721
|
+
updateTempOrderDepositAmount(amount) {
|
|
722
|
+
if (!this.store.order)
|
|
723
|
+
throw new Error("order 模块未初始化");
|
|
724
|
+
return this.store.order.updateTempOrderDepositAmount(amount);
|
|
725
|
+
}
|
|
329
726
|
updateTempOrderContactsInfo(contactsInfo) {
|
|
330
727
|
if (!this.store.order)
|
|
331
728
|
throw new Error("order 模块未初始化");
|
|
332
729
|
return this.store.order.updateTempOrderContactsInfo(contactsInfo);
|
|
333
730
|
}
|
|
731
|
+
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
732
|
+
setEnableTempOrderPersist(enabled) {
|
|
733
|
+
if (!this.store.order)
|
|
734
|
+
throw new Error("order 模块未初始化");
|
|
735
|
+
this.store.order.setEnableTempOrderPersist(enabled);
|
|
736
|
+
}
|
|
737
|
+
/** 是否允许 saveDraft 写入 IndexedDB 草稿。 */
|
|
738
|
+
isTempOrderPersistEnabled() {
|
|
739
|
+
if (!this.store.order)
|
|
740
|
+
return false;
|
|
741
|
+
return this.store.order.isTempOrderPersistEnabled();
|
|
742
|
+
}
|
|
334
743
|
ensureTempOrder() {
|
|
335
744
|
if (!this.store.order)
|
|
336
745
|
throw new Error("order 模块未初始化");
|
|
@@ -342,6 +751,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
342
751
|
if (!this.store.order)
|
|
343
752
|
throw new Error("order 模块未初始化");
|
|
344
753
|
const tempOrder = await this.store.order.addNewOrder();
|
|
754
|
+
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
755
|
+
this.store.order.persistTempOrder();
|
|
756
|
+
await this.store.order.saveDraft();
|
|
757
|
+
}
|
|
345
758
|
return tempOrder;
|
|
346
759
|
} catch (error) {
|
|
347
760
|
throw error;
|
|
@@ -360,6 +773,43 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
360
773
|
throw new Error("scanOrder 解决方案需要 order 模块支持");
|
|
361
774
|
}
|
|
362
775
|
const tempOrder = this.store.order.restoreOrder();
|
|
776
|
+
this.currentSalesDetail = null;
|
|
777
|
+
this.discountConfigCacheKey = null;
|
|
778
|
+
this.hasManualDiscountSelection = false;
|
|
779
|
+
await this.effectsEmit("onTempOrderReplaced", { tempOrder });
|
|
780
|
+
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
781
|
+
this.store.order.persistTempOrder();
|
|
782
|
+
await this.store.order.saveDraft();
|
|
783
|
+
}
|
|
784
|
+
return tempOrder;
|
|
785
|
+
} catch (error) {
|
|
786
|
+
throw error;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
|
|
791
|
+
* 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
|
|
792
|
+
*/
|
|
793
|
+
async clearOrderCartLines() {
|
|
794
|
+
try {
|
|
795
|
+
if (!this.store.order)
|
|
796
|
+
throw new Error("order 模块未初始化");
|
|
797
|
+
const tempOrder = await this.store.order.clearOrderCartLines();
|
|
798
|
+
if (this.currentSalesDetail) {
|
|
799
|
+
this.currentSalesDetail = {
|
|
800
|
+
...this.currentSalesDetail,
|
|
801
|
+
products: [],
|
|
802
|
+
bookings: [],
|
|
803
|
+
rootBooking: null,
|
|
804
|
+
bookingsByProductUid: {},
|
|
805
|
+
discount_list: []
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
await this.effectsEmit("onTempOrderReplaced", { tempOrder });
|
|
809
|
+
if (this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled()) {
|
|
810
|
+
this.store.order.persistTempOrder();
|
|
811
|
+
await this.store.order.saveDraft();
|
|
812
|
+
}
|
|
363
813
|
return tempOrder;
|
|
364
814
|
} catch (error) {
|
|
365
815
|
throw error;
|
|
@@ -381,6 +831,289 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
381
831
|
throw error;
|
|
382
832
|
}
|
|
383
833
|
}
|
|
834
|
+
getHistoricalProductDiscountList(products) {
|
|
835
|
+
const historyDiscountList = [];
|
|
836
|
+
products.forEach((item) => {
|
|
837
|
+
if (!this.isPersistedOrderProduct(item))
|
|
838
|
+
return;
|
|
839
|
+
(item.discount_list || []).forEach((discount) => {
|
|
840
|
+
var _a, _b, _c, _d, _e, _f;
|
|
841
|
+
const discountId = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
|
|
842
|
+
if (!discountId || !["good_pass", "discount_card"].includes(discount.type))
|
|
843
|
+
return;
|
|
844
|
+
const quantity = item.quantity || item.num || item.product_quantity || 1;
|
|
845
|
+
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);
|
|
846
|
+
const index = historyDiscountList.findIndex((n) => n.id === discountId);
|
|
847
|
+
if (index !== -1) {
|
|
848
|
+
historyDiscountList[index] = {
|
|
849
|
+
...historyDiscountList[index],
|
|
850
|
+
amount: new import_decimal.default(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
|
|
851
|
+
savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
|
|
852
|
+
};
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
historyDiscountList.push({
|
|
856
|
+
...discount,
|
|
857
|
+
id: discountId,
|
|
858
|
+
tag: discount.tag || discount.type,
|
|
859
|
+
name: discount.name || ((_d = (_c = discount.discount) == null ? void 0 : _c.title) == null ? void 0 : _d.auto),
|
|
860
|
+
format_title: ((_e = discount.discount) == null ? void 0 : _e.title) || discount.format_title,
|
|
861
|
+
isEditMode: true,
|
|
862
|
+
limited_relation_product_data: {},
|
|
863
|
+
savedAmount: savedAmount.toNumber(),
|
|
864
|
+
isAvailable: true,
|
|
865
|
+
isDisabled: true,
|
|
866
|
+
isSelected: true,
|
|
867
|
+
product_id: ((_f = discount.discount) == null ? void 0 : _f.product_id) || discount.product_id
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
});
|
|
871
|
+
return historyDiscountList;
|
|
872
|
+
}
|
|
873
|
+
isPersistedOrderProduct(product) {
|
|
874
|
+
const orderDetailId = product.order_detail_id ?? product.orderDetailId;
|
|
875
|
+
if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
878
|
+
const bookingId = product.booking_id ?? product.bookingId;
|
|
879
|
+
return bookingId !== void 0 && bookingId !== null && bookingId !== "";
|
|
880
|
+
}
|
|
881
|
+
mergeHistoricalDiscountList(discountList, products) {
|
|
882
|
+
const historyDiscountList = this.getHistoricalProductDiscountList(products);
|
|
883
|
+
const historyIds = new Set(historyDiscountList.map((discount) => discount.id));
|
|
884
|
+
return [
|
|
885
|
+
...historyDiscountList,
|
|
886
|
+
...(discountList || []).filter((discount) => !historyIds.has(discount.id))
|
|
887
|
+
];
|
|
888
|
+
}
|
|
889
|
+
shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
|
|
890
|
+
if (params.discountAction !== "edit")
|
|
891
|
+
return false;
|
|
892
|
+
if (!params.products.length)
|
|
893
|
+
return false;
|
|
894
|
+
const hasDraftProduct = params.products.some((product) => !this.isPersistedOrderProduct(product));
|
|
895
|
+
if (hasDraftProduct)
|
|
896
|
+
return false;
|
|
897
|
+
const hasSelectedDiscount = params.currentDiscountList.some(
|
|
898
|
+
(discount) => discount.isSelected || discount.isEditMode || discount.isManualSelect
|
|
899
|
+
);
|
|
900
|
+
if (hasSelectedDiscount)
|
|
901
|
+
return false;
|
|
902
|
+
return !params.nextDiscountList.some(
|
|
903
|
+
(discount) => discount.isSelected || discount.isEditMode || discount.isManualSelect
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
|
|
907
|
+
if (!currentDiscountList.length)
|
|
908
|
+
return discountList;
|
|
909
|
+
const currentDiscountMap = new Map(
|
|
910
|
+
currentDiscountList.map((discount) => [discount.id, discount])
|
|
911
|
+
);
|
|
912
|
+
return discountList.map((discount) => {
|
|
913
|
+
const currentDiscount = currentDiscountMap.get(discount.id);
|
|
914
|
+
if (!currentDiscount)
|
|
915
|
+
return discount;
|
|
916
|
+
if (currentDiscount.isManualSelect) {
|
|
917
|
+
return {
|
|
918
|
+
...discount,
|
|
919
|
+
isSelected: false,
|
|
920
|
+
isManualSelect: true
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
if (currentDiscount.isSelected) {
|
|
924
|
+
return {
|
|
925
|
+
...discount,
|
|
926
|
+
isSelected: true,
|
|
927
|
+
isManualSelect: false
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
return discount;
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
async loadDiscountConfig(params) {
|
|
934
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
935
|
+
if (!this.store.order)
|
|
936
|
+
throw new Error("order 模块未初始化");
|
|
937
|
+
const tempOrder = this.store.order.ensureTempOrder();
|
|
938
|
+
const orderStore = this.store.order.store || {};
|
|
939
|
+
const discountModule = orderStore.discount;
|
|
940
|
+
const rulesModule = orderStore.rules;
|
|
941
|
+
const orderId = tempOrder.order_id || ((_b = (_a = this.getOrderIdentity) == null ? void 0 : _a.call(this)) == null ? void 0 : _b.orderId);
|
|
942
|
+
const customerId = Number(
|
|
943
|
+
(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
|
|
944
|
+
);
|
|
945
|
+
const currentDiscountList = ((_h = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _h.call(discountModule)) || [];
|
|
946
|
+
const originalDiscountList = ((_i = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _i.call(discountModule)) || [];
|
|
947
|
+
const hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some((discount) => discount.isManualSelect);
|
|
948
|
+
const discountAction = (params == null ? void 0 : params.action) || (orderId ? "edit" : "create");
|
|
949
|
+
const discountConfigCacheKey = [
|
|
950
|
+
customerId,
|
|
951
|
+
discountAction,
|
|
952
|
+
Number(orderId) || 0
|
|
953
|
+
].join(":");
|
|
954
|
+
let preparedDiscountList = [];
|
|
955
|
+
if (customerId && customerId !== 1) {
|
|
956
|
+
if (this.discountConfigCacheKey === discountConfigCacheKey) {
|
|
957
|
+
preparedDiscountList = originalDiscountList;
|
|
958
|
+
} else {
|
|
959
|
+
preparedDiscountList = await this.store.order.loadDiscountConfig({
|
|
960
|
+
customerId,
|
|
961
|
+
action: discountAction,
|
|
962
|
+
orderId: Number(orderId) || void 0,
|
|
963
|
+
apply: false
|
|
964
|
+
});
|
|
965
|
+
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
966
|
+
await ((_j = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _j.call(discountModule, preparedDiscountList));
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (hasManualDiscountSelection && currentDiscountList.length) {
|
|
970
|
+
return {
|
|
971
|
+
productList: tempOrder.products || [],
|
|
972
|
+
discountList: currentDiscountList
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
let nextDiscountList = this.mergeHistoricalDiscountList(
|
|
976
|
+
preparedDiscountList || ((_k = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _k.call(discountModule)) || [],
|
|
977
|
+
tempOrder.products || []
|
|
978
|
+
);
|
|
979
|
+
nextDiscountList = this.mergeCurrentDiscountSelectionState(
|
|
980
|
+
nextDiscountList,
|
|
981
|
+
currentDiscountList
|
|
982
|
+
);
|
|
983
|
+
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
984
|
+
const shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
|
|
985
|
+
discountAction,
|
|
986
|
+
products: tempOrder.products || [],
|
|
987
|
+
currentDiscountList,
|
|
988
|
+
nextDiscountList
|
|
989
|
+
});
|
|
990
|
+
if (shouldSkipAutoApplyFetchedDiscounts) {
|
|
991
|
+
const summary2 = await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
992
|
+
this.store.order.persistTempOrder();
|
|
993
|
+
await this.effectsEmit("onDiscountApplied", {
|
|
994
|
+
productList: tempOrder.products || [],
|
|
995
|
+
discountList: nextDiscountList,
|
|
996
|
+
selectedDiscountList: tempOrder.discount_list || [],
|
|
997
|
+
tempOrder
|
|
998
|
+
});
|
|
999
|
+
return {
|
|
1000
|
+
productList: tempOrder.products || [],
|
|
1001
|
+
discountList: nextDiscountList
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
if (rulesModule) {
|
|
1005
|
+
const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
1006
|
+
const result = rulesModule.calcDiscount({
|
|
1007
|
+
productList: tempOrder.products,
|
|
1008
|
+
discountList: nextDiscountList,
|
|
1009
|
+
holders,
|
|
1010
|
+
isFormSubject: !!((_m = tempOrder.holder) == null ? void 0 : _m.type) && tempOrder.holder.type === "form",
|
|
1011
|
+
orderTotalAmount: Number(((_n = orderStore.summary) == null ? void 0 : _n.total_amount) || 0)
|
|
1012
|
+
}) || { productList: tempOrder.products, discountList: nextDiscountList };
|
|
1013
|
+
if (result.productList) {
|
|
1014
|
+
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1015
|
+
tempOrder.products,
|
|
1016
|
+
result.productList
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
for (const product of tempOrder.products || []) {
|
|
1020
|
+
const productUid = (_o = product.metadata) == null ? void 0 : _o.unique_identification_number;
|
|
1021
|
+
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;
|
|
1022
|
+
if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
|
|
1023
|
+
continue;
|
|
1024
|
+
const totalPerUnitDiscount = (product.discount_list || []).reduce(
|
|
1025
|
+
(sum, pd) => sum + Number(pd.amount || 0),
|
|
1026
|
+
0
|
|
1027
|
+
);
|
|
1028
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
|
|
1029
|
+
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");
|
|
1030
|
+
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1031
|
+
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1032
|
+
if (product.metadata) {
|
|
1033
|
+
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
1034
|
+
product.metadata.price_schema_version = 2;
|
|
1035
|
+
}
|
|
1036
|
+
product.selling_price = (0, import_utils.composeLinePrice)({
|
|
1037
|
+
mainPrice: newMainSellingPrice,
|
|
1038
|
+
bundle: product.product_bundle
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
if (result.discountList) {
|
|
1042
|
+
nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1043
|
+
result.discountList,
|
|
1044
|
+
tempOrder.products || []
|
|
1045
|
+
);
|
|
1046
|
+
import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1047
|
+
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1048
|
+
tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
const summary = await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1052
|
+
this.store.order.persistTempOrder();
|
|
1053
|
+
await this.effectsEmit("onDiscountApplied", {
|
|
1054
|
+
productList: tempOrder.products || [],
|
|
1055
|
+
discountList: nextDiscountList,
|
|
1056
|
+
selectedDiscountList: tempOrder.discount_list || [],
|
|
1057
|
+
tempOrder
|
|
1058
|
+
});
|
|
1059
|
+
return {
|
|
1060
|
+
productList: tempOrder.products || [],
|
|
1061
|
+
discountList: nextDiscountList
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
async bestDiscount(cb) {
|
|
1065
|
+
var _a, _b, _c, _d, _e;
|
|
1066
|
+
if (!this.store.order)
|
|
1067
|
+
throw new Error("order 模块未初始化");
|
|
1068
|
+
const tempOrder = this.store.order.ensureTempOrder();
|
|
1069
|
+
const orderStore = this.store.order.store || {};
|
|
1070
|
+
const discountModule = orderStore.discount;
|
|
1071
|
+
const rulesModule = orderStore.rules;
|
|
1072
|
+
const originalDiscountList = ((_a = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _a.call(discountModule)) || this.getDiscountList();
|
|
1073
|
+
const currentDiscountList = ((_b = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
|
|
1074
|
+
let nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1075
|
+
originalDiscountList || [],
|
|
1076
|
+
tempOrder.products || []
|
|
1077
|
+
);
|
|
1078
|
+
let result = {
|
|
1079
|
+
productList: tempOrder.products || [],
|
|
1080
|
+
discountList: nextDiscountList
|
|
1081
|
+
};
|
|
1082
|
+
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1083
|
+
if (rulesModule) {
|
|
1084
|
+
const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
1085
|
+
result = rulesModule.calcDiscount({
|
|
1086
|
+
productList: tempOrder.products,
|
|
1087
|
+
discountList: nextDiscountList,
|
|
1088
|
+
holders,
|
|
1089
|
+
isFormSubject: !!((_d = tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form",
|
|
1090
|
+
orderTotalAmount: Number(((_e = orderStore.summary) == null ? void 0 : _e.total_amount) || 0)
|
|
1091
|
+
}) || result;
|
|
1092
|
+
if (result.productList) {
|
|
1093
|
+
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1094
|
+
tempOrder.products,
|
|
1095
|
+
result.productList
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
if (result.discountList) {
|
|
1099
|
+
nextDiscountList = this.mergeHistoricalDiscountList(
|
|
1100
|
+
result.discountList,
|
|
1101
|
+
tempOrder.products || []
|
|
1102
|
+
);
|
|
1103
|
+
import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
1104
|
+
await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
|
|
1105
|
+
tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
|
|
1106
|
+
result = {
|
|
1107
|
+
productList: tempOrder.products,
|
|
1108
|
+
discountList: nextDiscountList
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1113
|
+
this.store.order.persistTempOrder();
|
|
1114
|
+
cb == null ? void 0 : cb(result);
|
|
1115
|
+
return result;
|
|
1116
|
+
}
|
|
384
1117
|
getDiscountList() {
|
|
385
1118
|
if (!this.store.order)
|
|
386
1119
|
return [];
|
|
@@ -406,7 +1139,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
406
1139
|
}
|
|
407
1140
|
// TODO 需要优化,这段逻辑太长了,里面应该有些历史遗留问题
|
|
408
1141
|
async setDiscountSelected(params) {
|
|
409
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
1142
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
410
1143
|
try {
|
|
411
1144
|
if (!this.store.order)
|
|
412
1145
|
throw new Error("order 模块未初始化");
|
|
@@ -418,6 +1151,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
418
1151
|
isManualSelect: !params.isSelected
|
|
419
1152
|
} : d
|
|
420
1153
|
);
|
|
1154
|
+
this.hasManualDiscountSelection = true;
|
|
421
1155
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
422
1156
|
const orderStore = this.store.order.store || {};
|
|
423
1157
|
const discountModule = orderStore.discount;
|
|
@@ -439,7 +1173,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
439
1173
|
}
|
|
440
1174
|
) || { productList: tempOrder.products, discountList: updated };
|
|
441
1175
|
if (result == null ? void 0 : result.productList) {
|
|
442
|
-
tempOrder.products =
|
|
1176
|
+
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1177
|
+
tempOrder.products,
|
|
1178
|
+
result.productList
|
|
1179
|
+
);
|
|
443
1180
|
}
|
|
444
1181
|
if (result == null ? void 0 : result.discountList) {
|
|
445
1182
|
nextDiscountList = result.discountList;
|
|
@@ -450,6 +1187,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
450
1187
|
for (const d of nextDiscountList) {
|
|
451
1188
|
if (d.isSelected && !beforeSelectedIds.has(d.id)) {
|
|
452
1189
|
d.isSelected = false;
|
|
1190
|
+
d.isManualSelect = true;
|
|
453
1191
|
}
|
|
454
1192
|
}
|
|
455
1193
|
}
|
|
@@ -461,7 +1199,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
461
1199
|
for (const product of tempOrder.products) {
|
|
462
1200
|
const productUid = (_c = product.metadata) == null ? void 0 : _c.unique_identification_number;
|
|
463
1201
|
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;
|
|
464
|
-
if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || (
|
|
1202
|
+
if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
|
|
465
1203
|
continue;
|
|
466
1204
|
product.discount_list = (product.discount_list || []).filter((pd) => {
|
|
467
1205
|
var _a2;
|
|
@@ -472,8 +1210,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
472
1210
|
(sum, pd) => sum + (pd.amount || 0),
|
|
473
1211
|
0
|
|
474
1212
|
);
|
|
475
|
-
const optionSum = (0, import_utils.sumOptionUnitPrice)(
|
|
476
|
-
const sourcePrice = ((
|
|
1213
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
|
|
1214
|
+
const sourcePrice = ((_g = product.metadata) == null ? void 0 : _g.source_product_price) ?? (((_h = product.metadata) == null ? void 0 : _h.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");
|
|
477
1215
|
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
478
1216
|
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
479
1217
|
if (product.metadata) {
|
|
@@ -490,6 +1228,43 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
490
1228
|
tempOrder.discount_list = (nextDiscountList || []).filter((d) => d.isSelected);
|
|
491
1229
|
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
492
1230
|
this.store.order.persistTempOrder();
|
|
1231
|
+
this.effectsEmit("onDiscountApplied", {
|
|
1232
|
+
productList: tempOrder.products,
|
|
1233
|
+
discountList: nextDiscountList,
|
|
1234
|
+
selectedDiscountList: tempOrder.discount_list,
|
|
1235
|
+
tempOrder
|
|
1236
|
+
});
|
|
1237
|
+
} catch (error) {
|
|
1238
|
+
throw error;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
async applyDiscountCalculationResult(result) {
|
|
1242
|
+
try {
|
|
1243
|
+
if (!this.store.order)
|
|
1244
|
+
throw new Error("order 模块未初始化");
|
|
1245
|
+
if (!result)
|
|
1246
|
+
return;
|
|
1247
|
+
const tempOrder = this.store.order.ensureTempOrder();
|
|
1248
|
+
const orderStore = this.store.order.store || {};
|
|
1249
|
+
const discountModule = orderStore.discount;
|
|
1250
|
+
if (result.productList) {
|
|
1251
|
+
tempOrder.products = preserveManualProductDiscountProducts(
|
|
1252
|
+
tempOrder.products,
|
|
1253
|
+
result.productList
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
if (result.discountList) {
|
|
1257
|
+
import_Order.OrderModule.populateSavedAmounts(
|
|
1258
|
+
tempOrder.products,
|
|
1259
|
+
result.discountList
|
|
1260
|
+
);
|
|
1261
|
+
await (discountModule == null ? void 0 : discountModule.setDiscountList(result.discountList));
|
|
1262
|
+
tempOrder.discount_list = result.discountList.filter(
|
|
1263
|
+
(discount) => discount.isSelected
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
1267
|
+
this.store.order.persistTempOrder();
|
|
493
1268
|
} catch (error) {
|
|
494
1269
|
throw error;
|
|
495
1270
|
}
|
|
@@ -508,30 +1283,142 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
508
1283
|
if (!this.store.order) {
|
|
509
1284
|
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
510
1285
|
}
|
|
511
|
-
this.
|
|
1286
|
+
const inferredPaymentStatus = this.getSubmitPaymentStatus(params == null ? void 0 : params.paymentStatus);
|
|
512
1287
|
const submitParams = {
|
|
513
1288
|
cacheId: this.cacheId,
|
|
514
1289
|
platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
|
|
515
|
-
businessCode: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
|
|
516
|
-
channel:
|
|
1290
|
+
businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1291
|
+
channel: this.getSubmitOrderSalesChannel(),
|
|
517
1292
|
type: (_d = this.otherParams) == null ? void 0 : _d.type,
|
|
1293
|
+
request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
|
|
518
1294
|
...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
|
|
519
|
-
...
|
|
1295
|
+
...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
|
|
520
1296
|
...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
|
|
521
1297
|
...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
522
1298
|
};
|
|
523
1299
|
return this.store.order.submitTempOrder(submitParams);
|
|
524
1300
|
}
|
|
1301
|
+
async submitTempOrderAsync(params) {
|
|
1302
|
+
var _a, _b, _c, _d;
|
|
1303
|
+
if (!this.store.order) {
|
|
1304
|
+
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1305
|
+
}
|
|
1306
|
+
const inferredPaymentStatus = this.getSubmitPaymentStatus(params == null ? void 0 : params.paymentStatus);
|
|
1307
|
+
const submitParams = {
|
|
1308
|
+
cacheId: this.cacheId,
|
|
1309
|
+
platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
|
|
1310
|
+
businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1311
|
+
channel: this.getSubmitOrderSalesChannel(),
|
|
1312
|
+
type: (_d = this.otherParams) == null ? void 0 : _d.type,
|
|
1313
|
+
...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
|
|
1314
|
+
...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
|
|
1315
|
+
...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
|
|
1316
|
+
...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
|
|
1317
|
+
};
|
|
1318
|
+
return this.store.order.submitTempOrderAsync(submitParams);
|
|
1319
|
+
}
|
|
1320
|
+
async printLocalOrderReceipt(lookup) {
|
|
1321
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1322
|
+
if (!this.store.order) {
|
|
1323
|
+
throw new Error("BaseSales 解决方案需要 order 模块支持");
|
|
1324
|
+
}
|
|
1325
|
+
const hasLookup = lookup !== void 0 && lookup !== null && lookup !== "";
|
|
1326
|
+
const lookupPayload = typeof lookup === "number" ? { order_id: lookup } : { external_sale_number: lookup };
|
|
1327
|
+
const context = {
|
|
1328
|
+
platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
|
|
1329
|
+
businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
1330
|
+
channel: this.getSubmitOrderSalesChannel(),
|
|
1331
|
+
type: (_d = this.otherParams) == null ? void 0 : _d.type
|
|
1332
|
+
};
|
|
1333
|
+
const payload = hasLookup ? {
|
|
1334
|
+
...lookupPayload,
|
|
1335
|
+
lookup_order_from_db: 1,
|
|
1336
|
+
small_ticket_data_flag: 1,
|
|
1337
|
+
platform: context.platform,
|
|
1338
|
+
business_code: context.businessCode,
|
|
1339
|
+
order_sales_channel: context.channel,
|
|
1340
|
+
type: context.type
|
|
1341
|
+
} : this.store.order.buildCurrentSubmitPayloadForLocalPrint({
|
|
1342
|
+
cacheId: this.cacheId,
|
|
1343
|
+
platform: context.platform,
|
|
1344
|
+
businessCode: context.businessCode,
|
|
1345
|
+
channel: context.channel,
|
|
1346
|
+
type: context.type
|
|
1347
|
+
});
|
|
1348
|
+
const response = await this.request.post("/local/print-order", payload, {
|
|
1349
|
+
osServer: true,
|
|
1350
|
+
customToast: () => {
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
if (!hasLookup) {
|
|
1354
|
+
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));
|
|
1355
|
+
}
|
|
1356
|
+
return response;
|
|
1357
|
+
}
|
|
1358
|
+
getSubmitPaymentStatus(paymentStatus) {
|
|
1359
|
+
var _a, _b;
|
|
1360
|
+
if (paymentStatus !== void 0)
|
|
1361
|
+
return paymentStatus;
|
|
1362
|
+
const amountSnapshot = (_b = (_a = this.store.order) == null ? void 0 : _a.getOrderAmountSnapshot) == null ? void 0 : _b.call(_a);
|
|
1363
|
+
if (!amountSnapshot)
|
|
1364
|
+
return void 0;
|
|
1365
|
+
try {
|
|
1366
|
+
return new import_decimal.default(amountSnapshot.amountGap || 0).lte(0) ? "paid" : void 0;
|
|
1367
|
+
} catch {
|
|
1368
|
+
return void 0;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
525
1371
|
async syncPaymentsToOrder(params) {
|
|
1372
|
+
var _a, _b;
|
|
526
1373
|
if (!this.store.order)
|
|
527
1374
|
throw new Error("order 模块未初始化");
|
|
528
|
-
|
|
1375
|
+
const businessCode = params.businessCode ?? ((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.business_code);
|
|
1376
|
+
const channel = params.channel ?? this.getSubmitOrderSalesChannel();
|
|
1377
|
+
const syncParams = {
|
|
1378
|
+
...params,
|
|
1379
|
+
...businessCode !== void 0 ? { businessCode } : {},
|
|
1380
|
+
...channel !== void 0 ? { channel } : {}
|
|
1381
|
+
};
|
|
1382
|
+
const syncState = this.store.order.getOrderSyncState();
|
|
1383
|
+
if (params.submitWhenPaid && syncState === "submitting") {
|
|
1384
|
+
return this.store.order.syncPaymentsToOrder(syncParams);
|
|
1385
|
+
}
|
|
1386
|
+
const payments = params.payments || [];
|
|
1387
|
+
await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncStart, {
|
|
1388
|
+
payments,
|
|
1389
|
+
params: syncParams,
|
|
1390
|
+
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
1391
|
+
orderSnapshot: this.store.order.getOrderSnapshot()
|
|
1392
|
+
});
|
|
1393
|
+
try {
|
|
1394
|
+
const syncResult = await this.store.order.syncPaymentsToOrder(syncParams);
|
|
1395
|
+
await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
|
|
1396
|
+
ok: true,
|
|
1397
|
+
syncResult,
|
|
1398
|
+
payments: this.store.order.getOrderPayments(),
|
|
1399
|
+
params: syncParams,
|
|
1400
|
+
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
1401
|
+
orderSnapshot: this.store.order.getOrderSnapshot()
|
|
1402
|
+
});
|
|
1403
|
+
return syncResult;
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
|
|
1406
|
+
ok: false,
|
|
1407
|
+
error,
|
|
1408
|
+
payments: this.store.order.getOrderPayments(),
|
|
1409
|
+
params: syncParams,
|
|
1410
|
+
amountSnapshot: this.store.order.getOrderAmountSnapshot(),
|
|
1411
|
+
orderSnapshot: this.store.order.getOrderSnapshot()
|
|
1412
|
+
});
|
|
1413
|
+
throw error;
|
|
1414
|
+
}
|
|
529
1415
|
}
|
|
530
1416
|
/** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
|
|
531
1417
|
getOrderPayments() {
|
|
532
1418
|
if (!this.store.order)
|
|
533
1419
|
return [];
|
|
534
|
-
|
|
1420
|
+
const payments = this.store.order.getOrderPayments();
|
|
1421
|
+
return this.hydrateOrderPaymentNames(payments);
|
|
535
1422
|
}
|
|
536
1423
|
/** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
|
|
537
1424
|
setOrderPayments(payments) {
|
|
@@ -541,9 +1428,51 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
541
1428
|
}
|
|
542
1429
|
/** 追加单个支付项到当前订单。 */
|
|
543
1430
|
addOrderPayment(payment) {
|
|
1431
|
+
var _a;
|
|
544
1432
|
if (!this.store.order)
|
|
545
1433
|
throw new Error("order 模块未初始化");
|
|
546
|
-
|
|
1434
|
+
const paymentRecord = payment;
|
|
1435
|
+
const paymentAmount = new import_decimal.default(paymentRecord.amount || 0);
|
|
1436
|
+
if (paymentAmount.isZero()) {
|
|
1437
|
+
this.logWarning("addOrderPayment: 支付金额为 0,跳过添加支付项", {
|
|
1438
|
+
payment: paymentRecord
|
|
1439
|
+
});
|
|
1440
|
+
return this.store.order.getOrderPayments();
|
|
1441
|
+
}
|
|
1442
|
+
const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
|
|
1443
|
+
const shopWalletPassId = (_a = this.otherParams) == null ? void 0 : _a.shop_wallet_pass_id;
|
|
1444
|
+
if (shopWalletPassId !== void 0 && shopWalletPassId !== null) {
|
|
1445
|
+
metadata.shop_wallet_pass_id = shopWalletPassId;
|
|
1446
|
+
}
|
|
1447
|
+
if (!metadata.unique_payment_number) {
|
|
1448
|
+
metadata.unique_payment_number = (0, import_utils.createUuidV4)();
|
|
1449
|
+
}
|
|
1450
|
+
const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
1451
|
+
const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
|
|
1452
|
+
const createdAt = paymentRecord.created_at ?? paymentTimestamp;
|
|
1453
|
+
const payments = this.store.order.addOrderPayment({
|
|
1454
|
+
...paymentRecord,
|
|
1455
|
+
metadata,
|
|
1456
|
+
payment_time: paymentTime,
|
|
1457
|
+
created_at: createdAt
|
|
1458
|
+
});
|
|
1459
|
+
const amountSnapshot = this.store.order.getOrderAmountSnapshot();
|
|
1460
|
+
const syncState = this.store.order.getOrderSyncState();
|
|
1461
|
+
if (amountSnapshot && syncState !== "submitting") {
|
|
1462
|
+
const paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? "paid" : "partially_paid";
|
|
1463
|
+
void this.syncPaymentsToOrder({
|
|
1464
|
+
payments,
|
|
1465
|
+
paymentStatus,
|
|
1466
|
+
submitWhenPaid: true,
|
|
1467
|
+
smallTicketDataFlag: 1
|
|
1468
|
+
}).catch((error) => {
|
|
1469
|
+
this.logError("auto sync payments failed", {
|
|
1470
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
} else {
|
|
1474
|
+
}
|
|
1475
|
+
return payments;
|
|
547
1476
|
}
|
|
548
1477
|
/** 更新当前订单中的指定支付项。 */
|
|
549
1478
|
updateOrderPayment(paymentIdentity, updates) {
|
|
@@ -564,11 +1493,12 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
564
1493
|
return this.store.order.updateVoucherOrderPayments(payments);
|
|
565
1494
|
}
|
|
566
1495
|
getWalletProductList() {
|
|
567
|
-
var _a, _b;
|
|
1496
|
+
var _a, _b, _c;
|
|
568
1497
|
const tempOrder = (_a = this.store.order) == null ? void 0 : _a.getTempOrder();
|
|
569
1498
|
if (!((_b = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _b.length))
|
|
570
1499
|
return [];
|
|
571
|
-
|
|
1500
|
+
const products = (_c = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _c.filter((n) => n.product_id);
|
|
1501
|
+
const walletProducts = products.map((product) => {
|
|
572
1502
|
const metadata = product.metadata || {};
|
|
573
1503
|
return {
|
|
574
1504
|
product_id: product.product_id,
|
|
@@ -578,6 +1508,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
578
1508
|
is_charge_tax: product.is_charge_tax ?? 0,
|
|
579
1509
|
tax_fee: product.tax_fee,
|
|
580
1510
|
selling_price: Number(product.selling_price || 0),
|
|
1511
|
+
discount_list: product.discount_list || [],
|
|
581
1512
|
holder_id: product.holder_id ?? metadata.holder_id,
|
|
582
1513
|
original_price: product.original_price,
|
|
583
1514
|
main_product_original_price: metadata.main_product_original_price ?? product.original_price,
|
|
@@ -591,8 +1522,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
591
1522
|
const bundleMetadata = bundle.metadata || {};
|
|
592
1523
|
return {
|
|
593
1524
|
is_price_include_tax: tempOrder.is_price_include_tax,
|
|
594
|
-
|
|
595
|
-
|
|
1525
|
+
// 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
|
|
1526
|
+
bundle_id: bundle.bundle_id ?? bundle.id,
|
|
1527
|
+
bundle_product_id: bundle.bundle_product_id ?? bundle._bundle_product_id,
|
|
1528
|
+
bundle_group_id: bundle.bundle_group_id ?? bundle.group_id,
|
|
596
1529
|
bundle_variant_id: bundle.bundle_variant_id,
|
|
597
1530
|
price_type: bundle.price_type,
|
|
598
1531
|
price_type_ext: bundle.price_type_ext,
|
|
@@ -609,6 +1542,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
609
1542
|
})
|
|
610
1543
|
};
|
|
611
1544
|
});
|
|
1545
|
+
return walletProducts;
|
|
612
1546
|
}
|
|
613
1547
|
async initWalletData(params) {
|
|
614
1548
|
if (!this.store.order)
|
|
@@ -672,11 +1606,25 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
672
1606
|
}
|
|
673
1607
|
/** 获取可用支付方式列表,供 PaymentModal 渲染支付选项。 */
|
|
674
1608
|
async getPaymentMethodsAsync() {
|
|
675
|
-
|
|
676
|
-
|
|
1609
|
+
try {
|
|
1610
|
+
const response = await this.request.get("/pay/custom-payment/all", {
|
|
1611
|
+
filterPaymentMethods: true
|
|
1612
|
+
}, {
|
|
1613
|
+
osServer: true
|
|
1614
|
+
});
|
|
1615
|
+
const paymentMethods = (response == null ? void 0 : response.data) || [];
|
|
1616
|
+
this.paymentMethodsCache = Array.isArray(paymentMethods) ? [...paymentMethods] : [];
|
|
1617
|
+
return this.getPaymentMethods();
|
|
1618
|
+
} catch (error) {
|
|
1619
|
+
this.logWarning("getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表", {
|
|
1620
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1621
|
+
});
|
|
1622
|
+
return this.getPaymentMethods();
|
|
677
1623
|
}
|
|
678
|
-
|
|
679
|
-
|
|
1624
|
+
}
|
|
1625
|
+
/** 同步读取初始化时缓存的支付方式列表。 */
|
|
1626
|
+
getPaymentMethods() {
|
|
1627
|
+
return [...this.paymentMethodsCache];
|
|
680
1628
|
}
|
|
681
1629
|
/** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
|
|
682
1630
|
roundAmount(params) {
|
|
@@ -731,6 +1679,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
731
1679
|
transformBaseProductToOrderProduct(params) {
|
|
732
1680
|
return (0, import_transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
|
|
733
1681
|
}
|
|
1682
|
+
async calculateProductBookingPrice(params) {
|
|
1683
|
+
const quotation = this.store.quotation;
|
|
1684
|
+
const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
|
|
1685
|
+
const authoritativeProduct = await this.loadProductForPriceQuery(params, customerId);
|
|
1686
|
+
const product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
|
|
1687
|
+
await this.loadQuotationForPriceQuery({
|
|
1688
|
+
quotation,
|
|
1689
|
+
customer_id: customerId,
|
|
1690
|
+
channel: params.channel
|
|
1691
|
+
});
|
|
1692
|
+
return (0, import_quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
1693
|
+
...params,
|
|
1694
|
+
product,
|
|
1695
|
+
fallback_price: authoritativeProduct ? void 0 : params.fallback_price,
|
|
1696
|
+
customer_id: customerId,
|
|
1697
|
+
quotation
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
734
1700
|
async addProductToOrder(product, booking) {
|
|
735
1701
|
try {
|
|
736
1702
|
if (!this.store.order)
|
|
@@ -741,16 +1707,35 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
741
1707
|
throw error;
|
|
742
1708
|
}
|
|
743
1709
|
}
|
|
744
|
-
async
|
|
1710
|
+
async updateOrderProduct(params) {
|
|
1711
|
+
try {
|
|
1712
|
+
if (!this.store.order)
|
|
1713
|
+
throw new Error("order 模块未初始化");
|
|
1714
|
+
const products = await this.store.order.updateOrderProduct(params);
|
|
1715
|
+
return products;
|
|
1716
|
+
} catch (error) {
|
|
1717
|
+
throw error;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
async updateOrderProductQuantity(params) {
|
|
745
1721
|
try {
|
|
746
1722
|
if (!this.store.order)
|
|
747
1723
|
throw new Error("order 模块未初始化");
|
|
748
|
-
const products = await this.store.order.
|
|
1724
|
+
const products = await this.store.order.updateOrderProductQuantity(params);
|
|
749
1725
|
return products;
|
|
750
1726
|
} catch (error) {
|
|
751
1727
|
throw error;
|
|
752
1728
|
}
|
|
753
1729
|
}
|
|
1730
|
+
updateOrderBooking(params) {
|
|
1731
|
+
try {
|
|
1732
|
+
if (!this.store.order)
|
|
1733
|
+
throw new Error("order 模块未初始化");
|
|
1734
|
+
return this.store.order.updateOrderBooking(params);
|
|
1735
|
+
} catch (error) {
|
|
1736
|
+
throw error;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
754
1739
|
/**
|
|
755
1740
|
* 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
|
|
756
1741
|
* 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
|
|
@@ -765,27 +1750,87 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
765
1750
|
if (identity.unique_identification_number !== void 0) {
|
|
766
1751
|
params.unique_identification_number = identity.unique_identification_number;
|
|
767
1752
|
}
|
|
768
|
-
if (identity.
|
|
769
|
-
params.
|
|
1753
|
+
if (identity.product_sku !== void 0) {
|
|
1754
|
+
params.product_sku = identity.product_sku;
|
|
770
1755
|
}
|
|
771
1756
|
if (identity.product_bundle !== void 0)
|
|
772
1757
|
params.product_bundle = identity.product_bundle;
|
|
773
|
-
const products = await this.
|
|
1758
|
+
const products = await this.updateOrderProduct(params);
|
|
774
1759
|
return products;
|
|
775
1760
|
} catch (error) {
|
|
776
1761
|
throw error;
|
|
777
1762
|
}
|
|
778
1763
|
}
|
|
779
|
-
|
|
1764
|
+
/**
|
|
1765
|
+
* 批量删除购物车行,末尾仅一次促销重算。
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* await baseSales.removeProductsFromOrder([identityA, identityB]);
|
|
1769
|
+
*/
|
|
1770
|
+
async removeProductsFromOrder(identities) {
|
|
780
1771
|
try {
|
|
781
1772
|
if (!this.store.order)
|
|
782
1773
|
throw new Error("order 模块未初始化");
|
|
783
|
-
|
|
784
|
-
return products;
|
|
1774
|
+
return await this.store.order.removeProductsFromOrder(identities);
|
|
785
1775
|
} catch (error) {
|
|
786
1776
|
throw error;
|
|
787
1777
|
}
|
|
788
1778
|
}
|
|
1779
|
+
async removeProductFromOrder(identity) {
|
|
1780
|
+
return this.removeProductsFromOrder([identity]);
|
|
1781
|
+
}
|
|
1782
|
+
// ─── 促销/赠品 透传(迁移自 booking usePromotion) ────────────────
|
|
1783
|
+
/**
|
|
1784
|
+
* 注入促销评估器到底层 OrderModule。
|
|
1785
|
+
*
|
|
1786
|
+
* @example
|
|
1787
|
+
* solution.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
|
|
1788
|
+
*/
|
|
1789
|
+
setPromotionEvaluator(evaluator) {
|
|
1790
|
+
if (!this.store.order)
|
|
1791
|
+
throw new Error("order 模块未初始化");
|
|
1792
|
+
this.store.order.setPromotionEvaluator(evaluator);
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* 注入赠品选择 resolver。UI 层(SalesSdk)通过 bridge 提供。
|
|
1796
|
+
*
|
|
1797
|
+
* @example
|
|
1798
|
+
* solution.setGiftSelectResolver(async (ctx) => bridge.request(ctx));
|
|
1799
|
+
*/
|
|
1800
|
+
setGiftSelectResolver(resolver) {
|
|
1801
|
+
if (!this.store.order)
|
|
1802
|
+
throw new Error("order 模块未初始化");
|
|
1803
|
+
this.store.order.setGiftSelectResolver(resolver);
|
|
1804
|
+
}
|
|
1805
|
+
/**
|
|
1806
|
+
* 为商品目录追加促销标签,供 SalesSdkProductProvider 等商品列表入口复用。
|
|
1807
|
+
*
|
|
1808
|
+
* @example
|
|
1809
|
+
* const products = solution.appendPromotionTags(catalogProducts);
|
|
1810
|
+
*/
|
|
1811
|
+
appendPromotionTags(products) {
|
|
1812
|
+
if (!this.store.order)
|
|
1813
|
+
throw new Error("order 模块未初始化");
|
|
1814
|
+
return this.store.order.appendPromotionTags(products);
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* 主动触发一次促销应用(一般写路径会自动触发,少数场景如客户切换后可手动调)。
|
|
1818
|
+
*/
|
|
1819
|
+
async applyPromotion() {
|
|
1820
|
+
if (!this.store.order)
|
|
1821
|
+
throw new Error("order 模块未初始化");
|
|
1822
|
+
await this.store.order.applyPromotion();
|
|
1823
|
+
}
|
|
1824
|
+
/** 最近一次促销计算输出的未满足提示。 */
|
|
1825
|
+
getUnfulfilledPromotions() {
|
|
1826
|
+
var _a;
|
|
1827
|
+
return ((_a = this.store.order) == null ? void 0 : _a.getUnfulfilledPromotions()) || [];
|
|
1828
|
+
}
|
|
1829
|
+
/** 最近一次促销计算输出的赠品操作 diff。 */
|
|
1830
|
+
getLastGiftActions() {
|
|
1831
|
+
var _a;
|
|
1832
|
+
return ((_a = this.store.order) == null ? void 0 : _a.getLastGiftActions()) || null;
|
|
1833
|
+
}
|
|
789
1834
|
// 获取商品列表
|
|
790
1835
|
// TODO 需要跟 webpos 内的对齐一下
|
|
791
1836
|
async getProductList() {
|
|
@@ -807,11 +1852,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
807
1852
|
return this.otherParams;
|
|
808
1853
|
}
|
|
809
1854
|
async setOtherParams(params, { cover = false } = {}) {
|
|
1855
|
+
var _a;
|
|
810
1856
|
if (cover) {
|
|
811
|
-
this.otherParams = params;
|
|
1857
|
+
this.otherParams = { ...params };
|
|
812
1858
|
} else {
|
|
813
1859
|
this.otherParams = { ...this.otherParams, ...params };
|
|
814
1860
|
}
|
|
1861
|
+
this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
|
|
1862
|
+
await this.syncOtherParamsToSubModules(params, { cover });
|
|
815
1863
|
}
|
|
816
1864
|
};
|
|
817
1865
|
// Annotate the CommonJS export names for ESM import in node:
|