@pisell/pisellos 0.10.50 → 0.10.52

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 (64) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  3. package/dist/modules/FulfillmentTiming/index.js +407 -0
  4. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  5. package/dist/modules/FulfillmentTiming/types.js +1 -0
  6. package/dist/modules/OpenData/types.d.ts +6 -0
  7. package/dist/modules/Order/index.d.ts +18 -1
  8. package/dist/modules/Order/index.js +322 -195
  9. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  10. package/dist/modules/Order/pickupTiming.js +53 -0
  11. package/dist/modules/Order/types.d.ts +11 -1
  12. package/dist/modules/Order/utils.d.ts +10 -0
  13. package/dist/modules/Order/utils.js +145 -85
  14. package/dist/modules/Rules/index.js +3 -2
  15. package/dist/modules/Schedule/index.d.ts +8 -0
  16. package/dist/modules/Schedule/index.js +134 -37
  17. package/dist/modules/index.d.ts +1 -0
  18. package/dist/modules/index.js +1 -0
  19. package/dist/server/modules/order/index.d.ts +8 -0
  20. package/dist/server/modules/order/index.js +506 -453
  21. package/dist/server/modules/order/types.d.ts +1 -0
  22. package/dist/server/utils/small-ticket.js +165 -94
  23. package/dist/solution/BaseSales/index.d.ts +24 -0
  24. package/dist/solution/BaseSales/index.js +1231 -1037
  25. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  26. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  27. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  28. package/dist/solution/BookingByStep/index.d.ts +1 -1
  29. package/dist/solution/BookingTicket/index.d.ts +2 -2
  30. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  31. package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
  32. package/dist/solution/UnifiedBookingSales/index.js +873 -708
  33. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  34. package/lib/modules/FulfillmentTiming/index.js +359 -0
  35. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  36. package/lib/modules/FulfillmentTiming/types.js +5 -0
  37. package/lib/modules/OpenData/types.d.ts +6 -0
  38. package/lib/modules/Order/index.d.ts +18 -1
  39. package/lib/modules/Order/index.js +101 -3
  40. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  41. package/lib/modules/Order/pickupTiming.js +61 -0
  42. package/lib/modules/Order/types.d.ts +11 -1
  43. package/lib/modules/Order/utils.d.ts +10 -0
  44. package/lib/modules/Order/utils.js +58 -4
  45. package/lib/modules/Rules/index.js +3 -2
  46. package/lib/modules/Schedule/index.d.ts +8 -0
  47. package/lib/modules/Schedule/index.js +64 -11
  48. package/lib/modules/index.d.ts +1 -0
  49. package/lib/modules/index.js +11 -0
  50. package/lib/server/modules/order/index.d.ts +8 -0
  51. package/lib/server/modules/order/index.js +19 -0
  52. package/lib/server/modules/order/types.d.ts +1 -0
  53. package/lib/server/utils/small-ticket.js +86 -22
  54. package/lib/solution/BaseSales/index.d.ts +24 -0
  55. package/lib/solution/BaseSales/index.js +109 -1
  56. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  57. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  58. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  59. package/lib/solution/BookingByStep/index.d.ts +1 -1
  60. package/lib/solution/BookingTicket/index.d.ts +2 -2
  61. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  62. package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
  63. package/lib/solution/UnifiedBookingSales/index.js +130 -46
  64. package/package.json +1 -1
@@ -10,6 +10,8 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
10
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
12
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
14
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
13
15
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
16
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
15
17
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -45,32 +47,37 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
45
47
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
46
48
  _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
47
49
  _defineProperty(_assertThisInitialized(_this), "hasLoadedScheduleList", false);
50
+ _defineProperty(_assertThisInitialized(_this), "scheduleListPromise", null);
51
+ _defineProperty(_assertThisInitialized(_this), "scheduleListRequestVersion", 0);
52
+ _defineProperty(_assertThisInitialized(_this), "scheduleCatalogScope", '');
53
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
48
54
  return _this;
49
55
  }
