@pisell/pisellos 0.0.10 → 0.0.13

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 (130) hide show
  1. package/dist/modules/Account/index.d.ts +4 -2
  2. package/dist/modules/Account/index.js +23 -36
  3. package/dist/modules/Account/types.d.ts +1 -0
  4. package/dist/modules/AccountList/index.d.ts +2 -0
  5. package/dist/modules/AccountList/index.js +34 -11
  6. package/dist/modules/Cart/index.d.ts +17 -11
  7. package/dist/modules/Cart/index.js +179 -121
  8. package/dist/modules/Cart/types.d.ts +98 -9
  9. package/dist/modules/Cart/types.js +8 -0
  10. package/dist/modules/Cart/utils.d.ts +114 -0
  11. package/dist/modules/Cart/utils.js +345 -0
  12. package/dist/modules/Date/index.d.ts +11 -12
  13. package/dist/modules/Date/index.js +104 -60
  14. package/dist/modules/Date/types.d.ts +51 -20
  15. package/dist/modules/Date/types.js +2 -5
  16. package/dist/modules/Date/utils.d.ts +35 -0
  17. package/dist/modules/Date/utils.js +211 -0
  18. package/dist/modules/Discount/index.d.ts +26 -0
  19. package/dist/modules/Discount/index.js +234 -0
  20. package/dist/modules/Discount/types.d.ts +66 -0
  21. package/dist/modules/Discount/types.js +5 -0
  22. package/dist/modules/Order/index.d.ts +16 -12
  23. package/dist/modules/Order/index.js +38 -166
  24. package/dist/modules/Order/types.d.ts +18 -41
  25. package/dist/modules/Order/types.js +0 -14
  26. package/dist/modules/Payment/index.d.ts +0 -2
  27. package/dist/modules/Payment/index.js +45 -76
  28. package/dist/modules/Payment/types.d.ts +0 -2
  29. package/dist/modules/Payment/types.js +2 -0
  30. package/dist/modules/Product/types.d.ts +48 -1
  31. package/dist/modules/ProductList/index.d.ts +1 -0
  32. package/dist/modules/ProductList/index.js +21 -1
  33. package/dist/modules/ProductList/types.d.ts +1 -0
  34. package/dist/modules/Resource/types.d.ts +6 -2
  35. package/dist/modules/Rules/index.d.ts +32 -0
  36. package/dist/modules/Rules/index.js +423 -0
  37. package/dist/modules/Rules/types.d.ts +46 -0
  38. package/dist/modules/Rules/types.js +5 -0
  39. package/dist/modules/Summary/index.d.ts +13 -0
  40. package/dist/modules/Summary/index.js +80 -0
  41. package/dist/modules/Summary/types.d.ts +13 -0
  42. package/dist/modules/Summary/types.js +1 -0
  43. package/dist/modules/Summary/utils.d.ts +19 -0
  44. package/dist/modules/Summary/utils.js +56 -0
  45. package/dist/plugins/index.d.ts +3 -2
  46. package/dist/plugins/index.js +2 -1
  47. package/dist/plugins/request.d.ts +4 -3
  48. package/dist/plugins/request.js +30 -30
  49. package/dist/plugins/shopStore.d.ts +4 -0
  50. package/dist/plugins/shopStore.js +1 -0
  51. package/dist/solution/BookingByStep/index.d.ts +73 -12
  52. package/dist/solution/BookingByStep/index.js +635 -99
  53. package/dist/solution/BookingByStep/types.d.ts +2 -0
  54. package/dist/solution/BookingByStep/types.js +11 -8
  55. package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
  56. package/dist/solution/BookingByStep/utils/products.js +47 -0
  57. package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
  58. package/dist/solution/BookingByStep/utils/resources.js +144 -79
  59. package/dist/solution/ShopDiscount/index.d.ts +50 -0
  60. package/dist/solution/ShopDiscount/index.js +546 -0
  61. package/dist/solution/ShopDiscount/types.d.ts +24 -0
  62. package/dist/solution/ShopDiscount/types.js +10 -0
  63. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  64. package/dist/solution/ShopDiscount/utils.js +7 -0
  65. package/dist/solution/index.d.ts +1 -0
  66. package/dist/solution/index.js +2 -1
  67. package/lib/modules/Account/index.d.ts +4 -2
  68. package/lib/modules/Account/index.js +14 -3
  69. package/lib/modules/Account/types.d.ts +1 -0
  70. package/lib/modules/AccountList/index.d.ts +2 -0
  71. package/lib/modules/AccountList/index.js +17 -0
  72. package/lib/modules/Cart/index.d.ts +17 -11
  73. package/lib/modules/Cart/index.js +72 -21
  74. package/lib/modules/Cart/types.d.ts +98 -9
  75. package/lib/modules/Cart/utils.d.ts +114 -0
  76. package/lib/modules/Cart/utils.js +320 -0
  77. package/lib/modules/Date/index.d.ts +11 -12
  78. package/lib/modules/Date/index.js +50 -31
  79. package/lib/modules/Date/types.d.ts +51 -20
  80. package/lib/modules/Date/types.js +0 -4
  81. package/lib/modules/Date/utils.d.ts +35 -0
  82. package/lib/modules/Date/utils.js +167 -0
  83. package/lib/modules/Discount/index.d.ts +26 -0
  84. package/lib/modules/Discount/index.js +118 -0
  85. package/lib/modules/Discount/types.d.ts +66 -0
  86. package/lib/modules/Discount/types.js +33 -0
  87. package/lib/modules/Order/index.d.ts +16 -12
  88. package/lib/modules/Order/index.js +23 -51
  89. package/lib/modules/Order/types.d.ts +18 -41
  90. package/lib/modules/Payment/index.d.ts +0 -2
  91. package/lib/modules/Payment/index.js +6 -17
  92. package/lib/modules/Payment/types.d.ts +0 -2
  93. package/lib/modules/Product/types.d.ts +48 -1
  94. package/lib/modules/ProductList/index.d.ts +1 -0
  95. package/lib/modules/ProductList/index.js +4 -0
  96. package/lib/modules/ProductList/types.d.ts +1 -0
  97. package/lib/modules/Resource/types.d.ts +6 -2
  98. package/lib/modules/Rules/index.d.ts +32 -0
  99. package/lib/modules/Rules/index.js +283 -0
  100. package/lib/modules/Rules/types.d.ts +46 -0
  101. package/lib/modules/Rules/types.js +33 -0
  102. package/lib/modules/Summary/index.d.ts +13 -0
  103. package/lib/modules/Summary/index.js +49 -0
  104. package/lib/modules/Summary/types.d.ts +13 -0
  105. package/lib/modules/Summary/types.js +17 -0
  106. package/lib/modules/Summary/utils.d.ts +19 -0
  107. package/lib/modules/Summary/utils.js +79 -0
  108. package/lib/plugins/index.d.ts +3 -2
  109. package/lib/plugins/index.js +3 -1
  110. package/lib/plugins/request.d.ts +4 -3
  111. package/lib/plugins/request.js +4 -20
  112. package/lib/plugins/shopStore.d.ts +4 -0
  113. package/lib/plugins/shopStore.js +17 -0
  114. package/lib/solution/BookingByStep/index.d.ts +73 -12
  115. package/lib/solution/BookingByStep/index.js +451 -24
  116. package/lib/solution/BookingByStep/types.d.ts +2 -0
  117. package/lib/solution/BookingByStep/types.js +3 -0
  118. package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
  119. package/lib/solution/BookingByStep/utils/products.js +60 -0
  120. package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
  121. package/lib/solution/BookingByStep/utils/resources.js +106 -49
  122. package/lib/solution/ShopDiscount/index.d.ts +50 -0
  123. package/lib/solution/ShopDiscount/index.js +321 -0
  124. package/lib/solution/ShopDiscount/types.d.ts +24 -0
  125. package/lib/solution/ShopDiscount/types.js +38 -0
  126. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  127. package/lib/solution/ShopDiscount/utils.js +32 -0
  128. package/lib/solution/index.d.ts +1 -0
  129. package/lib/solution/index.js +3 -1
  130. package/package.json +4 -4
