@pisell/pisellos 1.0.0 → 1.0.1

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 (53) hide show
  1. package/dist/modules/Cart/index.d.ts +0 -14
  2. package/dist/modules/Cart/index.js +0 -36
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -10
  4. package/dist/modules/Date/index.js +6 -57
  5. package/dist/modules/Discount/index.d.ts +0 -1
  6. package/dist/modules/Discount/index.js +7 -15
  7. package/dist/modules/Discount/types.d.ts +0 -10
  8. package/dist/modules/ProductList/index.d.ts +0 -7
  9. package/dist/modules/ProductList/index.js +39 -102
  10. package/dist/modules/Rules/index.js +71 -196
  11. package/dist/modules/Rules/types.d.ts +0 -6
  12. package/dist/modules/Schedule/index.d.ts +1 -9
  13. package/dist/modules/Schedule/index.js +2 -122
  14. package/dist/modules/Schedule/types.d.ts +0 -13
  15. package/dist/solution/BookingByStep/index.d.ts +30 -120
  16. package/dist/solution/BookingByStep/index.js +1065 -750
  17. package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
  18. package/dist/solution/BookingByStep/utils/resources.js +94 -39
  19. package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  20. package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
  21. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  22. package/dist/solution/ShopDiscount/index.js +32 -93
  23. package/lib/modules/Cart/index.d.ts +0 -14
  24. package/lib/modules/Cart/index.js +0 -32
  25. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  26. package/lib/modules/Date/index.js +10 -62
  27. package/lib/modules/Discount/index.d.ts +0 -1
  28. package/lib/modules/Discount/index.js +6 -18
  29. package/lib/modules/Discount/types.d.ts +0 -10
  30. package/lib/modules/ProductList/index.d.ts +0 -7
  31. package/lib/modules/ProductList/index.js +0 -45
  32. package/lib/modules/Rules/index.js +56 -147
  33. package/lib/modules/Rules/types.d.ts +0 -6
  34. package/lib/modules/Schedule/index.d.ts +1 -9
  35. package/lib/modules/Schedule/index.js +1 -79
  36. package/lib/modules/Schedule/types.d.ts +0 -13
  37. package/lib/solution/BookingByStep/index.d.ts +30 -120
  38. package/lib/solution/BookingByStep/index.js +581 -392
  39. package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
  40. package/lib/solution/BookingByStep/utils/resources.js +59 -23
  41. package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  42. package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
  43. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  44. package/lib/solution/ShopDiscount/index.js +18 -85
  45. package/package.json +1 -1
  46. package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
  47. package/dist/modules/Cart/utils/changePrice.js +0 -104
  48. package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
  49. package/dist/solution/BookingByStep/utils/capacity.js +0 -132
  50. package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
  51. package/lib/modules/Cart/utils/changePrice.js +0 -78
  52. package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
  53. package/lib/solution/BookingByStep/utils/capacity.js +0 -106
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
@@ -97,10 +97,7 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
97
97
  } | undefined;
98
98
  } | undefined;
99
99
  hasFlexibleDuration?: boolean | undefined;
100
- operating_day_boundary?: {
101
- type: string;
102
- time: string;
103
- } | undefined;
100
+ operating_day_boundary?: string | undefined;
104
101
  }) => TimeSliceItem[];
105
102
  /**
106
103
  * @title: 获取时间切片列表的交集
@@ -138,7 +135,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
138
135
  * @return {*}
139
136
  * @Author: zhiwei.Wang
140
137
  */
141
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
138
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
142
139
  resourceIds: number[];
143
140
  resourcesMap: any;
144
141
  duration: number;
@@ -157,10 +154,7 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
157
154
  } | undefined;
158
155
  } | undefined;
159
156
  hasFlexibleDuration?: boolean | undefined;
160
- operating_day_boundary?: {
161
- type: string;
162
- time: string;
163
- } | undefined;
157
+ operating_day_boundary?: string | undefined;
164
158
  }) => any[];
