@pisell/pisellos 2.3.122 → 2.3.124

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 (92) hide show
  1. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  3. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  4. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  5. package/dist/modules/Customer/index.js +6 -3
  6. package/dist/modules/Customer/types.d.ts +2 -0
  7. package/dist/modules/Discount/availability.d.ts +7 -0
  8. package/dist/modules/Discount/availability.js +49 -0
  9. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  10. package/dist/modules/Discount/entitlementPass.js +147 -0
  11. package/dist/modules/Discount/index.d.ts +2 -2
  12. package/dist/modules/Discount/index.js +37 -151
  13. package/dist/modules/Discount/types.d.ts +36 -5
  14. package/dist/modules/Order/index.d.ts +6 -0
  15. package/dist/modules/Order/index.js +437 -229
  16. package/dist/modules/Order/types.d.ts +1 -0
  17. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  18. package/dist/modules/Order/utils.d.ts +1 -1
  19. package/dist/modules/Order/utils.js +105 -60
  20. package/dist/modules/Payment/types.d.ts +21 -1
  21. package/dist/modules/Payment/types.js +2 -0
  22. package/dist/modules/Payment/walletpass.d.ts +1 -1
  23. package/dist/modules/Payment/walletpass.js +80 -47
  24. package/dist/modules/Rules/index.d.ts +2 -2
  25. package/dist/modules/Rules/index.js +480 -186
  26. package/dist/modules/Rules/types.d.ts +4 -0
  27. package/dist/server/modules/order/types.d.ts +3 -0
  28. package/dist/server/utils/small-ticket.js +25 -15
  29. package/dist/solution/BaseSales/index.d.ts +1 -0
  30. package/dist/solution/BaseSales/index.js +5 -2
  31. package/dist/solution/BaseSales/types.d.ts +2 -2
  32. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  33. package/dist/solution/BookingTicket/index.d.ts +1 -2
  34. package/dist/solution/BookingTicket/index.js +60 -63
  35. package/dist/solution/BookingTicket/types.d.ts +5 -1
  36. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  37. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  38. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  39. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  40. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  41. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  42. package/dist/solution/ShopDiscount/index.js +99 -42
  43. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  44. package/dist/solution/ShopDiscount/utils.js +43 -23
  45. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  46. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  47. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  48. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  49. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  50. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  51. package/lib/modules/Customer/index.js +5 -1
  52. package/lib/modules/Customer/types.d.ts +2 -0
  53. package/lib/modules/Discount/availability.d.ts +7 -0
  54. package/lib/modules/Discount/availability.js +43 -0
  55. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  56. package/lib/modules/Discount/entitlementPass.js +141 -0
  57. package/lib/modules/Discount/index.d.ts +2 -2
  58. package/lib/modules/Discount/index.js +23 -129
  59. package/lib/modules/Discount/types.d.ts +36 -5
  60. package/lib/modules/Order/index.d.ts +6 -0
  61. package/lib/modules/Order/index.js +213 -40
  62. package/lib/modules/Order/types.d.ts +1 -0
  63. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  64. package/lib/modules/Order/utils.d.ts +1 -1
  65. package/lib/modules/Order/utils.js +43 -3
  66. package/lib/modules/Payment/types.d.ts +21 -1
  67. package/lib/modules/Payment/types.js +1 -0
  68. package/lib/modules/Payment/walletpass.d.ts +1 -1
  69. package/lib/modules/Payment/walletpass.js +29 -9
  70. package/lib/modules/Rules/index.d.ts +2 -2
  71. package/lib/modules/Rules/index.js +357 -110
  72. package/lib/modules/Rules/types.d.ts +4 -0
  73. package/lib/server/modules/order/types.d.ts +3 -0
  74. package/lib/server/utils/small-ticket.js +25 -14
  75. package/lib/solution/BaseSales/index.d.ts +1 -0
  76. package/lib/solution/BaseSales/index.js +5 -2
  77. package/lib/solution/BaseSales/types.d.ts +2 -2
  78. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  79. package/lib/solution/BookingTicket/index.d.ts +1 -2
  80. package/lib/solution/BookingTicket/index.js +36 -33
  81. package/lib/solution/BookingTicket/types.d.ts +5 -1
  82. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  83. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  84. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  85. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  86. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  87. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  88. package/lib/solution/ShopDiscount/index.js +55 -9
  89. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  90. package/lib/solution/ShopDiscount/utils.js +42 -25
  91. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  92. package/package.json +1 -1
