@pisell/pisellos 1.0.138 → 1.0.139

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.
@@ -18,6 +18,14 @@ interface Formattitle {
18
18
  interface PackageSubItemUsageRules {
19
19
  type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
20
  rules: ("original_price" | "markup_price")[];
21
+ package_scope?: {
22
+ type: 'all_packages' | 'specific_packages';
23
+ exclude_bundle_product_ids: number[];
24
+ include_bundle_product_ids: number[];
25
+ filter: 0 | 1;
26
+ rule: any[];
27
+ rule_type: 'and' | 'or';
28
+ };
21
29
  }
22
30
  interface Limitedrelationproductdata {
23
31
  id: number;
@@ -2230,6 +2230,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2230
2230
  return true;
2231
2231
  }
2232
2232
  var ruleType = usageRules.type;
2233
+ // 套餐适用范围配置
2234
+ var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
2235
+ var _ref8 = packageScope || {},
2236
+ scopeType = _ref8.type,
2237
+ _ref8$exclude_bundle_ = _ref8.exclude_bundle_product_ids,
2238
+ exclude_bundle_product_ids = _ref8$exclude_bundle_ === void 0 ? [] : _ref8$exclude_bundle_,
2239
+ _ref8$include_bundle_ = _ref8.include_bundle_product_ids,
2240
+ include_bundle_product_ids = _ref8$include_bundle_ === void 0 ? [] : _ref8$include_bundle_,
2241
+ _ref8$filter = _ref8.filter,
2242
+ filter = _ref8$filter === void 0 ? 0 : _ref8$filter;
2233
2243
  var isMainProduct = flatItem.type === 'main'; // 单独购买
2234
2244
  var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
2235
2245
 
@@ -2244,10 +2254,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2244
2254
  return true; // 单独购买时可用
2245
2255
  }
