@pisell/pisellos 2.1.172 → 2.1.174

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 (238) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +0 -1
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +26 -99
  6. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  7. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -2
  8. package/dist/model/strategy/adapter/walletPass/evaluator.js +12 -63
  9. package/dist/model/strategy/adapter/walletPass/locales.js +3 -12
  10. package/dist/model/strategy/engine.d.ts +5 -18
  11. package/dist/model/strategy/engine.js +45 -145
  12. package/dist/model/strategy/type.d.ts +0 -17
  13. package/dist/model/strategy/type.js +0 -4
  14. package/dist/modules/Cart/types.d.ts +0 -2
  15. package/dist/modules/Cart/utils/cartProduct.js +25 -56
  16. package/dist/modules/Cart/utils/changePrice.js +16 -9
  17. package/dist/modules/Discount/availability.d.ts +7 -0
  18. package/dist/modules/Discount/availability.js +52 -0
  19. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  20. package/dist/modules/Discount/entitlementPass.js +147 -0
  21. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  22. package/dist/modules/Discount/entitlementState.js +205 -0
  23. package/dist/modules/Discount/index.d.ts +12 -3
  24. package/dist/modules/Discount/index.js +211 -17
  25. package/dist/modules/Discount/types.d.ts +42 -22
  26. package/dist/modules/Holder/index.d.ts +48 -0
  27. package/dist/modules/Holder/index.js +640 -0
  28. package/dist/modules/Holder/types.d.ts +123 -0
  29. package/dist/modules/Holder/types.js +1 -0
  30. package/dist/modules/Holder/utils.d.ts +13 -0
  31. package/dist/modules/Holder/utils.js +34 -0
  32. package/dist/modules/OpenData/index.d.ts +24 -0
  33. package/dist/modules/OpenData/index.js +173 -0
  34. package/dist/modules/OpenData/types.d.ts +73 -0
  35. package/dist/modules/OpenData/types.js +1 -0
  36. package/dist/modules/OpenData/utils.d.ts +2 -0
  37. package/dist/modules/OpenData/utils.js +75 -0
  38. package/dist/modules/Order/index.d.ts +67 -1
  39. package/dist/modules/Order/index.js +923 -30
  40. package/dist/modules/Order/types.d.ts +176 -12
  41. package/dist/modules/Order/types.js +2 -0
  42. package/dist/modules/Order/utils.d.ts +128 -0
  43. package/dist/modules/Order/utils.js +621 -5
  44. package/dist/modules/Payment/index.d.ts +1 -2
  45. package/dist/modules/Payment/index.js +7 -10
  46. package/dist/modules/Payment/utils.js +0 -3
  47. package/dist/modules/Payment/walletpass.d.ts +0 -23
  48. package/dist/modules/Payment/walletpass.js +95 -191
  49. package/dist/modules/Product/types.d.ts +7 -0
  50. package/dist/modules/Product/utils.js +2 -2
  51. package/dist/modules/ProductList/index.d.ts +1 -1
  52. package/dist/modules/ProductList/index.js +4 -3
  53. package/dist/modules/Quotation/index.d.ts +48 -0
  54. package/dist/modules/Quotation/index.js +248 -0
  55. package/dist/modules/Quotation/types.d.ts +42 -0
  56. package/dist/modules/Quotation/types.js +1 -0
  57. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  58. package/dist/modules/Rules/entitlementLines.js +157 -0
  59. package/dist/modules/Rules/index.d.ts +17 -11
  60. package/dist/modules/Rules/index.js +495 -726
  61. package/dist/modules/Rules/types.d.ts +2 -4
  62. package/dist/modules/SalesSummary/index.d.ts +63 -0
  63. package/dist/modules/SalesSummary/index.js +174 -0
  64. package/dist/modules/SalesSummary/types.d.ts +60 -0
  65. package/dist/modules/SalesSummary/types.js +1 -0
  66. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  67. package/dist/modules/SalesSummary/utils.js +480 -0
  68. package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
  69. package/dist/modules/ScanOrderLogger/index.js +174 -0
  70. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  71. package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
  72. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  73. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  74. package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
  75. package/dist/modules/ScanOrderLogger/types.js +1 -0
  76. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  77. package/dist/modules/Schedule/utils.d.ts +1 -1
  78. package/dist/modules/Summary/types.d.ts +0 -2
  79. package/dist/modules/Summary/utils.d.ts +3 -9
  80. package/dist/modules/Summary/utils.js +67 -57
  81. package/dist/modules/index.d.ts +5 -0
  82. package/dist/modules/index.js +6 -1
  83. package/dist/plugins/window.d.ts +3 -2
  84. package/dist/solution/BookingByStep/index.d.ts +17 -3
  85. package/dist/solution/BookingByStep/index.js +322 -247
  86. package/dist/solution/BookingByStep/types.d.ts +4 -1
  87. package/dist/solution/BookingByStep/types.js +7 -1
  88. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  89. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  90. package/dist/solution/Checkout/index.js +0 -2
  91. package/dist/solution/ScanOrder/index.d.ts +158 -0
  92. package/dist/solution/ScanOrder/index.js +3474 -0
  93. package/dist/solution/ScanOrder/types.d.ts +307 -0
  94. package/dist/solution/ScanOrder/types.js +35 -0
  95. package/dist/solution/ScanOrder/utils.d.ts +172 -0
  96. package/dist/solution/ScanOrder/utils.js +796 -0
  97. package/dist/solution/ShopDiscount/index.d.ts +6 -2
  98. package/dist/solution/ShopDiscount/index.js +194 -110
  99. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  100. package/dist/solution/ShopDiscount/types.js +1 -2
  101. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  102. package/dist/solution/ShopDiscount/utils.js +52 -27
  103. package/dist/solution/VenueBooking/index.d.ts +225 -0
  104. package/dist/solution/VenueBooking/index.js +3749 -0
  105. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  106. package/dist/solution/VenueBooking/types.d.ts +156 -0
  107. package/dist/solution/VenueBooking/types.js +21 -0
  108. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  109. package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
  110. package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
  111. package/dist/solution/VenueBooking/utils/resource.js +131 -0
  112. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  113. package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
  114. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  115. package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
  116. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  117. package/dist/solution/VenueBooking/utils.js +1 -0
  118. package/dist/solution/index.d.ts +2 -0
  119. package/dist/solution/index.js +3 -1
  120. package/dist/types/index.d.ts +1 -0
  121. package/lib/apis/picoding.d.ts +0 -0
  122. package/lib/apis/picoding.js +0 -0
  123. package/lib/index.d.ts +0 -1
  124. package/lib/index.js +1 -3
  125. package/lib/model/strategy/adapter/promotion/evaluator.js +8 -57
  126. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  127. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -2
  128. package/lib/model/strategy/adapter/walletPass/evaluator.js +7 -36
  129. package/lib/model/strategy/adapter/walletPass/locales.js +3 -12
  130. package/lib/model/strategy/engine.d.ts +5 -18
  131. package/lib/model/strategy/engine.js +21 -85
  132. package/lib/model/strategy/type.d.ts +0 -17
  133. package/lib/modules/Cart/types.d.ts +0 -2
  134. package/lib/modules/Cart/utils/cartProduct.js +12 -39
  135. package/lib/modules/Cart/utils/changePrice.js +13 -9
  136. package/lib/modules/Discount/availability.d.ts +7 -0
  137. package/lib/modules/Discount/availability.js +91 -0
  138. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  139. package/lib/modules/Discount/entitlementPass.js +184 -0
  140. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  141. package/lib/modules/Discount/entitlementState.js +206 -0
  142. package/lib/modules/Discount/index.d.ts +12 -3
  143. package/lib/modules/Discount/index.js +123 -12
  144. package/lib/modules/Discount/types.d.ts +42 -22
  145. package/lib/modules/Holder/index.d.ts +48 -0
  146. package/lib/modules/Holder/index.js +402 -0
  147. package/lib/modules/Holder/types.d.ts +123 -0
  148. package/lib/modules/Holder/types.js +17 -0
  149. package/lib/modules/Holder/utils.d.ts +13 -0
  150. package/lib/modules/Holder/utils.js +71 -0
  151. package/lib/modules/OpenData/index.d.ts +24 -0
  152. package/lib/modules/OpenData/index.js +119 -0
  153. package/lib/modules/OpenData/types.d.ts +73 -0
  154. package/lib/modules/OpenData/types.js +17 -0
  155. package/lib/modules/OpenData/utils.d.ts +2 -0
  156. package/lib/modules/OpenData/utils.js +111 -0
  157. package/lib/modules/Order/index.d.ts +67 -1
  158. package/lib/modules/Order/index.js +529 -1
  159. package/lib/modules/Order/types.d.ts +176 -12
  160. package/lib/modules/Order/utils.d.ts +128 -0
  161. package/lib/modules/Order/utils.js +514 -2
  162. package/lib/modules/Payment/index.d.ts +1 -2
  163. package/lib/modules/Payment/index.js +0 -1
  164. package/lib/modules/Payment/utils.js +0 -3
  165. package/lib/modules/Payment/walletpass.d.ts +0 -23
  166. package/lib/modules/Payment/walletpass.js +17 -94
  167. package/lib/modules/Product/types.d.ts +7 -0
  168. package/lib/modules/Product/utils.js +2 -2
  169. package/lib/modules/ProductList/index.d.ts +1 -1
  170. package/lib/modules/ProductList/index.js +5 -4
  171. package/lib/modules/Quotation/index.d.ts +48 -0
  172. package/lib/modules/Quotation/index.js +152 -0
  173. package/lib/modules/Quotation/types.d.ts +42 -0
  174. package/lib/modules/Quotation/types.js +17 -0
  175. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  176. package/lib/modules/Rules/entitlementLines.js +158 -0
  177. package/lib/modules/Rules/index.d.ts +17 -11
  178. package/lib/modules/Rules/index.js +548 -798
  179. package/lib/modules/Rules/types.d.ts +2 -4
  180. package/lib/modules/SalesSummary/index.d.ts +63 -0
  181. package/lib/modules/SalesSummary/index.js +105 -0
  182. package/lib/modules/SalesSummary/types.d.ts +60 -0
  183. package/lib/modules/SalesSummary/types.js +17 -0
  184. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  185. package/lib/modules/SalesSummary/utils.js +420 -0
  186. package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
  187. package/lib/modules/ScanOrderLogger/index.js +147 -0
  188. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  189. package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
  190. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  191. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  192. package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
  193. package/lib/modules/ScanOrderLogger/types.js +17 -0
  194. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  195. package/lib/modules/Schedule/utils.d.ts +1 -1
  196. package/lib/modules/Summary/types.d.ts +0 -2
  197. package/lib/modules/Summary/utils.d.ts +3 -9
  198. package/lib/modules/Summary/utils.js +45 -34
  199. package/lib/modules/index.d.ts +5 -0
  200. package/lib/modules/index.js +11 -1
  201. package/lib/plugins/window.d.ts +3 -2
  202. package/lib/solution/BookingByStep/index.d.ts +17 -3
  203. package/lib/solution/BookingByStep/index.js +45 -4
  204. package/lib/solution/BookingByStep/types.d.ts +4 -1
  205. package/lib/solution/BookingByStep/types.js +15 -0
  206. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  207. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  208. package/lib/solution/Checkout/index.js +0 -2
  209. package/lib/solution/ScanOrder/index.d.ts +158 -0
  210. package/lib/solution/ScanOrder/index.js +2135 -0
  211. package/lib/solution/ScanOrder/types.d.ts +307 -0
  212. package/lib/solution/ScanOrder/types.js +36 -0
  213. package/lib/solution/ScanOrder/utils.d.ts +172 -0
  214. package/lib/solution/ScanOrder/utils.js +658 -0
  215. package/lib/solution/ShopDiscount/index.d.ts +6 -2
  216. package/lib/solution/ShopDiscount/index.js +94 -50
  217. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  218. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  219. package/lib/solution/ShopDiscount/utils.js +48 -11
  220. package/lib/solution/VenueBooking/index.d.ts +225 -0
  221. package/lib/solution/VenueBooking/index.js +2073 -0
  222. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  223. package/lib/solution/VenueBooking/types.d.ts +156 -0
  224. package/lib/solution/VenueBooking/types.js +44 -0
  225. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  226. package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
  227. package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
  228. package/lib/solution/VenueBooking/utils/resource.js +92 -0
  229. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  230. package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
  231. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  232. package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
  233. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  234. package/lib/solution/VenueBooking/utils.js +69 -0
  235. package/lib/solution/index.d.ts +2 -0
  236. package/lib/solution/index.js +5 -1
  237. package/lib/types/index.d.ts +1 -0
  238. package/package.json +1 -1
