@pisell/pisellos 3.0.4 → 3.0.6

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 (189) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +8 -5
  13. package/dist/modules/Cart/index.js +101 -25
  14. package/dist/modules/Cart/types.d.ts +82 -5
  15. package/dist/modules/Cart/types.js +22 -0
  16. package/dist/modules/Cart/utils.d.ts +106 -13
  17. package/dist/modules/Cart/utils.js +289 -76
  18. package/dist/modules/Date/index.d.ts +6 -6
  19. package/dist/modules/Date/index.js +41 -58
  20. package/dist/modules/Date/types.d.ts +22 -6
  21. package/dist/modules/Date/utils.d.ts +4 -3
  22. package/dist/modules/Date/utils.js +81 -30
  23. package/dist/modules/Discount/index.d.ts +4 -4
  24. package/dist/modules/Discount/index.js +11 -11
  25. package/dist/modules/Order/index.d.ts +11 -5
  26. package/dist/modules/Order/index.js +47 -18
  27. package/dist/modules/Order/types.d.ts +10 -3
  28. package/dist/modules/Order/utils.d.ts +10 -0
  29. package/dist/modules/Order/utils.js +15 -0
  30. package/dist/modules/Product/index.d.ts +14 -1
  31. package/dist/modules/Product/index.js +35 -0
  32. package/dist/modules/Product/types.d.ts +27 -3
  33. package/dist/modules/ProductList/index.js +11 -5
  34. package/dist/modules/Resource/types.d.ts +1 -0
  35. package/dist/modules/Resource/utils.js +1 -1
  36. package/dist/modules/Rules/index.d.ts +3 -3
  37. package/dist/modules/Rules/index.js +121 -53
  38. package/dist/modules/Rules/types.d.ts +5 -1
  39. package/dist/modules/Schedule/index.d.ts +18 -0
  40. package/dist/modules/Schedule/index.js +111 -0
  41. package/dist/modules/Schedule/type.d.ts +157 -0
  42. package/dist/modules/Schedule/type.js +1 -0
  43. package/dist/modules/Schedule/types.d.ts +182 -0
  44. package/dist/modules/Schedule/types.js +1 -0
  45. package/dist/modules/Schedule/utils.d.ts +67 -0
  46. package/dist/modules/Schedule/utils.js +729 -0
  47. package/dist/modules/Step/index.d.ts +14 -3
  48. package/dist/modules/Step/index.js +54 -2
  49. package/dist/modules/Summary/index.d.ts +12 -5
  50. package/dist/modules/Summary/index.js +33 -7
  51. package/dist/modules/Summary/types.d.ts +23 -2
  52. package/dist/modules/Summary/utils.d.ts +14 -4
  53. package/dist/modules/Summary/utils.js +46 -4
  54. package/dist/modules/index.d.ts +10 -0
  55. package/dist/modules/index.js +11 -1
  56. package/dist/plugins/index.d.ts +3 -3
  57. package/dist/plugins/request.d.ts +3 -3
  58. package/dist/plugins/request.js +30 -30
  59. package/dist/plugins/shopStore.d.ts +1 -1
  60. package/dist/solution/BookingByStep/index.d.ts +97 -24
  61. package/dist/solution/BookingByStep/index.js +1024 -322
  62. package/dist/solution/BookingByStep/types.d.ts +3 -10
  63. package/dist/solution/BookingByStep/types.js +11 -15
  64. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  65. package/dist/solution/BookingByStep/utils/products.js +3 -0
  66. package/dist/solution/BookingByStep/utils/resources.d.ts +60 -6
  67. package/dist/solution/BookingByStep/utils/resources.js +293 -52
  68. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  69. package/dist/solution/ShopDiscount/index.js +16 -16
  70. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  71. package/dist/solution/ShopDiscount/utils.js +1 -1
  72. package/lib/core/index.js +7 -2
  73. package/lib/modules/Account/index.d.ts +2 -6
  74. package/lib/modules/Account/index.js +15 -30
  75. package/lib/modules/Account/types.d.ts +12 -1
  76. package/lib/modules/AccountList/index.d.ts +20 -1
  77. package/lib/modules/AccountList/index.js +122 -13
  78. package/lib/modules/AccountList/types.d.ts +33 -1
  79. package/lib/modules/AccountList/utils.d.ts +9 -0
  80. package/lib/modules/AccountList/utils.js +39 -0
  81. package/lib/modules/BaseModule.d.ts +2 -2
  82. package/lib/modules/BaseModule.js +14 -3
  83. package/lib/modules/Cart/index.d.ts +8 -5
  84. package/lib/modules/Cart/index.js +81 -8
  85. package/lib/modules/Cart/types.d.ts +82 -5
  86. package/lib/modules/Cart/types.js +20 -2
  87. package/lib/modules/Cart/utils.d.ts +106 -13
  88. package/lib/modules/Cart/utils.js +188 -45
  89. package/lib/modules/Date/index.d.ts +6 -6
  90. package/lib/modules/Date/index.js +13 -28
  91. package/lib/modules/Date/types.d.ts +22 -6
  92. package/lib/modules/Date/utils.d.ts +4 -3
  93. package/lib/modules/Date/utils.js +47 -13
  94. package/lib/modules/Discount/index.d.ts +4 -4
  95. package/lib/modules/Discount/index.js +9 -2
  96. package/lib/modules/Guests/index.js +4 -1
  97. package/lib/modules/Order/index.d.ts +11 -5
  98. package/lib/modules/Order/index.js +24 -3
  99. package/lib/modules/Order/types.d.ts +10 -3
  100. package/lib/modules/Order/utils.d.ts +10 -0
  101. package/lib/modules/Order/utils.js +45 -0
  102. package/lib/modules/Payment/index.js +1 -6
  103. package/lib/modules/Product/index.d.ts +14 -1
  104. package/lib/modules/Product/index.js +19 -0
  105. package/lib/modules/Product/types.d.ts +27 -3
  106. package/lib/modules/ProductList/index.js +21 -7
  107. package/lib/modules/Resource/index.js +4 -1
  108. package/lib/modules/Resource/types.d.ts +1 -0
  109. package/lib/modules/Resource/utils.js +7 -4
  110. package/lib/modules/Rules/index.d.ts +3 -3
  111. package/lib/modules/Rules/index.js +118 -43
  112. package/lib/modules/Rules/types.d.ts +5 -1
  113. package/lib/modules/Schedule/index.d.ts +18 -0
  114. package/lib/modules/Schedule/index.js +81 -0
  115. package/lib/modules/Schedule/type.d.ts +157 -0
  116. package/lib/modules/Schedule/type.js +17 -0
  117. package/lib/modules/Schedule/types.d.ts +182 -0
  118. package/lib/modules/Schedule/types.js +17 -0
  119. package/lib/modules/Schedule/utils.d.ts +67 -0
  120. package/lib/modules/Schedule/utils.js +600 -0
  121. package/lib/modules/Step/index.d.ts +14 -3
  122. package/lib/modules/Step/index.js +38 -1
  123. package/lib/modules/Summary/index.d.ts +12 -5
  124. package/lib/modules/Summary/index.js +15 -1
  125. package/lib/modules/Summary/types.d.ts +23 -2
  126. package/lib/modules/Summary/utils.d.ts +14 -4
  127. package/lib/modules/Summary/utils.js +30 -1
  128. package/lib/modules/index.d.ts +10 -0
  129. package/lib/modules/index.js +21 -1
  130. package/lib/plugins/index.d.ts +3 -3
  131. package/lib/plugins/request.d.ts +3 -3
  132. package/lib/plugins/request.js +48 -11
  133. package/lib/plugins/shopStore.d.ts +1 -1
  134. package/lib/solution/BookingByStep/index.d.ts +97 -24
  135. package/lib/solution/BookingByStep/index.js +693 -145
  136. package/lib/solution/BookingByStep/types.d.ts +3 -10
  137. package/lib/solution/BookingByStep/types.js +37 -14
  138. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  139. package/lib/solution/BookingByStep/utils/products.js +3 -0
  140. package/lib/solution/BookingByStep/utils/resources.d.ts +60 -6
  141. package/lib/solution/BookingByStep/utils/resources.js +286 -54
  142. package/lib/solution/BuyTickets/index.js +34 -20
  143. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  144. package/lib/solution/ShopDiscount/index.js +10 -2
  145. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  146. package/package.json +4 -2
  147. package/dist/core/index.d.ts.map +0 -1
  148. package/dist/effects/index.d.ts.map +0 -1
  149. package/dist/index.d.ts.map +0 -1
  150. package/dist/modules/Account/index.d.ts.map +0 -1
  151. package/dist/modules/Account/types.d.ts.map +0 -1
  152. package/dist/modules/AccountList/types.d.ts.map +0 -1
  153. package/dist/modules/Cart/index.d.ts.map +0 -1
  154. package/dist/modules/Cart/types.d.ts.map +0 -1
  155. package/dist/modules/Date/types.d.ts.map +0 -1
  156. package/dist/modules/Date/utils.d.ts.map +0 -1
  157. package/dist/modules/Guests/index.d.ts.map +0 -1
  158. package/dist/modules/Guests/types.d.ts.map +0 -1
  159. package/dist/modules/Order/index.d.ts.map +0 -1
  160. package/dist/modules/Order/types.d.ts.map +0 -1
  161. package/dist/modules/Payment/index.d.ts.map +0 -1
  162. package/dist/modules/Payment/types.d.ts.map +0 -1
  163. package/dist/modules/Product/index.d.ts.map +0 -1
  164. package/dist/modules/Product/types.d.ts.map +0 -1
  165. package/dist/modules/ProductList/types.d.ts.map +0 -1
  166. package/dist/modules/Resource/index.d.ts.map +0 -1
  167. package/dist/modules/Resource/types.d.ts.map +0 -1
  168. package/dist/modules/Resource/utils.d.ts.map +0 -1
  169. package/dist/modules/Rules/types.d.ts.map +0 -1
  170. package/dist/modules/Step/index.d.ts.map +0 -1
  171. package/dist/modules/Step/tyeps.d.ts.map +0 -1
  172. package/dist/modules/Summary/index.d.ts.map +0 -1
  173. package/dist/modules/Summary/types.d.ts.map +0 -1
  174. package/dist/modules/Summary/utils.d.ts.map +0 -1
  175. package/dist/modules/index.d.ts.map +0 -1
  176. package/dist/plugins/index.d.ts.map +0 -1
  177. package/dist/plugins/request.d.ts.map +0 -1
  178. package/dist/plugins/shopStore.d.ts.map +0 -1
  179. package/dist/plugins/window.d.ts.map +0 -1
  180. package/dist/solution/BookingByStep/types.d.ts.map +0 -1
  181. package/dist/solution/BookingByStep/utils/products.d.ts.map +0 -1
  182. package/dist/solution/BuyTickets/index.d.ts.map +0 -1
  183. package/dist/solution/BuyTickets/types.d.ts.map +0 -1
  184. package/dist/solution/PlaceOrder/index.d.ts.map +0 -1
  185. package/dist/solution/ShopDiscount/types.d.ts.map +0 -1
  186. package/dist/solution/ShopDiscount/utils.d.ts.map +0 -1
  187. package/dist/solution/index.d.ts.map +0 -1
  188. package/dist/store/createStore.d.ts.map +0 -1
  189. package/dist/types/index.d.ts.map +0 -1
