@pisell/pisellos 2.0.39 → 2.0.41

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 (57) hide show
  1. package/dist/modules/AccountList/index.js +17 -12
  2. package/dist/modules/Cart/index.d.ts +14 -0
  3. package/dist/modules/Cart/index.js +38 -1
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +2 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +23 -5
  6. package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
  7. package/dist/modules/Cart/utils/changePrice.js +104 -0
  8. package/dist/modules/Date/index.js +57 -6
  9. package/dist/modules/Discount/index.d.ts +1 -0
  10. package/dist/modules/Discount/index.js +13 -6
  11. package/dist/modules/Discount/types.d.ts +10 -0
  12. package/dist/modules/ProductList/index.d.ts +7 -0
  13. package/dist/modules/ProductList/index.js +102 -39
  14. package/dist/modules/Rules/index.js +194 -75
  15. package/dist/modules/Rules/types.d.ts +7 -1
  16. package/dist/modules/Schedule/index.d.ts +9 -1
  17. package/dist/modules/Schedule/index.js +122 -2
  18. package/dist/modules/Schedule/types.d.ts +13 -0
  19. package/dist/solution/BookingByStep/index.d.ts +120 -30
  20. package/dist/solution/BookingByStep/index.js +748 -1076
  21. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  22. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  23. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  24. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  25. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  26. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  27. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  28. package/dist/solution/ShopDiscount/index.js +119 -44
  29. package/lib/modules/AccountList/index.js +4 -0
  30. package/lib/modules/Cart/index.d.ts +14 -0
  31. package/lib/modules/Cart/index.js +34 -1
  32. package/lib/modules/Cart/utils/cartProduct.d.ts +2 -0
  33. package/lib/modules/Cart/utils/cartProduct.js +16 -5
  34. package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
  35. package/lib/modules/Cart/utils/changePrice.js +78 -0
  36. package/lib/modules/Date/index.js +62 -10
  37. package/lib/modules/Discount/index.d.ts +1 -0
  38. package/lib/modules/Discount/index.js +17 -6
  39. package/lib/modules/Discount/types.d.ts +10 -0
  40. package/lib/modules/ProductList/index.d.ts +7 -0
  41. package/lib/modules/ProductList/index.js +45 -0
  42. package/lib/modules/Rules/index.js +144 -63
  43. package/lib/modules/Rules/types.d.ts +7 -1
  44. package/lib/modules/Schedule/index.d.ts +9 -1
  45. package/lib/modules/Schedule/index.js +79 -1
  46. package/lib/modules/Schedule/types.d.ts +13 -0
  47. package/lib/solution/BookingByStep/index.d.ts +120 -30
  48. package/lib/solution/BookingByStep/index.js +381 -579
  49. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  50. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  51. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  52. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  53. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  54. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  55. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  56. package/lib/solution/ShopDiscount/index.js +91 -19
  57. package/package.json +1 -1
@@ -37,14 +37,20 @@ type ProductDetail = {
37
37
  options?: any[];
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
+ num?: number;
41
+ quantity: number;
40
42
  };
41
43
  export interface RulesParamsHooks {
42
44
  getProduct: (product: Record<string, any>) => ProductDetail;
43
45
  setProduct: (product: Record<string, any>, values: {
46
+ _id?: string;
44
47
  total?: number;
45
48
  discount_list: any[];
46
49
  origin_total?: number;
47
- price?: number;
50
+ price?: string | number;
51
+ variant?: any[];
52
+ original_price?: number;
53
+ quantity?: number;
48
54
  }) => Record<string, any>;
49
55
  }
50
56
  export {};
