@pisell/pisellos 3.0.42 → 3.0.43

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 (53) 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 +3 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +28 -8
  6. package/dist/modules/Date/index.js +70 -6
  7. package/dist/modules/Discount/index.d.ts +1 -0
  8. package/dist/modules/Discount/index.js +13 -6
  9. package/dist/modules/Discount/types.d.ts +10 -0
  10. package/dist/modules/ProductList/index.d.ts +7 -0
  11. package/dist/modules/ProductList/index.js +102 -39
  12. package/dist/modules/Rules/index.js +218 -80
  13. package/dist/modules/Rules/types.d.ts +7 -1
  14. package/dist/modules/Schedule/index.d.ts +9 -1
  15. package/dist/modules/Schedule/index.js +122 -2
  16. package/dist/modules/Schedule/types.d.ts +13 -0
  17. package/dist/solution/BookingByStep/index.d.ts +120 -30
  18. package/dist/solution/BookingByStep/index.js +753 -1076
  19. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  20. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  21. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  22. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  23. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  24. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  25. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  26. package/dist/solution/ShopDiscount/index.js +119 -44
  27. package/lib/modules/AccountList/index.js +4 -0
  28. package/lib/modules/Cart/index.d.ts +14 -0
  29. package/lib/modules/Cart/index.js +34 -1
  30. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
  31. package/lib/modules/Cart/utils/cartProduct.js +20 -8
  32. package/lib/modules/Date/index.js +59 -2
  33. package/lib/modules/Discount/index.d.ts +1 -0
  34. package/lib/modules/Discount/index.js +17 -6
  35. package/lib/modules/Discount/types.d.ts +10 -0
  36. package/lib/modules/ProductList/index.d.ts +7 -0
  37. package/lib/modules/ProductList/index.js +45 -0
  38. package/lib/modules/Rules/index.js +154 -63
  39. package/lib/modules/Rules/types.d.ts +7 -1
  40. package/lib/modules/Schedule/index.d.ts +9 -1
  41. package/lib/modules/Schedule/index.js +79 -1
  42. package/lib/modules/Schedule/types.d.ts +13 -0
  43. package/lib/solution/BookingByStep/index.d.ts +120 -30
  44. package/lib/solution/BookingByStep/index.js +391 -589
  45. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  46. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  47. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  48. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  49. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  50. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  51. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  52. package/lib/solution/ShopDiscount/index.js +91 -19
  53. package/package.json +1 -1
@@ -17,6 +17,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
17
17
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
18
  import { cloneDeep } from 'lodash-es';
19
19
  import { BaseModule } from "../BaseModule";
20
+ import dayjs from 'dayjs';
21
+ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
22
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
23
+ import { generateMonthDates, disableAllDates, disableDatesBeforeOneDay } from "../Date/utils";
24
+ dayjs.extend(isSameOrBefore);
25
+ dayjs.extend(isSameOrAfter);
20
26
  export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
21
27
  _inherits(ScheduleModule, _BaseModule);
22
28
  var _super = _createSuper(ScheduleModule);
@@ -26,6 +32,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
26
32
  _this = _super.call(this, name, version);
27
33
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'schedule');
28
34
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
35
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
29
36
  _defineProperty(_assertThisInitialized(_this), "store", {});
30
37
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
31
38
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
@@ -41,6 +48,15 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
41
48
  while (1) switch (_context.prev = _context.next) {
42
49
  case 0:
43
50
  this.core = core;
51
+
52
+ // 获取依赖的插件
53
+ this.request = core.getPlugin('request');
54
+ if (this.request) {
55
+ _context.next = 4;
56
+ break;
57
+ }
58
+ throw new Error('ScheduleModule 需要 request 插件支持');
59
+ case 4:
44
60
  // if (options?.initialState) {
45
61
  // this.state = { ...this.state, ...options.initialState }
46
62
  // }
@@ -59,7 +75,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
59
75
  if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
60
76
  this.fatherModule = options.otherParams.fatherModule;
61
77
  }
62
- case 5:
78
+ case 8:
63
79
  case "end":
64
80
  return _context.stop();
65
81
  }
@@ -70,11 +86,115 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
70
86
  }
71
87
  return initialize;
72
88
  }()