@@ -36,6 +36,8 @@ var import_utils = require("../../solution/ShopDiscount/utils");
36
36
  var import_BaseModule = require("../BaseModule");
37
37
  var import_types = require("./types");
38
38
  var import_decimal = __toESM(require("decimal.js"));
39
+ var import_entitlementPass = require("./entitlementPass");
40
+ var import_availability = require("./availability");
39
41
  var DiscountModule = class extends import_BaseModule.BaseModule {
40
42
  constructor(name, version) {
41
43
  super(name, version);
@@ -92,30 +94,80 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
92
94
  return this.store.originalDiscountList || [];
93
95
  }
94
96
  async loadPrepareConfig(params) {
95
- var _a, _b;
97
+ var _a, _b, _c, _d, _e;
96
98
  const prepareConfig = await this.request.post(
97
99
  `/order/prepare/config`,
98
100
  params
99
101
  );
100
- const goodPassList = this.filterEnabledDiscountList(
101
- [...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [], ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []]
102
- ) || [];
102
+ if (!params.with_entitlement_pass) {
103
+ return this.filterEnabledDiscountList([
104
+ ...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [],
105
+ ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []
106
+ ].filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)));
107
+ }
108
+ const entitlementPassList = ((_c = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _c.entitlement_pass_list) || [];
109
+ const ids = new Set(entitlementPassList.map((item) => String(item.id)));
110
+ const rawDiscountList = [
111
+ ...entitlementPassList,
112
+ ...(((_d = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _d.good_pass_list) || []).filter((item) => !ids.has(String(item.id))),
113
+ ...(((_e = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _e.discount_card_list) || []).filter((item) => !ids.has(String(item.id)))
114
+ ];
115
+ await this.setOriginalDiscountList(rawDiscountList);
116
+ const goodPassList = this.filterEnabledDiscountList(rawDiscountList);
103
117
  return goodPassList;
104
118
  }
105
- async batchSearch(code, customerId) {
106
- const result = await this.request.get(`/machinecode/batch-search`, {
119
+ async batchSearch(code, customerIdOrOptions) {
120
+ var _a, _b;
121
+ const { customerId, orderId, withEntitlementPass } = typeof customerIdOrOptions === "number" ? { customerId: customerIdOrOptions, orderId: void 0, withEntitlementPass: false } : customerIdOrOptions || {};
122
+ const params = {
107
123
  code,
108
124
  translate_flag: 1,
109
- tags: ["good_pass", "product_discount_card"],
110
- available: 1,
111
125
  relation_product: 1,
112
126
  with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
113
127
  order_behavior_count: 1,
114
128
  order_behavior_count_customer_id: customerId || 1,
129
+ ...orderId ? { order_behavior_count_order_id: orderId } : {},
130
+ unified_status_info_flag: 1,
115
131
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
116
- });
117
- const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
118
- return resultDiscountList;
132
+ };
133
+ if (!withEntitlementPass) {
134
+ const result2 = await this.request.get(`/machinecode/batch-search`, {
135
+ ...params,
136
+ tags: ["good_pass", "product_discount_card"]
137
+ });
138
+ return this.filterEnabledDiscountListWithReason(((result2 == null ? void 0 : result2.data) || []).filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)));
139
+ }
140
+ const search = (query) => this.request.get(`/machinecode/batch-search`, query).then(
141
+ (value) => ({ status: "fulfilled", value }),
142
+ (reason) => ({ status: "rejected", reason })
143
+ );
144
+ const [legacy, entitlement] = await Promise.all([
145
+ search({
146
+ ...params,
147
+ tags: ["good_pass", "product_discount_card"]
148
+ }),
149
+ search({
150
+ ...params,
151
+ tags: ["entitlement_pass"],
152
+ with_franchisor_data: 1,
153
+ unified_status_info_flag: 1,
154
+ with: [...params.with, "franchiseeWalletPass:shop_id,source_shop_id,product_id,use"]
155
+ })
156
+ ]);
157
+ const entitlementList = (entitlement.status === "fulfilled" ? ((_a = entitlement.value) == null ? void 0 : _a.data) || [] : []).filter(import_entitlementPass.isEntitlementPass);
158
+ const legacyList = legacy.status === "fulfilled" ? ((_b = legacy.value) == null ? void 0 : _b.data) || [] : [];
159
+ const ids = new Set(entitlementList.map((item) => String(item.id)));
160
+ const result = this.filterEnabledDiscountListWithReason([
161
+ ...entitlementList,
162
+ ...legacyList.filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item) && !ids.has(String(item.id)))
163
+ ]);
164
+ if (!result.discountList.length) {
165
+ if (legacy.status === "rejected")
166
+ throw legacy.reason;
167
+ if (entitlement.status === "rejected")
168
+ throw entitlement.reason;
169
+ }
170
+ return result;
119
171
  }
