@pisell/pisellos 2.3.113 → 2.3.115

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 (42) hide show
  1. package/dist/modules/Order/index.d.ts +14 -4
  2. package/dist/modules/Order/index.js +316 -248
  3. package/dist/modules/Order/types.d.ts +11 -0
  4. package/dist/modules/Order/utils.d.ts +3 -1
  5. package/dist/modules/Order/utils.js +171 -63
  6. package/dist/modules/Payment/index.d.ts +0 -5
  7. package/dist/modules/Payment/index.js +35 -85
  8. package/dist/modules/ResourcePlanner/planner.js +9 -5
  9. package/dist/modules/ResourcePlanner/types.d.ts +2 -1
  10. package/dist/server/index.js +4 -0
  11. package/dist/server/modules/order/index.js +6 -0
  12. package/dist/server/modules/order/types.d.ts +9 -0
  13. package/dist/server/modules/payment/index.d.ts +25 -6
  14. package/dist/server/modules/payment/index.js +660 -133
  15. package/dist/server/utils/small-ticket.js +108 -4
  16. package/dist/solution/BaseSales/index.d.ts +8 -0
  17. package/dist/solution/BaseSales/index.js +1381 -1141
  18. package/dist/solution/BookingByStep/index.d.ts +1 -1
  19. package/dist/solution/BookingTicket/index.d.ts +2 -1
  20. package/dist/solution/BookingTicket/index.js +37 -16
  21. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  22. package/lib/modules/Order/index.d.ts +14 -4
  23. package/lib/modules/Order/index.js +50 -15
  24. package/lib/modules/Order/types.d.ts +11 -0
  25. package/lib/modules/Order/utils.d.ts +3 -1
  26. package/lib/modules/Order/utils.js +101 -0
  27. package/lib/modules/Payment/index.d.ts +0 -5
  28. package/lib/modules/Payment/index.js +3 -28
  29. package/lib/modules/ResourcePlanner/planner.js +9 -5
  30. package/lib/modules/ResourcePlanner/types.d.ts +2 -1
  31. package/lib/server/index.js +4 -0
  32. package/lib/server/modules/order/index.js +6 -0
  33. package/lib/server/modules/order/types.d.ts +9 -0
  34. package/lib/server/modules/payment/index.d.ts +25 -6
  35. package/lib/server/modules/payment/index.js +350 -78
  36. package/lib/server/utils/small-ticket.js +114 -11
  37. package/lib/solution/BaseSales/index.d.ts +8 -0
  38. package/lib/solution/BaseSales/index.js +134 -22
  39. package/lib/solution/BookingByStep/index.d.ts +1 -1
  40. package/lib/solution/BookingTicket/index.d.ts +2 -1
  41. package/lib/solution/BookingTicket/index.js +23 -5
  42. package/package.json +1 -1
@@ -72,6 +72,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
72
72
  private walletAssetsRefreshSequence;
73
73
  private salesDetailHydrateQueue;
74
74
  private serverOrderChangeUnsubscribe;
75
+ private paymentMethodsChangedUnsubscribe;
75
76
  private serverOrderChangeHydrateInFlight;
76
77
  private queuedServerOrderChanges;
77
78
  private serverOrderChangeSyncEnabled;
@@ -101,6 +102,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
101
102
  private drainQueuedServerOrderChanges;
102
103
  private syncCurrentSalesDetailFromServerOrderChange;
103
104
  private registerServerOrderChangeSync;
105
+ private registerPaymentMethodsChangeSync;
104
106
  private hydrateLatestLoadedSalesDetail;
105
107
  private hydrateOrderPaymentNames;
106
108
  get payment(): PaymentModule | undefined;
@@ -271,6 +273,12 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
271
273
  private mergeHistoricalDiscountList;
272
274
  private shouldSkipAutoApplyFetchedDiscountsInEditMode;
273
275
  private mergeCurrentDiscountSelectionState;
