@pisell/pisellos 3.0.89 → 3.0.91

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 (242) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +7 -0
  6. package/dist/model/strategy/adapter/index.js +7 -0
  7. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  8. package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
  9. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  10. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  11. package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  12. package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
  13. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  14. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  15. package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
  16. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  17. package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  18. package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
  19. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  20. package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
  21. package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
  22. package/dist/model/strategy/adapter/promotion/examples.js +166 -0
  23. package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
  24. package/dist/model/strategy/adapter/promotion/index.js +0 -0
  25. package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
  26. package/dist/model/strategy/adapter/promotion/type.js +209 -0
  27. package/dist/model/strategy/adapter/type.d.ts +28 -0
  28. package/dist/model/strategy/adapter/type.js +1 -0
  29. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  30. package/dist/model/strategy/adapter/walletPass/evaluator.js +502 -0
  31. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  32. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  33. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  34. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  35. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  36. package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
  37. package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -0
  38. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  39. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  40. package/dist/model/strategy/adapter/walletPass/utils.js +1104 -0
  41. package/dist/model/strategy/engine.d.ts +106 -0
  42. package/dist/model/strategy/engine.js +611 -0
  43. package/dist/model/strategy/index.d.ts +3 -0
  44. package/dist/model/strategy/index.js +8 -0
  45. package/dist/model/strategy/strategy-example.d.ts +5 -0
  46. package/dist/model/strategy/strategy-example.js +331 -0
  47. package/dist/model/strategy/type.d.ts +228 -0
  48. package/dist/model/strategy/type.js +94 -0
  49. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  50. package/dist/modules/Discount/index.d.ts +4 -2
  51. package/dist/modules/Discount/index.js +90 -3
  52. package/dist/modules/Discount/types.d.ts +6 -0
  53. package/dist/modules/OpenData/index.d.ts +24 -0
  54. package/dist/modules/OpenData/index.js +173 -0
  55. package/dist/modules/OpenData/types.d.ts +73 -0
  56. package/dist/modules/OpenData/types.js +1 -0
  57. package/dist/modules/OpenData/utils.d.ts +2 -0
  58. package/dist/modules/OpenData/utils.js +75 -0
  59. package/dist/modules/Order/index.d.ts +66 -1
  60. package/dist/modules/Order/index.js +884 -10
  61. package/dist/modules/Order/types.d.ts +174 -12
  62. package/dist/modules/Order/types.js +2 -0
  63. package/dist/modules/Order/utils.d.ts +118 -0
  64. package/dist/modules/Order/utils.js +586 -2
  65. package/dist/modules/Product/utils.js +2 -2
  66. package/dist/modules/ProductList/index.d.ts +3 -1
  67. package/dist/modules/ProductList/index.js +19 -11
  68. package/dist/modules/Quotation/index.d.ts +48 -0
  69. package/dist/modules/Quotation/index.js +248 -0
  70. package/dist/modules/Quotation/types.d.ts +42 -0
  71. package/dist/modules/Quotation/types.js +1 -0
  72. package/dist/modules/Rules/index.js +17 -18
  73. package/dist/modules/SalesSummary/index.d.ts +63 -0
  74. package/dist/modules/SalesSummary/index.js +174 -0
  75. package/dist/modules/SalesSummary/types.d.ts +60 -0
  76. package/dist/modules/SalesSummary/types.js +1 -0
  77. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  78. package/dist/modules/SalesSummary/utils.js +480 -0
  79. package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
  80. package/dist/modules/ScanOrderLogger/index.js +174 -0
  81. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  82. package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
  83. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  84. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  85. package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
  86. package/dist/modules/ScanOrderLogger/types.js +1 -0
  87. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  88. package/dist/modules/Schedule/utils.d.ts +1 -1
  89. package/dist/modules/Summary/utils.d.ts +3 -3
  90. package/dist/modules/Summary/utils.js +41 -31
  91. package/dist/modules/index.d.ts +4 -0
  92. package/dist/modules/index.js +5 -1
  93. package/dist/solution/BookingByStep/index.d.ts +3 -3
  94. package/dist/solution/BookingByStep/index.js +2 -1
  95. package/dist/solution/BookingByStep/types.d.ts +3 -1
  96. package/dist/solution/BookingByStep/types.js +5 -1
  97. package/dist/solution/ScanOrder/index.d.ts +158 -0
  98. package/dist/solution/ScanOrder/index.js +3474 -0
  99. package/dist/solution/ScanOrder/types.d.ts +306 -0
  100. package/dist/solution/ScanOrder/types.js +35 -0
  101. package/dist/solution/ScanOrder/utils.d.ts +172 -0
  102. package/dist/solution/ScanOrder/utils.js +796 -0
  103. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  104. package/dist/solution/ShopDiscount/index.js +23 -18
  105. package/dist/solution/VenueBooking/index.d.ts +201 -0
  106. package/dist/solution/VenueBooking/index.js +3472 -0
  107. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  108. package/dist/solution/VenueBooking/types.d.ts +154 -0
  109. package/dist/solution/VenueBooking/types.js +21 -0
  110. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  111. package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
  112. package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
  113. package/dist/solution/VenueBooking/utils/resource.js +131 -0
  114. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  115. package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
  116. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  117. package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
  118. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  119. package/dist/solution/VenueBooking/utils.js +1 -0
  120. package/dist/solution/index.d.ts +2 -0
  121. package/dist/solution/index.js +3 -1
  122. package/lib/apis/picoding.d.ts +0 -0
  123. package/lib/apis/picoding.js +0 -0
  124. package/lib/model/index.d.ts +1 -0
  125. package/lib/model/index.js +23 -0
  126. package/lib/model/strategy/adapter/index.d.ts +7 -0
  127. package/lib/model/strategy/adapter/index.js +57 -0
  128. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  129. package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
  130. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  131. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  132. package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  133. package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
  134. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  135. package/lib/model/strategy/adapter/itemRule/index.js +60 -0
  136. package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
  137. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  138. package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  139. package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
  140. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  141. package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
  142. package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
  143. package/lib/model/strategy/adapter/promotion/examples.js +192 -0
  144. package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
  145. package/lib/model/strategy/adapter/promotion/index.js +0 -0
  146. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  147. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  148. package/lib/model/strategy/adapter/type.d.ts +28 -0
  149. package/lib/model/strategy/adapter/type.js +17 -0
  150. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  151. package/lib/model/strategy/adapter/walletPass/evaluator.js +424 -0
  152. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  153. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  154. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  155. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  156. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  157. package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
  158. package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
  159. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  160. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  161. package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
  162. package/lib/model/strategy/engine.d.ts +106 -0
  163. package/lib/model/strategy/engine.js +450 -0
  164. package/lib/model/strategy/index.d.ts +3 -0
  165. package/lib/model/strategy/index.js +38 -0
  166. package/lib/model/strategy/strategy-example.d.ts +5 -0
  167. package/lib/model/strategy/strategy-example.js +318 -0
  168. package/lib/model/strategy/type.d.ts +228 -0
  169. package/lib/model/strategy/type.js +44 -0
  170. package/lib/modules/Cart/utils/cartProduct.js +1 -0
  171. package/lib/modules/Discount/index.d.ts +4 -2
  172. package/lib/modules/Discount/index.js +60 -2
  173. package/lib/modules/Discount/types.d.ts +6 -0
  174. package/lib/modules/OpenData/index.d.ts +24 -0
  175. package/lib/modules/OpenData/index.js +119 -0
  176. package/lib/modules/OpenData/types.d.ts +73 -0
  177. package/lib/modules/OpenData/types.js +17 -0
  178. package/lib/modules/OpenData/utils.d.ts +2 -0
  179. package/lib/modules/OpenData/utils.js +111 -0
  180. package/lib/modules/Order/index.d.ts +66 -1
  181. package/lib/modules/Order/index.js +525 -0
  182. package/lib/modules/Order/types.d.ts +174 -12
  183. package/lib/modules/Order/utils.d.ts +118 -0
  184. package/lib/modules/Order/utils.js +483 -2
  185. package/lib/modules/Product/utils.js +2 -2
  186. package/lib/modules/ProductList/index.d.ts +3 -1
  187. package/lib/modules/ProductList/index.js +45 -34
  188. package/lib/modules/Quotation/index.d.ts +48 -0
  189. package/lib/modules/Quotation/index.js +152 -0
  190. package/lib/modules/Quotation/types.d.ts +42 -0
  191. package/lib/modules/Quotation/types.js +17 -0
  192. package/lib/modules/Rules/index.js +17 -18
  193. package/lib/modules/SalesSummary/index.d.ts +63 -0
  194. package/lib/modules/SalesSummary/index.js +105 -0
  195. package/lib/modules/SalesSummary/types.d.ts +60 -0
  196. package/lib/modules/SalesSummary/types.js +17 -0
  197. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  198. package/lib/modules/SalesSummary/utils.js +420 -0
  199. package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
  200. package/lib/modules/ScanOrderLogger/index.js +147 -0
  201. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  202. package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
  203. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  204. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  205. package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
  206. package/lib/modules/ScanOrderLogger/types.js +17 -0
  207. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  208. package/lib/modules/Schedule/utils.d.ts +1 -1
  209. package/lib/modules/Summary/utils.d.ts +3 -3
  210. package/lib/modules/Summary/utils.js +22 -16
  211. package/lib/modules/index.d.ts +4 -0
  212. package/lib/modules/index.js +9 -1
  213. package/lib/solution/BookingByStep/index.d.ts +3 -3
  214. package/lib/solution/BookingByStep/index.js +2 -2
  215. package/lib/solution/BookingByStep/types.d.ts +3 -1
  216. package/lib/solution/BookingByStep/types.js +10 -0
  217. package/lib/solution/ScanOrder/index.d.ts +158 -0
  218. package/lib/solution/ScanOrder/index.js +2135 -0
  219. package/lib/solution/ScanOrder/types.d.ts +306 -0
  220. package/lib/solution/ScanOrder/types.js +36 -0
  221. package/lib/solution/ScanOrder/utils.d.ts +172 -0
  222. package/lib/solution/ScanOrder/utils.js +658 -0
  223. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  224. package/lib/solution/ShopDiscount/index.js +4 -2
  225. package/lib/solution/VenueBooking/index.d.ts +201 -0
  226. package/lib/solution/VenueBooking/index.js +1937 -0
  227. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  228. package/lib/solution/VenueBooking/types.d.ts +154 -0
  229. package/lib/solution/VenueBooking/types.js +44 -0
  230. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  231. package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
  232. package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
  233. package/lib/solution/VenueBooking/utils/resource.js +92 -0
  234. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  235. package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
  236. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  237. package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
  238. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  239. package/lib/solution/VenueBooking/utils.js +69 -0
  240. package/lib/solution/index.d.ts +2 -0
  241. package/lib/solution/index.js +5 -1
  242. package/package.json +1 -1