89
+ /**
90
+ * 加载当前店铺下所有 schedule
91
+ *
92
+ * @memberof ScheduleModule
93
+ */
94
+ }, {
95
+ key: "loadAllSchedule",
96
+ value: (function () {
97
+ var _loadAllSchedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
98
+ var _scheduleList$data;
99
+ var scheduleList;
100
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
101
+ while (1) switch (_context2.prev = _context2.next) {
102
+ case 0:
103
+ _context2.next = 2;
104
+ return this.request.get("/schedule", {
105
+ num: 999
106
+ }, {
107
+ useCache: true
108
+ });
109
+ case 2:
110
+ scheduleList = _context2.sent;
111
+ this.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
112
+ case 4:
113
+ case "end":
114
+ return _context2.stop();
115
+ }
116
+ }, _callee2, this);
117
+ }));
118
+ function loadAllSchedule() {
119
+ return _loadAllSchedule.apply(this, arguments);
120
+ }
121
+ return loadAllSchedule;
122
+ }())
73
123
  }, {
74
124
  key: "setScheduleList",
75
125
  value: function setScheduleList(list) {
76
126
  this.store.scheduleList = list;
77
127
  }
128
+ }, {
129
+ key: "loadScheduleAvailableDate",
130
+ value: function () {
131
+ var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
132
+ var _res$data$date_list, _res$data$other_produ, _res$data$other_produ2;
133
+ var startDate, endDate, custom_page_id, channel, dates, res;
134
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
135
+ while (1) switch (_context3.prev = _context3.next) {
136
+ case 0:
137
+ startDate = _ref.startDate, endDate = _ref.endDate, custom_page_id = _ref.custom_page_id, channel = _ref.channel;
138
+ // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
139
+ if (dayjs(startDate).isBefore(dayjs(), 'day')) {
140
+ startDate = dayjs().format('YYYY-MM-DD');
141
+ }
142
+ // 1.生成当前月份的所有日期,默认都不可用
143
+ dates = generateMonthDates(startDate, endDate);
144
+ dates = disableAllDates(dates);
145
+ // 如果 endDate 在今天之前,则不用查接口,直接返回 dates
146
+ if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
147
+ _context3.next = 6;
148
+ break;
149
+ }
150
+ return _context3.abrupt("return", dates);
151
+ case 6:
152
+ _context3.next = 8;
153
+ return this.request.get("/schedule/product/availability/v2", {
154
+ start_date: startDate,
155
+ end_date: endDate,
156
+ custom_page_id: custom_page_id,
157
+ channel: channel
158
+ });
159
+ case 8:
160
+ res = _context3.sent;
161
+ this.setAvailabilityScheduleDateList(res.data.date_list);
162
+ this.setOtherProductsIds(res.data.other_product_ids || []);
163
+ // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
164
+ if (!(!((_res$data$date_list = res.data.date_list) !== null && _res$data$date_list !== void 0 && _res$data$date_list.length) && !((_res$data$other_produ = res.data.other_product_ids) !== null && _res$data$other_produ !== void 0 && _res$data$other_produ.length) || dayjs(endDate).isBefore(dayjs(), 'day'))) {
165
+ _context3.next = 13;
166
+ break;
167
+ }
168
+ return _context3.abrupt("return", dates);
169
+ case 13:
170
+ if ((_res$data$other_produ2 = res.data.other_product_ids) !== null && _res$data$other_produ2 !== void 0 && _res$data$other_produ2.length) {
171
+ // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
172
+ dates.forEach(function (n) {
173
+ n.status = 'available';
174
+ });
175
+ } else {
176
+ res.data.date_list.forEach(function (n) {
177
+ var index = dates.findIndex(function (m) {
178
+ return m.date === n.date;
179
+ });
180
+ if (index !== -1) {
181
+ dates[index].status = 'available';
182
+ }
183
+ });
184
+ }
185
+ dates = disableDatesBeforeOneDay(dates);
186
+ return _context3.abrupt("return", dates);
187
+ case 16:
188
+ case "end":
189
+ return _context3.stop();
190
+ }
191
+ }, _callee3, this);
192
+ }));
193
+ function loadScheduleAvailableDate(_x3) {
194
+ return _loadScheduleAvailableDate.apply(this, arguments);
195
+ }
196
+ return loadScheduleAvailableDate;
197
+ }()
78
198
  }, {
79
199
  key: "getScheduleListByIds",
80
200
  value: function getScheduleListByIds(ids) {
@@ -112,7 +232,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
112
232
  cacheId: this.cacheId,
113
233
  fatherModule: this.fatherModule,
114
234
  store: store,
115
- cacheKey: ['scheduleList', 'availabilityDateList']
235
+ cacheKey: ['scheduleList', 'availabilityDateList', 'otherProductsIds']
116
236
  });
117
237
  }
