@pisell/pisellos 2.2.325 → 2.2.326

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.
@@ -630,7 +630,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
630
630
  value: function () {
631
631
  var _configureIdGeneratorFromOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
632
632
  var _openDataConfig, _openDataConfig2, _openDataConfig3, _openDataConfig4, _openDataConfig5, _openDataConfig6;
633
- var idGenerator, openDataConfig, receiptSequenceLength, receiptSequenceStart, prefix, shopOrderPrefix, resetReceiptSequenceDaily, operatingDayBoundary, deviceId, businessCode, _openDataConfig7, _openDataConfig8, _openDataConfig9;
633
+ var idGenerator, openDataConfig, receiptSequenceLength, receiptSequenceStart, prefix, shopOrderPrefix, resetReceiptSequenceDaily, operatingDayBoundary, deviceId, businessCode, _openDataConfig7, _openDataConfig8, _openDataConfig9, _openDataConfig10;
634
634
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
635
635
  while (1) switch (_context10.prev = _context10.next) {
636
636
  case 0:
@@ -686,12 +686,13 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
686
686
  return idGenerator.configure({
687
687
  biz: businessCode,
688
688
  config: {
689
+ enableShortNumber: ((_openDataConfig7 = openDataConfig) === null || _openDataConfig7 === void 0 ? void 0 : _openDataConfig7['sale.enable_short_number']) !== false,
689
690
  prefix: prefix,
690
691
  deviceCode: deviceId,
691
- padReceiptSequence: ((_openDataConfig7 = openDataConfig) === null || _openDataConfig7 === void 0 ? void 0 : _openDataConfig7['sale.pad_with_leading_zeros']) === true,
692
+ padReceiptSequence: ((_openDataConfig8 = openDataConfig) === null || _openDataConfig8 === void 0 ? void 0 : _openDataConfig8['sale.pad_with_leading_zeros']) === true,
692
693
  receiptSequenceLength: receiptSequenceLength,
693
- receiptSequenceMax: this.normalizeShortNumberMaximum((_openDataConfig8 = openDataConfig) === null || _openDataConfig8 === void 0 ? void 0 : _openDataConfig8['sale.maximum_number']),
694
- randomReceiptSequence: ((_openDataConfig9 = openDataConfig) === null || _openDataConfig9 === void 0 ? void 0 : _openDataConfig9['sale.short_number_random']) === true,
694
+ receiptSequenceMax: this.normalizeShortNumberMaximum((_openDataConfig9 = openDataConfig) === null || _openDataConfig9 === void 0 ? void 0 : _openDataConfig9['sale.maximum_number']),
695
+ randomReceiptSequence: ((_openDataConfig10 = openDataConfig) === null || _openDataConfig10 === void 0 ? void 0 : _openDataConfig10['sale.short_number_random']) === true,
695
696
  resetReceiptSequenceDaily: resetReceiptSequenceDaily,
696
697
  receiptSequenceResetTime: operatingDayBoundary === null || operatingDayBoundary === void 0 ? void 0 : operatingDayBoundary.time,
697
698
  receiptSequenceStart: receiptSequenceStart,
@@ -3498,7 +3499,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3498
3499
  _context44.next = 9;
3499
3500
  return this.prepareInvoiceTemplateAtSolutionReady(Object.prototype.hasOwnProperty.call(params, 'openData') ? this.getInjectedOpenDataConfig() : undefined);
3500
3501
  case 9:
3501
- if (!((params === null || params === void 0 ? void 0 : params.businessCode) !== undefined || (params === null || params === void 0 ? void 0 : params.business_code) !== undefined)) {
3502
+ if (!((params === null || params === void 0 ? void 0 : params.businessCode) !== undefined || (params === null || params === void 0 ? void 0 : params.business_code) !== undefined || Object.prototype.hasOwnProperty.call(params !== null && params !== void 0 ? params : {}, 'openData'))) {
3502
3503
  _context44.next = 12;
3503
3504
  break;
3504
3505
  }
@@ -474,7 +474,7 @@ function _applyGlobalScan() {
474
474
  case 15:
475
475
  // 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
476
476
  if (!bindResult.resolveFailed) {
477
- bridge === null || bridge === void 0 || (_bridge$onNotify11 = bridge.onNotify) === null || _bridge$onNotify11 === void 0 || _bridge$onNotify11.call(bridge, 'fail', 'pisell2.text.goodpass.code-invalid-cart');
477
+ bridge === null || bridge === void 0 || (_bridge$onNotify11 = bridge.onNotify) === null || _bridge$onNotify11 === void 0 || _bridge$onNotify11.call(bridge, 'fail', walletResult.asset.reasonCode === 'empty_cart' ? 'pisell2.sale-detail.promotion-panel.add-items-first' : 'pisell2.text.goodpass.code-invalid-cart');
478
478
  }
479
479
  return _context5.abrupt("return", {
480
480
  status: 'failed',
@@ -2507,8 +2507,8 @@ export var UnifiedBookingSalesImpl = /*#__PURE__*/function (_BookingTicket) {
2507
2507
  key: "ensureLocalOrderNumbersForCheckout",
2508
2508
  value: (function () {
2509
2509
  var _ensureLocalOrderNumbersForCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
2510
- var _this$otherParams19, _this$appPlugin, _this$appPlugin$getAp, _this$appPlugin$getAp2;
2511
- var order, tempOrder, biz, idGenerator;
2510
+ var _this$otherParams19, _this$appPlugin, _this$appPlugin$getAp, _this$appPlugin$getAp2, _idGenerator$getConfi;
2511
+ var order, tempOrder, biz, idGenerator, useLongNumber;
2512
2512
  return _regeneratorRuntime().wrap(function _callee9$(_context10) {
2513
2513
  while (1) switch (_context10.prev = _context10.next) {
2514
2514
  case 0:
@@ -2540,56 +2540,67 @@ export var UnifiedBookingSalesImpl = /*#__PURE__*/function (_BookingTicket) {
2540
2540
  throw new Error('当前订单缺少业务类型,无法生成订单编号');
2541
2541
  case 11:
2542
2542
  idGenerator = (_this$appPlugin = this.appPlugin) === null || _this$appPlugin === void 0 || (_this$appPlugin$getAp = _this$appPlugin.getApp) === null || _this$appPlugin$getAp === void 0 || (_this$appPlugin$getAp = _this$appPlugin$getAp.call(_this$appPlugin)) === null || _this$appPlugin$getAp === void 0 || (_this$appPlugin$getAp2 = _this$appPlugin$getAp.getPlugin) === null || _this$appPlugin$getAp2 === void 0 ? void 0 : _this$appPlugin$getAp2.call(_this$appPlugin$getAp, 'idGenerator');
2543
- if (!(!tempOrder.shop_order_number && typeof (idGenerator === null || idGenerator === void 0 ? void 0 : idGenerator.generateShopOrderNumber) !== 'function' || !tempOrder.shop_full_order_number && typeof (idGenerator === null || idGenerator === void 0 ? void 0 : idGenerator.generateReceiptId) !== 'function')) {
2544
- _context10.next = 14;
2543
+ useLongNumber = (idGenerator === null || idGenerator === void 0 || (_idGenerator$getConfi = idGenerator.getConfig) === null || _idGenerator$getConfi === void 0 || (_idGenerator$getConfi = _idGenerator$getConfi.call(idGenerator, biz)) === null || _idGenerator$getConfi === void 0 ? void 0 : _idGenerator$getConfi.enableShortNumber) === false;
2544
+ if (!(!tempOrder.shop_order_number && typeof (idGenerator === null || idGenerator === void 0 ? void 0 : idGenerator.generateShopOrderNumber) !== 'function' || !tempOrder.shop_full_order_number && !useLongNumber && typeof (idGenerator === null || idGenerator === void 0 ? void 0 : idGenerator.generateReceiptId) !== 'function')) {
2545
+ _context10.next = 15;
2545
2546
  break;
2546
2547
  }
2547
2548
  throw new Error('订单编号生成器不可用,请重启应用后重试');
2548
- case 14:
2549
- _context10.prev = 14;
2549
+ case 15:
2550
+ _context10.prev = 15;
2550
2551
  if (tempOrder.shop_order_number) {
2551
- _context10.next = 19;
2552
+ _context10.next = 20;
2552
2553
  break;
2553
2554
  }
2554
- _context10.next = 18;
2555
+ _context10.next = 19;
2555
2556
  return idGenerator.generateShopOrderNumber({
2556
2557
  biz: biz
2557
2558
  });
2558
- case 18:
2559
- tempOrder.shop_order_number = _context10.sent;
2560
2559
  case 19:
2560
+ tempOrder.shop_order_number = _context10.sent;
2561
+ case 20:
2561
2562
  if (tempOrder.shop_full_order_number) {
2562
- _context10.next = 23;
2563
+ _context10.next = 29;
2563
2564
  break;
2564
2565
  }
2565
- _context10.next = 22;
2566
+ if (!useLongNumber) {
2567
+ _context10.next = 25;
2568
+ break;
2569
+ }
2570
+ _context10.t0 = tempOrder.shop_order_number;
2571
+ _context10.next = 28;
2572
+ break;
2573
+ case 25:
2574
+ _context10.next = 27;
2566
2575
  return idGenerator.generateReceiptId({
2567
2576
  biz: biz
2568
2577
  });
2569
- case 22:
2570
- tempOrder.shop_full_order_number = _context10.sent;
2571
- case 23:
2578
+ case 27:
2579
+ _context10.t0 = _context10.sent;
2580
+ case 28:
2581
+ tempOrder.shop_full_order_number = _context10.t0;
2582
+ case 29:
2572
2583
  if (!(order.getTempOrder() !== tempOrder)) {
2573
- _context10.next = 25;
2584
+ _context10.next = 31;
2574
2585
  break;
2575
2586
  }
2576
2587
  throw new Error('当前订单已切换,请重新发起支付');
2577
- case 25:
2588
+ case 31:
2578
2589
  if (!(!tempOrder.shop_order_number || !tempOrder.shop_full_order_number)) {
2579
- _context10.next = 27;
2590
+ _context10.next = 33;
2580
2591
  break;
2581
2592
  }
2582
2593
  throw new Error('订单编号生成失败,请重试');
2583
- case 27:
2584
- _context10.prev = 27;
2594
+ case 33:
2595
+ _context10.prev = 33;
2585
2596
  // 部分生成成功时也保留号码,后续只补仍然缺失的字段。
2586
2597
  if (order.getTempOrder() === tempOrder) order.persistTempOrder();
2587
- return _context10.finish(27);
2588
- case 30:
2598
+ return _context10.finish(33);
2599
+ case 36:
2589
2600
  case "end":
2590
2601
  return _context10.stop();
2591
2602
  }
2592
- }, _callee9, this, [[14,, 27, 30]]);
2603
+ }, _callee9, this, [[15,, 33, 36]]);
2593
2604
  }));
2594
2605
  function ensureLocalOrderNumbersForCheckout() {
2595
2606
  return _ensureLocalOrderNumbersForCheckout.apply(this, arguments);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.locales = void 0;
7
7
  const locales = exports.locales = {
8
8
  'zh-CN': {
9
+ 'empty_cart': '请先添加商品到购物车',
9
10
  'not_meet_the_required_conditions': '未达到使用条件',
10
11
  'exceeds_the_maximum_deduction_limit': '超出最大抵扣金额限制',
11
12
  'usage_limit_reached': '已达到使用次数上限',
@@ -17,6 +18,7 @@ const locales = exports.locales = {
17
18
  'applicable_product_count_not_enough': '至少 {value} 件'
18
19
  },
19
20
  'en': {
21
+ 'empty_cart': 'Add items to the cart first.',
20
22
  'not_meet_the_required_conditions': 'Not meet the required conditions.',
21
23
  'exceeds_the_maximum_deduction_limit': 'Exceeds the maximum deduction limit.',
22
24
  'usage_limit_reached': 'Usage limit reached.',
@@ -28,6 +30,7 @@ const locales = exports.locales = {
28
30
  'applicable_product_count_not_enough': 'Min. Qty {value}'
29
31
  },
30
32
  'zh-HK': {
33
+ 'empty_cart': '請先添加商品到購物車',
31
34
  'not_meet_the_required_conditions': '未達使用條件',
32
35
  'exceeds_the_maximum_deduction_limit': '超出最大抵扣金額限制',
33
36
  'usage_limit_reached': '已達使用次數上限',
@@ -37,5 +40,11 @@ const locales = exports.locales = {
37
40
  'order_total_amount_not_enough': '滿 {currency}{value} 可用',
38
41
  'applicable_product_total_amount_not_enough': '滿 {currency}{value} 可用',
39
42
  'applicable_product_count_not_enough': '至少 {value} 件'
43
+ },
44
+ 'ja': {
45
+ 'empty_cart': '先に商品をカートに追加してください。'
46
+ },
47
+ 'pt': {
48
+ 'empty_cart': 'Adicione produtos ao carrinho primeiro.'
40
49
  }
41
50
  };
@@ -10,6 +10,8 @@ export declare const formatWalletPassList2PreparePayments: (list?: any[]) => {
10
10
  wallet_pass_usage_unit: any;
11
11
  wallet_pass_use_value: any;
12
12
  }[];
13
+ /** 这两种不可用原因随订单内容变化,其他服务端错误需保留。 */
14
+ export declare const isWalletOrderAvailabilityError: (code: unknown) => boolean;
13
15
  /**
14
16
  * 对用户识别码列表进行排序
15
17
  * 排序规则:正常数据 -> unified_available_status===1 -> 500601/500602 -> unified_available_status===0
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.sortUserIdentificationCodeList = exports.getAvailableMaxAmount = exports.formatWalletPassList2PreparePayments = void 0;
6
+ exports.sortUserIdentificationCodeList = exports.isWalletOrderAvailabilityError = exports.getAvailableMaxAmount = exports.formatWalletPassList2PreparePayments = void 0;
7
7
  // 获取walletPass可用最大金额
8
8
  const getAvailableMaxAmount = data => {
9
9
  if (typeof data._available_max_amount === 'number') {
@@ -32,20 +32,21 @@ const formatWalletPassList2PreparePayments = list => {
32
32
  return formatted;
33
33
  };
34
34
 
35
+ /** 这两种不可用原因随订单内容变化,其他服务端错误需保留。 */
36
+ exports.formatWalletPassList2PreparePayments = formatWalletPassList2PreparePayments;
37
+ const isWalletOrderAvailabilityError = code => String(code) === '500601' || String(code) === '500602';
38
+
35
39
  /**
36
40
  * 对用户识别码列表进行排序
37
41
  * 排序规则:正常数据 -> unified_available_status===1 -> 500601/500602 -> unified_available_status===0
38
42
  * @param list 用户识别码列表
39
43
  * @returns 排序后的列表
40
44
  */
41
- exports.formatWalletPassList2PreparePayments = formatWalletPassList2PreparePayments;
45
+ exports.isWalletOrderAvailabilityError = isWalletOrderAvailabilityError;
42
46
  const sortUserIdentificationCodeList = list => {
43
47
  if (!Array.isArray(list) || list.length === 0) {
44
48
  return list;
45
49
  }
46
-
47
- // 定义中等优先级错误码
48
- const middlePriorityErrorCodes = ['500601', '500602'];
49
50
  return list.sort((a, b) => {
50
51
  // 确定每个项目的优先级
51
52
  // 0: 正常数据(没有特定错误码且available_status不是1或0)
@@ -53,11 +54,10 @@ const sortUserIdentificationCodeList = list => {
53
54
  // 2: 中等优先级错误码(500601、500602) 此订单内不可用 订单没有剩余金额
54
55
  // 3: unified_available_status === 0(最后)
55
56
  const getPriority = item => {
56
- const errorCode = item.unified_error_code?.toString();
57
57
  const availableStatus = item.unified_available_status;
58
58
 
59
59
  // 中等优先级错误码
60
- if (errorCode && middlePriorityErrorCodes.includes(errorCode)) return 2;
60
+ if (isWalletOrderAvailabilityError(item.unified_error_code)) return 2;
61
61
 
62
62
  // unified_available_status === 0 最后
63
63
  if (availableStatus === 0) return 3;
@@ -23,6 +23,8 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
23
23
  */
24
24
  private emitEvent;
25
25
  private publishWalletAssetsState;
26
+ private get hasEmptyWalletCart();
27
+ private walletAssetForEmptyCart;
26
28
  private recalculateWalletAssets;
27
29
  /**
28
30
  * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.WalletPassPaymentImpl = void 0;
7
7
  var _types = require("./types");
8
+ var _locales = require("../../model/strategy/adapter/walletPass/locales");
8
9
  var _utils = require("./utils");
9
10
  const WALLET_PAYMENT_ASSET_TAGS = new Set(['product_voucher', 'gift_card', 'point_card']);
11
+
12
+ // 旧版搜索响应可能只有订单不适用的提示文本,没有 unified_error_code。
13
+ const LEGACY_CART_MESSAGES = new Set(['Voucher not applicable to current cart', 'No eligible items in the cart', _locales.locales.en.exceeds_the_maximum_deduction_limit]);
10
14
  function isWalletPaymentAsset(asset) {
11
15
  return WALLET_PAYMENT_ASSET_TAGS.has(String(asset?.tag || '').toLowerCase());
12
16
  }
@@ -174,6 +178,32 @@ class WalletPassPaymentImpl {
174
178
  });
175
179
  return state;
176
180
  }
181
+ get hasEmptyWalletCart() {
182
+ return this.walletParams !== null && this.walletAssetsCalculationContext.products.length === 0;
183
+ }
184
+ walletAssetForEmptyCart(asset) {
185
+ const unavailableAsset = {
186
+ ...asset,
187
+ actualDeduction: 0,
188
+ deductionDetails: [],
189
+ _available_max_amount: 0,
190
+ _unified_available_status: 0,
191
+ _wallet_asset_recommended: false
192
+ };
193
+ const errorCode = asset.unified_error_code;
194
+ const reportedReason = asset.unified_messages?.title || asset.error_msg || asset.disabledReason;
195
+ const reportedUnavailable = Number(asset.unified_available_status) === 0 || asset.available === false || asset.isDisabled === true;
196
+ const hasAssetRestriction = errorCode ? !(0, _utils.isWalletOrderAvailabilityError)(errorCode) : reportedUnavailable && reportedReason && !LEGACY_CART_MESSAGES.has(reportedReason);
197
+ if (hasAssetRestriction) {
198
+ return unavailableAsset;
199
+ }
200
+ const evaluator = this.paymentModule.window?.getWalletPassEvaluator?.();
201
+ return {
202
+ ...unavailableAsset,
203
+ reasonCode: 'empty_cart',
204
+ reason: evaluator?.getText?.('empty_cart') || _locales.locales.en.empty_cart
205
+ };
206
+ }
177
207
  recalculateWalletAssets(items, requestedIds, selectionSources) {
178
208
  const committedKeys = new Set(this.walletAssetsState.committedIds.map(id => String(id)));
179
209
  const itemsByKey = new Map(items.map(item => [getWalletAssetKey(item), item]));
@@ -181,7 +211,10 @@ class WalletPassPaymentImpl {
181
211
  let nextItems = items;
182
212
  let selectedItems = requested;
183
213
  const evaluator = this.paymentModule.window?.getWalletPassEvaluator?.();
184
- if (evaluator?.recalculateVouchers) {
214
+ if (this.hasEmptyWalletCart) {
215
+ nextItems = items.map(asset => committedKeys.has(getWalletAssetKey(asset)) ? asset : this.walletAssetForEmptyCart(asset));
216
+ selectedItems = [];
217
+ } else if (evaluator?.recalculateVouchers) {
185
218
  try {
186
219
  const result = evaluator.recalculateVouchers(items, requested, this.walletAssetsCalculationContext.orderTotalAmount, this.walletAssetsCalculationContext.products);
187
220
  nextItems = mergeWalletAssets(items, result?.allWithUpdatedStatus || []);
@@ -868,14 +901,7 @@ class WalletPassPaymentImpl {
868
901
  if (!businessData.products?.length) {
869
902
  this.queuePendingAutoSelectForAssets(scanSelectedAssets);
870
903
  this.generateWalletParams(businessData);
871
- const restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map(item => ({
872
- ...item,
873
- actualDeduction: 0,
874
- deductionDetails: [],
875
- _available_max_amount: 0,
876
- _unified_available_status: 0,
877
- _wallet_asset_recommended: false
878
- }));
904
+ const restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map(item => this.walletAssetForEmptyCart(item));
879
905
  this.walletRecommendList = [];
880
906
  this.userIdentificationCodes = [];
881
907
  this.walletInitData = {
@@ -1170,10 +1196,15 @@ class WalletPassPaymentImpl {
1170
1196
  selectionSources[String(id)] = 'scan';
1171
1197
  });
1172
1198
  const selected = this.walletAssetsBehavior.autoSelectAfterSearch ? this.recalculateWalletAssets(items, Array.from(new Set([...this.walletAssetsState.selectedIds, ...assetIds])), selectionSources) : this.recalculateWalletAssets(items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1199
+ const anySelected = assetIds.some(id => selected.selectedIds.includes(id));
1200
+ if (this.hasEmptyWalletCart) {
1201
+ this.queuePendingAutoSelectForAssets(assetsToApply);
1202
+ }
1203
+ const firstAssetKey = getWalletAssetKey(asset);
1173
1204
  return {
1174
1205
  type: result.type,
1175
- asset,
1176
- selected: assetIds.some(id => selected.selectedIds.includes(id)),
1206
+ asset: selected.items.find(item => getWalletAssetKey(item) === firstAssetKey) || asset,
1207
+ selected: anySelected,
1177
1208
  state: selected
1178
1209
  };
1179
1210
  }
@@ -3897,10 +3897,15 @@ class Server {
3897
3897
  biz: next.business_code || 'ticket'
3898
3898
  });
3899
3899
  }
3900
- if (needsShopFullOrderNumber && idGenerator.generateReceiptId) {
3901
- next.shop_full_order_number = await idGenerator.generateReceiptId({
3902
- biz: next.business_code || 'ticket'
3903
- });
3900
+ if (needsShopFullOrderNumber) {
3901
+ const biz = next.business_code || 'ticket';
3902
+ if (idGenerator.getConfig?.(biz)?.enableShortNumber === false) {
3903
+ next.shop_full_order_number = next.shop_order_number;
3904
+ } else if (idGenerator.generateReceiptId) {
3905
+ next.shop_full_order_number = await idGenerator.generateReceiptId({
3906
+ biz
3907
+ });
3908
+ }
3904
3909
  }
3905
3910
  this.logInfo(`${title}: checkout 订单号已准备`, {
3906
3911
  shop_order_number: next.shop_order_number,
@@ -35,8 +35,10 @@ export declare class ProductsModule extends BaseModule implements Module {
35
35
  private syncTimer?;
36
36
  /** 最近一次 SSE 全量拉取完成时间 */
37
37
  private lastServerFullFetchAtMs;
38
- /** 最近一次 preload 完成时间(含 IndexDB 命中) */
38
+ /** 最近一次 preload 完成时间(含 IndexDB 命中,仅用于日志) */
39
39
  private lastPreloadCompletedAtMs;
40
+ private serverFullFetchPromise?;
41
+ private silentRefreshPromise?;
40
42
  /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
41
43
  private productIndexDBSaveQueue;
42
44
  /** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
@@ -206,7 +208,8 @@ export declare class ProductsModule extends BaseModule implements Module {
206
208
  */
207
209
  loadProductsByServer(options?: {
208
210
  trigger?: string;
209
- }): Promise<any>;
211
+ }): Promise<ProductData[]>;
212
+ private fetchAndPersistProductsByServer;
210
213
  /**
211
214
  * 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
212
215
  * @param params 查询参数
@@ -358,6 +361,7 @@ export declare class ProductsModule extends BaseModule implements Module {
358
361
  silentRefresh(options?: {
359
362
  trigger?: string;
360
363
  }): Promise<ProductData[]>;
364
+ private runSilentRefresh;
361
365
  /**
362
366
  * 销毁同步资源(取消 pubsub 订阅、清除定时器)
363
367
  */
@@ -16,7 +16,7 @@ var _replication = require("./replication");
16
16
  const INDEXDB_STORE_NAME = 'products';
17
17
  /** 商品同步防抖时间(毫秒) */
18
18
  const PRODUCT_SYNC_DEBOUNCE_MS = 10_000;
19
- /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
19
+ /** silentRefresh 最小间隔,仅从成功的服务器全量刷新计时 */
20
20
  const PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS = 30_000;
21
21
 
22
22
  /**
@@ -63,8 +63,10 @@ class ProductsModule extends _BaseModule.BaseModule {
63
63
  syncTimer;
64
64
  /** 最近一次 SSE 全量拉取完成时间 */
65
65
  lastServerFullFetchAtMs = 0;
66
- /** 最近一次 preload 完成时间(含 IndexDB 命中) */
66
+ /** 最近一次 preload 完成时间(含 IndexDB 命中,仅用于日志) */
67
67
  lastPreloadCompletedAtMs = 0;
68
+ serverFullFetchPromise;
69
+ silentRefreshPromise;
68
70
  /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
69
71
  productIndexDBSaveQueue = Promise.resolve();
70
72
 
@@ -961,11 +963,20 @@ class ProductsModule extends _BaseModule.BaseModule {
961
963
  */
962
964
  async loadProductsByServer(options = {}) {
963
965
  if (this.isMemoryReplica()) return this.refreshFromReplica(options.trigger || 'loadProductsByServer');
966
+ if (this.serverFullFetchPromise) return this.serverFullFetchPromise;
967
+ const fetchPromise = this.fetchAndPersistProductsByServer(options.trigger || 'unknown');
968
+ this.serverFullFetchPromise = fetchPromise;
969
+ try {
970
+ return await fetchPromise;
971
+ } finally {
972
+ if (this.serverFullFetchPromise === fetchPromise) this.serverFullFetchPromise = undefined;
973
+ }
974
+ }
975
+ async fetchAndPersistProductsByServer(trigger) {
964
976
  if (!this.productDataSource) {
965
977
  this.logWarning('loadProductsByServer: ProductDataSource 不可用');
966
978
  return [];
967
979
  }
968
- const trigger = options.trigger || 'unknown';
969
980
  this.logInfo('开始通过 DataSource SSE 加载商品列表', {
970
981
  trigger
971
982
  });
@@ -1415,6 +1426,8 @@ class ProductsModule extends _BaseModule.BaseModule {
1415
1426
  await this.refreshFromReplica('preload');
1416
1427
  return;
1417
1428
  }
1429
+ const productsBeforePreload = this.store.list;
1430
+ const fullFetchBeforePreload = this.lastServerFullFetchAtMs;
1418
1431
  const tTotal = performance.now();
1419
1432
  this.logInfo('开始预加载数据');
1420
1433
  try {
@@ -1423,6 +1436,11 @@ class ProductsModule extends _BaseModule.BaseModule {
1423
1436
  (0, _product.perfMark)('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1424
1437
  count: cachedData?.length ?? 0
1425
1438
  });
1439
+
1440
+ // PIN 刷新若先完成,不用随后读出的旧缓存覆盖服务器列表。
1441
+ if (this.lastServerFullFetchAtMs !== fullFetchBeforePreload && this.store.list !== productsBeforePreload) {
1442
+ return;
1443
+ }
1426
1444
  if (cachedData && cachedData.length > 0) {
1427
1445
  // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
1428
1446
  this.store.list = cachedData;
@@ -1915,13 +1933,18 @@ class ProductsModule extends _BaseModule.BaseModule {
1915
1933
  * @returns 刷新后的商品列表
1916
1934
  */
1917
1935
  async silentRefresh(options = {}) {
1918
- if (this.isMemoryReplica()) return this.refreshFromReplica(options.trigger || 'background');
1919
- const t0 = performance.now();
1920
- const now = Date.now();
1921
1936
  const trigger = options.trigger || 'background';
1937
+ if (this.isMemoryReplica()) return this.refreshFromReplica(trigger);
1938
+ if (this.silentRefreshPromise) {
1939
+ this.logInfo('silentRefresh 复用进行中的全量刷新', {
1940
+ trigger
1941
+ });
1942
+ return this.silentRefreshPromise;
1943
+ }
1944
+ const now = Date.now();
1922
1945
  const elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
1923
1946
  const elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
1924
- if (this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
1947
+ if (!this.serverFullFetchPromise && this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
1925
1948
  this.logInfo('silentRefresh 跳过全量 SSE', {
1926
1949
  trigger,
1927
1950
  reason: 'within_min_interval',
@@ -1938,6 +1961,16 @@ class ProductsModule extends _BaseModule.BaseModule {
1938
1961
  elapsedSinceFullFetchMs,
1939
1962
  productCount: this.store.list.length
1940
1963
  });
1964
+ const refreshPromise = this.runSilentRefresh(trigger);
1965
+ this.silentRefreshPromise = refreshPromise;
1966
+ try {
1967
+ return await refreshPromise;
1968
+ } finally {
1969
+ if (this.silentRefreshPromise === refreshPromise) this.silentRefreshPromise = undefined;
1970
+ }
1971
+ }
1972
+ async runSilentRefresh(trigger) {
1973
+ const t0 = performance.now();
1941
1974
  try {
1942
1975
  const products = await this.loadProductsByServer({
1943
1976
  trigger
@@ -384,6 +384,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
384
384
  await idGenerator.configure({
385
385
  biz: businessCode,
386
386
  config: {
387
+ enableShortNumber: openDataConfig?.['sale.enable_short_number'] !== false,
387
388
  prefix,
388
389
  deviceCode: deviceId,
389
390
  padReceiptSequence: openDataConfig?.['sale.pad_with_leading_zeros'] === true,
@@ -2076,7 +2077,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
2076
2077
  if (invoiceContextChanged) {
2077
2078
  await this.prepareInvoiceTemplateAtSolutionReady(Object.prototype.hasOwnProperty.call(params, 'openData') ? this.getInjectedOpenDataConfig() : undefined);
2078
2079
  }
2079
- if (params?.businessCode !== undefined || params?.business_code !== undefined) {
2080
+ if (params?.businessCode !== undefined || params?.business_code !== undefined || Object.prototype.hasOwnProperty.call(params ?? {}, 'openData')) {
2080
2081
  await this.configureIdGeneratorFromOpenData();
2081
2082
  }
2082
2083
  }
@@ -278,7 +278,7 @@ async function applyGlobalScan(host, formatted, bridge) {
278
278
  }
279
279
  // 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
280
280
  if (!bindResult.resolveFailed) {
281
- bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
281
+ bridge?.onNotify?.('fail', walletResult.asset.reasonCode === 'empty_cart' ? 'pisell2.sale-detail.promotion-panel.add-items-first' : 'pisell2.text.goodpass.code-invalid-cart');
282
282
  }
283
283
  return {
284
284
  status: 'failed',
@@ -1956,7 +1956,8 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1956
1956
  const biz = this.getBookingTicketBusinessCode();
1957
1957
  if (!biz) throw new Error('当前订单缺少业务类型,无法生成订单编号');
1958
1958
  const idGenerator = this.appPlugin?.getApp?.()?.getPlugin?.('idGenerator');
1959
- if (!tempOrder.shop_order_number && typeof idGenerator?.generateShopOrderNumber !== 'function' || !tempOrder.shop_full_order_number && typeof idGenerator?.generateReceiptId !== 'function') {
1959
+ const useLongNumber = idGenerator?.getConfig?.(biz)?.enableShortNumber === false;
1960
+ if (!tempOrder.shop_order_number && typeof idGenerator?.generateShopOrderNumber !== 'function' || !tempOrder.shop_full_order_number && !useLongNumber && typeof idGenerator?.generateReceiptId !== 'function') {
1960
1961
  throw new Error('订单编号生成器不可用,请重启应用后重试');
1961
1962
  }
1962
1963
  try {
@@ -1966,7 +1967,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1966
1967
  });
1967
1968
  }
1968
1969
  if (!tempOrder.shop_full_order_number) {
1969
- tempOrder.shop_full_order_number = await idGenerator.generateReceiptId({
1970
+ tempOrder.shop_full_order_number = useLongNumber ? tempOrder.shop_order_number : await idGenerator.generateReceiptId({
1970
1971
  biz
1971
1972
  });
1972
1973
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.325",
4
+ "version": "2.2.326",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",