@@ -1,16 +1,24 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem } from './types';
3
+ import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem, LoadScheduleAvailableDateParams } from './types';
4
4
  export declare class ScheduleModule extends BaseModule implements Module, ScheduleModuleAPI {
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
+ private request;
7
8
  private store;
8
9
  private cacheId;
9
10
  private openCache;
10
11
  private fatherModule;
11
12
  constructor(name?: string, version?: string);
12
13
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
14
+ /**
15
+ * 加载当前店铺下所有 schedule
16
+ *
17
+ * @memberof ScheduleModule
18
+ */
19
+ loadAllSchedule(): Promise<void>;
13
20
  setScheduleList(list: ScheduleItem[]): void;
21
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
14
22
  getScheduleListByIds(ids: number[]): ScheduleItem[];
15
23
  setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
16
24
  getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Schedule/index.ts
@@ -24,6 +34,12 @@ __export(Schedule_exports, {
24
34
  module.exports = __toCommonJS(Schedule_exports);
25
35
  var import_lodash_es = require("lodash-es");
26
36
  var import_BaseModule = require("../BaseModule");
37
+ var import_dayjs = __toESM(require("dayjs"));
38
+ var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
39
+ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
40
+ var import_utils = require("../Date/utils");
41
+ import_dayjs.default.extend(import_isSameOrBefore.default);
42
+ import_dayjs.default.extend(import_isSameOrAfter.default);
27
43
  var ScheduleModule = class extends import_BaseModule.BaseModule {
28
44
  constructor(name, version) {
29
45
  super(name, version);
@@ -35,6 +51,10 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
35
51
  async initialize(core, options) {
36
52
  var _a, _b;
37
53
  this.core = core;
54
+ this.request = core.getPlugin("request");
55
+ if (!this.request) {
56
+ throw new Error("ScheduleModule 需要 request 插件支持");
57
+ }
38
58
  this.store = options == null ? void 0 : options.store;
39
59
  if (options.initialState) {
40
60
  this.store.scheduleList = options.initialState.scheduleList;
@@ -51,9 +71,67 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
51
71
  this.fatherModule = options.otherParams.fatherModule;
52
72
  }
53
73
  }
74
+ /**
75
+ * 加载当前店铺下所有 schedule
76
+ *
77
+ * @memberof ScheduleModule
78
+ */
79
+ async loadAllSchedule() {
80
+ var _a;
81
+ const scheduleList = await this.request.get(
82
+ `/schedule`,
83
+ { num: 999 },
84
+ { useCache: true }
85
+ );
86
+ this.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
87
+ }
54
88
  setScheduleList(list) {
55
89
  this.store.scheduleList = list;
56
90
  }
91
+ async loadScheduleAvailableDate({
92
+ startDate,
93
+ endDate,
94
+ custom_page_id,
95
+ channel
96
+ }) {
97
+ var _a, _b, _c;
98
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
99
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
100
+ }
101
+ let dates = (0, import_utils.generateMonthDates)(startDate, endDate);
102
+ dates = (0, import_utils.disableAllDates)(dates);
103
+ if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
104
+ return dates;
105
+ }
106
+ const res = await this.request.get(
107
+ `/schedule/product/availability/v2`,
108
+ {
109
+ start_date: startDate,
110
+ end_date: endDate,
111
+ custom_page_id,
112
+ channel
113
+ }
114
+ );
115
+ this.setAvailabilityScheduleDateList(res.data.date_list);
116
+ this.setOtherProductsIds(res.data.other_product_ids || []);
117
+ if (!((_a = res.data.date_list) == null ? void 0 : _a.length) && !((_b = res.data.other_product_ids) == null ? void 0 : _b.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
118
+ return dates;
119
+ }
120
+ if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
121
+ dates.forEach((n) => {
122
+ n.status = "available";
123
+ });
124
+ } else {
125
+ res.data.date_list.forEach((n) => {
126
+ const index = dates.findIndex((m) => m.date === n.date);
127
+ if (index !== -1) {
128
+ dates[index].status = "available";
129
+ }
130
+ });
131
+ }
132
+ dates = (0, import_utils.disableDatesBeforeOneDay)(dates);
133
+ return dates;
134
+ }
57
135
  getScheduleListByIds(ids) {
58
136
  return this.store.scheduleList.filter((n) => ids.includes(n.id));
59
137
  }
@@ -76,7 +154,7 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
76
154
  cacheId: this.cacheId,
77
155
  fatherModule: this.fatherModule,
78
156
  store,
79
- cacheKey: ["scheduleList", "availabilityDateList"]
157
+ cacheKey: ["scheduleList", "availabilityDateList", "otherProductsIds"]
80
158
  });
81
159
  }
82
160
  }
@@ -9,6 +9,19 @@ export type ScheduleAvailabilityDateItem = {
9
9
  schedule_id: number[];
10
10
  product_ids: number[];
11
11
  };
