@pisell/pisellos 2.1.147 → 2.1.149

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.
@@ -685,25 +685,50 @@ var getBundleItemIsDiscountPrice = function getBundleItemIsDiscountPrice(item) {
685
685
  var getBundleItemIsMarkupOrDiscountPrice = function getBundleItemIsMarkupOrDiscountPrice(item) {
686
686
  return getBundleItemIsMarkupPrice(item) || getBundleItemIsDiscountPrice(item);
687
687
  };
688
+ var getDiscountAmount = function getDiscountAmount(discounts) {
689
+ return (discounts || []).reduce(function (total, discount) {
690
+ return total.add(new Decimal(discount.amount || 0));
691
+ }, new Decimal(0)).toNumber();
692
+ };
688
693
 
689
694
  /**
690
695
  * 获取主商品加价减价后的总价 (主商品价格 + 子商品加价减价)
691
696
  */
692
697
  var getMainProductTotal = function getMainProductTotal(item) {
693
- var _ref8, _ref9, _item$main_product_se, _item$metadata, _item$metadata2;
698
+ var _ref8, _ref9, _item$main_product_se, _item$metadata, _item$metadata2, _item$metadata3, _item$metadata4;
694
699
  // 新语义 v2 下 `main_product_selling_price` / `metadata.main_product_selling_price`
695
700
  // 已经是"含 option、含主商品折扣"的主价,直接作为主商品基准,无需再减折扣或加 option。
696
701
  // 仅需叠加 markup / markdown 类 bundle(原价 bundle 的税费单独处理)。
697
702
  var total = new Decimal((_ref8 = (_ref9 = (_item$main_product_se = item === null || item === void 0 ? void 0 : item.main_product_selling_price) !== null && _item$main_product_se !== void 0 ? _item$main_product_se : item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.main_product_selling_price) !== null && _ref9 !== void 0 ? _ref9 : item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.main_product_original_price) !== null && _ref8 !== void 0 ? _ref8 : 0);
703
+
704
+ // 做个兜底 如果新语义价格字段都没有,则切换回老逻辑
705
+ var hasMainProductPrice = (item === null || item === void 0 ? void 0 : item.main_product_selling_price) != null || (item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.main_product_selling_price) != null || (item === null || item === void 0 || (_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.main_product_original_price) != null;
706
+ if (!hasMainProductPrice) {
707
+ var _ref10, _ref11, _item$main_product_se2, _item$metadata5, _item$_origin3, _item$_originData;
708
+ total = new Decimal((_ref10 = (_ref11 = (_item$main_product_se2 = item === null || item === void 0 ? void 0 : item.main_product_selling_price) !== null && _item$main_product_se2 !== void 0 ? _item$main_product_se2 : item === null || item === void 0 || (_item$metadata5 = item.metadata) === null || _item$metadata5 === void 0 ? void 0 : _item$metadata5.main_product_selling_price) !== null && _ref11 !== void 0 ? _ref11 : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
709
+ var discount = (item === null || item === void 0 || (_item$_origin3 = item._origin) === null || _item$_origin3 === void 0 || (_item$_origin3 = _item$_origin3.product) === null || _item$_origin3 === void 0 ? void 0 : _item$_origin3.discount_list) || (item === null || item === void 0 || (_item$_originData = item._originData) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.product) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.discount_list) === null || _item$_originData === void 0 ? void 0 : _item$_originData.filter(function (item) {
710
+ var _item$metadata6;
711
+ return !(item !== null && item !== void 0 && (_item$metadata6 = item.metadata) !== null && _item$metadata6 !== void 0 && _item$metadata6.custom_product_bundle_map_id);
712
+ })) || [];
713
+ var mainProductDiscountAmount = getDiscountAmount(discount);
714
+ total = total.minus(mainProductDiscountAmount);
715
+
716
+ // 单规格
717
+ if (item !== null && item !== void 0 && item.option && Array.isArray(item === null || item === void 0 ? void 0 : item.option)) {
718
+ total = total.add(item === null || item === void 0 ? void 0 : item.option.reduce(function (t, option) {
719
+ return t.add(new Decimal(option.price || 0).mul(option.num || 1));
720
+ }, new Decimal(0)));
721
+ }
722
+ }
698
723
  var _iterator4 = _createForOfIteratorHelper((item === null || item === void 0 ? void 0 : item.bundle) || []),
699
724
  _step4;
700
725
  try {
701
726
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
702
727
  var bundleItem = _step4.value;
703
728
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
704
- var _ref10, _bundleItem$bundle_se2;
729
+ var _ref12, _bundleItem$bundle_se2;
705
730
  // IMPORTANT: 套餐子商品如果应用了 discount,bundle_selling_price 和 price 其实都已经是折后价格了,不需要单独再减一次
706
- var bundleItemTotal = new Decimal((_ref10 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
731
+ var bundleItemTotal = new Decimal((_ref12 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
707
732
  total = total.add(bundleItemTotal);
708
733
  }
709
734
  }
@@ -823,12 +848,12 @@ var isProductMatchSurchargeCondition = function isProductMatchSurchargeCondition
823
848
  * @param options.scheduleById schedule 映射表:`{ [scheduleId]: schedule }`(用于根据配置的 `available_schedule_ids` 做日程匹配)
824
849
  * @returns 附加费列表(仅返回金额 > 0 的项)
825
850
  */
826
- export var getSurcharge = function getSurcharge(_ref11, options) {
851
+ export var getSurcharge = function getSurcharge(_ref13, options) {
827
852
  var _service$filter;
828
- var service = _ref11.service,
829
- addons = _ref11.addons,
830
- bookingDetail = _ref11.bookingDetail,
831
- bookingId = _ref11.bookingId;
853
+ var service = _ref13.service,
854
+ addons = _ref13.addons,
855
+ bookingDetail = _ref13.bookingDetail,
856
+ bookingId = _ref13.bookingId;
832
857
  var isEdit = options.isEdit,
833
858
  isInScheduleByDate = options.isInScheduleByDate,
834
859
  surcharge_list = options.surcharge_list,
@@ -950,11 +975,11 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
950
975
  scheduleById: scheduleById || {},
951
976
  isInScheduleByDate: isInScheduleByDate
952
977
  })) {
953
- var _ref12, _bundleItem$bundle_se3;
978
+ var _ref14, _bundleItem$bundle_se3;
954
979
  var _mainQuantity = item.num || 1;
955
980
  matchedItems.push({
956
981
  isMain: false,
957
- total: Number((_ref12 = (_bundleItem$bundle_se3 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se3 !== void 0 ? _bundleItem$bundle_se3 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0),
982
+ total: Number((_ref14 = (_bundleItem$bundle_se3 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se3 !== void 0 ? _bundleItem$bundle_se3 : bundleItem.price) !== null && _ref14 !== void 0 ? _ref14 : 0),
958
983
  quantity: bundleItem.num || bundleItem.quantity || 1,
959
984
  item: bundleItem,
960
985
  mainQuantity: _mainQuantity // 子商品的mainQuantity是所属主商品的quantity
@@ -1170,9 +1195,9 @@ export var getSurcharge = function getSurcharge(_ref11, options) {
1170
1195
  }
1171
1196
  return surchargeWithAmount;
1172
1197
  };
1173
- function resetItemsSurchargeSideEffects(_ref13) {
1174
- var service = _ref13.service,
1175
- addons = _ref13.addons;
1198
+ function resetItemsSurchargeSideEffects(_ref15) {
1199
+ var service = _ref15.service,
1200
+ addons = _ref15.addons;
1176
1201
  var resetItem = function resetItem(item) {
1177
1202
  if (!item) return;
1178
1203
  item.surcharge_fee = 0;
@@ -1390,11 +1390,12 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1390
1390
  })
1391
1391
  } : undefined;
1392
1392
  var ruleProductUid = ruleProduct ? createUuidV4() : undefined;
1393
- // 有 collect_pax 时 booking/resource capacity 都代表本次 pax;否则使用资源占用兜底值。
1393
+ // 有 collect_pax 时 booking/resource capacity 与 number 都代表本次 pax;否则使用资源占用兜底值。
1394
1394
  var bookingCapacityValue = resourceCapacityValue;
1395
1395
  var bookingCapacityDimensionId = (_pickFirstCustomCapac = pickFirstCustomCapacityDimensionId(_this5.enabledReservationRuleProducts)) !== null && _pickFirstCustomCapac !== void 0 ? _pickFirstCustomCapac : 0;
1396
1396
  var nextBookings = (payload.bookings || []).map(function (booking, idx) {
1397
1397
  return _objectSpread(_objectSpread(_objectSpread({}, booking), {}, {
1398
+ number: bookingCapacityValue,
1398
1399
  appointment_status: 'started',
1399
1400
  metadata: _objectSpread(_objectSpread(_objectSpread({}, booking.metadata || {}), resourceSelectType ? {
1400
1401
  resource_select_type: resourceSelectType
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -423,11 +423,31 @@ var getBundleItemIsDiscountPrice = (item) => {
423
423
  var getBundleItemIsMarkupOrDiscountPrice = (item) => {
424
424
  return getBundleItemIsMarkupPrice(item) || getBundleItemIsDiscountPrice(item);
425
425
  };
426
+ var getDiscountAmount = (discounts) => {
427
+ return (discounts || []).reduce((total, discount) => {
428
+ return total.add(new import_decimal.default(discount.amount || 0));
429
+ }, new import_decimal.default(0)).toNumber();
430
+ };
426
431
  var getMainProductTotal = (item) => {
427
- var _a, _b;
432
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
428
433
  let total = new import_decimal.default(
429
434
  (item == null ? void 0 : item.main_product_selling_price) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.main_product_selling_price) ?? ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.main_product_original_price) ?? 0
430
435
  );
436
+ const hasMainProductPrice = (item == null ? void 0 : item.main_product_selling_price) != null || ((_c = item == null ? void 0 : item.metadata) == null ? void 0 : _c.main_product_selling_price) != null || ((_d = item == null ? void 0 : item.metadata) == null ? void 0 : _d.main_product_original_price) != null;
437
+ if (!hasMainProductPrice) {
438
+ total = new import_decimal.default((item == null ? void 0 : item.main_product_selling_price) ?? ((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.main_product_selling_price) ?? item.price ?? 0);
439
+ const discount = ((_g = (_f = item == null ? void 0 : item._origin) == null ? void 0 : _f.product) == null ? void 0 : _g.discount_list) || ((_j = (_i = (_h = item == null ? void 0 : item._originData) == null ? void 0 : _h.product) == null ? void 0 : _i.discount_list) == null ? void 0 : _j.filter((item2) => {
440
+ var _a2;
441
+ return !((_a2 = item2 == null ? void 0 : item2.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
442
+ })) || [];
443
+ const mainProductDiscountAmount = getDiscountAmount(discount);
444
+ total = total.minus(mainProductDiscountAmount);
445
+ if ((item == null ? void 0 : item.option) && Array.isArray(item == null ? void 0 : item.option)) {
446
+ total = total.add(item == null ? void 0 : item.option.reduce((t, option) => {
447
+ return t.add(new import_decimal.default(option.price || 0).mul(option.num || 1));
448
+ }, new import_decimal.default(0)));
449
+ }
450
+ }
431
451
  for (let bundleItem of (item == null ? void 0 : item.bundle) || []) {
432
452
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
433
453
  const bundleItemTotal = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
@@ -867,6 +867,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
867
867
  const bookingCapacityDimensionId = (0, import_utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
868
868
  const nextBookings = (payload.bookings || []).map((booking, idx) => ({
869
869
  ...booking,
870
+ number: bookingCapacityValue,
870
871
  appointment_status: "started",
871
872
  metadata: {
872
873
  ...booking.metadata || {},
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.147",
4
+ "version": "2.1.149",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",