@pisell/pisellos 2.0.2 → 2.0.4
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/Rules/index.js +86 -18
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/solution/BookingByStep/index.js +6 -0
- package/lib/modules/Rules/index.js +100 -25
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/solution/BookingByStep/index.js +6 -0
- package/package.json +2 -2
|
@@ -26,6 +26,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
26
26
|
import { BaseModule } from "../BaseModule";
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
28
|
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
29
|
+
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
29
30
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
30
31
|
_inherits(RulesModule, _BaseModule);
|
|
31
32
|
var _super = _createSuper(RulesModule);
|
|
@@ -277,12 +278,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
277
278
|
|
|
278
279
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
279
280
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
281
|
+
if (product.isClient) {
|
|
282
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
283
|
+
origin_total: getProductOriginTotalPrice({
|
|
284
|
+
product: {
|
|
285
|
+
original_price: product.original_price
|
|
286
|
+
},
|
|
287
|
+
bundle: product.bundle,
|
|
288
|
+
options: product.options
|
|
289
|
+
}),
|
|
290
|
+
total: getProductTotalPrice({
|
|
291
|
+
product: {
|
|
292
|
+
price: product.price
|
|
293
|
+
},
|
|
294
|
+
bundle: product.bundle,
|
|
295
|
+
options: product.options
|
|
296
|
+
}),
|
|
297
|
+
price: product.price
|
|
298
|
+
}), {}, {
|
|
299
|
+
discount_list: []
|
|
300
|
+
})));
|
|
301
|
+
} else {
|
|
302
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
303
|
+
total: product.origin_total || product.total,
|
|
304
|
+
price: product.price
|
|
305
|
+
}), {}, {
|
|
306
|
+
discount_list: []
|
|
307
|
+
})));
|
|
308
|
+
}
|
|
286
309
|
return;
|
|
287
310
|
}
|
|
288
311
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined') {
|
|
@@ -309,23 +332,68 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
309
332
|
|
|
310
333
|
// 记录应用了优惠券的商品
|
|
311
334
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
335
|
+
if (product.isClient) {
|
|
336
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
337
|
+
discount_list: [discountDetail],
|
|
338
|
+
price: 0,
|
|
339
|
+
origin_total: getProductOriginTotalPrice({
|
|
340
|
+
product: {
|
|
341
|
+
original_price: product.original_price
|
|
342
|
+
},
|
|
343
|
+
bundle: product.bundle,
|
|
344
|
+
options: product.options
|
|
345
|
+
}),
|
|
346
|
+
total: getProductTotalPrice({
|
|
347
|
+
product: {
|
|
348
|
+
price: '0'
|
|
349
|
+
},
|
|
350
|
+
bundle: product.bundle,
|
|
351
|
+
options: product.options
|
|
352
|
+
})
|
|
353
|
+
}));
|
|
354
|
+
} else {
|
|
355
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
356
|
+
discount_list: [discountDetail],
|
|
357
|
+
price: 0,
|
|
358
|
+
total: (product.origin_total || product.total) - product.price,
|
|
359
|
+
origin_total: product.origin_total || product.total
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
318
362
|
});
|
|
319
363
|
|
|
320
364
|
// 按原始顺序构建处理后的商品列表
|
|
321
365
|
var processedProductList = productList.map(function (originProduct) {
|
|
322
366
|
var product = _this3.hooks.getProduct(originProduct);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
367
|
+
var getDefaultProduct = function getDefaultProduct() {
|
|
368
|
+
if (product.isClient) {
|
|
369
|
+
_this3.hooks.setProduct(originProduct, {
|
|
370
|
+
discount_list: [],
|
|
371
|
+
price: product.price,
|
|
372
|
+
origin_total: getProductOriginTotalPrice({
|
|
373
|
+
product: {
|
|
374
|
+
original_price: product.original_price
|
|
375
|
+
},
|
|
376
|
+
bundle: product.bundle,
|
|
377
|
+
options: product.options
|
|
378
|
+
}),
|
|
379
|
+
total: getProductTotalPrice({
|
|
380
|
+
product: {
|
|
381
|
+
price: product.price
|
|
382
|
+
},
|
|
383
|
+
bundle: product.bundle,
|
|
384
|
+
options: product.options
|
|
385
|
+
})
|
|
386
|
+
});
|
|
387
|
+
} else {
|
|
388
|
+
_this3.hooks.setProduct(originProduct, {
|
|
389
|
+
discount_list: [],
|
|
390
|
+
total: product.total,
|
|
391
|
+
origin_total: product.origin_total,
|
|
392
|
+
price: product.price
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
return processedProductsMap.get(product._id) || getDefaultProduct();
|
|
329
397
|
});
|
|
330
398
|
|
|
331
399
|
// 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
|
|
@@ -25,6 +25,7 @@ export interface RulesModuleAPI {
|
|
|
25
25
|
}) => DiscountResult;
|
|
26
26
|
}
|
|
27
27
|
type ProductDetail = {
|
|
28
|
+
isClient?: boolean;
|
|
28
29
|
isManualDiscount?: boolean;
|
|
29
30
|
booking_id: any;
|
|
30
31
|
id: number;
|
|
@@ -33,6 +34,9 @@ type ProductDetail = {
|
|
|
33
34
|
discount_list: Discount[];
|
|
34
35
|
origin_total: number;
|
|
35
36
|
_id: string;
|
|
37
|
+
options?: any[];
|
|
38
|
+
bundle?: any[];
|
|
39
|
+
original_price?: number | string;
|
|
36
40
|
};
|
|
37
41
|
export interface RulesParamsHooks {
|
|
38
42
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
@@ -681,6 +681,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
681
681
|
key: "updateCart",
|
|
682
682
|
value: function updateCart(params) {
|
|
683
683
|
var _this5 = this;
|
|
684
|
+
if (params.resources) {
|
|
685
|
+
params.resources = params.resources.map(function (n) {
|
|
686
|
+
n.capacity = 1;
|
|
687
|
+
return n;
|
|
688
|
+
});
|
|
689
|
+
}
|
|
684
690
|
this.store.cart.updateItem(params);
|
|
685
691
|
var targetCartItem = this.store.cart.getItem(params._id);
|
|
686
692
|
if (!targetCartItem) {
|
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(Rules_exports);
|
|
|
25
25
|
var import_BaseModule = require("../BaseModule");
|
|
26
26
|
var import_types = require("./types");
|
|
27
27
|
var import_utils = require("../../solution/ShopDiscount/utils");
|
|
28
|
+
var import_utils2 = require("../Cart/utils");
|
|
28
29
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
29
30
|
constructor(name, version) {
|
|
30
31
|
super(name, version);
|
|
@@ -174,16 +175,42 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
174
175
|
isManualDiscount = false;
|
|
175
176
|
}
|
|
176
177
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
if (product.isClient) {
|
|
179
|
+
processedProductsMap.set(
|
|
180
|
+
product._id,
|
|
181
|
+
this.hooks.setProduct(originProduct, {
|
|
182
|
+
...isManualDiscount ? {} : {
|
|
183
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
184
|
+
product: {
|
|
185
|
+
original_price: product.original_price
|
|
186
|
+
},
|
|
187
|
+
bundle: product.bundle,
|
|
188
|
+
options: product.options
|
|
189
|
+
}),
|
|
190
|
+
total: (0, import_utils2.getProductTotalPrice)({
|
|
191
|
+
product: {
|
|
192
|
+
price: product.price
|
|
193
|
+
},
|
|
194
|
+
bundle: product.bundle,
|
|
195
|
+
options: product.options
|
|
196
|
+
}),
|
|
197
|
+
price: product.price
|
|
198
|
+
},
|
|
199
|
+
discount_list: []
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
} else {
|
|
203
|
+
processedProductsMap.set(
|
|
204
|
+
product._id,
|
|
205
|
+
this.hooks.setProduct(originProduct, {
|
|
206
|
+
...isManualDiscount ? {} : {
|
|
207
|
+
total: product.origin_total || product.total,
|
|
208
|
+
price: product.price
|
|
209
|
+
},
|
|
210
|
+
discount_list: []
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
}
|
|
187
214
|
return;
|
|
188
215
|
}
|
|
189
216
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined") {
|
|
@@ -203,24 +230,72 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
203
230
|
};
|
|
204
231
|
appliedProducts.push(discountDetail);
|
|
205
232
|
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
233
|
+
if (product.isClient) {
|
|
234
|
+
processedProductsMap.set(
|
|
235
|
+
product._id,
|
|
236
|
+
this.hooks.setProduct(originProduct, {
|
|
237
|
+
discount_list: [discountDetail],
|
|
238
|
+
price: 0,
|
|
239
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
240
|
+
product: {
|
|
241
|
+
original_price: product.original_price
|
|
242
|
+
},
|
|
243
|
+
bundle: product.bundle,
|
|
244
|
+
options: product.options
|
|
245
|
+
}),
|
|
246
|
+
total: (0, import_utils2.getProductTotalPrice)({
|
|
247
|
+
product: {
|
|
248
|
+
price: "0"
|
|
249
|
+
},
|
|
250
|
+
bundle: product.bundle,
|
|
251
|
+
options: product.options
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
} else {
|
|
256
|
+
processedProductsMap.set(
|
|
257
|
+
product._id,
|
|
258
|
+
this.hooks.setProduct(originProduct, {
|
|
259
|
+
discount_list: [discountDetail],
|
|
260
|
+
price: 0,
|
|
261
|
+
total: (product.origin_total || product.total) - product.price,
|
|
262
|
+
origin_total: product.origin_total || product.total
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
}
|
|
215
266
|
});
|
|
216
267
|
const processedProductList = productList.map((originProduct) => {
|
|
217
268
|
const product = this.hooks.getProduct(originProduct);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
269
|
+
const getDefaultProduct = () => {
|
|
270
|
+
if (product.isClient) {
|
|
271
|
+
this.hooks.setProduct(originProduct, {
|
|
272
|
+
discount_list: [],
|
|
273
|
+
price: product.price,
|
|
274
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
275
|
+
product: {
|
|
276
|
+
original_price: product.original_price
|
|
277
|
+
},
|
|
278
|
+
bundle: product.bundle,
|
|
279
|
+
options: product.options
|
|
280
|
+
}),
|
|
281
|
+
total: (0, import_utils2.getProductTotalPrice)({
|
|
282
|
+
product: {
|
|
283
|
+
price: product.price
|
|
284
|
+
},
|
|
285
|
+
bundle: product.bundle,
|
|
286
|
+
options: product.options
|
|
287
|
+
})
|
|
288
|
+
});
|
|
289
|
+
} else {
|
|
290
|
+
this.hooks.setProduct(originProduct, {
|
|
291
|
+
discount_list: [],
|
|
292
|
+
total: product.total,
|
|
293
|
+
origin_total: product.origin_total,
|
|
294
|
+
price: product.price
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
return processedProductsMap.get(product._id) || getDefaultProduct();
|
|
224
299
|
});
|
|
225
300
|
const updatedDiscountList = addModeDiscount.map((discount) => {
|
|
226
301
|
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
@@ -25,6 +25,7 @@ export interface RulesModuleAPI {
|
|
|
25
25
|
}) => DiscountResult;
|
|
26
26
|
}
|
|
27
27
|
type ProductDetail = {
|
|
28
|
+
isClient?: boolean;
|
|
28
29
|
isManualDiscount?: boolean;
|
|
29
30
|
booking_id: any;
|
|
30
31
|
id: number;
|
|
@@ -33,6 +34,9 @@ type ProductDetail = {
|
|
|
33
34
|
discount_list: Discount[];
|
|
34
35
|
origin_total: number;
|
|
35
36
|
_id: string;
|
|
37
|
+
options?: any[];
|
|
38
|
+
bundle?: any[];
|
|
39
|
+
original_price?: number | string;
|
|
36
40
|
};
|
|
37
41
|
export interface RulesParamsHooks {
|
|
38
42
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
@@ -295,6 +295,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
295
295
|
}
|
|
296
296
|
// 更新购物车
|
|
297
297
|
updateCart(params) {
|
|
298
|
+
if (params.resources) {
|
|
299
|
+
params.resources = params.resources.map((n) => {
|
|
300
|
+
n.capacity = 1;
|
|
301
|
+
return n;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
298
304
|
this.store.cart.updateItem(params);
|
|
299
305
|
const targetCartItem = this.store.cart.getItem(params._id);
|
|
300
306
|
if (!targetCartItem) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@pisell/pisellos",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.4",
|
|
5
5
|
"description": "一个可扩展的前端模块化SDK框架,支持插件系统",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"docs": "typedoc --out docs src/index.ts",
|
|
22
22
|
"sync": "node sync.js",
|
|
23
23
|
"prepublishOnly": "npm run build",
|
|
24
|
-
"deploy": "yarn run build && yarn run changeset && yarn run version &&
|
|
24
|
+
"deploy": "yarn run build && yarn run changeset && yarn run version && npm run release"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|