@@ -127,6 +127,7 @@ Object.defineProperty(exports, "syncManualProductDiscountProductNum", {
127
127
  }
128
128
  });
129
129
  var _dayjs = _interopRequireDefault(require("dayjs"));
130
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
130
131
  var _decimal = _interopRequireDefault(require("decimal.js"));
131
132
  var _utils = require("../Holder/utils");
132
133
  var _utils2 = require("../../solution/ScanOrder/utils");
@@ -134,6 +135,7 @@ var _orderCollectionIdentity = require("./utils/orderCollectionIdentity");
134
135
  var _salesNotes = require("./salesNotes");
135
136
  var _manualProductDiscount = require("./utils/manualProductDiscount");
136
137
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
138
+ _dayjs.default.extend(_customParseFormat.default);
137
139
  const POINT_CARD_SNAPSHOT_TAG = 'point_card';
138
140
  const VIRTUAL_CURRENCY_SNAPSHOT_TAG = 'virtual_currency';
139
141
  function isPlainObject(value) {
@@ -163,6 +165,10 @@ function normalizePointCardSnapshotItem(value) {
163
165
  if (productId !== undefined) {
164
166
  snapshot.product_id = productId;
165
167
  }
168
+ const code = normalizeSnapshotScalar(value.code);
169
+ if (code !== undefined) {
170
+ snapshot.code = String(code).trim();
171
+ }
166
172
  return snapshot;
167
173
  }
168
174
  function buildPointCardSnapshotFromWalletPassList(value) {
@@ -666,6 +672,24 @@ function resolveSubmitBundleMapId(bundle) {
666
672
  }
667
673
  return undefined;
668
674
  }
675
+ function ensureSubmitDiscountIdentity(discount) {
676
+ if (!discount || typeof discount !== 'object' || Array.isArray(discount)) {
677
+ return discount;
678
+ }
679
+ const discountRecord = discount;
680
+ const metadata = discountRecord.metadata && typeof discountRecord.metadata === 'object' && !Array.isArray(discountRecord.metadata) ? discountRecord.metadata : {};
681
+ const uniqueIdentificationNumber = metadata.unique_identification_number;
682
+ if (uniqueIdentificationNumber !== undefined && uniqueIdentificationNumber !== null && String(uniqueIdentificationNumber).trim() !== '') {
683
+ return discount;
684
+ }
685
+ return {
686
+ ...discountRecord,
687
+ metadata: {
688
+ ...metadata,
689
+ unique_identification_number: (0, _orderCollectionIdentity.createUuidV4)()
690
+ }
691
+ };
692
+ }
669
693
  function collectSubmitProductDiscountList(product) {
670
694
  const submitDiscountList = Array.isArray(product?.discount_list) ? [...product.discount_list] : [];
671
695
  for (const bundle of product?.product_bundle || []) {
@@ -687,7 +711,7 @@ function collectSubmitProductDiscountList(product) {
687
711
  });
688
712
  }
689
713
  }
690
- return normalizeOrderProductDiscountList(submitDiscountList);
714
+ return normalizeOrderProductDiscountList(submitDiscountList.map(ensureSubmitDiscountIdentity));
691
715
  }
692
716
 
