@pisell/pisellos 2.0.38 → 2.0.40

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 (57) hide show
  1. package/dist/modules/AccountList/index.js +17 -12
  2. package/dist/modules/Cart/index.d.ts +14 -0
  3. package/dist/modules/Cart/index.js +38 -1
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +2 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +23 -5
  6. package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
  7. package/dist/modules/Cart/utils/changePrice.js +104 -0
  8. package/dist/modules/Date/index.js +57 -6
  9. package/dist/modules/Discount/index.d.ts +1 -0
  10. package/dist/modules/Discount/index.js +13 -6
  11. package/dist/modules/Discount/types.d.ts +10 -0
  12. package/dist/modules/ProductList/index.d.ts +7 -0
  13. package/dist/modules/ProductList/index.js +102 -39
  14. package/dist/modules/Rules/index.js +191 -75
  15. package/dist/modules/Rules/types.d.ts +7 -1
  16. package/dist/modules/Schedule/index.d.ts +9 -1
  17. package/dist/modules/Schedule/index.js +122 -2
  18. package/dist/modules/Schedule/types.d.ts +13 -0
  19. package/dist/solution/BookingByStep/index.d.ts +120 -30
  20. package/dist/solution/BookingByStep/index.js +750 -1078
  21. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  22. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  23. package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
  24. package/dist/solution/BookingByStep/utils/resources.js +39 -94
  25. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  26. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  27. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  28. package/dist/solution/ShopDiscount/index.js +119 -44
  29. package/lib/modules/AccountList/index.js +4 -0
  30. package/lib/modules/Cart/index.d.ts +14 -0
  31. package/lib/modules/Cart/index.js +34 -1
  32. package/lib/modules/Cart/utils/cartProduct.d.ts +2 -0
  33. package/lib/modules/Cart/utils/cartProduct.js +16 -5
  34. package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
  35. package/lib/modules/Cart/utils/changePrice.js +78 -0
  36. package/lib/modules/Date/index.js +62 -10
  37. package/lib/modules/Discount/index.d.ts +1 -0
  38. package/lib/modules/Discount/index.js +17 -6
  39. package/lib/modules/Discount/types.d.ts +10 -0
  40. package/lib/modules/ProductList/index.d.ts +7 -0
  41. package/lib/modules/ProductList/index.js +45 -0
  42. package/lib/modules/Rules/index.js +142 -62
  43. package/lib/modules/Rules/types.d.ts +7 -1
  44. package/lib/modules/Schedule/index.d.ts +9 -1
  45. package/lib/modules/Schedule/index.js +79 -1
  46. package/lib/modules/Schedule/types.d.ts +13 -0
  47. package/lib/solution/BookingByStep/index.d.ts +120 -30
  48. package/lib/solution/BookingByStep/index.js +389 -587
  49. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  50. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  51. package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
  52. package/lib/solution/BookingByStep/utils/resources.js +23 -59
  53. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  54. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  55. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  56. package/lib/solution/ShopDiscount/index.js +91 -19
  57. package/package.json +1 -1
