@pisell/pisellos 0.10.57 → 0.10.58

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.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -592,7 +592,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
592
592
  generateIdempotencyToken(): string;
593
593
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
594
594
  createOrder(params: CommitOrderParams['query']): {
595
- type: "virtual" | "appointment_booking";
595
+ type: "appointment_booking" | "virtual";
596
596
  platform: string;
597
597
  sales_channel: string;
598
598
  order_sales_channel: string;
@@ -121,8 +121,9 @@ export declare function getBundleSellingMagnitude(bundle: Record<string, any> |
121
121
  * = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
122
122
  * - `metadata.source_product_price`:主商品/variant 基础价(已应用报价单),不含 option、
123
123
  * 不含折扣。**权威源**。
124
- * - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
125
- * - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
124
+ * - `product_sku.option[].add_price` 保留单规格折前单价;Rules 的 option.price 只用于本次计算。
125
+ * - `metadata.main_product_original_price` = source + Σ(option.add_price × option.num)(含 option、不含折扣)。
126
+ * - `metadata.main_product_selling_price` = main_original − 行内 per-unit amount(含主商品及 option 优惠)。
126
127
  * - `payment_price`:出站 payload 中为行 composite 已减整单折扣均摊价(无折扣时与 `selling_price` 同义)。
127
128
  *
128
129
  * Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
@@ -131,8 +132,9 @@ export declare function getBundleSellingMagnitude(bundle: Record<string, any> |
131
132
  * `getProductOriginTotalPrice` 会自行叠加 option + bundle,喂 source 可避免 option 双加。
132
133
  * - `getProduct.total` = `selling_price × num`(行 composite × num),与 Rules 内部产出的
133
134
  * total(source + option + bundle)对齐。
135
+ * - `getProduct.options` 用单规格原价参与重算;主商品折后价从 main_selling 减去 option 折后合计反推。
134
136
  * - `setProduct` 反向流程:把 Rules 返回的 source-level `main_product_selling_price` / `price`
135
- * 加回 Σoptions,重新合成含 option 的 main_product_* 并派生 composite。
137
+ * 加回单规格原价合计,再减去 optionDiscountAmount;保留订单单规格原价供取消折扣及后续重算。
136
138
  * 优先级:
137
139
  * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后 source-level 主价)
138
140
  * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
@@ -580,8 +580,9 @@ export function getBundleSellingMagnitude(bundle) {
580
580
  * = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
581
581
  * - `metadata.source_product_price`:主商品/variant 基础价(已应用报价单),不含 option、
582
582
  * 不含折扣。**权威源**。
583
- * - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
584
- * - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
583
+ * - `product_sku.option[].add_price` 保留单规格折前单价;Rules 的 option.price 只用于本次计算。
584
+ * - `metadata.main_product_original_price` = source + Σ(option.add_price × option.num)(含 option、不含折扣)。
585
+ * - `metadata.main_product_selling_price` = main_original − 行内 per-unit amount(含主商品及 option 优惠)。
585
586
  * - `payment_price`:出站 payload 中为行 composite 已减整单折扣均摊价(无折扣时与 `selling_price` 同义)。
586
587
  *
587
588
  * Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
@@ -590,8 +591,9 @@ export function getBundleSellingMagnitude(bundle) {
590
591
  * `getProductOriginTotalPrice` 会自行叠加 option + bundle,喂 source 可避免 option 双加。
591
592
  * - `getProduct.total` = `selling_price × num`(行 composite × num),与 Rules 内部产出的
592
593
  * total(source + option + bundle)对齐。
594
+ * - `getProduct.options` 用单规格原价参与重算;主商品折后价从 main_selling 减去 option 折后合计反推。
593
595
  * - `setProduct` 反向流程:把 Rules 返回的 source-level `main_product_selling_price` / `price`
594
- * 加回 Σoptions,重新合成含 option 的 main_product_* 并派生 composite。
596
+ * 加回单规格原价合计,再减去 optionDiscountAmount;保留订单单规格原价供取消折扣及后续重算。
595
597
  * 优先级:
596
598
  * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后 source-level 主价)
597
599
  * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
@@ -814,6 +816,15 @@ export function createDefaultOrderRulesHooks(getBookings) {
814
816
  var effectiveNum = Number(num) > 0 ? Number(num) : 1;
815
817
  return new Decimal(Number(totalLike) || 0).dividedBy(effectiveNum).toDecimalPlaces(2).toString();
816
818
  };
819
+
820
+ // optionDiscountAmount 已是每件主商品内的单规格优惠合计,不再乘商品数量。
821
+ var getOptionDiscountAmount = function getOptionDiscountAmount(discountList) {
822
+ return (discountList || []).reduce(function (total, discount) {
823
+ var _discount$metadata, _discount$metadata2;
824
+ if (discount !== null && discount !== void 0 && (_discount$metadata = discount.metadata) !== null && _discount$metadata !== void 0 && _discount$metadata.custom_product_bundle_map_id) return total;
825
+ return total.plus(Number(discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.optionDiscountAmount) || 0);
826
+ }, new Decimal(0));
827
+ };
817
828
  var getBundleIdentity = function getBundleIdentity(bundle) {
818
829
  var _ref21, _bundle$bundle_id, _ref22, _ref23, _bundle$bundle_produc, _ref24, _ref25, _bundle$bundle_varian, _ref26, _bundle$bundle_group_;
819
830
  return [(_ref21 = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id) !== null && _ref21 !== void 0 ? _ref21 : '', (_ref22 = (_ref23 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref23 !== void 0 ? _ref23 : bundle.product_id) !== null && _ref22 !== void 0 ? _ref22 : '', (_ref24 = (_ref25 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref25 !== void 0 ? _ref25 : bundle.product_variant_id) !== null && _ref24 !== void 0 ? _ref24 : 0, (_ref26 = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id) !== null && _ref26 !== void 0 ? _ref26 : ''].join('|');
@@ -851,12 +862,14 @@ export function createDefaultOrderRulesHooks(getBookings) {
851
862
  var _product$metadata7, _product$metadata8, _product$metadata9, _metadataAny$_promoti;
852
863
  // source_product_price 是权威源;兜底链:source → mainSelling − options(反推)→ 行 selling_price
853
864
  var metadataAny = product.metadata || {};
854
- var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
865
+ var productOptions = getProductSkuOptions(product);
866
+ var optionSum = sumOptionUnitPrice(productOptions);
867
+ var optionSellingSum = optionSum.minus(getOptionDiscountAmount(product.discount_list));
855
868
  var sourcePrice;
856
869
  if (metadataAny.source_product_price !== undefined) {
857
870
  sourcePrice = String(metadataAny.source_product_price);
858
871
  } else if (metadataAny.main_product_selling_price !== undefined) {
859
- sourcePrice = new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString();
872
+ sourcePrice = new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSellingSum).toDecimalPlaces(2).toString();
860
873
  } else {
861
874
  var _product$selling_pric;
862
875
  sourcePrice = String((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
@@ -887,6 +900,12 @@ export function createDefaultOrderRulesHooks(getBookings) {
887
900
  num: product.num || 1,
888
901
  discount_list: product.discount_list || [],
889
902
  bundle: product.product_bundle || [],
903
+ // 仅在 Rules 入参中映射 price,避免折后价污染订单的 add_price。
904
+ options: productOptions.map(function (option) {
905
+ return _objectSpread(_objectSpread({}, option), {}, {
906
+ price: option.add_price
907
+ });
908
+ }),
890
909
  booking_id: ((_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_id) || null,
891
910
  isClient: false,
892
911
  // 勿写死 false:否则 Rules 不会走 total≠origin_total 的手动价推断,
@@ -894,20 +913,22 @@ export function createDefaultOrderRulesHooks(getBookings) {
894
913
  isManualDiscount: resolveRulesManualDiscountFlag(metadataAny),
895
914
  holder_id: (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.holder_id,
896
915
  startDate: getProductStartDate(product),
897
- main_product_selling_price: metadataAny.main_product_selling_price !== undefined ? new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString() : undefined,
916
+ main_product_selling_price: metadataAny.main_product_selling_price !== undefined ? new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSellingSum).toDecimalPlaces(2).toString() : undefined,
898
917
  inPromotion: ((_metadataAny$_promoti = metadataAny._promotion) === null || _metadataAny$_promoti === void 0 ? void 0 : _metadataAny$_promoti.inPromotion) === true,
899
918
  _promotion: metadataAny._promotion
900
919
  };
901
920
  },
902
921
  setProduct: function setProduct(product, values) {
903
- var _ref32, _values$quantity, _ref33, _metadataAny$source_p, _product$product_sku, _values$discount_list, _values$quantity2;
922
+ var _ref32, _values$quantity, _ref33, _metadataAny$source_p, _values$discount_list, _product$product_sku, _values$quantity2;
904
923
  var nextNum = Number((_ref32 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref32 !== void 0 ? _ref32 : 1) || 1;
905
924
  var metadataAny = product.metadata || {};
906
925
  var existedSource = (_ref33 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref33 !== void 0 ? _ref33 : '0';
907
926
  var nextOptions = getProductSkuOptions(product);
908
927
  var optionSum = sumOptionUnitPrice(nextOptions);
928
+ var nextDiscountList = (_values$discount_list = values.discount_list) !== null && _values$discount_list !== void 0 ? _values$discount_list : product.discount_list;
929
+ var optionSellingSum = optionSum.minus(getOptionDiscountAmount(nextDiscountList));
909
930
 
910
- // Rules 返回的 main_product_selling_price / price / total 均为 source-level。
931
+ // Rules 返回的 main_product_selling_price / price 为不含 option 的主商品价。
911
932
  // 优先级:main_product_selling_price(per-unit 券后 source)> price(还原/good_pass 分支)>
912
933
  // total/num(仅当 Rules 只给 total 时的兜底)> 保留当前 source。
913
934
  var nextSourceSellingPrice = values.main_product_selling_price !== undefined ? String(values.main_product_selling_price) : values.price !== undefined ? String(values.price) : values.total !== undefined ? toUnitPriceString(values.total, nextNum) : String(existedSource);
@@ -916,8 +937,8 @@ export function createDefaultOrderRulesHooks(getBookings) {
916
937
  // 缺省时保留现有 source(券前 = 当前 source)。
917
938
  var nextSourceOriginalPrice = values.original_price !== undefined ? String(values.original_price) : String(existedSource);
918
939
 
919
- // 含 option 的 main_product_*
920
- var nextMainSellingPrice = new Decimal(Number(nextSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
940
+ // 成交价只加回 option 折后合计;原价仍使用订单中保存的 option 原价。
941
+ var nextMainSellingPrice = new Decimal(Number(nextSourceSellingPrice) || 0).plus(optionSellingSum).toDecimalPlaces(2).toFixed(2);
921
942
  var nextMainOriginalPrice = new Decimal(Number(nextSourceOriginalPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
922
943
  var nextBundle = values.bundle !== undefined ? mergeRulesBundlePrices(product.product_bundle, values.bundle) : product.product_bundle;
923
944
  var composedSellingPrice = composeLinePrice({
@@ -937,7 +958,7 @@ export function createDefaultOrderRulesHooks(getBookings) {
937
958
  return _objectSpread(_objectSpread({}, product), {}, {
938
959
  selling_price: composedSellingPrice,
939
960
  original_price: finalOriginalPrice,
940
- discount_list: (_values$discount_list = values.discount_list) !== null && _values$discount_list !== void 0 ? _values$discount_list : product.discount_list,
961
+ discount_list: nextDiscountList,
941
962
  num: (_values$quantity2 = values.quantity) !== null && _values$quantity2 !== void 0 ? _values$quantity2 : product.num,
942
963
  product_bundle: nextBundle,
943
964
  metadata: _objectSpread(_objectSpread({}, metadataAny), {}, {
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { ProductListLoadProductsParams, ProductListStoreQueryParams } from './types';
3
+ import { ProductListLoadProductsParams, ProductListStoreQueryParams, ProductEnrichmentContext } from './types';
4
4
  import { ProductData } from '../Product/types';
5
5
  export * from './types';
6
6
  export declare class ProductList extends BaseModule implements Module {
@@ -19,6 +19,8 @@ export declare class ProductList extends BaseModule implements Module {
19
19
  * productList.updateOtherParams({ channel: 'pos' });
20
20
  */
21
21
  updateOtherParams(params: Record<string, any>): void;
22
+ enrichProducts(products: ProductData[], context: ProductEnrichmentContext): Promise<ProductData[]>;
23
+ private enrichCatalog;
22
24
  storeChange(path?: string, value?: any): Promise<void>;
23
25
  /**
24
26
  * 获取加时商品列表。