@@ -1,4 +1,6 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
6
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -177,7 +179,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
177
179
  key: "batchSearch",
178
180
  value: function () {
179
181
  var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
180
- var result, resultDiscountList;
182
+ var result, resultDiscountWithReason;
181
183
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
182
184
  while (1) switch (_context5.prev = _context5.next) {
183
185
  case 0:
@@ -195,8 +197,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
195
197
  });
196
198
  case 2:
197
199
  result = _context5.sent;
198
- resultDiscountList = this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || [];
199
- return _context5.abrupt("return", resultDiscountList);
200
+ resultDiscountWithReason = this.filterEnabledDiscountListWithReason((result === null || result === void 0 ? void 0 : result.data) || []) || [];
201
+ return _context5.abrupt("return", resultDiscountWithReason);
200
202
  case 5:
201
203
  case "end":
202
204
  return _context5.stop();
@@ -276,6 +278,91 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
276
278
  return true;
277
279
  }
278
280
 
281
+ // 过滤启用且可用的优惠券,并返回校验失败原因
282
+ }, {
283
+ key: "filterEnabledDiscountListWithReason",
284
+ value: function filterEnabledDiscountListWithReason(discountList) {
285
+ var _this3 = this;
286
+ var lists = discountList.filter(function (discount) {
287
+ return discount.limit_status === 'enable';
288
+ }).filter(function (discount) {
289
+ var remaining = new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
290
+ return remaining;
291
+ }).map(function (discount) {
292
+ var limitFailKey = _this3.checkUsageCreditsLimitWithFailKey(discount);
293
+ return _objectSpread(_objectSpread({}, discount), {}, {
294
+ usageLimitFailKey: limitFailKey
295
+ });
296
+ });
297
+
298
+ // 可用的列表
299
+ var availableLists = lists.filter(function (item) {
300
+ return !item.usageLimitFailKey;
301
+ });
302
+ // 不可用数据
303
+ var currentFailDiscount = lists.find(function (item) {
304
+ return item.usageLimitFailKey;
305
+ });
306
+ return {
307
+ discountList: availableLists,
308
+ unavailableReasonKey: currentFailDiscount === null || currentFailDiscount === void 0 ? void 0 : currentFailDiscount.usageLimitFailKey
309
+ };
310
+ }
311
+
312
+ // 检查使用次数限制,并返回校验失败原因
313
+ }, {
314
+ key: "checkUsageCreditsLimitWithFailKey",
315
+ value: function checkUsageCreditsLimitWithFailKey(discount) {
316
+ if (!discount.extension_data || discount.extension_data.length === 0) {
317
+ return null;
318
+ }
319
+ var usageCreditsData = discount.extension_data.find(function (data) {
320
+ return data.field_key === 'usage_credits';
321
+ });
322
+ if (!usageCreditsData) {
323
+ return null;
324
+ }
325
+ var value = usageCreditsData.value;
326
+
327
+ // 总次数限制
328
+ if (value.total_credits && value.total_credits > 0) {
329
+ if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
330
+ return 'total_credits';
331
+ }
332
+ }
333
+
334
+ // 单用户限制
335
+ if (value.per_user_limit && value.per_user_limit > 0) {
336
+ if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
337
+ return 'per_user_limit';
338
+ }
339
+ }
340
+
341
+ // 单日限制
342
+ if (value.max_per_day && value.max_per_day > 0) {
343
+ if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
344
+ return 'max_per_day';
345
+ }
346
+ }
347
+
348
+ // 单周限制
349
+ if (value.max_per_week && value.max_per_week > 0) {
350
+ if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
351
+ return 'max_per_week';
352
+ }
353
+ }
354
+
355
+ // 单月限制
356
+ if (value.max_per_month && value.max_per_month > 0) {
357
+ if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
358
+ return 'max_per_month';
359
+ }
360
+ }
361
+
362
+ // 全部通过
363
+ return null;
364
+ }
365
+
279
366
  // 根据productIds去重
