@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
@@ -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/BookingByStep/index.ts
@@ -24,6 +34,11 @@ __export(BookingByStep_exports, {
24
34
  module.exports = __toCommonJS(BookingByStep_exports);
25
35
  var import_BaseModule = require("../../modules/BaseModule");
26
36
  var import_types = require("./types");
37
+ var import_products = require("./utils/products");
38
+ var import_resources = require("./utils/resources");
39
+ var import_dayjs = __toESM(require("dayjs"));
40
+ var import_utils = require("../../modules/Resource/utils");
41
+ var import_lodash_es = require("lodash-es");
27
42
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
28
43
  constructor() {
29
44
  super(...arguments);
@@ -39,10 +54,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
39
54
  console.log("[BookingByStep] 初始化完成");
40
55
  this.request = core.getPlugin("request");
41
56
  this.window = core.getPlugin("window");
57
+ this.shopStore = core.getPlugin("shopStore");
42
58
  if (!this.request) {
43
59
  throw new Error("bookingByStep解决方案需要 request 插件支持");
44
60
  }
45
- const moduleArr = ["cart", "step", "products", "guests", "date", "accountList", "order", "payment"];
61
+ const moduleArr = [
62
+ "cart",
63
+ "summary",
64
+ "step",
65
+ "products",
66
+ "guests",
67
+ "date",
68
+ "accountList",
69
+ "order",
70
+ "payment"
71
+ ];
46
72
  moduleArr.forEach((step) => {
47
73
  const targetModule = (0, import_types.createModule)(step, this.name);
48
74
  if (targetModule) {
@@ -64,15 +90,32 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
64
90
  step: this.store.step.getCurrentStep()
65
91
  };
66
92
  }
93
+ // step: 下一个
67
94
  next() {
68
95
  this.store.step.nextStep();
69
96
  }
97
+ // step: 上一个
98
+ back() {
99
+ this.store.step.prevStep();
100
+ }
101
+ // 跳转到指定步骤
102
+ gotoStep(index) {
103
+ this.store.step.gotoStep(index);
104
+ }
105
+ // 获取所有step
106
+ getStepList() {
107
+ return this.store.step.getStepList();
108
+ }
70
109
  // 获取购物车里 temp.xxx的方法
71
110
  async getStoreCart(key) {
72
111
  return this.store.cart.getTemp(key);
73
112
  }
74
113
  // 加载商品,然后导到商品列表里去
75
- async loadProducts({ category_ids, product_ids }) {
114
+ async loadProducts({
115
+ category_ids = [],
116
+ product_ids = [],
117
+ collection = []
118
+ }) {
76
119
  const productsData = await this.request.post(`/product/query`, {
77
120
  open_quotation: 1,
78
121
  open_bundle: 1,
@@ -81,18 +124,25 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
81
124
  num: 500,
82
125
  skip: 1,
83
126
  category_ids,
84
- ids: product_ids
127
+ ids: product_ids,
128
+ collection
85
129
  });
86
130
  this.store.products.addProduct(productsData.data.list);
131
+ return productsData.data.list;
87
132
  }
88
- // 往购物车里加一些商品/服务相关的选中数据
89
- async storeProducts(productData, { cover = false } = {}) {
90
- if (cover) {
91
- this.store.cart.storeTemp("products", productData);
92
- } else {
93
- const currentProducts = await this.store.cart.getTemp("products") || [];
94
- this.store.cart.storeTemp("products", [...currentProducts, ...productData]);
133
+ async storeProduct(productData) {
134
+ const activeAccount = this.getActiveAccount();
135
+ if (!activeAccount) {
136
+ throw new Error("没有找到当前账户");
95
137
  }
138
+ const { bundle, options, origin, product_variant_id } = productData || {};
139
+ const product = { ...origin, product_variant_id };
140
+ this.store.cart.addItem({
141
+ account: activeAccount,
142
+ product,
143
+ bundle,
144
+ options
145
+ });
96
146
  }
97
147
  // 添加账户或者 guest
98
148
  async addAccount(accounts) {
@@ -102,42 +152,104 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
102
152
  }
103
153
  // 获取所有账户
104
154
  async getAccounts() {
105
- return this.store.accountList.getAccounts();
155
+ const accounts = this.store.accountList.getAccounts();
156
+ return accounts.map((account) => account.getAccount());
157
+ }
158
+ checkHasLoginAccount() {
159
+ const accounts = this.store.accountList.getAccounts();
160
+ return accounts.some((account) => account.getLoginStatus());
161
+ }
162
+ setActiveAccount(id) {
163
+ this.store.accountList.setActiveAccount(id);
164
+ }
165
+ getActiveAccount() {
166
+ const activeAccount = this.store.accountList.getActiveAccount();
167
+ return activeAccount ? activeAccount.getAccount() : null;
168
+ }
169
+ removeAccount(id) {
170
+ this.store.accountList.removeAccount(id);
171
+ this.clearCartByAccount(id);
106
172
  }
107
173
  // 设置日期范围,注入到日期模块中
108
174
  async setDateRange(dateRange) {
175
+ this.store.date.setDateRange(dateRange);
109
176
  }
110
177
  // 获取日期模块里选中的日期
111
178
  async getRangeDate() {
112
179
  return "2024-01-01";
113
180
  }
181
+ async getCart() {
182
+ return this.store.cart.getItems();
183
+ }
114
184
  // 获取商品/服务的可用日期
115
- async getAvailableDate() {
116
- const products = await this.getStoreCart("products");
117
- console.log(products);
185
+ async getAvailableDate(params = {}) {
186
+ var _a, _b, _c, _d;
187
+ const { products, startDate, endDate } = params;
188
+ const tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
189
+ const tempStartDate = startDate || ((_b = (_a = this.otherParams) == null ? void 0 : _a.dateRange) == null ? void 0 : _b[0]);
190
+ const tempEndDate = endDate || ((_d = (_c = this.otherParams) == null ? void 0 : _c.dateRange) == null ? void 0 : _d[1]);
191
+ if (!tempProducts.length) {
192
+ return [];
193
+ }
194
+ const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
195
+ console.log("resourceIds", tempProducts);
196
+ this.otherParams.currentResourcesMap = resourcesMap;
197
+ const res = await this.store.date.getMonthDates({
198
+ query: {
199
+ start_date: tempStartDate,
200
+ end_date: tempEndDate,
201
+ resource_ids: resourceIds
202
+ },
203
+ rules
204
+ });
205
+ return res;
118
206
  }
119
- // 获取具体资源的可用时段
120
- async getResourceTimeslot() {
207
+ /**
208
+ * 获取购物车汇总信息
209
+ */
210
+ async getSummary() {
211
+ const cartItems = this.store.cart.getItems();
212
+ const summary = await this.store.summary.getSummary(cartItems);
213
+ return summary;
121
214
  }
122
215
  // 获取可选择的商品、服务列表
123
216
  async getProducts() {
124
217
  return this.store.products.getProducts();
125
218
  }
126
- // 往购物车里加一些资源相关的选中数据
127
- async storeResources(resources) {
128
- this.store.cart.storeTemp("resources", resources);
129
- }
130
219
  // 如果用户登录
131
- async setLoginAccount(account) {
132
- const accounts = await this.getAccounts();
133
- const mainAccount = accounts.find((n) => n.getLoginStatus());
134
- mainAccount == null ? void 0 : mainAccount.setAccountInfo(account);
220
+ async setLoginAccount(accountId, accountInfo) {
221
+ const account = this.store.accountList.getAccount(accountId);
222
+ if (account) {
223
+ account.setAccountInfo(accountInfo);
224
+ const cartItems = this.store.cart.getItems();
225
+ cartItems.forEach((item) => {
226
+ if (item.holder_id === accountId) {
227
+ this.store.cart.updateItem({
228
+ _id: item._id,
229
+ account: accountInfo
230
+ });
231
+ }
232
+ });
233
+ } else {
234
+ throw new Error(`没有找到${accountId}账户`);
235
+ }
135
236
  }
136
237
  // 生成购物车的正规数据
137
238
  async generateCartData() {
138
239
  }
139
240
  // 购物车提交订单
140
241
  async submitOrder() {
242
+ const cartItems = this.store.cart.getItems();
243
+ cartItems.forEach((item) => {
244
+ item._origin.resources = item._origin.resources.map((n) => {
245
+ const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
246
+ delete newResourcesItem.id;
247
+ delete newResourcesItem.main_field;
248
+ delete newResourcesItem.resourceType;
249
+ return { ...newResourcesItem };
250
+ });
251
+ });
252
+ return this.store.order.commitOrder({ query: { cartItems } });
141
253
  }
142
254
  // 拉起支付模块
143
255
  async pay() {
@@ -155,6 +267,321 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
155
267
  async getOtherParams() {
156
268
  return this.otherParams;
157
269
  }
270
+ // 更新购物车
271
+ updateCart(params) {
272
+ this.store.cart.updateItem(params);
273
+ }
274
+ // 删除购物车里某个商品
275
+ deleteCart(product_id) {
276
+ }
277
+ // 清空购物车
278
+ clearCart() {
279
+ this.store.cart.clear();
280
+ }
281
+ // 基于账户清空购物车
282
+ clearCartByAccount(account_id) {
283
+ this.store.cart.clearCartByAccount(account_id);
284
+ }
285
+ destory() {
286
+ var _a, _b, _c, _d, _e, _f;
287
+ (_a = this.store.cart) == null ? void 0 : _a.destory();
288
+ (_b = this.store.step) == null ? void 0 : _b.destory();
289
+ (_c = this.store.products) == null ? void 0 : _c.destory();
290
+ (_d = this.store.guests) == null ? void 0 : _d.destory();
291
+ (_e = this.store.date) == null ? void 0 : _e.destory();
292
+ (_f = this.store.accountList) == null ? void 0 : _f.destory();
293
+ this.core.effects.offByModuleDestroy(this.name);
294
+ this.core.unregisterModule(this);
295
+ }
296
+ // 获取当前购物车内所有关联的资源列表,拼装数据格式
297
+ getResourcesList() {
298
+ const dateRange = this.store.date.getDateRange();
299
+ const resources = [];
300
+ dateRange.forEach((n) => {
301
+ if (n.resource)
302
+ resources.push(...n.resource);
303
+ });
304
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
305
+ const cartItems = this.store.cart.getItems();
306
+ const arr = [];
307
+ cartItems.forEach((cartItem) => {
308
+ const productResources = (0, import_resources.getResourcesByProduct)(
309
+ resourcesMap,
310
+ cartItem,
311
+ cartItems
312
+ );
313
+ arr.push({
314
+ id: cartItem.id,
315
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
316
+ _id: cartItem._id,
317
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
318
+ product: cartItem._productOrigin,
319
+ resources: productResources,
320
+ holder_id: cartItem.holder_id,
321
+ holder_name: cartItem.holder_title
322
+ });
323
+ });
324
+ return arr;
325
+ }
326
+ // 通过资源列表和指定的资源 id,获取指定资源的时间切片
327
+ getResourceTimeSlot({
328
+ product,
329
+ resources,
330
+ currentResourceId
331
+ }) {
332
+ const dateRange = this.store.date.getDateRange();
333
+ const timeSlots = (0, import_resources.getTimeSlicesByResource)({
334
+ resource: resources.find((n) => n.id === currentResourceId),
335
+ duration: product.duration.value,
336
+ split: 10,
337
+ currentDate: dateRange[0].date
338
+ });
339
+ return timeSlots;
340
+ }
341
+ // 自动分派可用的资源-单种资源类型
342
+ autoSelectResource({
343
+ resourceProductData,
344
+ resources,
345
+ timeSlots
346
+ }) {
347
+ const dateRange = this.store.date.getDateRange();
348
+ if (timeSlots) {
349
+ const duration = resourceProductData.product.duration.value;
350
+ const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
351
+ const end_time = (0, import_dayjs.default)(`${dateRange[0].date} ${start_time}`).add(duration, resourceProductData.product.duration.type).format("HH:mm");
352
+ let targetResource = null;
353
+ for (const n of resources) {
354
+ const canUseTime = n.times.find(
355
+ (item) => (0, import_resources.getIsUsableByTimeItem)({
356
+ timeSlice: item,
357
+ time: { start_time, end_time },
358
+ resource: n,
359
+ currentCount: 1
360
+ })
361
+ );
362
+ if (canUseTime) {
363
+ targetResource = n;
364
+ break;
365
+ }
366
+ }
367
+ return {
368
+ selectedResource: targetResource
369
+ };
370
+ } else {
371
+ const duration = resourceProductData.product.duration.value;
372
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
373
+ const resourceIds = resources.map((n) => n.id);
374
+ const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
375
+ resourceIds,
376
+ resourcesMap,
377
+ duration,
378
+ currentDate: dateRange[0].date,
379
+ split: 10
380
+ });
381
+ if (!timeSlots2) {
382
+ return;
383
+ }
384
+ return {
385
+ timeSlots: timeSlots2,
386
+ selectedResource: resources[0]
387
+ };
388
+ }
389
+ }
390
+ // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
391
+ autoSelectAccountResources({
392
+ holder_id,
393
+ resources_code,
394
+ timeSlots
395
+ }) {
396
+ var _a;
397
+ const dateRange = this.store.date.getDateRange();
398
+ const cartItems = this.store.cart.getItems();
399
+ const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id);
400
+ let duration = accountCartItems.reduce((acc, n) => {
401
+ return acc + n._productOrigin.duration.value;
402
+ }, 0);
403
+ let durationType = ((_a = accountCartItems == null ? void 0 : accountCartItems[0]) == null ? void 0 : _a._productOrigin.duration.type) || "minutes";
404
+ const resources = [];
405
+ accountCartItems.forEach((item) => {
406
+ var _a2, _b;
407
+ (_b = (_a2 = item._productOrigin.product_resource) == null ? void 0 : _a2.resources) == null ? void 0 : _b.forEach((n) => {
408
+ if (n.code === resources_code) {
409
+ resources.push(...n.renderList || []);
410
+ }
411
+ });
412
+ });
413
+ if (timeSlots) {
414
+ const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
415
+ const end_time = (0, import_dayjs.default)(`${dateRange[0].date} ${start_time}`).add(duration, durationType).format("HH:mm");
416
+ let targetResource = null;
417
+ for (const n of resources) {
418
+ const canUseTime = n.times.find(
419
+ (item) => (0, import_resources.getIsUsableByTimeItem)({
420
+ timeSlice: item,
421
+ time: { start_time, end_time },
422
+ resource: n,
423
+ currentCount: 1
424
+ })
425
+ );
426
+ if (canUseTime) {
427
+ targetResource = n;
428
+ break;
429
+ }
430
+ }
431
+ return {
432
+ selectedResource: targetResource
433
+ };
434
+ } else {
435
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
436
+ const resourceIds = resources.map((n) => n.id);
437
+ const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
438
+ resourceIds,
439
+ resourcesMap,
440
+ duration,
441
+ currentDate: dateRange[0].date,
442
+ split: 10
443
+ });
444
+ if (!timeSlots2) {
445
+ return;
446
+ }
447
+ return {
448
+ timeSlots: timeSlots2,
449
+ selectedResource: resources[0]
450
+ };
451
+ }
452
+ }
453
+ // 给所有购物车里的商品先分配一个资源
454
+ autoSelectAllProductResources(resources_code, timeSlots) {
455
+ const dateRange = this.store.date.getDateRange();
456
+ const resources = [];
457
+ dateRange.forEach((n) => {
458
+ if (n.resource)
459
+ resources.push(...n.resource);
460
+ });
461
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
462
+ const errorList = [];
463
+ this.store.accountList.getAccounts().forEach((account) => {
464
+ const cartItems = this.store.cart.getCartByAccount(account.getId());
465
+ const allCartItems = this.store.cart.getItems();
466
+ cartItems.forEach((item) => {
467
+ var _a;
468
+ if (timeSlots) {
469
+ const res = this.autoSelectAccountResources({
470
+ holder_id: item.holder_id,
471
+ resources_code,
472
+ timeSlots
473
+ });
474
+ if (res == null ? void 0 : res.selectedResource) {
475
+ console.log(this.store.cart.getItems());
476
+ this.store.cart.updateItem({
477
+ _id: item._id,
478
+ resources: [...item._origin.resources || [], res.selectedResource]
479
+ });
480
+ console.log(this.store.cart.getItems());
481
+ } else {
482
+ errorList.push(item._id);
483
+ }
484
+ } else {
485
+ const productResources = (0, import_resources.getResourcesByProduct)(
486
+ resourcesMap,
487
+ item,
488
+ allCartItems
489
+ );
490
+ const targetRenderList = (_a = productResources.find(
491
+ (n) => n.code === resources_code
492
+ )) == null ? void 0 : _a.renderList;
493
+ if (targetRenderList && targetRenderList.length > 0) {
494
+ this.store.cart.updateItem({
495
+ _id: item._id,
496
+ resources: [...item._origin.resources || [], targetRenderList[0]]
497
+ });
498
+ } else {
499
+ errorList.push(item._id);
500
+ }
501
+ }
502
+ });
503
+ });
504
+ return { errorList };
505
+ }
506
+ // 从购物车中获取已经分配好第一步资源的所有时间片
507
+ getTimeSlotByAllResources(resources_code) {
508
+ const dateRange = this.store.date.getDateRange();
509
+ const resources = [];
510
+ const cartItems = this.store.cart.getItems();
511
+ const resourceIds = [];
512
+ cartItems.forEach((item) => {
513
+ var _a, _b, _c;
514
+ (_b = (_a = item._productOrigin.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach((n) => {
515
+ if (n.code === resources_code) {
516
+ resources.push(...n.renderList || []);
517
+ }
518
+ });
519
+ (_c = item._origin.resources) == null ? void 0 : _c.forEach((n) => {
520
+ resourceIds.push(n.relation_id);
521
+ });
522
+ });
523
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
524
+ let duration = 0;
525
+ this.store.accountList.getAccounts().forEach((account) => {
526
+ let accountDuration = 0;
527
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
528
+ cartItems2.forEach((item) => {
529
+ accountDuration += item._productOrigin.duration.value;
530
+ });
531
+ if (accountDuration > duration) {
532
+ duration = accountDuration;
533
+ }
534
+ });
535
+ const timeSlots = (0, import_resources.getTimeSlicesByResources)({
536
+ resourceIds,
537
+ resourcesMap,
538
+ duration,
539
+ currentDate: dateRange[0].date,
540
+ split: 10
541
+ });
542
+ return timeSlots;
543
+ }
544
+ // 提交时间切片,绑定到对应购物车的商品上,更新购物车
545
+ // submitTimeSlot({
546
+ // resourceProductData,
547
+ // selectedResources,
548
+ // timeSlots,
549
+ // }: {
550
+ // resourceProductData: any;
551
+ // selectedResources: any[];
552
+ // timeSlots: TimeSliceItem;
553
+ // }) {
554
+ // const newResources = cloneDeep(selectedResources);
555
+ // newResources.forEach((n) => {
556
+ // n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
557
+ // n.endTime = dayjs(n.startTime)
558
+ // .add(
559
+ // resourceProductData.product.duration.value,
560
+ // resourceProductData.product.duration.type
561
+ // )
562
+ // .format("YYYY-MM-DD HH:mm");
563
+ // delete n.times;
564
+ // });
565
+ // this.store.cart.updateItem({
566
+ // _id: resourceProductData._id,
567
+ // resources: newResources,
568
+ // });
569
+ // }
570
+ submitTimeSlot(timeSlots) {
571
+ const cartItems = this.store.cart.getItems();
572
+ cartItems.forEach((item) => {
573
+ const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
574
+ newResources.forEach((n) => {
575
+ n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
576
+ n.endTime = (0, import_dayjs.default)(n.startTime).add(item._productOrigin.duration.value, item._productOrigin.duration.type).format("YYYY-MM-DD HH:mm");
577
+ delete n.times;
578
+ });
579
+ this.store.cart.updateItem({
580
+ _id: item._id,
581
+ resources: newResources
582
+ });
583
+ });
584
+ }
158
585
  };
159
586
  // Annotate the CommonJS export names for ESM import in node:
160
587
  0 && (module.exports = {
@@ -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;
@@ -30,10 +30,13 @@ var import_Guests = require("../../modules/Guests");
30
30
  var import_Order = require("../../modules/Order");
31
31
  var import_Payment = require("../../modules/Payment");
32
32
  var import_Step = require("../../modules/Step");
33
+ var import_Summary = require("../../modules/Summary");
33
34
  function createModule(moduleName, solutionName, name, version) {
34
35
  switch (moduleName) {
35
36
  case "cart":
36
37
  return new import_modules.CartModule(`${solutionName}_${name || moduleName}`, version);
38
+ case "summary":
39
+ return new import_Summary.SummaryModule(`${solutionName}_${name || moduleName}`, version);
37
40
  case "step":
38
41
  return new import_Step.StepModule(`${solutionName}_${name || moduleName}`, version);
39
42
  case "products":
@@ -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,60 @@
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/products.ts
20
+ var products_exports = {};
21
+ __export(products_exports, {
22
+ getAvailableProductResources: () => getAvailableProductResources
23
+ });
24
+ module.exports = __toCommonJS(products_exports);
25
+ var getAvailableProductResources = (products) => {
26
+ const rules = [];
27
+ const resourcesMap = {};
28
+ const resourceIds = [];
29
+ products.forEach((product) => {
30
+ var _a, _b, _c;
31
+ const tempResourceIds = [];
32
+ (_c = (_b = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach) == null ? void 0 : _c.call(_b, (resource) => {
33
+ var _a2, _b2;
34
+ if ((resource == null ? void 0 : resource.status) == 1) {
35
+ tempResourceIds.push(resource == null ? void 0 : resource.id);
36
+ if (!resourcesMap[resource == null ? void 0 : resource.id]) {
37
+ resourcesMap[resource == null ? void 0 : resource.id] = resource;
38
+ }
39
+ if ((_a2 = resource == null ? void 0 : resource.default_resource) == null ? void 0 : _a2.length) {
40
+ resourceIds.push(...resource == null ? void 0 : resource.default_resource);
41
+ } else if ((_b2 = resource == null ? void 0 : resource.optional_resource) == null ? void 0 : _b2.length) {
42
+ resourceIds.push(...resource == null ? void 0 : resource.optional_resource);
43
+ }
44
+ }
45
+ });
46
+ const rule = {};
47
+ if (product == null ? void 0 : product.cut_off_time) {
48
+ rule.cut_off_time = product == null ? void 0 : product.cut_off_time;
49
+ }
50
+ if (tempResourceIds) {
51
+ rule.resourceFormIds = [...new Set(tempResourceIds)];
52
+ }
53
+ rules.push(rule);
54
+ });
55
+ return { resourceIds: [...new Set(resourceIds)], rules, resourcesMap };
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ getAvailableProductResources
60
+ });