@pisell/pisellos 2.2.324 → 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.
Files changed (32) hide show
  1. package/dist/model/strategy/adapter/walletPass/locales.js +9 -0
  2. package/dist/modules/Order/index.d.ts +1 -1
  3. package/dist/modules/Payment/utils.d.ts +2 -0
  4. package/dist/modules/Payment/utils.js +6 -6
  5. package/dist/modules/Payment/walletpass.d.ts +2 -0
  6. package/dist/modules/Payment/walletpass.js +75 -34
  7. package/dist/modules/Product/index.d.ts +1 -1
  8. package/dist/server/index.d.ts +3 -0
  9. package/dist/server/index.js +792 -645
  10. package/dist/server/modules/products/index.d.ts +6 -2
  11. package/dist/server/modules/products/index.js +476 -400
  12. package/dist/solution/BookingByStep/index.d.ts +1 -1
  13. package/dist/solution/BookingTicket/index.js +6 -5
  14. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +1 -1
  15. package/dist/solution/UnifiedBookingSales/index.js +34 -23
  16. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  17. package/lib/model/strategy/adapter/walletPass/locales.js +9 -0
  18. package/lib/modules/Order/index.d.ts +1 -1
  19. package/lib/modules/Payment/utils.d.ts +2 -0
  20. package/lib/modules/Payment/utils.js +7 -7
  21. package/lib/modules/Payment/walletpass.d.ts +2 -0
  22. package/lib/modules/Payment/walletpass.js +42 -11
  23. package/lib/modules/Product/index.d.ts +1 -1
  24. package/lib/server/index.d.ts +3 -0
  25. package/lib/server/index.js +79 -7
  26. package/lib/server/modules/products/index.d.ts +6 -2
  27. package/lib/server/modules/products/index.js +40 -7
  28. package/lib/solution/BookingByStep/index.d.ts +1 -1
  29. package/lib/solution/BookingTicket/index.js +2 -1
  30. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +1 -1
  31. package/lib/solution/UnifiedBookingSales/index.js +3 -2
  32. package/package.json +1 -1
@@ -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
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
345
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -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.324",
4
+ "version": "2.2.326",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",