@pisell/pisellos 2.3.74 → 2.3.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.js +6 -10
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +2 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +75 -91
- package/dist/modules/Order/types.d.ts +3 -1
- package/dist/modules/Payment/index.js +97 -162
- package/dist/modules/Rules/index.js +1 -4
- package/dist/modules/Schedule/index.js +0 -1
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.js +97 -129
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/order/index.js +2 -4
- package/dist/server/modules/products/index.js +24 -42
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +27 -35
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BaseSales/index.js +100 -72
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.js +0 -2
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -252
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.js +45 -55
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +134 -134
- package/lib/effects/index.js +46 -57
- package/lib/index.js +82 -49
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
- package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
- package/lib/model/strategy/adapter/promotion/examples.js +222 -234
- package/lib/model/strategy/adapter/promotion/index.js +1 -0
- package/lib/model/strategy/adapter/promotion/type.js +243 -36
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +23 -42
- package/lib/modules/BookingContext/index.js +158 -136
- package/lib/modules/BookingContext/types.js +46 -32
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
- package/lib/modules/BookingContext/utils/flexible.js +38 -55
- package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
- package/lib/modules/BookingContext/utils/index.js +124 -41
- package/lib/modules/BookingContext/utils/noResource.js +58 -70
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
- package/lib/modules/BookingContext/utils/productExtend.js +202 -155
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
- package/lib/modules/BookingContext/utils/resources.js +209 -167
- package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
- package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +321 -251
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +70 -78
- package/lib/modules/Cart/utils/changePrice.js +22 -50
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +235 -172
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +122 -127
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +70 -76
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +1733 -2121
- package/lib/modules/Order/payment-utils.js +77 -120
- package/lib/modules/Order/types.d.ts +3 -1
- package/lib/modules/Order/types.js +88 -35
- package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
- package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
- package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
- package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
- package/lib/modules/Order/utils.js +814 -647
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +532 -399
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +230 -108
- package/lib/modules/Payment/utils.js +52 -51
- package/lib/modules/Payment/walletpass.js +485 -660
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +113 -123
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +81 -118
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/ResourcePlanner/index.js +25 -23
- package/lib/modules/ResourcePlanner/localClock.js +54 -119
- package/lib/modules/ResourcePlanner/planner.js +589 -770
- package/lib/modules/ResourcePlanner/types.js +10 -29
- package/lib/modules/Rules/index.js +1218 -959
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +85 -90
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +355 -430
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
- package/lib/modules/Schedule/index.js +100 -114
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -71
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +773 -418
- package/lib/modules/SurchargeList/index.js +46 -60
- package/lib/modules/SurchargeList/types.js +4 -16
- package/lib/modules/index.js +245 -63
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.js +3050 -2665
- package/lib/server/modules/floor-plan/index.js +118 -134
- package/lib/server/modules/floor-plan/types.js +15 -30
- package/lib/server/modules/index.js +106 -68
- package/lib/server/modules/menu/index.js +142 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +784 -1002
- package/lib/server/modules/order/types.js +122 -33
- package/lib/server/modules/order/utils/filterBookings.js +219 -194
- package/lib/server/modules/order/utils/filterOrders.js +118 -92
- package/lib/server/modules/payment/index.js +59 -83
- package/lib/server/modules/payment/types.js +4 -16
- package/lib/server/modules/products/index.js +583 -471
- package/lib/server/modules/products/types.js +44 -34
- package/lib/server/modules/quotation/index.js +137 -172
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +220 -186
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +135 -123
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/small-ticket.js +479 -456
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BaseSales/index.js +1220 -1412
- package/lib/solution/BaseSales/types.js +42 -38
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
- package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
- package/lib/solution/BaseSales/utils.js +158 -143
- package/lib/solution/BookingByStep/index.js +1527 -1340
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.js +607 -522
- package/lib/solution/BookingTicket/types.js +99 -77
- package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
- package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
- package/lib/solution/BookingTicket/utils/cartView.js +114 -99
- package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
- package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +228 -156
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +328 -324
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +832 -864
- package/lib/solution/ScanOrder/types.js +33 -34
- package/lib/solution/ScanOrder/utils.js +409 -374
- package/lib/solution/ShopDiscount/index.js +226 -232
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +300 -172
- package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
- package/lib/solution/UnifiedBookingSales/types.js +10 -32
- package/lib/solution/VenueBooking/index.js +811 -879
- package/lib/solution/VenueBooking/types.js +19 -39
- package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
- package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +124 -41
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/payment-number.js +26 -46
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,52 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/solution/ShopDiscount/index.ts
|
|
30
|
-
var ShopDiscount_exports = {};
|
|
31
|
-
__export(ShopDiscount_exports, {
|
|
32
|
-
ShopDiscountImpl: () => ShopDiscountImpl,
|
|
33
|
-
default: () => ShopDiscount_default
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
34
5
|
});
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
6
|
+
exports.default = exports.ShopDiscountImpl = void 0;
|
|
7
|
+
var _BaseModule = require("../../modules/BaseModule");
|
|
8
|
+
var _Discount = require("../../modules/Discount");
|
|
9
|
+
var _Rules = require("../../modules/Rules");
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
var _types = require("../../modules/Rules/types");
|
|
12
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
13
|
+
var _lodashEs = require("lodash-es");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
16
|
+
defaultName = 'shopDiscount';
|
|
17
|
+
defaultVersion = '1.0.0';
|
|
18
|
+
isSolution = true;
|
|
19
|
+
request;
|
|
20
|
+
window;
|
|
21
|
+
store;
|
|
22
|
+
options = {};
|
|
23
|
+
hooks;
|
|
44
24
|
constructor(name, version) {
|
|
45
25
|
super(name, version);
|
|
46
|
-
|
|
47
|
-
this.defaultVersion = "1.0.0";
|
|
48
|
-
this.isSolution = true;
|
|
49
|
-
this.options = {};
|
|
26
|
+
// 初始化所有必要的状态属性
|
|
50
27
|
this.store = {
|
|
51
28
|
customer: null,
|
|
52
29
|
productList: [],
|
|
@@ -56,97 +33,105 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
56
33
|
originalDiscountList: [],
|
|
57
34
|
currentBookingTime: "",
|
|
58
35
|
filteredDiscountList: [],
|
|
59
|
-
bookingSubject:
|
|
36
|
+
bookingSubject: undefined,
|
|
60
37
|
orderTotalAmount: 0,
|
|
61
|
-
orderId:
|
|
38
|
+
orderId: undefined
|
|
62
39
|
};
|
|
63
40
|
}
|
|
41
|
+
|
|
64
42
|
// =========== 生命周期方法 ===========
|
|
43
|
+
|
|
65
44
|
async initialize(core, options) {
|
|
66
|
-
var _a, _b;
|
|
67
45
|
this.core = core;
|
|
68
46
|
this.options = options;
|
|
69
|
-
this.store = {
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
this.store = {
|
|
48
|
+
...this.store,
|
|
49
|
+
...(options.store || {})
|
|
50
|
+
};
|
|
51
|
+
this.hooks = options.otherParams?.rules?.hooks;
|
|
52
|
+
// 获取依赖的插件
|
|
72
53
|
this.initializePlugins();
|
|
54
|
+
|
|
55
|
+
// 注册依赖模块
|
|
73
56
|
this.registerDependentModules();
|
|
57
|
+
|
|
58
|
+
// 注册事件监听
|
|
74
59
|
this.registerEventListeners();
|
|
75
60
|
}
|
|
76
61
|
async destroy() {
|
|
77
|
-
var _a, _b;
|
|
78
62
|
this.store.productList = [];
|
|
79
63
|
this.store.customer = null;
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
this.store.discount?.destroy();
|
|
65
|
+
this.store.rules?.destroy();
|
|
82
66
|
this.core.effects.offByModuleDestroy(this.name);
|
|
83
67
|
await this.core.effects.emit(`${this.name}:onDestroy`, {});
|
|
84
|
-
console.log("[ShopDiscount] 已销毁");
|
|
85
68
|
}
|
|
86
69
|
async clear() {
|
|
87
|
-
var _a, _b;
|
|
88
70
|
this.store.productList = [];
|
|
89
71
|
this.store.customer = null;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.log("[ShopDiscount] clear");
|
|
72
|
+
this.store.discount?.clear();
|
|
73
|
+
this.store.rules?.clear();
|
|
93
74
|
}
|
|
75
|
+
|
|
94
76
|
// =========== 初始化辅助方法 ===========
|
|
77
|
+
|
|
95
78
|
initializePlugins() {
|
|
96
|
-
this.request = this.core.getPlugin(
|
|
97
|
-
this.window = this.core.getPlugin(
|
|
79
|
+
this.request = this.core.getPlugin('request');
|
|
80
|
+
this.window = this.core.getPlugin('window');
|
|
98
81
|
if (!this.request) {
|
|
99
|
-
throw new Error(
|
|
82
|
+
throw new Error('ShopDiscount需要 request 插件支持');
|
|
100
83
|
}
|
|
101
84
|
if (!this.window) {
|
|
102
|
-
throw new Error(
|
|
85
|
+
throw new Error('ShopDiscount需要 window 插件支持');
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
88
|
registerDependentModules() {
|
|
106
|
-
|
|
89
|
+
// 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
|
|
90
|
+
// 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
|
|
107
91
|
let targetCacheData = {};
|
|
108
|
-
if (
|
|
92
|
+
if (this.options.otherParams?.cacheId) {
|
|
109
93
|
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
110
94
|
if (sessionData) {
|
|
111
95
|
const data = JSON.parse(sessionData);
|
|
112
96
|
targetCacheData = data[this.options.otherParams.cacheId];
|
|
113
97
|
}
|
|
114
98
|
}
|
|
115
|
-
|
|
99
|
+
// 注册优惠模块
|
|
100
|
+
const discount = new _Discount.DiscountModule(`${this.name}_discount`);
|
|
116
101
|
this.core.registerModule(discount, {
|
|
117
|
-
initialState: targetCacheData
|
|
118
|
-
hooks:
|
|
102
|
+
initialState: targetCacheData?.[discount.name],
|
|
103
|
+
hooks: this.options.otherParams?.discount?.hooks,
|
|
119
104
|
otherParams: {
|
|
120
105
|
fatherModule: this.name,
|
|
121
|
-
openCache:
|
|
122
|
-
cacheId:
|
|
106
|
+
openCache: this.options.otherParams?.cacheId ? true : false,
|
|
107
|
+
cacheId: this.options.otherParams?.cacheId
|
|
123
108
|
}
|
|
124
109
|
});
|
|
125
110
|
this.store.discount = discount;
|
|
126
|
-
|
|
111
|
+
|
|
112
|
+
// 注册规则模块
|
|
113
|
+
const rules = new _Rules.RulesModule(`${this.name}_rules`);
|
|
127
114
|
this.core.registerModule(rules, {
|
|
128
|
-
hooks:
|
|
115
|
+
hooks: this.options.otherParams?.rules?.hooks
|
|
129
116
|
});
|
|
130
117
|
this.store.rules = rules;
|
|
131
118
|
}
|
|
132
119
|
registerEventListeners() {
|
|
133
|
-
this.core.effects.only(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var _a;
|
|
137
|
-
if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.loadPrepareConfig({
|
|
141
|
-
customerId: customer.id,
|
|
142
|
-
action: "create",
|
|
143
|
-
with_good_pass: 1,
|
|
144
|
-
with_discount_card: 1
|
|
145
|
-
});
|
|
120
|
+
this.core.effects.only(`${this.name}:onCustomerChange`, customer => {
|
|
121
|
+
if (this.options.otherParams?.cacheId && this.getDiscountList().length) {
|
|
122
|
+
return;
|
|
146
123
|
}
|
|
147
|
-
|
|
124
|
+
this.loadPrepareConfig({
|
|
125
|
+
customerId: customer.id,
|
|
126
|
+
action: 'create',
|
|
127
|
+
with_good_pass: 1,
|
|
128
|
+
with_discount_card: 1
|
|
129
|
+
});
|
|
130
|
+
});
|
|
148
131
|
}
|
|
132
|
+
|
|
149
133
|
// =========== 公共 API ===========
|
|
134
|
+
|
|
150
135
|
// 设置预约时间
|
|
151
136
|
// public async setBookingTime(bookingTime: string | null): Promise<void> {
|
|
152
137
|
// if (this.store.currentBookingTime !== bookingTime) {
|
|
@@ -156,17 +141,23 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
156
141
|
// await this.updateFilteredDiscountList();
|
|
157
142
|
// }
|
|
158
143
|
// }
|
|
144
|
+
|
|
159
145
|
// 获取当前预约时间
|
|
160
146
|
getCurrentBookingTime() {
|
|
161
147
|
return this.store.currentBookingTime;
|
|
162
148
|
}
|
|
149
|
+
|
|
163
150
|
// 根据预约时间过滤优惠券列表
|
|
164
151
|
filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
165
|
-
|
|
152
|
+
// 如果全部是普通商品,不需要过滤,直接返回当前数据
|
|
153
|
+
if ((0, _utils.isAllNormalProduct)(this.store.productList || [])) {
|
|
166
154
|
return discountList;
|
|
167
155
|
}
|
|
168
|
-
|
|
156
|
+
|
|
157
|
+
// 否则使用 bookingTime 进行过滤
|
|
158
|
+
return (0, _utils.filterDiscountListByBookingTime)(discountList, bookingTime);
|
|
169
159
|
}
|
|
160
|
+
|
|
170
161
|
// 更新过滤后的优惠券列表
|
|
171
162
|
// private async updateFilteredDiscountList(): Promise<void> {
|
|
172
163
|
// const originalList = this.store.originalDiscountList;
|
|
@@ -185,20 +176,18 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
185
176
|
// );
|
|
186
177
|
// }
|
|
187
178
|
// }
|
|
179
|
+
|
|
188
180
|
// 设置客户
|
|
189
181
|
async setCustomer(customer) {
|
|
190
|
-
|
|
191
|
-
if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
|
|
182
|
+
if (this.store.customer?.id !== customer.id) {
|
|
192
183
|
this.store.customer = customer;
|
|
193
|
-
await this.core.effects.emit(
|
|
194
|
-
`${this.name}:onCustomerChange`,
|
|
195
|
-
customer
|
|
196
|
-
);
|
|
184
|
+
await this.core.effects.emit(`${this.name}:onCustomerChange`, customer);
|
|
197
185
|
}
|
|
198
186
|
}
|
|
199
187
|
setOriginTotalAmount(amount) {
|
|
200
188
|
this.store.orderTotalAmount = amount;
|
|
201
189
|
}
|
|
190
|
+
|
|
202
191
|
// 设置holders
|
|
203
192
|
setHolders(holders) {
|
|
204
193
|
this.store.holders = holders;
|
|
@@ -209,24 +198,30 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
209
198
|
setOrderId(id) {
|
|
210
199
|
this.store.orderId = id;
|
|
211
200
|
}
|
|
201
|
+
|
|
212
202
|
// 计算优惠券
|
|
213
203
|
calcDiscount(productList, options) {
|
|
214
|
-
var _a;
|
|
215
204
|
this.store.productList = productList;
|
|
216
205
|
const rulesModule = this.core.getModule(`${this.name}_rules`);
|
|
217
206
|
if (!rulesModule) {
|
|
218
|
-
return {
|
|
219
|
-
}
|
|
220
|
-
let { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
|
|
221
|
-
{
|
|
207
|
+
return {
|
|
222
208
|
productList,
|
|
223
|
-
discountList: this.getDiscountList()
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
209
|
+
discountList: this.getDiscountList()
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
let {
|
|
213
|
+
productList: newProductList,
|
|
214
|
+
discountList: newDiscountList
|
|
215
|
+
} = rulesModule.calcDiscount({
|
|
216
|
+
productList,
|
|
217
|
+
discountList: this.getDiscountList(),
|
|
218
|
+
orderTotalAmount: this.store.orderTotalAmount || 0,
|
|
219
|
+
holders: this.store.holders || [],
|
|
220
|
+
isFormSubject: this.store.bookingSubject?.type === 'form'
|
|
221
|
+
}, options) || {
|
|
222
|
+
productList,
|
|
223
|
+
discountList: this.getDiscountList()
|
|
224
|
+
};
|
|
230
225
|
if (newDiscountList) {
|
|
231
226
|
newDiscountList = this.setDiscountList(newDiscountList);
|
|
232
227
|
}
|
|
@@ -235,24 +230,35 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
235
230
|
discountList: newDiscountList || this.getDiscountList()
|
|
236
231
|
};
|
|
237
232
|
}
|
|
233
|
+
|
|
238
234
|
// 设置优惠券使用状态
|
|
239
235
|
setDiscountSelected(params) {
|
|
236
|
+
// 获取当前优惠券列表
|
|
240
237
|
const discountList = this.getDiscountList();
|
|
238
|
+
|
|
239
|
+
// 构建选择操作列表
|
|
241
240
|
const selectionOperations = [];
|
|
241
|
+
|
|
242
|
+
// 主要操作
|
|
242
243
|
selectionOperations.push({
|
|
243
244
|
discountId: params.discountId,
|
|
244
245
|
isSelected: params.isSelected
|
|
245
246
|
});
|
|
247
|
+
|
|
248
|
+
// 如果有批量操作列表,添加到操作列表中
|
|
246
249
|
if (params.selectedList && params.selectedList.length > 0) {
|
|
247
250
|
selectionOperations.push(...params.selectedList);
|
|
248
251
|
}
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
|
|
253
|
+
// 创建选择状态映射(去重处理,后面的操作会覆盖前面的)
|
|
254
|
+
const selectionMap = new Map();
|
|
255
|
+
selectionOperations.forEach(operation => {
|
|
251
256
|
selectionMap.set(operation.discountId, operation.isSelected);
|
|
252
257
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
258
|
+
|
|
259
|
+
// 找到需要修改状态的优惠券
|
|
260
|
+
const newDiscountList = discountList.map(discount => {
|
|
261
|
+
if (discount.isEditMode) return discount;
|
|
256
262
|
if (selectionMap.has(discount.id)) {
|
|
257
263
|
const targetIsSelected = selectionMap.get(discount.id);
|
|
258
264
|
return {
|
|
@@ -262,8 +268,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
262
268
|
isManualSelect: !targetIsSelected
|
|
263
269
|
};
|
|
264
270
|
}
|
|
265
|
-
return {
|
|
271
|
+
return {
|
|
272
|
+
...discount,
|
|
273
|
+
isManualSelect: !discount?.isSelected
|
|
274
|
+
};
|
|
266
275
|
});
|
|
276
|
+
|
|
277
|
+
// 更新优惠券列表
|
|
267
278
|
this.setDiscountList(newDiscountList);
|
|
268
279
|
return this.calcDiscount(this.store.productList || [], params);
|
|
269
280
|
}
|
|
@@ -271,9 +282,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
271
282
|
this.store.productList = productList;
|
|
272
283
|
}
|
|
273
284
|
async batchSearchByProductIds(productIds) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
resultDiscountList = resultDiscountList.map((item) => {
|
|
285
|
+
let resultDiscountList = (await this.store.discount?.batchSearchByProductIds(productIds)) || [];
|
|
286
|
+
resultDiscountList = resultDiscountList.map(item => {
|
|
277
287
|
return {
|
|
278
288
|
...item,
|
|
279
289
|
discount_rule_uncheck_flag: true
|
|
@@ -284,12 +294,21 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
284
294
|
this.setDiscountList(newDiscountList);
|
|
285
295
|
return newDiscountList;
|
|
286
296
|
}
|
|
297
|
+
|
|
287
298
|
// 扫码输入code
|
|
288
299
|
async scanCode(code, customerId) {
|
|
289
|
-
var _a, _b, _c;
|
|
290
300
|
try {
|
|
291
|
-
const resultDiscountWithReason = await
|
|
292
|
-
|
|
301
|
+
const resultDiscountWithReason = (await this.store.discount?.batchSearch(code, {
|
|
302
|
+
customerId,
|
|
303
|
+
orderId: this.store.orderId
|
|
304
|
+
})) || {
|
|
305
|
+
discountList: [],
|
|
306
|
+
unavailableReasonKey: null
|
|
307
|
+
};
|
|
308
|
+
const {
|
|
309
|
+
discountList: resultDiscountList,
|
|
310
|
+
unavailableReasonKey
|
|
311
|
+
} = resultDiscountWithReason;
|
|
293
312
|
const rulesModule = this.store.rules;
|
|
294
313
|
if (!rulesModule) {
|
|
295
314
|
return {
|
|
@@ -297,7 +316,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
297
316
|
isAvailable: false,
|
|
298
317
|
productList: this.store.productList || [],
|
|
299
318
|
discountList: this.getDiscountList(),
|
|
300
|
-
unavailableReason:
|
|
319
|
+
unavailableReason: _types.UnavailableReason.Unknown
|
|
301
320
|
};
|
|
302
321
|
}
|
|
303
322
|
if (!resultDiscountList.length) {
|
|
@@ -309,14 +328,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
309
328
|
unavailableReasonKey
|
|
310
329
|
};
|
|
311
330
|
}
|
|
312
|
-
const withScanList = resultDiscountList.map(
|
|
331
|
+
const withScanList = resultDiscountList.map(item => {
|
|
313
332
|
return {
|
|
314
333
|
...item,
|
|
315
334
|
isScan: true
|
|
316
335
|
};
|
|
317
336
|
});
|
|
318
|
-
|
|
319
|
-
|
|
337
|
+
// 如果扫回来的券当前有选中的,则不进行计算
|
|
338
|
+
const currentSelectedDiscountList = this.getDiscountList().filter(n => n.isSelected);
|
|
339
|
+
if (currentSelectedDiscountList.length && currentSelectedDiscountList.some(n => withScanList.some(m => m.id === n.id))) {
|
|
320
340
|
return {
|
|
321
341
|
type: "clientCalc",
|
|
322
342
|
isAvailable: true,
|
|
@@ -334,7 +354,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
334
354
|
oldDiscountList: this.getDiscountList(),
|
|
335
355
|
newDiscountList: withScanList,
|
|
336
356
|
holders: this.store.holders || [],
|
|
337
|
-
isFormSubject:
|
|
357
|
+
isFormSubject: this.store.bookingSubject?.type === 'form',
|
|
338
358
|
orderTotalAmount: this.store.orderTotalAmount || 0
|
|
339
359
|
}) || {
|
|
340
360
|
isAvailable: false,
|
|
@@ -345,10 +365,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
345
365
|
this.setDiscountList(newDiscountList || []);
|
|
346
366
|
this.store.originalDiscountList = newDiscountList || [];
|
|
347
367
|
this.setProductList(newProductList || []);
|
|
348
|
-
if (this.isWalkIn() && resultDiscountList.length &&
|
|
349
|
-
await this.getCustomerWallet(
|
|
350
|
-
resultDiscountList[0].customer_id
|
|
351
|
-
);
|
|
368
|
+
if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1)) {
|
|
369
|
+
await this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
352
370
|
}
|
|
353
371
|
}
|
|
354
372
|
return {
|
|
@@ -359,60 +377,52 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
359
377
|
unavailableReason
|
|
360
378
|
};
|
|
361
379
|
} catch (error) {
|
|
362
|
-
console.error(
|
|
380
|
+
console.error('[ShopDiscount] 扫码出错:', error);
|
|
363
381
|
return {
|
|
364
382
|
type: "clientCalc",
|
|
365
383
|
isAvailable: false,
|
|
366
384
|
productList: this.store.productList || [],
|
|
367
385
|
discountList: this.getDiscountList(),
|
|
368
|
-
unavailableReason:
|
|
386
|
+
unavailableReason: _types.UnavailableReason.Unknown
|
|
369
387
|
};
|
|
370
388
|
}
|
|
371
389
|
}
|
|
372
390
|
calcDiscountApplicableProductTotalPrice(discount) {
|
|
373
|
-
|
|
374
|
-
return (_a = this.store.discount) == null ? void 0 : _a.calcDiscountApplicableProductTotalPrice(
|
|
375
|
-
discount
|
|
376
|
-
);
|
|
391
|
+
return this.store.discount?.calcDiscountApplicableProductTotalPrice(discount);
|
|
377
392
|
}
|
|
393
|
+
|
|
378
394
|
// =========== 私有辅助方法 ===========
|
|
395
|
+
|
|
379
396
|
// 获取客户
|
|
380
397
|
getCustomer() {
|
|
381
398
|
return this.store.customer;
|
|
382
399
|
}
|
|
400
|
+
|
|
383
401
|
// 是否是walkIn
|
|
384
402
|
isWalkIn() {
|
|
385
|
-
|
|
386
|
-
return (((_a = this.getCustomer()) == null ? void 0 : _a.id) || 1) === 1;
|
|
403
|
+
return (this.getCustomer()?.id || 1) === 1;
|
|
387
404
|
}
|
|
405
|
+
|
|
388
406
|
// 触发优惠列表变更事件
|
|
389
407
|
async emitDiscountListChange(discountList) {
|
|
390
|
-
await this.core.effects.emit(
|
|
391
|
-
`${this.name}:onDiscountListChange`,
|
|
392
|
-
discountList
|
|
393
|
-
);
|
|
408
|
+
await this.core.effects.emit(`${this.name}:onDiscountListChange`, discountList);
|
|
394
409
|
}
|
|
410
|
+
|
|
395
411
|
// 设置优惠券列表
|
|
396
412
|
setDiscountList(discountList) {
|
|
397
|
-
var _a;
|
|
398
413
|
const productList = this.store.productList || [];
|
|
399
414
|
const editModeDiscountList = [];
|
|
400
|
-
productList.forEach(
|
|
401
|
-
var _a2;
|
|
415
|
+
productList.forEach(item => {
|
|
402
416
|
if (item.booking_id) {
|
|
403
|
-
const product =
|
|
404
|
-
(item.discount_list || []).forEach(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const index = editModeDiscountList.findIndex((n) => {
|
|
408
|
-
var _a4;
|
|
409
|
-
return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
|
|
410
|
-
});
|
|
417
|
+
const product = this.hooks?.getProduct(item);
|
|
418
|
+
(item.discount_list || []).forEach(discount => {
|
|
419
|
+
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
420
|
+
const index = editModeDiscountList.findIndex(n => n.id === (discount.discount?.resource_id || discount.id));
|
|
411
421
|
if (index !== -1) {
|
|
412
422
|
editModeDiscountList[index] = {
|
|
413
423
|
...editModeDiscountList[index],
|
|
414
|
-
amount: new
|
|
415
|
-
savedAmount: new
|
|
424
|
+
amount: new _decimal.default(discount.amount || 0).plus(new _decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
425
|
+
savedAmount: new _decimal.default(discount.amount || 0).times(product?.quantity || product?.num || 1).plus(discount?.metadata?.product_discount_difference || 0).plus(new _decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
416
426
|
};
|
|
417
427
|
} else {
|
|
418
428
|
if (discount.type && !discount.tag) {
|
|
@@ -423,44 +433,34 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
423
433
|
name: discount.name || discount.discount.title.auto,
|
|
424
434
|
isEditMode: true,
|
|
425
435
|
limited_relation_product_data: {},
|
|
426
|
-
savedAmount: new
|
|
436
|
+
savedAmount: new _decimal.default(discount.amount || 0).times(product?.quantity || product?.num || 1).plus(discount?.metadata?.product_discount_difference || 0).toNumber(),
|
|
427
437
|
isAvailable: true,
|
|
428
|
-
id:
|
|
429
|
-
format_title:
|
|
438
|
+
id: discount.discount?.resource_id || discount.id,
|
|
439
|
+
format_title: discount.discount?.title || discount.format_title,
|
|
430
440
|
isDisabled: true,
|
|
431
441
|
isSelected: true,
|
|
432
|
-
product_id:
|
|
442
|
+
product_id: discount.discount?.product_id || discount.product_id
|
|
433
443
|
});
|
|
434
444
|
}
|
|
435
445
|
}
|
|
436
446
|
});
|
|
437
447
|
}
|
|
438
448
|
});
|
|
439
|
-
const newDiscountList = [
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
return false;
|
|
448
|
-
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
449
|
-
return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
|
|
449
|
+
const newDiscountList = [...editModeDiscountList, ...discountList.filter(item => !item.isDisabled)];
|
|
450
|
+
const isProductFree = id => {
|
|
451
|
+
const targetProduct = productList.find(n => n.id === id);
|
|
452
|
+
if (!targetProduct) return false;
|
|
453
|
+
const product = this.hooks?.getProduct(targetProduct);
|
|
454
|
+
// 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
|
|
455
|
+
// 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
|
|
456
|
+
return Number(product?.total) <= 0 && (Number(product?.origin_total) <= 0 || !product?.origin_total) || (0, _lodashEs.isBoolean)(product?.vouchersApplicable) && !product?.vouchersApplicable;
|
|
450
457
|
};
|
|
451
|
-
const allUsedProductIds = newDiscountList.filter(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}).flat();
|
|
458
|
-
newDiscountList.forEach((item) => {
|
|
459
|
-
var _a2;
|
|
460
|
-
const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|
|
461
|
-
var _a3;
|
|
462
|
-
const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
|
|
463
|
-
const targetIdTimes = (allUsedProductIds == null ? void 0 : allUsedProductIds.filter((n) => n === id).length) || 0;
|
|
458
|
+
const allUsedProductIds = newDiscountList.filter(item => !item?.isEditMode).map(n => n.isSelected ? n.appliedProductDetails?.map(n => n.discount?.product_id) || n.product_id : []).flat();
|
|
459
|
+
newDiscountList.forEach(item => {
|
|
460
|
+
const isAllProductUsedOrFree = item.applicableProductIds?.every(id => {
|
|
461
|
+
// 检查当前 id是否在 item.applicableProductIds 里出现了几次,且要求次数和 item.applicableProductIds 里出现的次数一致
|
|
462
|
+
const sameIdTimes = item.applicableProductIds?.filter(n => n === id).length || 1;
|
|
463
|
+
const targetIdTimes = allUsedProductIds?.filter(n => n === id).length || 0;
|
|
464
464
|
return targetIdTimes >= sameIdTimes || isProductFree(id);
|
|
465
465
|
});
|
|
466
466
|
if (!item.isSelected && isAllProductUsedOrFree) {
|
|
@@ -469,95 +469,89 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
469
469
|
item.isDisabledForProductUsed = false;
|
|
470
470
|
}
|
|
471
471
|
});
|
|
472
|
-
|
|
472
|
+
this.store.discount?.setDiscountList(newDiscountList);
|
|
473
473
|
this.emitDiscountListChange(newDiscountList);
|
|
474
474
|
return newDiscountList;
|
|
475
475
|
}
|
|
476
|
+
|
|
476
477
|
// 获取优惠券列表
|
|
477
478
|
getDiscountList() {
|
|
478
|
-
|
|
479
|
-
return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
479
|
+
return this.store.discount?.getDiscountList() || [];
|
|
480
480
|
}
|
|
481
|
+
|
|
481
482
|
// 获取客户钱包信息
|
|
482
483
|
async getCustomerWallet(id) {
|
|
483
484
|
try {
|
|
484
485
|
const result = await this.request.get(`/customer/info/${id}`, {
|
|
485
486
|
with_trashed: 1
|
|
486
487
|
});
|
|
487
|
-
if (result
|
|
488
|
-
const {
|
|
488
|
+
if (result?.data) {
|
|
489
|
+
const {
|
|
490
|
+
...customer
|
|
491
|
+
} = result.data;
|
|
489
492
|
this.setCustomer(customer);
|
|
490
|
-
await this.core.effects.emit(
|
|
491
|
-
`${this.name}:onScanCustomerChange`,
|
|
492
|
-
customer
|
|
493
|
-
);
|
|
493
|
+
await this.core.effects.emit(`${this.name}:onScanCustomerChange`, customer);
|
|
494
494
|
}
|
|
495
495
|
} catch (error) {
|
|
496
|
-
console.error(
|
|
496
|
+
console.error('[ShopDiscount] 获取客户钱包信息出错:', error);
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
async bestDiscount(cb) {
|
|
500
|
-
var _a;
|
|
501
500
|
const newDiscountList = this.store.originalDiscountList;
|
|
502
501
|
this.setDiscountList(newDiscountList);
|
|
503
|
-
if (
|
|
502
|
+
if (this.store.productList?.length) {
|
|
504
503
|
const result = this.calcDiscount(this.store.productList);
|
|
505
|
-
cb
|
|
506
|
-
await this.core.effects.emit(
|
|
507
|
-
`${this.name}:onLoadPrepareCalcResult`,
|
|
508
|
-
result
|
|
509
|
-
);
|
|
504
|
+
cb?.(result);
|
|
505
|
+
await this.core.effects.emit(`${this.name}:onLoadPrepareCalcResult`, result);
|
|
510
506
|
}
|
|
511
|
-
await this.core.effects.emit(
|
|
512
|
-
`${this.name}:onLoadDiscountList`,
|
|
513
|
-
newDiscountList
|
|
514
|
-
);
|
|
507
|
+
await this.core.effects.emit(`${this.name}:onLoadDiscountList`, newDiscountList);
|
|
515
508
|
}
|
|
509
|
+
|
|
516
510
|
// 加载准备配置
|
|
517
511
|
async loadPrepareConfig(params) {
|
|
518
|
-
var _a, _b, _c, _d, _e;
|
|
519
512
|
try {
|
|
520
513
|
const orderId = this.store.orderId;
|
|
521
|
-
const customerId = params.customerId ||
|
|
522
|
-
|
|
514
|
+
const customerId = params.customerId || this.getCustomer()?.id;
|
|
515
|
+
// if (customerId === 1 || !customerId) {
|
|
516
|
+
// return
|
|
517
|
+
// }
|
|
518
|
+
|
|
519
|
+
const prepareConfigResult = await this.store.discount?.loadPrepareConfig({
|
|
523
520
|
customer_id: customerId,
|
|
524
|
-
action: orderId ?
|
|
521
|
+
action: orderId ? 'edit' : 'create',
|
|
525
522
|
with_good_pass: 1,
|
|
526
523
|
with_discount_card: 1,
|
|
527
524
|
with_wallet_pass_holder: 1,
|
|
528
525
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
529
|
-
...orderId ? {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
);
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
const
|
|
526
|
+
...(orderId ? {
|
|
527
|
+
order_id: orderId
|
|
528
|
+
} : {})
|
|
529
|
+
});
|
|
530
|
+
const goodPassList = prepareConfigResult?.discountList || [];
|
|
531
|
+
const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
|
|
532
|
+
|
|
533
|
+
// goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
|
|
534
|
+
const scanDiscountIds = scanDiscount.map(n => n.id);
|
|
535
|
+
const newGoodPassList = goodPassList?.filter(n => !scanDiscountIds.includes(n.id));
|
|
536
|
+
const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
|
|
537
|
+
|
|
538
|
+
// 存储原始优惠券列表
|
|
538
539
|
this.store.originalDiscountList = newDiscountList;
|
|
539
|
-
await
|
|
540
|
+
await this.store.discount?.setOriginalDiscountList(newDiscountList);
|
|
541
|
+
|
|
542
|
+
// 根据当前预约时间过滤优惠券列表
|
|
540
543
|
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
541
544
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
542
545
|
this.setDiscountList(filteredDiscountList || []);
|
|
543
|
-
if (
|
|
546
|
+
if (this.store.productList?.length) {
|
|
544
547
|
const result = this.calcDiscount(this.store.productList);
|
|
545
|
-
await this.core.effects.emit(
|
|
546
|
-
`${this.name}:onLoadPrepareCalcResult`,
|
|
547
|
-
result
|
|
548
|
-
);
|
|
548
|
+
await this.core.effects.emit(`${this.name}:onLoadPrepareCalcResult`, result);
|
|
549
549
|
}
|
|
550
|
-
await this.core.effects.emit(
|
|
551
|
-
`${this.name}:onLoadDiscountList`,
|
|
552
|
-
filteredDiscountList
|
|
553
|
-
);
|
|
550
|
+
await this.core.effects.emit(`${this.name}:onLoadDiscountList`, filteredDiscountList);
|
|
554
551
|
} catch (error) {
|
|
555
|
-
console.error(
|
|
552
|
+
console.error('[ShopDiscount] 加载准备配置出错:', error);
|
|
556
553
|
}
|
|
557
554
|
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
0 && (module.exports = {
|
|
562
|
-
ShopDiscountImpl
|
|
563
|
-
});
|
|
555
|
+
}
|
|
556
|
+
exports.ShopDiscountImpl = ShopDiscountImpl;
|
|
557
|
+
var _default = exports.default = ShopDiscountImpl;
|