@pisell/pisellos 0.0.43 → 0.0.45

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 (127) 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 +19 -0
  5. package/dist/modules/AccountList/index.js +224 -70
  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 +5 -5
  13. package/dist/modules/Cart/index.js +32 -19
  14. package/dist/modules/Cart/types.d.ts +18 -4
  15. package/dist/modules/Cart/utils.d.ts +29 -5
  16. package/dist/modules/Cart/utils.js +72 -26
  17. package/dist/modules/Date/index.d.ts +6 -6
  18. package/dist/modules/Date/index.js +41 -55
  19. package/dist/modules/Date/types.d.ts +22 -6
  20. package/dist/modules/Date/utils.d.ts +4 -3
  21. package/dist/modules/Date/utils.js +74 -23
  22. package/dist/modules/Discount/index.d.ts +4 -4
  23. package/dist/modules/Discount/index.js +11 -11
  24. package/dist/modules/Order/index.d.ts +11 -5
  25. package/dist/modules/Order/index.js +39 -18
  26. package/dist/modules/Order/types.d.ts +10 -3
  27. package/dist/modules/Product/index.d.ts +4 -1
  28. package/dist/modules/Product/index.js +22 -0
  29. package/dist/modules/Product/types.d.ts +7 -3
  30. package/dist/modules/ProductList/index.js +11 -5
  31. package/dist/modules/Resource/utils.js +1 -1
  32. package/dist/modules/Rules/index.d.ts +4 -4
  33. package/dist/modules/Rules/index.js +11 -11
  34. package/dist/modules/Rules/types.d.ts +1 -1
  35. package/dist/modules/Schedule/index.d.ts +8 -3
  36. package/dist/modules/Schedule/index.js +45 -5
  37. package/dist/modules/Schedule/type.d.ts +7 -7
  38. package/dist/modules/Schedule/types.d.ts +8 -8
  39. package/dist/modules/Schedule/utils.d.ts +9 -3
  40. package/dist/modules/Schedule/utils.js +77 -48
  41. package/dist/modules/Step/index.d.ts +14 -3
  42. package/dist/modules/Step/index.js +54 -2
  43. package/dist/modules/Summary/index.d.ts +5 -5
  44. package/dist/modules/Summary/index.js +7 -7
  45. package/dist/modules/Summary/types.d.ts +2 -2
  46. package/dist/modules/Summary/utils.d.ts +4 -4
  47. package/dist/modules/Summary/utils.js +3 -3
  48. package/dist/plugins/index.d.ts +3 -3
  49. package/dist/plugins/request.d.ts +3 -3
  50. package/dist/plugins/request.js +30 -30
  51. package/dist/plugins/shopStore.d.ts +1 -1
  52. package/dist/solution/BookingByStep/index.d.ts +65 -16
  53. package/dist/solution/BookingByStep/index.js +553 -216
  54. package/dist/solution/BookingByStep/types.d.ts +2 -2
  55. package/dist/solution/BookingByStep/types.js +9 -9
  56. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  57. package/dist/solution/BookingByStep/utils/products.js +3 -0
  58. package/dist/solution/BookingByStep/utils/resources.d.ts +5 -5
  59. package/dist/solution/BookingByStep/utils/resources.js +11 -11
  60. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  61. package/dist/solution/ShopDiscount/index.js +16 -16
  62. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  63. package/dist/solution/ShopDiscount/utils.js +1 -1
  64. package/lib/core/index.js +7 -2
  65. package/lib/modules/Account/index.d.ts +2 -6
  66. package/lib/modules/Account/index.js +15 -30
  67. package/lib/modules/Account/types.d.ts +12 -1
  68. package/lib/modules/AccountList/index.d.ts +19 -0
  69. package/lib/modules/AccountList/index.js +109 -12
  70. package/lib/modules/AccountList/types.d.ts +33 -1
  71. package/lib/modules/AccountList/utils.d.ts +9 -0
  72. package/lib/modules/AccountList/utils.js +39 -0
  73. package/lib/modules/BaseModule.d.ts +2 -2
  74. package/lib/modules/BaseModule.js +14 -3
  75. package/lib/modules/Cart/index.d.ts +5 -5
  76. package/lib/modules/Cart/index.js +27 -6
  77. package/lib/modules/Cart/types.d.ts +18 -4
  78. package/lib/modules/Cart/utils.d.ts +29 -5
  79. package/lib/modules/Cart/utils.js +47 -3
  80. package/lib/modules/Date/index.d.ts +6 -6
  81. package/lib/modules/Date/index.js +6 -6
  82. package/lib/modules/Date/types.d.ts +22 -6
  83. package/lib/modules/Date/utils.d.ts +4 -3
  84. package/lib/modules/Date/utils.js +37 -6
  85. package/lib/modules/Discount/index.d.ts +4 -4
  86. package/lib/modules/Discount/index.js +9 -2
  87. package/lib/modules/Guests/index.js +4 -1
  88. package/lib/modules/Order/index.d.ts +11 -5
  89. package/lib/modules/Order/index.js +18 -3
  90. package/lib/modules/Order/types.d.ts +10 -3
  91. package/lib/modules/Payment/index.js +1 -6
  92. package/lib/modules/Product/index.d.ts +4 -1
  93. package/lib/modules/Product/index.js +16 -0
  94. package/lib/modules/Product/types.d.ts +7 -3
  95. package/lib/modules/ProductList/index.js +21 -7
  96. package/lib/modules/Resource/index.js +4 -1
  97. package/lib/modules/Resource/utils.js +7 -4
  98. package/lib/modules/Rules/index.d.ts +4 -4
  99. package/lib/modules/Rules/types.d.ts +1 -1
  100. package/lib/modules/Schedule/index.d.ts +8 -3
  101. package/lib/modules/Schedule/index.js +33 -2
  102. package/lib/modules/Schedule/type.d.ts +7 -7
  103. package/lib/modules/Schedule/types.d.ts +8 -8
  104. package/lib/modules/Schedule/utils.d.ts +9 -3
  105. package/lib/modules/Schedule/utils.js +32 -4
  106. package/lib/modules/Step/index.d.ts +14 -3
  107. package/lib/modules/Step/index.js +38 -1
  108. package/lib/modules/Summary/index.d.ts +5 -5
  109. package/lib/modules/Summary/types.d.ts +2 -2
  110. package/lib/modules/Summary/utils.d.ts +4 -4
  111. package/lib/plugins/index.d.ts +3 -3
  112. package/lib/plugins/request.d.ts +3 -3
  113. package/lib/plugins/request.js +48 -11
  114. package/lib/plugins/shopStore.d.ts +1 -1
  115. package/lib/solution/BookingByStep/index.d.ts +65 -16
  116. package/lib/solution/BookingByStep/index.js +351 -39
  117. package/lib/solution/BookingByStep/types.d.ts +2 -2
  118. package/lib/solution/BookingByStep/types.js +36 -9
  119. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  120. package/lib/solution/BookingByStep/utils/products.js +3 -0
  121. package/lib/solution/BookingByStep/utils/resources.d.ts +5 -5
  122. package/lib/solution/BookingByStep/utils/resources.js +103 -52
  123. package/lib/solution/BuyTickets/index.js +34 -20
  124. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  125. package/lib/solution/ShopDiscount/index.js +10 -2
  126. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  127. package/package.json +4 -2