@@ -7,8 +7,10 @@ import { OrderModule } from "../../modules/Order";
7
7
  import { PaymentModule } from "../../modules/Payment";
8
8
  import { ResourceListModule } from "../../modules/Resource";
9
9
  import { StepModule } from "../../modules/Step";
10
+ import { SummaryModule } from "../../modules/Summary";
10
11
  export interface BookingByStepState {
11
12
  cart: CartModule;
13
+ summary: SummaryModule;
12
14
  step: StepModule;
13
15
  products: ProductList;
14
16
  guests: GuestListModule;
@@ -5,23 +5,26 @@ import { GuestListModule } from "../../modules/Guests";
5
5
  import { OrderModule } from "../../modules/Order";
6
6
  import { PaymentModule } from "../../modules/Payment";
7
7
  import { StepModule } from "../../modules/Step";
8
+ import { SummaryModule } from "../../modules/Summary";
8
9
  export function createModule(moduleName, solutionName, name, version) {
9
10
  switch (moduleName) {
10
- case 'cart':
11
+ case "cart":
11
12
  return new CartModule("".concat(solutionName, "_").concat(name || moduleName), version);
12
- case 'step':
13
+ case "summary":
14
+ return new SummaryModule("".concat(solutionName, "_").concat(name || moduleName), version);
15
+ case "step":
13
16
  return new StepModule("".concat(solutionName, "_").concat(name || moduleName), version);
14
- case 'products':
17
+ case "products":
15
18
  return new ProductList("".concat(solutionName, "_").concat(name || moduleName), version);
16
- case 'guests':
19
+ case "guests":
17
20
  return new GuestListModule("".concat(solutionName, "_").concat(name || moduleName), version);
18
- case 'date':
21
+ case "date":
19
22
  return new DateModule("".concat(solutionName, "_").concat(name || moduleName), version);
20
- case 'accountList':
23
+ case "accountList":
21
24
  return new AccountListModule("".concat(solutionName, "_").concat(name || moduleName), version);
22
- case 'order':
25
+ case "order":
23
26
  return new OrderModule("".concat(solutionName, "_").concat(name || moduleName), version);
24
- case 'payment':
27
+ case "payment":
25
28
  return new PaymentModule("".concat(solutionName, "_").concat(name || moduleName), version);
26
29
  default:
27
30
  throw new Error("Unknown module type: ".concat(moduleName));
@@ -0,0 +1,11 @@
1
+ import { ProductData, ProductResourceItem } from "../../../modules";
2
+ /**
3
+ * 获取商品的可用资源
4
+ * @param product 商品数据
5
+ * @returns 可用资源
6
+ */
7
+ export declare const getAvailableProductResources: (products: ProductData[]) => {
8
+ resourceIds: number[];
9
+ rules: any[];
10
+ resourcesMap: Record<number, ProductResourceItem>;
11
+ };
@@ -0,0 +1,47 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ 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); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; }
7
+ /**
8
+ * 获取商品的可用资源
9
+ * @param product 商品数据
10
+ * @returns 可用资源
11
+ */
12
+ export var getAvailableProductResources = function getAvailableProductResources(products) {
13
+ var rules = []; // 每个商品对应的预约规则
14
+ var resourcesMap = {}; // 每个资源对应的商品
15
+ var resourceIds = []; // 所有商品的资源id
16
+ products.forEach(function (product) {
17
+ var _product$product_reso, _product$product_reso2;
18
+ var tempResourceIds = [];
19
+ product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 || (_product$product_reso = _product$product_reso.resources) === null || _product$product_reso === void 0 || (_product$product_reso2 = _product$product_reso.forEach) === null || _product$product_reso2 === void 0 || _product$product_reso2.call(_product$product_reso, function (resource) {
20
+ if ((resource === null || resource === void 0 ? void 0 : resource.status) == 1) {
21
+ var _resource$default_res, _resource$optional_re;
22
+ tempResourceIds.push(resource === null || resource === void 0 ? void 0 : resource.id);
23
+ if (!resourcesMap[resource === null || resource === void 0 ? void 0 : resource.id]) {
24
+ resourcesMap[resource === null || resource === void 0 ? void 0 : resource.id] = resource;
25
+ }
26
+ if (resource !== null && resource !== void 0 && (_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.length) {
27
+ resourceIds.push.apply(resourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.default_resource));
28
+ } else if (resource !== null && resource !== void 0 && (_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.length) {
29
+ resourceIds.push.apply(resourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource));
30
+ }
31
+ }
32
+ });
33
+ var rule = {};
34
+ if (product !== null && product !== void 0 && product.cut_off_time) {
35
+ rule.cut_off_time = product === null || product === void 0 ? void 0 : product.cut_off_time;
36
+ }
37
+ if (tempResourceIds) {
38
+ rule.resourceFormIds = _toConsumableArray(new Set(tempResourceIds));
39
+ }
40
+ rules.push(rule);
41
+ });
42
+ return {
43
+ resourceIds: _toConsumableArray(new Set(resourceIds)),
44
+ rules: rules,
45
+ resourcesMap: resourcesMap
46
+ };
47
+ };
@@ -1,27 +1,42 @@
1
1
  import { Dayjs } from 'dayjs';
2
+ import { CartItem } from '../../../modules';
2
3
  /**
3
4
  * 1. 获取资源列表
4
5
  * 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
5
6
  * 3. 格式化资源相关 格式化资源列表 --> 格式化资源 --> 获取时间切片列表 --> 判断单个时间切片是否可用 formatResources
6
7
  *
7
8
  */
8
- type DateType = Dayjs | string;
9
- interface TimeSliceItem {
10
- start: DateType;
11
- end: DateType;
9
+ type DateType = Dayjs;
10
+ export interface TimeSliceItem {
11
+ start_time: string;
12
+ end_time: string;
12
13
  start_at: DateType;
13
14
  end_at: DateType;
14
15
  [key: string]: any;
15
16
  }
16
- interface ResourceItem {
17
+ export interface ResourceItem {
17
18
  [key: string]: any;
18
19
  }
19
20
  interface BookingItem {
20
21
  [key: string]: any;
21
22
  }
22
- interface ProductItem {
23
- [key: string]: any;
24
- }
23
+ /**
24
+ * @title: 获取时间切片是否可用
25
+ * @description: 根据时间切片、资源、当前预约量判断时间切片是否可用
26
+ * @param {any} param1
27
+ * @return {*}
28
+ * @Author: zhiwei.Wang
29
+ */
30
+ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount }: {
31
+ timeSlice: TimeSliceItem;
32
+ time: any;
33
+ resource: ResourceItem;
34
+ currentCount: number;
35
+ }) => {
36
+ afterToDay: boolean;
37
+ capacity: boolean;
38
+ usable: boolean;
39
+ };
25
40
  /**
26
41
  * @title: 获取商品下绑定的资源列表
27
42
  * @description:
@@ -30,7 +45,7 @@ interface ProductItem {
30
45
  * @return {*}
31
46
  * @Author: zhiwei.Wang
32
47
  */
33
- export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, product: ProductItem) => any;
48
+ export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, cartItem: CartItem, cartList: CartItem[]) => ResourceItem[];
34
49
  export declare const getSumCapacity: () => number;
