@pisell/pisellos 3.0.46 → 3.0.49

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.
@@ -22,7 +22,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
22
22
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
23
23
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
24
  import { BaseModule } from "../BaseModule";
25
- import { generateDuration } from "./utils";
25
+ import { generateDuration, mergeRelationForms } from "./utils";
26
26
  import { isNormalProduct } from "../Product/utils";
27
27
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
28
28
  _inherits(OrderModule, _BaseModule);
@@ -92,6 +92,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
92
92
  (_order$relation_forms = order.relation_forms).push.apply(_order$relation_forms, _toConsumableArray(relationForms));
93
93
  delete item._origin.relation_forms;
94
94
  } else {
95
+ // 合并关联表单
96
+ var _relationForms = mergeRelationForms(item._origin.relation_forms || []);
97
+ item._origin.relation_forms = _relationForms;
95
98
  order.bookings.push(item._origin);
96
99
  }
97
100
  if (item !== null && item !== void 0 && item.deposit) {
@@ -8,3 +8,15 @@ export declare const generateDuration: (cartItem: CartItem) => {
8
8
  duration: number;
9
9
  durationType: string;
10
10
  };
11
+ /**
12
+ * 合并关联表单
13
+ * @param relationForms 关联表单
14
+ * @returns 合并后的关联表单
15
+ */
16
+ export declare const mergeRelationForms: (relationForms: {
17
+ form_id: number;
18
+ form_record_ids: number[];
19
+ }[]) => {
20
+ form_id: number;
21
+ form_record_ids: number[];
22
+ }[];
@@ -1,3 +1,9 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
7
  import dayjs from "dayjs";
2
8
  /**
3
9
  * 通过 session 类商品的开始时间结束时间生成商品的时长
@@ -12,4 +18,37 @@ export var generateDuration = function generateDuration(cartItem) {
12
18
  duration: duration,
13
19
  durationType: 'minutes'
14
20
  };
21
+ };
22
+
23
+ /**
24
+ * 合并关联表单
25
+ * @param relationForms 关联表单
26
+ * @returns 合并后的关联表单
27
+ */
28
+ export var mergeRelationForms = function mergeRelationForms(relationForms) {
29
+ return Object.values(relationForms.reduce(function (acc, cur) {
30
+ var _acc$form_id$form_rec;
31
+ var form_id = cur.form_id,
32
+ form_record_ids = cur.form_record_ids;
33
+ // 如果 acc 中没有 form_id,则初始化一个空数组
34
+ if (!acc[form_id]) {
35
+ acc[form_id] = {
36
+ form_id: form_id,
37
+ form_record_ids: []
38
+ };
39
+ }
40
+
41
+ // 兼容 form_record_id 可能是数组或单个数字
42
+ var ids = Array.isArray(form_record_ids) ? form_record_ids : [form_record_ids];
43
+ // 过滤掉空值(null、undefined等)
44
+ var validIds = ids.filter(function (id) {
45
+ return id != null;
46
+ });
47
+ (_acc$form_id$form_rec = acc[form_id].form_record_ids).push.apply(_acc$form_id$form_rec, _toConsumableArray(validIds));
48
+ // 去重
49
+ acc[form_id].form_record_ids = _toConsumableArray(new Set(acc[form_id].form_record_ids));
50
+ return acc;
51
+ }, {})).filter(function (item) {
52
+ return item.form_record_ids.length > 0;
53
+ }); // 过滤掉没有有效记录的表单
15
54
  };
@@ -429,7 +429,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
429
429
  }));
430
430
  }
