@pisell/pisellos 2.3.74 → 2.3.76

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 (283) hide show
  1. package/dist/core/index.js +6 -10
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/strategy-example.js +5 -19
  5. package/dist/modules/Cart/index.js +0 -3
  6. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  7. package/dist/modules/Date/index.js +1 -5
  8. package/dist/modules/Discount/index.js +2 -4
  9. package/dist/modules/OpenData/index.js +0 -2
  10. package/dist/modules/Order/index.d.ts +1 -1
  11. package/dist/modules/Order/index.js +75 -91
  12. package/dist/modules/Order/types.d.ts +3 -1
  13. package/dist/modules/Payment/index.js +97 -162
  14. package/dist/modules/Rules/index.js +1 -4
  15. package/dist/modules/Schedule/index.js +0 -1
  16. package/dist/modules/Schedule/utils.js +0 -1
  17. package/dist/modules/Step/index.js +0 -1
  18. package/dist/plugins/request.js +1 -4
  19. package/dist/plugins/window.js +2 -6
  20. package/dist/server/index.js +97 -129
  21. package/dist/server/modules/menu/index.js +32 -41
  22. package/dist/server/modules/order/index.js +2 -4
  23. package/dist/server/modules/products/index.js +24 -42
  24. package/dist/server/modules/quotation/index.js +29 -38
  25. package/dist/server/modules/resource/index.js +3 -4
  26. package/dist/server/modules/schedule/index.js +27 -35
  27. package/dist/server/utils/product.js +0 -1
  28. package/dist/solution/BaseSales/index.js +100 -72
  29. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
  31. package/dist/solution/BookingByStep/index.js +7 -59
  32. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  33. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  34. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  35. package/dist/solution/BookingTicket/index.js +0 -2
  36. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
  37. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  38. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  39. package/dist/solution/BuyTickets/index.js +9 -12
  40. package/dist/solution/Checkout/index.js +177 -252
  41. package/dist/solution/Checkout/utils/index.js +4 -16
  42. package/dist/solution/RegisterAndLogin/index.js +30 -76
  43. package/dist/solution/ScanOrder/index.js +50 -60
  44. package/dist/solution/ShopDiscount/index.js +2 -7
  45. package/dist/solution/VenueBooking/index.js +45 -55
  46. package/dist/utils/task.js +15 -18
  47. package/dist/utils/watch.js +0 -1
  48. package/lib/apis/picoding.js +2 -0
  49. package/lib/core/index.js +134 -134
  50. package/lib/effects/index.js +46 -57
  51. package/lib/index.js +82 -49
  52. package/lib/model/index.js +14 -21
  53. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  54. package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
  55. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  56. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  57. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  58. package/lib/model/strategy/adapter/index.js +100 -64
  59. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  60. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  61. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  62. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  63. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  64. package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
  65. package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
  66. package/lib/model/strategy/adapter/promotion/examples.js +222 -234
  67. package/lib/model/strategy/adapter/promotion/index.js +1 -0
  68. package/lib/model/strategy/adapter/promotion/type.js +243 -36
  69. package/lib/model/strategy/adapter/type.js +4 -16
  70. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
  71. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  72. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  73. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  74. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  75. package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
  76. package/lib/model/strategy/engine.js +270 -168
  77. package/lib/model/strategy/index.js +49 -34
  78. package/lib/model/strategy/strategy-example.js +243 -239
  79. package/lib/model/strategy/type.js +100 -40
  80. package/lib/modules/Account/index.js +39 -53
  81. package/lib/modules/Account/types.js +20 -33
  82. package/lib/modules/AccountList/index.js +116 -154
  83. package/lib/modules/AccountList/types.js +30 -31
  84. package/lib/modules/AccountList/utils.js +18 -30
  85. package/lib/modules/BaseModule.js +23 -42
  86. package/lib/modules/BookingContext/index.js +158 -136
  87. package/lib/modules/BookingContext/types.js +46 -32
  88. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
  89. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
  90. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
  91. package/lib/modules/BookingContext/utils/flexible.js +38 -55
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
  93. package/lib/modules/BookingContext/utils/index.js +124 -41
  94. package/lib/modules/BookingContext/utils/noResource.js +58 -70
  95. package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
  96. package/lib/modules/BookingContext/utils/productExtend.js +202 -155
  97. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  98. package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
  99. package/lib/modules/BookingContext/utils/resources.js +209 -167
  100. package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
  101. package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
  102. package/lib/modules/Cart/index.js +170 -124
  103. package/lib/modules/Cart/types.js +46 -51
  104. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  105. package/lib/modules/Cart/utils/cartDate.js +56 -61
  106. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  107. package/lib/modules/Cart/utils/cartNote.js +27 -32
  108. package/lib/modules/Cart/utils/cartProduct.js +321 -251
  109. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  110. package/lib/modules/Cart/utils/cartResource.js +70 -78
  111. package/lib/modules/Cart/utils/changePrice.js +22 -50
  112. package/lib/modules/Cart/utils/index.js +106 -48
  113. package/lib/modules/Customer/constants.js +13 -34
  114. package/lib/modules/Customer/index.js +235 -172
  115. package/lib/modules/Customer/types.js +38 -35
  116. package/lib/modules/Date/index.js +116 -115
  117. package/lib/modules/Date/types.js +16 -28
  118. package/lib/modules/Date/utils.js +174 -123
  119. package/lib/modules/Discount/index.js +122 -127
  120. package/lib/modules/Discount/types.js +9 -31
  121. package/lib/modules/Guests/index.js +30 -56
  122. package/lib/modules/Guests/types.js +23 -33
  123. package/lib/modules/Holder/index.js +209 -189
  124. package/lib/modules/Holder/types.js +4 -16
  125. package/lib/modules/Holder/utils.js +20 -49
  126. package/lib/modules/OpenData/index.js +70 -76
  127. package/lib/modules/OpenData/types.js +4 -16
  128. package/lib/modules/OpenData/utils.js +44 -78
  129. package/lib/modules/Order/index.d.ts +1 -1
  130. package/lib/modules/Order/index.js +1733 -2121
  131. package/lib/modules/Order/payment-utils.js +77 -120
  132. package/lib/modules/Order/types.d.ts +3 -1
  133. package/lib/modules/Order/types.js +88 -35
  134. package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
  135. package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
  136. package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
  137. package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
  138. package/lib/modules/Order/utils.js +814 -647
  139. package/lib/modules/Payment/cash.js +20 -33
  140. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  141. package/lib/modules/Payment/eftpos.js +16 -30
  142. package/lib/modules/Payment/index.js +532 -399
  143. package/lib/modules/Payment/mx51.js +1 -0
  144. package/lib/modules/Payment/types.js +230 -108
  145. package/lib/modules/Payment/utils.js +52 -51
  146. package/lib/modules/Payment/walletpass.js +485 -660
  147. package/lib/modules/Product/index.js +51 -46
  148. package/lib/modules/Product/types.js +4 -16
  149. package/lib/modules/Product/utils.js +32 -33
  150. package/lib/modules/ProductList/index.js +113 -123
  151. package/lib/modules/ProductList/types.js +9 -31
  152. package/lib/modules/Quotation/index.js +81 -118
  153. package/lib/modules/Quotation/types.js +4 -16
  154. package/lib/modules/Resource/index.js +27 -59
  155. package/lib/modules/Resource/types.js +22 -32
  156. package/lib/modules/Resource/utils.js +30 -38
  157. package/lib/modules/ResourcePlanner/index.js +25 -23
  158. package/lib/modules/ResourcePlanner/localClock.js +54 -119
  159. package/lib/modules/ResourcePlanner/planner.js +589 -770
  160. package/lib/modules/ResourcePlanner/types.js +10 -29
  161. package/lib/modules/Rules/index.js +1218 -959
  162. package/lib/modules/Rules/types.js +17 -40
  163. package/lib/modules/SalesSummary/index.js +85 -90
  164. package/lib/modules/SalesSummary/types.js +4 -16
  165. package/lib/modules/SalesSummary/utils.js +355 -430
  166. package/lib/modules/ScanOrderLogger/index.js +59 -79
  167. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  168. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  169. package/lib/modules/ScanOrderLogger/types.js +4 -16
  170. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
  171. package/lib/modules/Schedule/index.js +100 -114
  172. package/lib/modules/Schedule/type.js +4 -16
  173. package/lib/modules/Schedule/types.js +4 -16
  174. package/lib/modules/Schedule/utils.js +433 -291
  175. package/lib/modules/Step/index.js +40 -52
  176. package/lib/modules/Step/tyeps.js +4 -16
  177. package/lib/modules/Summary/index.js +66 -71
  178. package/lib/modules/Summary/types.js +4 -16
  179. package/lib/modules/Summary/utils.js +773 -418
  180. package/lib/modules/SurchargeList/index.js +46 -60
  181. package/lib/modules/SurchargeList/types.js +4 -16
  182. package/lib/modules/index.js +245 -63
  183. package/lib/plugins/app.js +4 -16
  184. package/lib/plugins/index.js +36 -25
  185. package/lib/plugins/request.js +137 -126
  186. package/lib/plugins/shopStore.js +4 -16
  187. package/lib/plugins/user.js +4 -16
  188. package/lib/plugins/window.js +171 -179
  189. package/lib/server/index.js +3050 -2665
  190. package/lib/server/modules/floor-plan/index.js +118 -134
  191. package/lib/server/modules/floor-plan/types.js +15 -30
  192. package/lib/server/modules/index.js +106 -68
  193. package/lib/server/modules/menu/index.js +142 -122
  194. package/lib/server/modules/menu/types.js +18 -31
  195. package/lib/server/modules/order/index.js +784 -1002
  196. package/lib/server/modules/order/types.js +122 -33
  197. package/lib/server/modules/order/utils/filterBookings.js +219 -194
  198. package/lib/server/modules/order/utils/filterOrders.js +118 -92
  199. package/lib/server/modules/payment/index.js +59 -83
  200. package/lib/server/modules/payment/types.js +4 -16
  201. package/lib/server/modules/products/index.js +583 -471
  202. package/lib/server/modules/products/types.js +44 -34
  203. package/lib/server/modules/quotation/index.js +137 -172
  204. package/lib/server/modules/quotation/types.js +21 -31
  205. package/lib/server/modules/resource/index.js +220 -186
  206. package/lib/server/modules/resource/types.js +42 -33
  207. package/lib/server/modules/schedule/index.js +135 -123
  208. package/lib/server/modules/schedule/types.js +14 -21
  209. package/lib/server/modules/schedule/utils.js +334 -163
  210. package/lib/server/types.js +4 -16
  211. package/lib/server/utils/index.js +25 -23
  212. package/lib/server/utils/product.js +196 -139
  213. package/lib/server/utils/schedule.js +34 -41
  214. package/lib/server/utils/small-ticket.js +479 -456
  215. package/lib/server/utils/time.js +40 -49
  216. package/lib/solution/BaseSales/index.js +1220 -1412
  217. package/lib/solution/BaseSales/types.js +42 -38
  218. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  219. package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
  220. package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
  221. package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
  222. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
  223. package/lib/solution/BaseSales/utils.js +158 -143
  224. package/lib/solution/BookingByStep/index.js +1527 -1340
  225. package/lib/solution/BookingByStep/types.js +40 -99
  226. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  227. package/lib/solution/BookingByStep/utils/products.js +42 -52
  228. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  229. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  230. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  231. package/lib/solution/BookingTicket/index.js +607 -522
  232. package/lib/solution/BookingTicket/types.js +99 -77
  233. package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
  234. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
  235. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
  236. package/lib/solution/BookingTicket/utils/cartView.js +114 -99
  237. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  238. package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
  239. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
  240. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
  241. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
  242. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
  243. package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
  244. package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
  245. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  246. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
  247. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
  248. package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
  249. package/lib/solution/BuyTickets/index.js +67 -70
  250. package/lib/solution/BuyTickets/types.js +22 -38
  251. package/lib/solution/Checkout/index.js +1451 -1158
  252. package/lib/solution/Checkout/types.js +91 -61
  253. package/lib/solution/Checkout/utils/index.js +228 -156
  254. package/lib/solution/PlaceOrder/index.js +55 -0
  255. package/lib/solution/RegisterAndLogin/config.js +493 -460
  256. package/lib/solution/RegisterAndLogin/index.js +633 -630
  257. package/lib/solution/RegisterAndLogin/types.js +189 -76
  258. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  259. package/lib/solution/Sales/index.js +328 -324
  260. package/lib/solution/Sales/types.js +27 -33
  261. package/lib/solution/ScanOrder/index.js +832 -864
  262. package/lib/solution/ScanOrder/types.js +33 -34
  263. package/lib/solution/ScanOrder/utils.js +409 -374
  264. package/lib/solution/ShopDiscount/index.js +226 -232
  265. package/lib/solution/ShopDiscount/types.js +15 -37
  266. package/lib/solution/ShopDiscount/utils.js +300 -172
  267. package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
  268. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
  269. package/lib/solution/UnifiedBookingSales/types.js +10 -32
  270. package/lib/solution/VenueBooking/index.js +811 -879
  271. package/lib/solution/VenueBooking/types.js +19 -39
  272. package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
  273. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  274. package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
  275. package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
  276. package/lib/solution/VenueBooking/utils.js +130 -67
  277. package/lib/solution/index.js +124 -41
  278. package/lib/store/createStore.js +32 -29
  279. package/lib/types/index.js +4 -16
  280. package/lib/utils/payment-number.js +26 -46
  281. package/lib/utils/task.js +36 -36
  282. package/lib/utils/watch.js +81 -47
  283. package/package.json +2 -1