35
50
  /**
36
51
  * @title: 获取资源列表
@@ -56,6 +71,40 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
56
71
  resource: ResourceItem;
57
72
  duration: number;
58
73
  split: number;
59
- currentDate: DateType;
74
+ currentDate: DateType | string;
60
75
  }) => TimeSliceItem[];
76
+ /**
77
+ * @title: 获取时间切片列表的交集
78
+ * @description: 注意: 需要将多个时间切片列表合并在一起,然后判断交集
79
+ * @param {TimeSliceItem} times 多个时间切片
80
+ * @param {number} count 交集次数, 符合此次数的会返回
81
+ * @return {*}
82
+ * @Author: zhiwei.Wang
83
+ */
84
+ export declare const getTimesIntersection: (times: TimeSliceItem[], count: number) => any[];
85
+ /**
86
+ * @title: 根据ids筛选资源列表
87
+ * @description:
88
+ * @param {any} resourcesMap
89
+ * @param {any} ids
90
+ * @return {*}
91
+ * @Author: zhiwei.Wang
92
+ * @Date: 2024-09-19 20:23
93
+ */
94
+ export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceItem>, ids: number[]) => ResourceItem[];
95
+ /**
96
+ * @title: 根据资源id列表获取时间切片
97
+ * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
98
+ * @param {ResourceItem} resources
99
+ * @param {CartItem} cart
100
+ * @return {*}
101
+ * @Author: zhiwei.Wang
102
+ */
103
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split }: {
104
+ resourceIds: number[];
105
+ resourcesMap: any;
106
+ duration: number;
107
+ currentDate: DateType | string;
108
+ split: number;
109
+ }) => any[];
61
110
  export {};