@@ -39,6 +39,8 @@ var import_resources = require("./utils/resources");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
40
  var import_utils = require("../../modules/Resource/utils");
41
41
  var import_lodash_es = require("lodash-es");
42
+ var import_utils2 = require("../../modules/Schedule/utils");
43
+ var import_utils3 = require("../../modules/Date/utils");
42
44
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
43
45
  constructor() {
44
46
  super(...arguments);
@@ -46,9 +48,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
46
48
  this.defaultVersion = "1.0.0";
47
49
  this.isSolution = true;
48
50
  this.otherParams = {};
51
+ this.otherData = {};
49
52
  }
53
+ // 提供给 UI 层的临时数据存储,会进缓存
50
54
  async initialize(core, options) {
51
- var _a, _b;
55
+ var _a, _b, _c, _d;
52
56
  this.core = core;
53
57
  this.store = options.store || {};
54
58
  this.otherParams = options.otherParams || {};
@@ -66,9 +70,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
66
70
  if (sessionData) {
67
71
  const data = JSON.parse(sessionData);
68
72
  targetCacheData = data[this.otherParams.cacheId];
73
+ this.otherData = ((_d = (_c = data[this.otherParams.cacheId]) == null ? void 0 : _c[this.name]) == null ? void 0 : _d["otherData"]) || {};
69
74
  }
70
75
  }
