@pisell/pisellos 0.0.150 → 0.0.152

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.
@@ -149,6 +149,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
149
149
  var _this3 = this;
150
150
  var discountList = _ref2.discountList,
151
151
  productList = _ref2.productList;
152
+ // debugger
153
+
154
+ // 识别出来是不是在编辑的界面里又新增了商品
155
+ // 这种情况下,如果有可用的优惠券,也会自动勾选上
156
+ var isEditModeAddNewProduct = productList.find(function (n) {
157
+ return n.booking_id;
158
+ }) && productList.find(function (n) {
159
+ return !n.booking_id;
160
+ });
152
161
  var editModeDiscount = [];
153
162
  var addModeDiscount = [];
154
163
  discountList.forEach(function (discount) {
@@ -262,7 +271,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
262
271
 
263
272
  // 编辑的商品 使用了优惠券不可用
264
273
  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) {
265
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
274
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
266
275
  }));
267
276
 
268
277
  // 判断优惠券是否适用于该商品
@@ -275,7 +284,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
275
284
  var applicableProducts = discountApplicableProducts.get(discount.id) || [];
276
285
  applicableProducts.push({
277
286
  amount: product.price,
278
- type: discount.tag,
287
+ type: discount.tag || discount.type,
288
+ tag: discount.tag || discount.type,
279
289
  discount: {
280
290
  resource_id: discount.id,
281
291
  title: discount.format_title,
@@ -296,7 +306,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
296
306
  var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
297
307
  var product = _this3.hooks.getProduct(originProduct);
298
308
  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) {
299
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
309
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
300
310
  })) {
301
311
  processedProductsMap.set(product._id, [originProduct]);
302
312
  return;
@@ -308,7 +318,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
308
318
  if (Number(product.price) === 0 || !product.price) return false;
309
319
  // 如果优惠券已被使用,则跳过
310
320
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
311
- if (targetUsedDiscounts && discount.tag === 'good_pass') return false;
321
+ if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
312
322
  var limitedData = discount.limited_relation_product_data;
313
323
 
314
324
  // 判断优惠券是否适用于该商品
@@ -369,15 +379,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
369
379
  }
370
380
  return;
371
381
  }
372
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan)) {
382
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct) {
373
383
  return;
374
384
  }
375
385
 
386
+ // 是否需要拆分
387
+ var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
388
+
376
389
  // 需要拆分出来的数量
377
- var splitCount = Math.min(product.quantity, applicableDiscounts.length);
378
- debugger;
390
+ var splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter(function (item) {
391
+ return (item.tag || item.type) === 'good_pass';
392
+ }).length) : 1;
379
393
  var arr = [];
