@pisell/pisellos 0.0.145 → 0.0.147
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/Discount/types.d.ts +2 -0
- package/dist/modules/Rules/index.js +2 -0
- package/dist/solution/ShopDiscount/index.js +35 -12
- package/lib/modules/Discount/types.d.ts +2 -0
- package/lib/modules/Rules/index.js +2 -0
- package/lib/solution/ShopDiscount/index.js +32 -12
- package/package.json +1 -1
|
@@ -61,6 +61,8 @@ export interface Discount {
|
|
|
61
61
|
applicableProductIds?: number[];
|
|
62
62
|
applicableProductDetails: ApplicableProductDetails[];
|
|
63
63
|
appliedProductDetails: ApplicableProductDetails[];
|
|
64
|
+
isDisabledForProductUsed?: boolean;
|
|
65
|
+
amount?: number;
|
|
64
66
|
}
|
|
65
67
|
export interface DiscountState {
|
|
66
68
|
discountList: Discount[];
|
|
@@ -282,6 +282,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
282
282
|
|
|
283
283
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
284
284
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
285
|
+
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
286
|
+
if (Number(product.price) === 0 || !product.price) return false;
|
|
285
287
|
// 如果优惠券已被使用,则跳过
|
|
286
288
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
287
289
|
if (targetUsedDiscounts && discount.type === 'good_pass') return false;
|
|
@@ -441,18 +441,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
441
441
|
var product = (_this3$hooks = _this3.hooks) === null || _this3$hooks === void 0 ? void 0 : _this3$hooks.getProduct(item);
|
|
442
442
|
(item.discount_list || []).forEach(function (discount) {
|
|
443
443
|
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
444
|
-
var
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
444
|
+
var index = editModeDiscountList.findIndex(function (n) {
|
|
445
|
+
return n.id === discount.id;
|
|
446
|
+
});
|
|
447
|
+
if (index !== -1) {
|
|
448
|
+
editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
|
|
449
|
+
amount: discount.amount + editModeDiscountList[index].amount
|
|
450
|
+
});
|
|
451
|
+
} else {
|
|
452
|
+
var _discount$discount, _discount$discount2, _discount$discount3;
|
|
453
|
+
editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
|
|
454
|
+
isEditMode: true,
|
|
455
|
+
limited_relation_product_data: {},
|
|
456
|
+
savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
|
|
457
|
+
isAvailable: true,
|
|
458
|
+
id: ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id,
|
|
459
|
+
format_title: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.title) || discount.format_title,
|
|
460
|
+
isDisabled: true,
|
|
461
|
+
isSelected: true,
|
|
462
|
+
product_id: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.product_id) || discount.product_id
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
456
465
|
}
|
|
457
466
|
});
|
|
458
467
|
}
|
|
@@ -460,6 +469,20 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
460
469
|
var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
|
|
461
470
|
return !item.isDisabled;
|
|
462
471
|
})));
|
|
472
|
+
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
473
|
+
return n.isSelected ? n.applicableProductIds : [];
|
|
474
|
+
}).flat();
|
|
475
|
+
newDiscountList.forEach(function (item) {
|
|
476
|
+
var _item$applicableProdu;
|
|
477
|
+
var isAllProductUsed = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
|
|
478
|
+
return allUsedProductIds === null || allUsedProductIds === void 0 ? void 0 : allUsedProductIds.includes(id);
|
|
479
|
+
});
|
|
480
|
+
if (!item.isSelected && isAllProductUsed) {
|
|
481
|
+
item.isDisabledForProductUsed = true;
|
|
482
|
+
} else {
|
|
483
|
+
item.isDisabledForProductUsed = false;
|
|
484
|
+
}
|
|
485
|
+
});
|
|
463
486
|
(_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
|
|
464
487
|
this.emitDiscountListChange(newDiscountList);
|
|
465
488
|
return newDiscountList;
|
|
@@ -61,6 +61,8 @@ export interface Discount {
|
|
|
61
61
|
applicableProductIds?: number[];
|
|
62
62
|
applicableProductDetails: ApplicableProductDetails[];
|
|
63
63
|
appliedProductDetails: ApplicableProductDetails[];
|
|
64
|
+
isDisabledForProductUsed?: boolean;
|
|
65
|
+
amount?: number;
|
|
64
66
|
}
|
|
65
67
|
export interface DiscountState {
|
|
66
68
|
discountList: Discount[];
|
|
@@ -191,6 +191,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
191
191
|
return;
|
|
192
192
|
}
|
|
193
193
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
194
|
+
if (Number(product.price) === 0 || !product.price)
|
|
195
|
+
return false;
|
|
194
196
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
195
197
|
if (targetUsedDiscounts && discount.type === "good_pass")
|
|
196
198
|
return false;
|
|
@@ -276,18 +276,26 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
276
276
|
(item.discount_list || []).forEach((discount) => {
|
|
277
277
|
var _a3, _b, _c;
|
|
278
278
|
if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
|
|
279
|
-
editModeDiscountList.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
279
|
+
const index = editModeDiscountList.findIndex((n) => n.id === discount.id);
|
|
280
|
+
if (index !== -1) {
|
|
281
|
+
editModeDiscountList[index] = {
|
|
282
|
+
...editModeDiscountList[index],
|
|
283
|
+
amount: discount.amount + editModeDiscountList[index].amount
|
|
284
|
+
};
|
|
285
|
+
} else {
|
|
286
|
+
editModeDiscountList.push({
|
|
287
|
+
...discount,
|
|
288
|
+
isEditMode: true,
|
|
289
|
+
limited_relation_product_data: {},
|
|
290
|
+
savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
|
|
291
|
+
isAvailable: true,
|
|
292
|
+
id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
|
|
293
|
+
format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
|
|
294
|
+
isDisabled: true,
|
|
295
|
+
isSelected: true,
|
|
296
|
+
product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
|
|
297
|
+
});
|
|
298
|
+
}
|
|
291
299
|
}
|
|
292
300
|
});
|
|
293
301
|
}
|
|
@@ -296,6 +304,18 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
296
304
|
...editModeDiscountList,
|
|
297
305
|
...discountList.filter((item) => !item.isDisabled)
|
|
298
306
|
];
|
|
307
|
+
const allUsedProductIds = newDiscountList.map((n) => n.isSelected ? n.applicableProductIds : []).flat();
|
|
308
|
+
newDiscountList.forEach((item) => {
|
|
309
|
+
var _a2;
|
|
310
|
+
const isAllProductUsed = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|
|
311
|
+
return allUsedProductIds == null ? void 0 : allUsedProductIds.includes(id);
|
|
312
|
+
});
|
|
313
|
+
if (!item.isSelected && isAllProductUsed) {
|
|
314
|
+
item.isDisabledForProductUsed = true;
|
|
315
|
+
} else {
|
|
316
|
+
item.isDisabledForProductUsed = false;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
299
319
|
(_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
|
|
300
320
|
this.emitDiscountListChange(newDiscountList);
|
|
301
321
|
return newDiscountList;
|