276
+ private resolveDiscountConfigCustomerId;
277
+ /**
278
+ * Stable across notifyTempOrderChanged's immutable object replacement, while
279
+ * still distinguishing two local orders for the same customer.
280
+ */
281
+ private getDiscountConfigOrderIdentityKey;
274
282
  loadDiscountConfig(params?: {
275
283
  customerId?: number;
276
284
  action?: 'create' | 'edit';
@@ -37,6 +37,7 @@ var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductT
37
37
  var _quotationPrice = require("./utils/quotationPrice");
38
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
39
  const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
40
+ const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
40
41
  const OS_FULFILLMENT_REF_MODE_FIELD = '_os_fulfillment_ref_mode';
41
42
  const OS_INVOICE_LAYOUT_CONFIG_FIELD = '_os_invoice_layout_config';
42
43
  const OS_INVOICE_TEMPLATE_SETTINGS_FIELD = '_os_invoice_template_settings';
@@ -345,6 +346,7 @@ function areBaseSalesNotesEquivalent(currentValue, loadedValue, options) {
345
346
  return currentNotes !== null && loadedNotes !== null && (0, _lodashEs.isEqual)(currentNotes, loadedNotes);
346
347
  }
347
348
  function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
349
+ const loadedHasOrderMetaList = Object.prototype.hasOwnProperty.call(loadedRecord || {}, 'order_meta_list');
348
350
  const loadedHasSalesNotes = Object.prototype.hasOwnProperty.call(loadedRecord || {}, 'notes');
349
351
  const hasDirtyLocalSalesNotes = currentTempOrder?._extend?.salesNotesState?.dirty === true;
350
352
  const incomingSalesNotesMatchLocal = loadedHasSalesNotes && areBaseSalesNotesEquivalent(currentTempOrder?.notes, loadedRecord.notes, {
@@ -363,6 +365,12 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
363
365
  });
364
366
  const uidRemaps = [];
365
367
  const mergedRecord = (0, _lodashEs.mergeWith)(normalizedCurrentTempOrder, normalizedLoadedRecord, (currentValue, loadedValue, key) => {
368
+ // order_meta_list 是服务端/本地订单携带的完整业务快照。若 incoming
369
+ // 明确提供它,必须整体替换;若省略,则保留当前值,避免 snapshot
370
+ // 数组递归拼接后出现同 ID 的旧数据。
371
+ if (key === 'order_meta_list') {
372
+ return (0, _lodashEs.cloneDeep)(loadedHasOrderMetaList ? loadedValue : currentValue);
373
+ }
366
374
  if (key === 'notes') {
367
375
  if (preserveDirtyLocalSalesNotes && Array.isArray(currentValue)) {
368
376
  return (0, _lodashEs.cloneDeep)(currentValue);
@@ -487,6 +495,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
487
495
  walletAssetsRefreshSequence = 0;
488
496
  salesDetailHydrateQueue = Promise.resolve();
489
497
  serverOrderChangeUnsubscribe = null;
498
+ paymentMethodsChangedUnsubscribe = null;
490
499
  serverOrderChangeHydrateInFlight = null;
491
500
  queuedServerOrderChanges = [];
492
501
  serverOrderChangeSyncEnabled = false;
@@ -630,6 +639,15 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
630
639
  });
631
640
  });
632
641
  }
642
+ registerPaymentMethodsChangeSync() {
643
+ this.paymentMethodsChangedUnsubscribe?.();
644
+ const effects = this.core?.effects;
645
+ if (!effects || typeof effects.on !== 'function') return;
646
+ this.paymentMethodsChangedUnsubscribe = effects.on(PAYMENT_METHODS_CHANGED_EVENT, async payload => {
647
+ if (!Array.isArray(payload?.newMethods)) return;
648
+ await this.getPaymentMethodsAsync();
649
+ });
650
+ }
633
651
  async hydrateLatestLoadedSalesDetail(record, loadSequence, options) {
634
652
  let hydratedSales = null;
635
653
  let skippedBeforeHydrate = false;
@@ -1331,9 +1349,22 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1331
1349
  }
1332
1350
  syncAppDataToTempOrder(tempOrder) {
1333
1351
  const isPriceIncludeTax = this.getAppData('is_price_include_tax');
1334
- const taxCountryCode = this.getAppData('tax_country_code');
1335
- const currencyCode = this.getAppData('shop_currency_code');
1336
- const currencySymbol = this.getAppData('shop_symbol');
1352
+ const rawTaxCountryCode = this.getAppData('tax_country_code');
1353
+ const rawCurrencyCode = this.getAppData('shop_currency_code');
1354
+ const rawCurrencySymbol = this.getAppData('shop_symbol');
1355
+ const normalizeNonBlankValue = value => {
1356
+ if (value === undefined || value === null) return undefined;
1357
+ const normalizedValue = String(value).trim();
1358
+ return normalizedValue || undefined;
1359
+ };
1360
+ const taxCountryCode = normalizeNonBlankValue(rawTaxCountryCode);
1361
+ const currencyCode = normalizeNonBlankValue(rawCurrencyCode);
1362
+ const currencySymbol = normalizeNonBlankValue(rawCurrencySymbol);
1363
+ const before = {
1364
+ tax_country_code: tempOrder.tax_country_code,
1365
+ currency_code: tempOrder.currency_code,
1366
+ currency_symbol: tempOrder.currency_symbol
1367
+ };
1337
1368
  // 历史虚拟币订单不依赖交易开关;普通 POS 不从商品行残留快照推断订单币种。
1338
1369
  const isHistoricalVirtualSettlement = this.isHistoricalVirtualSettlementOrder(tempOrder);
1339
1370
  const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder) || isHistoricalVirtualSettlement;
@@ -1347,9 +1378,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1347
1378
  }
