@pisell/pisellos 0.0.569 → 0.10.2

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