50
56
  _createClass(ScheduleModule, [{
51
57
  key: "initialize",
52
58
  value: function () {
53
59
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
54
- var _options$otherParams, _options$otherParams2;
55
60
  return _regeneratorRuntime().wrap(function _callee$(_context) {
56
61
  while (1) switch (_context.prev = _context.next) {
57
62
  case 0:
63
+ this.resetScheduleCatalog();
58
64
  this.core = core;
59
65
 
60
66
  // 获取依赖的插件
61
67
  this.request = core.getPlugin('request');
62
68
  if (this.request) {
63
- _context.next = 4;
69
+ _context.next = 5;
64
70
  break;
65
71
  }
66
72
  throw new Error('ScheduleModule 需要 request 插件支持');
67
- case 4:
73
+ case 5:
68
74
  // if (options?.initialState) {
69
75
  // this.state = { ...this.state, ...options.initialState }
70
76
  // }
71
77
  this.store = options === null || options === void 0 ? void 0 : options.store;
78
+ this.updateOtherParams(options.otherParams || {});
72
79
  if (options.initialState) {
73
- this.store.scheduleList = options.initialState.scheduleList;
80
+ this.store.scheduleList = options.initialState.scheduleList || [];
74
81
  this.syncScheduleMap();
75
82
  this.store.availabilityDateList = options.initialState.availabilityDateList;
76
83
  this.hasLoadedScheduleList = Array.isArray(options.initialState.scheduleList);
@@ -80,13 +87,6 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
80
87
  this.store.availabilityDateList = [];
81
88
  this.hasLoadedScheduleList = false;
82
89
  }
83
- if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
84
- this.openCache = options.otherParams.openCache;
85
- this.cacheId = options.otherParams.cacheId;
86
- }
87
- if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
88
- this.fatherModule = options.otherParams.fatherModule;
89
- }
90
90
  case 8:
91
91
  case "end":
92
92
  return _context.stop();
@@ -109,9 +109,41 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
109
109
  value: function updateOtherParams(params) {
110
110
  var _otherParams$openCach;
111
111
  var otherParams = params || {};
112
+ this.otherParams = _objectSpread({}, otherParams);
112
113
  this.openCache = (_otherParams$openCach = otherParams.openCache) !== null && _otherParams$openCach !== void 0 ? _otherParams$openCach : false;
113
114
  this.cacheId = otherParams.cacheId;
114
115
  this.fatherModule = otherParams.fatherModule;
116
+ this.syncScheduleCatalogScope();
117
+ }
118
+ }, {
119
+ key: "syncScheduleCatalogScope",
120
+ value: function syncScheduleCatalogScope() {
121
+ var _this$core, _params$businessCode;
122
+ var context = (_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.context;
123
+ var shopId = typeof (context === null || context === void 0 ? void 0 : context.getData) === 'function' ? context.getData('shop_id') : context === null || context === void 0 ? void 0 : context.shop_id;
124
+ var params = this.otherParams;
125
+ var scope = JSON.stringify([this.cacheId, this.fatherModule, (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : params.business_code, params.channel, params.platform, params.businessTimezone, shopId].map(function (value) {
126
+ return String(value !== null && value !== void 0 ? value : '').trim();
127
+ }));
128
+ if (scope !== this.scheduleCatalogScope) {
129
+ this.resetScheduleCatalog();
130
+ this.scheduleCatalogScope = scope;
131
+ }
132
+ }
133
+ }, {
134
+ key: "resetScheduleCatalog",
135
+ value: function resetScheduleCatalog() {
136
+ this.scheduleListRequestVersion += 1;
137
+ this.scheduleListPromise = null;
138
+ this.hasLoadedScheduleList = false;
139
+ this.store.scheduleList = [];
140
+ this.store.map = new Map();
141
+ }
142
+ }, {
143
+ key: "destroy",
144
+ value: function destroy() {
145
+ this.resetScheduleCatalog();
146
+ _get(_getPrototypeOf(ScheduleModule.prototype), "destroy", this).call(this);
115
147
  }
116
148
 
117
149
  /**
@@ -123,37 +155,99 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
123
155
  key: "loadAllSchedule",
124
156
  value: (function () {
125
157
  var _loadAllSchedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
126
- var _options$useCache, _scheduleList$data;
158
+ var _options$useCache;
127
159
  var options,
128
- scheduleList,
160
+ useCache,
161
+ requestVersion,
162
+ promise,
129
163
  _args2 = arguments;
130
164
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
131
165
  while (1) switch (_context2.prev = _context2.next) {
132
166
  case 0:
133
167
  options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
134
- _context2.next = 3;
135
- return this.request.get("/schedule", {
136
- num: 999
137
- }, {
138
- useCache: (_options$useCache = options.useCache) !== null && _options$useCache !== void 0 ? _options$useCache : true
139
- });
140
- case 3:
141
- scheduleList = _context2.sent;
142
- this.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
143
- case 5:
168
+ this.syncScheduleCatalogScope();
169
+ useCache = (_options$useCache = options.useCache) !== null && _options$useCache !== void 0 ? _options$useCache : true;
170
+ if (!useCache) {
171
+ _context2.next = 8;
172
+ break;
173
+ }
174
+ if (!this.scheduleListPromise) {
175
+ _context2.next = 6;
176
+ break;
177
+ }
178
+ return _context2.abrupt("return", this.scheduleListPromise);
179
+ case 6:
180
+ if (!this.hasLoadedScheduleList) {
181
+ _context2.next = 8;
182
+ break;
183
+ }
184
+ return _context2.abrupt("return");
185
+ case 8:
186
+ requestVersion = ++this.scheduleListRequestVersion;
187
+ promise = this.loadScheduleCatalog(useCache, requestVersion);
188
+ this.scheduleListPromise = promise;
189
+ _context2.prev = 11;
190
+ _context2.next = 14;
191
+ return promise;
192
+ case 14:
193
+ _context2.prev = 14;
194
+ if (this.scheduleListPromise === promise) {
195
+ this.scheduleListPromise = null;
196
+ }
197
+ return _context2.finish(14);
198
+ case 17:
144
199
  case "end":
145
200
  return _context2.stop();
146
201
  }
147
- }, _callee2, this);
202
+ }, _callee2, this, [[11,, 14, 17]]);
148
203
  }));
149
204
  function loadAllSchedule() {
150
205
  return _loadAllSchedule.apply(this, arguments);
151
206
  }
152
207
  return loadAllSchedule;
153
208
  }())
209
+ }, {
210
+ key: "loadScheduleCatalog",
211
+ value: function () {
212
+ var _loadScheduleCatalog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(useCache, requestVersion) {
213
+ var response, _response$data;
214
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
215
+ while (1) switch (_context3.prev = _context3.next) {
216
+ case 0:
217
+ _context3.next = 2;
218
+ return this.request.get("/schedule", {
219
+ num: 999
220
+ }, {
221
+ useCache: useCache
222
+ });
223
+ case 2:
224
+ response = _context3.sent;
225
+ if (!(response.code !== undefined && Number(response.code) !== 200 || response.status === false || typeof response.status === 'number' && response.status >= 400 || response.success === false)) {
226
+ _context3.next = 5;
227
+ break;
228
+ }
229
+ throw new Error(response.message || 'Schedule catalog request failed');
230
+ case 5:
231
+ this.syncScheduleCatalogScope();
232
+ // A refresh or a different runtime may have superseded this request.
233
+ if (requestVersion === this.scheduleListRequestVersion) {
234
+ this.setScheduleList(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || []);
235
+ }
236
+ case 7:
237
+ case "end":
238
+ return _context3.stop();
239
+ }
240
+ }, _callee3, this);
241
+ }));
242
+ function loadScheduleCatalog(_x3, _x4) {
243
+ return _loadScheduleCatalog.apply(this, arguments);
244
+ }
245
+ return loadScheduleCatalog;
246
+ }()
154
247
  }, {
155
248
  key: "setScheduleList",
156
249
  value: function setScheduleList(list) {
250
+ this.syncScheduleCatalogScope();
157
251
  this.store.scheduleList = list;
158
252
  this.syncScheduleMap();
159
253
  this.hasLoadedScheduleList = true;
@@ -168,20 +262,22 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
168
262
  }, {
169
263
  key: "getScheduleList",
170
264
  value: function getScheduleList() {
265
+ this.syncScheduleCatalogScope();
171
266
  return this.store.scheduleList || [];
172
267
  }
173
268
  }, {
174
269
  key: "isScheduleListLoaded",
175
270
  value: function isScheduleListLoaded() {
271
+ this.syncScheduleCatalogScope();
176
272
  return this.hasLoadedScheduleList;
177
273
  }
178
274
  }, {
179
275
  key: "loadScheduleAvailableDate",
180
276
  value: function () {
181
- var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
277
+ var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
182
278
  var startDate, endDate, custom_page_id, channel, dates, res, responseData, dateList, otherProductIds;
183
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
184
- while (1) switch (_context3.prev = _context3.next) {
279
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
280
+ while (1) switch (_context4.prev = _context4.next) {
185
281
  case 0:
186
282
  startDate = _ref.startDate, endDate = _ref.endDate, custom_page_id = _ref.custom_page_id, channel = _ref.channel;
187
283
  // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
@@ -193,12 +289,12 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
193
289
  dates = disableAllDates(dates);
194
290
  // 如果 endDate 在今天之前,则不用查接口,直接返回 dates
195
291
  if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
196
- _context3.next = 6;
292
+ _context4.next = 6;
197
293
  break;
198
294
  }
199
- return _context3.abrupt("return", dates);
295
+ return _context4.abrupt("return", dates);
200
296
  case 6:
201
- _context3.next = 8;
297
+ _context4.next = 8;
202
298
  return this.request.get("/schedule/product/availability/v2", {
203
299
  start_date: startDate,
204
300
  end_date: endDate,
@@ -206,7 +302,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
206
302
  channel: channel
207
303
  });
208
304
  case 8:
209
- res = _context3.sent;
305
+ res = _context4.sent;
210
306
  responseData = res.data || {};
211
307
  dateList = Array.isArray(responseData.date_list) ? responseData.date_list : [];
212
308
  otherProductIds = Array.isArray(responseData.other_product_ids) ? responseData.other_product_ids : [];
@@ -214,10 +310,10 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
214
310
  this.setOtherProductsIds(otherProductIds);
215
311
  // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
216
312
  if (!(!dateList.length && !otherProductIds.length || dayjs(endDate).isBefore(dayjs(), 'day'))) {
217
- _context3.next = 16;
313
+ _context4.next = 16;
218
314
  break;
219
315
  }
220
- return _context3.abrupt("return", dates);
316
+ return _context4.abrupt("return", dates);
221
317
  case 16:
222
318
  if (otherProductIds.length) {
223
319
  // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
@@ -235,14 +331,14 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
235
331
  });
236
332
  }
237
333
  dates = disableDatesBeforeOneDay(dates);
238
- return _context3.abrupt("return", dates);
334
+ return _context4.abrupt("return", dates);
239
335
  case 19:
240
336
  case "end":
241
- return _context3.stop();
337
+ return _context4.stop();
242
338
  }
243
- }, _callee3, this);
339
+ }, _callee4, this);
244
340
  }));
245
- function loadScheduleAvailableDate(_x3) {
341
+ function loadScheduleAvailableDate(_x5) {
246
342
  return _loadScheduleAvailableDate.apply(this, arguments);
247
343
  }
248
344
  return loadScheduleAvailableDate;
@@ -252,6 +348,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
252
348
  value: function getScheduleListByIds(ids) {
253
349
  var _this2 = this,
254
350
  _this$store$scheduleL;
351
+ this.syncScheduleCatalogScope();
255
352
  var idSet = new Set(ids.map(function (id) {
256
353
  return String(id);
257
354
  }));
@@ -17,6 +17,7 @@ export * from './Schedule';
17
17
  export * from './Quotation';
18
18
  export * from './ScanOrderLogger';
19
19
  export * from './OpenData';
20
+ export * from './FulfillmentTiming';
20
21
  export * from './BookingContext';
21
22
  export * from './Holder';
22
23
  export * from './ResourcePlanner';
@@ -17,6 +17,7 @@ export * from "./Schedule";
17
17
  export * from "./Quotation";
18
18
  export * from "./ScanOrderLogger";
19
19
  export * from "./OpenData";
20
+ export * from "./FulfillmentTiming";
20
21
  export * from "./BookingContext";
21
22
  export * from "./Holder";
22
23
  export * from "./ResourcePlanner";
@@ -24,6 +24,7 @@ export declare class OrderModule extends BaseModule implements Module {
24
24
  private lastRecentSqliteWriteCleanupAtMs;
25
25
  /** 最近一次 SSE 全量拉取完成时间 */
26
26
  private lastServerFullFetchAtMs;
27
+ private businessDayRefreshPromise;
27
28
  constructor(name?: string, version?: string);
28
29
  /**
29
30
  * 广播订单变更事件,兼容全量列表订阅并额外携带本次变更订单。
@@ -130,6 +131,13 @@ export declare class OrderModule extends BaseModule implements Module {
130
131
  loadOrdersByServer(options?: {
131
132
  trigger?: string;
132
133
  }): Promise<OrderData[]>;
134
+ /**
135
+ * 供展示屏按需补齐当前营业日的订单快照;成功标记复用全量拉取落库逻辑。
136
+ * 拉取或落库失败时不记录已刷新,下一次调用仍可重试。
137
+ */
138
+ refreshOrdersForCurrentBusinessDay(options?: {
139
+ trigger?: string;
140
+ }): Promise<void>;
133
141
  /**
134
142
  * 静默全量刷新:后台重新拉取全量 SSE 订单数据并更新本地
135
143
  * 拿到完整数据后一次性替换 store,触发订单变更与同步完成事件