@@ -1,10 +1,10 @@
1
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 _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; } } }; }
2
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ 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); }
4
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- 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; } } }; }
7
- 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); }
8
8
  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; }
9
9
  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; }
10
10
  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; }
@@ -148,7 +148,7 @@ var checkCapacity = function checkCapacity(_ref) {
148
148
  * @return {*}
149
149
  * @Author: zhiwei.Wang
150
150
  */
151
- var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
151
+ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
152
152
  var timeSlice = _ref2.timeSlice,
153
153
  time = _ref2.time,
154
154
  resource = _ref2.resource,
@@ -188,72 +188,61 @@ var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
188
188
  * @return {*}
189
189
  * @Author: zhiwei.Wang
190
190
  */
191
- export var getResourcesByProduct = function getResourcesByProduct(resourcesMap, product) {
191
+ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap, cartItem, cartList) {
192
192
  var _product$product_reso;
193
- // 过滤出开启的资源
194
- var _resources = ((product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.resources) || []).filter(function (d) {
195
- return d.status == 1;
196
- });
197
- var _iterator = _createForOfIteratorHelper(_resources),
198
- _step;
199
- try {
200
- var _loop = function _loop() {
201
- var item = _step.value;
202
- // 资源类型id
193
+ var product = cartItem._productOrigin;
194
+ return ((product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.resources) || []).reduce(function (acc, item) {
195
+ if ((item === null || item === void 0 ? void 0 : item.status) == 1) {
203
196
  var form_id = item.id;
204
-
205
197
  // 去重 可选资源和必选资源可能会有重复的
206
198
  item.optional_resource = (item.optional_resource || []).filter(function (d) {
207
199
  return item.default_resource.indexOf(d) == -1;
208
200
  });
209
201
 
210
- // 可选项
211
- var optional_resource = item.optional_resource.map(function (d) {
212
- return (
213
- // 合并数据, 将资源配置项添加到每一条内
214
- resourcesMap[d] ? Object.assign({}, resourcesMap[d], {
202
+ // 如果购物车里有 某一项的 resources 选中过了某些资源,则把这些资源给过滤掉
203
+ // 这里做一个拍平,把非当前 holder_id 的资源洗到一个数组里
204
+ var selectedResources = cartList.reduce(function (acc, d) {
205
+ if (d.holder_id !== cartItem.holder_id) {
206
+ var _d$_origin;
207
+ if ((_d$_origin = d._origin) !== null && _d$_origin !== void 0 && _d$_origin.resources) {
208
+ d._origin.resources.forEach(function (n) {
209
+ acc.push(n.id);
210
+ });
211
+ }
212
+ }
213
+ return acc;
214
+ }, []);
215
+ var optional_resource = item.optional_resource.reduce(function (childAcc, d) {
216
+ if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
217
+ childAcc.push(Object.assign({}, resourcesMap[d], {
215
218
  form_id: form_id,
216
219
  resourceType: item.type
217
- }) : null
218
- );
219
- })
220
- // 过滤空值, 商品绑定的资源可能已经不存在
221
- .filter(function (d) {
222
- return d;
223
- });
224
-
225
- // 默认项
226
- var default_resource = item.default_resource.map(function (d) {
227
- var item = resourcesMap[d];
228
- if (item) {
229
- item.is_default = 1;
230
- return Object.assign({}, item, {
220
+ }));
221
+ }
222
+ return childAcc;
223
+ }, []);
224
+ var default_resource = item.default_resource.reduce(function (childAcc, d) {
225
+ if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
226
+ childAcc.push(Object.assign({}, resourcesMap[d], {
231
227
  form_id: form_id,
232
- resourceType: item.type
233
- });
234
- } else {
235
- return null;
228
+ resourceType: item.type,
229
+ is_default: 1
230
+ }));
236
231
  }
237
- }).filter(function (d) {
238
- return d;
239
- });
232
+ return childAcc;
233
+ }, []);
240
234
 
241
235
  // 合并渲染
242
236
  item.renderList = optional_resource.concat(default_resource);
243
-
244
- // 统一字段 将id改为form_id
237
+ // renderList里 times 的每一项需要匹配一下当前时间,如果 times 里最小的end_at小于当前时间,则这个资源应该从 renderList 删除
238
+ item.renderList = item.renderList.filter(function (d) {
239
+ return dayjs(d.times[0].end_at).isAfter(dayjs());
240
+ });
245
241
  item.form_id = form_id;
246
- };
247
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
248
- _loop();
242
+ acc.push(item);
249
243
  }
250
- } catch (err) {
251
- _iterator.e(err);
252
- } finally {
253
- _iterator.f();
254
- }
255
- console.log('_resources', _resources);
256
- return _resources;
244
+ return acc;
245
+ }, []);
257
246
  };