71
- const moduleArr = ["accountList", "cart", "summary", "step", "products", "date", "order", "payment"];
76
+ const moduleArr = [
77
+ "accountList",
78
+ "cart",
79
+ "schedule",
80
+ "summary",
81
+ "step",
82
+ "products",
83
+ "date",
84
+ "order",
85
+ "payment"
86
+ ];
72
87
  moduleArr.forEach((step) => {
73
88
  var _a2, _b2;
74
89
  const targetModule = (0, import_types.createModule)(step, this.name);
@@ -115,6 +130,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
115
130
  getStepList() {
116
131
  return this.store.step.getStepList();
117
132
  }
133
+ /**
134
+ * 添加step
135
+ */
136
+ addStep(step, key) {
137
+ this.store.step.addStep(step, key);
138
+ }
139
+ /**
140
+ * 删除step
141
+ */
142
+ removeStep(key) {
143
+ this.store.step.removeStep(key);
144
+ }
118
145
  // 获取购物车里 temp.xxx的方法
119
146
  // async getStoreCart(key?: string) {
120
147
  // return this.store.cart.getTemp(key);
@@ -123,47 +150,146 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
123
150
  async loadProducts({
124
151
  category_ids = [],
125
152
  product_ids = [],
126
- collection = []
153
+ collection = [],
154
+ schedule_ids = []
127
155
  }) {
156
+ if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
157
+ const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
158
+ if (schedule_ids_data.length) {
159
+ schedule_ids = schedule_ids_data;
160
+ }
161
+ }
128
162
  const productsData = await this.request.post(
129
163
  `/product/query`,
130
164
  {
131
165
  open_quotation: 1,
132
166
  open_bundle: 1,
133
- extension_type: ["product_appointment", "appointment_ticket"],
134
- with: ["category", "collection"],
167
+ extension_type: [
168
+ "product_appointment",
169
+ "appointment_ticket",
170
+ "session_product",
171
+ "session_ticket"
172
+ ],
173
+ with: ["category", "collection", "resourceRelation"],
135
174
  status: "published",
136
175
  num: 500,
137
176
  skip: 1,
138
177
  category_ids,
139
178
  ids: product_ids,
140
179
  collection,
141
- front_end_cache_id: this.cacheId
180
+ front_end_cache_id: this.cacheId,
181
+ client_schedule_ids: schedule_ids
142
182
  },
143
183
  { useCache: true }
144
184
  );
145
185
  this.store.products.addProduct(productsData.data.list);
146
186
  return productsData.data.list;
147
187
  }
188
+ async loadProductByScheduleDate({
189
+ date,
190
+ product_ids,
191
+ category_ids = []
192
+ }) {
193
+ const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
194
+ this.setDateRange([
195
+ { date, status: "available", week: "", weekNum: 0 },
196
+ { date, status: "available", week: "", weekNum: 0 }
197
+ ]);
198
+ const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
199
+ return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids });
200
+ }
201
+ // 加载当前店铺下所有 schedule
202
+ async loadAllSchedule() {
203
+ var _a;
204
+ const scheduleList = await this.request.get(`/schedule`);
205
+ this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
206
+ }
207
+ // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
208
+ async loadScheduleAvailableDate({
209
+ startDate,
210
+ endDate,
211
+ custom_page_id
212
+ }) {
213
+ var _a;
214
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
215
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
216
+ }
217
+ let dates = (0, import_utils3.generateMonthDates)(startDate, endDate);
218
+ dates = (0, import_utils3.disableAllDates)(dates);
219
+ if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
220
+ return dates;
221
+ }
222
+ const res = await this.request.get(
223
+ `/schedule/product/availability`,
224
+ {
225
+ start_date: startDate,
226
+ end_date: endDate,
227
+ custom_page_id
228
+ }
229
+ );
230
+ this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
231
+ if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
232
+ return dates;
233
+ }
234
+ res.data.date_list.forEach((n) => {
235
+ if (n.schedule_id && n.schedule_id.length) {
236
+ const index = dates.findIndex((m) => m.date === n.date);
237
+ if (index !== -1) {
238
+ dates[index].status = "available";
239
+ }
240
+ }
241
+ });
242
+ dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
243
+ return dates;
244
+ }
148
245
  async storeProduct(productData) {
149
246
  const activeAccount = this.getActiveAccount();
150
- if (!activeAccount) {
151
- throw new Error("没有找到当前账户");
152
- }
153
247
  const { bundle, options, origin, product_variant_id } = productData || {};
154
248
  const product = { ...origin, product_variant_id };
155
- this.store.cart.addItem({
156
- account: activeAccount,
249
+ const addCartItem = {
157
250
  product,
158
251
  bundle,
159
252
  options
160
- });
253
+ };
254
+ if (activeAccount) {
255
+ addCartItem.account = activeAccount;
256
+ }
257
+ this.store.cart.addItem(addCartItem);
258
+ }
259
+ // 添加单个账户或者 guest
260
+ async addAccount(account, extra) {
261
+ if ((extra == null ? void 0 : extra.type) === "holder") {
262
+ const accountModules = await this.store.accountList.addHolderAccounts(
263
+ [account],
264
+ extra.customerId
265
+ );
266
+ return accountModules[0].getAccount();
267
+ }
268
+ const newAccount = await this.store.accountList.addAccount(
269
+ account
270
+ );
271
+ return newAccount.getAccount();
161
272
  }
162
273
  // 添加账户或者 guest
