@pisell/pisellos 2.2.260 → 2.2.262

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.
Files changed (107) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +1 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +15 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +25 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.js +1 -6
  6. package/dist/model/strategy/adapter/dataVariant/type.d.ts +2 -0
  7. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  8. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +23 -13
  9. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  11. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  12. package/dist/modules/Discount/index.d.ts +5 -2
  13. package/dist/modules/Discount/index.js +30 -7
  14. package/dist/modules/Discount/types.d.ts +4 -0
  15. package/dist/modules/Order/index.d.ts +45 -2
  16. package/dist/modules/Order/index.js +1552 -926
  17. package/dist/modules/Order/types.d.ts +36 -2
  18. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  19. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  20. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  21. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  22. package/dist/modules/Order/utils.d.ts +8 -3
  23. package/dist/modules/Order/utils.js +136 -56
  24. package/dist/modules/Rules/index.d.ts +4 -10
  25. package/dist/modules/Rules/index.js +63 -12
  26. package/dist/modules/Rules/types.d.ts +12 -2
  27. package/dist/modules/SalesSummary/index.d.ts +7 -3
  28. package/dist/modules/SalesSummary/index.js +67 -39
  29. package/dist/modules/SalesSummary/types.d.ts +1 -0
  30. package/dist/modules/SalesSummary/utils.js +2 -1
  31. package/dist/modules/SurchargeList/index.d.ts +6 -4
  32. package/dist/modules/SurchargeList/index.js +62 -39
  33. package/dist/modules/SurchargeList/types.d.ts +6 -2
  34. package/dist/server/index.d.ts +8 -0
  35. package/dist/server/index.js +1365 -911
  36. package/dist/server/modules/order/index.d.ts +32 -7
  37. package/dist/server/modules/order/index.js +551 -464
  38. package/dist/server/modules/order/types.d.ts +4 -0
  39. package/dist/server/modules/products/index.d.ts +5 -1
  40. package/dist/server/modules/products/index.js +384 -315
  41. package/dist/server/modules/products/types.d.ts +4 -0
  42. package/dist/solution/BaseSales/index.d.ts +42 -2
  43. package/dist/solution/BaseSales/index.js +1416 -775
  44. package/dist/solution/BaseSales/types.d.ts +7 -1
  45. package/dist/solution/BaseSales/types.js +3 -2
  46. package/dist/solution/BaseSales/utils/cartPromotion.js +19 -7
  47. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  48. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +20 -4
  50. package/dist/solution/BookingByStep/index.d.ts +1 -1
  51. package/dist/solution/BookingTicket/index.d.ts +8 -0
  52. package/dist/solution/BookingTicket/index.js +212 -31
  53. package/dist/solution/ShopDiscount/index.js +15 -14
  54. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +1 -0
  55. package/lib/model/strategy/adapter/dataVariant/adapter.js +10 -0
  56. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -0
  57. package/lib/model/strategy/adapter/dataVariant/evaluator.js +20 -1
  58. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -2
  59. package/lib/model/strategy/adapter/dataVariant/type.d.ts +2 -0
  60. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  61. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -1
  62. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
  63. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  64. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  65. package/lib/modules/Discount/index.d.ts +5 -2
  66. package/lib/modules/Discount/index.js +23 -3
  67. package/lib/modules/Discount/types.d.ts +4 -0
  68. package/lib/modules/Order/index.d.ts +45 -2
  69. package/lib/modules/Order/index.js +720 -116
  70. package/lib/modules/Order/types.d.ts +36 -2
  71. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  72. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  73. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  74. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  75. package/lib/modules/Order/utils.d.ts +8 -3
  76. package/lib/modules/Order/utils.js +104 -18
  77. package/lib/modules/Rules/index.d.ts +4 -10
  78. package/lib/modules/Rules/index.js +61 -9
  79. package/lib/modules/Rules/types.d.ts +12 -2
  80. package/lib/modules/SalesSummary/index.d.ts +7 -3
  81. package/lib/modules/SalesSummary/index.js +28 -11
  82. package/lib/modules/SalesSummary/types.d.ts +1 -0
  83. package/lib/modules/SalesSummary/utils.js +2 -0
  84. package/lib/modules/SurchargeList/index.d.ts +6 -4
  85. package/lib/modules/SurchargeList/index.js +41 -21
  86. package/lib/modules/SurchargeList/types.d.ts +6 -2
  87. package/lib/server/index.d.ts +8 -0
  88. package/lib/server/index.js +336 -11
  89. package/lib/server/modules/order/index.d.ts +32 -7
  90. package/lib/server/modules/order/index.js +298 -189
  91. package/lib/server/modules/order/types.d.ts +4 -0
  92. package/lib/server/modules/products/index.d.ts +5 -1
  93. package/lib/server/modules/products/index.js +21 -0
  94. package/lib/server/modules/products/types.d.ts +4 -0
  95. package/lib/solution/BaseSales/index.d.ts +42 -2
  96. package/lib/solution/BaseSales/index.js +535 -108
  97. package/lib/solution/BaseSales/types.d.ts +7 -1
  98. package/lib/solution/BaseSales/types.js +2 -1
  99. package/lib/solution/BaseSales/utils/cartPromotion.js +13 -1
  100. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  101. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  102. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -6
  103. package/lib/solution/BookingByStep/index.d.ts +1 -1
  104. package/lib/solution/BookingTicket/index.d.ts +8 -0
  105. package/lib/solution/BookingTicket/index.js +134 -8
  106. package/lib/solution/ShopDiscount/index.js +2 -1
  107. package/package.json +1 -1