@@ -26,6 +26,7 @@ var import_lodash_es = require("lodash-es");
26
26
  var import_Account = require("../Account");
27
27
  var import_BaseModule = require("../BaseModule");
28
28
  var import_types = require("./types");
29
+ var import_utils = require("./utils");
29
30
  var AccountListModule = class extends import_BaseModule.BaseModule {
30
31
  constructor(name, version) {
31
32
  super(name, version);
@@ -45,6 +46,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
45
46
  var _a, _b, _c;
46
47
  this.core = core;
47
48
  this.store = options == null ? void 0 : options.store;
49
+ this.request = this.core.getPlugin("request");
48
50
  if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.accountList)) {
49
51
  const recordList = (0, import_lodash_es.cloneDeep)(options.initialState.accountList || []);
50
52
  this.store.accounts = [];
@@ -63,6 +65,27 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
63
65
  this.fatherModule = options.otherParams.fatherModule;
64
66
  }
65
67
  }
68
+ /**
69
+ * 创建账号并添加到列表中
70
+ * @param account 账号信息
71
+ * @param needEmit 是否需要触发事件
72
+ */
73
+ async createAccountAndAdd(account, needEmit = true) {
74
+ if (this.store.accounts.some((a) => a.getId() === account.id)) {
75
+ return;
76
+ }
77
+ this.store.accountList.push(account);
78
+ const accountModule = new import_Account.AccountModule(`account_${account.id}`);
79
+ this.core.registerModule(accountModule);
80
+ accountModule.setAccountInfo(account);
81
+ this.store.accounts = [...this.store.accounts || [], accountModule];
82
+ if (needEmit) {
83
+ await this.core.effects.emit(
84
+ import_types.AccountListHooks.OnAccountListUpdate,
85
+ this.store
86
+ );
87
+ }
88
+ }
66
89
  async addAccount(account) {
67
90
  try {
68
91
  this.store.isLoading = true;
@@ -79,11 +102,17 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
79
102
  if (this.store.accounts.length === 1) {
80
103
  this.setActiveAccount(accountModule.getId());
81
104
  }
82
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
105
+ await this.core.effects.emit(
106
+ import_types.AccountListHooks.OnAccountListUpdate,
107
+ this.store
108
+ );
83
109
  } catch (error) {
84
110
  console.error(error);
85
111
  this.store.error = error instanceof Error ? error.message : "Failed to add account";
86
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
112
+ await this.core.effects.emit(
113
+ import_types.AccountListHooks.OnAccountListError,
114
+ this.store.error
115
+ );
87
116
  } finally {
88
117
  this.store.isLoading = false;
89
118
  }
@@ -97,14 +126,22 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
97
126
  throw new Error(`Account with id ${id} not found`);
98
127
  }
