@pisell/pisellos 2.0.38 → 2.0.40
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/modules/AccountList/index.js +17 -12
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +38 -1
- package/dist/modules/Cart/utils/cartProduct.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +23 -5
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +104 -0
- package/dist/modules/Date/index.js +57 -6
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +191 -75
- package/dist/modules/Rules/types.d.ts +7 -1
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +122 -2
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/solution/BookingByStep/index.d.ts +120 -30
- package/dist/solution/BookingByStep/index.js +750 -1078
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/dist/solution/BookingByStep/utils/resources.js +39 -94
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +119 -44
- package/lib/modules/AccountList/index.js +4 -0
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +34 -1
- package/lib/modules/Cart/utils/cartProduct.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +16 -5
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +78 -0
- package/lib/modules/Date/index.js +62 -10
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +17 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +142 -62
- package/lib/modules/Rules/types.d.ts +7 -1
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +79 -1
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/solution/BookingByStep/index.d.ts +120 -30
- package/lib/solution/BookingByStep/index.js +389 -587
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/lib/solution/BookingByStep/utils/resources.js +23 -59
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +91 -19
- package/package.json +1 -1
|
@@ -97,15 +97,78 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
97
97
|
return storeChange;
|
|
98
98
|
}()
|
|
99
99
|
}, {
|
|
100
|
-
key: "
|
|
100
|
+
key: "loadProducts",
|
|
101
101
|
value: function () {
|
|
102
|
-
var
|
|
103
|
-
var _ref$
|
|
102
|
+
var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
103
|
+
var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, cacheId, userPlugin, customer_id, _userPlugin$get, productsData;
|
|
104
104
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
105
105
|
while (1) switch (_context3.prev = _context3.next) {
|
|
106
106
|
case 0:
|
|
107
|
-
_ref$
|
|
108
|
-
|
|
107
|
+
_ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, schedule_date = _ref.schedule_date, cacheId = _ref.cacheId;
|
|
108
|
+
// // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
|
|
109
|
+
// if (!schedule_ids?.length) {
|
|
110
|
+
// const schedule_ids_data = this.store.schedule
|
|
111
|
+
// .getScheduleListByIds(schedule_ids)
|
|
112
|
+
// .map((n) => n.id);
|
|
113
|
+
// if (schedule_ids_data.length) {
|
|
114
|
+
// schedule_ids = schedule_ids_data;
|
|
115
|
+
// } else if (schedule_date) {
|
|
116
|
+
// // 后端说如果 schedule_ids 如果为空,需要给[0]
|
|
117
|
+
// schedule_ids = [0];
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
userPlugin = this.core.getPlugin('user');
|
|
121
|
+
customer_id = undefined;
|
|
122
|
+
try {
|
|
123
|
+
customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get = userPlugin.get()) === null || _userPlugin$get === void 0 ? void 0 : _userPlugin$get.id;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(error);
|
|
126
|
+
}
|
|
127
|
+
// 如果没传schedule_date,则从
|
|
128
|
+
_context3.next = 6;
|
|
129
|
+
return this.request.post("/product/query", {
|
|
130
|
+
open_quotation: 1,
|
|
131
|
+
open_bundle: 0,
|
|
132
|
+
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
133
|
+
with: ['category', 'collection', 'resourceRelation'],
|
|
134
|
+
status: 'published',
|
|
135
|
+
num: 500,
|
|
136
|
+
skip: 1,
|
|
137
|
+
customer_id: customer_id,
|
|
138
|
+
category_ids: category_ids,
|
|
139
|
+
ids: product_ids,
|
|
140
|
+
collection: collection,
|
|
141
|
+
front_end_cache_id: cacheId,
|
|
142
|
+
// client_schedule_ids: schedule_ids,
|
|
143
|
+
schedule_date: schedule_date
|
|
144
|
+
}, {
|
|
145
|
+
useCache: true
|
|
146
|
+
});
|
|
147
|
+
case 6:
|
|
148
|
+
productsData = _context3.sent;
|
|
149
|
+
this.addProduct(productsData.data.list);
|
|
150
|
+
return _context3.abrupt("return", productsData.data.list);
|
|
151
|
+
case 9:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context3.stop();
|
|
154
|
+
}
|
|
155
|
+
}, _callee3, this);
|
|
156
|
+
}));
|
|
157
|
+
function loadProducts(_x5) {
|
|
158
|
+
return _loadProducts.apply(this, arguments);
|
|
159
|
+
}
|
|
160
|
+
return loadProducts;
|
|
161
|
+
}()
|
|
162
|
+
}, {
|
|
163
|
+
key: "loadProductsPrice",
|
|
164
|
+
value: function () {
|
|
165
|
+
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref2) {
|
|
166
|
+
var _ref2$ids, ids, customer_id, schedule_date, channel, productsData;
|
|
167
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
168
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
_ref2$ids = _ref2.ids, ids = _ref2$ids === void 0 ? [] : _ref2$ids, customer_id = _ref2.customer_id, schedule_date = _ref2.schedule_date, channel = _ref2.channel;
|
|
171
|
+
_context4.next = 3;
|
|
109
172
|
return this.request.post("/product/query/price", {
|
|
110
173
|
ids: ids,
|
|
111
174
|
customer_id: customer_id,
|
|
@@ -115,15 +178,15 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
115
178
|
useCache: true
|
|
116
179
|
});
|
|
117
180
|
case 3:
|
|
118
|
-
productsData =
|
|
119
|
-
return
|
|
181
|
+
productsData = _context4.sent;
|
|
182
|
+
return _context4.abrupt("return", productsData.data);
|
|
120
183
|
case 5:
|
|
121
184
|
case "end":
|
|
122
|
-
return
|
|
185
|
+
return _context4.stop();
|
|
123
186
|
}
|
|
124
|
-
},
|
|
187
|
+
}, _callee4, this);
|
|
125
188
|
}));
|
|
126
|
-
function loadProductsPrice(
|
|
189
|
+
function loadProductsPrice(_x6) {
|
|
127
190
|
return _loadProductsPrice.apply(this, arguments);
|
|
128
191
|
}
|
|
129
192
|
return loadProductsPrice;
|
|
@@ -131,19 +194,19 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
131
194
|
}, {
|
|
132
195
|
key: "getProducts",
|
|
133
196
|
value: function () {
|
|
134
|
-
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
135
|
-
return _regeneratorRuntime().wrap(function
|
|
136
|
-
while (1) switch (
|
|
197
|
+
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
198
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
199
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
137
200
|
case 0:
|
|
138
|
-
|
|
201
|
+
_context5.next = 2;
|
|
139
202
|
return this.core.effects.emit(ProductListHooks.onGetProducts, this.store.list);
|
|
140
203
|
case 2:
|
|
141
|
-
return
|
|
204
|
+
return _context5.abrupt("return", cloneDeep(this.store.list));
|
|
142
205
|
case 3:
|
|
143
206
|
case "end":
|
|
144
|
-
return
|
|
207
|
+
return _context5.stop();
|
|
145
208
|
}
|
|
146
|
-
},
|
|
209
|
+
}, _callee5, this);
|
|
147
210
|
}));
|
|
148
211
|
function getProducts() {
|
|
149
212
|
return _getProducts.apply(this, arguments);
|
|
@@ -153,29 +216,29 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
153
216
|
}, {
|
|
154
217
|
key: "getProduct",
|
|
155
218
|
value: function () {
|
|
156
|
-
var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
219
|
+
var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
|
|
157
220
|
var product;
|
|
158
|
-
return _regeneratorRuntime().wrap(function
|
|
159
|
-
while (1) switch (
|
|
221
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
222
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
160
223
|
case 0:
|
|
161
|
-
|
|
224
|
+
_context6.next = 2;
|
|
162
225
|
return this.core.effects.emit(ProductListHooks.onGetProduct, this.store.list);
|
|
163
226
|
case 2:
|
|
164
227
|
product = this.store.productMap.get("".concat(id));
|
|
165
228
|
if (!product) {
|
|
166
|
-
|
|
229
|
+
_context6.next = 5;
|
|
167
230
|
break;
|
|
168
231
|
}
|
|
169
|
-
return
|
|
232
|
+
return _context6.abrupt("return", product);
|
|
170
233
|
case 5:
|
|
171
|
-
return
|
|
234
|
+
return _context6.abrupt("return", undefined);
|
|
172
235
|
case 6:
|
|
173
236
|
case "end":
|
|
174
|
-
return
|
|
237
|
+
return _context6.stop();
|
|
175
238
|
}
|
|
176
|
-
},
|
|
239
|
+
}, _callee6, this);
|
|
177
240
|
}));
|
|
178
|
-
function getProduct(
|
|
241
|
+
function getProduct(_x7) {
|
|
179
242
|
return _getProduct.apply(this, arguments);
|
|
180
243
|
}
|
|
181
244
|
return getProduct;
|
|
@@ -183,10 +246,10 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
183
246
|
}, {
|
|
184
247
|
key: "addProduct",
|
|
185
248
|
value: function () {
|
|
186
|
-
var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
249
|
+
var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(products) {
|
|
187
250
|
var _this3 = this;
|
|
188
|
-
return _regeneratorRuntime().wrap(function
|
|
189
|
-
while (1) switch (
|
|
251
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
252
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
190
253
|
case 0:
|
|
191
254
|
// 加到 list 以后上面的storeChange 会自动初始化商品详情的 module 实例
|
|
192
255
|
// list 需要根据 id 去重
|
|
@@ -206,11 +269,11 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
206
269
|
this.storeChange();
|
|
207
270
|
case 3:
|
|
208
271
|
case "end":
|
|
209
|
-
return
|
|
272
|
+
return _context7.stop();
|
|
210
273
|
}
|
|
211
|
-
},
|
|
274
|
+
}, _callee7, this);
|
|
212
275
|
}));
|
|
213
|
-
function addProduct(
|
|
276
|
+
function addProduct(_x8) {
|
|
214
277
|
return _addProduct.apply(this, arguments);
|
|
215
278
|
}
|
|
216
279
|
return addProduct;
|
|
@@ -218,18 +281,18 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
218
281
|
}, {
|
|
219
282
|
key: "selectProducts",
|
|
220
283
|
value: function () {
|
|
221
|
-
var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
222
|
-
return _regeneratorRuntime().wrap(function
|
|
223
|
-
while (1) switch (
|
|
284
|
+
var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(products) {
|
|
285
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
286
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
224
287
|
case 0:
|
|
225
288
|
this.store.selectProducts = products;
|
|
226
289
|
case 1:
|
|
227
290
|
case "end":
|
|
228
|
-
return
|
|
291
|
+
return _context8.stop();
|
|
229
292
|
}
|
|
230
|
-
},
|
|
293
|
+
}, _callee8, this);
|
|
231
294
|
}));
|
|
232
|
-
function selectProducts(
|
|
295
|
+
function selectProducts(_x9) {
|
|
233
296
|
return _selectProducts.apply(this, arguments);
|
|
234
297
|
}
|
|
235
298
|
return selectProducts;
|
|
@@ -27,6 +27,7 @@ import { BaseModule } from "../BaseModule";
|
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
28
|
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
29
29
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
30
|
+
import Decimal from 'decimal.js';
|
|
30
31
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
31
32
|
_inherits(RulesModule, _BaseModule);
|
|
32
33
|
var _super = _createSuper(RulesModule);
|
|
@@ -106,8 +107,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
//
|
|
110
|
-
|
|
110
|
+
// 编辑商品已有商品券
|
|
111
|
+
if (productList.every(function (item) {
|
|
112
|
+
var _item$discount_list;
|
|
113
|
+
return item.booking_id && (((_item$discount_list = item.discount_list) === null || _item$discount_list === void 0 ? void 0 : _item$discount_list.length) || item.price == 0);
|
|
114
|
+
})) {
|
|
115
|
+
return {
|
|
116
|
+
isAvailable: false,
|
|
117
|
+
discountList: oldDiscountList,
|
|
118
|
+
productList: productList
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 合并新旧折扣列表,并计算折扣结果,注意,如果旧折扣里有 isEditMode 为 true 的优惠券,则不合并
|
|
123
|
+
var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
|
|
124
|
+
return !discount.isEditMode && discount.tag !== 'good_pass';
|
|
125
|
+
});
|
|
126
|
+
var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
|
|
111
127
|
var result = this.calcDiscount({
|
|
112
128
|
discountList: mergedDiscountList,
|
|
113
129
|
productList: _toConsumableArray(productList)
|
|
@@ -148,6 +164,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
148
164
|
var _this3 = this;
|
|
149
165
|
var discountList = _ref2.discountList,
|
|
150
166
|
productList = _ref2.productList;
|
|
167
|
+
// debugger
|
|
168
|
+
|
|
169
|
+
// 识别出来是不是在编辑的界面里又新增了商品
|
|
170
|
+
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
171
|
+
var isEditModeAddNewProduct = productList.find(function (n) {
|
|
172
|
+
return n.booking_id;
|
|
173
|
+
}) && productList.find(function (n) {
|
|
174
|
+
return !n.booking_id;
|
|
175
|
+
});
|
|
151
176
|
var editModeDiscount = [];
|
|
152
177
|
var addModeDiscount = [];
|
|
153
178
|
discountList.forEach(function (discount) {
|
|
@@ -163,24 +188,69 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
163
188
|
return !discount.isManualSelect;
|
|
164
189
|
});
|
|
165
190
|
|
|
166
|
-
//
|
|
191
|
+
// 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
|
|
192
|
+
// 商品券(n.tag=good_pass)视为最优惠(免费),折扣券(n.tag=product_discount_card)按照n.par_value排序
|
|
193
|
+
// 如果最后拍出来商品券有多个,或者说没有商品券,但是有多个相同折扣的折扣券(比如 6 折券有 3张),则按照过期时间(n.expire_time)排序
|
|
167
194
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
195
|
+
// 1. 商品券优先级最高
|
|
196
|
+
if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
|
|
197
|
+
if (b.tag === 'good_pass' && a.tag !== 'good_pass') return 1;
|
|
198
|
+
|
|
199
|
+
// 2. 如果都是商品券或都不是商品券,按照类型和折扣力度排序
|
|
200
|
+
if (a.tag === 'good_pass' && b.tag === 'good_pass') {
|
|
201
|
+
// 都是商品券,按照过期时间排序
|
|
202
|
+
return compareByExpireTime(a, b);
|
|
203
|
+
} else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
204
|
+
// 都是折扣券,按照par_value排序(折扣越大越优先,即par_value越小越优先)
|
|
205
|
+
if (a.par_value !== b.par_value) {
|
|
206
|
+
var valueA = new Decimal(100).minus(a.par_value || 0);
|
|
207
|
+
var valueB = new Decimal(100).minus(b.par_value || 0);
|
|
208
|
+
return valueA.minus(valueB).toNumber();
|
|
209
|
+
}
|
|
210
|
+
// 相同折扣的情况下,按照过期时间排序
|
|
211
|
+
return compareByExpireTime(a, b);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 3. 其他情况按照过期时间排序
|
|
215
|
+
return compareByExpireTime(a, b);
|
|
216
|
+
function compareByExpireTime(itemA, itemB) {
|
|
217
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
218
|
+
var timeA = new Date(itemA.expire_time).getTime();
|
|
219
|
+
var timeB = new Date(itemB.expire_time).getTime();
|
|
220
|
+
return timeA - timeB;
|
|
221
|
+
}
|
|
222
|
+
// 有过期时间的优先级高于永久的
|
|
223
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
172
224
|
}
|
|
173
|
-
// 有过期时间的优先级高于永久的
|
|
174
|
-
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
175
225
|
});
|
|
176
226
|
|
|
177
|
-
//
|
|
227
|
+
// const newProductList = [];
|
|
228
|
+
//
|
|
229
|
+
// productList.forEach(item => {
|
|
230
|
+
// const product = this.hooks.getProduct(item);
|
|
231
|
+
// if (product.quantity > 1) {
|
|
232
|
+
// for (let i = 1; i < product.quantity; i++) {
|
|
233
|
+
// newProductList.push(product)
|
|
234
|
+
// }
|
|
235
|
+
// } else {
|
|
236
|
+
// newProductList.push(item)
|
|
237
|
+
// }
|
|
238
|
+
// })
|
|
239
|
+
|
|
240
|
+
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
178
241
|
var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
|
|
179
242
|
var aProduct = _this3.hooks.getProduct(a);
|
|
180
243
|
var bProduct = _this3.hooks.getProduct(b);
|
|
181
|
-
var priceA =
|
|
182
|
-
var priceB =
|
|
183
|
-
|
|
244
|
+
var priceA = new Decimal(aProduct.price || '0');
|
|
245
|
+
var priceB = new Decimal(bProduct.price || '0');
|
|
246
|
+
if (priceA.toNumber() === priceB.toNumber()) {
|
|
247
|
+
if (aProduct.quantity === bProduct.quantity) {
|
|
248
|
+
var _bProduct$discount_li, _aProduct$discount_li;
|
|
249
|
+
return ((_bProduct$discount_li = bProduct.discount_list) === null || _bProduct$discount_li === void 0 ? void 0 : _bProduct$discount_li.length) - ((_aProduct$discount_li = aProduct.discount_list) === null || _aProduct$discount_li === void 0 ? void 0 : _aProduct$discount_li.length);
|
|
250
|
+
}
|
|
251
|
+
return aProduct.quantity - bProduct.quantity;
|
|
252
|
+
}
|
|
253
|
+
return priceB.toNumber() - priceA.toNumber();
|
|
184
254
|
});
|
|
185
255
|
|
|
186
256
|
// 标记已使用的优惠券
|
|
@@ -216,7 +286,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
216
286
|
|
|
217
287
|
// 编辑的商品 使用了优惠券不可用
|
|
218
288
|
var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.every(function (discount) {
|
|
219
|
-
return discount.id && discount.
|
|
289
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
220
290
|
}));
|
|
221
291
|
|
|
222
292
|
// 判断优惠券是否适用于该商品
|
|
@@ -229,33 +299,41 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
229
299
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
230
300
|
applicableProducts.push({
|
|
231
301
|
amount: product.price,
|
|
232
|
-
type: discount.tag,
|
|
302
|
+
type: discount.tag || discount.type,
|
|
303
|
+
tag: discount.tag || discount.type,
|
|
233
304
|
discount: {
|
|
234
305
|
resource_id: discount.id,
|
|
235
306
|
title: discount.format_title,
|
|
236
|
-
original_amount: product.origin_total
|
|
237
|
-
|
|
307
|
+
original_amount: product.origin_total,
|
|
308
|
+
pre_value: discount.par_value,
|
|
309
|
+
product_id: originProduct.id
|
|
310
|
+
},
|
|
311
|
+
num: product.num || 1
|
|
238
312
|
});
|
|
239
313
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
240
314
|
}
|
|
241
315
|
});
|
|
242
316
|
});
|
|
317
|
+
console.log(sortedProductList, 'sortedProductListsortedProductList');
|
|
243
318
|
|
|
244
319
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
245
|
-
sortedProductList.forEach(function (originProduct) {
|
|
246
|
-
var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
|
|
320
|
+
sortedProductList.forEach(function (originProduct, i) {
|
|
321
|
+
var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7, _product$discount_lis8;
|
|
247
322
|
var product = _this3.hooks.getProduct(originProduct);
|
|
248
323
|
if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
|
|
249
|
-
return discount.id && discount.
|
|
324
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
250
325
|
})) {
|
|
251
|
-
processedProductsMap.set(product._id, originProduct);
|
|
326
|
+
processedProductsMap.set(product._id, [originProduct]);
|
|
252
327
|
return;
|
|
253
328
|
}
|
|
254
329
|
|
|
255
330
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
256
331
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
332
|
+
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
333
|
+
if (Number(product.price) === 0 || !product.price) return false;
|
|
257
334
|
// 如果优惠券已被使用,则跳过
|
|
258
|
-
|
|
335
|
+
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
336
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
259
337
|
var limitedData = discount.limited_relation_product_data;
|
|
260
338
|
|
|
261
339
|
// 判断优惠券是否适用于该商品
|
|
@@ -276,14 +354,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
276
354
|
})));
|
|
277
355
|
|
|
278
356
|
// 勾选时覆盖手动折扣
|
|
279
|
-
if (options !== null && options !== void 0 && options.discountId && (
|
|
357
|
+
if (options !== null && options !== void 0 && options.discountId && (_product$discount_lis8 = product.discount_list) !== null && _product$discount_lis8 !== void 0 && _product$discount_lis8.some(function (item) {
|
|
358
|
+
var _item$discount;
|
|
359
|
+
return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
|
|
360
|
+
})) {
|
|
280
361
|
isManualDiscount = false;
|
|
281
362
|
}
|
|
282
363
|
|
|
283
364
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
284
365
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
285
366
|
if (product.isClient) {
|
|
286
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
367
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
287
368
|
origin_total: getProductOriginTotalPrice({
|
|
288
369
|
product: {
|
|
289
370
|
original_price: product.original_price
|
|
@@ -291,6 +372,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
291
372
|
bundle: product.bundle,
|
|
292
373
|
options: product.options
|
|
293
374
|
}),
|
|
375
|
+
variant: originProduct._productInit.variant,
|
|
376
|
+
original_price: originProduct._productInit.original_price,
|
|
294
377
|
total: getProductTotalPrice({
|
|
295
378
|
product: {
|
|
296
379
|
price: product.price
|
|
@@ -301,72 +384,98 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
301
384
|
price: product.price
|
|
302
385
|
}), {}, {
|
|
303
386
|
discount_list: []
|
|
304
|
-
})));
|
|
387
|
+
}))]);
|
|
305
388
|
} else {
|
|
306
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
389
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
390
|
+
_id: product._id.split('___')[0] + '___' + i,
|
|
307
391
|
total: product.origin_total || product.total,
|
|
308
392
|
price: product.price
|
|
309
393
|
}), {}, {
|
|
310
394
|
discount_list: []
|
|
311
|
-
})));
|
|
395
|
+
}))]);
|
|
312
396
|
}
|
|
313
397
|
return;
|
|
314
398
|
}
|
|
315
|
-
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan)) {
|
|
399
|
+
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct) {
|
|
316
400
|
return;
|
|
317
401
|
}
|
|
318
402
|
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
var
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
appliedProducts.push(discountDetail);
|
|
335
|
-
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
336
|
-
|
|
337
|
-
// 记录应用了优惠券的商品
|
|
338
|
-
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
339
|
-
if (product.isClient) {
|
|
340
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
341
|
-
discount_list: [discountDetail],
|
|
342
|
-
price: 0,
|
|
343
|
-
origin_total: getProductOriginTotalPrice({
|
|
344
|
-
product: {
|
|
345
|
-
original_price: product.original_price
|
|
346
|
-
},
|
|
347
|
-
bundle: product.bundle,
|
|
348
|
-
options: product.options
|
|
349
|
-
}),
|
|
350
|
-
total: getProductTotalPrice({
|
|
351
|
-
product: {
|
|
352
|
-
price: '0'
|
|
353
|
-
},
|
|
354
|
-
bundle: product.bundle,
|
|
355
|
-
options: product.options
|
|
356
|
-
})
|
|
357
|
-
}));
|
|
358
|
-
} else {
|
|
359
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
360
|
-
discount_list: [discountDetail],
|
|
361
|
-
price: 0,
|
|
362
|
-
total: (product.origin_total || product.total) - product.price,
|
|
363
|
-
origin_total: product.origin_total || product.total
|
|
403
|
+
// 是否需要拆分
|
|
404
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
405
|
+
|
|
406
|
+
// 需要拆分出来的数量
|
|
407
|
+
var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter(function (item) {
|
|
408
|
+
return (item.tag || item.type) === 'good_pass';
|
|
409
|
+
}).length) : 1;
|
|
410
|
+
var arr = [];
|
|
411
|
+
if (splitCount < product.quantity && isNeedSplit) {
|
|
412
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
413
|
+
discount_list: [],
|
|
414
|
+
quantity: product.quantity - splitCount,
|
|
415
|
+
_id: product._id.split('___')[0]
|
|
364
416
|
}));
|
|
365
417
|
}
|
|
418
|
+
for (var _i = 0; _i < splitCount; _i++) {
|
|
419
|
+
var _selectedDiscount = applicableDiscounts[_i];
|
|
420
|
+
// 标记优惠券为已使用
|
|
421
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
422
|
+
|
|
423
|
+
// 记录实际应用了优惠券的商品信息
|
|
424
|
+
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
425
|
+
|
|
426
|
+
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
427
|
+
var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(product.origin_total || 0).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.origin_total || 0)).toNumber();
|
|
428
|
+
var discountDetail = {
|
|
429
|
+
amount: new Decimal(product.origin_total || 0).minus(new Decimal(targetProductTotal)).toNumber(),
|
|
430
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
|
|
431
|
+
discount: {
|
|
432
|
+
resource_id: _selectedDiscount.id,
|
|
433
|
+
title: _selectedDiscount.format_title,
|
|
434
|
+
original_amount: product.origin_total,
|
|
435
|
+
product_id: originProduct.id,
|
|
436
|
+
percent: _selectedDiscount.par_value
|
|
437
|
+
},
|
|
438
|
+
num: product.num || 1
|
|
439
|
+
};
|
|
440
|
+
appliedProducts.push(discountDetail);
|
|
441
|
+
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
442
|
+
|
|
443
|
+
// 记录应用了优惠券的商品
|
|
444
|
+
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
445
|
+
if (product.isClient) {
|
|
446
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
447
|
+
discount_list: [discountDetail],
|
|
448
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
449
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
450
|
+
origin_total: getProductOriginTotalPrice({
|
|
451
|
+
product: {
|
|
452
|
+
original_price: product.original_price
|
|
453
|
+
},
|
|
454
|
+
bundle: product.bundle,
|
|
455
|
+
options: product.options
|
|
456
|
+
}),
|
|
457
|
+
variant: originProduct._productInit.variant,
|
|
458
|
+
original_price: new Decimal(product.price || 0).toNumber(),
|
|
459
|
+
total: targetProductTotal
|
|
460
|
+
}));
|
|
461
|
+
} else {
|
|
462
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
463
|
+
discount_list: [discountDetail],
|
|
464
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
|
|
465
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
466
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
467
|
+
total: targetProductTotal,
|
|
468
|
+
origin_total: product.origin_total || product.total
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
console.log(arr, 'arrarrarr');
|
|
473
|
+
processedProductsMap.set(product._id, arr);
|
|
366
474
|
});
|
|
367
475
|
|
|
368
476
|
// 按原始顺序构建处理后的商品列表
|
|
369
|
-
var processedProductList =
|
|
477
|
+
var processedProductList = [];
|
|
478
|
+
productList.forEach(function (originProduct) {
|
|
370
479
|
var product = _this3.hooks.getProduct(originProduct);
|
|
371
480
|
var getDefaultProduct = function getDefaultProduct() {
|
|
372
481
|
if (product.isClient) {
|
|
@@ -380,6 +489,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
380
489
|
bundle: product.bundle,
|
|
381
490
|
options: product.options
|
|
382
491
|
}),
|
|
492
|
+
variant: originProduct._productInit.variant,
|
|
493
|
+
original_price: originProduct._productInit.original_price,
|
|
383
494
|
total: getProductTotalPrice({
|
|
384
495
|
product: {
|
|
385
496
|
price: product.price
|
|
@@ -397,7 +508,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
397
508
|
});
|
|
398
509
|
}
|
|
399
510
|
};
|
|
400
|
-
|
|
511
|
+
var arr = processedProductsMap.get(product._id);
|
|
512
|
+
arr !== null && arr !== void 0 && arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
|
|
401
513
|
});
|
|
402
514
|
|
|
403
515
|
// 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
|
|
@@ -430,6 +542,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
430
542
|
if (usedDiscounts.get(discount.id)) {
|
|
431
543
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
432
544
|
isSelected: true,
|
|
545
|
+
isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
|
|
433
546
|
// 标记为可用,因为它已被应用
|
|
434
547
|
isAvailable: true,
|
|
435
548
|
// 记录适用的商品IDs
|
|
@@ -452,6 +565,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
452
565
|
// 如果有适用的商品,标记为可用
|
|
453
566
|
isAvailable: isAvailable,
|
|
454
567
|
isSelected: isSelected,
|
|
568
|
+
// 如果是扫码进来的,要手动设置为手动选择:false
|
|
569
|
+
isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
|
|
455
570
|
// 记录适用的商品IDs
|
|
456
571
|
applicableProductIds: applicableProducts,
|
|
457
572
|
// 添加可抵扣的商品详情
|
|
@@ -460,6 +575,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
460
575
|
appliedProductDetails: []
|
|
461
576
|
});
|
|
462
577
|
});
|
|
578
|
+
console.log(processedProductList, 'processedProductList');
|
|
463
579
|
return {
|
|
464
580
|
productList: processedProductList,
|
|
465
581
|
discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
|
|
@@ -37,14 +37,20 @@ type ProductDetail = {
|
|
|
37
37
|
options?: any[];
|
|
38
38
|
bundle?: any[];
|
|
39
39
|
original_price?: number | string;
|
|
40
|
+
num?: number;
|
|
41
|
+
quantity: number;
|
|
40
42
|
};
|
|
41
43
|
export interface RulesParamsHooks {
|
|
42
44
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
43
45
|
setProduct: (product: Record<string, any>, values: {
|
|
46
|
+
_id?: string;
|
|
44
47
|
total?: number;
|
|
45
48
|
discount_list: any[];
|
|
46
49
|
origin_total?: number;
|
|
47
|
-
price?: number;
|
|
50
|
+
price?: string | number;
|
|
51
|
+
variant?: any[];
|
|
52
|
+
original_price?: number;
|
|
53
|
+
quantity?: number;
|
|
48
54
|
}) => Record<string, any>;
|
|
49
55
|
}
|
|
50
56
|
export {};
|