@pisell/pisellos 0.0.228 → 0.0.229

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.
@@ -20,8 +20,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
20
20
  with_discount_card: 0 | 1;
21
21
  customer_id: number;
22
22
  }): Promise<Discount[]>;
23
- batchSearch(code: string): Promise<Discount[]>;
23
+ batchSearch(code: string, customerId?: number): Promise<Discount[]>;
24
24
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
25
+ private checkUsageCreditsLimit;
25
26
  uniqueByProductId(discountList: Discount[]): Discount[];
26
27
  filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
27
28
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
@@ -145,7 +145,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
145
145
  }, {
146
146
  key: "batchSearch",
147
147
  value: function () {
148
- var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code) {
148
+ var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code, customerId) {
149
149
  var result, resultDiscountList;
150
150
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
151
151
  while (1) switch (_context4.prev = _context4.next) {
@@ -156,7 +156,10 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
156
156
  translate_flag: 1,
157
157
  tags: ['good_pass', 'product_discount_card'],
158
158
  available: 1,
159
- relation_product: 1
159
+ relation_product: 1,
160
+ with: ['extensionData'],
161
+ order_behavior_count: 1,
162
+ order_behavior_count_customer_id: customerId || 1
160
163
  });
161
164
  case 2:
162
165
  result = _context4.sent;
@@ -168,7 +171,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
168
171
  }
169
172
  }, _callee4, this);
170
173
  }));
171
- function batchSearch(_x5) {
174
+ function batchSearch(_x5, _x6) {
172
175
  return _batchSearch.apply(this, arguments);
173
176
  }
174
177
  return batchSearch;
@@ -176,11 +179,71 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
176
179
  }, {
177
180
  key: "filterEnabledDiscountList",
178
181
  value: function filterEnabledDiscountList(discountList) {
182
+ var _this2 = this;
179
183
  return discountList.filter(function (discount) {
180
- return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
184
+ return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && _this2.checkUsageCreditsLimit(discount);
181
185
  });
182
186
  }
183
187
 
188
+ // 检查使用次数限制
189
+ }, {
190
+ key: "checkUsageCreditsLimit",
191
+ value: function checkUsageCreditsLimit(discount) {
192
+ // 如果没有 extension_data,则不需要限制
193
+ if (!discount.extension_data || discount.extension_data.length === 0) {
194
+ return true;
195
+ }
196
+
197
+ // 查找 field_key 为 usage_credits 的数据
198
+ var usageCreditsData = discount.extension_data.find(function (data) {
199
+ return data.field_key === 'usage_credits';
200
+ });
201
+
202
+ // 如果没有找到 usage_credits 数据,则不需要限制
203
+ if (!usageCreditsData) {
204
+ return true;
205
+ }
206
+ var value = usageCreditsData.value;
207
+
208
+ // 检查总次数限制
209
+ if (value.total_credits && value.total_credits > 0) {
210
+ if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
211
+ return false;
212
+ }
213
+ }
214
+
215
+ // 检查单用户限制
216
+ if (value.per_user_limit && value.per_user_limit > 0) {
217
+ if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
218
+ return false;
219
+ }
220
+ }
221
+
222
+ // 检查单日限制
223
+ if (value.max_per_day && value.max_per_day > 0) {
224
+ if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
225
+ return false;
226
+ }
227
+ }
228
+
229
+ // 检查单周限制
230
+ if (value.max_per_week && value.max_per_week > 0) {
231
+ if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
232
+ return false;
233
+ }
234
+ }
235
+
236
+ // 检查单月限制
237
+ if (value.max_per_month && value.max_per_month > 0) {
238
+ if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
239
+ return false;
240
+ }
241
+ }
242
+
243
+ // 所有检查都通过
244
+ return true;
245
+ }
246
+
184
247
  // 根据productIds去重
185
248
  }, {
186
249
  key: "uniqueByProductId",
@@ -36,6 +36,25 @@ interface ApplicableProductDetails {
36
36
  title?: string;
37
37
  };
38
38
  }