163
- async addAccount(accounts) {
164
- accounts.forEach((account) => {
165
- this.store.accountList.addAccount(account);
166
- });
274
+ async addAccounts(accounts, extra) {
275
+ if ((extra == null ? void 0 : extra.type) === "holder") {
276
+ this.store.accountList.addHolderAccounts(
277
+ accounts,
278
+ extra.customerId
279
+ );
280
+ return;
281
+ }
282
+ const res = [];
283
+ for (const account of accounts) {
284
+ const accountModule = await this.store.accountList.addAccount(
285
+ account
286
+ );
287
+ const accountData = accountModule.getAccount();
288
+ if (accountData) {
289
+ res.push(accountData);
290
+ }
291
+ }
292
+ return res;
167
293
  }
168
294
  // 获取所有账户
169
295
  async getAccounts() {
@@ -185,6 +311,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
185
311
  this.store.accountList.removeAccount(id);
186
312
  this.clearCartByAccount(id);
187
313
  }
314
+ /**
315
+ * 获取holder类型账户列表
316
+ * @param params
317
+ */
318
+ async fetchHolderAccountsAsync(params) {
319
+ return this.store.accountList.fetchHolderAccounts(params);
320
+ }
188
321
  // 设置日期范围,注入到日期模块中
189
322
  async setDateRange(dateRange) {
190
323
  this.store.date.setDateRange(dateRange);
@@ -201,24 +334,44 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
201
334
  }
202
335
  // 获取商品/服务的可用日期
203
336
  async getAvailableDate(params = {}) {
204
- var _a, _b, _c, _d;
205
- const { products, startDate, endDate } = params;
206
- const tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
207
- const tempStartDate = startDate || ((_b = (_a = this.otherParams) == null ? void 0 : _a.dateRange) == null ? void 0 : _b[0]);
208
- const tempEndDate = endDate || ((_d = (_c = this.otherParams) == null ? void 0 : _c.dateRange) == null ? void 0 : _d[1]);
337
+ let { products, startDate, endDate, type } = params;
338
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
339
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
340
+ }
341
+ let tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
342
+ if (tempProducts.length) {
343
+ tempProducts.forEach((p) => {
344
+ if (p == null ? void 0 : p["schedule.ids"]) {
345
+ const scheduleData = this.getScheduleDataByIds(p["schedule.ids"]);
346
+ p["_schedule"] = scheduleData;
347
+ }
348
+ });
349
+ }
350
+ if (this.store.currentProduct) {
351
+ tempProducts = [
352
+ {
353
+ ...this.store.currentProduct.getData(),
354
+ _schedule: this.store.currentProduct.getOtherParams()["schedule"]
355
+ }
356
+ ];
357
+ }
358
+ let dateRange = this.store.date.getDateRange();
359
+ const tempStartDate = startDate || (dateRange == null ? void 0 : dateRange[0].date);
360
+ const tempEndDate = endDate || (dateRange == null ? void 0 : dateRange[1].date);
209
361
  if (!tempProducts.length) {
210
362
  return [];
211
363
  }
212
364
  const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
213
- console.log("resourceIds", tempProducts);
214
365
  this.otherParams.currentResourcesMap = resourcesMap;
215
- const res = await this.store.date.getMonthDates({
366
+ const res = await this.store.date.getResourceDates({
367
+ url: params.url,
216
368
  query: {
217
369
  start_date: tempStartDate,
218
370
  end_date: tempEndDate,
219
371
  resource_ids: resourceIds
220
372
  },
221
- rules
373
+ rules,
374
+ type
222
375
  });
223
376
  return res;
224
377
  }
@@ -230,6 +383,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
230
383
  const summary = await this.store.summary.getSummary(cartItems);
231
384
  return summary;
232
385
  }
386
+ /**
387
+ * 获取协议
388
+ */
389
+ async getProtocol(protocolId) {
390
+ return this.store.summary.getProtocol(protocolId);
391
+ }
233
392
  // 获取可选择的商品、服务列表
234
393
  async getProducts() {
235
394
  return this.store.products.getProducts();
@@ -262,11 +421,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
262
421
  const res = await this.request.post(`/pay/order/free-pay/${id}`);
263
422
  return res;
264
423
  }
424
+ /**
425
+ * 检查购物车提交订单前是否符合条件
426
+ * @param type 类型 "holder" | "account"
427
+ * @returns boolean
428
+ */
429
+ checkBeforeSubmitOrder(type) {
430
+ return this.store.order.checkBeforeSubmitOrder({
431
+ type,
432
+ cartItems: this.store.cart.getItems()
433
+ });
434
+ }
265
435
  // 购物车提交订单
266
436
  async submitOrder() {
267
437
  const cartItems = this.store.cart.getItems();
268
438
  const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
269
439
  newCartItems.forEach((item) => {
440
+ var _a, _b;
270
441
  item._origin.resources = item._origin.resources.map((n) => {
271
442
  const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
272
443
  delete newResourcesItem.id;
@@ -274,8 +445,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
274
445
  delete newResourcesItem.resourceType;
275
446
  return { ...newResourcesItem };
276
447
  });
448
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
449
+ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
450
+ product_bundle: item._origin.product.product_bundle
451
+ });
452
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
453
+ if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
454
+ item._origin.metadata = {};
455
+ }
456
+ item._origin.metadata.capacity = formatCapacity;
457
+ item._origin.number = currentCapacity;
277
458
  });
278
- return this.store.order.commitOrder({ query: { cartItems: newCartItems } });
459
+ return this.store.order.submitOrder({ query: { cartItems: newCartItems } });
279
460
  }
280
461
  // 拉起支付模块
281
462
  async pay() {
@@ -295,24 +476,40 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
295
476
  }
296
477
  // 更新购物车
297
478
  updateCart(params) {
479
+ var _a;
480
+ const targetCartItem = this.store.cart.getItem(params._id);
481
+ if (!targetCartItem) {
482
+ throw new Error(`没有找到${params._id}购物车商品`);
483
+ }
298
484
  if (params.resources) {
485
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
486
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
487
+ product_bundle: targetCartItem._origin.product.product_bundle
488
+ });
489
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
299
490
  params.resources = params.resources.map((n) => {
300
- n.capacity = 1;
491
+ n.capacity = currentCapacity || 1;
492
+ (0, import_resources.checkSubResourcesCapacity)(n);
301
493
  return n;
302
494
  });
303
495
  }
304
496
  this.store.cart.updateItem(params);
305
- const targetCartItem = this.store.cart.getItem(params._id);
306
- if (!targetCartItem) {
307
- throw new Error(`没有找到${params._id}购物车商品`);
308
- }
309
497
  const cartItems = this.store.cart.getItems();