12
+ /**
13
+ * 加载日程可用日期参数接口
14
+ */
15
+ export interface LoadScheduleAvailableDateParams {
16
+ /** 开始日期 */
17
+ startDate: string;
18
+ /** 结束日期 */
19
+ endDate: string;
20
+ /** 自定义页面ID */
21
+ custom_page_id?: number;
22
+ /** 渠道 */
23
+ channel?: string;
24
+ }
12
25
  export interface ScheduleModuleAPI {
13
26
  }
14
27
  export type ScheduleItem = {
@@ -8,6 +8,7 @@ import { IStep } from '../../modules/Step/tyeps';
8
8
  import { TimeSliceItem, ResourceItem } from './utils/resources';
9
9
  import { ITime } from '../../modules/Date/types';
10
10
  import dayjs from 'dayjs';
11
+ import { LoadScheduleAvailableDateParams } from '../../modules/Schedule/types';
11
12
  import { IHolder, IFetchHolderAccountsParams } from '../../modules/AccountList/types';
12
13
  export declare class BookingByStepImpl extends BaseModule implements Module {
13
14
  protected defaultName: string;
@@ -42,26 +43,70 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
42
43
  * 更新step
43
44
  */
44
45
  updateStep(key: string, step: IStep): void;
46
+ /**
47
+ *
48
+ * 加载商品,然后导到商品列表里去
49
+ * @param {({
50
+ * category_ids?: number[];
51
+ * product_ids?: number[];
52
+ * collection?: number | string[];
53
+ * schedule_date?: string;
54
+ * })} {
55
+ * category_ids = [],
56
+ * product_ids = [],
57
+ * collection = [],
58
+ * schedule_date,
59
+ * }
60
+ * @return {*}
61
+ * @memberof BookingByStepImpl
62
+ */
45
63
  loadProducts({ category_ids, product_ids, collection, schedule_date, }: {
46
64
  category_ids?: number[];
47
65
  product_ids?: number[];
48
66
  collection?: number | string[];
49
67
  schedule_date?: string;
50
68
  }): Promise<any>;
69
+ /**
70
+ * 通过 schedule 来读取商品,适用于 session 类商品
71
+ *
72
+ * @param {{
73
+ * date: string;
74
+ * product_ids?: number[];
75
+ * category_ids?: number[];
76
+ * }} {
77
+ * date,
78
+ * product_ids = [],
79
+ * category_ids = [],
80
+ * }
81
+ * @return {*}
82
+ * @memberof BookingByStepImpl
83
+ */
51
84
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
52
85
  date: string;
53
86
  product_ids?: number[];
54
87
  category_ids?: number[];
55
88
  }): Promise<any>;
89
+ /**
90
+ * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
91
+ *
92
+ * @param {string} date
93
+ * @memberof BookingByStepImpl
94
+ */
56
95
  updateQuotationPriceAndCart(date: string): Promise<void>;