2246
2256
  if (isBundleItem) {
2247
- var _flatItem$bundleItem8, _flatItem$bundleItem9;
2257
+ var _flatItem$bundleItem8, _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu;
2248
2258
  // 套餐中购买时,判断是否为原价
2249
2259
  var priceType = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type;
2250
2260
  var priceTypeExt = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type_ext;
2261
+ // 主商品id
2262
+ var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.product_id) || (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || 0;
2251
2263
  // original_price 对应:
2252
2264
  // 1. price_type: "markup" && price_type_ext: "product_price"
2253
2265
  // markup_price 对应:
@@ -2259,16 +2271,43 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2259
2271
 
2260
2272
  // 检查 rules
2261
2273
  if (rules.length > 0) {
2262
- // 检查原价
2263
- if (isOriginalPrice && rules.includes('original_price')) {
2264
- return true;
2274
+ var _isOriginalPrice = isOriginalPrice && rules.includes('original_price');
2275
+ var _isMarkupPrice = isMarkupPrice && rules.includes('markup_price');
2276
+ // 价格是否符合规则:原价或加价
2277
+ var isPriceValid = _isOriginalPrice || _isMarkupPrice;
2278
+ // 套餐适用范围校验
2279
+ var isScopeValid = false;
2280
+
2281
+ // 排除套餐判断
2282
+ if (scopeType === 'all_packages') {
2283
+ // 所有套餐可用
2284
+ if (!filter) {
2285
+ isScopeValid = true;
2286
+ } else {
2287
+ isScopeValid = !exclude_bundle_product_ids.includes(Number(mainProductId));
2288
+ }
2265
2289
  }
2266
2290
 
2267
- // 检查加价
2268
- if (isMarkupPrice && rules.includes('markup_price')) {
2291
+ // 包含套餐判断
2292
+ if (scopeType === 'specific_packages') {
2293
+ isScopeValid = include_bundle_product_ids.includes(Number(mainProductId));
2294
+ }
2295
+
2296
+ // 价格和套餐适用范围都符合,则可用
2297
+ if (isPriceValid && isScopeValid) {
2269
2298
  return true;
2270
2299
  }
2271
2300
 
2301
+ // 检查原价
2302
+ // if (isOriginalPrice && rules.includes('original_price')) {
2303
+ // return true;
2304
+ // }
2305
+
2306
+ // 检查加价
2307
+ // if (isMarkupPrice && rules.includes('markup_price')) {
2308
+ // return true;
2309
+ // }
2310
+
2272
2311
  // 如果都不匹配,则不可用
2273
2312
  return false;
2274
2313
  }
@@ -2285,29 +2324,29 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2285
2324
  return false; // 单独购买时不可用
2286
2325
  }
2287
2326
  if (isBundleItem) {
2288
- var _flatItem$bundleItem10, _flatItem$bundleItem11;
2327
+ var _flatItem$bundleItem11, _flatItem$bundleItem12;
2289
2328
  // 套餐中购买时,判断是否为原价
2290
- var _priceType = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type;
2291
- var _priceTypeExt = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type_ext;
2329
+ var _priceType = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type;
2330
+ var _priceTypeExt = (_flatItem$bundleItem12 = flatItem.bundleItem) === null || _flatItem$bundleItem12 === void 0 ? void 0 : _flatItem$bundleItem12.price_type_ext;
2292
2331
 
2293
2332
  // original_price 对应:
2294
2333
  // 1. price_type: "markup" && price_type_ext: "product_price"
2295
2334
  // markup_price 对应:
2296
2335
  // price_type: "markup" && price_type_ext: ""
2297
2336
  /** 原价 */
2298
- var _isOriginalPrice = _priceType === 'markup' && _priceTypeExt === 'product_price';
2337
+ var _isOriginalPrice2 = _priceType === 'markup' && _priceTypeExt === 'product_price';
2299
2338
  /** 加价 */
2300
- var _isMarkupPrice = _priceType === 'markup' && (_priceTypeExt === '' || !_priceTypeExt);
2339
+ var _isMarkupPrice2 = _priceType === 'markup' && (_priceTypeExt === '' || !_priceTypeExt);
2301
2340
 
2302
2341
  // 检查 rules
2303
2342
  if (rules.length > 0) {
2304
2343
  // 检查原价
2305
- if (_isOriginalPrice && rules.includes('original_price')) {
2344
+ if (_isOriginalPrice2 && rules.includes('original_price')) {
2306
2345
  return true;
2307
2346
  }
2308
2347
 
2309
2348
  // 检查加价
2310
- if (_isMarkupPrice && rules.includes('markup_price')) {
2349
+ if (_isMarkupPrice2 && rules.includes('markup_price')) {
2311
2350
  return true;
2312
2351
  }
2313
2352
 
@@ -2316,7 +2355,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2316
2355
  }
2317
2356
 
2318
2357
  // 原价包括:price_type: "markup" && price_type_ext: "product_price"
2319
- return _isOriginalPrice;
2358
+ return _isOriginalPrice2;
2320
2359
  }
2321
2360
  return false;
2322
2361
  }
@@ -18,6 +18,14 @@ interface Formattitle {
18
18
  interface PackageSubItemUsageRules {
19
19
  type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
20
  rules: ("original_price" | "markup_price")[];
21
+ package_scope?: {
22
+ type: 'all_packages' | 'specific_packages';
23
+ exclude_bundle_product_ids: number[];
24
+ include_bundle_product_ids: number[];
25
+ filter: 0 | 1;
26
+ rule: any[];
27
+ rule_type: 'and' | 'or';
28
+ };
21
29
  }
22
30
  interface Limitedrelationproductdata {
23
31
  id: number;
@@ -1786,7 +1786,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1786
1786
  * @returns 是否可用
1787
1787
  */
1788
1788
  checkPackageSubItemUsageRules(discount, flatItem) {
1789
- var _a, _b, _c, _d;
1789
+ var _a, _b, _c, _d, _e, _f;
1790
1790
  const limitedData = discount.limited_relation_product_data;
1791
1791
  const usageRules = limitedData == null ? void 0 : limitedData.package_sub_item_usage_rules;
1792
1792
  const rules = ["original_price", ...(usageRules == null ? void 0 : usageRules.rules) || []];
@@ -1794,6 +1794,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1794
1794
  return true;
1795
1795
  }
1796
1796
  const ruleType = usageRules.type;
1797
+ const packageScope = usageRules == null ? void 0 : usageRules.package_scope;
1798
+ const { type: scopeType, exclude_bundle_product_ids = [], include_bundle_product_ids = [], filter = 0 } = packageScope || {};
1797
1799
  const isMainProduct = flatItem.type === "main";
1798
1800
  const isBundleItem = flatItem.type === "bundle";
1799
1801
  if (isMainProduct) {
@@ -1806,13 +1808,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1806
1808
  if (isBundleItem) {
1807
1809
  const priceType = (_a = flatItem.bundleItem) == null ? void 0 : _a.price_type;
1808
1810
  const priceTypeExt = (_b = flatItem.bundleItem) == null ? void 0 : _b.price_type_ext;
1811
+ const mainProductId = ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.product_id) || ((_d = flatItem == null ? void 0 : flatItem.originProduct) == null ? void 0 : _d.id) || 0;
1809
1812
  const isOriginalPrice = priceType === "markup" && priceTypeExt === "product_price";
1810
1813
  const isMarkupPrice = priceType === "markup" && (priceTypeExt === "" || !priceTypeExt);
1811
1814
  if (rules.length > 0) {
1812
- if (isOriginalPrice && rules.includes("original_price")) {
1813
- return true;
1815
+ const _isOriginalPrice = isOriginalPrice && rules.includes("original_price");
1816
+ const _isMarkupPrice = isMarkupPrice && rules.includes("markup_price");
1817
+ const isPriceValid = _isOriginalPrice || _isMarkupPrice;
1818
+ let isScopeValid = false;
1819
+ if (scopeType === "all_packages") {
1820
+ if (!filter) {
1821
+ isScopeValid = true;
1822
+ } else {
1823
+ isScopeValid = !exclude_bundle_product_ids.includes(Number(mainProductId));
1824
+ }
1814
1825
  }
1815
- if (isMarkupPrice && rules.includes("markup_price")) {
1826
+ if (scopeType === "specific_packages") {
1827
+ isScopeValid = include_bundle_product_ids.includes(Number(mainProductId));
1828
+ }
1829
+ if (isPriceValid && isScopeValid) {
1816
1830
  return true;
1817
1831
  }
1818
1832
  return false;
@@ -1826,8 +1840,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1826
1840
  return false;
1827
1841
  }
1828
1842
  if (isBundleItem) {
1829
- const priceType = (_c = flatItem.bundleItem) == null ? void 0 : _c.price_type;
1830
- const priceTypeExt = (_d = flatItem.bundleItem) == null ? void 0 : _d.price_type_ext;
1843
+ const priceType = (_e = flatItem.bundleItem) == null ? void 0 : _e.price_type;
1844
+ const priceTypeExt = (_f = flatItem.bundleItem) == null ? void 0 : _f.price_type_ext;
1831
1845
  const isOriginalPrice = priceType === "markup" && priceTypeExt === "product_price";
1832
1846
  const isMarkupPrice = priceType === "markup" && (priceTypeExt === "" || !priceTypeExt);
1833
1847
  if (rules.length > 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.138",
4
+ "version": "1.0.139",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",