310
498
  cartItems.forEach((item) => {
311
- var _a;
499
+ var _a2;
312
500
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
313
- const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter(
314
- (m) => !targetCartItem._origin.resources.some((targetRes) => targetRes.id === m.id)
315
- );
501
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
502
+ return !targetCartItem._origin.resources.some((targetRes) => {
503
+ var _a3, _b;
504
+ if (targetRes.id === m.id)
505
+ return true;
506
+ if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
507
+ return true;
508
+ if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
509
+ return true;
510
+ return false;
511
+ });
512
+ });
316
513
  this.store.cart.updateItem({
317
514
  _id: item._id,
318
515
  resources
@@ -346,8 +543,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
346
543
  /**
347
544
  * 从购物车中按类别删除信息
348
545
  */
349
- deleteCartItemInfo(types) {
350
- this.store.cart.deleteCartItemInfo(types);
546
+ deleteCartItemInfo(type, _id) {
547
+ this.store.cart.deleteCartItemInfo(type, _id);
548
+ }
549
+ checkCartItemByType(cartItem, type) {
550
+ return this.store.cart.checkCartItemByType(cartItem, type);
551
+ }
552
+ /**
553
+ * 检查购物车商品是否符合条件
554
+ * @param type 类型
555
+ * @returns 不符合条件的购物车商品ID列表
556
+ */
557
+ checkCartItems(type) {
558
+ const cartItems = this.store.cart.getItems();
559
+ const errorCartItemIds = [];
560
+ cartItems.forEach((cartItem) => {
561
+ const result = this.store.cart.checkCartItemByType(cartItem, type);
562
+ if (!result) {
563
+ errorCartItemIds.push(cartItem._id);
564
+ }
565
+ });
566
+ return errorCartItemIds;
351
567
  }
352
568
  destroy() {
353
569
  var _a, _b, _c, _d, _e, _f;
@@ -364,15 +580,94 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
364
580
  getResourcesList() {
365
581
  const dateRange = this.store.date.getDateRange();
366
582
  const resources = [];
367
- dateRange.forEach((n) => {
368
- if (n.resource)
369
- resources.push(...n.resource);
370
- });
371
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
583
+ if (dateRange == null ? void 0 : dateRange.length) {
584
+ dateRange.forEach((n) => {
585
+ if (n.resource)
586
+ resources.push(...n.resource);
587
+ });
588
+ }
589
+ if (!resources.length) {
590
+ const dateList = this.store.date.getDateList();
591
+ dateList.forEach((n) => {
592
+ if (n.resource)
593
+ resources.push(...n.resource);
594
+ });
595
+ }
596
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
372
597
  const cartItems = this.store.cart.getItems();
373
598
  const arr = [];
599
+ const capacityMap = {};
374
600
  cartItems.forEach((cartItem) => {
375
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, cartItem, cartItems);
601
+ var _a, _b, _c;
602
+ let selectedResources = [];
603
+ if (cartItem.holder_id) {
604
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
605
+ cartItems,
606
+ cartItem.holder_id,
607
+ resourcesMap
608
+ );
609
+ } else {
610
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
611
+ cartItems,
612
+ cartItem._id,
613
+ resourcesMap
614
+ );
615
+ }
616
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
617
+ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
618
+ product_bundle: cartItem._origin.product.product_bundle
619
+ });
620
+ cartItem._origin.metadata.capacity = formatCapacity;
621
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
622
+ const productResources = (0, import_resources.getResourcesByProduct)(
623
+ resourcesMap,
624
+ ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
625
+ selectedResources,
626
+ currentCapacity
627
+ );
628
+ if (cartItem._origin.start_time) {
629
+ const startTime = (0, import_dayjs.default)(
630
+ `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
631
+ );
632
+ const endTime = (0, import_dayjs.default)(
633
+ `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
634
+ );
635
+ const resourcesUseableMap = {};
636
+ productResources.forEach((n) => {
637
+ n.renderList = n.renderList.sort((a, b) => {
638
+ var _a2, _b2, _c2, _d;
639
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
640
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
641
+ if (aIsCombined && !bIsCombined)
642
+ return 1;
643
+ if (!aIsCombined && bIsCombined)
644
+ return -1;
645
+ return 0;
646
+ });
647
+ n.renderList = n.renderList.filter((m) => {
648
+ const recordCount = capacityMap[m.id] || 0;
649
+ const canUseTime = m.times.find((item) => {
650
+ const res = (0, import_resources.getIsUsableByTimeItem)({
651
+ timeSlice: {
652
+ start_time: startTime.format("HH:mm"),
653
+ end_time: endTime.format("HH:mm"),
654
+ start_at: startTime,
655
+ end_at: endTime
656
+ },
657
+ time: item,
658
+ resource: m,
659
+ currentCount: recordCount + (currentCapacity || 0),
660
+ resourcesUseableMap
661
+ });
662
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
663
+ resourcesUseableMap[m.id] = res.usable;
664
+ }
665
+ return res.usable;
666
+ });
667
+ return canUseTime;
668
+ });
669
+ });
670
+ }
376
671
  arr.push({
377
672
  id: cartItem.id,
378
673
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -388,20 +683,44 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
388
683
  }
389
684
  // 给单个购物车里的商品获取资源列表
390
685
  getResourcesListByCartItem(id) {
391
- const cartItems = this.store.cart.getItems();
686
+ var _a, _b, _c;
687
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
392
688
  const dateRange = this.store.date.getDateRange();
393
689
  const resources = [];
394
690
  dateRange.forEach((n) => {
395
691
  if (n.resource)
396
692
  resources.push(...n.resource);
397
693
  });
398
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
399
- const arr = [];
694
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
400
695
  const targetCartItem = cartItems.find((n) => n._id === id);
401
696
  if (!targetCartItem) {
402
697
  throw new Error(`没有找到${id}购物车商品`);
403
698
  }
404
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, targetCartItem, cartItems);
699
+ let selectedResources = [];
700
+ if (targetCartItem.holder_id) {
701
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
702
+ cartItems,
703
+ targetCartItem.holder_id,
704
+ resourcesMap
705
+ );
706
+ } else {
707
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
708
+ cartItems,
709
+ targetCartItem._id,
710
+ resourcesMap
711
+ );
712
+ }
713
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
714
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
715
+ product_bundle: targetCartItem._origin.product.product_bundle
716
+ });
717
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
718
+ const productResources = (0, import_resources.getResourcesByProduct)(
719
+ resourcesMap,
720
+ ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
721
+ selectedResources,
722
+ currentCapacity
723
+ );
405
724
  if (productResources) {
406
725
  return {
407
726
  id: targetCartItem.id,
@@ -430,83 +749,44 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
430
749
  });
431
750
  return timeSlots;
432
751
  }