258
247
  export var getSumCapacity = function getSumCapacity() {
259
248
  // let sum = 0;
@@ -277,30 +266,28 @@ export var formatResources = function formatResources(_ref3) {
277
266
  try {
278
267
  var _list = _toConsumableArray(resources);
279
268
  var maps = {};
280
- var _iterator2 = _createForOfIteratorHelper(_list),
281
- _step2;
269
+ var _iterator = _createForOfIteratorHelper(_list),
270
+ _step;
282
271
  try {
283
- var _loop2 = function _loop2() {
284
- var item = _step2.value;
272
+ var _loop = function _loop() {
273
+ var item = _step.value;
285
274
  var renderListMaps = {};
286
275
  item.renderList = item.renderList.map(function (d) {
287
276
  var res = formatResource(d, booking);
288
277
  renderListMaps[res.id] = res;
289
278
  return res;
290
- }).sort(function (a, b) {
291
- return b.usable ? 1 : -1;
292
279
  });
293
280
  maps[item.form_id] = _objectSpread(_objectSpread({}, item), {}, {
294
281
  renderListMaps: renderListMaps
295
282
  });
296
283
  };
297
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
298
- _loop2();
284
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
285
+ _loop();
299
286
  }
300
287
  } catch (err) {
301
- _iterator2.e(err);
288
+ _iterator.e(err);
302
289
  } finally {
303
- _iterator2.f();
290
+ _iterator.f();
304
291
  }
305
292
  return {
306
293
  list: _list,
@@ -339,8 +326,8 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
339
326
  var today = dayjs(currentDate).format('YYYY-MM-DD');
340
327
 
341
328
  // 解析开始和结束时间
342
- var startTime = dayjs("".concat(today, " ").concat(time.start_time));
343
- var endTime = dayjs("".concat(today, " ").concat(time.end_time));
329
+ var startTime = dayjs("".concat(time.start_at));
330
+ var endTime = dayjs("".concat(time.end_at));
344
331
 
345
332
  // 当前切片的开始时间
346
333
  var currentStart = startTime;
@@ -355,26 +342,104 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
355
342
  break;
356
343
  }
357
344
  var timeSlice = {
358
- start: currentStart.format('HH:mm'),
359
- end: currentEnd.format('HH:mm'),
345
+ start_time: currentStart.format('HH:mm'),
346
+ end_time: currentEnd.format('HH:mm'),
360
347
  start_at: currentStart,
361
348
  end_at: currentEnd
362
349
  };
363
-
364
- // 添加时间切片
365
- timeSlices.push(_objectSpread(_objectSpread({}, timeSlice), {}, {
366
- // 这里需要补充这个时间段内是否可预约
367
- _status: getIsUsableByTimeItem({
368
- timeSlice: timeSlice,
369
- time: time,
370
- resource: resource,
371
- currentCount: getSumCapacity()
372
- })
373
- }));
374
-
350
+ var _status = getIsUsableByTimeItem({
351
+ timeSlice: timeSlice,
352
+ time: time,
353
+ resource: resource,
354
+ currentCount: getSumCapacity()
355
+ });
356
+ if (_status.usable) {
357
+ // 添加时间切片 09:00 ~ 10:00 09:20 ~ 10:20 09:00 ~ 10:00 09:20 ~ 10:20 11:00 ~ 12:00 11:20 ~ 12:20
358
+ timeSlices.push(_objectSpread(_objectSpread({}, timeSlice), {}, {
359
+ // 这里需要补充这个时间段内是否可预约
360
+ _status: _status
361
+ }));
362
+ }
375
363
  // 移动到下一个开始时间(增加10分钟)
376
364
  currentStart = currentStart.add(split, 'minute');
377
365
  }
378
366
  });