693
717
  /**
@@ -754,7 +778,23 @@ function resolveEffectivePerUnitDiscount(product) {
754
778
  if (!Number.isFinite(originalPrice) || !Number.isFinite(finalPrice)) return fromList;
755
779
  return fromList + (originalPrice - finalPrice);
756
780
  }
757
- function createDefaultOrderRulesHooks() {
781
+ function createDefaultOrderRulesHooks(getBookings) {
782
+ const getProductStartDate = product => {
783
+ const productUid = String(product.metadata?.unique_identification_number ?? product.unique_identification_number ?? '');
784
+ const bookingUid = String(product.booking_uid ?? product.metadata?.booking_uid ?? '');
785
+ // 每次读取当前 bookings,覆盖改期、订单回显以及直接调用 Rules 的选券入口。
786
+ const bookings = getBookings?.() || [];
787
+ const booking = bookings.find(item => productUid && String(item?.product_uid ?? item?.metadata?.product_uid ?? '') === productUid) || bookings.find(item => bookingUid && String(item?.metadata?.unique_identification_number ?? item?.booking_uid ?? '') === bookingUid);
788
+ if (booking) {
789
+ // 严格解析并保留 Invalid Date,让公共时间校验拒绝缺失/非法时间,避免回退到当前时间。
790
+ return (0, _dayjs.default)(`${booking.start_date} ${booking.start_time}`, ['YYYY-MM-DD HH:mm', 'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD H:mm', 'YYYY-MM-DD H:mm:ss'], true);
791
+ }
792
+ if (getBookings && (bookingUid || product.booking_id || product.metadata?.booking_id)) {
793
+ return (0, _dayjs.default)('');
794
+ }
795
+ const legacyStartDate = product.metadata?.start_date || product.metadata?.startDate;
796
+ return legacyStartDate ? (0, _dayjs.default)(legacyStartDate) : undefined;
797
+ };
758
798
  const toUnitPriceString = (totalLike, num) => {
759
799
  const effectiveNum = Number(num) > 0 ? Number(num) : 1;
760
800
  return new _decimal.default(Number(totalLike) || 0).dividedBy(effectiveNum).toDecimalPlaces(2).toString();
@@ -842,7 +882,7 @@ function createDefaultOrderRulesHooks() {
842
882
  // 无券时会把 bundle 价还原成 original_price(手动改价套餐会从 20 回到 30)。
843
883
  isManualDiscount: resolveRulesManualDiscountFlag(metadataAny),
844
884
  holder_id: product.metadata?.holder_id,
845
- startDate: product.metadata?.start_date || product.metadata?.startDate,
885
+ startDate: getProductStartDate(product),
846
886
  main_product_selling_price: metadataAny.main_product_selling_price !== undefined ? new _decimal.default(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString() : undefined,
847
887
  inPromotion: metadataAny._promotion?.inPromotion === true,
848
888
  _promotion: metadataAny._promotion
@@ -412,6 +412,8 @@ export interface WalletAssetsBehaviorOptions {
412
412
  export interface RefreshWalletAssetsOptions {
413
413
  /** 商品/金额变化默认保留并重验选择;客户变化由实现层强制清空。 */
414
414
  preserveSelection?: boolean;
415
+ /** 客户变化时,仅保留与本次扫码匹配的搜索结果;其他搜索缓存仍会清空。 */
416
+ retainSearchResultCodes?: string[];
415
417
  }