280
367
  }, {
281
368
  key: "uniqueByProductId",
@@ -61,6 +61,11 @@ interface UsageCreditsValue {
61
61
  max_per_week: number;
62
62
  max_per_month: number;
63
63
  }
64
+ export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
65
+ export interface DiscountWithReason {
66
+ discountList: Discount[];
67
+ unavailableReasonKey: DiscountFilterRejectKey | null;
68
+ }
64
69
  interface ExtensionData {
65
70
  id: number;
66
71
  shop_id: number;
@@ -130,6 +135,7 @@ export interface Discount {
130
135
  num?: number;
131
136
  start_date?: string;
132
137
  start_time?: string;
138
+ usageLimitFailKey?: string | null;
133
139
  }
134
140
  export interface DiscountState {
135
141
  discountList: Discount[];
@@ -0,0 +1,24 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import type { ScheduleModule } from '../Schedule';
4
+ import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult } from './types';
5
+ export * from './types';
6
+ export { computeAvailability } from './utils';
7
+ export declare class OpenDataModule extends BaseModule implements Module {
8
+ protected defaultName: string;
9
+ protected defaultVersion: string;
10
+ private request;
11
+ private window;
12
+ private store;
13
+ private cacheId;
14
+ private openCache;
15
+ private fatherModule;
16
+ private otherParams;
17
+ constructor(name?: string, version?: string);
18
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
19
+ fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
20
+ getOpenData(): OpenDataConfig | null;
21
+ getLastFetchedAt(): number | null;
22
+ checkAvailability(scheduleModule?: ScheduleModule): OpenDataAvailabilityResult;
23
+ storeChange(): void;
24
+ }
@@ -0,0 +1,173 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ 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); }
9
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10
+ 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); }; }
11
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
12
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
13
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
+ import { BaseModule } from "../BaseModule";
19
+ import { computeAvailability } from "./utils";
20
+ export * from "./types";
21
+ export { computeAvailability } from "./utils";
22
+ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
23
+ _inherits(OpenDataModule, _BaseModule);
24
+ var _super = _createSuper(OpenDataModule);
25
+ function OpenDataModule(name, version) {
26
+ var _this;
27
+ _classCallCheck(this, OpenDataModule);
28
+ _this = _super.call(this, name, version);
29
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'openData');
30
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
31
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
35
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
36
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
37
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
38
+ return _this;
39
+ }
40
+ _createClass(OpenDataModule, [{
41
+ key: "initialize",
42
+ value: function () {
43
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
44
+ var _options$initialState, _options$initialState2, _options$initialState3, _options$initialState4;
45
+ var _this$otherParams$ope;
46
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
47
+ while (1) switch (_context.prev = _context.next) {
48
+ case 0:
49
+ this.core = core;
50
+ this.store = options.store;
51
+ this.store.data = (_options$initialState = (_options$initialState2 = options.initialState) === null || _options$initialState2 === void 0 ? void 0 : _options$initialState2.data) !== null && _options$initialState !== void 0 ? _options$initialState : null;
52
+ this.store.lastFetchedAt = (_options$initialState3 = (_options$initialState4 = options.initialState) === null || _options$initialState4 === void 0 ? void 0 : _options$initialState4.lastFetchedAt) !== null && _options$initialState3 !== void 0 ? _options$initialState3 : null;
53
+ this.otherParams = options.otherParams || {};
54
+ if (this.otherParams.cacheId) {
55
+ this.openCache = (_this$otherParams$ope = this.otherParams.openCache) !== null && _this$otherParams$ope !== void 0 ? _this$otherParams$ope : false;
56
+ this.cacheId = this.otherParams.cacheId;
57
+ }
58
+ if (this.otherParams.fatherModule) {
59
+ this.fatherModule = this.otherParams.fatherModule;
60
+ }
61
+ this.request = core.getPlugin('request');
62
+ this.window = core.getPlugin('window');
63
+ if (this.request) {
64
+ _context.next = 11;
65
+ break;
66
+ }
67
+ throw new Error('OpenDataModule 需要 request 插件支持');
68
+ case 11:
69
+ if (this.window) {
70
+ _context.next = 13;
71
+ break;
72
+ }
73
+ throw new Error('OpenDataModule 需要 window 插件支持');
74
+ case 13:
75
+ console.log('[OpenDataModule] 初始化完成');
76
+ case 14:
77
+ case "end":
78
+ return _context.stop();
79
+ }
80
+ }, _callee, this);
81
+ }));
82
+ function initialize(_x, _x2) {
83
+ return _initialize.apply(this, arguments);
84
+ }
85
+ return initialize;
86
+ }()
87
+ }, {
88
+ key: "fetchOpenData",
89
+ value: function () {
90
+ var _fetchOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
91
+ var _this$otherParams, _this$otherParams$get, _this$otherParams2, _this$otherParams2$ge;
92
+ var shopId, tenantId, headers, response, data;
93
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
94
+ while (1) switch (_context2.prev = _context2.next) {
95
+ case 0:
96
+ shopId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 || (_this$otherParams$get = _this$otherParams.getStateData) === null || _this$otherParams$get === void 0 ? void 0 : _this$otherParams$get.call(_this$otherParams, 'shop_id');
97
+ if (shopId) {
98
+ _context2.next = 3;
99
+ break;
100
+ }
101
+ throw new Error('[OpenDataModule] 无法获取 shop_id');
102
+ case 3:
103
+ tenantId = (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 || (_this$otherParams2$ge = _this$otherParams2.getStateData) === null || _this$otherParams2$ge === void 0 ? void 0 : _this$otherParams2$ge.call(_this$otherParams2, 'tenant_id');
104
+ headers = {};
105
+ if (tenantId) headers['Tenant-Id'] = String(tenantId);
106
+ _context2.next = 8;
107
+ return this.request.post("/open/my-pisell/".concat(shopId, "/setting"), {
108
+ scope: params.scope,
109
+ target: params.target,
110
+ section_code: params.section_code
111
+ }, {
112
+ pisell2: true,
113
+ headers: headers
114
+ });
115
+ case 8:
116
+ response = _context2.sent;
117
+ if (!((response === null || response === void 0 ? void 0 : response.status) === false)) {
118
+ _context2.next = 11;
119
+ break;
120
+ }
121
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取 OpenData 配置失败');
122
+ case 11:
123
+ data = (response === null || response === void 0 ? void 0 : response.data) || {};
124
+ this.store.data = data;
125
+ this.store.lastFetchedAt = Date.now();
126
+ return _context2.abrupt("return", data);
127
+ case 15:
128
+ case "end":
129
+ return _context2.stop();
130
+ }
131
+ }, _callee2, this);
132
+ }));
133
+ function fetchOpenData(_x3) {
134
+ return _fetchOpenData.apply(this, arguments);
135
+ }
136
+ return fetchOpenData;
137
+ }()
138
+ }, {
139
+ key: "getOpenData",
140
+ value: function getOpenData() {
141
+ return this.store.data;
142
+ }
143
+ }, {
144
+ key: "getLastFetchedAt",
145
+ value: function getLastFetchedAt() {
146
+ var _this$store$lastFetch;
147
+ return (_this$store$lastFetch = this.store.lastFetchedAt) !== null && _this$store$lastFetch !== void 0 ? _this$store$lastFetch : null;
148
+ }
149
+ }, {
150
+ key: "checkAvailability",
151
+ value: function checkAvailability(scheduleModule) {
152
+ var _this$store$data;
153
+ var scheduleList = scheduleModule ? scheduleModule.getScheduleListByIds(((_this$store$data = this.store.data) === null || _this$store$data === void 0 ? void 0 : _this$store$data['availability.operating_hours']) || []) : undefined;
154
+ return computeAvailability({
155
+ config: this.store.data,
156
+ scheduleList: scheduleList
157
+ });
158
+ }
159
+ }, {
160
+ key: "storeChange",
161
+ value: function storeChange() {
162
+ if (this.openCache) {
163
+ this.checkSaveCache({
164
+ cacheId: this.cacheId,
165
+ fatherModule: this.fatherModule,
166
+ store: this.store,
167
+ cacheKey: ['data', 'lastFetchedAt']
168
+ });
169
+ }
170
+ }
171
+ }]);
172
+ return OpenDataModule;
173
+ }(BaseModule);
@@ -0,0 +1,73 @@
1
+ import type { ScheduleItem } from '../Schedule/types';
2
+ export interface MultiLangObject {
3
+ en?: string;
4
+ ja?: string;
5
+ pt?: string;
6
+ 'zh-CN'?: string;
7
+ 'zh-HK'?: string;
8
+ original?: string;
9
+ [key: string]: string | undefined;
10
+ }
11
+ export interface OpenDataConfig {
12
+ 'basic.enable'?: boolean;
13
+ 'basic.code'?: string | null;
14
+ 'basic.name'?: string | MultiLangObject;
15
+ 'basic.unavailable_message'?: string | MultiLangObject;
16
+ 'availability.paused'?: boolean;
17
+ 'availability.pause_message'?: string | MultiLangObject;
18
+ 'availability.pause_behavior'?: string;
19
+ 'availability.closed_behavior'?: string;
20
+ 'availability.closed_message'?: string | MultiLangObject;
21
+ 'availability.operating_hours'?: number[];
22
+ 'reservation.enable'?: boolean;
23
+ 'reservation.auto_confirm'?: boolean;
24
+ 'reservation.auto_confirm_mode'?: string;
25
+ 'reservation.auto_confirm_delay_seconds'?: number;
26
+ 'sale.allow_item_notes'?: boolean;
27
+ 'sale.allow_order_notes'?: boolean;
28
+ 'sale.enable_item_rules'?: boolean;
29
+ 'sale.enable_short_number'?: boolean;
30
+ 'sale.short_number_daily_reset'?: boolean;
31
+ 'sale.short_number_start_number'?: number;
32
+ 'sale.short_number_prefix'?: string | null;
33
+ 'sale.sale_number_prefix'?: string | null;
34
+ 'sale.enabled_item_rules'?: number[];
35
+ 'fulfillment.enable_pickup'?: boolean;
36
+ 'fulfillment.overdue_reminder'?: boolean;
37
+ 'fulfillment.manual_input_type'?: string;
38
+ 'fulfillment.enable_auto_complete'?: boolean;
39
+ 'fulfillment.enable_table_service'?: boolean;
40
+ 'fulfillment.fulfillment_ref_mode'?: string;
41
+ 'fulfillment.advance_warning_minutes'?: number;
42
+ 'fulfillment.update_end_time_on_auto_complete'?: string;
43
+ 'menu.associated_menus'?: Array<{
44
+ label: string;
45
+ value: number;
46
+ }>;
47
+ [key: string]: any;
48
+ }
49
+ export interface OpenDataState {
50
+ data: OpenDataConfig | null;
51
+ lastFetchedAt: number | null;
52
+ }
53
+ export interface OpenDataFetchParams {
54
+ scope: string;
55
+ target: string;
56
+ section_code: string[];
57
+ }
58
+ export interface OpenDataApiResponse {
59
+ status: boolean;
60
+ code: number;
61
+ message: string;
62
+ data: OpenDataConfig;
63
+ }
64
+ export type OpenDataUnavailableReason = 'shop_disabled' | 'paused' | 'closed' | 'reservation_disabled';
65
+ export interface OpenDataAvailabilityResult {
66
+ available: boolean;
67
+ reason: OpenDataUnavailableReason | null;
68
+ message: string | MultiLangObject | null;
69
+ }
70
+ export interface ComputeAvailabilityParams {
71
+ config: OpenDataConfig | null;
72
+ scheduleList?: ScheduleItem[];
73
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { OpenDataAvailabilityResult, ComputeAvailabilityParams } from './types';
2
+ export declare function computeAvailability(params: ComputeAvailabilityParams): OpenDataAvailabilityResult;
@@ -0,0 +1,75 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ import dayjs from 'dayjs';
3
+ import { getDateIsInSchedule } from "../Schedule/getDateIsInSchedule";
4
+ function toBoolean(value) {
5
+ if (typeof value === 'boolean') return value;
6
+ if (typeof value === 'string') return value === 'true' || value === '1';
7
+ if (typeof value === 'number') return value !== 0;
8
+ return false;
9
+ }
10
+ function resolveMessage() {
11
+ for (var _len = arguments.length, candidates = new Array(_len), _key = 0; _key < _len; _key++) {
12
+ candidates[_key] = arguments[_key];
13
+ }
14
+ for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
15
+ var val = _candidates[_i];
16
+ if (!val) continue;
17
+ if (typeof val === 'string' && val.length > 0) return val;
18
+ if (_typeof(val) === 'object' && val !== null && !Array.isArray(val)) return val;
19
+ }
20
+ return null;
21
+ }
22
+ export function computeAvailability(params) {
23
+ var config = params.config,
24
+ scheduleList = params.scheduleList;
25
+ if (!config) {
26
+ return {
27
+ available: true,
28
+ reason: null,
29
+ message: null
30
+ };
31
+ }
32
+ if (config['basic.enable'] === false) {
33
+ return {
34
+ available: false,
35
+ reason: 'shop_disabled',
36
+ message: resolveMessage(config['basic.unavailable_message'], config['availability.closed_message'])
37
+ };
38
+ }
39
+ if (toBoolean(config['availability.paused'])) {
40
+ return {
41
+ available: false,
42
+ reason: 'paused',
43
+ message: resolveMessage(config['availability.pause_message'], config['availability.closed_message'])
44
+ };
45
+ }
46
+ var operatingHourIds = config['availability.operating_hours'];
47
+ if (Array.isArray(operatingHourIds) && operatingHourIds.length > 0 && scheduleList !== null && scheduleList !== void 0 && scheduleList.length) {
48
+ var relevantSchedules = scheduleList.filter(function (s) {
49
+ return operatingHourIds.includes(s.id);
50
+ });
51
+ if (relevantSchedules.length > 0) {
52
+ var now = dayjs().format('YYYY-MM-DD HH:mm:ss');
53
+ var isOpen = getDateIsInSchedule(now, relevantSchedules);
54
+ if (!isOpen) {
55
+ return {
56
+ available: false,
57
+ reason: 'closed',
58
+ message: resolveMessage(config['availability.closed_message'])
59
+ };
60
+ }
61
+ }
62
+ }
63
+ if (config['reservation.enable'] === false) {
64
+ return {
65
+ available: false,
66
+ reason: 'reservation_disabled',
67
+ message: resolveMessage(config['availability.closed_message'])
68
+ };
69
+ }
70
+ return {
71
+ available: true,
72
+ reason: null,
73
+ message: null
74
+ };
75
+ }
@@ -1,14 +1,74 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { OrderModuleAPI, CommitOrderParams } from './types';
3
+ import { OrderModuleAPI, CommitOrderParams, SubmitScanOrderParams, ScanOrderMoreParams, UpdateProductInOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
+ import { type SubmitPayloadEnhancer } from './utils';
6
+ import type { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderSummary, ScanOrderTempOrder } from '../../solution/ScanOrder/types';
7
+ import type { Discount } from '../Discount/types';
8
+ import { UnavailableReason } from '../Rules/types';
5
9
  export declare class OrderModule extends BaseModule implements Module, OrderModuleAPI {
6
10
  protected defaultName: string;
7
11
  protected defaultVersion: string;
8
12
  private store;
9
13
  private request;
14
+ private window;
15
+ private cacheId;
16
+ private salesSummaryModuleName;
17
+ private rulesHooksOverride?;
18
+ /**
19
+ * Populate `savedAmount` on each discount based on product-level discount details.
20
+ * Only selected discounts get a non-zero value.
21
+ */
22
+ static populateSavedAmounts(productList: Array<Record<string, any>>, discountList: Array<Record<string, any>>): void;
10
23
  constructor(name?: string, version?: string);
11
24
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
25
+ private registerDiscountModules;
26
+ private createDefaultRulesHooks;
27
+ loadDiscountConfig(params: {
28
+ customerId: number;
29
+ action?: 'create';
30
+ }): Promise<void>;
31
+ getDiscountList(): Discount[];
32
+ scanCode(code: string, customerId?: number): Promise<{
33
+ isAvailable: boolean;
34
+ discountList: Discount[];
35
+ type: 'server' | 'clientCalc';
36
+ unavailableReason?: UnavailableReason;
37
+ unavailableReasonKey?: string | null;
38
+ }>;
39
+ applyDiscount(): void;
40
+ initTempOrder(params: {
41
+ cacheId?: string;
42
+ salesSummaryModuleName?: string;
43
+ }): void;
44
+ private getTempOrderStorageKey;
45
+ private restoreTempOrderFromStorage;
46
+ persistTempOrder(): void;
47
+ private createDefaultTempOrderInstance;
48
+ ensureTempOrder(): ScanOrderTempOrder;
49
+ restoreOrder(): ScanOrderTempOrder;
50
+ getTempOrder(): ScanOrderTempOrder | null;
51
+ addNewOrder(): Promise<ScanOrderTempOrder>;
52
+ getOrderProducts(): ScanOrderOrderProduct[];
53
+ private getSalesSummary;
54
+ recalculateSummary(options?: {
55
+ createIfMissing?: boolean;
56
+ }): Promise<ScanOrderSummary | null>;
57
+ getScanOrderSummary(): Promise<ScanOrderSummary>;
58
+ updateTempOrderNote(note: string): string;
59
+ updateTempOrderBuzzer(buzzer: string): string;
60
+ updateTempOrderContactsInfo(contactsInfo: any[]): any[];
61
+ addProductToOrder(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
62
+ updateProductInOrder(params: UpdateProductInOrderParams): Promise<ScanOrderOrderProduct[]>;
63
+ removeProductFromOrder(identity: ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
64
+ submitTempOrder<T = any>(params?: {
65
+ cacheId?: string;
66
+ platform?: string;
67
+ businessCode?: string;
68
+ channel?: string;
69
+ type?: string;
70
+ enhancePayload?: SubmitPayloadEnhancer;
71
+ }): Promise<T>;
12
72
  createOrder(params: CommitOrderParams['query']): {
13
73
  type: "virtual" | "appointment_booking";
14
74
  platform: string;
@@ -26,4 +86,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
26
86
  type: 'holder' | 'account';
27
87
  }): boolean;
28
88
  submitOrder(order: CommitOrderParams): Promise<void>;
89
+ submitScanOrder<T = any>(params: SubmitScanOrderParams): Promise<T>;
90
+ scanOrderMore<T = any>(params: ScanOrderMoreParams): Promise<T>;
91
+ getOrderInfoByRemote(order_id: number): Promise<any>;
92
+ getLastOrderInfo(): Record<string, any> | undefined;
29
93
  }
94
+ export type { UpdateProductInOrderParams } from './types';