380
- if (splitCount < product.quantity) {
394
+ if (splitCount < product.quantity && isNeedSplit) {
381
395
  arr.push(_this3.hooks.setProduct(originProduct, {
382
396
  discount_list: [],
383
397
  quantity: product.quantity - splitCount,
@@ -413,7 +427,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
413
427
  arr.push(_this3.hooks.setProduct(originProduct, {
414
428
  discount_list: [discountDetail],
415
429
  price: new Decimal(targetProductPrice).toNumber(),
416
- quantity: 1,
430
+ quantity: isNeedSplit ? 1 : product.quantity,
417
431
  origin_total: getProductOriginTotalPrice({
418
432
  product: {
419
433
  original_price: product.original_price
@@ -434,7 +448,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
434
448
  discount_list: [discountDetail],
435
449
  _id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
436
450
  price: new Decimal(targetProductPrice).toNumber(),
437
- quantity: 1,
451
+ quantity: isNeedSplit ? 1 : product.quantity,
438
452
  total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
439
453
  origin_total: product.origin_total || product.total
440
454
  }));
@@ -478,7 +492,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
478
492
  }
479
493
  };
480
494
  var arr = processedProductsMap.get(product._id);
481
- arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
495
+ arr !== null && arr !== void 0 && arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
482
496
  });
483
497
 
484
498
  // 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
@@ -2242,7 +2242,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2242
2242
  break;
2243
2243
  }
2244
2244
  dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2245
- if (dateRange.length) {
2245
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2246
2246
  _context25.next = 15;
2247
2247
  break;
2248
2248
  }
@@ -2876,6 +2876,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2876
2876
  }, {
2877
2877
  key: "isTargetNormalProduct",
2878
2878
  value: function isTargetNormalProduct(product) {
2879
+ if (!product) return false;
2879
2880
  return isNormalProduct(product);
2880
2881
  }
2881
2882
  }, {
@@ -38,6 +38,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
38
38
  isAvailable: boolean;
39
39
  productList: Record<string, any>[];
40
40
  discountList: Discount[];
41
+ type: "server" | "clientCalc";
41
42
  }>;
42
43
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
43
44
  private getCustomer;
@@ -327,11 +327,23 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
327
327
  break;
328
328
  }
329
329
  return _context5.abrupt("return", {
330
+ type: "clientCalc",
330
331
  isAvailable: false,
331
332
  productList: this.store.productList || [],
332
333
  discountList: this.getDiscountList()
333
334
  });
334
335
  case 10:
336
+ if (resultDiscountList.length) {
337
+ _context5.next = 12;
338
+ break;
339
+ }
340
+ return _context5.abrupt("return", {
341
+ type: "server",
342
+ isAvailable: false,
343
+ productList: this.store.productList || [],
344
+ discountList: this.getDiscountList()
345
+ });
346
+ case 12:
335
347
  withScanList = resultDiscountList.map(function (item) {
336
348
  return _objectSpread(_objectSpread({}, item), {}, {
337
349
  isScan: true
@@ -347,37 +359,39 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
347
359
  discountList: this.getDiscountList()
348
360
  }, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable;
349
361
  if (!isAvailable) {
350
- _context5.next = 18;
362
+ _context5.next = 20;
351
363
  break;
352
364
  }
353
365
  this.setDiscountList(newDiscountList || []);
354
366
  this.setProductList(newProductList || []);
355
367
  if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
356
- _context5.next = 18;
368
+ _context5.next = 20;
357
369
  break;
358
370
  }
359
- _context5.next = 18;
371
+ _context5.next = 20;
360
372
  return this.getCustomerWallet(resultDiscountList[0].customer_id);
361
- case 18:
373
+ case 20:
362
374
  return _context5.abrupt("return", {
375
+ type: "clientCalc",
363
376
  isAvailable: isAvailable || false,
364
377
  productList: newProductList || this.store.productList || [],
365
378
  discountList: newDiscountList || this.getDiscountList()
366
379
  });
367
- case 21:
368
- _context5.prev = 21;
380
+ case 23:
381
+ _context5.prev = 23;
369
382
  _context5.t1 = _context5["catch"](0);
370
383
  console.error('[ShopDiscount] 扫码出错:', _context5.t1);
371
384
  return _context5.abrupt("return", {
385
+ type: "clientCalc",
372
386
  isAvailable: false,
373
387
  productList: this.store.productList || [],
374
388
  discountList: this.getDiscountList()
375
389
  });
376
- case 25:
390
+ case 27:
377
391
  case "end":
378
392
  return _context5.stop();
379
393
  }
380
- }, _callee5, this, [[0, 21]]);
394
+ }, _callee5, this, [[0, 23]]);
381
395
  }));