99
128
  account.setAccountInfo(updates);
100
- const index = this.store.accountList.findIndex((account2) => account2.id === id);
129
+ const index = this.store.accountList.findIndex(
130
+ (account2) => account2.id === id
131
+ );
101
132
  if (index !== -1) {
102
133
  this.store.accountList[index] = updates;
103
134
  }
104
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
135
+ await this.core.effects.emit(
136
+ import_types.AccountListHooks.OnAccountListUpdate,
137
+ this.store
138
+ );
105
139
  } catch (error) {
106
140
  this.store.error = error instanceof Error ? error.message : "Failed to update account";
107
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
141
+ await this.core.effects.emit(
142
+ import_types.AccountListHooks.OnAccountListError,
143
+ this.store.error
144
+ );
108
145
  } finally {
109
146
  this.store.isLoading = false;
110
147
  }
@@ -116,7 +153,10 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
116
153
  }
117
154
  return account;
118
155
  });
119
- this.core.effects.emit(`${this.name}:changed`, { path: "accounts", value: this.store.accountList });
156
+ this.core.effects.emit(`${this.name}:changed`, {
157
+ path: "accounts",
158
+ value: this.store.accountList
159
+ });
120
160
  }
121
161
  async removeAccount(id) {
122
162
  try {
@@ -131,11 +171,19 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
131
171
  ...(this.store.accounts || []).slice(0, index),
132
172
  ...(this.store.accounts || []).slice(index + 1)
133
173
  ];
134
- this.store.accountList = this.store.accountList.filter((account) => account.id !== id);
135
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
174
+ this.store.accountList = this.store.accountList.filter(
175
+ (account) => account.id !== id
176
+ );
177
+ await this.core.effects.emit(
178
+ import_types.AccountListHooks.OnAccountListUpdate,
179
+ this.store
180
+ );
136
181
  } catch (error) {
137
182
  this.store.error = error instanceof Error ? error.message : "Failed to remove account";
138
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
183
+ await this.core.effects.emit(
184
+ import_types.AccountListHooks.OnAccountListError,
185
+ this.store.error
186
+ );
139
187
  } finally {
140
188
  this.store.isLoading = false;
141
189
  }
@@ -151,10 +199,16 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
151
199
  this.store.isLoading = true;
152
200
  this.store.error = null;
153
201
  this.store.accounts = [];