416
418
  export interface SelectWalletAssetOptions {
417
419
  selected: boolean;
@@ -419,6 +421,8 @@ export interface SelectWalletAssetOptions {
419
421
  }
420
422
  export interface ScanWalletAssetResult {
421
423
  type: SearchIdentificationCodeResult['type'];
424
+ /** walletCode 时保留完整 Wallet Detail,供客户解析与客户选择器使用。 */
425
+ data?: WalletDetailSearchData;
422
426
  asset?: any;
423
427
  selected: boolean;
424
428
  state: WalletAssetsState;
@@ -864,6 +868,8 @@ export interface SearchIdentificationCodeParams extends WalletDeductionRecommend
864
868
  * 搜索识别码响应数据
865
869
  */
866
870
  export interface SearchIdentificationCodeResponse {
871
+ /** 业务是否成功 */
872
+ status?: boolean;
867
873
  /** 响应状态码 */
868
874
  code?: number;
869
875
  /** 响应消息 */
@@ -871,12 +877,26 @@ export interface SearchIdentificationCodeResponse {
871
877
  /** 响应数据 */
872
878
  data?: SearchIdentificationCodeItem[];
873
879
  }
880
+ /** Wallet code 精确搜索返回的 Wallet Detail。 */
881
+ export interface WalletDetailSearchData {
882
+ id?: string | number;
883
+ customer_id?: string | number;
884
+ customer?: Record<string, any> | null;
885
+ is_cross_shop_wallet?: boolean | 0 | 1;
886
+ [key: string]: any;
887
+ }
888
+ export interface WalletDetailSearchResponse {
889
+ status?: boolean;
890
+ code?: number;
891
+ message?: string;
892
+ data?: WalletDetailSearchData | null;
893
+ }
874
894
  /**
875
895
  * 搜索识别码结果类型
876
896
  */
877
897
  export type SearchIdentificationCodeResult = {
878
898
  type: 'walletCode';
879
- data: SearchIdentificationCodeItem[];
899
+ data: WalletDetailSearchData;
880
900
  } | {
881
901
  type: 'normalCode';
882
902
  data: SearchIdentificationCodeItem[];
@@ -221,6 +221,7 @@ let PaymentHooks = exports.PaymentHooks = /*#__PURE__*/function (PaymentHooks) {
221
221
  /**
222
222
  * 搜索识别码响应数据
223
223
  */
224
+ /** Wallet code 精确搜索返回的 Wallet Detail。 */
224
225
  /**
225
226
  * 搜索识别码结果类型
226
227
  */
@@ -96,7 +96,7 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
96
96
  * 搜索识别码信息
97
97
  * 通过识别码搜索相关的钱包通行证信息
98
98
  * 基于 WalletDeductionRecommendParams 参数结构
99
- * 特殊逻辑:当识别码长度为9位且前3位为"000"时,调用 /wallet/detail/search 接口
99
+ * 特殊逻辑:WL 或指定 200 格式的 Wallet Code 调用 /wallet/detail/search 接口。
100
100
  */
101
101
  searchIdentificationCodeAsync(params: SearchIdentificationCodeParams, config?: {
102
102
  noCache?: boolean;
@@ -705,7 +705,7 @@ class WalletPassPaymentImpl {
705
705
  * 搜索识别码信息
706
706
  * 通过识别码搜索相关的钱包通行证信息
707
707
  * 基于 WalletDeductionRecommendParams 参数结构
708
- * 特殊逻辑:当识别码长度为9位且前3位为"000"时,调用 /wallet/detail/search 接口
708
+ * 特殊逻辑:WL 或指定 200 格式的 Wallet Code 调用 /wallet/detail/search 接口。
709
709
  */
710
710
  async searchIdentificationCodeAsync(params, config = {}) {
711
711
  try {
@@ -725,6 +725,7 @@ class WalletPassPaymentImpl {
725
725
  const walletDetailParams = {
726
726
  code: code,
727
727
  with_customer: 1,
728
+ with_franchisor_data: 1,
728
729
  with: ['wallet']
729
730
  };
730
731
  this.paymentModule.logInfo('[WalletPass] 搜索钱包识别码', {
@@ -733,15 +734,18 @@ class WalletPassPaymentImpl {
733
734
  with: walletDetailParams.with
734
735
  });
735
736
  const response = await this.paymentModule.request.post('/wallet/detail/search', walletDetailParams);
736
- const searchResults = response?.data || [];
737
+ const walletDetail = response?.data;
738
+ if (response?.status !== true || response?.code !== 200 || !walletDetail || typeof walletDetail !== 'object' || Array.isArray(walletDetail)) {
739
+ throw new Error(response?.message || 'Wallet detail search failed');
740
+ }
737
741
  this.paymentModule.logInfo('[WalletPass] 钱包识别码搜索完成', {
738
742
  code: code,
739
- results_count: searchResults.length,
743
+ results_count: 1,
740
744
  type: 'walletCode'
741
745
  });
742
746
  return {
743
747
  type: 'walletCode',
744
- data: searchResults
748
+ data: walletDetail
745
749
  };
746
750
  }
747
751
 
@@ -830,9 +834,16 @@ class WalletPassPaymentImpl {
830
834
  const previousCustomerId = this.walletAssetsState.customerId;
831
835
  const customerChanged = String(previousCustomerId ?? '') !== String(nextCustomerId ?? '');
832
836
  const preserveSelection = options.preserveSelection !== false && !customerChanged;
837
+ const retainedSearchCodeKeys = new Set((options.retainSearchResultCodes || []).map(normalizeWalletAssetCode).filter(Boolean));
838
+ const retainedSearchResults = customerChanged && retainedSearchCodeKeys.size > 0 ? this.searchResults.filter(item => isWalletPaymentAsset(item) && getWalletAssetCodeKeys(item).some(code => retainedSearchCodeKeys.has(code))) : [];
833
839
  if (customerChanged) {
834
840
  this.clearSearchResults();
841
+ if (retainedSearchResults.length > 0) {
842
+ this.searchResults = mergeWalletAssets(retainedSearchResults);
843
+ this.queuePendingAutoSelectForAssets(retainedSearchResults);
844
+ }
835
845
  }
846
+ const preserveSearchContext = preserveSelection || retainedSearchResults.length > 0;
836
847
  const committedKeys = new Set(this.walletAssetsState.committedIds.map(id => String(id)));
837
848
  const committedItems = this.walletAssetsState.items.filter(item => committedKeys.has(getWalletAssetKey(item)));
838
849
  const selectedIds = preserveSelection ? [...this.walletAssetsState.selectedIds] : [];
@@ -901,8 +912,8 @@ class WalletPassPaymentImpl {
901
912
  error: null
902
913
  });
903
914
  try {
904
- const searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
905
- const useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
915
+ const searchedWalletAssetCodes = preserveSearchContext ? this.getSearchedWalletAssetCodes() : [];
916
+ const useAggregateRecalculate = preserveSearchContext && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
906
917
  const aggregateResult = useAggregateRecalculate ? await this.aggregateRecalculateWalletAssetsAsync(businessData, selectedIds) : null;
907
918
  const result = aggregateResult || (await this.initializeWalletDataFromBusinessAsync(businessData));
908
919
  if (requestSequence !== this.walletAssetsRequestSequence) {
@@ -920,7 +931,7 @@ class WalletPassPaymentImpl {
920
931
  this.searchResults = this.searchResults.filter(item => !missingSelectedKeys.has(getWalletAssetKey(item)));
921
932
  }
922
933
  }
923
- const searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([...(result.transformList || []), ...(result.noApplicableVoucher || [])]) : [];
934
+ const searchedWalletAssets = preserveSearchContext ? this.syncSearchedWalletAssets([...(result.transformList || []), ...(result.noApplicableVoucher || [])]) : [];
924
935
  if (requestSequence !== this.walletAssetsRequestSequence) {
925
936
  return this.getWalletAssetsState();
926
937
  }
@@ -1122,14 +1133,23 @@ class WalletPassPaymentImpl {
1122
1133
  code: normalizedCode,
1123
1134
  prepare_payments: this.formatWalletPassList2PreparePayments(this.walletAssetsState.selectedItems)
1124
1135
  });
1136
+ if (result.type === 'walletCode') {
1137
+ return {
1138
+ type: 'walletCode',
1139
+ data: result.data,
1140
+ asset: result.data,
1141
+ selected: false,
1142
+ state: this.getWalletAssetsState()
1143
+ };
1144
+ }
1125
1145
  const paymentAssets = this.formatSearchedWalletPaymentAssets(result.data.filter(isWalletPaymentAsset));
1126
1146
  if (paymentAssets.length > 0) {
1127
1147
  this.searchResults = mergeWalletAssets(this.searchResults, paymentAssets);
1128
1148
  }
1129
1149
  const asset = paymentAssets.find(item => String(item?.code || '') === normalizedCode) || paymentAssets[0];
1130
- if (!asset || result.type === 'walletCode') {
1150
+ if (!asset) {
1131
1151
  return {
1132
- type: result.type,
1152
+ type: 'normalCode',
1133
1153
  asset,
1134
1154
  selected: false,
1135
1155
  state: this.getWalletAssetsState()
@@ -16,8 +16,8 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
16
16
  getWalletPassEvaluator(): import("../..").WalletPassEvaluator | undefined;
17
17
  private normalizeHolderRecordIds;
18
18
  /**
19
- * 特定 form Holder 卡只授权给绑定同一 Holder Record 的商品行。
20
- * required/isNeedHolder 仅控制是否强制选择 Holder,不参与优惠资格。
19
+ * 商品未开启 Holder 选择时跳过匹配;已开启时,特定 form Holder 卡
20
+ * 只适用于同一 Holder Record,是否必填不影响匹配规则。
21
21
  */
22
22
  private checkHolderMatch;
23
23
  isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, orderTotalAmount, holders, isFormSubject, }: {