@pisell/pisellos 2.2.265 → 2.2.270

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.
Files changed (59) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +1 -1
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/OpenData/index.d.ts +2 -0
  14. package/dist/modules/OpenData/index.js +8 -0
  15. package/dist/modules/Order/index.d.ts +1 -1
  16. package/dist/modules/Order/index.js +10 -3
  17. package/dist/modules/Order/utils.js +2 -1
  18. package/dist/modules/Rules/index.d.ts +1 -0
  19. package/dist/modules/Rules/index.js +34 -14
  20. package/dist/solution/BaseSales/index.d.ts +14 -1
  21. package/dist/solution/BaseSales/index.js +36 -12
  22. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  23. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  24. package/dist/solution/BookingByStep/index.d.ts +1 -1
  25. package/dist/solution/BookingTicket/index.d.ts +3 -1
  26. package/dist/solution/BookingTicket/index.js +43 -31
  27. package/dist/solution/ScanOrder/index.js +31 -20
  28. package/dist/solution/VenueBooking/index.js +30 -19
  29. package/dist/types/index.d.ts +1 -0
  30. package/lib/core/index.d.ts +2 -0
  31. package/lib/core/index.js +4 -0
  32. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  33. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  34. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  35. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  36. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  37. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  38. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  39. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  40. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  41. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  42. package/lib/modules/OpenData/index.d.ts +2 -0
  43. package/lib/modules/OpenData/index.js +5 -0
  44. package/lib/modules/Order/index.d.ts +1 -1
  45. package/lib/modules/Order/index.js +9 -3
  46. package/lib/modules/Order/utils.js +6 -1
  47. package/lib/modules/Rules/index.d.ts +1 -0
  48. package/lib/modules/Rules/index.js +23 -4
  49. package/lib/solution/BaseSales/index.d.ts +14 -1
  50. package/lib/solution/BaseSales/index.js +22 -1
  51. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  52. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  53. package/lib/solution/BookingByStep/index.d.ts +1 -1
  54. package/lib/solution/BookingTicket/index.d.ts +3 -1
  55. package/lib/solution/BookingTicket/index.js +11 -3
  56. package/lib/solution/ScanOrder/index.js +8 -0
  57. package/lib/solution/VenueBooking/index.js +8 -0
  58. package/lib/types/index.d.ts +1 -0
  59. package/package.json +2 -2
@@ -77,19 +77,43 @@ function getOrderProductOriginalPriceForPromotion(product) {
77
77
  }
78
78
  return getOrderProductBasePrice(product);
79
79
  }
80
- function updatePromotionDiscountList(item, promotionDiscount) {
80
+ var X_ITEMS_FOR_Y_PRICE = "X_ITEMS_FOR_Y_PRICE";
81
+ var ITEM_REWARD = "ITEM_REWARD";
82
+ function isItemRewardPromotionDiscountItem(item) {
83
+ var _a, _b;
84
+ return (item == null ? void 0 : item.type) === "product" && ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.actionType) === ITEM_REWARD;
85
+ }
86
+ function isManagedPromotionDiscountItem(item) {
87
+ if ((item == null ? void 0 : item.type) === "promotion")
88
+ return true;
89
+ return isItemRewardPromotionDiscountItem(item);
90
+ }
91
+ function wasInPromotionBeforeEvaluation(item) {
92
+ var _a, _b;
93
+ if (((_b = (_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a._promotion) == null ? void 0 : _b.inPromotion) === true)
94
+ return true;
95
+ return Array.isArray(item == null ? void 0 : item.discount_list) && item.discount_list.some(isItemRewardPromotionDiscountItem);
96
+ }
97
+ function updatePromotionDiscountList(item, promotionDiscount, options) {
81
98
  let discountList = Array.isArray(item.discount_list) ? [...item.discount_list] : [];
82
- discountList = discountList.filter((d) => (d == null ? void 0 : d.type) !== "promotion");
99
+ discountList = discountList.filter((d) => !isManagedPromotionDiscountItem(d));
83
100
  if (promotionDiscount) {
101
+ const discountType = (options == null ? void 0 : options.discountType) || "promotion";
84
102
  discountList.push({
85
- type: "promotion",
103
+ type: discountType,
86
104
  amount: promotionDiscount.amount,
87
105
  discount: {
88
106
  original_amount: promotionDiscount.original_amount,
89
107
  fixed_amount: promotionDiscount.fixed_amount,
90
108
  title: promotionDiscount.title,
91
109
  resource_id: ""
92
- }
110
+ },
111
+ ...discountType === "product" ? {
112
+ metadata: {
113
+ source: "promotion",
114
+ actionType: (options == null ? void 0 : options.actionType) || ITEM_REWARD
115
+ }
116
+ } : {}
93
117
  });
94
118
  }
95
119
  if (discountList.length > 0) {
@@ -98,7 +122,15 @@ function updatePromotionDiscountList(item, promotionDiscount) {
98
122
  delete item.discount_list;
99
123
  }
100
124
  }
101
- var X_ITEMS_FOR_Y_PRICE = "X_ITEMS_FOR_Y_PRICE";
125
+ function evaluatorHasActionType(evaluator, actionType) {
126
+ var _a;
127
+ const configs = (_a = evaluator == null ? void 0 : evaluator.getStrategyConfigs) == null ? void 0 : _a.call(evaluator);
128
+ if (!Array.isArray(configs))
129
+ return false;
130
+ return configs.some(
131
+ (config) => ((config == null ? void 0 : config.actions) || []).some((action) => (action == null ? void 0 : action.type) === actionType)
132
+ );
133
+ }
102
134
  function applyPromoUnitPriceToLine(item, input) {
103
135
  const metadata = item.metadata || (item.metadata = {});
104
136
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(item)).toNumber();
@@ -125,6 +157,9 @@ function applyPromoUnitPriceToLine(item, input) {
125
157
  amount: discountAmount,
126
158
  original_amount: catalogSource,
127
159
  fixed_amount: discountAmount
160
+ }, {
161
+ actionType: input.actionType,
162
+ discountType: input.actionType === ITEM_REWARD ? "product" : "promotion"
128
163
  });