@@ -0,0 +1,47 @@
1
+ import { CartItem } from "../../../modules";
2
+ import { CapacityItem, ResourceItem } from "./resources";
3
+ /**
4
+ * @title: 基于选择的商品格式化容量
5
+ * @description:
6
+ * @param {any} param1
7
+ * @return {*}
8
+ * @Author: zhiwei.Wang
9
+ */
10
+ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
11
+ /**
12
+ * @title: 获取总容量
13
+ * @description:
14
+ * @param {object} capacity 为 formatDefaultCapacitys()的结果
15
+ * @return {*}
16
+ * @Author: zhiwei.Wang
17
+ */
18
+ export declare const getSumCapacity: ({ capacity }: {
19
+ capacity: CapacityItem[];
20
+ }) => number;
21
+ /**
22
+ * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
23
+ *
24
+ * @export
25
+ * @param {CartItem} targetCartItem
26
+ * @return {*}
27
+ */
28
+ export declare function getCapacityInfoByCartItem(targetCartItem: CartItem): {
29
+ formatCapacity: CapacityItem[];
30
+ currentCapacity: number;
31
+ };
32
+ /**
33
+ * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
34
+ * @description:
35
+ * @param {object} resource
36
+ * @return {*}
37
+ * @Author: jinglin.tan
38
+ */
39
+ export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
40
+ /**
41
+ * 检查资源是否有足够的容量供额外使用
42
+ * @param currentCapacity - 当前已使用的容量
43
+ * @param requiredCapacity - 需要的额外容量
44
+ * @param maxCapacity - 最大允许容量
45
+ * @returns 如果资源可以容纳额外的容量则返回 true
46
+ */
47
+ export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
@@ -0,0 +1,106 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/solution/BookingByStep/utils/capacity.ts
20
+ var capacity_exports = {};
21
+ __export(capacity_exports, {
22
+ checkResourceCanUseByCapacity: () => checkResourceCanUseByCapacity,
23
+ checkSubResourcesCapacity: () => checkSubResourcesCapacity,
24
+ formatDefaultCapacitys: () => formatDefaultCapacitys,
25
+ getCapacityInfoByCartItem: () => getCapacityInfoByCartItem,
26
+ getSumCapacity: () => getSumCapacity
27
+ });
28
+ module.exports = __toCommonJS(capacity_exports);
29
+ var formatDefaultCapacitys = ({
30
+ capacity,
31
+ product_bundle
32
+ }) => {
33
+ if ((capacity == null ? void 0 : capacity.type) === "package") {
34
+ return (product_bundle || []).map((d) => {
35
+ const id = d.bundle_product_id;
36
+ const item = ((capacity == null ? void 0 : capacity.package) || []).find(
37
+ (item2) => item2.product_id === id
38
+ );
39
+ return {
40
+ id,
41
+ value: item ? d.num || 0 : 0,
42
+ name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
43
+ };
44
+ });
45
+ }
46
+ if ((capacity == null ? void 0 : capacity.type) === "custom") {
47
+ return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
48
+ return {
49
+ id: d.id,
50
+ value: d.min,
51
+ name: d.name
52
+ };
53
+ });
54
+ }
55
+ return [{ id: 0, value: 1, name: "" }];
56
+ };
57
+ var getSumCapacity = ({ capacity }) => {
58
+ let sum = 0;
59
+ for (let item of capacity || []) {
60
+ sum += item.value;
61
+ }
62
+ return sum;
63
+ };
64
+ function getCapacityInfoByCartItem(targetCartItem) {
65
+ var _a;
66
+ const formatCapacity = formatDefaultCapacitys({
67
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
68
+ product_bundle: targetCartItem._origin.product.product_bundle
69
+ });
70
+ const currentCapacity = getSumCapacity({ capacity: formatCapacity });
71
+ return {
72
+ formatCapacity,
73
+ currentCapacity
74
+ };
75
+ }
76
+ var checkSubResourcesCapacity = (resource) => {
77
+ if (resource.children && resource.children.length) {
78
+ let countCapacity = resource.capacity;
79
+ resource.children.forEach((child, index) => {
80
+ if (index === resource.children.length - 1) {
81
+ child.capacity = countCapacity;
82
+ return;
83
+ }
84
+ if (child.capacity <= countCapacity) {
85
+ countCapacity -= child.capacity;
86
+ } else {
87
+ child.capacity = countCapacity;
88
+ countCapacity = 0;
89
+ }
90
+ });
91
+ }
92
+ };
93
+ var checkResourceCanUseByCapacity = (currentCapacity, requiredCapacity, maxCapacity) => {
94
+ if (currentCapacity < 0 || requiredCapacity < 0 || maxCapacity <= 0) {
95
+ return false;
96
+ }
97
+ return currentCapacity + requiredCapacity <= maxCapacity;
98
+ };
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ checkResourceCanUseByCapacity,
102
+ checkSubResourcesCapacity,
103
+ formatDefaultCapacitys,
104
+ getCapacityInfoByCartItem,
105
+ getSumCapacity
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,7 +97,10 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
97
97
  } | undefined;
98
98
  } | undefined;
99
99
  hasFlexibleDuration?: boolean | undefined;
100
- operating_day_boundary?: string | undefined;
100
+ operating_day_boundary?: {
101
+ type: string;
102
+ time: string;
103
+ } | undefined;
101
104
  }) => TimeSliceItem[];
102
105
  /**
103
106
  * @title: 获取时间切片列表的交集
@@ -135,7 +138,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
135
138
  * @return {*}
136
139
  * @Author: zhiwei.Wang
137
140
  */
138
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
141
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
139
142
  resourceIds: number[];
140
143
  resourcesMap: any;
141
144
  duration: number;
@@ -154,7 +157,10 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
154
157
  } | undefined;
155
158
  } | undefined;
156
159
  hasFlexibleDuration?: boolean | undefined;
157
- operating_day_boundary?: string | undefined;
160
+ operating_day_boundary?: {
161
+ type: string;
162
+ time: string;
163
+ } | undefined;
158
164
  }) => any[];
159
165
  /**
160
166
  * @title: 获取其他人的已选资源
@@ -174,37 +180,11 @@ export declare const getOthersSelectedResources: (cartItems: CartItem[], account
174
180
  * @Author: jinglin.tan
175
181
  */
176
182
  export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