379
367
  return timeSlices;
368
+ };
369
+
370
+ /**
371
+ * @title: 获取时间切片列表的交集
372
+ * @description: 注意: 需要将多个时间切片列表合并在一起,然后判断交集
373
+ * @param {TimeSliceItem} times 多个时间切片
374
+ * @param {number} count 交集次数, 符合此次数的会返回
375
+ * @return {*}
376
+ * @Author: zhiwei.Wang
377
+ */
378
+ export var getTimesIntersection = function getTimesIntersection(times, count) {
379
+ var obj = times.reduce(function (acc, item) {
380
+ var _key = "".concat(item.start_time, "-").concat(item.end_time);
381
+ if (!acc[_key]) {
382
+ acc[_key] = {
383
+ item: item,
384
+ count: 1
385
+ };
386
+ } else {
387
+ acc[_key].count += 1;
388
+ }
389
+ return acc;
390
+ }, {});
391
+
392
+ // 过滤出符合交集次数的
393
+ return Object.values(obj).filter(function (d) {
394
+ return d.count >= count;
395
+ }).map(function (d) {
396
+ return d.item;
397
+ });
398
+ };
399
+
400
+ /**
401
+ * @title: 根据ids筛选资源列表
402
+ * @description:
403
+ * @param {any} resourcesMap
404
+ * @param {any} ids
405
+ * @return {*}
406
+ * @Author: zhiwei.Wang
407
+ * @Date: 2024-09-19 20:23
408
+ */
409
+ export var getResourcesByIds = function getResourcesByIds(resourcesMap, ids) {
410
+ return (ids || []).map(function (id) {
411
+ return resourcesMap[id];
412
+ });
413
+ };
414
+
415
+ /**
416
+ * @title: 根据资源id列表获取时间切片
417
+ * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
418
+ * @param {ResourceItem} resources
419
+ * @param {CartItem} cart
420
+ * @return {*}
421
+ * @Author: zhiwei.Wang
422
+ */
423
+ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
424
+ var resourceIds = _ref5.resourceIds,
425
+ resourcesMap = _ref5.resourcesMap,
426
+ duration = _ref5.duration,
427
+ currentDate = _ref5.currentDate,
428
+ split = _ref5.split;
429
+ // 获取资源列表
430
+ var resources = getResourcesByIds(resourcesMap, resourceIds);
431
+
432
+ // 获取资源列表中所有的时间切片
433
+ var timeSliceList = resources.reduce(function (acc, item) {
434
+ return acc.concat(getTimeSlicesByResource({
435
+ resource: item,
436
+ duration: duration,
437
+ split: split,
438
+ currentDate: currentDate
439
+ }));
440
+ }, []);
441
+
442
+ // 获取时间切片列表的交集
443
+ var intersection = getTimesIntersection(timeSliceList, resources.length);
444
+ return intersection;
380
445
  };