382
396
  function scanCode(_x4) {
383
397
  return _scanCode.apply(this, arguments);
@@ -444,7 +458,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
444
458
  if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
445
459
  var index = editModeDiscountList.findIndex(function (n) {
446
460
  var _discount$discount;
447
- return n.id === ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
461
+ return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
448
462
  });
449
463
  if (index !== -1) {
450
464
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
@@ -105,6 +105,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
105
105
  discountList,
106
106
  productList
107
107
  }, options) {
108
+ const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
108
109
  const editModeDiscount = [];
109
110
  const addModeDiscount = [];
110
111
  discountList.forEach((discount) => {
@@ -171,13 +172,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
171
172
  var _a, _b, _c;
172
173
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
173
174
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
174
- const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag))));
175
+ const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type))));
175
176
  if (isAvailableProduct && isLimitedProduct) {
176
177
  (_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
177
178
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
178
179
  applicableProducts.push({
179
180
  amount: product.price,
180
- type: discount.tag,
181
+ type: discount.tag || discount.type,
182
+ tag: discount.tag || discount.type,
181
183
  discount: {
182
184
  resource_id: discount.id,
183
185
  title: discount.format_title,
@@ -195,7 +197,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
195
197
  sortedProductList.forEach((originProduct, i) => {
196
198
  var _a, _b, _c, _d, _e;
197
199
  const product = this.hooks.getProduct(originProduct);
198
- if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag)))) {
200
+ if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
199
201
  processedProductsMap.set(product._id, [originProduct]);
200
202
  return;
201
203
  }
@@ -203,7 +205,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
203
205
  if (Number(product.price) === 0 || !product.price)
204
206
  return false;
205
207
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
206
- if (targetUsedDiscounts && discount.tag === "good_pass")
208
+ if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
207
209
  return false;
208
210
  const limitedData = discount.limited_relation_product_data;
209
211
  if (limitedData.type === "product_all") {
@@ -261,13 +263,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
261
263
  }
262
264
  return;
263
265
  }
264
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
266
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
265
267
  return;
266
268
  }
267
- const splitCount = Math.min(product.quantity, applicableDiscounts.length);
268
- debugger;
269
+ const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
270
+ const splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
269
271
  const arr = [];
270
- if (splitCount < product.quantity) {
272
+ if (splitCount < product.quantity && isNeedSplit) {
271
273
  arr.push(this.hooks.setProduct(originProduct, {
272
274
  discount_list: [],
273
275
  quantity: product.quantity - splitCount,
@@ -297,7 +299,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
297
299
  arr.push(this.hooks.setProduct(originProduct, {
298
300
  discount_list: [discountDetail],
299
301
  price: new import_decimal.default(targetProductPrice).toNumber(),
300
- quantity: 1,
302
+ quantity: isNeedSplit ? 1 : product.quantity,
301
303
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
302
304
  product: {
303
305
  original_price: product.original_price
@@ -318,7 +320,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
318
320
  discount_list: [discountDetail],
319
321
  _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
320
322
  price: new import_decimal.default(targetProductPrice).toNumber(),
321
- quantity: 1,
323
+ quantity: isNeedSplit ? 1 : product.quantity,
322
324
  total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
323
325
  origin_total: product.origin_total || product.total
324
326
  }));
@@ -360,7 +362,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
360
362
  }
361
363
  };
362
364
  const arr = processedProductsMap.get(product._id);
363
- arr.length ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
365
+ (arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
364
366
  });
365
367
  const updatedDiscountList = addModeDiscount.map((discount) => {
366
368
  const applicableProducts = discountApplicability.get(discount.id) || [];
@@ -1562,7 +1562,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1562
1562
  targetProduct.setOtherParams("schedule", newScheduleArr);
1563
1563
  } else if (targetProductData.duration) {
1564
1564
  const dateRange = this.store.date.getDateRange();
1565
- if (!dateRange.length)
1565
+ if (!(dateRange == null ? void 0 : dateRange.length))
1566
1566
  return;
1567
1567
  this.getAvailableDate({
1568
1568
  startDate: dateRange[0].date,
@@ -2034,6 +2034,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2034
2034
  });
2035
2035
  }
2036
2036
  isTargetNormalProduct(product) {
2037
+ if (!product)
2038
+ return false;
2037
2039
  return (0, import_utils4.isNormalProduct)(product);
2038
2040
  }
2039
2041
  isTargetCartIdNormalProduct(id) {
@@ -38,6 +38,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
38
38
  isAvailable: boolean;
39
39
  productList: Record<string, any>[];
40
40
  discountList: Discount[];
41
+ type: "server" | "clientCalc";
41
42
  }>;
42
43
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
43
44
  private getCustomer;
@@ -205,6 +205,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
205
205
  const rulesModule = this.store.rules;
206
206
  if (!rulesModule) {
207
207
  return {
208
+ type: "clientCalc",
209
+ isAvailable: false,
210
+ productList: this.store.productList || [],
211
+ discountList: this.getDiscountList()
212
+ };
213
+ }
214
+ if (!resultDiscountList.length) {
215
+ return {
216
+ type: "server",
208
217
  isAvailable: false,
209
218
  productList: this.store.productList || [],
210
219
  discountList: this.getDiscountList()
@@ -239,6 +248,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
239
248
  }
240
249
  }
241
250
  return {
251
+ type: "clientCalc",
242
252
  isAvailable: isAvailable || false,
243
253
  productList: newProductList || this.store.productList || [],
244
254
  discountList: newDiscountList || this.getDiscountList()
@@ -246,6 +256,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
246
256
  } catch (error) {
247
257
  console.error("[ShopDiscount] 扫码出错:", error);
248
258
  return {
259
+ type: "clientCalc",
249
260
  isAvailable: false,
250
261
  productList: this.store.productList || [],
251
262
  discountList: this.getDiscountList()
@@ -289,7 +300,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
289
300
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
290
301
  const index = editModeDiscountList.findIndex((n) => {
291
302
  var _a4;
292
- return n.id === ((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id;
303
+ return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
293
304
  });
294
305
  if (index !== -1) {
295
306
  editModeDiscountList[index] = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.150",
4
+ "version": "0.0.152",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",