57
- loadAllSchedule(): Promise<void>;
58
- loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: {
59
- startDate: string;
60
- endDate: string;
61
- custom_page_id?: number;
62
- channel?: string;
63
- }): Promise<ITime[]>;
64
- storeProduct(productData: ProductData): Promise<void>;
96
+ /**
97
+ * ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
98
+ * 适用于先选日期的流程,确定日期是否可用
99
+ * 已知问题:如果挂接的商品的资源不可用,后端是不会计算的
100
+ *
101
+ * @param {LoadScheduleAvailableDateParams} {
102
+ * startDate,
103
+ * endDate,
104
+ * custom_page_id,
105
+ * channel,
106
+ * }
107
+ * @memberof BookingByStepImpl
108
+ */
109
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<ITime[]>;
65
110
  addAccount(account: Account | IHolder, extra?: {
66
111
  type: 'account' | 'holder';
67
112
  customerId: number;
@@ -73,7 +118,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
73
118
  getAccounts(): Promise<(Account | null)[]>;
74
119
  checkHasLoginAccount(): boolean;
75
120
  setActiveAccount(id: string): void;
76
- getActiveAccount(): Account | null;
121
+ getActiveAccount(): Account | undefined;
77
122
  removeAccount(id: string): void;
78
123
  /**
79
124
  * 获取holder类型账户列表
@@ -126,7 +171,60 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
126
171
  cover?: boolean;
127
172
  }): Promise<void>;
128
173
  getOtherParams(): Promise<Record<string, any>>;
174
+ /**
175
+ * 往购物车加商品数据(duration 类、普通商品)
176
+ * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
177
+ *
178
+ * @param {ProductData} productData
179
+ * @memberof BookingByStepImpl
180
+ */
181
+ storeProduct(productData: ProductData): Promise<void>;
182
+ /**
183
+ * 往购物车加商品数据
184
+ *
185
+ * @param {({
186
+ * product: ProductData;
187
+ * date?: { startTime: string; endTime: string } | null;
188
+ * account?: Account | null;
189
+ * })} {
190
+ * product,
191
+ * date,
192
+ * account,
193
+ * }
194
+ * @return {*}
195
+ * @memberof BookingByStepImpl
196
+ */
197
+ addProductToCart({ product, date, account, }: {
198
+ product: ProductData;
199
+ date?: {
200
+ startTime: string;
201
+ endTime: string;
202
+ } | null;
203
+ account?: Account | null;
204
+ }): void;
205
+ /**
206
+ * 添加完购物车以后做的一些检测,比如日期是否在同一天
207
+ *
208
+ * @param {({ date?: { startTime: string; endTime: string } | null })} { date }
209
+ * @memberof BookingByStepImpl
210
+ */
211
+ addProductCheck({ date, }: {
212
+ date?: {
213
+ startTime: string;
214
+ endTime: string;
215
+ } | null;
216
+ }): void;
217
+ beforeUpdateCart(params: IUpdateItemParams, targetCartItem: CartItem): void;
129
218
  updateCart(params: IUpdateItemParams): void;
219
+ /**
220
+ * 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
221
+ *
222
+ * @param {IUpdateItemParams} params
223
+ * @param {CartItem} targetCartItem
224
+ * @return {*}
225
+ * @memberof BookingByStepImpl
226
+ */
227
+ updateCartCheck(params: IUpdateItemParams, targetCartItem: CartItem): void;
130
228
  deleteCart(cartItemId: string): void;
131
229
  clearCart(): void;
132
230
  clearCartByAccount(account_id: string): void;
@@ -147,7 +245,20 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
147
245
  checkCartItems(type: ECartItemCheckType): string[];
148
246
  destroy(): void;
149
247
  getResourcesList(): any[];
248
+ /**
249
+ * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
250
+ *
251
+ * @return {*}
252
+ * @memberof BookingByStepImpl
253
+ */
150
254
  checkResourceListForDate(): boolean;
255
+ /**
256
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
257
+ *
258
+ * @param {(string | number)} id
259
+ * @return {*}
260
+ * @memberof BookingByStepImpl
261
+ */
151
262
  getResourcesListByCartItem(id: string | number): {
152
263
  id: number | undefined;
153
264
  _id: string;
@@ -156,11 +267,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
156
267
  holder_id: string | number | undefined;
157
268
  holder_name: string | undefined;
158
269
  } | undefined;
159
- getResourceTimeSlot({ product, resources, currentResourceId, }: {
160
- product: ProductData;
161
- resources: any[];
162
- currentResourceId: number;
163
- }): TimeSliceItem[];
164
270
  autoSelectAccountResources({ cartItem, holder_id, resources_code, timeSlots, countMap, capacity, }: {
165
271
  cartItem: CartItem;
166
272
  holder_id: string;
@@ -204,14 +310,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
204
310
  count: number;
205
311
  left: number;
206
312
  }[];
207
- addProductToCart({ product, date, account, }: {
208
- product: ProductData;
209
- date: {
210
- startTime: string;
211
- endTime: string;
212
- };
213
- account: Account;
214
- }): void;
215
313
  setOtherData(key: string, value: any): void;
216
314
  getOtherData(key: string): any;
217
315
  getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
@@ -235,14 +333,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
235
333
  scheduleIds?: number[];
236
334
  resources?: ProductResourceItem[];
237
335
  }): Promise<Record<string, TimeSliceItem[]>>;
238
- getAvailableDateForSession(params?: {
239
- startDate?: string;
240
- endDate?: string;
241
- type?: 'month';
242
- }): Promise<{
243
- dateList: ITime[];
244
- firstAvailableDate: ITime | undefined;
245
- }>;
246
336
  getAvailableDateForSessionOptimize(params?: {
247
337
  startDate?: string;
248
338
  endDate?: string;