@pisell/pisellos 0.0.79 → 0.0.81

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.
@@ -242,7 +242,11 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
242
242
  return item.default_resource.indexOf(d) == -1;
243
243
  });
244
244
  var optional_resource = item.optional_resource.reduce(function (childAcc, d) {
245
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
245
+ var _resourcesMap$d;
246
+ // 如果其他资源选择过,并且这个资源是单个预约,则不可以选中此资源
247
+ // TODO: 如果容量超了这里怎么处理?
248
+ var isSelectSingleResources = ((_resourcesMap$d = resourcesMap[d]) === null || _resourcesMap$d === void 0 ? void 0 : _resourcesMap$d.resourceType) === 'single' && selectedResources.includes(resourcesMap[d].id);
249
+ if (resourcesMap[d] && !isSelectSingleResources) {
246
250
  // 拼装组合资源的数据
247
251
  var combiningResources = [];
248
252
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
@@ -274,7 +278,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
274
278
  return childAcc;
275
279
  }, []);
276
280
  var default_resource = item.default_resource.reduce(function (childAcc, d) {
277
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
281
+ var _resourcesMap$d2;
282
+ var isSelectSingleResources = ((_resourcesMap$d2 = resourcesMap[d]) === null || _resourcesMap$d2 === void 0 ? void 0 : _resourcesMap$d2.resourceType) === 'single' && selectedResources.includes(resourcesMap[d].id);
283
+ if (resourcesMap[d] && !isSelectSingleResources) {
278
284
  // 拼装组合资源的数据
279
285
  var combiningResources = [];
280
286
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
@@ -574,7 +580,7 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
574
580
  * @return {*}
575
581
  * @Author: jinglin.tan
576
582
  */
577
- export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap) {
583
+ export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap, currentCapacity) {
578
584
  return cartItems.reduce(function (acc, d) {
579
585
  if (d.holder_id !== accountId) {
580
586
  var _d$_origin;
@@ -589,9 +595,9 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
589
595
  return acc;
590
596
  }
591
597
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
592
- n.metadata.combined_resource.resource_ids.forEach(function (m) {
593
- resourcesMap[m].capacity -= n.num;
594
- });
598
+ // n.metadata.combined_resource.resource_ids.forEach((m: number) => {
599
+ // if (resourcesMap[m]) resourcesMap[m].capacity -= d.num || 0;
600
+ // });
595
601
  } else {
596
602
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
597
603
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -599,13 +605,13 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
599
605
  if (m.combined_resource && m.combined_resource.status === 1) {
600
606
  if (m.combined_resource.resource_ids.includes(n.id)) {
601
607
  acc.push(m.id);
602
- resourcesMap[m.id].capacity -= n.num;
608
+ // if (resourcesMap[m.id]) resourcesMap[m.id].capacity -= d.num || 0;
603
609
  }
604
610
  }
605
611
  });
606
612
  }
607
613
  acc.push(n.id);
608
- resourcesMap[n.id].capacity -= n.num;
614
+ if (resourcesMap[n.id]) resourcesMap[n.id].capacity -= currentCapacity || 0;
609
615
  });
610
616
  }
611
617
  }
@@ -621,7 +627,7 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
621
627
  * @return {*}
622
628
  * @Author: jinglin.tan
623
629
  */
624
- export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap) {
630
+ export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap, currentCapacity) {
625
631
  return cartItems.reduce(function (acc, d) {
626
632
  if (d._id !== cartItemId) {
627
633
  var _d$_origin2;
@@ -636,9 +642,9 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
636
642
  return acc;
637
643
  }
638
644
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
639
- n.metadata.combined_resource.resource_ids.forEach(function (m) {
640
- resourcesMap[m].capacity -= n.num;
641
- });
645
+ // n.metadata.combined_resource.resource_ids.forEach((m: number) => {
646
+ // resourcesMap[m].capacity -= n.num;
647
+ // });
642
648
  } else {
643
649
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
644
650
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -646,14 +652,14 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
646
652
  if (m.combined_resource && m.combined_resource.status === 1) {
647
653
  if (m.combined_resource.resource_ids.includes(n.id)) {
648
654
  acc.push(m.id);
649
- resourcesMap[m.id].capacity -= n.num;
655
+ // resourcesMap[m.id].capacity -= n.num;
650
656
  }
651
657
  }
652
658
  });
653
659
  }
654
660
  acc.push(n.id);
655
661
  // push 完以后,把 resourceMap 的 capacity 减掉当前的商品数量
656
- resourcesMap[n.id].capacity -= n.num;
662
+ // resourcesMap[n.id].capacity -= currentCapacity || 0;
657
663
  });
658
664
  }
659
665
  }
