@pisell/pisellos 2.3.114 → 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.
- package/dist/modules/Order/index.d.ts +14 -4
- package/dist/modules/Order/index.js +316 -248
- package/dist/modules/Order/types.d.ts +11 -0
- package/dist/modules/Order/utils.d.ts +3 -1
- package/dist/modules/Order/utils.js +171 -63
- package/dist/server/modules/order/index.js +6 -0
- package/dist/server/modules/order/types.d.ts +9 -0
- package/dist/server/utils/small-ticket.js +108 -4
- package/dist/solution/BaseSales/index.d.ts +6 -0
- package/dist/solution/BaseSales/index.js +364 -163
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -0
- package/dist/solution/BookingTicket/index.js +37 -16
- package/lib/modules/Order/index.d.ts +14 -4
- package/lib/modules/Order/index.js +50 -15
- package/lib/modules/Order/types.d.ts +11 -0
- package/lib/modules/Order/utils.d.ts +3 -1
- package/lib/modules/Order/utils.js +101 -0
- package/lib/server/modules/order/index.js +6 -0
- package/lib/server/modules/order/types.d.ts +9 -0
- package/lib/server/utils/small-ticket.js +114 -11
- package/lib/solution/BaseSales/index.d.ts +6 -0
- package/lib/solution/BaseSales/index.js +120 -22
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -0
- package/lib/solution/BookingTicket/index.js +23 -5
- package/package.json +1 -1
|
@@ -1378,20 +1378,30 @@ function resolveRefundPayment(refund, payments) {
|
|
|
1378
1378
|
return matchedPayment || refund;
|
|
1379
1379
|
}
|
|
1380
1380
|
function buildWallets(params) {
|
|
1381
|
+
const virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order);
|
|
1381
1382
|
const displayedWalletPayments = normalizeArray(params.order.payments).filter(payment => isPrintablePayment(payment) && !!getFundRecord(payment));
|
|
1382
|
-
const paymentWallets = displayedWalletPayments.map(payment =>
|
|
1383
|
-
payment,
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1383
|
+
const paymentWallets = displayedWalletPayments.map(payment => {
|
|
1384
|
+
const virtualCurrencySnapshot = findVirtualCurrencySnapshotForPayment(payment, virtualCurrencySnapshots.byId);
|
|
1385
|
+
return buildPaymentItems({
|
|
1386
|
+
payment,
|
|
1387
|
+
locale: params.locale,
|
|
1388
|
+
currencySymbol: params.currencySymbol,
|
|
1389
|
+
includeFundRecordBalance: true,
|
|
1390
|
+
includeFundRecordUsage: false,
|
|
1391
|
+
includePaymentAmount: false,
|
|
1392
|
+
virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
|
|
1393
|
+
});
|
|
1394
|
+
});
|
|
1390
1395
|
const displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
|
|
1391
1396
|
return [...paymentWallets, ...buildVoucherAssets(params), ...buildPointCardSnapshotAssets({
|
|
1392
1397
|
order: params.order,
|
|
1393
1398
|
locale: params.locale,
|
|
1394
1399
|
displayedWalletPassIds
|
|
1400
|
+
}), ...buildVirtualCurrencySnapshotAssets({
|
|
1401
|
+
snapshots: virtualCurrencySnapshots.items,
|
|
1402
|
+
order: params.order,
|
|
1403
|
+
locale: params.locale,
|
|
1404
|
+
displayedWalletPassIds
|
|
1395
1405
|
})];
|
|
1396
1406
|
}
|
|
1397
1407
|
function collectDisplayedWalletPassIds(payments) {
|
|
@@ -1438,6 +1448,88 @@ function buildPointCardSnapshotAssets(params) {
|
|
|
1438
1448
|
return [rows];
|
|
1439
1449
|
});
|
|
1440
1450
|
}
|
|
1451
|
+
function collectVirtualCurrencySnapshots(order) {
|
|
1452
|
+
const items = [];
|
|
1453
|
+
const byId = new Map();
|
|
1454
|
+
const snapshots = order.order_meta_list?.virtual_currency_snapshot;
|
|
1455
|
+
if (!Array.isArray(snapshots)) return {
|
|
1456
|
+
items,
|
|
1457
|
+
byId
|
|
1458
|
+
};
|
|
1459
|
+
snapshots.forEach(snapshot => {
|
|
1460
|
+
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) return;
|
|
1461
|
+
const virtualCurrency = snapshot;
|
|
1462
|
+
if (stringify(virtualCurrency.tag).trim().toLowerCase() !== 'virtual_currency') return;
|
|
1463
|
+
const id = normalizeWalletPassId(virtualCurrency.id);
|
|
1464
|
+
if (!id || byId.has(id)) return;
|
|
1465
|
+
byId.set(id, virtualCurrency);
|
|
1466
|
+
items.push(virtualCurrency);
|
|
1467
|
+
});
|
|
1468
|
+
return {
|
|
1469
|
+
items,
|
|
1470
|
+
byId
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
|
|
1474
|
+
const fundRecord = getFundRecord(payment);
|
|
1475
|
+
for (const value of [fundRecord?.voucher_id, payment.voucher_id]) {
|
|
1476
|
+
const id = normalizeWalletPassId(value);
|
|
1477
|
+
if (!id) continue;
|
|
1478
|
+
const snapshot = snapshotsById.get(id);
|
|
1479
|
+
if (snapshot) return snapshot;
|
|
1480
|
+
}
|
|
1481
|
+
return undefined;
|
|
1482
|
+
}
|
|
1483
|
+
function buildVirtualCurrencySnapshotAssets(params) {
|
|
1484
|
+
const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1485
|
+
return params.snapshots.flatMap(virtualCurrency => {
|
|
1486
|
+
const id = normalizeWalletPassId(virtualCurrency.id);
|
|
1487
|
+
if (!id || params.displayedWalletPassIds.has(id)) return [];
|
|
1488
|
+
const rows = [{
|
|
1489
|
+
item: stringify(virtualCurrency.product_name).trim(),
|
|
1490
|
+
value: ''
|
|
1491
|
+
}];
|
|
1492
|
+
const balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
|
|
1493
|
+
if (balance) {
|
|
1494
|
+
rows.push({
|
|
1495
|
+
item: label(params.locale, 'balance'),
|
|
1496
|
+
value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
if (isPresentId(snapshotTime)) {
|
|
1500
|
+
rows.push({
|
|
1501
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1502
|
+
value: ''
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
return [rows];
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
function getVirtualCurrencySnapshotBalance(snapshot) {
|
|
1509
|
+
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
1510
|
+
return null;
|
|
1511
|
+
}
|
|
1512
|
+
return _decimal.default.max(new _decimal.default(snapshot.par_value).minus(new _decimal.default(snapshot.used_par_value)), 0);
|
|
1513
|
+
}
|
|
1514
|
+
function getVirtualCurrencySnapshotUnit(snapshot, locale) {
|
|
1515
|
+
return getNonEmptyLocalizedValue(snapshot.name, locale);
|
|
1516
|
+
}
|
|
1517
|
+
function getNonEmptyLocalizedValue(value, locale) {
|
|
1518
|
+
if (value === undefined || value === null) return '';
|
|
1519
|
+
if (typeof value !== 'object' || Array.isArray(value)) return stringify(value).trim();
|
|
1520
|
+
const dashedLocale = locale.replace('_', '-');
|
|
1521
|
+
const underscoredLocale = locale.replace('-', '_');
|
|
1522
|
+
for (const candidate of [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]) {
|
|
1523
|
+
const text = stringify(candidate).trim();
|
|
1524
|
+
if (text) return text;
|
|
1525
|
+
}
|
|
1526
|
+
return '';
|
|
1527
|
+
}
|
|
1528
|
+
function formatVirtualCurrencyBalance(value, unit) {
|
|
1529
|
+
const amount = trimDecimal(value);
|
|
1530
|
+
const normalizedUnit = unit.trim();
|
|
1531
|
+
return normalizedUnit ? `${amount} ${normalizedUnit}` : amount;
|
|
1532
|
+
}
|
|
1441
1533
|
function normalizeWalletPassId(value) {
|
|
1442
1534
|
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
1443
1535
|
if (typeof value !== 'string') return null;
|
|
@@ -1604,7 +1696,8 @@ function buildPaymentItems(params) {
|
|
|
1604
1696
|
currencySymbol,
|
|
1605
1697
|
includeFundRecordBalance,
|
|
1606
1698
|
includeFundRecordUsage,
|
|
1607
|
-
includePaymentAmount
|
|
1699
|
+
includePaymentAmount,
|
|
1700
|
+
virtualCurrencyUnit
|
|
1608
1701
|
} = params;
|
|
1609
1702
|
const serviceFee = getPaymentServiceFee(payment);
|
|
1610
1703
|
const items = [{
|
|
@@ -1630,7 +1723,8 @@ function buildPaymentItems(params) {
|
|
|
1630
1723
|
locale,
|
|
1631
1724
|
currencySymbol,
|
|
1632
1725
|
includeBalance: includeFundRecordBalance,
|
|
1633
|
-
includeUsage: includeFundRecordUsage
|
|
1726
|
+
includeUsage: includeFundRecordUsage,
|
|
1727
|
+
virtualCurrencyUnit
|
|
1634
1728
|
}));
|
|
1635
1729
|
} else {
|
|
1636
1730
|
const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
|
|
@@ -1695,7 +1789,8 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1695
1789
|
locale,
|
|
1696
1790
|
currencySymbol,
|
|
1697
1791
|
includeBalance,
|
|
1698
|
-
includeUsage
|
|
1792
|
+
includeUsage,
|
|
1793
|
+
virtualCurrencyUnit
|
|
1699
1794
|
} = params;
|
|
1700
1795
|
const items = [];
|
|
1701
1796
|
const usingBeforeValue = fundRecord.using_before_value;
|
|
@@ -1717,6 +1812,14 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1717
1812
|
return items;
|
|
1718
1813
|
}
|
|
1719
1814
|
if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
|
|
1815
|
+
if (virtualCurrencyUnit !== undefined) {
|
|
1816
|
+
if (!isNumericAmount(usingAfterValue)) return items;
|
|
1817
|
+
items.push({
|
|
1818
|
+
item: label(locale, 'balance'),
|
|
1819
|
+
value: formatVirtualCurrencyBalance(new _decimal.default(usingAfterValue), virtualCurrencyUnit)
|
|
1820
|
+
});
|
|
1821
|
+
return items;
|
|
1822
|
+
}
|
|
1720
1823
|
items.push({
|
|
1721
1824
|
item: label(locale, 'balance'),
|
|
1722
1825
|
value: formatMoney(usingAfterValue, currencySymbol)
|
|
@@ -273,6 +273,12 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
273
273
|
private mergeHistoricalDiscountList;
|
|
274
274
|
private shouldSkipAutoApplyFetchedDiscountsInEditMode;
|
|
275
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;
|
|
276
282
|
loadDiscountConfig(params?: {
|
|
277
283
|
customerId?: number;
|
|
278
284
|
action?: 'create' | 'edit';
|
|
@@ -346,6 +346,7 @@ function areBaseSalesNotesEquivalent(currentValue, loadedValue, options) {
|
|
|
346
346
|
return currentNotes !== null && loadedNotes !== null && (0, _lodashEs.isEqual)(currentNotes, loadedNotes);
|
|
347
347
|
}
|
|
348
348
|
function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
|
|
349
|
+
const loadedHasOrderMetaList = Object.prototype.hasOwnProperty.call(loadedRecord || {}, 'order_meta_list');
|
|
349
350
|
const loadedHasSalesNotes = Object.prototype.hasOwnProperty.call(loadedRecord || {}, 'notes');
|
|
350
351
|
const hasDirtyLocalSalesNotes = currentTempOrder?._extend?.salesNotesState?.dirty === true;
|
|
351
352
|
const incomingSalesNotesMatchLocal = loadedHasSalesNotes && areBaseSalesNotesEquivalent(currentTempOrder?.notes, loadedRecord.notes, {
|
|
@@ -364,6 +365,12 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, str
|
|
|
364
365
|
});
|
|
365
366
|
const uidRemaps = [];
|
|
366
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
|
+
}
|
|
367
374
|
if (key === 'notes') {
|
|
368
375
|
if (preserveDirtyLocalSalesNotes && Array.isArray(currentValue)) {
|
|
369
376
|
return (0, _lodashEs.cloneDeep)(currentValue);
|
|
@@ -1342,9 +1349,22 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1342
1349
|
}
|
|
1343
1350
|
syncAppDataToTempOrder(tempOrder) {
|
|
1344
1351
|
const isPriceIncludeTax = this.getAppData('is_price_include_tax');
|
|
1345
|
-
const
|
|
1346
|
-
const
|
|
1347
|
-
const
|
|
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
|
+
};
|
|
1348
1368
|
// 历史虚拟币订单不依赖交易开关;普通 POS 不从商品行残留快照推断订单币种。
|
|
1349
1369
|
const isHistoricalVirtualSettlement = this.isHistoricalVirtualSettlementOrder(tempOrder);
|
|
1350
1370
|
const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder) || isHistoricalVirtualSettlement;
|
|
@@ -1358,9 +1378,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1358
1378
|
}
|
|
1359
1379
|
}
|
|
1360
1380
|
if (taxCountryCode !== undefined) {
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
tempOrder.tax_country_code = nextTaxCountryCode;
|
|
1381
|
+
if (tempOrder.tax_country_code !== taxCountryCode) {
|
|
1382
|
+
tempOrder.tax_country_code = taxCountryCode;
|
|
1364
1383
|
isChanged = true;
|
|
1365
1384
|
}
|
|
1366
1385
|
}
|
|
@@ -1377,19 +1396,45 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1377
1396
|
}
|
|
1378
1397
|
}
|
|
1379
1398
|
if (!isVirtualSettlement && currencyCode !== undefined) {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
tempOrder.currency_code = nextCurrencyCode;
|
|
1399
|
+
if (tempOrder.currency_code !== currencyCode) {
|
|
1400
|
+
tempOrder.currency_code = currencyCode;
|
|
1383
1401
|
isChanged = true;
|
|
1384
1402
|
}
|
|
1385
1403
|
}
|
|
1386
1404
|
if (!isVirtualSettlement && currencySymbol !== undefined) {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
tempOrder.currency_symbol = nextCurrencySymbol;
|
|
1405
|
+
if (tempOrder.currency_symbol !== currencySymbol) {
|
|
1406
|
+
tempOrder.currency_symbol = currencySymbol;
|
|
1390
1407
|
isChanged = true;
|
|
1391
1408
|
}
|
|
1392
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
|
+
}
|
|
1393
1438
|
return isChanged;
|
|
1394
1439
|
}
|
|
1395
1440
|
async initialize(core, options = {}) {
|
|
@@ -1896,19 +1941,46 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1896
1941
|
return discount;
|
|
1897
1942
|
});
|
|
1898
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
|
+
}
|
|
1899
1956
|
async loadDiscountConfig(params) {
|
|
1900
1957
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1901
1958
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
1902
1959
|
const orderStore = this.store.order.store || {};
|
|
1903
1960
|
const discountModule = orderStore.discount;
|
|
1904
1961
|
const rulesModule = orderStore.rules;
|
|
1905
|
-
const orderId = tempOrder.order_id || this.getOrderIdentity?.()?.orderId;
|
|
1962
|
+
const orderId = tempOrder.order_id || this.store.order.getOrderIdentity?.()?.orderId;
|
|
1906
1963
|
const customerId = Number(params?.customerId || tempOrder.customer_id || tempOrder.customer?.id || tempOrder._extend?.customerSnapshot?.id || tempOrder._extend?.customerSnapshot?.customer_id || 0);
|
|
1907
1964
|
const currentDiscountList = discountModule?.getDiscountList?.() || [];
|
|
1908
1965
|
const originalDiscountList = discountModule?.getOriginalDiscountList?.() || [];
|
|
1909
1966
|
const hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some(discount => discount.isManualSelect);
|
|
1910
1967
|
const discountAction = params?.action || (orderId ? 'edit' : 'create');
|
|
1911
|
-
const
|
|
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
|
+
};
|
|
1912
1984
|
|
|
1913
1985
|
// Walk-In 不请求 prepare config;当前搜索/扫码券必须继续参与本次重算。
|
|
1914
1986
|
// current 优先于 original,保留搜索后的最新选择与可用状态。
|
|
@@ -1919,26 +1991,34 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1919
1991
|
if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
|
|
1920
1992
|
preparedDiscountList = originalDiscountList;
|
|
1921
1993
|
} else {
|
|
1922
|
-
|
|
1994
|
+
const prepareConfigPromise = this.store.order.loadDiscountConfig({
|
|
1923
1995
|
customerId,
|
|
1924
1996
|
action: discountAction,
|
|
1925
1997
|
orderId: Number(orderId) || undefined,
|
|
1926
1998
|
apply: false
|
|
1927
1999
|
});
|
|
1928
|
-
this
|
|
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();
|
|
1929
2004
|
await discountModule?.setOriginalDiscountList?.(preparedDiscountList);
|
|
2005
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2006
|
+
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
1930
2007
|
}
|
|
1931
2008
|
}
|
|
1932
2009
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
2010
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1933
2011
|
await discountModule?.setOriginalDiscountList?.([]);
|
|
2012
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1934
2013
|
await discountModule?.setDiscountList?.([]);
|
|
2014
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1935
2015
|
tempOrder.discount_list = [];
|
|
1936
2016
|
tempOrder.shop_discount = '0.00';
|
|
1937
2017
|
return {
|
|
1938
2018
|
productList: tempOrder.products || [],
|
|
1939
2019
|
discountList: [],
|
|
1940
2020
|
availableWalletIds: this.getAvailableWalletIds(),
|
|
1941
|
-
virtualCurrencyList: this.
|
|
2021
|
+
virtualCurrencyList: this.getVirtualCurrencyList()
|
|
1942
2022
|
};
|
|
1943
2023
|
}
|
|
1944
2024
|
if (hasManualDiscountSelection && currentDiscountList.length) {
|
|
@@ -1946,12 +2026,14 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1946
2026
|
productList: tempOrder.products || [],
|
|
1947
2027
|
discountList: currentDiscountList,
|
|
1948
2028
|
availableWalletIds: this.getAvailableWalletIds(),
|
|
1949
|
-
virtualCurrencyList: this.
|
|
2029
|
+
virtualCurrencyList: this.getVirtualCurrencyList()
|
|
1950
2030
|
};
|
|
1951
2031
|
}
|
|
1952
2032
|
let nextDiscountList = this.mergeHistoricalDiscountList(preparedDiscountList || discountModule?.getDiscountList?.() || [], tempOrder.products || []);
|
|
1953
2033
|
nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
|
|
2034
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1954
2035
|
await discountModule?.setDiscountList(nextDiscountList);
|
|
2036
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1955
2037
|
const shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
|
|
1956
2038
|
discountAction,
|
|
1957
2039
|
products: tempOrder.products || [],
|
|
@@ -1959,24 +2041,28 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1959
2041
|
nextDiscountList
|
|
1960
2042
|
});
|
|
1961
2043
|
if (shouldSkipAutoApplyFetchedDiscounts) {
|
|
1962
|
-
|
|
2044
|
+
await this.store.order.recalculateSummary({
|
|
1963
2045
|
createIfMissing: true
|
|
1964
2046
|
});
|
|
2047
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1965
2048
|
this.store.order.persistTempOrder();
|
|
2049
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1966
2050
|
await this.effectsEmit('onDiscountApplied', {
|
|
1967
2051
|
productList: tempOrder.products || [],
|
|
1968
2052
|
discountList: nextDiscountList,
|
|
1969
2053
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
1970
2054
|
tempOrder
|
|
1971
2055
|
});
|
|
2056
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1972
2057
|
return {
|
|
1973
2058
|
productList: tempOrder.products || [],
|
|
1974
2059
|
discountList: nextDiscountList,
|
|
1975
2060
|
availableWalletIds: this.getAvailableWalletIds(),
|
|
1976
|
-
virtualCurrencyList: this.
|
|
2061
|
+
virtualCurrencyList: this.getVirtualCurrencyList()
|
|
1977
2062
|
};
|
|
1978
2063
|
}
|
|
1979
2064
|
if (rulesModule) {
|
|
2065
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
1980
2066
|
const orderTotalAmount = Number(orderStore.summary?.total_amount || 0);
|
|
1981
2067
|
const result = rulesModule.calcDiscount({
|
|
1982
2068
|
productList: tempOrder.products,
|
|
@@ -2012,25 +2098,31 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2012
2098
|
if (result.discountList) {
|
|
2013
2099
|
nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
|
|
2014
2100
|
_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
|
|
2101
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2015
2102
|
await discountModule?.setDiscountList(nextDiscountList);
|
|
2103
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2016
2104
|
tempOrder.discount_list = nextDiscountList.filter(discount => discount.isSelected);
|
|
2017
2105
|
}
|
|
2018
2106
|
}
|
|
2019
|
-
|
|
2107
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2108
|
+
await this.store.order.recalculateSummary({
|
|
2020
2109
|
createIfMissing: true
|
|
2021
2110
|
});
|
|
2111
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2022
2112
|
this.store.order.persistTempOrder();
|
|
2113
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2023
2114
|
await this.effectsEmit('onDiscountApplied', {
|
|
2024
2115
|
productList: tempOrder.products || [],
|
|
2025
2116
|
discountList: nextDiscountList,
|
|
2026
2117
|
selectedDiscountList: tempOrder.discount_list || [],
|
|
2027
2118
|
tempOrder
|
|
2028
2119
|
});
|
|
2120
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2029
2121
|
return {
|
|
2030
2122
|
productList: tempOrder.products || [],
|
|
2031
2123
|
discountList: nextDiscountList,
|
|
2032
2124
|
availableWalletIds: this.getAvailableWalletIds(),
|
|
2033
|
-
virtualCurrencyList: this.
|
|
2125
|
+
virtualCurrencyList: this.getVirtualCurrencyList()
|
|
2034
2126
|
};
|
|
2035
2127
|
}
|
|
2036
2128
|
getAvailableWalletIds() {
|
|
@@ -3211,7 +3303,13 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
3211
3303
|
*/
|
|
3212
3304
|
updateOrderCustomer(customer) {
|
|
3213
3305
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
3306
|
+
const previousCustomerId = this.resolveDiscountConfigCustomerId(this.store.order.getTempOrder?.());
|
|
3214
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
|
+
}
|
|
3215
3313
|
this.store.order.recalculateSummary({
|
|
3216
3314
|
createIfMissing: true
|
|
3217
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 | 3 |
|
|
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;
|
|
@@ -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
|
-
|
|
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
|
|
1137
|
-
const
|
|
1138
|
-
const
|
|
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
|
}
|