39
+ interface UsageCreditsValue {
40
+ total_credits: number;
41
+ per_user_limit: number;
42
+ max_per_day: number;
43
+ max_per_week: number;
44
+ max_per_month: number;
45
+ }
46
+ interface ExtensionData {
47
+ id: number;
48
+ shop_id: number;
49
+ product_id: number;
50
+ field_id: number;
51
+ field_key: string;
52
+ type: string;
53
+ value: UsageCreditsValue | Record<string, any> | string | number | boolean | any[];
54
+ created_at: string | null;
55
+ updated_at: string | null;
56
+ deleted_at: string | null;
57
+ }
39
58
  export interface Discount {
40
59
  id: number;
41
60
  product_name: string;
@@ -70,6 +89,12 @@ export interface Discount {
70
89
  appliedProductDetails: ApplicableProductDetails[];
71
90
  isDisabledForProductUsed?: boolean;
72
91
  amount?: number;
92
+ extension_data?: ExtensionData[];
93
+ total_order_behavior_count?: number;
94
+ today_order_behavior_count?: number;
95
+ week_order_behavior_count?: number;
96
+ month_order_behavior_count?: number;
97
+ customer_order_behavior_count?: number;
73
98
  }
74
99
  export interface DiscountState {
75
100
  discountList: Discount[];
@@ -1281,7 +1281,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1281
1281
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1282
1282
  if (!allOriginResources.length) {
1283
1283
  var dateList = this.store.date.getDateList();
1284
- dateList.forEach(function (n) {
1284
+ dateList === null || dateList === void 0 || dateList.forEach(function (n) {
1285
1285
  if (n.resource) allOriginResources.push.apply(allOriginResources, _toConsumableArray(n.resource));
1286
1286
  });
1287
1287
  }
@@ -34,7 +34,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
34
34
  discountList: Discount[];
35
35
  };
36
36
  setProductList(productList: Record<string, any>[]): void;
37
- scanCode(code: string): Promise<{
37
+ scanCode(code: string, customerId?: number): Promise<{
38
38
  isAvailable: boolean;
39
39
  productList: Record<string, any>[];
40
40
  discountList: Discount[];
@@ -305,14 +305,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
305
305
  }, {
306
306
  key: "scanCode",
307
307
  value: function () {
308
- var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code) {
308
+ var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
309
309
  var _this$store$discount3, resultDiscountList, rulesModule, withScanList, _ref3, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
310
310
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
311
311
  while (1) switch (_context5.prev = _context5.next) {
312
312
  case 0:
313
313
  _context5.prev = 0;
314
314
  _context5.next = 3;
315
- return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code);
315
+ return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, customerId);
316
316
  case 3:
317
317
  _context5.t0 = _context5.sent;
318
318
  if (_context5.t0) {
@@ -394,7 +394,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
394
394
  }
395
395
  }, _callee5, this, [[0, 23]]);
396
396
  }));
397
- function scanCode(_x4) {
397
+ function scanCode(_x4, _x5) {
398
398
  return _scanCode.apply(this, arguments);
399
399
  }
400
400
  return scanCode;
@@ -439,7 +439,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
439
439
  }
440
440
  }, _callee6, this);
441
441
  }));
442
- function emitDiscountListChange(_x5) {
442
+ function emitDiscountListChange(_x6) {
443
443
  return _emitDiscountListChange.apply(this, arguments);
444
444
  }
445
445
  return emitDiscountListChange;
@@ -576,7 +576,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
576
576
  }
577
577
  }, _callee7, this, [[0, 11]]);
578
578
  }));
579
- function getCustomerWallet(_x6) {
579
+ function getCustomerWallet(_x7) {
580
580
  return _getCustomerWallet.apply(this, arguments);
581
581
  }
582
582
  return getCustomerWallet;
@@ -636,7 +636,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
636
636
  }
637
637
  }, _callee8, this, [[0, 18]]);
638
638
  }));
639
- function loadPrepareConfig(_x7) {
639
+ function loadPrepareConfig(_x8) {
640
640
  return _loadPrepareConfig.apply(this, arguments);
641
641
  }
642
642
  return loadPrepareConfig;
@@ -20,8 +20,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
20
20
  with_discount_card: 0 | 1;
21
21
  customer_id: number;
22
22
  }): Promise<Discount[]>;
23
- batchSearch(code: string): Promise<Discount[]>;
23
+ batchSearch(code: string, customerId?: number): Promise<Discount[]>;
24
24
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
25
+ private checkUsageCreditsLimit;
25
26
  uniqueByProductId(discountList: Discount[]): Discount[];
26
27
  filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
27
28
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
@@ -89,22 +89,64 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
89
89
  ) || [];
90
90
  return goodPassList;
91
91
  }