154
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
202
+ await this.core.effects.emit(
203
+ import_types.AccountListHooks.OnAccountListUpdate,
204
+ this.store
205
+ );
155
206
  } catch (error) {
156
207
  this.store.error = error instanceof Error ? error.message : "Failed to clear accounts";
157
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
208
+ await this.core.effects.emit(
209
+ import_types.AccountListHooks.OnAccountListError,
210
+ this.store.error
211
+ );
158
212
  } finally {
159
213
  this.store.isLoading = false;
160
214
  }
@@ -177,7 +231,50 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
177
231
  store.accountList = store.accountList.filter(
178
232
  (account, index, self) => index === self.findIndex((t) => t.id === account.id)
179
233
  );
180
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store, cacheKey: ["accountList"] });
234
+ this.checkSaveCache({
235
+ cacheId: this.cacheId,
236
+ fatherModule: this.fatherModule,
237
+ store,
238
+ cacheKey: ["accountList"]
239
+ });
240
+ }
241
+ }
242
+ /**
243
+ * 批量添加holder类型账号
244
+ * @param holders 账号信息列表
245
+ * @param customerId 账户id
246
+ */
247
+ async addHolderAccounts(holders, customerId) {
248
+ for (const holder of holders) {
249
+ const account = (0, import_utils.createHolderAccount)(holder, customerId);
250
+ await this.createAccountAndAdd(account, false);
251
+ }
252
+ await this.core.effects.emit(
253
+ import_types.AccountListHooks.OnAccountListUpdate,
254
+ this.store
255
+ );
256
+ }
257
+ /**
258
+ * 获取holder类型账户列表
259
+ * @param params
260
+ */
261
+ async fetchHolderAccounts(params) {
262
+ var _a, _b;
263
+ const url = params.url || "/account/holder";
264
+ const { form_id, shop_id, num, skip, customer_id } = (params == null ? void 0 : params.query) || {};
265
+ try {
266
+ const res = await this.request.get(url, {
267
+ customer_id,
268
+ form_id,
269
+ shop_id,
270
+ num: num || 100,
271
+ skip: skip || 1
272
+ });
273
+ if ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) {
274
+ await this.addHolderAccounts(res.data.list, customer_id);
275
+ }
276
+ } catch (error) {
277
+ console.error(error);
181
278
  }
182
279
  }
183
280
  };