118
238
  }
@@ -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类型账户列表
@@ -127,7 +172,60 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
127
172
  cover?: boolean;
128
173
  }): Promise<void>;
129
174
  getOtherParams(): Promise<Record<string, any>>;
175
+ /**
176
+ * 往购物车加商品数据(duration 类、普通商品)
177
+ * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
178
+ *
179
+ * @param {ProductData} productData
180
+ * @memberof BookingByStepImpl
181
+ */
182
+ storeProduct(productData: ProductData): Promise<void>;
183
+ /**
184
+ * 往购物车加商品数据
185
+ *
186
+ * @param {({
187
+ * product: ProductData;
188
+ * date?: { startTime: string; endTime: string } | null;
189
+ * account?: Account | null;
190
+ * })} {
191
+ * product,
192
+ * date,
193
+ * account,
194
+ * }
195
+ * @return {*}
196
+ * @memberof BookingByStepImpl
197
+ */
198
+ addProductToCart({ product, date, account, }: {
199
+ product: ProductData;
200
+ date?: {
201
+ startTime: string;
202
+ endTime: string;
203
+ } | null;
204
+ account?: Account | null;
205
+ }): void;
206
+ /**
207
+ * 添加完购物车以后做的一些检测,比如日期是否在同一天
208
+ *
209
+ * @param {({ date?: { startTime: string; endTime: string } | null })} { date }
210
+ * @memberof BookingByStepImpl
211
+ */
212
+ addProductCheck({ date, }: {
213
+ date?: {
214
+ startTime: string;
215
+ endTime: string;
216
+ } | null;
217
+ }): void;
218
+ beforeUpdateCart(params: IUpdateItemParams, targetCartItem: CartItem): void;
130
219
  updateCart(params: IUpdateItemParams): void;
220
+ /**
221
+ * 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
222
+ *
223
+ * @param {IUpdateItemParams} params
224
+ * @param {CartItem} targetCartItem
225
+ * @return {*}
226
+ * @memberof BookingByStepImpl
227
+ */
228
+ updateCartCheck(params: IUpdateItemParams, targetCartItem: CartItem): void;
131
229
  deleteCart(cartItemId: string): void;
132
230
  clearCart(): void;
133
231
  clearCartByAccount(account_id: string): void;
@@ -148,7 +246,20 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
148
246
  checkCartItems(type: ECartItemCheckType): string[];
149
247
  destroy(): void;
150
248
  getResourcesList(): any[];
249
+ /**
250
+ * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
251
+ *
252
+ * @return {*}
253
+ * @memberof BookingByStepImpl
254
+ */
151
255
  checkResourceListForDate(): boolean;
256
+ /**
257
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
258
+ *
259
+ * @param {(string | number)} id
260
+ * @return {*}
261
+ * @memberof BookingByStepImpl
262
+ */
152
263
  getResourcesListByCartItem(id: string | number): {
153
264
  id: number | undefined;
154
265
  _id: string;
@@ -157,11 +268,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
157
268
  holder_id: string | number | undefined;
158
269
  holder_name: string | undefined;
159
270
  } | undefined;
160
- getResourceTimeSlot({ product, resources, currentResourceId, }: {
161
- product: ProductData;
162
- resources: any[];
163
- currentResourceId: number;
164
- }): TimeSliceItem[];
165
271
  autoSelectAccountResources({ cartItem, holder_id, resources_code, timeSlots, countMap, capacity, }: {
166
272
  cartItem: CartItem;
167
273
  holder_id: string;
@@ -205,14 +311,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
205
311
  count: number;
206
312
  left: number;
207
313
  }[];
208
- addProductToCart({ product, date, account, }: {
209
- product: ProductData;
210
- date: {
211
- startTime: string;
212
- endTime: string;
213
- };
214
- account: Account;
215
- }): void;
216
314
  setOtherData(key: string, value: any): void;
217
315
  getOtherData(key: string): any;
218
316
  getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
@@ -236,14 +334,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
236
334
  scheduleIds?: number[];
237
335
  resources?: ProductResourceItem[];
238
336
  }): Promise<Record<string, TimeSliceItem[]>>;
239
- getAvailableDateForSession(params?: {
240
- startDate?: string;
241
- endDate?: string;
242
- type?: 'month';
243
- }): Promise<{
244
- dateList: ITime[];
245
- firstAvailableDate: ITime | undefined;
246
- }>;
247
337
  getAvailableDateForSessionOptimize(params?: {
248
338
  startDate?: string;
249
339
  endDate?: string;