165
159
  /**
166
160
  * @title: 获取其他人的已选资源
@@ -180,11 +174,37 @@ export declare const getOthersSelectedResources: (cartItems: CartItem[], account
180
174
  * @Author: jinglin.tan
181
175
  */
182
176
  export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
183
- export interface CapacityItem {
177
+ interface CapacityItem {
184
178
  id: number;
185
179
  value: number;
186
180
  name: string;
187
181
  }
182
+ /**
183
+ * @title: 基于选择的商品格式化容量
184
+ * @description:
185
+ * @param {any} param1
186
+ * @return {*}
187
+ * @Author: zhiwei.Wang
188
+ */
189
+ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
190
+ /**
191
+ * @title: 获取总容量
192
+ * @description:
193
+ * @param {object} capacity 为 formatDefaultCapacitys()的结果
194
+ * @return {*}
195
+ * @Author: zhiwei.Wang
196
+ */
197
+ export declare const getSumCapacity: ({ capacity }: {
198
+ capacity: CapacityItem[];
199
+ }) => number;
200
+ /**
201
+ * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
202
+ * @description:
203
+ * @param {object} resource
204
+ * @return {*}
205
+ * @Author: jinglin.tan
206
+ */
207
+ export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
188
208
  /**
189
209
  * @title: 根据日期范围过滤日程
190
210
  *
@@ -222,22 +242,4 @@ export declare function getResourcesIdsByProduct(product: ProductData): number[]
222
242
  * @return {*}
223
243
  */
224
244
  export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
225
- /**
226
- * 传入一个资源组,根据 formid筛出相同类型的资源
227
- *
228
- * @export
229
- * @param {ResourceItem[]} resources
230
- * @param {string} form_id
231
- * @return {*}
232
- */
233
- export declare function filterResourcesByFormItem(resources: ResourceItem[], form_id: string): ResourceItem[];
234
- /**
235
- * 传入两个资源,确认这两个资源是否有交集(包括组合资源)
236
- *
237
- * @export
238
- * @param {ResourceItem} resource1
239
- * @param {ResourceItem} resource2
240
- * @return {*}
241
- */
242
- export declare function checkTwoResourcesIntersection(resource1: ResourceItem, resource2: ResourceItem): true | undefined;
243
245
  export {};
@@ -30,9 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var resources_exports = {};
31
31
  __export(resources_exports, {
32
32
  checkSessionProductLeadTime: () => checkSessionProductLeadTime,
33
- checkTwoResourcesIntersection: () => checkTwoResourcesIntersection,
34
- filterResourcesByFormItem: () => filterResourcesByFormItem,
33
+ checkSubResourcesCapacity: () => checkSubResourcesCapacity,
35
34
  filterScheduleByDateRange: () => filterScheduleByDateRange,
35
+ formatDefaultCapacitys: () => formatDefaultCapacitys,
36
36
  formatResources: () => formatResources,
37
37
  getIsUsableByTimeItem: () => getIsUsableByTimeItem,
38
38
  getOthersCartSelectedResources: () => getOthersCartSelectedResources,
@@ -40,6 +40,7 @@ __export(resources_exports, {
40
40
  getResourcesByIds: () => getResourcesByIds,
41
41
  getResourcesByProduct: () => getResourcesByProduct,
42
42
  getResourcesIdsByProduct: () => getResourcesIdsByProduct,
43
+ getSumCapacity: () => getSumCapacity,
43
44
  getTimeSlicesByResource: () => getTimeSlicesByResource,
44
45
  getTimeSlicesByResources: () => getTimeSlicesByResources,
45
46
  getTimesIntersection: () => getTimesIntersection,
@@ -365,8 +366,7 @@ var getTimeSlicesByResource = ({
365
366
  resourcesUseableMap[resource.id] = _status.usable;
366
367
  }
367
368
  if (_status.usable) {
368
- const operatingBoundaryDateTime = (operating_day_boundary == null ? void 0 : operating_day_boundary.type) === "start_time" ? "23:59" : operating_day_boundary == null ? void 0 : operating_day_boundary.time;
369
- if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= (operatingBoundaryDateTime || "23:59")) {
369
+ if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= operating_day_boundary) {
370
370
  break;
371
371
  }
372
372
  timeSlices.push({
@@ -521,6 +521,58 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
521
521
  return acc;
522
522
  }, []);
523
523
  };
524
+ var formatDefaultCapacitys = ({
525
+ capacity,
526
+ product_bundle
527
+ }) => {
528
+ if ((capacity == null ? void 0 : capacity.type) === "package") {
529
+ return (product_bundle || []).map((d) => {
530
+ const id = d.bundle_product_id;
531
+ const item = ((capacity == null ? void 0 : capacity.package) || []).find(
532
+ (item2) => item2.product_id === id
533
+ );
534
+ return {
535
+ id,
536
+ value: item ? d.num || 0 : 0,
537
+ name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
538
+ };
539
+ });
540
+ }
541
+ if ((capacity == null ? void 0 : capacity.type) === "custom") {
542
+ return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
543
+ return {
544
+ id: d.id,
545
+ value: d.min,
546
+ name: d.name
547
+ };
548
+ });
549
+ }
550
+ return [{ id: 0, value: 1, name: "" }];
551
+ };
552
+ var getSumCapacity = ({ capacity }) => {
553
+ let sum = 0;
554
+ for (let item of capacity || []) {
555
+ sum += item.value;
556
+ }
557
+ return sum;
558
+ };
559
+ var checkSubResourcesCapacity = (resource) => {
560
+ if (resource.children && resource.children.length) {
561
+ let countCapacity = resource.capacity;
562
+ resource.children.forEach((child, index) => {
563
+ if (index === resource.children.length - 1) {
564
+ child.capacity = countCapacity;
565
+ return;
566
+ }
567
+ if (child.capacity <= countCapacity) {
568
+ countCapacity -= child.capacity;
569
+ } else {
570
+ child.capacity = countCapacity;
571
+ countCapacity = 0;
572
+ }
573
+ });
574
+ }
575
+ };
524
576
  function filterScheduleByDateRange(schedule, startDate, endDate) {
525
577
  if (!(schedule == null ? void 0 : schedule.length))
526
578
  return [];
@@ -584,29 +636,12 @@ function sortCombinedResources(resourcesList) {
584
636
  });
585
637
  return newResourcesList;
586
638
  }
587
- function filterResourcesByFormItem(resources, form_id) {
588
- return resources.filter((n) => n.form_id === form_id);
589
- }
590
- function checkTwoResourcesIntersection(resource1, resource2) {
591
- var _a, _b;
592
- if (resource1.id === resource2.id)
593
- return true;
594
- if (((_a = resource1.metadata.combined_resource) == null ? void 0 : _a.status) === 1 && // 如果现在选择的是组合资源,需要判断
595
- // 1、当前其他购物车里是否选了当前组合资源的子资源
596
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
597
- (resource1.metadata.combined_resource.resource_ids.includes(resource2.id) || resource1.metadata.combined_resource.resource_ids.some((n) => {
598
- return resource2.metadata.combined_resource.resource_ids.includes(n);
599
- })))
600
- return true;
601
- if (((_b = resource2.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && resource2.metadata.combined_resource.resource_ids.includes(resource2.id))
602
- return true;
603
- }
604
639
  // Annotate the CommonJS export names for ESM import in node:
605
640
  0 && (module.exports = {
606
641
  checkSessionProductLeadTime,
607
- checkTwoResourcesIntersection,
608
- filterResourcesByFormItem,
642
+ checkSubResourcesCapacity,
609
643
  filterScheduleByDateRange,
644
+ formatDefaultCapacitys,
610
645
  formatResources,
611
646
  getIsUsableByTimeItem,
612
647
  getOthersCartSelectedResources,
@@ -614,6 +649,7 @@ function checkTwoResourcesIntersection(resource1, resource2) {
614
649
  getResourcesByIds,
615
650
  getResourcesByProduct,
616
651
  getResourcesIdsByProduct,
652
+ getSumCapacity,
617
653
  getTimeSlicesByResource,
618
654
  getTimeSlicesByResources,
619
655
  getTimesIntersection,
@@ -1,4 +1,3 @@
1
- import { Dayjs } from "dayjs";
2
1
  import { ResourceItem, TimeSliceItem } from "./resources";
3
2
  /**
4
3
  * 计算资源在指定时间段内的总可用时间(以分钟为单位)
@@ -24,13 +23,3 @@ export declare function findFastestAvailableResource({ resources, currentCapacit
24
23
  currentCapacity?: number;
25
24
  countMap?: Record<number, number>;
26
25
  }): ResourceItem | null;
27
- /**
28
- * 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
29
- *
30
- * @export
31
- * @param {TimeSliceItem[]} times
32
- * @param {Dayjs} startTime
33
- * @param {Dayjs} endTime
34
- * @return {*}
35
- */
36
- export declare function filterConditionTimeSlots(times: TimeSliceItem[], startTime: Dayjs, endTime: Dayjs): TimeSliceItem[];
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var timeslots_exports = {};
31
31
  __export(timeslots_exports, {
32
32
  calculateResourceAvailableTime: () => calculateResourceAvailableTime,
33
- filterConditionTimeSlots: () => filterConditionTimeSlots,
34
33
  findFastestAvailableResource: () => findFastestAvailableResource
35
34
  });
36
35
  module.exports = __toCommonJS(timeslots_exports);
@@ -153,14 +152,8 @@ function findFastestAvailableResource({
153
152
  }
154
153
  return selectedResource;
155
154
  }
156
- function filterConditionTimeSlots(times, startTime, endTime) {
157
- return times.filter((n) => {
158
- return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
159
- });
160
- }
161
155
  // Annotate the CommonJS export names for ESM import in node:
162
156
  0 && (module.exports = {
163
157
  calculateResourceAvailableTime,
164
- filterConditionTimeSlots,
165
158
  findFastestAvailableResource
166
159
  });
@@ -10,7 +10,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
10
10
  private window;
11
11
  private store;
12
12
  private options;
13
- private hooks?;
14
13
  constructor(name?: string, version?: string);
15
14
  initialize(core: PisellCore, options: any): Promise<void>;
16
15
  destroy(): Promise<void>;
@@ -38,7 +37,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
38
37
  isAvailable: boolean;
39
38
  productList: Record<string, any>[];
40
39
  discountList: Discount[];
41
- type: "server" | "clientCalc";
42
40
  }>;
43
41
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
44
42
  private getCustomer;
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/solution/ShopDiscount/index.ts
@@ -37,7 +27,6 @@ var import_BaseModule = require("../../modules/BaseModule");
37
27
  var import_types = require("./types");
38
28
  var import_Discount = require("../../modules/Discount");
39
29
  var import_Rules = require("../../modules/Rules");
40
- var import_decimal = __toESM(require("decimal.js"));
41
30
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
42
31
  constructor(name, version) {
43
32
  super(name, version);
@@ -54,11 +43,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
54
43
  }
55
44
  // =========== 生命周期方法 ===========
56
45
  async initialize(core, options) {
57
- var _a, _b;
58
46
  this.core = core;
59
47
  this.options = options;
60
48
  this.store = { ...this.store, ...options.store || {} };
61
- this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
62
49
  console.log("[ShopDiscount] 初始化完成");
63
50
  this.initializePlugins();
64
51
  this.registerDependentModules();
@@ -131,8 +118,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
131
118
  this.loadPrepareConfig({
132
119
  customerId: customer.id,
133
120
  action: "create",
134
- with_good_pass: 1,
135
- with_discount_card: 1
121
+ with_good_pass: 1
136
122
  });
137
123
  }
138
124
  );
@@ -205,15 +191,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
205
191
  const rulesModule = this.store.rules;
206
192
  if (!rulesModule) {
207
193
  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",
217
194
  isAvailable: false,
218
195
  productList: this.store.productList || [],
219
196
  discountList: this.getDiscountList()
@@ -248,7 +225,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
248
225
  }
249
226
  }
250
227
  return {
251
- type: "clientCalc",
252
228
  isAvailable: isAvailable || false,
253
229
  productList: newProductList || this.store.productList || [],
254
230
  discountList: newDiscountList || this.getDiscountList()
@@ -256,7 +232,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
256
232
  } catch (error) {
257
233
  console.error("[ShopDiscount] 扫码出错:", error);
258
234
  return {
259
- type: "clientCalc",
260
235
  isAvailable: false,
261
236
  productList: this.store.productList || [],
262
237
  discountList: this.getDiscountList()
@@ -292,39 +267,22 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
292
267
  const productList = this.store.productList || [];
293
268
  const editModeDiscountList = [];
294
269
  productList.forEach((item) => {
295
- var _a2;
296
270
  if (item.booking_id) {
297
- const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
298
271
  (item.discount_list || []).forEach((discount) => {
299
- var _a3, _b, _c;
300
- if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
301
- const index = editModeDiscountList.findIndex((n) => {
302
- var _a4;
303
- return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
272
+ var _a2, _b, _c;
273
+ if (discount.id && discount.type === "good_pass") {
274
+ editModeDiscountList.push({
275
+ ...discount,
276
+ isEditMode: true,
277
+ limited_relation_product_data: {},
278
+ savedAmount: discount.amount,
279
+ isAvailable: true,
280
+ id: ((_a2 = discount.discount) == null ? void 0 : _a2.resource_id) || discount.id,
281
+ format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
282
+ isDisabled: true,
283
+ isSelected: true,
284
+ product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
304
285
  });
305
- if (index !== -1) {
306
- editModeDiscountList[index] = {
307
- ...editModeDiscountList[index],
308
- amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
309
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
310
- };
311
- } else {
312
- if (discount.type && !discount.tag) {
313
- discount.tag = discount.type;
314
- }
315
- editModeDiscountList.push({
316
- ...discount,
317
- isEditMode: true,
318
- limited_relation_product_data: {},
319
- savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
320
- isAvailable: true,
321
- id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
322
- format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
323
- isDisabled: true,
324
- isSelected: true,
325
- product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
326
- });
327
- }
328
286
  }
329
287
  });
330
288
  }
@@ -333,30 +291,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
333
291
  ...editModeDiscountList,
334
292
  ...discountList.filter((item) => !item.isDisabled)
335
293
  ];
336
- const allUsedProductIds = newDiscountList.map((n) => {
337
- var _a2;
338
- return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
339
- var _a3;
340
- return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
341
- }) : [];
342
- }).flat();
343
- newDiscountList.forEach((item) => {
344
- var _a2;
345
- const isProductFree = (id) => {
346
- var _a3;
347
- const targetProduct = productList.find((n) => n.id === id);
348
- const product = (_a3 = this.hooks) == null ? void 0 : _a3.getProduct(targetProduct);
349
- return Number(product == null ? void 0 : product.price) === 0;
350
- };
351
- const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
352
- return (allUsedProductIds == null ? void 0 : allUsedProductIds.includes(id)) || isProductFree(id);
353
- });
354
- if (!item.isSelected && isAllProductUsedOrFree) {
355
- item.isDisabledForProductUsed = true;
356
- } else {
357
- item.isDisabledForProductUsed = false;
358
- }
359
- });
360
294
  (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
361
295
  this.emitDiscountListChange(newDiscountList);
362
296
  return newDiscountList;
@@ -369,11 +303,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
369
303
  // 获取客户钱包信息
370
304
  async getCustomerWallet(id) {
371
305
  try {
372
- const result = await this.request.get(`/customer/info/${id}`, {
373
- with_trashed: 1
306
+ const result = await this.request.get(`/customer/info/wallet/${id}`, {
307
+ wallet_pass_tags: ["good_pass"]
374
308
  });
375
309
  if (result == null ? void 0 : result.data) {
376
- const { ...customer } = result.data;
310
+ const { wallet_pass_list, ...customer } = result.data;
377
311
  this.setCustomer(customer);
378
312
  await this.core.effects.emit(
379
313
  import_types.ShopDiscountHooks.onScanCustomerChange,
@@ -392,8 +326,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
392
326
  const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
393
327
  customer_id: customerId,
394
328
  action: "create",
395
- with_good_pass: 1,
396
- with_discount_card: 1
329
+ with_good_pass: 1
397
330
  }));
398
331
  const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
399
332
  (item) => item.isScan
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1,3 +0,0 @@
1
- import { Product } from "../../Product";
2
- import { CartItem, IUpdateItemParams } from "../types";
3
- export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
@@ -1,104 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
- import Decimal from "decimal.js";
14
- export function updateAllCartItemPrice(_x, _x2, _x3, _x4) {
15
- return _updateAllCartItemPrice.apply(this, arguments);
16
- }
17
- function _updateAllCartItemPrice() {
18
- _updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart) {
19
- var _iterator, _step, _loop;
20
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
21
- while (1) switch (_context2.prev = _context2.next) {
22
- case 0:
23
- _iterator = _createForOfIteratorHelper(cartItems);
24
- _context2.prev = 1;
25
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
26
- var _bundle;
27
- var item, targetProduct, cartProduct, productInfo, bundle;
28
- return _regeneratorRuntime().wrap(function _loop$(_context) {
29
- while (1) switch (_context.prev = _context.next) {
30
- case 0:
31
- item = _step.value;
32
- targetProduct = priceData.find(function (n) {
33
- return n.id === item.id;
34
- });
35
- _context.next = 4;
36
- return getProduct(item.id);
37
- case 4:
38
- cartProduct = _context.sent;
39
- productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
40
- bundle = item._bundleOrigin;
41
- productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
42
- productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
43
- bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
44
- var _targetProduct$bundle;
45
- // 更新 bundle 的价格
46
- var targetBundle = targetProduct === null || targetProduct === void 0 || (_targetProduct$bundle = targetProduct.bundle_group) === null || _targetProduct$bundle === void 0 ? void 0 : _targetProduct$bundle.find(function (m) {
47
- return m.id === n.group_id;
48
- });
49
- if (targetBundle) {
50
- var targetBundleItem = targetBundle.bundle_item.find(function (m) {
51
- return m.id === n.id;
52
- });
53
- if (targetBundleItem.price_type === 'markdown') {
54
- targetBundleItem.price = new Decimal(targetBundleItem.price || 0).mul(-1).toNumber();
55
- }
56
- if (targetBundleItem) {
57
- return _objectSpread(_objectSpread({}, n), {}, {
58
- price: targetBundleItem.price,
59
- base_price: targetBundleItem.base_price
60
- });
61
- }
62
- }
63
- return n;
64
- });
65
- updateCart({
66
- _id: item._id,
67
- product: productInfo,
68
- bundle: bundle
69
- });
70
- case 11:
71
- case "end":
72
- return _context.stop();
73
- }
74
- }, _loop);
75
- });
76
- _iterator.s();
77
- case 4:
78
- if ((_step = _iterator.n()).done) {
79
- _context2.next = 8;
80
- break;
81
- }
82
- return _context2.delegateYield(_loop(), "t0", 6);
83
- case 6:
84
- _context2.next = 4;
85
- break;
86
- case 8:
87
- _context2.next = 13;
88
- break;
89
- case 10:
90
- _context2.prev = 10;
91
- _context2.t1 = _context2["catch"](1);
92
- _iterator.e(_context2.t1);
93
- case 13:
94
- _context2.prev = 13;
95
- _iterator.f();
96
- return _context2.finish(13);
97
- case 16:
98
- case "end":
99
- return _context2.stop();
100
- }
101
- }, _callee, null, [[1, 10, 13, 16]]);
102
- }));
103
- return _updateAllCartItemPrice.apply(this, arguments);
104
- }