120
172
  async batchSearchByProductIds(productIds) {
121
173
  const result = await this.request.get(`/machinecode/batch-search`, {
@@ -128,7 +180,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
128
180
  }
129
181
  filterEnabledDiscountList(discountList) {
130
182
  return discountList.filter(
131
- (discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount)
183
+ (discount) => (0, import_entitlementPass.isEntitlementPass)(discount) ? !(0, import_availability.getDiscountLifecycleReason)(discount) : discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount)
132
184
  );
133
185
  }
134
186
  // 检查使用次数限制
@@ -170,6 +222,65 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
170
222
  }
171
223
  return true;
172
224
  }
225
+ // 过滤启用且可用的优惠券,并返回校验失败原因
226
+ filterEnabledDiscountListWithReason(discountList) {
227
+ const entitlementPasses = discountList.filter((item) => (0, import_entitlementPass.isEntitlementPass)(item) && !(0, import_availability.getDiscountLifecycleReason)(item));
228
+ let lists = discountList.filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)).filter((discount) => discount.limit_status === "enable").filter((discount) => {
229
+ const remaining = new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
230
+ return remaining;
231
+ }).map((discount) => {
232
+ const limitFailKey = this.checkUsageCreditsLimitWithFailKey(discount);
233
+ return {
234
+ ...discount,
235
+ usageLimitFailKey: limitFailKey
236
+ };
237
+ });
238
+ const availableLists = lists.filter((item) => !item.usageLimitFailKey && item.unified_available_status !== 0);
239
+ const currentFailDiscount = lists.find((item) => item.usageLimitFailKey);
240
+ return {
241
+ discountList: [...entitlementPasses.map((item) => ({ ...item, usageLimitFailKey: (0, import_availability.getDiscountUsageLimitFailKey)(item) })), ...availableLists],
242
+ unavailableReasonKey: (currentFailDiscount == null ? void 0 : currentFailDiscount.usageLimitFailKey) || discountList.filter(import_entitlementPass.isEntitlementPass).map(import_availability.getDiscountLifecycleReason).find(Boolean) || null
243
+ };
244
+ }
245
+ // 检查使用次数限制,并返回校验失败原因
246
+ checkUsageCreditsLimitWithFailKey(discount) {
247
+ if (!discount.extension_data || discount.extension_data.length === 0) {
248
+ return null;
249
+ }
250
+ const usageCreditsData = discount.extension_data.find(
251
+ (data) => data.field_key === "usage_credits"
252
+ );
253
+ if (!usageCreditsData) {
254
+ return null;
255
+ }
256
+ const value = usageCreditsData.value;
257
+ if (value.total_credits && value.total_credits > 0) {
258
+ if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
259
+ return "total_credits";
260
+ }
261
+ }
262
+ if (value.per_user_limit && value.per_user_limit > 0) {
263
+ if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
264
+ return "per_user_limit";
265
+ }
266
+ }
267
+ if (value.max_per_day && value.max_per_day > 0) {
268
+ if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
269
+ return "max_per_day";
270
+ }
271
+ }
272
+ if (value.max_per_week && value.max_per_week > 0) {
273
+ if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
274
+ return "max_per_week";
275
+ }
276
+ }
277
+ if (value.max_per_month && value.max_per_month > 0) {
278
+ if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
279
+ return "max_per_month";
280
+ }
281
+ }
282
+ return null;
283
+ }
173
284
  // 根据productIds去重