1348
1379
  }
1349
1380
  if (taxCountryCode !== undefined) {
1350
- const nextTaxCountryCode = String(taxCountryCode || '');
1351
- if (tempOrder.tax_country_code !== nextTaxCountryCode) {
1352
- tempOrder.tax_country_code = nextTaxCountryCode;
1381
+ if (tempOrder.tax_country_code !== taxCountryCode) {
1382
+ tempOrder.tax_country_code = taxCountryCode;
1353
1383
  isChanged = true;
1354
1384
  }
1355
1385
  }
@@ -1366,19 +1396,45 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1366
1396
  }
1367
1397
  }
1368
1398
  if (!isVirtualSettlement && currencyCode !== undefined) {
1369
- const nextCurrencyCode = String(currencyCode || '');
1370
- if (tempOrder.currency_code !== nextCurrencyCode) {
1371
- tempOrder.currency_code = nextCurrencyCode;
1399
+ if (tempOrder.currency_code !== currencyCode) {
1400
+ tempOrder.currency_code = currencyCode;
1372
1401
  isChanged = true;
1373
1402
  }
1374
1403
  }
1375
1404
  if (!isVirtualSettlement && currencySymbol !== undefined) {
1376
- const nextCurrencySymbol = String(currencySymbol || '');
1377
- if (tempOrder.currency_symbol !== nextCurrencySymbol) {
1378
- tempOrder.currency_symbol = nextCurrencySymbol;
1405
+ if (tempOrder.currency_symbol !== currencySymbol) {
1406
+ tempOrder.currency_symbol = currencySymbol;
1379
1407
  isChanged = true;
1380
1408
  }
1381
1409
  }
1410
+ try {
1411
+ const orderIdentity = this.store.order?.getOrderIdentity?.();
1412
+ this.logger?.addLog?.({
1413
+ type: 'info',
1414
+ title: 'syncAppDataToTempOrder',
1415
+ metadata: {
1416
+ moduleName: this.name,
1417
+ cacheId: this.cacheId,
1418
+ orderId: orderIdentity?.orderId ?? tempOrder.order_id,
1419
+ externalSaleNumber: orderIdentity?.externalSaleNumber ?? tempOrder.external_sale_number,
1420
+ shopOrderNumber: orderIdentity?.shopOrderNumber ?? tempOrder.shop_order_number,
1421
+ readValues: {
1422
+ tax_country_code: rawTaxCountryCode,
1423
+ shop_currency_code: rawCurrencyCode,
1424
+ shop_symbol: rawCurrencySymbol
1425
+ },
1426
+ before,
1427
+ after: {
1428
+ tax_country_code: tempOrder.tax_country_code,
1429
+ currency_code: tempOrder.currency_code,
1430
+ currency_symbol: tempOrder.currency_symbol
1431
+ },
1432
+ isChanged
1433
+ }
1434
+ });
1435
+ } catch {
1436
+ // 诊断日志不能影响订单字段同步。
1437
+ }
1382
1438
  return isChanged;
1383
1439
  }
1384
1440
  async initialize(core, options = {}) {
@@ -1429,12 +1485,15 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1429
1485
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
1430
1486
  }
1431
1487
  await this.getPaymentMethodsAsync();
1488
+ this.registerPaymentMethodsChangeSync();
1432
1489
  this.registerServerOrderChangeSync();
1433
1490
  this.core.effects.emit(`${this.name}:onInited`, {});
1434
1491
  }