177
- interface CapacityItem {
183
+ export interface CapacityItem {
178
184
  id: number;
179
185
  value: number;
180
186
  name: string;
181
187
  }
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;
208
188
  /**
209
189
  * @title: 根据日期范围过滤日程
210
190
  *
@@ -242,4 +222,22 @@ export declare function getResourcesIdsByProduct(product: ProductData): number[]
242
222
  * @return {*}
243
223
  */
244
224
  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;
245
243
  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
- checkSubResourcesCapacity: () => checkSubResourcesCapacity,
33
+ checkTwoResourcesIntersection: () => checkTwoResourcesIntersection,
34
+ filterResourcesByFormItem: () => filterResourcesByFormItem,
34
35
  filterScheduleByDateRange: () => filterScheduleByDateRange,
35
- formatDefaultCapacitys: () => formatDefaultCapacitys,
36
36
  formatResources: () => formatResources,
37
37
  getIsUsableByTimeItem: () => getIsUsableByTimeItem,
38
38
  getOthersCartSelectedResources: () => getOthersCartSelectedResources,
@@ -40,7 +40,6 @@ __export(resources_exports, {
40
40
  getResourcesByIds: () => getResourcesByIds,
41
41
  getResourcesByProduct: () => getResourcesByProduct,
42
42
  getResourcesIdsByProduct: () => getResourcesIdsByProduct,
43
- getSumCapacity: () => getSumCapacity,
44
43
  getTimeSlicesByResource: () => getTimeSlicesByResource,
45
44
  getTimeSlicesByResources: () => getTimeSlicesByResources,
46
45
  getTimesIntersection: () => getTimesIntersection,
@@ -366,7 +365,8 @@ var getTimeSlicesByResource = ({
366
365
  resourcesUseableMap[resource.id] = _status.usable;
367
366
  }
368
367
  if (_status.usable) {
369
- if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= operating_day_boundary) {
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")) {
370
370
  break;
371
371
  }
372
372
  timeSlices.push({
@@ -521,58 +521,6 @@ 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
- };
576
524
  function filterScheduleByDateRange(schedule, startDate, endDate) {
577
525
  if (!(schedule == null ? void 0 : schedule.length))
578
526
  return [];
@@ -636,12 +584,29 @@ function sortCombinedResources(resourcesList) {
636
584
  });
637
585
  return newResourcesList;
638
586
  }
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
+ }
639
604
  // Annotate the CommonJS export names for ESM import in node:
640
605
  0 && (module.exports = {
641
606
  checkSessionProductLeadTime,
642
- checkSubResourcesCapacity,
607
+ checkTwoResourcesIntersection,
608
+ filterResourcesByFormItem,
643
609
  filterScheduleByDateRange,
644
- formatDefaultCapacitys,
645
610
  formatResources,
646
611
  getIsUsableByTimeItem,
647
612
  getOthersCartSelectedResources,
@@ -649,7 +614,6 @@ function sortCombinedResources(resourcesList) {
649
614
  getResourcesByIds,
650
615
  getResourcesByProduct,
651
616
  getResourcesIdsByProduct,
652
- getSumCapacity,
653
617
  getTimeSlicesByResource,
654
618
  getTimeSlicesByResources,
655
619
  getTimesIntersection,
@@ -1,3 +1,4 @@
1
+ import { Dayjs } from "dayjs";
1
2
  import { ResourceItem, TimeSliceItem } from "./resources";
2
3
  /**
3
4
  * 计算资源在指定时间段内的总可用时间(以分钟为单位)
@@ -23,3 +24,13 @@ export declare function findFastestAvailableResource({ resources, currentCapacit
23
24
  currentCapacity?: number;
24
25
  countMap?: Record<number, number>;
25
26
  }): 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,6 +30,7 @@ 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,
33
34
  findFastestAvailableResource: () => findFastestAvailableResource
34
35
  });
35
36
  module.exports = __toCommonJS(timeslots_exports);
@@ -152,8 +153,14 @@ function findFastestAvailableResource({
152
153
  }
153
154
  return selectedResource;
154
155
  }
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
+ }
155
161
  // Annotate the CommonJS export names for ESM import in node:
156
162
  0 && (module.exports = {
157
163
  calculateResourceAvailableTime,
164
+ filterConditionTimeSlots,
158
165
  findFastestAvailableResource
159
166
  });
@@ -10,6 +10,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
10
10
  private window;
11
11
  private store;
12
12
  private options;
13
+ private hooks?;
13
14
  constructor(name?: string, version?: string);
14
15
  initialize(core: PisellCore, options: any): Promise<void>;
15
16
  destroy(): Promise<void>;
@@ -37,6 +38,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
37
38
  isAvailable: boolean;
38
39
  productList: Record<string, any>[];
39
40
  discountList: Discount[];
41
+ type: "server" | "clientCalc";
40
42
  }>;
41
43
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
42
44
  private getCustomer;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/solution/ShopDiscount/index.ts
@@ -27,6 +37,7 @@ var import_BaseModule = require("../../modules/BaseModule");
27
37
  var import_types = require("./types");
28
38
  var import_Discount = require("../../modules/Discount");
29
39
  var import_Rules = require("../../modules/Rules");
40
+ var import_decimal = __toESM(require("decimal.js"));
30
41
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
31
42
  constructor(name, version) {
32
43
  super(name, version);
@@ -43,9 +54,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
43
54
  }
44
55
  // =========== 生命周期方法 ===========
45
56
  async initialize(core, options) {
57
+ var _a, _b;
46
58
  this.core = core;
47
59
  this.options = options;
48
60
  this.store = { ...this.store, ...options.store || {} };
61
+ this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
49
62
  console.log("[ShopDiscount] 初始化完成");
50
63
  this.initializePlugins();
51
64
  this.registerDependentModules();
@@ -118,7 +131,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
118
131
  this.loadPrepareConfig({
119
132
  customerId: customer.id,
120
133
  action: "create",
121
- with_good_pass: 1
134
+ with_good_pass: 1,
135
+ with_discount_card: 1
122
136
  });
123
137
  }
124
138
  );
@@ -191,6 +205,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
191
205
  const rulesModule = this.store.rules;
192
206
  if (!rulesModule) {
193
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",
194
217
  isAvailable: false,
195
218
  productList: this.store.productList || [],
196
219
  discountList: this.getDiscountList()
@@ -225,6 +248,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
225
248
  }
226
249
  }
227
250
  return {
251
+ type: "clientCalc",
228
252
  isAvailable: isAvailable || false,
229
253
  productList: newProductList || this.store.productList || [],
230
254
  discountList: newDiscountList || this.getDiscountList()
@@ -232,6 +256,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
232
256
  } catch (error) {
233
257
  console.error("[ShopDiscount] 扫码出错:", error);
234
258
  return {
259
+ type: "clientCalc",
235
260
  isAvailable: false,
236
261
  productList: this.store.productList || [],
237
262
  discountList: this.getDiscountList()
@@ -267,22 +292,39 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
267
292
  const productList = this.store.productList || [];
268
293
  const editModeDiscountList = [];
269
294
  productList.forEach((item) => {
295
+ var _a2;
270
296
  if (item.booking_id) {
297
+ const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
271
298
  (item.discount_list || []).forEach((discount) => {
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
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);
285
304
  });
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
+ }
286
328
  }
287
329
  });
288
330
  }
@@ -291,6 +333,33 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
291
333
  ...editModeDiscountList,
292
334
  ...discountList.filter((item) => !item.isDisabled)
293
335
  ];
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
+ var _a3;
353
+ const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
354
+ const targetIdTimes = (allUsedProductIds == null ? void 0 : allUsedProductIds.filter((n) => n === id).length) || 0;
355
+ return targetIdTimes >= sameIdTimes || isProductFree(id);
356
+ });
357
+ if (!item.isSelected && isAllProductUsedOrFree) {
358
+ item.isDisabledForProductUsed = true;
359
+ } else {
360
+ item.isDisabledForProductUsed = false;
361
+ }
362
+ });
294
363
  (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
295
364
  this.emitDiscountListChange(newDiscountList);
296
365
  return newDiscountList;
@@ -303,11 +372,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
303
372
  // 获取客户钱包信息
304
373
  async getCustomerWallet(id) {
305
374
  try {
306
- const result = await this.request.get(`/customer/info/wallet/${id}`, {
307
- wallet_pass_tags: ["good_pass"]
375
+ const result = await this.request.get(`/customer/info/${id}`, {
376
+ with_trashed: 1
308
377
  });
309
378
  if (result == null ? void 0 : result.data) {
310
- const { wallet_pass_list, ...customer } = result.data;
379
+ const { ...customer } = result.data;
311
380
  this.setCustomer(customer);
312
381
  await this.core.effects.emit(
313
382
  import_types.ShopDiscountHooks.onScanCustomerChange,
@@ -326,12 +395,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
326
395
  const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
327
396
  customer_id: customerId,
328
397
  action: "create",
329
- with_good_pass: 1
398
+ with_good_pass: 1,
399
+ with_discount_card: 1
330
400
  }));
331
401
  const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
332
402
  (item) => item.isScan
333
403
  );
334
- const newDiscountList = [...scanDiscount, ...goodPassList || []];
404
+ const scanDiscountIds = scanDiscount.map((n) => n.id);
405
+ const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
406
+ const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
335
407
  this.setDiscountList(newDiscountList || []);
336
408
  if ((_d = this.store.productList) == null ? void 0 : _d.length) {
337
409
  const result = this.calcDiscount(this.store.productList);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.38",
4
+ "version": "2.0.40",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",