@@ -1,52 +1,29 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/solution/ShopDiscount/index.ts
30
- var ShopDiscount_exports = {};
31
- __export(ShopDiscount_exports, {
32
- ShopDiscountImpl: () => ShopDiscountImpl,
33
- default: () => ShopDiscount_default
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
34
5
  });
35
- module.exports = __toCommonJS(ShopDiscount_exports);
36
- var import_BaseModule = require("../../modules/BaseModule");
37
- var import_Discount = require("../../modules/Discount");
38
- var import_Rules = require("../../modules/Rules");
39
- var import_utils = require("./utils");
40
- var import_types = require("../../modules/Rules/types");
41
- var import_decimal = __toESM(require("decimal.js"));
42
- var import_lodash_es = require("lodash-es");
43
- var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
6
+ exports.default = exports.ShopDiscountImpl = void 0;
7
+ var _BaseModule = require("../../modules/BaseModule");
8
+ var _Discount = require("../../modules/Discount");
9
+ var _Rules = require("../../modules/Rules");
10
+ var _utils = require("./utils");
11
+ var _types = require("../../modules/Rules/types");
12
+ var _decimal = _interopRequireDefault(require("decimal.js"));
13
+ var _lodashEs = require("lodash-es");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ class ShopDiscountImpl extends _BaseModule.BaseModule {
16
+ defaultName = 'shopDiscount';
17
+ defaultVersion = '1.0.0';
18
+ isSolution = true;
19
+ request;
20
+ window;
21
+ store;
22
+ options = {};
23
+ hooks;
44
24
  constructor(name, version) {
45
25
  super(name, version);
46
- this.defaultName = "shopDiscount";
47
- this.defaultVersion = "1.0.0";
48
- this.isSolution = true;
49
- this.options = {};
26
+ // 初始化所有必要的状态属性
50
27
  this.store = {
51
28
  customer: null,
52
29
  productList: [],
@@ -56,97 +33,105 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
56
33
  originalDiscountList: [],
57
34
  currentBookingTime: "",
58
35
  filteredDiscountList: [],
59
- bookingSubject: void 0,
36
+ bookingSubject: undefined,
60
37
  orderTotalAmount: 0,
61
- orderId: void 0
38
+ orderId: undefined
62
39
  };
63
40
  }
41
+
64
42
  // =========== 生命周期方法 ===========
43
+
65
44
  async initialize(core, options) {
66
- var _a, _b;
67
45
  this.core = core;
68
46
  this.options = options;
69
- this.store = { ...this.store, ...options.store || {} };
70
- this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
71
- console.log("[ShopDiscount] 初始化完成");
47
+ this.store = {
48
+ ...this.store,
49
+ ...(options.store || {})
50
+ };
51
+ this.hooks = options.otherParams?.rules?.hooks;
52
+ // 获取依赖的插件
72
53
  this.initializePlugins();
54
+
55
+ // 注册依赖模块
73
56
  this.registerDependentModules();
57
+
58
+ // 注册事件监听
74
59
  this.registerEventListeners();
75
60
  }
76
61
  async destroy() {
77
- var _a, _b;
78
62
  this.store.productList = [];
79
63
  this.store.customer = null;
80
- (_a = this.store.discount) == null ? void 0 : _a.destroy();
81
- (_b = this.store.rules) == null ? void 0 : _b.destroy();
64
+ this.store.discount?.destroy();
65
+ this.store.rules?.destroy();
82
66
  this.core.effects.offByModuleDestroy(this.name);
83
67
  await this.core.effects.emit(`${this.name}:onDestroy`, {});
84
- console.log("[ShopDiscount] 已销毁");
85
68
  }
86
69
  async clear() {
87
- var _a, _b;
88
70
  this.store.productList = [];
89
71
  this.store.customer = null;
90
- (_a = this.store.discount) == null ? void 0 : _a.clear();
91
- (_b = this.store.rules) == null ? void 0 : _b.clear();
92
- console.log("[ShopDiscount] clear");
72
+ this.store.discount?.clear();
73
+ this.store.rules?.clear();
93
74
  }
75
+
94
76
  // =========== 初始化辅助方法 ===========
77
+
95
78
  initializePlugins() {
96
- this.request = this.core.getPlugin("request");
97
- this.window = this.core.getPlugin("window");
79
+ this.request = this.core.getPlugin('request');
80
+ this.window = this.core.getPlugin('window');
98
81
  if (!this.request) {
99
- throw new Error("ShopDiscount需要 request 插件支持");
82
+ throw new Error('ShopDiscount需要 request 插件支持');
100
83
  }
101
84
  if (!this.window) {
102
- throw new Error("ShopDiscount需要 window 插件支持");
85
+ throw new Error('ShopDiscount需要 window 插件支持');
103
86
  }
104
87
  }
105
88
  registerDependentModules() {
106
- var _a, _b, _c, _d, _e, _f, _g;
89
+ // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
90
+ // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
107
91
  let targetCacheData = {};
108
- if ((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) {
92
+ if (this.options.otherParams?.cacheId) {
109
93
  const sessionData = this.window.sessionStorage.getItem(this.name);
110
94
  if (sessionData) {
111
95
  const data = JSON.parse(sessionData);
112
96
  targetCacheData = data[this.options.otherParams.cacheId];
113
97
  }
114
98
  }
115
- const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
99
+ // 注册优惠模块
100
+ const discount = new _Discount.DiscountModule(`${this.name}_discount`);
116
101
  this.core.registerModule(discount, {
117
- initialState: targetCacheData == null ? void 0 : targetCacheData[discount.name],
118
- hooks: (_c = (_b = this.options.otherParams) == null ? void 0 : _b.discount) == null ? void 0 : _c.hooks,
102
+ initialState: targetCacheData?.[discount.name],
103
+ hooks: this.options.otherParams?.discount?.hooks,
119
104
  otherParams: {
120
105
  fatherModule: this.name,
121
- openCache: ((_d = this.options.otherParams) == null ? void 0 : _d.cacheId) ? true : false,
122
- cacheId: (_e = this.options.otherParams) == null ? void 0 : _e.cacheId
106
+ openCache: this.options.otherParams?.cacheId ? true : false,
107
+ cacheId: this.options.otherParams?.cacheId
123
108
  }
124
109
  });
125
110
  this.store.discount = discount;
126
- const rules = new import_Rules.RulesModule(`${this.name}_rules`);
111
+
112
+ // 注册规则模块
113
+ const rules = new _Rules.RulesModule(`${this.name}_rules`);
127
114
  this.core.registerModule(rules, {
128
- hooks: (_g = (_f = this.options.otherParams) == null ? void 0 : _f.rules) == null ? void 0 : _g.hooks
115
+ hooks: this.options.otherParams?.rules?.hooks
129
116
  });
130
117
  this.store.rules = rules;
131
118
  }
132
119
  registerEventListeners() {
133
- this.core.effects.only(
134
- `${this.name}:onCustomerChange`,
135
- (customer) => {
136
- var _a;
137
- if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
138
- return;
139
- }
140
- this.loadPrepareConfig({
141
- customerId: customer.id,
142
- action: "create",
143
- with_good_pass: 1,
144
- with_discount_card: 1
145
- });
120
+ this.core.effects.only(`${this.name}:onCustomerChange`, customer => {
121
+ if (this.options.otherParams?.cacheId && this.getDiscountList().length) {
122
+ return;
146
123
  }
147
- );
124
+ this.loadPrepareConfig({
125
+ customerId: customer.id,
126
+ action: 'create',
127
+ with_good_pass: 1,
128
+ with_discount_card: 1
129
+ });
130
+ });
148
131
  }
132
+
149
133
  // =========== 公共 API ===========
134
+
150
135
  // 设置预约时间
151
136
  // public async setBookingTime(bookingTime: string | null): Promise<void> {
152
137
  // if (this.store.currentBookingTime !== bookingTime) {
@@ -156,17 +141,23 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
156
141
  // await this.updateFilteredDiscountList();
157
142
  // }
158
143
  // }
144
+
159
145
  // 获取当前预约时间
160
146
  getCurrentBookingTime() {
161
147
  return this.store.currentBookingTime;
162
148
  }
149
+
163
150
  // 根据预约时间过滤优惠券列表
164
151
  filterDiscountListByBookingTime(discountList, bookingTime) {
165
- if ((0, import_utils.isAllNormalProduct)(this.store.productList || [])) {
152
+ // 如果全部是普通商品,不需要过滤,直接返回当前数据
153
+ if ((0, _utils.isAllNormalProduct)(this.store.productList || [])) {
166
154
  return discountList;
167
155
  }
168
- return (0, import_utils.filterDiscountListByBookingTime)(discountList, bookingTime);
156
+
157
+ // 否则使用 bookingTime 进行过滤
158
+ return (0, _utils.filterDiscountListByBookingTime)(discountList, bookingTime);
169
159
  }
160
+
170
161
  // 更新过滤后的优惠券列表
171
162
  // private async updateFilteredDiscountList(): Promise<void> {
172
163
  // const originalList = this.store.originalDiscountList;
@@ -185,20 +176,18 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
185
176
  // );
186
177
  // }
187
178
  // }
179
+
188
180
  // 设置客户
189
181
  async setCustomer(customer) {
190
- var _a;
191
- if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
182
+ if (this.store.customer?.id !== customer.id) {
192
183
  this.store.customer = customer;
193
- await this.core.effects.emit(
194
- `${this.name}:onCustomerChange`,
195
- customer
196
- );
184
+ await this.core.effects.emit(`${this.name}:onCustomerChange`, customer);
197
185
  }
198
186
  }
199
187
  setOriginTotalAmount(amount) {
200
188
  this.store.orderTotalAmount = amount;
201
189
  }
190
+
202
191
  // 设置holders
203
192
  setHolders(holders) {
204
193
  this.store.holders = holders;
@@ -209,24 +198,30 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
209
198
  setOrderId(id) {
210
199
  this.store.orderId = id;
211
200
  }
201
+
212
202
  // 计算优惠券
213
203
  calcDiscount(productList, options) {
214
- var _a;
215
204
  this.store.productList = productList;
216
205
  const rulesModule = this.core.getModule(`${this.name}_rules`);
217
206
  if (!rulesModule) {
218
- return { productList, discountList: this.getDiscountList() };
219
- }
220
- let { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
221
- {
207
+ return {
222
208
  productList,
223
- discountList: this.getDiscountList(),
224
- orderTotalAmount: this.store.orderTotalAmount || 0,
225
- holders: this.store.holders || [],
226
- isFormSubject: ((_a = this.store.bookingSubject) == null ? void 0 : _a.type) === "form"
227
- },
228
- options
229
- ) || { productList, discountList: this.getDiscountList() };
209
+ discountList: this.getDiscountList()
210
+ };
211
+ }
212
+ let {
213
+ productList: newProductList,
214
+ discountList: newDiscountList
215
+ } = rulesModule.calcDiscount({
216
+ productList,
217
+ discountList: this.getDiscountList(),
218
+ orderTotalAmount: this.store.orderTotalAmount || 0,
219
+ holders: this.store.holders || [],
220
+ isFormSubject: this.store.bookingSubject?.type === 'form'
221
+ }, options) || {
222
+ productList,
223
+ discountList: this.getDiscountList()
224
+ };
230
225
  if (newDiscountList) {
231
226
  newDiscountList = this.setDiscountList(newDiscountList);
232
227
  }
@@ -235,24 +230,35 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
235
230
  discountList: newDiscountList || this.getDiscountList()
236
231
  };
237
232
  }
233
+
238
234
  // 设置优惠券使用状态
239
235
  setDiscountSelected(params) {
236
+ // 获取当前优惠券列表
240
237
  const discountList = this.getDiscountList();
238
+
239
+ // 构建选择操作列表
241
240
  const selectionOperations = [];
241
+
242
+ // 主要操作
242
243
  selectionOperations.push({
243
244
  discountId: params.discountId,
244
245
  isSelected: params.isSelected
245
246
  });
247
+
248
+ // 如果有批量操作列表,添加到操作列表中
246
249
  if (params.selectedList && params.selectedList.length > 0) {
247
250
  selectionOperations.push(...params.selectedList);
248
251
  }
249
- const selectionMap = /* @__PURE__ */ new Map();
250
- selectionOperations.forEach((operation) => {
252
+
253
+ // 创建选择状态映射(去重处理,后面的操作会覆盖前面的)
254
+ const selectionMap = new Map();
255
+ selectionOperations.forEach(operation => {
251
256
  selectionMap.set(operation.discountId, operation.isSelected);
252
257
  });
253
- const newDiscountList = discountList.map((discount) => {
254
- if (discount.isEditMode)
255
- return discount;
258
+
259
+ // 找到需要修改状态的优惠券
260
+ const newDiscountList = discountList.map(discount => {
261
+ if (discount.isEditMode) return discount;
256
262
  if (selectionMap.has(discount.id)) {
257
263
  const targetIsSelected = selectionMap.get(discount.id);
258
264
  return {
@@ -262,8 +268,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
262
268
  isManualSelect: !targetIsSelected
263
269
  };
264
270
  }
265
- return { ...discount, isManualSelect: !(discount == null ? void 0 : discount.isSelected) };
271
+ return {
272
+ ...discount,
273
+ isManualSelect: !discount?.isSelected
274
+ };
266
275
  });
276
+
277
+ // 更新优惠券列表
267
278
  this.setDiscountList(newDiscountList);
268
279
  return this.calcDiscount(this.store.productList || [], params);
269
280
  }
@@ -271,9 +282,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
271
282
  this.store.productList = productList;
272
283
  }
273
284
  async batchSearchByProductIds(productIds) {
274
- var _a;
275
- let resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearchByProductIds(productIds)) || [];
276
- resultDiscountList = resultDiscountList.map((item) => {
285
+ let resultDiscountList = (await this.store.discount?.batchSearchByProductIds(productIds)) || [];
286
+ resultDiscountList = resultDiscountList.map(item => {
277
287
  return {
278
288
  ...item,
279
289
  discount_rule_uncheck_flag: true
@@ -284,12 +294,21 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
284
294
  this.setDiscountList(newDiscountList);
285
295
  return newDiscountList;
286
296
  }
297
+
287
298
  // 扫码输入code
288
299
  async scanCode(code, customerId) {
289
- var _a, _b, _c;
290
300
  try {
291
- const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId, orderId: this.store.orderId })) || { discountList: [], unavailableReasonKey: null };
292
- const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
301
+ const resultDiscountWithReason = (await this.store.discount?.batchSearch(code, {
302
+ customerId,
303
+ orderId: this.store.orderId
304
+ })) || {
305
+ discountList: [],
306
+ unavailableReasonKey: null
307
+ };
308
+ const {
309
+ discountList: resultDiscountList,
310
+ unavailableReasonKey
311
+ } = resultDiscountWithReason;
293
312
  const rulesModule = this.store.rules;
294
313
  if (!rulesModule) {
295
314
  return {
@@ -297,7 +316,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
297
316
  isAvailable: false,
298
317
  productList: this.store.productList || [],
299
318
  discountList: this.getDiscountList(),
300
- unavailableReason: import_types.UnavailableReason.Unknown
319
+ unavailableReason: _types.UnavailableReason.Unknown
301
320
  };
302
321
  }
303
322
  if (!resultDiscountList.length) {
@@ -309,14 +328,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
309
328
  unavailableReasonKey
310
329
  };
311
330
  }
312
- const withScanList = resultDiscountList.map((item) => {
331
+ const withScanList = resultDiscountList.map(item => {
313
332
  return {
314
333
  ...item,
315
334
  isScan: true
316
335
  };
317
336
  });
318
- const currentSelectedDiscountList = this.getDiscountList().filter((n) => n.isSelected);
319
- if (currentSelectedDiscountList.length && currentSelectedDiscountList.some((n) => withScanList.some((m) => m.id === n.id))) {
337
+ // 如果扫回来的券当前有选中的,则不进行计算
338
+ const currentSelectedDiscountList = this.getDiscountList().filter(n => n.isSelected);
339
+ if (currentSelectedDiscountList.length && currentSelectedDiscountList.some(n => withScanList.some(m => m.id === n.id))) {
320
340
  return {
321
341
  type: "clientCalc",
322
342
  isAvailable: true,
@@ -334,7 +354,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
334
354
  oldDiscountList: this.getDiscountList(),
335
355
  newDiscountList: withScanList,
336
356
  holders: this.store.holders || [],
337
- isFormSubject: ((_b = this.store.bookingSubject) == null ? void 0 : _b.type) === "form",
357
+ isFormSubject: this.store.bookingSubject?.type === 'form',
338
358
  orderTotalAmount: this.store.orderTotalAmount || 0
339
359
  }) || {
340
360
  isAvailable: false,
@@ -345,10 +365,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
345
365
  this.setDiscountList(newDiscountList || []);
346
366
  this.store.originalDiscountList = newDiscountList || [];
347
367
  this.setProductList(newProductList || []);
348
- if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop" && !((resultDiscountList[0].customer_id || 1) === 1)) {
349
- await this.getCustomerWallet(
350
- resultDiscountList[0].customer_id
351
- );
368
+ if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1)) {
369
+ await this.getCustomerWallet(resultDiscountList[0].customer_id);
352
370
  }
353
371
  }
354
372
  return {
@@ -359,60 +377,52 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
359
377
  unavailableReason
360
378
  };
361
379
  } catch (error) {
362
- console.error("[ShopDiscount] 扫码出错:", error);
380
+ console.error('[ShopDiscount] 扫码出错:', error);
363
381
  return {
364
382
  type: "clientCalc",
365
383
  isAvailable: false,
366
384
  productList: this.store.productList || [],
367
385
  discountList: this.getDiscountList(),
368
- unavailableReason: import_types.UnavailableReason.Unknown
386
+ unavailableReason: _types.UnavailableReason.Unknown
369
387
  };
370
388
  }
371
389
  }
372
390
  calcDiscountApplicableProductTotalPrice(discount) {
373
- var _a;
374
- return (_a = this.store.discount) == null ? void 0 : _a.calcDiscountApplicableProductTotalPrice(
375
- discount
376
- );
391
+ return this.store.discount?.calcDiscountApplicableProductTotalPrice(discount);
377
392
  }
393
+
378
394
  // =========== 私有辅助方法 ===========
395
+
379
396
  // 获取客户
380
397
  getCustomer() {
381
398
  return this.store.customer;
382
399
  }
400
+
383
401
  // 是否是walkIn
384
402
  isWalkIn() {
385
- var _a;
386
- return (((_a = this.getCustomer()) == null ? void 0 : _a.id) || 1) === 1;
403
+ return (this.getCustomer()?.id || 1) === 1;
387
404
  }
405
+
388
406
  // 触发优惠列表变更事件
389
407
  async emitDiscountListChange(discountList) {
390
- await this.core.effects.emit(
391
- `${this.name}:onDiscountListChange`,
392
- discountList
393
- );
408
+ await this.core.effects.emit(`${this.name}:onDiscountListChange`, discountList);
394
409
  }
410
+
395
411
  // 设置优惠券列表
396
412
  setDiscountList(discountList) {
397
- var _a;
398
413
  const productList = this.store.productList || [];
399
414
  const editModeDiscountList = [];
400
- productList.forEach((item) => {
401
- var _a2;
415
+ productList.forEach(item => {
402
416
  if (item.booking_id) {
403
- const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
404
- (item.discount_list || []).forEach((discount) => {
405
- var _a3, _b, _c, _d, _e;
406
- if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
407
- const index = editModeDiscountList.findIndex((n) => {
408
- var _a4;
409
- return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
410
- });
417
+ const product = this.hooks?.getProduct(item);
418
+ (item.discount_list || []).forEach(discount => {
419
+ if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
420
+ const index = editModeDiscountList.findIndex(n => n.id === (discount.discount?.resource_id || discount.id));
411
421
  if (index !== -1) {
412
422
  editModeDiscountList[index] = {
413
423
  ...editModeDiscountList[index],
414
- amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
415
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_a3 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a3.product_discount_difference) || 0).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
424
+ amount: new _decimal.default(discount.amount || 0).plus(new _decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
425
+ savedAmount: new _decimal.default(discount.amount || 0).times(product?.quantity || product?.num || 1).plus(discount?.metadata?.product_discount_difference || 0).plus(new _decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
416
426
  };
417
427
  } else {
418
428
  if (discount.type && !discount.tag) {
@@ -423,44 +433,34 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
423
433
  name: discount.name || discount.discount.title.auto,
424
434
  isEditMode: true,
425
435
  limited_relation_product_data: {},
426
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0).toNumber(),
436
+ savedAmount: new _decimal.default(discount.amount || 0).times(product?.quantity || product?.num || 1).plus(discount?.metadata?.product_discount_difference || 0).toNumber(),
427
437
  isAvailable: true,
428
- id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
429
- format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
438
+ id: discount.discount?.resource_id || discount.id,
439
+ format_title: discount.discount?.title || discount.format_title,
430
440
  isDisabled: true,
431
441
  isSelected: true,
432
- product_id: ((_e = discount.discount) == null ? void 0 : _e.product_id) || discount.product_id
442
+ product_id: discount.discount?.product_id || discount.product_id
433
443
  });
434
444
  }
435
445
  }
436
446
  });
437
447
  }
438
448
  });
439
- const newDiscountList = [
440
- ...editModeDiscountList,
441
- ...discountList.filter((item) => !item.isDisabled)
442
- ];
443
- const isProductFree = (id) => {
444
- var _a2;
445
- const targetProduct = productList.find((n) => n.id === id);
446
- if (!targetProduct)
447
- return false;
448
- const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
449
- return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
449
+ const newDiscountList = [...editModeDiscountList, ...discountList.filter(item => !item.isDisabled)];
450
+ const isProductFree = id => {
451
+ const targetProduct = productList.find(n => n.id === id);
452
+ if (!targetProduct) return false;
453
+ const product = this.hooks?.getProduct(targetProduct);
454
+ // 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
455
+ // 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
456
+ return Number(product?.total) <= 0 && (Number(product?.origin_total) <= 0 || !product?.origin_total) || (0, _lodashEs.isBoolean)(product?.vouchersApplicable) && !product?.vouchersApplicable;
450
457
  };
451
- const allUsedProductIds = newDiscountList.filter((item) => !(item == null ? void 0 : item.isEditMode)).map((n) => {
452
- var _a2;
453
- return n.isSelected ? ((_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
454
- var _a3;
455
- return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
456
- })) || n.product_id : [];
457
- }).flat();
458
- newDiscountList.forEach((item) => {
459
- var _a2;
460
- const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
461
- var _a3;
462
- const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
463
- const targetIdTimes = (allUsedProductIds == null ? void 0 : allUsedProductIds.filter((n) => n === id).length) || 0;
458
+ const allUsedProductIds = newDiscountList.filter(item => !item?.isEditMode).map(n => n.isSelected ? n.appliedProductDetails?.map(n => n.discount?.product_id) || n.product_id : []).flat();
459
+ newDiscountList.forEach(item => {
460
+ const isAllProductUsedOrFree = item.applicableProductIds?.every(id => {
461
+ // 检查当前 id是否在 item.applicableProductIds 里出现了几次,且要求次数和 item.applicableProductIds 里出现的次数一致
462
+ const sameIdTimes = item.applicableProductIds?.filter(n => n === id).length || 1;
463
+ const targetIdTimes = allUsedProductIds?.filter(n => n === id).length || 0;
464
464
  return targetIdTimes >= sameIdTimes || isProductFree(id);
465
465
  });
466
466
  if (!item.isSelected && isAllProductUsedOrFree) {
@@ -469,95 +469,89 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
469
469
  item.isDisabledForProductUsed = false;
470
470
  }
471
471
  });
472
- (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
472
+ this.store.discount?.setDiscountList(newDiscountList);
473
473
  this.emitDiscountListChange(newDiscountList);
474
474
  return newDiscountList;
475
475
  }
476
+
476
477
  // 获取优惠券列表
477
478
  getDiscountList() {
478
- var _a;
479
- return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
479
+ return this.store.discount?.getDiscountList() || [];
480
480
  }
481
+
481
482
  // 获取客户钱包信息
482
483
  async getCustomerWallet(id) {
483
484
  try {
484
485
  const result = await this.request.get(`/customer/info/${id}`, {
485
486
  with_trashed: 1
486
487
  });
487
- if (result == null ? void 0 : result.data) {
488
- const { ...customer } = result.data;
488
+ if (result?.data) {
489
+ const {
490
+ ...customer
491
+ } = result.data;
489
492
  this.setCustomer(customer);
490
- await this.core.effects.emit(
491
- `${this.name}:onScanCustomerChange`,
492
- customer
493
- );
493
+ await this.core.effects.emit(`${this.name}:onScanCustomerChange`, customer);
494
494
  }
495
495
  } catch (error) {
496
- console.error("[ShopDiscount] 获取客户钱包信息出错:", error);
496
+ console.error('[ShopDiscount] 获取客户钱包信息出错:', error);
497
497
  }
498
498
  }
499
499
  async bestDiscount(cb) {
500
- var _a;
501
500
  const newDiscountList = this.store.originalDiscountList;
502
501
  this.setDiscountList(newDiscountList);
503
- if ((_a = this.store.productList) == null ? void 0 : _a.length) {
502
+ if (this.store.productList?.length) {
504
503
  const result = this.calcDiscount(this.store.productList);
505
- cb == null ? void 0 : cb(result);
506
- await this.core.effects.emit(
507
- `${this.name}:onLoadPrepareCalcResult`,
508
- result
509
- );
504
+ cb?.(result);
505
+ await this.core.effects.emit(`${this.name}:onLoadPrepareCalcResult`, result);
510
506
  }
511
- await this.core.effects.emit(
512
- `${this.name}:onLoadDiscountList`,
513
- newDiscountList
514
- );
507
+ await this.core.effects.emit(`${this.name}:onLoadDiscountList`, newDiscountList);
515
508
  }
509
+
516
510
  // 加载准备配置
517
511
  async loadPrepareConfig(params) {
518
- var _a, _b, _c, _d, _e;
519
512
  try {
520
513
  const orderId = this.store.orderId;
521
- const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
522
- const prepareConfigResult = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
514
+ const customerId = params.customerId || this.getCustomer()?.id;
515
+ // if (customerId === 1 || !customerId) {
516
+ // return
517
+ // }
518
+
519
+ const prepareConfigResult = await this.store.discount?.loadPrepareConfig({
523
520
  customer_id: customerId,
524
- action: orderId ? "edit" : "create",
521
+ action: orderId ? 'edit' : 'create',
525
522
  with_good_pass: 1,
526
523
  with_discount_card: 1,
527
524
  with_wallet_pass_holder: 1,
528
525
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
529
- ...orderId ? { order_id: orderId } : {}
530
- }));
531
- const goodPassList = (prepareConfigResult == null ? void 0 : prepareConfigResult.discountList) || [];
532
- const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
533
- (item) => item.isScan
534
- );
535
- const scanDiscountIds = scanDiscount.map((n) => n.id);
536
- const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
537
- const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
526
+ ...(orderId ? {
527
+ order_id: orderId
528
+ } : {})
529
+ });
530
+ const goodPassList = prepareConfigResult?.discountList || [];
531
+ const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
532
+
533
+ // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
534
+ const scanDiscountIds = scanDiscount.map(n => n.id);
535
+ const newGoodPassList = goodPassList?.filter(n => !scanDiscountIds.includes(n.id));
536
+ const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
537
+
538
+ // 存储原始优惠券列表
538
539
  this.store.originalDiscountList = newDiscountList;
539
- await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
540
+ await this.store.discount?.setOriginalDiscountList(newDiscountList);
541
+
542
+ // 根据当前预约时间过滤优惠券列表
540
543
  const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
541
544
  this.store.filteredDiscountList = filteredDiscountList;
542
545
  this.setDiscountList(filteredDiscountList || []);
543
- if ((_e = this.store.productList) == null ? void 0 : _e.length) {
546
+ if (this.store.productList?.length) {
544
547
  const result = this.calcDiscount(this.store.productList);
545
- await this.core.effects.emit(
546
- `${this.name}:onLoadPrepareCalcResult`,
547
- result
548
- );
548
+ await this.core.effects.emit(`${this.name}:onLoadPrepareCalcResult`, result);
549
549
  }
550
- await this.core.effects.emit(
551
- `${this.name}:onLoadDiscountList`,
552
- filteredDiscountList
553
- );
550
+ await this.core.effects.emit(`${this.name}:onLoadDiscountList`, filteredDiscountList);
554
551
  } catch (error) {
555
- console.error("[ShopDiscount] 加载准备配置出错:", error);
552
+ console.error('[ShopDiscount] 加载准备配置出错:', error);
556
553
  }
557
554
  }
558
- };
559
- var ShopDiscount_default = ShopDiscountImpl;
560
- // Annotate the CommonJS export names for ESM import in node:
561
- 0 && (module.exports = {
562
- ShopDiscountImpl
563
- });
555
+ }
556
+ exports.ShopDiscountImpl = ShopDiscountImpl;
557
+ var _default = exports.default = ShopDiscountImpl;