@@ -1,4 +1,4 @@
1
- import { Account, AccountModule } from "../Account";
1
+ import { Account, AccountModule } from '../Account';
2
2
  export declare enum AccountListHooks {
3
3
  OnAccountListUpdate = "accountList:onUpdate",
4
4
  OnAccountListError = "accountList:onError"
@@ -27,11 +27,43 @@ export interface AccountListState {
27
27
  * 账户列表模块 API
28
28
  */
29
29
  export interface AccountListModuleAPI {
30
+ /** 添加账户 */
30
31
  addAccount: (account: Account) => Promise<void>;
32
+ /** 更新账户 */
31
33
  updateAccount: (id: string, updates: Partial<AccountModule>) => Promise<void>;
34
+ /** 删除账户 */
32
35
  removeAccount: (id: string) => Promise<void>;
36
+ /** 获取账户列表 */
33
37
  getAccounts: () => AccountModule[];
38
+ /** 获取单个账户 */
34
39
  getAccount: (id: string) => AccountModule | null;
40
+ /** 清空账户列表 */
35
41
  clearAccounts: () => Promise<void>;
42
+ /** 批量添加账户 */
36
43
  addAccounts: (accounts: AccountModule[]) => Promise<void>;
44
+ /** 获取holder类型账户列表 */
45
+ fetchHolderAccounts: (params: IFetchHolderAccountsParams) => Promise<void>;
46
+ }
47
+ /**
48
+ * 获取holder类型账户列表参数
49
+ */
50
+ export interface IFetchHolderAccountsParams {
51
+ url?: string;
52
+ query: {
53
+ customer_id: number;
54
+ form_id: string | number;
55
+ shop_id: string | number;
56
+ num?: number;
57
+ skip?: number;
58
+ };
59
+ }
60
+ /**
61
+ * holder类型数据
62
+ */
63
+ export interface IHolder {
64
+ created_at: string;
65
+ form_id: number;
66
+ form_record_id: number;
67
+ main_field: string;
68
+ customer_cover?: string;
37
69
  }
@@ -0,0 +1,9 @@
1
+ import { Account } from '../Account/types';
2
+ import { IHolder } from './types';
3
+ /**
4
+ * 创建holder类型账号
5
+ * @param holder
6
+ * @param customer_id 账户id
7
+ * @returns
8
+ */
9
+ export declare const createHolderAccount: (holder: IHolder, customerId: number) => Account;
@@ -0,0 +1,39 @@
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/modules/AccountList/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ createHolderAccount: () => createHolderAccount
23
+ });
24
+ module.exports = __toCommonJS(utils_exports);
25
+ var createHolderAccount = (holder, customerId) => {
26
+ const account = {
27
+ id: holder.form_record_id,
28
+ name: holder.main_field,
29
+ username: holder.main_field,
30
+ avatar: (holder == null ? void 0 : holder.customer_cover) || "",
31
+ type: "holder",
32
+ _origin: { ...holder, customer_id: customerId }
33
+ };
34
+ return account;
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ createHolderAccount
39
+ });
@@ -1,4 +1,4 @@
1
- import { PisellCore } from "../types";
1
+ import { PisellCore } from '../types';
2
2
  export declare class BaseModule {
3
3
  protected defaultName: string;
4
4
  protected defaultVersion: string;
@@ -8,7 +8,7 @@ export declare class BaseModule {
8
8
  protected core: PisellCore;
9
9
  constructor(name?: string, version?: string);
10
10
  destroy(): void;
11
- checkSaveCache({ cacheId, fatherModule, store, cacheKey }: {
11
+ checkSaveCache({ cacheId, fatherModule, store, cacheKey, }: {
12
12
  cacheId: string | undefined;
13
13
  fatherModule: string | undefined;
14
14
  store: any;
@@ -35,7 +35,12 @@ var BaseModule = class {
35
35
  this.core.unregisterModule(this);
36
36
  }
37
37
  // 提供统一的缓存 module 里的数据的方法
38
- checkSaveCache({ cacheId, fatherModule, store, cacheKey }) {
38
+ checkSaveCache({
39
+ cacheId,
40
+ fatherModule,
41
+ store,
42
+ cacheKey
43
+ }) {
39
44
  const window = this.core.getPlugin("window");
40
45
  if (cacheId) {
41
46
  if (fatherModule) {
@@ -54,7 +59,10 @@ var BaseModule = class {
54
59
  cacheKey.forEach((key) => {
55
60
  currentCacheDataObj[cacheId][this.name][key] = store == null ? void 0 : store[key];
56
61
  });
57
- window.sessionStorage.setItem(fatherModule, JSON.stringify(currentCacheDataObj));
62
+ window.sessionStorage.setItem(
63
+ fatherModule,
64
+ JSON.stringify(currentCacheDataObj)
65
+ );
58
66
  } else {
59
67
  let currentCacheData = window.sessionStorage.getItem(cacheId);
60
68
  let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
@@ -67,7 +75,10 @@ var BaseModule = class {
67
75
  cacheKey.forEach((key) => {
68
76
  currentCacheDataObj[this.name][key] = store[key];
69
77
  });
70
- window.sessionStorage.setItem(cacheId, JSON.stringify(currentCacheDataObj));
78
+ window.sessionStorage.setItem(
79
+ cacheId,
80
+ JSON.stringify(currentCacheDataObj)
81
+ );
71
82
  }
72
83
  }
73
84
  }
@@ -1,7 +1,7 @@
1
- import { Module, PisellCore, ModuleOptions } from "../../types";
2
- import { BaseModule } from "../BaseModule";
3
- import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from "./types";
4
- export * from "./types";
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from './types';
4
+ export * from './types';
5
5
  /**
6
6
  * 购物车模块实现
7
7
  */
@@ -58,7 +58,7 @@ export declare class CartModule extends BaseModule implements Module, CartModule
58
58
  /**
59
59
  * 清除购物车商品中的信息
60
60
  */
61
- deleteCartItemInfo(types: "resource" | "time"): void;
61
+ deleteCartItemInfo(types: 'resource' | 'time'): void;
62
62
  /**
63
63
  * 清除购物车
64
64
  */
@@ -23,9 +23,9 @@ __export(Cart_exports, {
23
23
  CartModule: () => CartModule
24
24
  });
25
25
  module.exports = __toCommonJS(Cart_exports);
26
- var import_lodash_es = require("lodash-es");
27
26
  var import_BaseModule = require("../BaseModule");
28
27
  var import_utils = require("./utils");
28
+ var import_lodash_es = require("lodash-es");
29
29
  __reExport(Cart_exports, require("./types"), module.exports);
30
30
  var CartModule = class extends import_BaseModule.BaseModule {
31
31
  constructor(name, version) {
@@ -69,7 +69,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
69
69
  * 添加商品到购物车
70
70
  */
71
71
  async addItem(params) {
72
- const { account, product, bundle, options } = params;
72
+ const { account, product, bundle, options, date } = params;
73
73
  let cartItem = {
74
74
  _id: (0, import_utils.getUniqueId)(),
75
75
  _origin: (0, import_utils.createCartItemOrigin)()
@@ -86,6 +86,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
86
86
  if (account) {
87
87
  cartItem = (0, import_utils.formatAccountToCartItem)({ cartItem, account });
88
88
  }
89
+ if (date) {
90
+ cartItem = (0, import_utils.formatDateToCartItem)({ cartItem, date });
91
+ }
89
92
  const items = [...this.store.list, cartItem];
90
93
  this.store.list = items;
91
94
  await this.core.effects.emit(`${this.name}:onAddItem`, cartItem);
@@ -112,7 +115,16 @@ var CartModule = class extends import_BaseModule.BaseModule {
112
115
  * 格式化数据到购物车
113
116
  */
114
117
  formatCartItem(params) {
115
- const { _id, cartItem, account, product, discounts, resources, note } = params;
118
+ const {
119
+ _id,
120
+ cartItem,
121
+ account,
122
+ product,
123
+ discounts,
124
+ resources,
125
+ note,
126
+ date
127
+ } = params;
116
128
  let tempCartItem = this.store.list.find((i) => i._id === _id);
117
129
  if (!tempCartItem) {
118
130
  throw new Error("[CartModule] 格式化数据到购物车失败,商品不存在");
@@ -145,6 +157,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
145
157
  resources
146
158
  });
147
159
  }
160
+ if (date) {
161
+ tempCartItem = (0, import_utils.formatDateToCartItem)({ cartItem: tempCartItem, date });
162
+ }
148
163
  if (note) {
149
164
  tempCartItem = (0, import_utils.formatNoteToCartItem)({ cartItem: tempCartItem, note });
150
165
  }
@@ -172,7 +187,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
172
187
  * 根据账户ID获取购物车
173
188
  */
174
189
  getCartByAccount(account_id) {
175
- return this.store.list.filter((item) => item.holder_id === account_id);
190
+ return this.store.list.filter(
191
+ (item) => item.holder_id === account_id
192
+ );
176
193
  }
177
194
  /**
178
195
  * 移除购物车商品
@@ -186,7 +203,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
186
203
  * 根据账户ID清除购物车
187
204
  */
188
205
  clearCartByAccount(account_id) {
189
- const items = this.store.list.filter((item) => item.holder_id !== account_id);
206
+ const items = this.store.list.filter(
207
+ (item) => item.holder_id !== account_id
208
+ );
190
209
  this.store.list = [...items || []];
191
210
  }
192
211
  /**
@@ -212,7 +231,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
212
231
  storeChange() {
213
232
  if (this.openCache) {
214
233
  const store = (0, import_lodash_es.cloneDeep)(this.store);
215
- store.list = store.list.filter((item, index, self) => index === self.findIndex((t) => t._id === item._id));
234
+ store.list = store.list.filter(
235
+ (item, index, self) => index === self.findIndex((t) => t._id === item._id)
236
+ );
216
237
  this.checkSaveCache({
217
238
  cacheId: this.cacheId,
218
239
  fatherModule: this.fatherModule,
@@ -1,6 +1,6 @@
1
- import { ProductData } from "../Product/types";
2
- import { Account } from "../Account/types";
3
- import { Resource } from "../Resource/types";
1
+ import { ProductData } from '../Product/types';
2
+ import { Account } from '../Account/types';
3
+ import { Resource } from '../Resource/types';
4
4
  export declare enum CartHooks {
5
5
  OnAddItem = "card:onAddItem",
6
6
  OnCartChange = "card:onCartChange",
@@ -57,7 +57,7 @@ export interface CartItem {
57
57
  /** 备注 */
58
58
  note?: string;
59
59
  /** 点赞状态 */
60
- like_status?: "like" | "common";
60
+ like_status?: 'like' | 'common';
61
61
  /** 用户名称 */
62
62
  holder_title?: string;
63
63
  /** 用户ID */
@@ -127,6 +127,13 @@ export interface IAddItemParams {
127
127
  bundle?: any[];
128
128
  /** 商品规格信息 */
129
129
  options?: any[];
130
+ /** 日期 */
131
+ date?: {
132
+ /** 开始时间 */
133
+ startTime: string;
134
+ /** 结束时间 */
135
+ endTime: string;
136
+ };
130
137
  }
131
138
  /**
132
139
  * 更新购物车信息参数
@@ -148,6 +155,13 @@ export interface IUpdateItemParams {
148
155
  resources?: Resource[];
149
156
  /** 备注 */
150
157
  note?: string;
158
+ /** 日期 */
159
+ date?: {
160
+ /** 开始时间 */
161
+ startTime: string;
162
+ /** 结束时间 */
163
+ endTime: string;
164
+ };
151
165
  }
152
166
  /**
153
167
  * 折扣
@@ -1,8 +1,8 @@
1
- import { Account } from "../Account";
2
- import { ProductData } from "../Product/types";
3
- import { Resource } from "../Resource/types";
4
- import { CartItem, IDiscount } from "./types";
5
- import Decimal from "decimal.js";
1
+ import { Account } from '../Account';
2
+ import { ProductData } from '../Product/types';
3
+ import { Resource } from '../Resource/types';
4
+ import { CartItem, IDiscount } from './types';
5
+ import Decimal from 'decimal.js';
6
6
  /**
7
7
  * 生成一个唯一的 ID
8
8
  */
@@ -90,6 +90,30 @@ export declare const formatResourceToCartItemOrigin: (params: {
90
90
  cartItem: CartItem;
91
91
  resources: Resource[];
92
92
  }) => any;
93
+ /**
94
+ * 格式化日期到购物车
95
+ * @param date 开始时间和结束时间
96
+ * @returns 格式化后的日期
97
+ */
98
+ export declare const formatDateToCartItem: (params: {
99
+ cartItem: CartItem;
100
+ date: {
101
+ startTime: string;
102
+ endTime: string;
103
+ };
104
+ }) => CartItem;
105
+ /**
106
+ * 格式化日期到购物车原始数据
107
+ * @param date 开始时间和结束时间
108
+ * @returns 格式化后的日期原始数据
109
+ */
110
+ export declare const formatDateToCartItemOrigin: (params: {
111
+ cartItem: CartItem;
112
+ date: {
113
+ startTime: string;
114
+ endTime: string;
115
+ };
116
+ }) => any;
93
117
  /**
94
118
  * 从购物车中删除资源相关信息
95
119
  * @param cartItem 购物车
@@ -36,6 +36,8 @@ __export(utils_exports, {
36
36
  formatAccountToCartItemOrigin: () => formatAccountToCartItemOrigin,
37
37
  formatBundle: () => formatBundle,
38
38
  formatBundleToOrigin: () => formatBundleToOrigin,
39
+ formatDateToCartItem: () => formatDateToCartItem,
40
+ formatDateToCartItemOrigin: () => formatDateToCartItemOrigin,
39
41
  formatDiscountToCartItem: () => formatDiscountToCartItem,
40
42
  formatDiscountToCartItemOrigin: () => formatDiscountToCartItemOrigin,
41
43
  formatNoteToCartItem: () => formatNoteToCartItem,
@@ -112,7 +114,12 @@ var formatProductToCartItem = (params) => {
112
114
  cartItem.price = product == null ? void 0 : product.price;
113
115
  cartItem.num = num;
114
116
  cartItem.total = getProductTotalPrice({ product, bundle, options, num });
115
- cartItem.origin_total = getProductOriginTotalPrice({ product, bundle, options, num });
117
+ cartItem.origin_total = getProductOriginTotalPrice({
118
+ product,
119
+ bundle,
120
+ options,
121
+ num
122
+ });
116
123
  cartItem.image = product == null ? void 0 : product.cover;
117
124
  cartItem.like_status = "common";
118
125
  cartItem.duration = product == null ? void 0 : product.duration;
@@ -126,7 +133,13 @@ var formatProductToCartItem = (params) => {
126
133
  cartItem.options = formatOptions(options);
127
134
  }
128
135
  if (((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) == 1) {
129
- cartItem.deposit = getProductDeposit({ cartItem, product, bundle, options, num });
136
+ cartItem.deposit = getProductDeposit({
137
+ cartItem,
138
+ product,
139
+ bundle,
140
+ options,
141
+ num
142
+ });
130
143
  }
131
144
  const oringin = formatProductToCartItemOrigin(params);
132
145
  cartItem._origin = oringin;
@@ -187,7 +200,16 @@ var formatAccountToCartItemOrigin = (params) => {
187
200
  const { cartItem, account } = params;
188
201
  let origin = cartItem._origin;
189
202
  if (account) {
190
- origin.metadata.account = account;
203
+ if ((account == null ? void 0 : account.type) === "holder") {
204
+ const { customer_id, form_id, form_record_id } = (account == null ? void 0 : account._origin) || {};
205
+ origin.holder = {
206
+ customer_id,
207
+ form_id,
208
+ form_record: form_record_id ? [form_record_id] : null
209
+ };
210
+ } else {
211
+ origin.metadata.account = account;
212
+ }
191
213
  }
192
214
  return origin;
193
215
  };
@@ -265,6 +287,26 @@ var formatResourceToCartItemOrigin = (params) => {
265
287
  }
266
288
  return origin;
267
289
  };
290
+ var formatDateToCartItem = (params) => {
291
+ const { cartItem, date } = params;
292
+ cartItem.start_date = (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD");
293
+ cartItem.start_time = (0, import_dayjs.default)(date.startTime).format("HH:mm");
294
+ cartItem.end_date = (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD");
295
+ cartItem.end_time = (0, import_dayjs.default)(date.endTime).format("HH:mm");
296
+ const oringin = formatDateToCartItemOrigin(params);
297
+ cartItem._origin = oringin;
298
+ return cartItem;
299
+ };
300
+ var formatDateToCartItemOrigin = (params) => {
301
+ const { cartItem, date } = params;
302
+ const origin = cartItem._origin;
303
+ origin.select_date = (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD");
304
+ origin.start_date = (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD");
305
+ origin.start_time = (0, import_dayjs.default)(date.startTime).format("HH:mm");
306
+ origin.end_date = (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD");
307
+ origin.end_time = (0, import_dayjs.default)(date.endTime).format("HH:mm");
308
+ return origin;
309
+ };
268
310
  var deleteResourceFromCartItem = (cartItem) => {
269
311
  cartItem.resource_id = void 0;
270
312
  cartItem.relation_form_name = void 0;
@@ -464,6 +506,8 @@ var handleProductDeposit = (params) => {
464
506
  formatAccountToCartItemOrigin,
465
507
  formatBundle,
466
508
  formatBundleToOrigin,
509
+ formatDateToCartItem,
510
+ formatDateToCartItemOrigin,
467
511
  formatDiscountToCartItem,
468
512
  formatDiscountToCartItemOrigin,
469
513
  formatNoteToCartItem,
@@ -1,6 +1,6 @@
1
- import { Module, PisellCore, ModuleOptions } from "../../types";
2
- import { BaseModule } from "../BaseModule";
3
- import { DateModuleAPI, IGetAvailableTimeListParams, ITime } from "./types";
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { DateModuleAPI, IGetAvailableTimeListParams, ITime } from './types';
4
4
  export declare class DateModule extends BaseModule implements Module, DateModuleAPI {
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
@@ -13,9 +13,9 @@ export declare class DateModule extends BaseModule implements Module, DateModule
13
13
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
14
14
  setDateRange(dateRange: ITime[]): void;
15
15
  getDateRange(): ITime[];
16
- getMonthDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
- getDateList(): Promise<ITime[]>;
18
- getAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
16
+ getResourceDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
+ getDateList(): ITime[];
18
+ getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
19
19
  clearDateRange(): void;
20
20
  storeChange(): void;
21
21
  }