174
285
  uniqueByProductId(discountList) {
175
286
  return (0, import_utils.uniqueById)(discountList, "product_id");
@@ -33,8 +33,8 @@ interface Limitedrelationproductdata {
33
33
  product_ids: number[];
34
34
  product_collection_id: number[];
35
35
  package_sub_item_usage_rules?: PackageSubItemUsageRules;
36
- filter: 0 | 1;
37
- exclude_product_ids: number[];
36
+ exclude_product_ids?: number[];
37
+ filter?: 0 | 1;
38
38
  }
39
39
  interface ApplicableProductDetails {
40
40
  amount: string;
@@ -45,6 +45,8 @@ interface ApplicableProductDetails {
45
45
  num: number;
46
46
  metadata?: {
47
47
  product_discount_difference?: number;
48
+ num?: number;
49
+ custom_product_bundle_map_id?: string;
48
50
  };
49
51
  discount?: {
50
52
  fixed_amount?: number;
@@ -63,6 +65,18 @@ interface UsageCreditsValue {
63
65
  max_per_week: number;
64
66
  max_per_month: number;
65
67
  }
68
+ export type IncludedUses = {
69
+ type: 'limited';
70
+ value: number;
71
+ } | {
72
+ type: 'unlimited';
73
+ value: null;
74
+ };
75
+ export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
76
+ export interface DiscountWithReason {
77
+ discountList: Discount[];
78
+ unavailableReasonKey: DiscountFilterRejectKey | string | null;
79
+ }
66
80
  interface ExtensionData {
67
81
  id: number;
68
82
  shop_id: number;
@@ -88,20 +102,39 @@ export interface Discount {
88
102
  used_par_value: string;
89
103
  limit_status: string;
90
104
  limited_relation_product_data: Limitedrelationproductdata;
91
- balance: string;
105
+ balance?: string | number | null;
92
106
  format_title: Formattitle;
93
107
  metadata?: {
94
- num?: number;
95
108
  discount_card_type?: 'fixed_amount' | 'percent';
96
109
  custom_product_bundle_map_id?: string;
97
110
  validity_type?: "custom_schedule_validity" | "fixed_validity";
98
- discount_calculation_mode: 'item_level' | 'order_level';
99
- holder: {
111
+ included_uses?: IncludedUses;
112
+ discount_calculation_mode?: 'item_level' | 'order_level';
113
+ holder?: {
100
114
  type: "customer" | "custom";
101
115
  };
102
116
  };
103
117
  product: Product;
104
- type: "product" | 'good_pass';
118
+ type?: 'product' | 'good_pass' | 'entitlement_pass' | 'discount_card' | 'product_discount_card';
119
+ shop_id?: number;
120
+ customer_id?: number | string | null;
121
+ holder?: {
122
+ holder_type?: string;
123
+ holder_id?: number | string | Array<number | string>;
124
+ [key: string]: any;
125
+ };
126
+ config?: {
127
+ isAvailable?: boolean;
128
+ maxUsagePerOrder?: number;
129
+ [key: string]: any;
130
+ };
131
+ reason?: string;
132
+ reasonCode?: string;
133
+ is_franchisor_pass?: number;
134
+ franchisee_wallet_pass?: {
135
+ use?: string;
136
+ };
137
+ committedAppliedProductDetails?: ApplicableProductDetails[];
105
138
  resource_id?: number;
106
139
  savedAmount?: number;
107
140
  isEditMode?: boolean;
@@ -116,21 +149,6 @@ export interface Discount {
116
149
  isSelected?: boolean;
117
150
  isAvailable?: boolean;
118
151
  isUsed?: boolean;
119
- config?: {
120
- isAvailable?: boolean;
121
- /** 最大抵扣金额 */
122
- maxDeductionAmount?: number;
123
- /** 每单最多使用张数 */
124
- maxUsagePerOrder?: number;
125
- /** 是否抵扣税费与附加费 */
126
- deductTaxAndFee?: boolean;
127
- /** 适用粒度(多商品共用) */
128
- allowCrossProduct?: boolean;
129
- /** 可用商品数量上限 */
130
- applicableProductLimit?: number;
131
- /** 是否抵扣单规格价格 (Option Price) */
132
- deductOptionPrice?: boolean;
133
- };
134
152
  applicableProductIds?: number[];
135
153
  applicableProductDetails: ApplicableProductDetails[];
136
154
  appliedProductDetails: ApplicableProductDetails[];
@@ -149,6 +167,8 @@ export interface Discount {
149
167
  start_date?: string;
150
168
  start_time?: string;
151
169
  discount_rule_uncheck_flag?: boolean;
170
+ usageLimitFailKey?: string | null;
171
+ unified_available_status?: number | undefined | null;
152
172
  }
153
173
  export interface DiscountState {
154
174
  discountList: Discount[];
@@ -0,0 +1,48 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { IFormInfo, IFormRecord, IFormItemData, IFetchFormInfoParams, IFetchFormRecordsParams, IAddFormRecordParams, IAppendFormRecordParams, IEnsureFormDataParams, IEnsureFormByProductParams, IRefreshAllFormRecordsParams, HolderModuleAPI, HolderFormMap } from './types';
4
+ export * from './types';
5
+ export * from './utils';
6
+ export declare class HolderModule extends BaseModule implements Module, HolderModuleAPI {
7
+ protected defaultName: string;
8
+ protected defaultVersion: string;
9
+ private store;
10
+ private request;
11
+ private cacheId;
12
+ private openCache;
13
+ private fatherModule;
14
+ private isLoading;
15
+ private error;
16
+ /** 已加载过表单数据的 form_id 缓存标记 */
17
+ private loadedFormIds;
18
+ private window;
19
+ constructor(name?: string, version?: string);
20
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
21
+ /** 统一提交 formMap,仅此处触发 store changed */
22
+ private commitFormMap;
23
+ /** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
24
+ private notifyFormMapChanged;
25
+ getHolderFormMap(): HolderFormMap;
26
+ getHolderFormData(formId: number | string): IFormItemData | undefined;
27
+ setFormData(formId: number | string, data: Partial<IFormItemData>): void;
28
+ private ensureFormItem;
29
+ private hasFormData;
30
+ private patchFormMap;
31
+ fetchFormInfo(params: IFetchFormInfoParams): Promise<IFormInfo | IFormInfo[]>;
32
+ fetchRecords(params: IFetchFormRecordsParams): Promise<any>;
33
+ ensureFormData(params: IEnsureFormDataParams): Promise<IFormItemData>;
34
+ ensureFormByProduct(params: IEnsureFormByProductParams): Promise<IFormItemData | null>;
35
+ addFormRecord(params: IAddFormRecordParams): Promise<any>;
36
+ /**
37
+ * UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
38
+ */
39
+ appendFormRecord(params: IAppendFormRecordParams): IFormRecord;
40
+ removeFormRecord(formId: number | string, formRecordId: number): void;
41
+ clearFormData(formId?: number | string): void;
42
+ /**
43
+ * 登录后按当前 holderMap 批量刷新所有表单的 records。
44
+ * 遍历 holderMap,从 form.form 中读取 form_id、shop_id,结合 customer_id 重新拉取记录。
45
+ */
46
+ refreshAllFormRecords(params?: IRefreshAllFormRecordsParams): Promise<HolderFormMap>;
47
+ storeChange(path?: string): void;
48
+ }