1435
1492
  async destroy() {
1436
1493
  this.serverOrderChangeUnsubscribe?.();
1437
1494
  this.serverOrderChangeUnsubscribe = null;
1495
+ this.paymentMethodsChangedUnsubscribe?.();
1496
+ this.paymentMethodsChangedUnsubscribe = null;
1438
1497
  Object.keys(this.store).forEach(key => {
1439
1498
  if (this.reusedSharedSubModuleNames.has(key)) return;
1440
1499
  const sub = this.store[key];
@@ -1882,19 +1941,46 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1882
1941
  return discount;
1883
1942
  });
1884
1943
  }
1944
+ resolveDiscountConfigCustomerId(tempOrder) {
1945
+ return Number(tempOrder?.customer_id || tempOrder?.customer?.id || tempOrder?._extend?.customerSnapshot?.id || tempOrder?._extend?.customerSnapshot?.customer_id || 0);
1946
+ }
1947
+
1948
+ /**
1949
+ * Stable across notifyTempOrderChanged's immutable object replacement, while
1950
+ * still distinguishing two local orders for the same customer.
1951
+ */
1952
+ getDiscountConfigOrderIdentityKey(tempOrder) {
1953
+ const identity = this.store.order?.getOrderIdentity?.();
1954
+ return JSON.stringify([identity?.orderId ?? tempOrder?.order_id ?? '', tempOrder?.request_unique_idempotency_token ?? '', identity?.externalSaleNumber ?? tempOrder?.external_sale_number ?? '', identity?.localId ?? tempOrder?._extend?.localId ?? this.cacheId ?? '']);
1955
+ }
1885
1956
  async loadDiscountConfig(params) {
1886
1957
  if (!this.store.order) throw new Error('order 模块未初始化');
1887
1958
  const tempOrder = this.store.order.ensureTempOrder();
1888
1959
  const orderStore = this.store.order.store || {};
1889
1960
  const discountModule = orderStore.discount;
1890
1961
  const rulesModule = orderStore.rules;
1891
- const orderId = tempOrder.order_id || this.getOrderIdentity?.()?.orderId;
1962
+ const orderId = tempOrder.order_id || this.store.order.getOrderIdentity?.()?.orderId;
1892
1963
  const customerId = Number(params?.customerId || tempOrder.customer_id || tempOrder.customer?.id || tempOrder._extend?.customerSnapshot?.id || tempOrder._extend?.customerSnapshot?.customer_id || 0);
1893
1964
  const currentDiscountList = discountModule?.getDiscountList?.() || [];
1894
1965
  const originalDiscountList = discountModule?.getOriginalDiscountList?.() || [];
1895
1966
  const hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some(discount => discount.isManualSelect);
1896
1967
  const discountAction = params?.action || (orderId ? 'edit' : 'create');
1897
- const discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
1968
+ const requestOrderIdentityKey = this.getDiscountConfigOrderIdentityKey(tempOrder);
1969
+ const discountConfigCacheKey = JSON.stringify([customerId, discountAction, Number(orderId) || 0, requestOrderIdentityKey]);
1970
+ let requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
1971
+ const isCurrentRequest = () => {
1972
+ const currentTempOrder = this.store.order?.getTempOrder?.();
1973
+ return Boolean(currentTempOrder && (requestEpoch === undefined || this.store.order?.getCustomerWalletPrepareConfigEpoch?.() === requestEpoch) && this.resolveDiscountConfigCustomerId(currentTempOrder) === customerId && this.getDiscountConfigOrderIdentityKey(currentTempOrder) === requestOrderIdentityKey);
1974
+ };
1975
+ const getCurrentResult = () => {
1976
+ const currentTempOrder = this.store.order?.getTempOrder?.();
1977
+ return {
1978
+ productList: currentTempOrder?.products || [],
1979
+ discountList: discountModule?.getDiscountList?.() || [],
1980
+ availableWalletIds: this.getAvailableWalletIds(),
1981
+ virtualCurrencyList: this.getVirtualCurrencyList()
1982
+ };
1983
+ };
1898
1984
 
1899
1985
  // Walk-In 不请求 prepare config;当前搜索/扫码券必须继续参与本次重算。
1900
1986
  // current 优先于 original,保留搜索后的最新选择与可用状态。
@@ -1905,26 +1991,34 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1905
1991
  if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
1906
1992
  preparedDiscountList = originalDiscountList;
1907
1993
  } else {
1908
- preparedDiscountList = await this.store.order.loadDiscountConfig({
1994
+ const prepareConfigPromise = this.store.order.loadDiscountConfig({
1909
1995
  customerId,
1910
1996
  action: discountAction,
1911
1997
  orderId: Number(orderId) || undefined,
1912
1998
  apply: false
1913
1999
  });
1914
- this.discountConfigCacheKey = discountConfigCacheKey;
2000
+ // OrderModule increments this epoch synchronously before its first await.
2001
+ requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
2002
+ preparedDiscountList = await prepareConfigPromise;
2003
+ if (!isCurrentRequest()) return getCurrentResult();
1915
2004
  await discountModule?.setOriginalDiscountList?.(preparedDiscountList);
2005
+ if (!isCurrentRequest()) return getCurrentResult();
2006
+ this.discountConfigCacheKey = discountConfigCacheKey;
1916
2007
  }
1917
2008
  }
1918
2009
  if (this.isActiveVirtualSettlementOrder(tempOrder)) {
2010
+ if (!isCurrentRequest()) return getCurrentResult();
1919
2011
  await discountModule?.setOriginalDiscountList?.([]);
2012
+ if (!isCurrentRequest()) return getCurrentResult();
1920
2013
  await discountModule?.setDiscountList?.([]);
2014
+ if (!isCurrentRequest()) return getCurrentResult();
1921
2015
  tempOrder.discount_list = [];
1922
2016
  tempOrder.shop_discount = '0.00';
1923
2017
  return {
1924
2018
  productList: tempOrder.products || [],
1925
2019
  discountList: [],
1926
2020
  availableWalletIds: this.getAvailableWalletIds(),
1927
- virtualCurrencyList: this.store.order.getVirtualCurrencyList()
2021
+ virtualCurrencyList: this.getVirtualCurrencyList()
1928
2022
  };
1929
2023
  }
1930
2024
  if (hasManualDiscountSelection && currentDiscountList.length) {
@@ -1932,12 +2026,14 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1932
2026
  productList: tempOrder.products || [],
1933
2027
  discountList: currentDiscountList,
1934
2028
  availableWalletIds: this.getAvailableWalletIds(),
1935
- virtualCurrencyList: this.store.order.getVirtualCurrencyList()
2029
+ virtualCurrencyList: this.getVirtualCurrencyList()
1936
2030
  };
1937
2031
  }