129
164
  } else {
130
165
  updatePromotionDiscountList(item, null);
@@ -396,14 +431,13 @@ function buildConsolidateKeyForPromotion(item) {
396
431
  ].join("#");
397
432
  }
398
433
  function consolidateMainProductsForPromotion(entries) {
399
- var _a, _b;
400
434
  if (!Array.isArray(entries) || entries.length <= 1) {
401
435
  return [...entries || []];
402
436
  }
403
437
  const groups = /* @__PURE__ */ new Map();
404
438
  for (const { item, originalListIndex } of entries) {
405
439
  const key = buildConsolidateKeyForPromotion(item);
406
- const wasInPromotion = ((_b = (_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a._promotion) == null ? void 0 : _b.inPromotion) === true;
440
+ const wasInPromotion = wasInPromotionBeforeEvaluation(item);
407
441
  const existing = groups.get(key);
408
442
  if (!existing) {
409
443
  const mergedItem = (0, import_lodash_es.cloneDeep)(item);
@@ -469,6 +503,9 @@ function splitXItemsPromoLinesByGroup(lines, strategyActionMap) {
469
503
  function generateNumericId() {
470
504
  return Math.floor(Math.random() * 1e9) + Date.now();
471
505
  }
506
+ function isBookingEditProductLine(product) {
507
+ return (product == null ? void 0 : product.booking_id) !== void 0 && (product == null ? void 0 : product.booking_id) !== null && product.booking_id !== 0 && product.booking_id !== "0";
508
+ }
472
509
  function convertToPromotionProduct(product, index) {
473
510
  const metadata = (product == null ? void 0 : product.metadata) || {};
474
511
  const numericId = generateNumericId();
@@ -481,6 +518,7 @@ function convertToPromotionProduct(product, index) {
481
518
  price: getOrderProductOriginalPriceForPromotion(product),
482
519
  quantity: Number((product == null ? void 0 : product.num) ?? 1) || 1,
483
520
  bundle: getProductBundleForEvaluator(product),
521
+ _promotionOnlyForItemReward: isBookingEditProductLine(product),
484
522
  _originalItem: originalItem,
485
523
  _originalId: getOrderProductUid(product),
486
524
  _originalIndex: index
@@ -582,6 +620,9 @@ function resolveStrategyRequiredQuantity(matched) {
582
620
  if (matched.actionType === "BUY_X_GET_Y_FREE") {
583
621
  return Number(detail.buyQuantity) || 1;
584
622
  }
623
+ if (matched.actionType === "ITEM_REWARD") {
624
+ return Number(detail.triggerQuantity) || 1;
625
+ }
585
626
  return 1;
586
627
  }
587
628
  function resolveStrategyEligibleProducts(matched) {
@@ -692,6 +733,10 @@ function processCartPromotion(list, evaluator, options) {
692
733
  };
693
734
  if (!list || list.length === 0 || !evaluator)
694
735
  return empty;
736
+ const shouldIncludeEditProductsForItemReward = evaluatorHasActionType(
737
+ evaluator,
738
+ ITEM_REWARD
739
+ );
695
740
  const mainProductsWithIndex = [];
696
741
  const existingGiftsWithIndex = [];
697
742
  const editProductsWithIndex = [];
@@ -702,8 +747,12 @@ function processCartPromotion(list, evaluator, options) {
702
747
  editProductsWithIndex.push({ item, originalListIndex: i });
703
748
  } else if (giftInfo) {
704
749
  existingGiftsWithIndex.push({ item, originalListIndex: i });
705
- } else if ((item == null ? void 0 : item.booking_id) !== void 0 && (item == null ? void 0 : item.booking_id) !== null && item.booking_id !== 0 && item.booking_id !== "0") {
706
- editProductsWithIndex.push({ item, originalListIndex: i });
750
+ } else if (isBookingEditProductLine(item)) {
751
+ if (shouldIncludeEditProductsForItemReward) {
752
+ mainProductsWithIndex.push({ item, originalListIndex: i });
753
+ } else {
754
+ editProductsWithIndex.push({ item, originalListIndex: i });
755
+ }
707
756
  } else {
708
757
  mainProductsWithIndex.push({ item, originalListIndex: i });
709
758
  }
@@ -746,7 +795,8 @@ function processCartPromotion(list, evaluator, options) {
746
795
  name: ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.product_name) || (item == null ? void 0 : item.title) || "",
747
796
  price: getOrderProductBasePrice(item),
748
797
  quantity: Number((item == null ? void 0 : item.num) ?? 1) || 1,
749
- bundle: getProductBundleForEvaluator(item)
798
+ bundle: getProductBundleForEvaluator(item),
799
+ _promotionOnlyForItemReward: isBookingEditProductLine(item)
750
800
  };
751
801
  });
752
802
  for (let i = 0; i < consolidatedMainProductsWithIndex.length; i++) {
@@ -815,7 +865,7 @@ function processCartPromotion(list, evaluator, options) {
815
865
  const metadata = newItem.metadata || {};
816
866
  const sourceCartNum = (0, import_utils2.getSafeProductNum)(originalItem.num);
817
867
  newItem._sourceCartNum = sourceCartNum;
818
- const wasInPromotion = ((_a = metadata._promotion) == null ? void 0 : _a.inPromotion) === true || originalItem._wasInPromotionBeforeConsolidate === true;
868
+ const wasInPromotion = wasInPromotionBeforeEvaluation(originalItem) || originalItem._wasInPromotionBeforeConsolidate === true;
819
869
  delete metadata._promotion;
820
870
  if (Array.isArray(newItem.product_bundle)) {
821
871
  for (const b of newItem.product_bundle) {
@@ -832,7 +882,8 @@ function processCartPromotion(list, evaluator, options) {
832
882
  applyPromoUnitPriceToLine(newItem, {
833
883
  promoUnitPrice,
834
884
  originalBasePrice,
835
- strategyTitle: (_b = priced.strategyMetadata) == null ? void 0 : _b.name
885
+ strategyTitle: (_a = priced.strategyMetadata) == null ? void 0 : _a.name,
886
+ actionType: priced.strategyId ? (_b = strategyActionMap.get(priced.strategyId)) == null ? void 0 : _b.actionType : void 0
836
887
  });
837
888
  } else {
838
889
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(newItem)).toNumber();
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 5 | 4 | 3 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -46,6 +46,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
46
46
  private getIdGeneratorPlugin;
47
47
  private loadOpenDataConfig;
48
48
  getOpenData(): Promise<OpenDataConfig | null>;
49
+ /** 清除店铺级 OpenData;下一次 getOpenData 时会重新拉取。 */
50
+ clearOpenDataCache(): void;
49
51
  private getShortNumberOrDeviceId;
50
52
  private configureIdGeneratorFromOpenData;
51
53
  private normalizePositiveInteger;
@@ -322,7 +324,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
322
324
  * 获取当前的客户搜索条件
323
325
  * @returns 当前搜索条件
324
326
  */
325
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
327
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
326
328
  /**
327
329
  * 获取客户列表状态(包含滚动加载相关状态)
328
330
  * @returns 客户状态
@@ -219,8 +219,14 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
219
219
  }
220
220
  }
221
221
  async getOpenData() {
222
+ return this.loadOpenDataConfig();
223
+ }
224
+ /** 清除店铺级 OpenData;下一次 getOpenData 时会重新拉取。 */
225
+ clearOpenDataCache() {
222
226
  var _a;
223
- return (_a = this.store.openData) == null ? void 0 : _a.getOpenData();
227
+ this.loadOpenDataConfigInFlight = null;
228
+ this.otherParams.openData = null;
229
+ (_a = this.store.openData) == null ? void 0 : _a.clearCache();
224
230
  }
225
231
  async getShortNumberOrDeviceId() {
226
232
  const getAsyncIotDeviceInfo = this.getAppData("async_iot_device_info");
@@ -233,6 +239,7 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
233
239
  return String(this.getAppData("device_id") || 0).slice(-2);
234
240
  }
235
241
  async configureIdGeneratorFromOpenData() {
242
+ this.setPaymentNumberDevicePrefix(null);
236
243
  let openDataConfig = null;
237
244
  try {
238
245
  openDataConfig = await this.loadOpenDataConfig();
@@ -264,6 +271,7 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
264
271
  const resetReceiptSequenceDaily = typeof (openDataConfig == null ? void 0 : openDataConfig["sale.short_number_daily_reset"]) === "boolean" ? openDataConfig == null ? void 0 : openDataConfig["sale.short_number_daily_reset"] : false;
265
272
  const operatingDayBoundary = this.getAppData("operating_day_boundary");
266
273
  const deviceId = await this.getShortNumberOrDeviceId();
274
+ this.setPaymentNumberDevicePrefix(deviceId);
267
275
  const businessCode = this.getBookingTicketBusinessCode();
268
276
  if (!businessCode) {
269
277
  console.warn("[BookingTicket] businessCode 缺失,跳过 idGenerator 配置");
@@ -1527,8 +1535,8 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
1527
1535
  return result;
1528
1536
  }
1529
1537
  async setOtherParams(params, { cover = false } = {}) {
1530
- super.setOtherParams(params, { cover });
1531
- if (params == null ? void 0 : params.businessCode) {
1538
+ await super.setOtherParams(params, { cover });
1539
+ if ((params == null ? void 0 : params.businessCode) !== void 0 || (params == null ? void 0 : params.business_code) !== void 0) {
1532
1540
  await this.configureIdGeneratorFromOpenData();
1533
1541
  }
1534
1542
  }
@@ -48,6 +48,10 @@ var import_utils2 = require("../../modules/Order/utils");
48
48
  var import_dayjs = __toESM(require("dayjs"));
49
49
  var import_itemRule = require("../../model/strategy/adapter/itemRule");
50
50
  __reExport(ScanOrder_exports, require("./types"), module.exports);
51
+ function isItemRewardProductDiscount(discount) {
52
+ var _a, _b;
53
+ return (discount == null ? void 0 : discount.type) === "product" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.actionType) === "ITEM_REWARD";
54
+ }
51
55
  var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
52
56
  constructor(name, version) {
53
57
  super(name, version);
@@ -742,6 +746,10 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
742
746
  for (const product of tempOrder.products) {
743
747
  if ((_c = product._origin) == null ? void 0 : _c.isManualDiscount)
744
748
  continue;
749
+ if ((product.discount_list || []).some(isItemRewardProductDiscount)) {
750
+ product.discount_list = (product.discount_list || []).filter(isItemRewardProductDiscount);
751
+ continue;
752
+ }
745
753
  product.discount_list = (product.discount_list || []).filter((pd) => {
746
754
  var _a2;
747
755
  const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
@@ -65,6 +65,10 @@ var OPEN_DATA_SECTION_CODES = [
65
65
  "workflow",
66
66
  "checkout"
67
67
  ];
68
+ function isItemRewardProductDiscount(discount) {
69
+ var _a, _b;
70
+ return (discount == null ? void 0 : discount.type) === "product" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.actionType) === "ITEM_REWARD";
71
+ }
68
72
  function cloneCustomDepositData(customDepositData) {
69
73
  if (!customDepositData || typeof customDepositData !== "object")
70
74
  return void 0;
@@ -1339,6 +1343,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1339
1343
  for (const product of tempOrder.products) {
1340
1344
  if ((_c = product._origin) == null ? void 0 : _c.isManualDiscount)
1341
1345
  continue;
1346
+ if ((product.discount_list || []).some(isItemRewardProductDiscount)) {
1347
+ product.discount_list = (product.discount_list || []).filter(isItemRewardProductDiscount);
1348
+ continue;
1349
+ }
1342
1350
  product.discount_list = (product.discount_list || []).filter((pd) => {
1343
1351
  var _a2;
1344
1352
  const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
@@ -47,6 +47,7 @@ export interface PisellCore {
47
47
  getModule: <T extends Module>(name: string) => T | null;
48
48
  getModuleExports: <T = any>(name: string) => T | null;
49
49
  hasModule: (name: string) => boolean;
50
+ getModuleNames: () => string[];
50
51
  effects: {
51
52
  on: (event: string, callback: (payload: any) => void) => () => void;
52
53
  once: (event: string, callback: (payload: any) => void) => () => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.265",
4
+ "version": "2.2.270",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
19
19
  "changeset": "changeset",
20
20
  "version": "changeset version",
21
- "release": "changeset publish --registry=https://registry.npmjs.com/ && npm run sync && git push",
21
+ "release": "changeset publish && npm run sync && git push",
22
22
  "example": "npx parcel-bundler examples/index.html",
23
23
  "docs": "typedoc --out docs src/index.ts",
24
24
  "sync": "node sync.js",