92
- async batchSearch(code) {
92
+ async batchSearch(code, customerId) {
93
93
  const result = await this.request.get(`/machinecode/batch-search`, {
94
94
  code,
95
95
  translate_flag: 1,
96
96
  tags: ["good_pass", "product_discount_card"],
97
97
  available: 1,
98
- relation_product: 1
98
+ relation_product: 1,
99
+ with: ["extensionData"],
100
+ order_behavior_count: 1,
101
+ order_behavior_count_customer_id: customerId || 1
99
102
  });
100
103
  const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
101
104
  return resultDiscountList;
102
105
  }
103
106
  filterEnabledDiscountList(discountList) {
104
107
  return discountList.filter(
105
- (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)
108
+ (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)
106
109
  );
107
110
  }
111
+ // 检查使用次数限制
112
+ checkUsageCreditsLimit(discount) {
113
+ if (!discount.extension_data || discount.extension_data.length === 0) {
114
+ return true;
115
+ }
116
+ const usageCreditsData = discount.extension_data.find(
117
+ (data) => data.field_key === "usage_credits"
118
+ );
119
+ if (!usageCreditsData) {
120
+ return true;
121
+ }
122
+ const value = usageCreditsData.value;
123
+ if (value.total_credits && value.total_credits > 0) {
124
+ if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
125
+ return false;
126
+ }
127
+ }
128
+ if (value.per_user_limit && value.per_user_limit > 0) {
129
+ if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
130
+ return false;
131
+ }
132
+ }
133
+ if (value.max_per_day && value.max_per_day > 0) {
134
+ if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
135
+ return false;
136
+ }
137
+ }
138
+ if (value.max_per_week && value.max_per_week > 0) {
139
+ if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
140
+ return false;
141
+ }
142
+ }
143
+ if (value.max_per_month && value.max_per_month > 0) {
144
+ if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
145
+ return false;
146
+ }
147
+ }
148
+ return true;
149
+ }
108
150
  // 根据productIds去重
109
151
  uniqueByProductId(discountList) {
110
152
  return (0, import_utils.uniqueById)(discountList, "product_id");
@@ -36,6 +36,25 @@ interface ApplicableProductDetails {
36
36
  title?: string;
37
37
  };
38
38
  }
39
+ interface UsageCreditsValue {
40
+ total_credits: number;
41
+ per_user_limit: number;
42
+ max_per_day: number;
43
+ max_per_week: number;
44
+ max_per_month: number;
45
+ }
46
+ interface ExtensionData {
47
+ id: number;
48
+ shop_id: number;
49
+ product_id: number;
50
+ field_id: number;
51
+ field_key: string;
52
+ type: string;
53
+ value: UsageCreditsValue | Record<string, any> | string | number | boolean | any[];
54
+ created_at: string | null;
55
+ updated_at: string | null;
56
+ deleted_at: string | null;
57
+ }
39
58
  export interface Discount {
40
59
  id: number;
41
60
  product_name: string;
@@ -70,6 +89,12 @@ export interface Discount {
70
89
  appliedProductDetails: ApplicableProductDetails[];
71
90
  isDisabledForProductUsed?: boolean;
72
91
  amount?: number;
92
+ extension_data?: ExtensionData[];
93
+ total_order_behavior_count?: number;
94
+ today_order_behavior_count?: number;
95
+ week_order_behavior_count?: number;
96
+ month_order_behavior_count?: number;
97
+ customer_order_behavior_count?: number;
73
98
  }
74
99
  export interface DiscountState {
75
100
  discountList: Discount[];
@@ -693,7 +693,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
693
693
  }
694
694
  if (!allOriginResources.length) {
695
695
  const dateList = this.store.date.getDateList();
696
- dateList.forEach((n) => {
696
+ dateList == null ? void 0 : dateList.forEach((n) => {
697
697
  if (n.resource)
698
698
  allOriginResources.push(...n.resource);
699
699
  });
@@ -34,7 +34,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
34
34
  discountList: Discount[];
35
35
  };
36
36
  setProductList(productList: Record<string, any>[]): void;
37
- scanCode(code: string): Promise<{
37
+ scanCode(code: string, customerId?: number): Promise<{
38
38
  isAvailable: boolean;
39
39
  productList: Record<string, any>[];
40
40
  discountList: Discount[];
@@ -199,10 +199,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
199
199
  this.store.productList = productList;
200
200
  }
201
201
  // 扫码输入code
202
- async scanCode(code) {
202
+ async scanCode(code, customerId) {
203
203
  var _a, _b;
204
204
  try {
205
- const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code)) || [];
205
+ const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
206
206
  const rulesModule = this.store.rules;
207
207
  if (!rulesModule) {
208
208
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.228",
4
+ "version": "0.0.229",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",