1938
2032
  let nextDiscountList = this.mergeHistoricalDiscountList(preparedDiscountList || discountModule?.getDiscountList?.() || [], tempOrder.products || []);
1939
2033
  nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
2034
+ if (!isCurrentRequest()) return getCurrentResult();
1940
2035
  await discountModule?.setDiscountList(nextDiscountList);
2036
+ if (!isCurrentRequest()) return getCurrentResult();
1941
2037
  const shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
1942
2038
  discountAction,
1943
2039
  products: tempOrder.products || [],
@@ -1945,24 +2041,28 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1945
2041
  nextDiscountList
1946
2042
  });
1947
2043
  if (shouldSkipAutoApplyFetchedDiscounts) {
1948
- const summary = await this.store.order.recalculateSummary({
2044
+ await this.store.order.recalculateSummary({
1949
2045
  createIfMissing: true
1950
2046
  });
2047
+ if (!isCurrentRequest()) return getCurrentResult();
1951
2048
  this.store.order.persistTempOrder();
2049
+ if (!isCurrentRequest()) return getCurrentResult();
1952
2050
  await this.effectsEmit('onDiscountApplied', {
1953
2051
  productList: tempOrder.products || [],
1954
2052
  discountList: nextDiscountList,
1955
2053
  selectedDiscountList: tempOrder.discount_list || [],
1956
2054
  tempOrder
1957
2055
  });
2056
+ if (!isCurrentRequest()) return getCurrentResult();
1958
2057
  return {
1959
2058
  productList: tempOrder.products || [],
1960
2059
  discountList: nextDiscountList,
1961
2060
  availableWalletIds: this.getAvailableWalletIds(),
1962
- virtualCurrencyList: this.store.order.getVirtualCurrencyList()
2061
+ virtualCurrencyList: this.getVirtualCurrencyList()
1963
2062
  };
1964
2063
  }
1965
2064
  if (rulesModule) {
2065
+ if (!isCurrentRequest()) return getCurrentResult();
1966
2066
  const orderTotalAmount = Number(orderStore.summary?.total_amount || 0);
1967
2067
  const result = rulesModule.calcDiscount({
1968
2068
  productList: tempOrder.products,
@@ -1998,25 +2098,31 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1998
2098
  if (result.discountList) {
1999
2099
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
2000
2100
  _Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
2101
+ if (!isCurrentRequest()) return getCurrentResult();
2001
2102
  await discountModule?.setDiscountList(nextDiscountList);
2103
+ if (!isCurrentRequest()) return getCurrentResult();
2002
2104
  tempOrder.discount_list = nextDiscountList.filter(discount => discount.isSelected);
2003
2105
  }
2004
2106
  }
2005
- const summary = await this.store.order.recalculateSummary({
2107
+ if (!isCurrentRequest()) return getCurrentResult();
2108
+ await this.store.order.recalculateSummary({
2006
2109
  createIfMissing: true
2007
2110
  });
2111
+ if (!isCurrentRequest()) return getCurrentResult();
2008
2112
  this.store.order.persistTempOrder();
2113
+ if (!isCurrentRequest()) return getCurrentResult();
2009
2114
  await this.effectsEmit('onDiscountApplied', {
2010
2115
  productList: tempOrder.products || [],
2011
2116
  discountList: nextDiscountList,
2012
2117
  selectedDiscountList: tempOrder.discount_list || [],
2013
2118
  tempOrder
2014
2119
  });
2120
+ if (!isCurrentRequest()) return getCurrentResult();
2015
2121
  return {
2016
2122
  productList: tempOrder.products || [],
2017
2123
  discountList: nextDiscountList,
2018
2124
  availableWalletIds: this.getAvailableWalletIds(),
2019
- virtualCurrencyList: this.store.order.getVirtualCurrencyList()
2125
+ virtualCurrencyList: this.getVirtualCurrencyList()
2020
2126
  };
2021
2127
  }
2022
2128
  getAvailableWalletIds() {
@@ -3197,7 +3303,13 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3197
3303
  */
3198
3304
  updateOrderCustomer(customer) {
3199
3305
  if (!this.store.order) throw new Error('order 模块未初始化');
3306
+ const previousCustomerId = this.resolveDiscountConfigCustomerId(this.store.order.getTempOrder?.());
3200
3307
  const result = this.store.order.updateTempOrderCustomer(customer);
3308
+ const nextCustomerId = this.resolveDiscountConfigCustomerId(this.store.order.getTempOrder?.());
3309
+ if (String(previousCustomerId) !== String(nextCustomerId)) {
3310
+ this.discountConfigCacheKey = null;
3311
+ this.hasManualDiscountSelection = false;
3312
+ }
3201
3313
  this.store.order.recalculateSummary({
3202
3314
  createIfMissing: true
3203
3315
  });
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 6 | 5 | 3 | 4;
329
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -29,6 +29,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
29
29
  private addTimeProductsCatalog;
30
30
  private orderCustomerDiscountRefreshInFlight;
31
31
  private orderCustomerDiscountRefreshCustomerId;
32
+ private orderCustomerDiscountRefreshTarget;
32
33
  private orderCustomerPromotionRefreshInFlight;
33
34
  protected loadOpenDataInFlight: Promise<OpenDataConfig> | null;
34
35
  protected loadOpenDataInFlightTarget: string | null;
@@ -345,7 +346,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
345
346
  * 获取当前的客户搜索条件
346
347
  * @returns 当前搜索条件
347
348
  */
348
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
349
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
349
350
  /**
350
351
  * 获取客户列表状态(包含滚动加载相关状态)
351
352
  * @returns 客户状态
@@ -160,6 +160,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
160
160
  addTimeProductsCatalog = [];
161
161
  orderCustomerDiscountRefreshInFlight = null;
162
162
  orderCustomerDiscountRefreshCustomerId = null;
163
+ orderCustomerDiscountRefreshTarget = null;
163
164
  orderCustomerPromotionRefreshInFlight = null;
164
165
  loadOpenDataInFlight = null;
165
166
  loadOpenDataInFlightTarget = null;
@@ -1121,7 +1122,13 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1121
1122
  }
1122
1123
  refreshDiscountConfigAfterOrderCustomerChange(customerId) {
1123
1124
  if (!customerId || customerId === 1) return Promise.resolve();
1124
- if (this.orderCustomerDiscountRefreshInFlight && this.orderCustomerDiscountRefreshCustomerId === customerId) {
1125
+ const tempOrder = this.store.order.getTempOrder?.();
1126
+ const orderIdentity = this.getOrderIdentity?.();
1127
+ const orderId = tempOrder?.order_id || orderIdentity?.orderId;
1128
+ const action = !orderId || String(orderId).startsWith('local_order') ? 'create' : 'edit';
1129
+ const orderTarget = orderId ? `order:${String(orderId)}` : `external:${String(tempOrder?.external_sale_number || orderIdentity?.externalSaleNumber || orderIdentity?.localId || 'new')}`;
1130
+ const refreshTarget = `${customerId}:${action}:${orderTarget}`;
1131
+ if (this.orderCustomerDiscountRefreshInFlight && this.orderCustomerDiscountRefreshTarget === refreshTarget) {
1125
1132
  return this.orderCustomerDiscountRefreshInFlight;
1126
1133
  }
1127
1134
  const previousRefresh = this.orderCustomerDiscountRefreshInFlight;
@@ -1133,22 +1140,33 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1133
1140
  if (!currentCustomer || Number(currentCustomer.customer_id) !== customerId) {
1134
1141
  return;
1135
1142
  }
1136
- const tempOrder = this.store.order.getTempOrder?.();
1137
- const orderId = tempOrder?.order_id || this.getOrderIdentity?.()?.orderId;
1138
- const action = !orderId || String(orderId).startsWith('local_order') ? 'create' : 'edit';
1143
+ const currentTempOrder = this.store.order.getTempOrder?.();
1144
+ const currentOrderIdentity = this.getOrderIdentity?.();
1145
+ const currentOrderId = currentTempOrder?.order_id || currentOrderIdentity?.orderId;
1146
+ const currentAction = !currentOrderId || String(currentOrderId).startsWith('local_order') ? 'create' : 'edit';
1147
+ const currentOrderTarget = currentOrderId ? `order:${String(currentOrderId)}` : `external:${String(currentTempOrder?.external_sale_number || currentOrderIdentity?.externalSaleNumber || currentOrderIdentity?.localId || 'new')}`;
1148
+ if (`${customerId}:${currentAction}:${currentOrderTarget}` !== refreshTarget) {
1149
+ return;
1150
+ }
1151
+
1152
+ // 上一个订单的迟到请求可能在客户切换后重新写入 BaseSales cache key;
1153
+ // 客户变更触发的目标订单刷新必须绕过该缓存。
1139
1154
  await this.loadDiscountConfig({
1140
1155
  customerId,
1141
- action
1156
+ action,
1157
+ force: true
1142
1158
  });
1143
1159
  })();
1144
1160
  this.orderCustomerDiscountRefreshInFlight = refreshTask;
1145
1161
  this.orderCustomerDiscountRefreshCustomerId = customerId;
1162
+ this.orderCustomerDiscountRefreshTarget = refreshTarget;
1146
1163
  refreshTask.catch(error => {
1147
1164
  console.error('Failed to load discount config after customer change:', error);
1148
1165
  }).finally(() => {
1149
1166
  if (this.orderCustomerDiscountRefreshInFlight !== refreshTask) return;
1150
1167
  this.orderCustomerDiscountRefreshInFlight = null;
1151
1168
  this.orderCustomerDiscountRefreshCustomerId = null;
1169
+ this.orderCustomerDiscountRefreshTarget = null;
1152
1170
  });
1153
1171
  return refreshTask;
1154
1172
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.113",
4
+ "version": "2.3.115",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",