431
431
  for (var _i = 0; _i < splitCount; _i++) {
432
- var _originProduct$_produ, _product$discount_lis11;
432
+ var _product$discount_lis11, _originProduct$_produ;
433
433
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
434
434
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
435
435
  // 标记优惠券为已使用
@@ -440,14 +440,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
440
440
 
441
441
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
442
442
  var productOriginTotal = product.origin_total || product.total || 0;
443
+ // 如果当前 product 有 discount_list,则先从 origin_total 拿
444
+ if ((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.length && product.origin_total) {
445
+ productOriginTotal = product.origin_total;
446
+ }
443
447
  // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
444
448
  if (Number((originProduct === null || originProduct === void 0 || (_originProduct$_produ = originProduct._productInit) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
445
449
  productOriginTotal = product.total;
446
450
  }
447
- // 如果当前 product 有 discount_list,则必须从 origin_total 拿
448
- if ((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.length && product.origin_total) {
449
- productOriginTotal = product.origin_total;
450
- }
451
451
 
452
452
  // 计算使用折扣卡/商品券以后,单个商品的总 total
453
453
  var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
@@ -65,6 +65,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
65
65
  order.relation_forms.push(...relationForms);
66
66
  delete item._origin.relation_forms;
67
67
  } else {
68
+ const relationForms = (0, import_utils.mergeRelationForms)(item._origin.relation_forms || []);
69
+ item._origin.relation_forms = relationForms;
68
70
  order.bookings.push(item._origin);
69
71
  }
70
72
  if (item == null ? void 0 : item.deposit) {
@@ -8,3 +8,15 @@ export declare const generateDuration: (cartItem: CartItem) => {
8
8
  duration: number;
9
9
  durationType: string;
10
10
  };
11
+ /**
12
+ * 合并关联表单
13
+ * @param relationForms 关联表单
14
+ * @returns 合并后的关联表单
15
+ */
16
+ export declare const mergeRelationForms: (relationForms: {
17
+ form_id: number;
18
+ form_record_ids: number[];
19
+ }[]) => {
20
+ form_id: number;
21
+ form_record_ids: number[];
22
+ }[];
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/modules/Order/utils.ts
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
- generateDuration: () => generateDuration
32
+ generateDuration: () => generateDuration,
33
+ mergeRelationForms: () => mergeRelationForms
33
34
  });
34
35
  module.exports = __toCommonJS(utils_exports);
35
36
  var import_dayjs = __toESM(require("dayjs"));
@@ -39,7 +40,23 @@ var generateDuration = (cartItem) => {
39
40
  const duration = endDate.diff(startDate, "minutes");
40
41
  return { duration, durationType: "minutes" };
41
42
  };
43
+ var mergeRelationForms = (relationForms) => {
44
+ return Object.values(
45
+ relationForms.reduce((acc, cur) => {
46
+ const { form_id, form_record_ids } = cur;
47
+ if (!acc[form_id]) {
48
+ acc[form_id] = { form_id, form_record_ids: [] };
49
+ }
50
+ const ids = Array.isArray(form_record_ids) ? form_record_ids : [form_record_ids];
51
+ const validIds = ids.filter((id) => id != null);
52
+ acc[form_id].form_record_ids.push(...validIds);
53
+ acc[form_id].form_record_ids = [...new Set(acc[form_id].form_record_ids)];
54
+ return acc;
55
+ }, {})
56
+ ).filter((item) => item.form_record_ids.length > 0);
57
+ };
42
58
  // Annotate the CommonJS export names for ESM import in node:
43
59
  0 && (module.exports = {
44
- generateDuration
60
+ generateDuration,
61
+ mergeRelationForms
45
62
  });
@@ -302,12 +302,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
302
302
  usedDiscounts.set(selectedDiscount2.id, true);
303
303
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
304
304
  let productOriginTotal = product.origin_total || product.total || 0;
305
- if (Number(((_g = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _g.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
306
- productOriginTotal = product.total;
307
- }
308
- if (((_h = product.discount_list) == null ? void 0 : _h.length) && product.origin_total) {
305
+ if (((_g = product.discount_list) == null ? void 0 : _g.length) && product.origin_total) {
309
306
  productOriginTotal = product.origin_total;
310
307
  }
308
+ if (Number(((_h = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _h.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
309
+ productOriginTotal = product.total;
310
+ }
311
311
  const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
312
312
  const discountDetail = {
313
313
  amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.46",
4
+ "version": "3.0.49",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",