@@ -0,0 +1,50 @@
1
+ import { Module, PisellCore } from "../../types";
2
+ import { BaseModule } from "../../modules/BaseModule";
3
+ import { Customer } from "./types";
4
+ import { Discount } from "../../modules/Discount/types";
5
+ export declare class ShopDiscountImpl extends BaseModule implements Module {
6
+ protected defaultName: string;
7
+ protected defaultVersion: string;
8
+ isSolution: boolean;
9
+ private request;
10
+ private window;
11
+ private store;
12
+ private options;
13
+ constructor(name?: string, version?: string);
14
+ initialize(core: PisellCore, options: any): Promise<void>;
15
+ destroy(): Promise<void>;
16
+ clear(): Promise<void>;
17
+ private initializePlugins;
18
+ private registerDependentModules;
19
+ private registerEventListeners;
20
+ setCustomer(customer: Customer): Promise<void>;
21
+ calcDiscount(productList: Record<string, any>[], options?: {
22
+ discountId: number;
23
+ isSelected: boolean;
24
+ }): {
25
+ productList: Record<string, any>[];
26
+ discountList: Discount[];
27
+ };
28
+ setDiscountSelected({ discountId, isSelected, }: {
29
+ discountId: number;
30
+ isSelected: boolean;
31
+ }): {
32
+ productList: Record<string, any>[];
33
+ discountList: Discount[];
34
+ };
35
+ setProductList(productList: Record<string, any>[]): void;
36
+ scanCode(code: string): Promise<{
37
+ isAvailable: boolean;
38
+ productList: Record<string, any>[];
39
+ discountList: Discount[];
40
+ }>;
41
+ calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
42
+ private getCustomer;
43
+ private isWalkIn;
44
+ private emitDiscountListChange;
45
+ private setDiscountList;
46
+ private getDiscountList;
47
+ private getCustomerWallet;
48
+ private loadPrepareConfig;
49
+ }
50
+ export default ShopDiscountImpl;