@pisell/pisellos 0.0.356 → 0.0.358

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.
@@ -17,10 +17,7 @@ interface Formattitle {
17
17
  }
18
18
  interface PackageSubItemUsageRules {
19
19
  type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
- custom_usage_rules: {
21
- types: ("standalone_product" | "package_sub_item")[];
22
- package_sub_item_rules: ("original_price" | "markup_price")[];
23
- };
20
+ rules: ("original_price" | "markup_price")[];
24
21
  }
25
22
  interface Limitedrelationproductdata {
26
23
  id: number;
@@ -1290,6 +1290,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1290
1290
  value: function checkPackageSubItemUsageRules(discount, flatItem) {
1291
1291
  var limitedData = discount.limited_relation_product_data;
1292
1292
  var usageRules = limitedData === null || limitedData === void 0 ? void 0 : limitedData.package_sub_item_usage_rules;
1293
+ var rules = ['original_price'].concat(_toConsumableArray((usageRules === null || usageRules === void 0 ? void 0 : usageRules.rules) || []));
1293
1294
 
1294
1295
  // 如果没有配置 package_sub_item_usage_rules,则默认可用
1295
1296
  if (!usageRules) {
@@ -1299,6 +1300,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1299
1300
  var isMainProduct = flatItem.type === 'main'; // 单独购买
1300
1301
  var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
1301
1302
 
1303
+ // 主商品直接可用
1304
+ if (isMainProduct) {
1305
+ return true;
1306
+ }
1307
+
1302
1308
  // universal_discount: 单独购买和套餐中(子商品为原价)均可使用
1303
1309
  if (ruleType === 'universal_discount') {
1304
1310
  if (isMainProduct) {
@@ -1325,8 +1331,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1325
1331
  // 套餐中购买时,判断是否为原价
1326
1332
  var _priceType = (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.price_type;
1327
1333
  var _priceTypeExt = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type_ext;
1334
+
1335
+ // original_price 对应:
1336
+ // 1. price_type: "markup" && price_type_ext: "product_price"
1337
+ // markup_price 对应:
1338
+ // price_type: "markup" && price_type_ext: ""
1339
+ /** 原价 */
1340
+ var isOriginalPrice = _priceType === 'markup' && _priceTypeExt === 'product_price';
1341
+ /** 加价 */
1342
+ var isMarkupPrice = _priceType === 'markup' && (_priceTypeExt === '' || !_priceTypeExt);
1343
+
1344
+ // 检查 rules
1345
+ if (rules.length > 0) {
1346
+ // 检查原价
1347
+ if (isOriginalPrice && rules.includes('original_price')) {
1348
+ return true;
1349
+ }
1350
+
1351
+ // 检查加价
1352
+ if (isMarkupPrice && rules.includes('markup_price')) {
1353
+ return true;
1354
+ }
1355
+
1356
+ // 如果都不匹配,则不可用
1357
+ return false;
1358
+ }
1359
+
1328
1360
  // 原价包括:price_type: "markup" && price_type_ext: "product_price"
1329
- return _priceType === 'markup' && _priceTypeExt === 'product_price';
1361
+ return isOriginalPrice;
1330
1362
  }
1331
1363
  return false;
1332
1364
  }
@@ -1336,16 +1368,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1336
1368
  return isMainProduct; // 只有单独购买时可用
1337
1369
  }
1338
1370
 
1371
+ /*
1339
1372
  // custom_usage_rules: 根据自定义规则判断
1340
1373
  if (ruleType === 'custom_usage_rules') {
1341
- var customRules = usageRules.custom_usage_rules;
1342
- if (!customRules) {
1374
+ const customRules = usageRules.custom_usage_rules;
1375
+ if (!customRules) {
1343
1376
  return true; // 如果没有自定义规则,默认可用
1344
1377
  }
1345
- var types = customRules.types,
1346
- package_sub_item_rules = customRules.package_sub_item_rules;
1347
-
1348
- // 判断商品类型是否在允许的类型中
1378
+ const { types, package_sub_item_rules } = customRules;
1379
+ // 判断商品类型是否在允许的类型中
1349
1380
  if (isMainProduct) {
1350
1381
  // 主商品对应 standalone_product
1351
1382
  if (!types.includes('standalone_product')) {
@@ -1353,40 +1384,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1353
1384
  }
1354
1385
  return true; // 主商品不需要判断 package_sub_item_rules
1355
1386
  }
1356
- if (isBundleItem) {
1357
- var _flatItem$bundleItem9, _flatItem$bundleItem10;
1387
+ if (isBundleItem) {
1358
1388
  // bundle子商品对应 package_sub_item
1359
1389
  if (!types.includes('package_sub_item')) {
1360
1390
  return false;
1361
1391
  }
1362
-
1363
- // 如果包含 package_sub_item,还需要判断 price_type
1364
- var _priceType2 = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type;
1365
- var _priceTypeExt2 = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type_ext;
1366
-
1367
- // 检查 package_sub_item_rules
1392
+ // 如果包含 package_sub_item,还需要判断 price_type
1393
+ const priceType = flatItem.bundleItem?.price_type;
1394
+ const priceTypeExt = flatItem.bundleItem?.price_type_ext;
1395
+ // 检查 package_sub_item_rules
1368
1396
  if (package_sub_item_rules && package_sub_item_rules.length > 0) {
1369
1397
  // original_price 对应:
1370
1398
  // 1. price_type: "markup" && price_type_ext: "product_price"
1371
1399
  // markup_price 对应:
1372
1400
  // price_type: "markup" && price_type_ext: ""
1373
-
1374
- var isOriginalPrice = _priceType2 === 'markup' && _priceTypeExt2 === 'product_price';
1375
- var isMarkupPrice = _priceType2 === 'markup' && (_priceTypeExt2 === '' || !_priceTypeExt2);
1376
- if (isOriginalPrice && package_sub_item_rules.includes('original_price')) {
1401
+ const isOriginalPrice = (priceType === 'markup' && priceTypeExt === 'product_price');
1402
+ const isMarkupPrice = priceType === 'markup' && (priceTypeExt === '' || !priceTypeExt);
1403
+ if (isOriginalPrice && package_sub_item_rules.includes('original_price')) {
1377
1404
  return true;
1378
1405
  }
1379
- if (isMarkupPrice && package_sub_item_rules.includes('markup_price')) {
1406
+ if (isMarkupPrice && package_sub_item_rules.includes('markup_price')) {
1380
1407
  return true;
1381
1408
  }
1382
-
1383
- // 如果都不匹配,则不可用
1409
+ // 如果都不匹配,则不可用
1384
1410
  return false;
1385
1411
  }
1386
- return true; // 如果没有 package_sub_item_rules 配置,默认可用
1412
+ return true; // 如果没有 package_sub_item_rules 配置,默认可用
1387
1413
  }
1388
- return true;
1414
+ return true;
1389
1415
  }
1416
+ * */
1390
1417
 
1391
1418
  // 默认可用
1392
1419
  return true;
@@ -24,8 +24,9 @@ export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref) {
24
24
  if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
25
25
  return (product_bundle || []).map(function (d) {
26
26
  var id = d.bundle_product_id;
27
+ var variantId = d.bundle_variant_id;
27
28
  var item = ((capacity === null || capacity === void 0 ? void 0 : capacity.package) || []).find(function (item) {
28
- return item.product_id === id;
29
+ return item.product_id === id || item.product_id === variantId;
29
30
  });
30
31
  return {
31
32
  id: id,
@@ -385,10 +385,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
385
385
  };
386
386
  var formatProduct = function formatProduct(items) {
387
387
  return items.map(function (item) {
388
+ var _item$is_charge_tax;
388
389
  return {
389
390
  product_id: item.product_id,
390
391
  product_variant_id: item.product_variant_id,
391
392
  quantity: item.num,
393
+ // 商品是否含税:1;0
394
+ is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
395
+ // 若商品不含税,计算得到的税费,单位(元)
396
+ tax_fee: item.tax_fee,
392
397
  // 整个商品折扣后的总金额
393
398
  selling_price: item.calculated_selling_price,
394
399
  // 整个商品折扣前的总金额
@@ -17,10 +17,7 @@ interface Formattitle {
17
17
  }
18
18
  interface PackageSubItemUsageRules {
19
19
  type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
- custom_usage_rules: {
21
- types: ("standalone_product" | "package_sub_item")[];
22
- package_sub_item_rules: ("original_price" | "markup_price")[];
23
- };
20
+ rules: ("original_price" | "markup_price")[];
24
21
  }
25
22
  interface Limitedrelationproductdata {
26
23
  id: number;
@@ -994,15 +994,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
994
994
  * @returns 是否可用
995
995
  */
996
996
  checkPackageSubItemUsageRules(discount, flatItem) {
997
- var _a, _b, _c, _d, _e, _f;
997
+ var _a, _b, _c, _d;
998
998
  const limitedData = discount.limited_relation_product_data;
999
999
  const usageRules = limitedData == null ? void 0 : limitedData.package_sub_item_usage_rules;
1000
+ const rules = ["original_price", ...(usageRules == null ? void 0 : usageRules.rules) || []];
1000
1001
  if (!usageRules) {
1001
1002
  return true;
1002
1003
  }
1003
1004
  const ruleType = usageRules.type;
1004
1005
  const isMainProduct = flatItem.type === "main";
1005
1006
  const isBundleItem = flatItem.type === "bundle";
1007
+ if (isMainProduct) {
1008
+ return true;
1009
+ }
1006
1010
  if (ruleType === "universal_discount") {
1007
1011
  if (isMainProduct) {
1008
1012
  return true;
@@ -1021,45 +1025,23 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1021
1025
  if (isBundleItem) {
1022
1026
  const priceType = (_c = flatItem.bundleItem) == null ? void 0 : _c.price_type;
1023
1027
  const priceTypeExt = (_d = flatItem.bundleItem) == null ? void 0 : _d.price_type_ext;
1024
- return priceType === "markup" && priceTypeExt === "product_price";
1025
- }
1026
- return false;
1027
- }
1028
- if (ruleType === "single_item_promo") {
1029
- return isMainProduct;
1030
- }
1031
- if (ruleType === "custom_usage_rules") {
1032
- const customRules = usageRules.custom_usage_rules;
1033
- if (!customRules) {
1034
- return true;
1035
- }
1036
- const { types, package_sub_item_rules } = customRules;
1037
- if (isMainProduct) {
1038
- if (!types.includes("standalone_product")) {
1039
- return false;
1040
- }
1041
- return true;
1042
- }
1043
- if (isBundleItem) {
1044
- if (!types.includes("package_sub_item")) {
1045
- return false;
1046
- }
1047
- const priceType = (_e = flatItem.bundleItem) == null ? void 0 : _e.price_type;
1048
- const priceTypeExt = (_f = flatItem.bundleItem) == null ? void 0 : _f.price_type_ext;
1049
- if (package_sub_item_rules && package_sub_item_rules.length > 0) {
1050
- const isOriginalPrice = priceType === "markup" && priceTypeExt === "product_price";
1051
- const isMarkupPrice = priceType === "markup" && (priceTypeExt === "" || !priceTypeExt);
1052
- if (isOriginalPrice && package_sub_item_rules.includes("original_price")) {
1028
+ const isOriginalPrice = priceType === "markup" && priceTypeExt === "product_price";
1029
+ const isMarkupPrice = priceType === "markup" && (priceTypeExt === "" || !priceTypeExt);
1030
+ if (rules.length > 0) {
1031
+ if (isOriginalPrice && rules.includes("original_price")) {
1053
1032
  return true;
1054
1033
  }
1055
- if (isMarkupPrice && package_sub_item_rules.includes("markup_price")) {
1034
+ if (isMarkupPrice && rules.includes("markup_price")) {
1056
1035
  return true;
1057
1036
  }
1058
1037
  return false;
1059
1038
  }
1060
- return true;
1039
+ return isOriginalPrice;
1061
1040
  }
1062
- return true;
1041
+ return false;
1042
+ }
1043
+ if (ruleType === "single_item_promo") {
1044
+ return isMainProduct;
1063
1045
  }
1064
1046
  return true;
1065
1047
  }
@@ -47,8 +47,9 @@ var formatDefaultCapacitys = ({
47
47
  if ((capacity == null ? void 0 : capacity.type) === "package") {
48
48
  return (product_bundle || []).map((d) => {
49
49
  const id = d.bundle_product_id;
50
+ const variantId = d.bundle_variant_id;
50
51
  const item = ((capacity == null ? void 0 : capacity.package) || []).find(
51
- (item2) => item2.product_id === id
52
+ (item2) => item2.product_id === id || item2.product_id === variantId
52
53
  );
53
54
  return {
54
55
  id,
@@ -212,6 +212,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
212
212
  product_id: item.product_id,
213
213
  product_variant_id: item.product_variant_id,
214
214
  quantity: item.num,
215
+ // 商品是否含税:1;0
216
+ is_charge_tax: item.is_charge_tax ?? 0,
217
+ // 若商品不含税,计算得到的税费,单位(元)
218
+ tax_fee: item.tax_fee,
215
219
  // 整个商品折扣后的总金额
216
220
  selling_price: item.calculated_selling_price,
217
221
  // 整个商品折扣前的总金额
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.356",
4
+ "version": "0.0.358",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",