433
- // 自动分派可用的资源-单种资源类型
434
- autoSelectResource({
435
- resourceProductData,
436
- resources,
437
- timeSlots
438
- }) {
439
- const dateRange = this.store.date.getDateRange();
440
- if (timeSlots) {
441
- let targetResource = null;
442
- for (const n of resources) {
443
- const canUseTime = n.times.find((item) => {
444
- const res = (0, import_resources.getIsUsableByTimeItem)({
445
- timeSlice: timeSlots,
446
- time: item,
447
- resource: n,
448
- currentCount: 1
449
- });
450
- return res.usable;
451
- });
452
- if (canUseTime) {
453
- targetResource = n;
454
- break;
455
- }
456
- }
457
- return {
458
- selectedResource: targetResource
459
- };
460
- } else {
461
- const duration = resourceProductData.product.duration.value;
462
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
463
- const resourceIds = resources.map((n) => n.id);
464
- const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
465
- resourceIds,
466
- resourcesMap,
467
- duration,
468
- currentDate: dateRange[0].date,
469
- split: 10
470
- });
471
- if (!timeSlots2) {
472
- return;
473
- }
474
- return {
475
- timeSlots: timeSlots2,
476
- selectedResource: resources[0]
477
- };
478
- }
479
- }
480
752
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
481
753
  autoSelectAccountResources({
482
754
  holder_id,
483
755
  resources_code,
484
756
  timeSlots,
485
- countMap
757
+ countMap,
758
+ capacity
486
759
  }) {
487
- var _a, _b, _c;
488
760
  const dateRange = this.store.date.getDateRange();
489
- const cartItems = this.store.cart.getItems();
490
- const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
761
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
762
+ let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
491
763
  if (!accountCartItems.length) {
492
- return {
493
- selectedResource: null
494
- };
764
+ accountCartItems = cartItems;
495
765
  }
496
766
  let duration = accountCartItems.reduce((acc, n) => {
497
- var _a2, _b2;
498
- return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
767
+ var _a, _b;
768
+ return acc + (((_b = (_a = n._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0);
499
769
  }, 0);
500
- let durationType = ((_c = (_b = (_a = accountCartItems[0]) == null ? void 0 : _a._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.type) ?? "minutes";
501
- const resources = [];
770
+ let resources = [];
502
771
  accountCartItems.forEach((item) => {
503
- var _a2, _b2, _c2;
504
- (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
772
+ var _a, _b, _c;
773
+ (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
505
774
  if (n.code === resources_code) {
506
775
  resources.push(...n.renderList || []);
507
776
  }
508
777
  });
509
778
  });
779
+ resources.sort((a, b) => {
780
+ var _a, _b, _c, _d;
781
+ const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
782
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
783
+ if (aIsCombined && !bIsCombined)
784
+ return 1;
785
+ if (!aIsCombined && bIsCombined)
786
+ return -1;
787
+ return 0;
788
+ });
789
+ const resourcesUseableMap = {};
510
790
  if (timeSlots) {
511
791
  let targetResource = null;
512
792
  for (const n of resources) {
@@ -516,8 +796,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
516
796
  timeSlice: timeSlots,
517
797
  time: item,
518
798
  resource: n,
519
- currentCount: recordCount + 1
799
+ currentCount: recordCount + (capacity || 0),
800
+ resourcesUseableMap
520
801
  });
802
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false) {
803
+ resourcesUseableMap[n.id] = res.usable;
804
+ }
521
805
  return res.usable;
522
806
  });
523
807
  if (canUseTime) {
@@ -536,7 +820,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
536
820
  resourcesMap,
537
821
  duration,
538
822
  currentDate: dateRange[0].date,
539
- split: 10
823
+ split: 10,
824
+ capacity,
825
+ resourcesUseableMap
540
826
  });
541
827
  if (!timeSlots2) {
542
828
  return;
@@ -549,30 +835,45 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
549
835
  }
550
836
  // 给所有购物车里的商品先分配一个资源
551
837
  autoSelectAllProductResources(resources_code, timeSlots) {
838
+ var _a;
552
839
  const dateRange = this.store.date.getDateRange();
553
840
  const resources = [];
554
- dateRange.forEach((n) => {
555
- if (n.resource)
556
- resources.push(...n.resource);
557
- });
558
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
841
+ if ((_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.date) {
842
+ dateRange.forEach((n) => {
843
+ if (n.resource)
844
+ resources.push(...n.resource);
845
+ });
846
+ }
847
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
559
848
  const errorList = [];
560
849
  const selectResourcesMap = {};
561
- this.store.accountList.getAccounts().forEach((account) => {
562
- const cartItems = this.store.cart.getCartByAccount(account.getId());
563
- const allCartItems = this.store.cart.getItems();
850
+ const accountList = this.store.accountList.getAccounts();
851
+ const selectForCartResources = (cartItems2) => {
564
852
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
565
- cartItems.forEach((item, index) => {
566
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
567
- if (timeSlots) {
853
+ cartItems2.forEach((item, index) => {
854
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
855
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
856
+ capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
857
+ product_bundle: item._origin.product.product_bundle
858
+ });
859
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
860
+ if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
861
+ recordTimeSlots = {
862
+ start_time: item._origin.start_time,
863
+ end_time: item._origin.end_time,
864
+ start_at: (0, import_dayjs.default)(`${item.start_date} ${item._origin.start_time}`),
865
+ end_at: (0, import_dayjs.default)(`${item.end_date} ${item._origin.end_time}`)
866
+ };
867
+ }
868
+ if (recordTimeSlots) {
568
869
  if (index !== 0 && recordTimeSlots) {
569
870
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
570
- ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
571
- ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
871
+ ((_c = (_b = item._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.value) ?? 0,
872
+ ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) ?? "minutes"
572
873
  );
573
874
  let end_at = start_at.add(
574
- ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
575
- ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
875
+ ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
876
+ ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
576
877
  );
577
878
  recordTimeSlots = {
578
879
  start_time: start_at.format("HH:mm"),
@@ -585,16 +886,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
585
886
  holder_id: item.holder_id,
586
887
  resources_code,
587
888
  timeSlots: recordTimeSlots,
588
- countMap: selectResourcesMap
889
+ countMap: selectResourcesMap,
890
+ capacity: currentCapacity
589
891
  });
590
892
  if (res == null ? void 0 : res.selectedResource) {
591
893
  if (!selectResourcesMap[res.selectedResource.id]) {
592
- selectResourcesMap[res.selectedResource.id] = 1;
894
+ selectResourcesMap[res.selectedResource.id] = currentCapacity;
593
895
  } else {
594
- selectResourcesMap[res.selectedResource.id]++;
896
+ selectResourcesMap[res.selectedResource.id] += currentCapacity;
595
897
  }
596
- console.log(this.store.cart.getItems());
597
- res.selectedResource.capacity = 1;
898
+ res.selectedResource.capacity = currentCapacity;
899
+ (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
598
900
  this.store.cart.updateItem({
599
901
  _id: item._id,
600
902
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -605,19 +907,52 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
605
907
  res.selectedResource
606
908
  ]
607
909
  });
608
- console.log(this.store.cart.getItems());
609
910
  } else {
610
911
  errorList.push(item._id);
611
912
  }
612
913
  } else {
613
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
614
- const targetRenderList = (_i = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _i.renderList;
914
+ const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
915
+ let selectedResources = [];
916
+ const resources2 = (0, import_lodash_es.cloneDeep)(((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []);
917
+ const currentResourcesRenderList = [];
918
+ resources2.forEach((n) => {
919
+ var _a3;
920
+ if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
921
+ currentResourcesRenderList.push(...n.renderList || []);
922
+ }
923
+ });
924
+ const resourcesMap2 = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
925
+ if (item.holder_id) {
926
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
927
+ allCartItems,
928
+ item.holder_id,
929
+ resourcesMap2
930
+ );
931
+ } else {
932
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
933
+ allCartItems,
934
+ item._id,
935
+ resourcesMap2
936
+ );
937
+ }
938
+ const productResources = (0, import_resources.getResourcesByProduct)(
939
+ resourcesMap2,
940
+ (0, import_lodash_es.cloneDeep)(resources2),
941
+ selectedResources,
942
+ currentCapacity
943
+ );
944
+ const targetRenderList = (_l = productResources.find(
945
+ (n) => n.code === resources_code
946
+ )) == null ? void 0 : _l.renderList;
615
947
  if (targetRenderList && targetRenderList.length > 0) {
616
- if ((_j = item._origin.resources) == null ? void 0 : _j.some((n) => n.form_id === targetRenderList[0].form_id)) {
948
+ if ((_m = item._origin.resources) == null ? void 0 : _m.some(
949
+ (n) => n.form_id === targetRenderList[0].form_id
950
+ )) {
617
951
  return;
618
952
  }
619
953
  const targetResource = targetRenderList[0];
620
- targetResource.capacity = 1;
954
+ targetResource.capacity = currentCapacity;
955
+ (0, import_resources.checkSubResourcesCapacity)(targetResource);
621
956
  this.store.cart.updateItem({
622
957
  _id: item._id,
623
958
  resources: [
@@ -632,18 +967,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
632
967
  }
633
968
  }
634
969
  });
635
- });
970
+ };
971
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
972
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
973
+ accountList.forEach((account) => {
974
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
975
+ selectForCartResources(cartItems2);
976
+ });
977
+ } else {
978
+ selectForCartResources(cartItems);
979
+ }
636
980
  return { errorList };
637
981
  }
638
982
  // 从购物车中获取已经分配好第一步资源的所有时间片
639
983
  getTimeSlotByAllResources(resources_code) {
640
- const dateRange = this.store.date.getDateRange();
984
+ var _a, _b, _c, _d;
985
+ let dateRange = this.store.date.getDateRange();
641
986
  const resources = [];
642
- const cartItems = this.store.cart.getItems();
987
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
643
988
  const resourceIds = [];
644
989
  cartItems.forEach((item) => {
645
- var _a, _b, _c;
646
- (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
990
+ var _a2, _b2, _c2;
991
+ (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
647
992
  if (n.code === resources_code) {
648
993
  resources.push(...n.renderList || []);
649
994
  }
@@ -654,29 +999,58 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
654
999
  });
655
1000
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
656
1001
  let duration = 0;
657
- this.store.accountList.getAccounts().forEach((account) => {
1002
+ const accountList = this.store.accountList.getAccounts();
1003
+ const checkDuration = (cartItems2) => {
658
1004
  let accountDuration = 0;
659
- const cartItems2 = this.store.cart.getCartByAccount(account.getId());
660
1005
  cartItems2.forEach((item) => {
661
- var _a, _b;
662
- accountDuration += ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0;
1006
+ var _a2, _b2;
1007
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0;
663
1008
  });
664
1009
  if (accountDuration > duration) {
665
1010
  duration = accountDuration;
666
1011
  }
667
- });
1012
+ };
1013
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1014
+ accountList.forEach((account) => {
1015
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
1016
+ checkDuration(cartItems2);
1017
+ });
1018
+ } else {
1019
+ checkDuration(cartItems);
1020
+ }
1021
+ if (!((_a = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _a.start_date) && !((_b = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _b.resource_id) || !(cartItems == null ? void 0 : cartItems[0].duration)) {
1022
+ return [];
1023
+ }
1024
+ if ((cartItems == null ? void 0 : cartItems[0].start_date) && !dateRange) {
1025
+ dateRange = [
1026
+ {
1027
+ date: cartItems == null ? void 0 : cartItems[0].start_date,
1028
+ status: "available",
1029
+ week: "",
1030
+ weekNum: 0
1031
+ },
1032
+ {
1033
+ date: ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.end_date) || ((_d = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _d.start_date) || "",
1034
+ status: "available",
1035
+ week: "",
1036
+ weekNum: 0
1037
+ }
1038
+ ];
1039
+ }
1040
+ const resourcesUseableMap = {};
668
1041
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
669
1042
  resourceIds,
670
1043
  resourcesMap,
671
1044
  duration,
672
1045
  currentDate: dateRange[0].date,
673
- split: 10
1046
+ split: 10,
1047
+ resourcesUseableMap
674
1048
  });
675
1049
  return timeSlots;
676
1050
  }
677
1051
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
678
1052
  submitTimeSlot(timeSlots) {
679
- const cartItems = this.store.cart.getItems();
1053
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
680
1054
  const itemsByAccount = cartItems.reduce((acc, item) => {
681
1055
  const holderId = item.holder_id;
682
1056
  if (!acc[holderId]) {
@@ -712,6 +1086,180 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
712
1086
  }
713
1087
  clearCacheByModule(module2) {
714
1088
  }
1089
+ getScheduleDataByIds(scheduleIds) {
1090
+ const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1091
+ const targetSchedulesData = targetSchedules.map((item) => {
1092
+ return (0, import_utils2.calcCalendarDataByScheduleResult)(item);
1093
+ });
1094
+ const newSchedule = {};
1095
+ targetSchedulesData.forEach((item) => {
1096
+ item.forEach((n) => {
1097
+ if (!newSchedule[n.date]) {
1098
+ newSchedule[n.date] = n;
1099
+ } else {
1100
+ if (!n.isExcluded) {
1101
+ newSchedule[n.date].isExcluded = false;
1102
+ }
1103
+ }
1104
+ });
1105
+ });
1106
+ const newScheduleArr = Object.values(newSchedule);
1107
+ return newScheduleArr;
1108
+ }
1109
+ // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
1110
+ async openProductDetail(productId) {
1111
+ const targetProduct = await this.store.products.getProduct(productId);
1112
+ if (targetProduct) {
1113
+ const targetProductData = targetProduct.getData();
1114
+ this.store.currentProduct = targetProduct;
1115
+ const newScheduleArr = this.getScheduleDataByIds(
1116
+ targetProductData["schedule.ids"]
1117
+ );
1118
+ targetProduct.setOtherParams("schedule", newScheduleArr);
1119
+ }
1120
+ }
1121
+ closeProductDetail() {
1122
+ var _a;
1123
+ (_a = this.store.currentProduct) == null ? void 0 : _a.setOtherParams("schedule", []);
1124
+ this.store.currentProduct = void 0;
1125
+ }
1126
+ getTimeslotBySchedule({
1127
+ date,
1128
+ scheduleIds,
1129
+ resources
1130
+ }) {
1131
+ var _a, _b, _c;
1132
+ const targetProduct = this.store.currentProduct;
1133
+ const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
1134
+ let targetSchedules = [];
1135
+ if (scheduleIds == null ? void 0 : scheduleIds.length) {
1136
+ targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1137
+ } else {
1138
+ targetSchedules = this.store.schedule.getScheduleListByIds(
1139
+ targetProductData["schedule.ids"]
1140
+ );
1141
+ }
1142
+ const resourcesDates = this.store.date.getDateList();
1143
+ const targetResourceDate = resourcesDates.find((n) => n.date === date);
1144
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1145
+ const resourcesMap = (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1146
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
1147
+ cartItems,
1148
+ "",
1149
+ resourcesMap
1150
+ );
1151
+ const productResources = (0, import_resources.getResourcesByProduct)(
1152
+ resourcesMap,
1153
+ resources || ((_c = (_b = (_a = this.store.currentProduct) == null ? void 0 : _a.getData()) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
1154
+ selectedResources,
1155
+ 1
1156
+ );
1157
+ const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
1158
+ targetSchedules,
1159
+ {},
1160
+ date
1161
+ );
1162
+ const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1163
+ console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
1164
+ let allProductResources = productResources.flatMap((n) => n.renderList);
1165
+ allProductResources.sort((a, b) => {
1166
+ var _a2, _b2, _c2, _d;
1167
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1168
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1169
+ if (aIsCombined && !bIsCombined)
1170
+ return 1;
1171
+ if (!aIsCombined && bIsCombined)
1172
+ return -1;
1173
+ return 0;
1174
+ });
1175
+ const resourcesUseableMap = {};
1176
+ const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1177
+ let count = 0;
1178
+ allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1179
+ m.times.forEach((childTiem) => {
1180
+ const res = (0, import_resources.getIsUsableByTimeItem)({
1181
+ timeSlice: {
1182
+ start_time: item.start,
1183
+ end_time: item.end,
1184
+ start_at: (0, import_dayjs.default)(item.start),
1185
+ end_at: (0, import_dayjs.default)(item.end)
1186
+ },
1187
+ time: childTiem,
1188
+ resource: m,
1189
+ currentCount: 1,
1190
+ resourcesUseableMap
1191
+ });
1192
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
1193
+ resourcesUseableMap[m.id] = res.usable;
1194
+ }
1195
+ if (res.usable && res.remainingCapacity >= count) {
1196
+ count = res.remainingCapacity;
1197
+ }
1198
+ });
1199
+ });
1200
+ const startDayJs = (0, import_dayjs.default)(item.start);
1201
+ const endDayJs = (0, import_dayjs.default)(item.end);
1202
+ return {
1203
+ start_time: startDayJs.format("HH:mm"),
1204
+ end_time: endDayJs.format("HH:mm"),
1205
+ start_at: startDayJs,
1206
+ end_at: endDayJs,
1207
+ count
1208
+ };
1209
+ });
1210
+ return formatScheduleTimeSlots;
1211
+ }
1212
+ addProductToCart({
1213
+ product,
1214
+ date,
1215
+ account
1216
+ }) {
1217
+ const { bundle, options, origin, product_variant_id } = product || {};
1218
+ const productData = { ...origin, product_variant_id };
1219
+ if (!account) {
1220
+ const activeAccount = this.getActiveAccount();
1221
+ if (activeAccount) {
1222
+ account = activeAccount;
1223
+ }
1224
+ }
1225
+ this.store.cart.addItem({
1226
+ product: productData,
1227
+ date,
1228
+ account,
1229
+ bundle,
1230
+ options
1231
+ });
1232
+ if (date) {
1233
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1234
+ const cartItemsByDate = cartItems.filter(
1235
+ (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
1236
+ );
1237
+ if (cartItemsByDate.length) {
1238
+ cartItemsByDate.forEach((n) => {
1239
+ this.store.cart.removeItem(n._id);
1240
+ });
1241
+ }
1242
+ }
1243
+ }
1244
+ setOtherData(key, value) {
1245
+ this.otherData[key] = value;
1246
+ this.checkSaveCache({
1247
+ cacheId: this.cacheId,
1248
+ fatherModule: this.name,
1249
+ store: { otherData: this.otherData },
1250
+ cacheKey: ["otherData"]
1251
+ });
1252
+ }
1253
+ getOtherData(key) {
1254
+ return this.otherData[key];
1255
+ }
1256
+ async getProductTypeById(id) {
1257
+ const product = await this.store.products.getProduct(id);
1258
+ if (product) {
1259
+ return product.getProductType();
1260
+ }
1261
+ return "normal";
1262
+ }
715
1263
  };
716
1264
  // Annotate the CommonJS export names for ESM import in node:
717
1265
  0 && (module.exports = {