@@ -37,7 +37,7 @@ __export(utils_exports, {
37
37
  createDefaultOrderRulesHooks: () => createDefaultOrderRulesHooks,
38
38
  createDefaultTempOrder: () => createDefaultTempOrder,
39
39
  createEmptySummary: () => import_utils2.createEmptySummary,
40
- createUuidV4: () => createUuidV4,
40
+ createUuidV4: () => import_orderCollectionIdentity.createUuidV4,
41
41
  ensureManualProductDiscountList: () => import_manualProductDiscount.ensureManualProductDiscountList,
42
42
  ensureProductSku: () => ensureProductSku,
43
43
  findManualProductDiscountItem: () => import_manualProductDiscount.findManualProductDiscountItem,
@@ -49,9 +49,11 @@ __export(utils_exports, {
49
49
  getBundleSignedUnit: () => getBundleSignedUnit,
50
50
  getOrderProductLineUid: () => getOrderProductLineUid,
51
51
  getProductSkuOptions: () => getProductSkuOptions,
52
+ getRuntimeProductOrigin: () => getRuntimeProductOrigin,
52
53
  hasAssignedHolderId: () => hasAssignedHolderId,
53
54
  indexOrderProductsByUid: () => indexOrderProductsByUid,
54
55
  isEmptyOrderProductDisplayValue: () => isEmptyOrderProductDisplayValue,
56
+ isHolderConfigRequired: () => isHolderConfigRequired,
55
57
  isMarkdownBundle: () => isMarkdownBundle,
56
58
  isTempOrder: () => isTempOrder,
57
59
  mapPaymentItemToOrderPayment: () => mapPaymentItemToOrderPayment,
@@ -65,7 +67,9 @@ __export(utils_exports, {
65
67
  normalizeProductSkuOptions: () => normalizeProductSkuOptions,
66
68
  normalizeSubmitBooking: () => normalizeSubmitBooking,
67
69
  normalizeSubmitCollectPaxValue: () => normalizeSubmitCollectPaxValue,
70
+ productRequiresFormSubject: () => productRequiresFormSubject,
68
71
  resolveEffectivePerUnitDiscount: () => resolveEffectivePerUnitDiscount,
72
+ resolveIsFormSubject: () => resolveIsFormSubject,
69
73
  resolveManualDiscountMessage: () => import_manualProductDiscount.resolveManualDiscountMessage,
70
74
  resolveManualDiscountOriginTotal: () => import_manualProductDiscount.resolveManualDiscountOriginTotal,
71
75
  resolveManualDiscountReasonFromSources: () => import_manualProductDiscount.resolveManualDiscountReasonFromSources,
@@ -82,6 +86,7 @@ module.exports = __toCommonJS(utils_exports);
82
86
  var import_dayjs = __toESM(require("dayjs"));
83
87
  var import_decimal = __toESM(require("decimal.js"));
84
88
  var import_utils = require("../../solution/ScanOrder/utils");
89
+ var import_orderCollectionIdentity = require("./utils/orderCollectionIdentity");
85
90
  var import_utils2 = require("../../solution/ScanOrder/utils");
86
91
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
87
92
  function composeLinePrice(params) {
@@ -282,9 +287,6 @@ function calculateOrderProductsDeposit(products = [], options) {
282
287
  if (!(deposit == null ? void 0 : deposit.total) || Number(deposit.total) <= 0)
283
288
  continue;
284
289
  total = total.plus(deposit.total);
285
- for (const discount of product.discount_list || []) {
286
- total = total.minus((discount == null ? void 0 : discount.amount) || 0);
287
- }
288
290
  for (const protocol of deposit.protocols || []) {
289
291
  if (!protocolMap.has(protocol.id))
290
292
  protocolMap.set(protocol.id, protocol);
@@ -376,6 +378,42 @@ function normalizeOrderProductDiscountList(discountList) {
376
378
  return normalized;
377
379
  });
378
380
  }
381
+ function resolveSubmitBundleMapId(bundle) {
382
+ var _a;
383
+ const metadataMapId = (_a = bundle.metadata) == null ? void 0 : _a.custom_product_bundle_map_id;
384
+ if (metadataMapId !== void 0 && metadataMapId !== null && metadataMapId !== "") {
385
+ return metadataMapId;
386
+ }
387
+ if (bundle._id !== void 0 && bundle._id !== null && bundle._id !== "") {
388
+ return bundle._id;
389
+ }
390
+ return void 0;
391
+ }
392
+ function collectSubmitProductDiscountList(product) {
393
+ const submitDiscountList = Array.isArray(product == null ? void 0 : product.discount_list) ? [...product.discount_list] : [];
394
+ for (const bundle of (product == null ? void 0 : product.product_bundle) || []) {
395
+ if (!bundle || typeof bundle !== "object")
396
+ continue;
397
+ const bundleMapId = resolveSubmitBundleMapId(bundle);
398
+ const bundleDiscountList = Array.isArray(bundle.discount_list) ? bundle.discount_list : [];
399
+ for (const discount of bundleDiscountList) {
400
+ if (!discount || typeof discount !== "object")
401
+ continue;
402
+ const discountMetadata = discount.metadata && typeof discount.metadata === "object" ? discount.metadata : {};
403
+ const discountMapId = discountMetadata.custom_product_bundle_map_id !== void 0 && discountMetadata.custom_product_bundle_map_id !== null && discountMetadata.custom_product_bundle_map_id !== "" ? discountMetadata.custom_product_bundle_map_id : bundleMapId;
404
+ submitDiscountList.push({
405
+ ...discount,
406
+ ...discountMapId !== void 0 ? {
407
+ metadata: {
408
+ ...discountMetadata,
409
+ custom_product_bundle_map_id: discountMapId
410
+ }
411
+ } : {}
412
+ });
413
+ }
414
+ }
415
+ return normalizeOrderProductDiscountList(submitDiscountList);
416
+ }
379
417
  function resolveManualOverrideLineOriginalPrice(params, fallbackCompositeOriginal) {
380
418
  var _a, _b;
381
419
  const metadata = params.metadata || {};
@@ -455,13 +493,17 @@ function createDefaultOrderRulesHooks() {
455
493
  const current = currentByIdentity.get(getBundleIdentity(bundle));
456
494
  if (!current)
457
495
  return bundle;
496
+ const bundleWithDisplayFields = {
497
+ ...bundle,
498
+ ...isEmptyOrderProductDisplayValue(bundle.cover) && !isEmptyOrderProductDisplayValue(current.cover) ? { cover: current.cover } : {}
499
+ };
458
500
  const isProductPriceBundle = (bundle.price_type_ext ?? current.price_type_ext) === "product_price";
459
501
  if (!isProductPriceBundle)
460
- return bundle;
502
+ return bundleWithDisplayFields;
461
503
  const sourcePrice = current.price ?? current.custom_price ?? current.original_price ?? current.bundle_selling_price;
462
504
  const originalPrice = current.original_price ?? current.product_price ?? current.price ?? current.custom_price ?? sourcePrice;
463
505
  return {
464
- ...bundle,
506
+ ...bundleWithDisplayFields,
465
507
  ...sourcePrice !== void 0 ? { price: sourcePrice } : {},
466
508
  ...originalPrice !== void 0 ? { original_price: originalPrice } : {},
467
509
  ...current.original_total !== void 0 ? { original_total: current.original_total } : {}
@@ -600,14 +642,6 @@ var getAllDiscountList = (cartItem) => {
600
642
  });
601
643
  return discountList;
602
644
  };
603
- function createUuidV4() {
604
- const template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
605
- return template.replace(/[xy]/g, (char) => {
606
- const randomValue = Math.floor(Math.random() * 16);
607
- const value = char === "x" ? randomValue : randomValue & 3 | 8;
608
- return value.toString(16);
609
- });
610
- }
611
645
  function isTempOrder(data) {
612
646
  if (!data || typeof data !== "object")
613
647
  return false;
@@ -671,6 +705,10 @@ function formatSubmitBundleItems(bundle) {
671
705
  return bundle.map((b) => {
672
706
  const rawBundle = b && typeof b === "object" ? b : {};
673
707
  const existedMetadata = rawBundle.metadata && typeof rawBundle.metadata === "object" ? rawBundle.metadata : {};
708
+ const {
709
+ custom_product_bundle_map_id: _customProductBundleMapId,
710
+ ...submitMetadata
711
+ } = existedMetadata;
674
712
  const sellingPrice = getBundleSellingMagnitude(rawBundle).toFixed(2);
675
713
  const paymentPrice = rawBundle.bundle_payment_price !== void 0 && rawBundle.bundle_payment_price !== null && rawBundle.bundle_payment_price !== "" ? toMoneyString(rawBundle.bundle_payment_price) : sellingPrice;
676
714
  const priceValue = rawBundle.price ?? rawBundle.custom_price ?? rawBundle.bundle_selling_price;
@@ -683,6 +721,8 @@ function formatSubmitBundleItems(bundle) {
683
721
  0
684
722
  );
685
723
  const num = toBundleNumber(rawBundle.num ?? rawBundle.quantity, 1);
724
+ const bundleMapId = resolveSubmitBundleMapId(rawBundle);
725
+ const hasSubmitBundleDiscounts = Array.isArray(rawBundle.discount_list) && rawBundle.discount_list.length > 0;
686
726
  return {
687
727
  is_charge_tax: rawBundle.is_charge_tax ?? 0,
688
728
  bundle_variant_id: rawBundle.bundle_variant_id ?? 0,
@@ -699,8 +739,10 @@ function formatSubmitBundleItems(bundle) {
699
739
  bundle_group_id: (rawBundle == null ? void 0 : rawBundle.bundle_group_id) ?? (rawBundle == null ? void 0 : rawBundle.group_id),
700
740
  bundle_id: (rawBundle == null ? void 0 : rawBundle.bundle_id) ?? (rawBundle == null ? void 0 : rawBundle.id),
701
741
  bundle_product_id: (rawBundle == null ? void 0 : rawBundle.bundle_product_id) ?? (rawBundle == null ? void 0 : rawBundle._bundle_product_id),
742
+ cover: rawBundle.cover,
702
743
  metadata: {
703
- ...existedMetadata,
744
+ ...submitMetadata,
745
+ ...hasSubmitBundleDiscounts && bundleMapId !== void 0 ? { custom_product_bundle_map_id: bundleMapId } : {},
704
746
  surcharge_fee: surchargeFee,
705
747
  relation_surcharge_ids: relationSurchargeIds,
706
748
  product_discount_difference: productDiscountDifference
@@ -756,6 +798,9 @@ function normalizeSubmitProduct(product) {
756
798
  if (rawMetadata.is_rule !== void 0) {
757
799
  cleanMetadata.is_rule = rawMetadata.is_rule;
758
800
  }
801
+ if (rawMetadata.holder_config !== void 0) {
802
+ cleanMetadata.holder_config = rawMetadata.holder_config;
803
+ }
759
804
  const productSku = {
760
805
  ...submitProduct.product_sku && typeof submitProduct.product_sku === "object" ? submitProduct.product_sku : {},
761
806
  option: formatSubmitOptionItems((_a = submitProduct.product_sku) == null ? void 0 : _a.option)
@@ -765,7 +810,7 @@ function normalizeSubmitProduct(product) {
765
810
  ...bookingUid ? { booking_uid: bookingUid } : {},
766
811
  product_quantity: toBundleNumber(num ?? submitProduct.product_quantity, 1),
767
812
  product_sku: productSku,
768
- discount_list: normalizeOrderProductDiscountList(submitProduct.discount_list),
813
+ discount_list: collectSubmitProductDiscountList(submitProduct),
769
814
  product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
770
815
  metadata: cleanMetadata,
771
816
  // 出站兼容:后端消费 payment_price 字段(行 composite 已减整单折扣均摊)。
@@ -886,7 +931,7 @@ function buildSubmitPayload(params) {
886
931
  enhance
887
932
  } = params;
888
933
  const scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
889
- const bookingUuid = createUuidV4();
934
+ const bookingUuid = (0, import_orderCollectionIdentity.createUuidV4)();
890
935
  const {
891
936
  _extend,
892
937
  relation_id: _relationId,
@@ -1034,7 +1079,7 @@ function formatV1Product(products) {
1034
1079
  note: String(product.note ?? ""),
1035
1080
  rowKey: product.product_id,
1036
1081
  session: null,
1037
- unique: createUuidV4()
1082
+ unique: (0, import_orderCollectionIdentity.createUuidV4)()
1038
1083
  };
1039
1084
  });
1040
1085
  }
@@ -1094,6 +1139,42 @@ function getOrderProductLineUid(product) {
1094
1139
  return null;
1095
1140
  return String(uid);
1096
1141
  }
1142
+ function getRuntimeProductOrigin(tempOrder, product) {
1143
+ var _a, _b, _c, _d, _e, _f;
1144
+ const uid = getOrderProductLineUid(product);
1145
+ if (uid && ((_c = (_b = (_a = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _a.productsByUid) == null ? void 0 : _b[uid]) == null ? void 0 : _c.origin)) {
1146
+ return tempOrder._extend.productsByUid[uid].origin;
1147
+ }
1148
+ const matchedProduct = ((tempOrder == null ? void 0 : tempOrder.products) || []).find((item) => item === product || getOrderProductLineUid(item) === uid || String((item == null ? void 0 : item.product_id) ?? (item == null ? void 0 : item.id) ?? "") === String((product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id) ?? ""));
1149
+ const matchedUid = matchedProduct ? getOrderProductLineUid(matchedProduct) : "";
1150
+ return matchedUid ? ((_f = (_e = (_d = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _d.productsByUid) == null ? void 0 : _e[matchedUid]) == null ? void 0 : _f.origin) || null : null;
1151
+ }
1152
+ function isHolderConfigRequired(holderConfig) {
1153
+ if (!holderConfig || typeof holderConfig !== "object")
1154
+ return false;
1155
+ if (holderConfig.status === "disable")
1156
+ return false;
1157
+ return Number(holderConfig.required) === 1;
1158
+ }
1159
+ function productRequiresFormSubject(tempOrder, product) {
1160
+ var _a, _b;
1161
+ const _orderProduct = (_a = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _a.find((item) => {
1162
+ return item.metadata.unique_identification_number === product._id || item.product_id === product.id;
1163
+ });
1164
+ const runtimeOrigin = getRuntimeProductOrigin(tempOrder, product);
1165
+ return isHolderConfigRequired((_b = _orderProduct == null ? void 0 : _orderProduct.metadata) == null ? void 0 : _b.holder_config) || isHolderConfigRequired(runtimeOrigin == null ? void 0 : runtimeOrigin.holder_config) || isHolderConfigRequired(product == null ? void 0 : product.holder_config);
1166
+ }
1167
+ function resolveIsFormSubject(tempOrder, product) {
1168
+ var _a;
1169
+ debugger;
1170
+ if (((_a = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _a.type) === "form")
1171
+ return true;
1172
+ if (product)
1173
+ return productRequiresFormSubject(tempOrder, product);
1174
+ return ((tempOrder == null ? void 0 : tempOrder.products) || []).some(
1175
+ (item) => productRequiresFormSubject(tempOrder, item)
1176
+ );
1177
+ }
1097
1178
  function isEmptyOrderProductDisplayValue(value) {
1098
1179
  if (value === void 0 || value === null)
1099
1180
  return true;
@@ -1114,6 +1195,7 @@ function mergeOrderProductDisplayFields(previous, next) {
1114
1195
  "product_name",
1115
1196
  "product_cover",
1116
1197
  "cover",
1198
+ "product_cover",
1117
1199
  "variant_title",
1118
1200
  "product_sku",
1119
1201
  "payment_price"
@@ -1174,9 +1256,11 @@ function indexOrderProductsByUid(products) {
1174
1256
  getBundleSignedUnit,
1175
1257
  getOrderProductLineUid,
1176
1258
  getProductSkuOptions,
1259
+ getRuntimeProductOrigin,
1177
1260
  hasAssignedHolderId,
1178
1261
  indexOrderProductsByUid,
1179
1262
  isEmptyOrderProductDisplayValue,
1263
+ isHolderConfigRequired,
1180
1264
  isMarkdownBundle,
1181
1265
  isTempOrder,
1182
1266
  mapPaymentItemToOrderPayment,
@@ -1190,7 +1274,9 @@ function indexOrderProductsByUid(products) {
1190
1274
  normalizeProductSkuOptions,
1191
1275
  normalizeSubmitBooking,
1192
1276
  normalizeSubmitCollectPaxValue,
1277
+ productRequiresFormSubject,
1193
1278
  resolveEffectivePerUnitDiscount,
1279
+ resolveIsFormSubject,
1194
1280
  resolveManualDiscountMessage,
1195
1281
  resolveManualDiscountOriginTotal,
1196
1282
  resolveManualDiscountReasonFromSources,
@@ -1,8 +1,7 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, RulesCalcDiscountOptions, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
- import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
5
  import { WindowPlugin } from '../../plugins';
7
6
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
8
7
  protected defaultName: string;
@@ -24,7 +23,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
23
  holders: {
25
24
  form_record_id: number;
26
25
  }[];
27
- isFormSubject: boolean;
26
+ isFormSubject: RulesFormSubject;
28
27
  }): {
29
28
  isAvailable: boolean;
30
29
  discountList: Discount[];
@@ -43,14 +42,9 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
43
42
  holders: {
44
43
  form_record_id: number;
45
44
  }[];
46
- isFormSubject: boolean;
45
+ isFormSubject: RulesFormSubject;
47
46
  orderTotalAmount: number;
48
- }, options?: {
49
- isSelected?: boolean;
50
- discountId?: number;
51
- selectedList?: SetDiscountSelectedParams[];
52
- scan?: boolean;
53
- }): DiscountResult;
47
+ }, options?: RulesCalcDiscountOptions): DiscountResult;
54
48
  /**
55
49
  * 检查优惠是否符合 PackageSubItemUsageRules 配置
56
50
  * @param discount 优惠券
@@ -70,7 +70,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
70
70
  var _a;
71
71
  if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
72
72
  return true;
73
- const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
73
+ const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id || holders[0] : void 0;
74
74
  const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
75
75
  if (!product.isNeedHolder)
76
76
  return true;
@@ -207,7 +207,38 @@ var RulesModule = class extends import_BaseModule.BaseModule {
207
207
  orderTotalAmount
208
208
  }, options) {
209
209
  var _a;
210
+ const resolveIsFormSubject = (product) => typeof isFormSubject === "function" ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
210
211
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
212
+ const reapplyBookingDiscountProductUids = new Set(
213
+ ((options == null ? void 0 : options.reapplyBookingDiscountProductUids) || []).filter((uid) => uid !== void 0 && uid !== null && uid !== "").map(String)
214
+ );
215
+ const getOriginProductUid = (originProduct) => {
216
+ var _a2;
217
+ const uid = ((_a2 = originProduct == null ? void 0 : originProduct.metadata) == null ? void 0 : _a2.unique_identification_number) ?? (originProduct == null ? void 0 : originProduct.unique_identification_number);
218
+ if (uid === void 0 || uid === null || uid === "")
219
+ return void 0;
220
+ return String(uid);
221
+ };
222
+ const shouldReapplyBookingDiscount = (originProduct, selectedDiscount) => {
223
+ if (!selectedDiscount)
224
+ return false;
225
+ const uid = getOriginProductUid(originProduct);
226
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid))
227
+ return false;
228
+ const discountType = selectedDiscount.tag || selectedDiscount.type;
229
+ return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ["good_pass", "discount_card", "product_discount_card"].includes(discountType);
230
+ };
231
+ const resolveReapplyEditModeDiscountPercent = (originProduct, selectedDiscount) => {
232
+ var _a2;
233
+ if (!shouldReapplyBookingDiscount(originProduct, selectedDiscount))
234
+ return void 0;
235
+ const discountType = (selectedDiscount == null ? void 0 : selectedDiscount.tag) || (selectedDiscount == null ? void 0 : selectedDiscount.type);
236
+ if (discountType !== "discount_card" && discountType !== "product_discount_card") {
237
+ return void 0;
238
+ }
239
+ const percent = Number((_a2 = selectedDiscount.discount) == null ? void 0 : _a2.percent);
240
+ return Number.isFinite(percent) ? percent : void 0;
241
+ };
211
242
  const editModeDiscount = [];
212
243
  const addModeDiscount = [];
213
244
  discountList.forEach((discount) => {
@@ -231,9 +262,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
231
262
  }
232
263
  });
233
264
  }
234
- const filteredDiscountList = addModeDiscount.filter((discount) => {
235
- return !discount.isManualSelect;
236
- });
237
265
  const hasDiscountInput = editModeDiscount.length > 0 || addModeDiscount.length > 0 || Boolean(options == null ? void 0 : options.discountId) || Boolean((_a = options == null ? void 0 : options.selectedList) == null ? void 0 : _a.length) || Boolean(options == null ? void 0 : options.scan);
238
266
  if (!hasDiscountInput) {
239
267
  return {
@@ -241,6 +269,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
241
269
  productList
242
270
  };
243
271
  }
272
+ const canUseEditModeDiscountForReapply = (discount) => {
273
+ const discountType = discount.tag || discount.type;
274
+ return reapplyBookingDiscountProductUids.size > 0 && discount.isEditMode === true && discount.isSelected === true && ["good_pass", "discount_card", "product_discount_card"].includes(discountType);
275
+ };
276
+ const filteredDiscountList = [
277
+ ...addModeDiscount.filter((discount) => !discount.isManualSelect),
278
+ ...editModeDiscount.filter(canUseEditModeDiscountForReapply)
279
+ ];
244
280
  const flattenProductsWithBundle = (productList2) => {
245
281
  const flattened = [];
246
282
  productList2.forEach((originProduct) => {
@@ -596,7 +632,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
596
632
  const isHolderMatch = this.checkHolderMatch(
597
633
  discount,
598
634
  {
599
- isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
635
+ isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
600
636
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
601
637
  },
602
638
  holders
@@ -736,9 +772,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
736
772
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
737
773
  var _a3, _b2, _c2, _d2;
738
774
  const discountType = discount.tag || discount.type;
775
+ const currentOriginUid = getOriginProductUid(originProduct);
776
+ const isReapplyEditModeDiscountForProduct = discount.isEditMode && reapplyBookingDiscountProductUids.size > 0 && currentOriginUid && reapplyBookingDiscountProductUids.has(String(currentOriginUid)) && discount.isSelected === true;
777
+ if (discount.isEditMode && reapplyBookingDiscountProductUids.size > 0) {
778
+ const uid = currentOriginUid;
779
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid))
780
+ return false;
781
+ if (!discount.isSelected)
782
+ return false;
783
+ }
739
784
  if (["good_pass", "discount_card", "product_discount_card"].includes(
740
785
  discountType
741
- )) {
786
+ ) && !isReapplyEditModeDiscountForProduct) {
742
787
  if (discount.config === void 0 || !((_a3 = discount == null ? void 0 : discount.config) == null ? void 0 : _a3.isAvailable)) {
743
788
  return false;
744
789
  }
@@ -767,7 +812,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
767
812
  const isHolderMatch = this.checkHolderMatch(
768
813
  discount,
769
814
  {
770
- isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
815
+ isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
771
816
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
772
817
  },
773
818
  holders
@@ -954,7 +999,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
954
999
  }
955
1000
  return;
956
1001
  }
957
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
1002
+ const shouldReapplyBookingDiscountForProduct = shouldReapplyBookingDiscount(originProduct, selectedDiscount);
1003
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct && !shouldReapplyBookingDiscountForProduct) {
958
1004
  return;
959
1005
  }
960
1006
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
@@ -1010,10 +1056,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1010
1056
  let productDiscountDifference;
1011
1057
  let discountedOptions = product.options;
1012
1058
  let optionDiscountAmount = 0;
1059
+ let reapplyDiscountPercent;
1013
1060
  if (isOrderLevel && productAllocation) {
1014
1061
  amount = productAllocation.discountAmount;
1015
1062
  productDiscountDifference = productAllocation.difference;
1016
1063
  mainProductSellingPrice = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
1064
+ } else if (resolveReapplyEditModeDiscountPercent(originProduct, selectedDiscount2) !== void 0) {
1065
+ const percent = resolveReapplyEditModeDiscountPercent(originProduct, selectedDiscount2);
1066
+ reapplyDiscountPercent = new import_decimal.default(percent).toFixed(2);
1067
+ mainProductSellingPrice = new import_decimal.default(product.price || 0).mul(new import_decimal.default(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
1068
+ amount = new import_decimal.default(product.price).minus(mainProductSellingPrice).toNumber();
1017
1069
  } else {
1018
1070
  mainProductSellingPrice = (0, import_utils.getDiscountAmount)(
1019
1071
  selectedDiscount2,
@@ -1048,7 +1100,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1048
1100
  title: selectedDiscount2.format_title,
1049
1101
  original_amount: product.price,
1050
1102
  product_id: originProduct.id || originProduct.product_id,
1051
- percent: selectedDiscount2.par_value,
1103
+ percent: reapplyDiscountPercent ?? selectedDiscount2.par_value,
1052
1104
  discount_product_id: selectedDiscount2.product_id
1053
1105
  },
1054
1106
  // 前端使用的num数量,为了计算优惠金额
@@ -1,4 +1,5 @@
1
1
  import { Discount } from '../Discount/types';
2
+ import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
2
3
  export declare enum UnavailableReason {
3
4
  TimeLimit = "time_limit",
4
5
  ProductNotApplicable = "product_not_applicable",
@@ -22,6 +23,15 @@ export interface DiscountResult {
22
23
  productList: any[];
23
24
  discountList: any[];
24
25
  }
26
+ export type RulesFormSubject = boolean | ((product: any) => boolean);
27
+ export interface RulesCalcDiscountOptions {
28
+ isSelected?: boolean;
29
+ discountId?: number;
30
+ selectedList?: SetDiscountSelectedParams[];
31
+ scan?: boolean;
32
+ /** Change time 重报价目标行:允许已选编辑态折扣卡重新应用到这些 booking 商品。 */
33
+ reapplyBookingDiscountProductUids?: string[];
34
+ }
25
35
  export interface RulesModuleAPI {
26
36
  setRulesList: (rulesList: Rules[]) => Promise<void>;
27
37
  clear: () => Promise<void>;
@@ -31,9 +41,9 @@ export interface RulesModuleAPI {
31
41
  holders: {
32
42
  form_record_id: number;
33
43
  }[];
34
- isFormSubject: boolean;
44
+ isFormSubject: RulesFormSubject;
35
45
  orderTotalAmount: number;
36
- }) => DiscountResult;
46
+ }, options?: RulesCalcDiscountOptions) => DiscountResult;
37
47
  }
38
48
  type ProductDetail = {
39
49
  isClient?: boolean;
@@ -9,16 +9,19 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
9
9
  private store;
10
10
  private request;
11
11
  private surchargeListModuleName;
12
+ private otherParams;
13
+ private surchargeListChannel;
12
14
  constructor(name?: string, version?: string);
13
15
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
14
16
  /**
15
- * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名变化时刷新附加费列表。
17
+ * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名或渠道变化时刷新附加费列表。
16
18
  *
17
19
  * @example
18
- * await salesSummaryModule.updateOtherParams({ surchargeListModuleName: 'custom_surchargeList' });
20
+ * await salesSummaryModule.updateOtherParams({ channel: 'pos', surchargeListModuleName: 'custom_surchargeList' });
19
21
  */
20
22
  updateOtherParams(params: Record<string, any>): Promise<void>;
21
- getSurchargeList(): Promise<void>;
23
+ private resolveChannel;
24
+ getSurchargeList(channel?: string): Promise<void>;
22
25
  private getAppData;
23
26
  private getTaxConfig;
24
27
  getSummary(params: {
@@ -26,6 +29,7 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
26
29
  isPriceIncludeTax?: number;
27
30
  taxRate?: number;
28
31
  shopDiscount?: string | number;
32
+ channel?: string;
29
33
  }): Promise<{
30
34
  tax_title: string;
31
35
  tax_rate: number | undefined;
@@ -33,12 +33,15 @@ var salesSummaryDataKeys = {
33
33
  taxTitle: "tax_title",
34
34
  taxCountryCode: "tax_country_code"
35
35
  };
36
+ var DEFAULT_SURCHARGE_CHANNEL = "online-store";
36
37
  var SalesSummaryModule = class extends import_BaseModule.BaseModule {
37
38
  constructor(name, version) {
38
39
  super(name, version);
39
40
  this.defaultName = "salesSummary";
40
41
  this.defaultVersion = "1.0.0";
41
42
  this.surchargeListModuleName = "surchargeList";
43
+ this.otherParams = {};
44
+ this.surchargeListChannel = DEFAULT_SURCHARGE_CHANNEL;
42
45
  }
43
46
  async initialize(core, options) {
44
47
  var _a, _b, _c;
@@ -46,9 +49,10 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
46
49
  this.store = options.store;
47
50
  this.appPlugin = this.core.getPlugin("app");
48
51
  this.request = this.core.getPlugin("request");
52
+ this.otherParams = options.otherParams || {};
49
53
  this.store.surchargeList = ((_a = options.initialState) == null ? void 0 : _a.surchargeList) || [];
50
54
  this.store.summary = ((_b = options.initialState) == null ? void 0 : _b.summary) || (0, import_utils.createEmptySalesSummary)();
51
- this.surchargeListModuleName = ((_c = options.otherParams) == null ? void 0 : _c.surchargeListModuleName) || "surchargeList";
55
+ this.surchargeListModuleName = ((_c = this.otherParams) == null ? void 0 : _c.surchargeListModuleName) || "surchargeList";
52
56
  if (!this.appPlugin) {
53
57
  throw new Error("SalesSummaryModule 需要 app 插件支持");
54
58
  }
@@ -58,41 +62,50 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
58
62
  await this.getSurchargeList();
59
63
  }
60
64
  /**
61
- * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名变化时刷新附加费列表。
65
+ * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名或渠道变化时刷新附加费列表。
62
66
  *
63
67
  * @example
64
- * await salesSummaryModule.updateOtherParams({ surchargeListModuleName: 'custom_surchargeList' });
68
+ * await salesSummaryModule.updateOtherParams({ channel: 'pos', surchargeListModuleName: 'custom_surchargeList' });
65
69
  */
66
70
  async updateOtherParams(params) {
71
+ const previousChannel = this.resolveChannel();
67
72
  const nextSurchargeListModuleName = (params == null ? void 0 : params.surchargeListModuleName) || "surchargeList";
68
- if (nextSurchargeListModuleName === this.surchargeListModuleName)
69
- return;
73
+ const nextChannel = this.resolveChannel(params);
74
+ const shouldReload = nextSurchargeListModuleName !== this.surchargeListModuleName || nextChannel !== previousChannel;
75
+ this.otherParams = params || {};
70
76
  this.surchargeListModuleName = nextSurchargeListModuleName;
71
- await this.getSurchargeList();
77
+ if (shouldReload) {
78
+ await this.getSurchargeList(nextChannel);
79
+ }
72
80
  }
73
- async getSurchargeList() {
81
+ resolveChannel(params = this.otherParams) {
82
+ return (params == null ? void 0 : params.channel) || DEFAULT_SURCHARGE_CHANNEL;
83
+ }
84
+ async getSurchargeList(channel = this.resolveChannel()) {
74
85
  try {
75
86
  const surchargeListModule = this.core.getModule(
76
87
  this.surchargeListModuleName
77
88
  );
78
89
  if (surchargeListModule == null ? void 0 : surchargeListModule.getSurchargeList) {
79
- this.store.surchargeList = await surchargeListModule.getSurchargeList();
90
+ this.store.surchargeList = await surchargeListModule.getSurchargeList({ channel });
91
+ this.surchargeListChannel = channel;
80
92
  return;
81
93
  }
82
94
  const surchargeList = await this.request.get(
83
95
  "/order/custom-surcharge/available/v2",
84
96
  {
85
- // TODO 真实的渠道
86
- channel: "online-store",
97
+ channel,
87
98
  is_assemble_product_data: 1,
88
99
  is_assemble_schedule_data: 1,
89
100
  with: ["relationSchedule"]
90
101
  }
91
102
  );
92
103
  this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
104
+ this.surchargeListChannel = channel;
93
105
  } catch (error) {
94
106
  console.warn("[SalesSummaryModule] 加载附加费配置失败", error);
95
107
  this.store.surchargeList = [];
108
+ this.surchargeListChannel = channel;
96
109
  }
97
110
  }
98
111
  getAppData(key) {
@@ -114,7 +127,11 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
114
127
  }
115
128
  async getSummary(params) {
116
129
  var _a, _b;
117
- const { products = [], isPriceIncludeTax, taxRate, shopDiscount } = params;
130
+ const { products = [], isPriceIncludeTax, taxRate, shopDiscount, channel } = params;
131
+ const summaryChannel = channel || this.resolveChannel();
132
+ if (summaryChannel !== this.surchargeListChannel) {
133
+ await this.getSurchargeList(summaryChannel);
134
+ }
118
135
  const taxConfig = this.getTaxConfig();
119
136
  const summarySchedule = this.core.getModule(
120
137
  `${this.name.split("_")[0]}_schedule`
@@ -63,5 +63,6 @@ export interface SalesSummaryModuleAPI {
63
63
  isPriceIncludeTax?: number;
64
64
  taxRate?: number;
65
65
  shopDiscount?: string | number;
66
+ channel?: string;
66
67
  }): Promise<SalesSummaryData>;
67
68
  }
@@ -308,6 +308,8 @@ function getFallbackAllProductSurchargeIds(surchargeList) {
308
308
  return ids;
309
309
  if (Number(config.is_all ?? 0) !== 1)
310
310
  return ids;
311
+ if (Number(config.open_schedule ?? 0) === 1 && config.schedule_type !== "all")
312
+ return ids;
311
313
  ids.push(id);
312
314
  return ids;
313
315
  }, []);
@@ -1,16 +1,18 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { SurchargeListItem, SurchargeListModuleAPI } from './types';
3
+ import { SurchargeListItem, SurchargeListModuleAPI, SurchargeListQuery } from './types';
4
4
  export * from './types';
5
5
  export declare class SurchargeListModule extends BaseModule implements Module, SurchargeListModuleAPI {
6
6
  protected defaultName: string;
7
7
  protected defaultVersion: string;
8
8
  private request;
9
9
  private store;
10
- private loadingPromise;
10
+ private loadingPromises;
11
+ private requestVersion;
11
12
  constructor(name?: string, version?: string);
12
13
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
13
- getSurchargeList(): Promise<SurchargeListItem[]>;
14
- refreshSurchargeList(): Promise<SurchargeListItem[]>;
14
+ private resolveChannel;
15
+ getSurchargeList(query?: SurchargeListQuery): Promise<SurchargeListItem[]>;
16
+ refreshSurchargeList(query?: SurchargeListQuery): Promise<SurchargeListItem[]>;
15
17
  private loadSurchargeList;
16
18
  }