@@ -16,6 +16,7 @@ export declare class AccountListModule extends BaseModule implements Module {
16
16
  * 创建账号并添加到列表中
17
17
  * @param account 账号信息
18
18
  * @param needEmit 是否需要触发事件
19
+ * @param type 添加类型
19
20
  */
20
21
  private createAccountAndAdd;
21
22
  addAccount(account: Account): Promise<AccountModule>;
@@ -30,10 +31,12 @@ export declare class AccountListModule extends BaseModule implements Module {
30
31
  storeChange(): void;
31
32
  /**
32
33
  * 批量添加holder类型账号
33
- * @param holders 账号信息列表
34
- * @param customerId 账户id
35
34
  */
36
- addHolderAccounts(holders: IHolder[], customerId: number): Promise<AccountModule[]>;
35
+ addHolderAccounts(params: {
36
+ holders: IHolder[];
37
+ customerId: number;
38
+ type?: 'unshift' | 'push';
39
+ }): Promise<AccountModule[]>;
37
40
  /**
38
41
  * 获取holder类型账户列表
39
42
  * @param params
@@ -69,19 +69,30 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
69
69
  * 创建账号并添加到列表中
70
70
  * @param account 账号信息
71
71
  * @param needEmit 是否需要触发事件
72
+ * @param type 添加类型
72
73
  */
73
- async createAccountAndAdd(account, needEmit = true) {
74
+ async createAccountAndAdd(account, needEmit = true, type) {
74
75
  const tempAccountModule = this.store.accounts.find(
75
76
  (a) => a.getId() === account.id
76
77
  );
77
78
  if (tempAccountModule) {
78
79
  return tempAccountModule;
79
80
  }
80
- this.store.accountList.push(account);
81
+ const newAccountList = [...this.store.accountList || []];
82
+ if (type === "unshift") {
83
+ newAccountList.unshift(account);
84
+ } else {
85
+ newAccountList.push(account);
86
+ }
87
+ this.store.accountList = newAccountList;
81
88
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
82
89
  this.core.registerModule(accountModule);
83
90
  accountModule.setAccountInfo(account);
84
- this.store.accounts = [...this.store.accounts || [], accountModule];
91
+ if (type === "unshift") {
92
+ this.store.accounts = [accountModule, ...this.store.accounts || []];
93
+ } else {
94
+ this.store.accounts = [...this.store.accounts || [], accountModule];
95
+ }
85
96
  if (needEmit) {
86
97
  await this.core.effects.emit(
87
98
  import_types.AccountListHooks.OnAccountListUpdate,
@@ -250,15 +261,22 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
250
261
  }
251
262
  /**
252
263
  * 批量添加holder类型账号
253
- * @param holders 账号信息列表
254
- * @param customerId 账户id
255
264
  */
256
- async addHolderAccounts(holders, customerId) {
265
+ async addHolderAccounts(params) {
266
+ const { holders, customerId, type = "push" } = params;
257
267
  const accountModules = [];
258
268
  for (const holder of holders) {
259
269
  const account = (0, import_utils.createHolderAccount)(holder, customerId);
260
- const accountModule = await this.createAccountAndAdd(account, false);
261
- accountModules.push(accountModule);
270
+ const accountModule = await this.createAccountAndAdd(
271
+ account,
272
+ false,
273
+ type
274
+ );
275
+ if (type === "unshift") {
276
+ accountModules.unshift(accountModule);
277
+ } else {
278
+ accountModules.push(accountModule);
279
+ }
262
280
  }
263
281
  await this.core.effects.emit(
264
282
  import_types.AccountListHooks.OnAccountListUpdate,
@@ -283,7 +301,10 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
283
301
  skip: skip || 1
284
302
  });
285
303
  if ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) {
286
- await this.addHolderAccounts(res.data.list, customer_id);
304
+ await this.addHolderAccounts({
305
+ holders: res.data.list,
306
+ customerId: customer_id
307
+ });
287
308
  }
288
309
  } catch (error) {
289
310
  console.error(error);
@@ -445,6 +445,7 @@ var getProductDeposit = (params) => {
445
445
  let total = new import_decimal.default(0);
446
446
  const { deposit_fixed, deposit_percentage, deposit_policy_data } = (product == null ? void 0 : product.custom_deposit_data) || {};
447
447
  protocols.push(...deposit_policy_data || []);
448
+ let productHasDeposit = false;
448
449
  if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
449
450
  const { depositTotal, result } = handleProductDeposit({
450
451
  depositData: product == null ? void 0 : product.custom_deposit_data,
@@ -453,6 +454,7 @@ var getProductDeposit = (params) => {
453
454
  });
454
455
  if (result) {
455
456
  total = depositTotal;
457
+ productHasDeposit = true;
456
458
  }
457
459
  } else {
458
460
  if (bundle == null ? void 0 : bundle.length) {
@@ -463,13 +465,17 @@ var getProductDeposit = (params) => {
463
465
  num: currentBundleProduct.num
464
466
  });
465
467
  if (result) {
468
+ productHasDeposit = true;
466
469
  return accumulator.plus(depositTotal);
467
470
  }
468
471
  return accumulator;
469
472
  }, new import_decimal.default(0));
470
473
  }
471
474
  }
472
- return { total: total.toNumber(), protocols };
475
+ if (productHasDeposit) {
476
+ return { total: total.toNumber(), protocols };
477
+ }
478
+ return null;
473
479
  }
474
480
  return null;
475
481
  };
@@ -147,6 +147,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
147
147
  checkCartItems(type: ECartItemCheckType): string[];
148
148
  destroy(): void;
149
149
  getResourcesList(): any[];
150
+ checkResourceListForDate(): boolean;
150
151
  getResourcesListByCartItem(id: string | number): {
151
152
  id: number | undefined;
152
153
  _id: string;