@pisell/pisellos 2.3.170 → 2.3.172
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inventory/index.d.ts +92 -0
- package/dist/inventory/index.js +509 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +5 -4
- package/dist/modules/Discount/index.js +1 -0
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +25 -3
- package/dist/modules/Order/index.js +1791 -1318
- package/dist/modules/Order/types.d.ts +7 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
- package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
- package/dist/modules/Payment/walletpass.js +32 -6
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +33 -12
- package/dist/modules/Rules/index.d.ts +5 -10
- package/dist/modules/Rules/index.js +197 -107
- package/dist/modules/Rules/promotionSelection.d.ts +14 -0
- package/dist/modules/Rules/promotionSelection.js +390 -0
- package/dist/modules/Rules/types.d.ts +9 -0
- package/dist/server/modules/order/index.d.ts +6 -0
- package/dist/server/modules/order/index.js +782 -447
- package/dist/solution/BaseSales/index.d.ts +16 -1
- package/dist/solution/BaseSales/index.js +1545 -1339
- package/dist/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.js +200 -108
- package/dist/solution/BookingTicket/types.d.ts +14 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +4 -3
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +94 -58
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +117 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/dist/solution/UnifiedBookingSales/index.d.ts +1 -1
- package/dist/solution/UnifiedBookingSales/index.js +69 -49
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.js +6 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -0
- package/lib/inventory/index.d.ts +92 -0
- package/lib/inventory/index.js +287 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +5 -4
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Discount/index.js +1 -0
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +25 -3
- package/lib/modules/Order/index.js +203 -38
- package/lib/modules/Order/types.d.ts +7 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
- package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
- package/lib/modules/Payment/walletpass.js +23 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +15 -0
- package/lib/modules/Rules/index.d.ts +5 -10
- package/lib/modules/Rules/index.js +68 -22
- package/lib/modules/Rules/promotionSelection.d.ts +14 -0
- package/lib/modules/Rules/promotionSelection.js +230 -0
- package/lib/modules/Rules/types.d.ts +9 -0
- package/lib/server/modules/order/index.d.ts +6 -0
- package/lib/server/modules/order/index.js +226 -29
- package/lib/solution/BaseSales/index.d.ts +16 -1
- package/lib/solution/BaseSales/index.js +108 -14
- package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.js +38 -2
- package/lib/solution/BookingTicket/types.d.ts +14 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -3
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +14 -2
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +71 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/lib/solution/UnifiedBookingSales/index.d.ts +1 -1
- package/lib/solution/UnifiedBookingSales/index.js +14 -3
- package/lib/utils/platform.d.ts +2 -0
- package/lib/utils/platform.js +7 -0
- package/package.json +1 -1
|
@@ -1235,6 +1235,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1235
1235
|
this.logInfo('upsertPendingSyncOrders-开始', {
|
|
1236
1236
|
count: pendingMap.size
|
|
1237
1237
|
});
|
|
1238
|
+
const storageKeyMigrations = [];
|
|
1239
|
+
const previousStorageKeys = this.store.list.map(order => this.getPersistedOrderStorageKey(order));
|
|
1238
1240
|
const mergeActions = {};
|
|
1239
1241
|
const updatedList = this.store.list.map(order => this.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory'));
|
|
1240
1242
|
|
|
@@ -1248,7 +1250,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1248
1250
|
}
|
|
1249
1251
|
}
|
|
1250
1252
|
for (const [storageKey, pendingOrder] of memoryPendingMap.entries()) {
|
|
1251
|
-
const matchIndex = this.
|
|
1253
|
+
const matchIndex = this.findLocalOrderIndexByIdentity(identityKeyToIndex, updatedList, pendingOrder);
|
|
1252
1254
|
if (matchIndex >= 0) {
|
|
1253
1255
|
const existingOrder = updatedList[matchIndex];
|
|
1254
1256
|
const mergedOrder = this.mergeOrderRecords(existingOrder, pendingOrder);
|
|
@@ -1257,6 +1259,15 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1257
1259
|
need_sync: 1,
|
|
1258
1260
|
is_draft_order: 0
|
|
1259
1261
|
};
|
|
1262
|
+
const previousStorageKey = previousStorageKeys[matchIndex];
|
|
1263
|
+
if (previousStorageKey && previousStorageKey !== storageKey) {
|
|
1264
|
+
storageKeyMigrations.push({
|
|
1265
|
+
orderId: nextOrder.order_id ?? null,
|
|
1266
|
+
from: previousStorageKey,
|
|
1267
|
+
to: storageKey
|
|
1268
|
+
});
|
|
1269
|
+
delete nextOrder[ORDER_STORAGE_KEY_FIELD];
|
|
1270
|
+
}
|
|
1260
1271
|
updatedList[matchIndex] = nextOrder;
|
|
1261
1272
|
const pendingSnapshot = pendingMap.get(storageKey);
|
|
1262
1273
|
if (pendingSnapshot) {
|
|
@@ -1278,7 +1289,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1278
1289
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
|
|
1279
1290
|
this.syncOrdersMap();
|
|
1280
1291
|
try {
|
|
1281
|
-
await this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions,
|
|
1292
|
+
await this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, {
|
|
1293
|
+
...options,
|
|
1294
|
+
storageKeyMigrations
|
|
1295
|
+
});
|
|
1282
1296
|
} catch (error) {
|
|
1283
1297
|
this.store.list = previousList;
|
|
1284
1298
|
this.syncOrdersMap();
|
|
@@ -1327,8 +1341,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1327
1341
|
memoryDraftCount: memoryDraftMap.size,
|
|
1328
1342
|
sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
|
|
1329
1343
|
});
|
|
1344
|
+
const storageKeyMigrations = [];
|
|
1330
1345
|
const mergeActions = {};
|
|
1331
1346
|
const updatedList = this.store.list.filter(order => this.shouldKeepOrderInMemory(order));
|
|
1347
|
+
const previousStorageKeys = updatedList.map(order => this.getPersistedOrderStorageKey(order));
|
|
1332
1348
|
const identityKeyToIndex = new Map();
|
|
1333
1349
|
for (let index = 0; index < updatedList.length; index += 1) {
|
|
1334
1350
|
for (const key of this.getOrderIdentityMatchKeys(updatedList[index])) {
|
|
@@ -1336,9 +1352,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1336
1352
|
}
|
|
1337
1353
|
}
|
|
1338
1354
|
for (const [storageKey, draftOrder] of memoryDraftMap.entries()) {
|
|
1339
|
-
const matchIndex = this.
|
|
1355
|
+
const matchIndex = this.findLocalOrderIndexByIdentity(identityKeyToIndex, updatedList, draftOrder);
|
|
1340
1356
|
if (matchIndex >= 0) {
|
|
1341
1357
|
const existingOrder = updatedList[matchIndex];
|
|
1358
|
+
const previousStorageKey = previousStorageKeys[matchIndex];
|
|
1342
1359
|
const reconciledDraftOrder = this.preserveExistingBusinessCodeForDraft(existingOrder, draftOrder);
|
|
1343
1360
|
this.applyHolderRelationsSnapshot(reconciledDraftOrder, existingOrder, draftOrder);
|
|
1344
1361
|
const mergedOrder = this.mergeOrderRecords(existingOrder, reconciledDraftOrder);
|
|
@@ -1347,6 +1364,14 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1347
1364
|
need_sync: 0,
|
|
1348
1365
|
is_draft_order: 1
|
|
1349
1366
|
};
|
|
1367
|
+
if (previousStorageKey && previousStorageKey !== storageKey) {
|
|
1368
|
+
storageKeyMigrations.push({
|
|
1369
|
+
orderId: nextOrder.order_id ?? null,
|
|
1370
|
+
from: previousStorageKey,
|
|
1371
|
+
to: storageKey
|
|
1372
|
+
});
|
|
1373
|
+
delete nextOrder[ORDER_STORAGE_KEY_FIELD];
|
|
1374
|
+
}
|
|
1350
1375
|
updatedList[matchIndex] = nextOrder;
|
|
1351
1376
|
// SQLite 必须与内存中的草稿保持同一份 business_code,避免下次 hydrate 再次丢失分类。
|
|
1352
1377
|
draftMap.set(storageKey, reconciledDraftOrder);
|
|
@@ -1365,7 +1390,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1365
1390
|
this.syncOrdersMap();
|
|
1366
1391
|
try {
|
|
1367
1392
|
await this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
|
|
1368
|
-
throwOnError: true
|
|
1393
|
+
throwOnError: true,
|
|
1394
|
+
storageKeyMigrations
|
|
1369
1395
|
});
|
|
1370
1396
|
} catch (error) {
|
|
1371
1397
|
this.store.list = previousList;
|
|
@@ -2037,6 +2063,23 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2037
2063
|
}
|
|
2038
2064
|
return this.getOrderStorageKey(order);
|
|
2039
2065
|
}
|
|
2066
|
+
getRealOrderId(order) {
|
|
2067
|
+
if (this.isBlankIdentityValue(order.order_id)) return '';
|
|
2068
|
+
if (String(order.order_id) === String(order.external_sale_number)) return '';
|
|
2069
|
+
return String(order.order_id);
|
|
2070
|
+
}
|
|
2071
|
+
findLocalOrderIndexByIdentity(identityKeyToIndex, orders, target) {
|
|
2072
|
+
const id = this.getRealOrderId(target);
|
|
2073
|
+
const keys = id ? [`order_id:${id}`] : [];
|
|
2074
|
+
if (!this.isBlankIdentityValue(target.external_sale_number)) {
|
|
2075
|
+
keys.push(`external_sale_number:${target.external_sale_number}`);
|
|
2076
|
+
}
|
|
2077
|
+
const indexes = keys.map(key => identityKeyToIndex.get(key)).filter(index => index !== undefined).sort((left, right) => left - right);
|
|
2078
|
+
return indexes.find(index => {
|
|
2079
|
+
const existingId = this.getRealOrderId(orders[index]);
|
|
2080
|
+
return !id || !existingId || id === existingId;
|
|
2081
|
+
}) ?? -1;
|
|
2082
|
+
}
|
|
2040
2083
|
getOrderIdentityMatchKeys(order) {
|
|
2041
2084
|
return this.getOrderIdentityEntries(order).map(entry => `${entry.field}:${entry.key}`);
|
|
2042
2085
|
}
|
|
@@ -2383,23 +2426,190 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2383
2426
|
if (!this.dbManager) return [];
|
|
2384
2427
|
try {
|
|
2385
2428
|
const loadStartedAt = performance.now();
|
|
2386
|
-
const
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2429
|
+
const memoryBeforeLoad = this.store.list;
|
|
2430
|
+
let normalizedOrders = [];
|
|
2431
|
+
// 读修复与普通订单写入共用队列,避免用排队前的旧快照覆盖新的待同步订单。
|
|
2432
|
+
await this.runInOrderSQLiteSaveQueue(async () => {
|
|
2433
|
+
const rawReadStartedAt = performance.now();
|
|
2434
|
+
const orders = await this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2435
|
+
const sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
|
|
2436
|
+
const normalizeStartedAt = performance.now();
|
|
2437
|
+
const {
|
|
2438
|
+
list,
|
|
2439
|
+
repairs,
|
|
2440
|
+
obsoleteKeys
|
|
2441
|
+
} = this.deduplicateStoredOrders(orders || []);
|
|
2442
|
+
normalizedOrders = list;
|
|
2443
|
+
const sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
|
|
2444
|
+
if (repairs.length > 0) {
|
|
2445
|
+
try {
|
|
2446
|
+
// 先保存完整的保留记录,成功后才逐个删除旧键;不清空 orders 表。
|
|
2447
|
+
await this.writeOrderRowsToSQLite(repairs);
|
|
2448
|
+
this.recordRecentSqliteWrite('loadOrdersFromSQLite.deduplicate', repairs);
|
|
2449
|
+
for (const key of obsoleteKeys) {
|
|
2450
|
+
await this.dbManager.delete(INDEXDB_STORE_NAME, key);
|
|
2451
|
+
this.recentSqliteWriteByStorageKey.delete(key);
|
|
2452
|
+
}
|
|
2453
|
+
this.logInfo('SQLite重复订单已修复', {
|
|
2454
|
+
beforeCount: orders.length,
|
|
2455
|
+
afterCount: list.length,
|
|
2456
|
+
repairedCount: repairs.length,
|
|
2457
|
+
deletedKeyCount: obsoleteKeys.size
|
|
2458
|
+
});
|
|
2459
|
+
} catch (error) {
|
|
2460
|
+
// 本次仍使用去重后的内存快照;保留磁盘记录,后续读取可重试修复。
|
|
2461
|
+
this.logError('SQLite重复订单修复写入失败', {
|
|
2462
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2463
|
+
repairedCount: repairs.length
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
options.onTiming?.({
|
|
2468
|
+
sqliteRawReadMs,
|
|
2469
|
+
sqliteNormalizeMs,
|
|
2470
|
+
sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
|
|
2471
|
+
});
|
|
2396
2472
|
});
|
|
2473
|
+
if (this.store.list !== memoryBeforeLoad) {
|
|
2474
|
+
// 读取期间可能已开始新的本地结账;回灌不能抹掉尚在排队落库的修改。
|
|
2475
|
+
const previousOrders = new Map(memoryBeforeLoad.map(order => [this.getOrderStorageKey(order), order]));
|
|
2476
|
+
const protectedMemoryOrders = this.store.list.filter(order => this.shouldProtectLocalOrderFromRemoteSnapshot(order) && !(0, _lodashEs.isEqual)(previousOrders.get(this.getOrderStorageKey(order)), order));
|
|
2477
|
+
normalizedOrders = this.deduplicateStoredOrders([...normalizedOrders, ...protectedMemoryOrders], new Set(protectedMemoryOrders)).list;
|
|
2478
|
+
}
|
|
2397
2479
|
return normalizedOrders;
|
|
2398
2480
|
} catch (error) {
|
|
2399
2481
|
if (options.throwOnError) throw error;
|
|
2400
2482
|
return [];
|
|
2401
2483
|
}
|
|
2402
2484
|
}
|
|
2485
|
+
|
|
2486
|
+
/** 历史记录只按真实订单 ID / 唯一本地编号归组,不使用桌号或小票短号。 */
|
|
2487
|
+
deduplicateStoredOrders(orders, authoritativeOrders = new Set()) {
|
|
2488
|
+
const idsByExternal = new Map();
|
|
2489
|
+
for (const order of orders) {
|
|
2490
|
+
const id = this.getRealOrderId(order);
|
|
2491
|
+
const external = order.external_sale_number;
|
|
2492
|
+
if (!id || this.isBlankIdentityValue(external)) continue;
|
|
2493
|
+
const key = String(external);
|
|
2494
|
+
const previous = idsByExternal.get(key);
|
|
2495
|
+
idsByExternal.set(key, previous === undefined || previous === id ? id : null);
|
|
2496
|
+
}
|
|
2497
|
+
const groups = new Map();
|
|
2498
|
+
for (const [index, rawOrder] of orders.entries()) {
|
|
2499
|
+
const external = this.isBlankIdentityValue(rawOrder.external_sale_number) ? '' : String(rawOrder.external_sale_number);
|
|
2500
|
+
const id = this.getRealOrderId(rawOrder) || external && idsByExternal.get(external);
|
|
2501
|
+
const identity = id ? `id:${id}` : external ? `external:${external}` : `row:${index}`;
|
|
2502
|
+
const storageKey = this.getPersistedOrderStorageKey(rawOrder);
|
|
2503
|
+
const order = this.normalizeOrderCollectionsForIngress(rawOrder, 'loadOrdersFromSQLite');
|
|
2504
|
+
const group = groups.get(identity);
|
|
2505
|
+
if (group) {
|
|
2506
|
+
group.order = this.mergeStoredOrderCopies(group.order, order, authoritativeOrders.has(rawOrder));
|
|
2507
|
+
group.keys.add(storageKey);
|
|
2508
|
+
group.count += 1;
|
|
2509
|
+
} else {
|
|
2510
|
+
groups.set(identity, {
|
|
2511
|
+
order,
|
|
2512
|
+
keys: new Set([storageKey]),
|
|
2513
|
+
count: 1
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
const canonicalKeyCounts = new Map();
|
|
2518
|
+
for (const {
|
|
2519
|
+
order
|
|
2520
|
+
} of groups.values()) {
|
|
2521
|
+
const key = this.getOrderStorageKey(order);
|
|
2522
|
+
canonicalKeyCounts.set(key, (canonicalKeyCounts.get(key) || 0) + 1);
|
|
2523
|
+
}
|
|
2524
|
+
const list = [];
|
|
2525
|
+
const repairs = [];
|
|
2526
|
+
const obsoleteKeys = new Set();
|
|
2527
|
+
for (const group of groups.values()) {
|
|
2528
|
+
const key = this.getOrderStorageKey(group.order);
|
|
2529
|
+
const needsRepair = group.count > 1 || [...group.keys].some(oldKey => oldKey !== key);
|
|
2530
|
+
// 不同真实订单若错误地共用 external 编号,不允许修复写入互相覆盖。
|
|
2531
|
+
if (needsRepair && key && canonicalKeyCounts.get(key) === 1) {
|
|
2532
|
+
group.order = {
|
|
2533
|
+
...group.order,
|
|
2534
|
+
[ORDER_STORAGE_KEY_FIELD]: key
|
|
2535
|
+
};
|
|
2536
|
+
repairs.push(group.order);
|
|
2537
|
+
for (const oldKey of group.keys) {
|
|
2538
|
+
if (oldKey && oldKey !== key && !canonicalKeyCounts.has(oldKey)) obsoleteKeys.add(oldKey);
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
list.push(group.order);
|
|
2542
|
+
}
|
|
2543
|
+
return {
|
|
2544
|
+
list,
|
|
2545
|
+
repairs,
|
|
2546
|
+
obsoleteKeys
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
mergeStoredOrderCopies(left, right, preferIncoming = false) {
|
|
2550
|
+
const priority = order => this.isPendingSyncOrder(order) ? 2 : this.isDraftOrder(order) ? 1 : 0;
|
|
2551
|
+
const leftHasExternal = !this.isBlankIdentityValue(left.external_sale_number);
|
|
2552
|
+
const rightHasExternal = !this.isBlankIdentityValue(right.external_sale_number);
|
|
2553
|
+
let preferred = leftHasExternal !== rightHasExternal ? leftHasExternal ? left : right : this.pickPreferredOrder(left, right);
|
|
2554
|
+
if (preferIncoming) {
|
|
2555
|
+
preferred = right;
|
|
2556
|
+
} else if (priority(left) !== priority(right)) {
|
|
2557
|
+
preferred = priority(left) > priority(right) ? left : right;
|
|
2558
|
+
} else {
|
|
2559
|
+
for (const field of ['updated_at', 'created_at']) {
|
|
2560
|
+
const timestamp = order => {
|
|
2561
|
+
const value = order[field];
|
|
2562
|
+
if (!value) return 0;
|
|
2563
|
+
const parsed = (0, _dayjs.default)(value);
|
|
2564
|
+
return parsed.isValid() ? parsed.valueOf() : 0;
|
|
2565
|
+
};
|
|
2566
|
+
if (timestamp(left) === timestamp(right)) continue;
|
|
2567
|
+
preferred = timestamp(left) > timestamp(right) ? left : right;
|
|
2568
|
+
break;
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
const secondary = preferred === left ? right : left;
|
|
2572
|
+
// 复用集合合并中的 pending/finalized 支付保护,但完整业务快照以胜者为准。
|
|
2573
|
+
const reconciled = this.mergeOrderRecords(secondary, preferred);
|
|
2574
|
+
const merged = {
|
|
2575
|
+
...reconciled,
|
|
2576
|
+
...(0, _lodashEs.cloneDeep)(preferred)
|
|
2577
|
+
};
|
|
2578
|
+
const realOrder = this.getRealOrderId(preferred) ? preferred : secondary;
|
|
2579
|
+
if (this.getRealOrderId(realOrder)) merged.order_id = realOrder.order_id;
|
|
2580
|
+
for (const {
|
|
2581
|
+
field
|
|
2582
|
+
} of this.getOrderIdentityEntries(reconciled)) {
|
|
2583
|
+
if (this.isBlankIdentityValue(merged[field])) merged[field] = reconciled[field];
|
|
2584
|
+
}
|
|
2585
|
+
for (const field of ORDER_AUTHORITATIVE_COLLECTION_FIELDS) {
|
|
2586
|
+
if (Object.prototype.hasOwnProperty.call(reconciled, field)) merged[field] = reconciled[field];
|
|
2587
|
+
}
|
|
2588
|
+
if ((0, _localEftposState.requiresLocalPaymentRefresh)(secondary)) {
|
|
2589
|
+
merged.metadata = {
|
|
2590
|
+
...merged.metadata,
|
|
2591
|
+
[_localEftposState.LOCAL_EFTPOS_REFRESH_REQUIRED]: true
|
|
2592
|
+
};
|
|
2593
|
+
}
|
|
2594
|
+
merged.need_sync = this.isPendingSyncOrder(left) || this.isPendingSyncOrder(right) ? 1 : 0;
|
|
2595
|
+
merged.is_draft_order = this.isDraftOrder(preferred) ? 1 : 0;
|
|
2596
|
+
return merged;
|
|
2597
|
+
}
|
|
2598
|
+
async writeOrderRowsToSQLite(orders) {
|
|
2599
|
+
if (typeof this.dbManager.bulkUpdate === 'function') {
|
|
2600
|
+
await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders);
|
|
2601
|
+
return 'bulkUpdate';
|
|
2602
|
+
}
|
|
2603
|
+
if (typeof this.dbManager.bulkAdd === 'function') {
|
|
2604
|
+
await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orders);
|
|
2605
|
+
return 'bulkAdd';
|
|
2606
|
+
}
|
|
2607
|
+
if (typeof this.dbManager.update === 'function') {
|
|
2608
|
+
for (const order of orders) await this.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2609
|
+
return 'update';
|
|
2610
|
+
}
|
|
2611
|
+
throw new Error('订单 SQLite 数据库不支持写入');
|
|
2612
|
+
}
|
|
2403
2613
|
isPendingSyncOrder(order) {
|
|
2404
2614
|
return Number(order?.need_sync) === 1;
|
|
2405
2615
|
}
|
|
@@ -2496,7 +2706,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2496
2706
|
const {
|
|
2497
2707
|
toWrite,
|
|
2498
2708
|
skipped
|
|
2499
|
-
} = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys);
|
|
2709
|
+
} = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, new Set([...forceWriteStorageKeys, ...migrationTargetStorageKeys]));
|
|
2500
2710
|
if (toWrite.length === 0) {
|
|
2501
2711
|
return;
|
|
2502
2712
|
}
|
|
@@ -2519,20 +2729,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2519
2729
|
count: compactedToWrite.length,
|
|
2520
2730
|
dedupedCount: skipped.length
|
|
2521
2731
|
});
|
|
2522
|
-
|
|
2523
|
-
writeMethod = 'bulkUpdate';
|
|
2524
|
-
await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2525
|
-
} else if (typeof this.dbManager.bulkAdd === 'function') {
|
|
2526
|
-
writeMethod = 'bulkAdd';
|
|
2527
|
-
await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2528
|
-
} else if (typeof this.dbManager.update === 'function') {
|
|
2529
|
-
writeMethod = 'update';
|
|
2530
|
-
for (const order of compactedToWrite) {
|
|
2531
|
-
await this.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2532
|
-
}
|
|
2533
|
-
} else if (options.throwOnError) {
|
|
2534
|
-
throw new Error('订单 SQLite 数据库不支持写入');
|
|
2535
|
-
}
|
|
2732
|
+
writeMethod = await this.writeOrderRowsToSQLite(compactedToWrite);
|
|
2536
2733
|
this.recordRecentSqliteWrite(source, compactedToWrite);
|
|
2537
2734
|
if (writeMethod !== 'none') {
|
|
2538
2735
|
for (const migration of storageKeyMigrations.values()) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InventoryController, type CheckoutRuntimeSnapshot } from '../../inventory';
|
|
1
2
|
import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
2
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
3
4
|
import { type LocalEftposFinalization } from '../../modules/Order/localEftposState';
|
|
@@ -52,6 +53,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
52
53
|
protected appPlugin: AppPlugin;
|
|
53
54
|
protected store: BaseSalesState;
|
|
54
55
|
protected otherParams: Record<string, any>;
|
|
56
|
+
getInventory(): InventoryController | undefined;
|
|
57
|
+
prepareCheckout(signal?: AbortSignal): Promise<CheckoutRuntimeSnapshot | undefined>;
|
|
55
58
|
protected cacheId: string | undefined;
|
|
56
59
|
/**
|
|
57
60
|
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
@@ -194,6 +197,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
194
197
|
* 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
|
|
195
198
|
*/
|
|
196
199
|
protected createSubModule(moduleName: string): Module | null;
|
|
200
|
+
private inventoryOrderHooks?;
|
|
197
201
|
protected getSubModuleHooks(moduleName: string): any;
|
|
198
202
|
/**
|
|
199
203
|
* 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
|
|
@@ -231,7 +235,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
231
235
|
private isActiveVirtualSettlementOrder;
|
|
232
236
|
private isHistoricalVirtualSettlementOrder;
|
|
233
237
|
private syncAppDataToTempOrder;
|
|
238
|
+
private initialization?;
|
|
239
|
+
/** Hosts can await readiness without changing Core's synchronous registration API. */
|
|
240
|
+
whenInitialized(): Promise<void>;
|
|
234
241
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
242
|
+
private initializeSalesRuntime;
|
|
235
243
|
destroy(): Promise<void>;
|
|
236
244
|
/**
|
|
237
245
|
* 加载销售订单到统一 tempOrder 工作区。
|
|
@@ -340,7 +348,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
340
348
|
discountList: Discount[];
|
|
341
349
|
originalDiscountList?: Discount[];
|
|
342
350
|
}): Promise<void>;
|
|
343
|
-
scanPromotionCode(code: string, customerId?: number
|
|
351
|
+
scanPromotionCode(code: string, customerId?: number, options?: {
|
|
352
|
+
productVouchersOnly?: boolean;
|
|
353
|
+
}): Promise<BaseSalesScanCodeResult>;
|
|
344
354
|
setDiscountSelected(params: {
|
|
345
355
|
discountId: number;
|
|
346
356
|
isSelected: boolean;
|
|
@@ -525,6 +535,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
525
535
|
private hasSmartPricingStrategies;
|
|
526
536
|
shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
|
|
527
537
|
calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
|
|
538
|
+
setProductVoucherGroups(groups: Array<{
|
|
539
|
+
key: string;
|
|
540
|
+
discountIds: Array<number | string>;
|
|
541
|
+
}>): void;
|
|
542
|
+
validateProductVoucherSelection(): void;
|
|
528
543
|
addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
529
544
|
updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
530
545
|
updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
@@ -7,6 +7,7 @@ var _exportNames = {
|
|
|
7
7
|
BaseSalesImpl: true
|
|
8
8
|
};
|
|
9
9
|
exports.BaseSalesImpl = void 0;
|
|
10
|
+
var _inventory = require("../../inventory");
|
|
10
11
|
var _BaseModule = require("../../modules/BaseModule");
|
|
11
12
|
var _localEftposState = require("../../modules/Order/localEftposState");
|
|
12
13
|
var _types = require("./types");
|
|
@@ -27,6 +28,7 @@ var _pickupTiming2 = require("./pickupTiming");
|
|
|
27
28
|
var _fulfillmentItemRules = require("./fulfillmentItemRules");
|
|
28
29
|
var _holderRelations = require("../../modules/Order/holderRelations");
|
|
29
30
|
var _contactInfo = require("../../modules/OpenData/contactInfo");
|
|
31
|
+
var _promotionSelection = require("../../modules/Rules/promotionSelection");
|
|
30
32
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
31
33
|
var _lodashEs = require("lodash-es");
|
|
32
34
|
var _types2 = require("../BookingByStep/types");
|
|
@@ -510,6 +512,40 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
510
512
|
order: undefined
|
|
511
513
|
};
|
|
512
514
|
otherParams = {};
|
|
515
|
+
getInventory() {
|
|
516
|
+
return this.otherParams.inventory;
|
|
517
|
+
}
|
|
518
|
+
async prepareCheckout(signal) {
|
|
519
|
+
const inventory = this.getInventory();
|
|
520
|
+
const hooks = this.otherParams.checkoutHooks;
|
|
521
|
+
if (!inventory && !hooks?.beforeCheckout) return undefined;
|
|
522
|
+
if (!this.store.order) throw new Error('Order module is not ready');
|
|
523
|
+
return this.store.order.prepareCheckout(async items => {
|
|
524
|
+
const assertCurrent = () => {
|
|
525
|
+
if (signal?.aborted) throw Object.assign(new Error('Checkout cancelled'), {
|
|
526
|
+
name: 'AbortError'
|
|
527
|
+
});
|
|
528
|
+
if (inventory !== this.getInventory() || hooks !== this.otherParams.checkoutHooks) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
|
|
529
|
+
};
|
|
530
|
+
assertCurrent();
|
|
531
|
+
try {
|
|
532
|
+
await hooks?.beforeCheckout?.({
|
|
533
|
+
items,
|
|
534
|
+
signal
|
|
535
|
+
});
|
|
536
|
+
if (inventory) await inventory.refresh({
|
|
537
|
+
reason: 'checkout',
|
|
538
|
+
force: true,
|
|
539
|
+
signal
|
|
540
|
+
});
|
|
541
|
+
assertCurrent();
|
|
542
|
+
return inventory?.freezeCheckout(items);
|
|
543
|
+
} catch (error) {
|
|
544
|
+
if (error?.name === 'AbortError') throw error;
|
|
545
|
+
throw (0, _inventory.salesGuardError)(error instanceof Error ? error.message : String(error));
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}
|
|
513
549
|
cacheId;
|
|
514
550
|
/**
|
|
515
551
|
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
@@ -1400,12 +1436,35 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1400
1436
|
}
|
|
1401
1437
|
return (0, _types2.createModule)(moduleName, this.name);
|
|
1402
1438
|
}
|
|
1439
|
+
inventoryOrderHooks;
|
|
1403
1440
|
getSubModuleHooks(moduleName) {
|
|
1404
1441
|
const optionHooks = this.initializeOptions.hooks || {};
|
|
1405
1442
|
const otherHooks = this.otherParams.hooks || {};
|
|
1406
1443
|
if (moduleName === 'order') {
|
|
1407
1444
|
const directOrderHooks = optionHooks;
|
|
1408
|
-
|
|
1445
|
+
const hooks = optionHooks.order || this.otherParams.order?.hooks || otherHooks.order || (directOrderHooks.onBeforeMergeProductToOrder || directOrderHooks.onBeforeCartCommit ? directOrderHooks : undefined);
|
|
1446
|
+
const inventory = this.getInventory();
|
|
1447
|
+
if (!inventory) {
|
|
1448
|
+
this.inventoryOrderHooks = undefined;
|
|
1449
|
+
return hooks;
|
|
1450
|
+
}
|
|
1451
|
+
if (this.inventoryOrderHooks?.inventory === inventory && this.inventoryOrderHooks.base === hooks) {
|
|
1452
|
+
return this.inventoryOrderHooks.hooks;
|
|
1453
|
+
}
|
|
1454
|
+
const combined = {
|
|
1455
|
+
...hooks,
|
|
1456
|
+
onBeforeCartCommit: async context => {
|
|
1457
|
+
await hooks?.onBeforeCartCommit?.(context);
|
|
1458
|
+
if (inventory !== this.getInventory()) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
|
|
1459
|
+
inventory.validate(context.proposedItems, context.currentItems);
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
this.inventoryOrderHooks = {
|
|
1463
|
+
inventory,
|
|
1464
|
+
base: hooks,
|
|
1465
|
+
hooks: combined
|
|
1466
|
+
};
|
|
1467
|
+
return combined;
|
|
1409
1468
|
}
|
|
1410
1469
|
return optionHooks[moduleName] || this.otherParams[moduleName]?.hooks || otherHooks[moduleName];
|
|
1411
1470
|
}
|
|
@@ -1453,7 +1512,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1453
1512
|
const nextSubModuleOtherParams = this.buildSubModuleOtherParams(moduleName);
|
|
1454
1513
|
await targetModule.updateOtherParams(nextSubModuleOtherParams, {
|
|
1455
1514
|
changedParams,
|
|
1456
|
-
cover
|
|
1515
|
+
cover,
|
|
1516
|
+
...(moduleName === 'order' ? {
|
|
1517
|
+
hooks: this.getSubModuleHooks(moduleName)
|
|
1518
|
+
} : {})
|
|
1457
1519
|
});
|
|
1458
1520
|
}));
|
|
1459
1521
|
}
|
|
@@ -1602,7 +1664,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1602
1664
|
}
|
|
1603
1665
|
return isChanged;
|
|
1604
1666
|
}
|
|
1605
|
-
|
|
1667
|
+
initialization;
|
|
1668
|
+
|
|
1669
|
+
/** Hosts can await readiness without changing Core's synchronous registration API. */
|
|
1670
|
+
whenInitialized() {
|
|
1671
|
+
return this.initialization || Promise.reject(new Error('Sales module is not registered'));
|
|
1672
|
+
}
|
|
1673
|
+
initialize(core, options = {}) {
|
|
1674
|
+
this.initialization = this.initializeSalesRuntime(core, options);
|
|
1675
|
+
return this.initialization;
|
|
1676
|
+
}
|
|
1677
|
+
async initializeSalesRuntime(core, options = {}) {
|
|
1606
1678
|
this.resetPickupTimingCache();
|
|
1607
1679
|
this.core = core;
|
|
1608
1680
|
this.initializeOptions = options || {};
|
|
@@ -1662,17 +1734,19 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1662
1734
|
this.serverOrderChangeUnsubscribe = null;
|
|
1663
1735
|
this.paymentMethodsChangedUnsubscribe?.();
|
|
1664
1736
|
this.paymentMethodsChangedUnsubscribe = null;
|
|
1665
|
-
Object.keys(this.store)
|
|
1666
|
-
if (this.reusedSharedSubModuleNames.has(key))
|
|
1737
|
+
for (const key of Object.keys(this.store)) {
|
|
1738
|
+
if (this.reusedSharedSubModuleNames.has(key)) continue;
|
|
1667
1739
|
const sub = this.store[key];
|
|
1668
1740
|
if (sub && typeof sub.destroy === 'function') {
|
|
1669
1741
|
try {
|
|
1670
|
-
|
|
1742
|
+
// A host may register a replacement after destroy resolves. Wait for
|
|
1743
|
+
// nested modules so their cleanup cannot unregister the replacement.
|
|
1744
|
+
await sub.destroy();
|
|
1671
1745
|
} catch (error) {
|
|
1672
1746
|
console.warn(`[BaseSales] 子模块 ${key} 销毁失败`, error);
|
|
1673
1747
|
}
|
|
1674
1748
|
}
|
|
1675
|
-
}
|
|
1749
|
+
}
|
|
1676
1750
|
this.currentSalesDetail = null;
|
|
1677
1751
|
this.paymentNumberDevicePrefix = null;
|
|
1678
1752
|
this.queuedServerOrderChanges = [];
|
|
@@ -2141,17 +2215,25 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2141
2215
|
return {
|
|
2142
2216
|
...discount,
|
|
2143
2217
|
isSelected: false,
|
|
2144
|
-
isManualSelect: true
|
|
2218
|
+
isManualSelect: true,
|
|
2219
|
+
promotionSelection: currentDiscount.promotionSelection,
|
|
2220
|
+
promotionSelectionStrategyIds: currentDiscount.promotionSelectionStrategyIds
|
|
2145
2221
|
};
|
|
2146
2222
|
}
|
|
2147
2223
|
if (currentDiscount.isSelected) {
|
|
2148
2224
|
return {
|
|
2149
2225
|
...discount,
|
|
2150
2226
|
isSelected: true,
|
|
2151
|
-
isManualSelect: false
|
|
2227
|
+
isManualSelect: false,
|
|
2228
|
+
promotionSelection: currentDiscount.promotionSelection,
|
|
2229
|
+
promotionSelectionStrategyIds: currentDiscount.promotionSelectionStrategyIds
|
|
2152
2230
|
};
|
|
2153
2231
|
}
|
|
2154
|
-
return
|
|
2232
|
+
return currentDiscount.promotionSelection ? {
|
|
2233
|
+
...discount,
|
|
2234
|
+
promotionSelection: currentDiscount.promotionSelection,
|
|
2235
|
+
promotionSelectionStrategyIds: currentDiscount.promotionSelectionStrategyIds
|
|
2236
|
+
} : discount;
|
|
2155
2237
|
});
|
|
2156
2238
|
}
|
|
2157
2239
|
resolveDiscountConfigCustomerId(tempOrder) {
|
|
@@ -2348,6 +2430,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2348
2430
|
}
|
|
2349
2431
|
async bestDiscount(cb) {
|
|
2350
2432
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2433
|
+
this.hasManualDiscountSelection = false;
|
|
2351
2434
|
const tempOrder = this.store.order.ensureTempOrder();
|
|
2352
2435
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
2353
2436
|
const result = {
|
|
@@ -2431,10 +2514,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2431
2514
|
}
|
|
2432
2515
|
await discountModule.setDiscountList(params.discountList);
|
|
2433
2516
|
}
|
|
2434
|
-
async scanPromotionCode(code, customerId) {
|
|
2517
|
+
async scanPromotionCode(code, customerId, options) {
|
|
2435
2518
|
try {
|
|
2436
2519
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2437
|
-
const raw = await this.store.order.scanCode(code, customerId);
|
|
2520
|
+
const raw = await this.store.order.scanCode(code, customerId, options);
|
|
2438
2521
|
if (raw.isAvailable) {
|
|
2439
2522
|
await this.store.order.recalculateSummary({
|
|
2440
2523
|
createIfMissing: true
|
|
@@ -2512,8 +2595,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2512
2595
|
nextDiscountList = result.discountList;
|
|
2513
2596
|
if (!params.isSelected) {
|
|
2514
2597
|
const beforeSelectedIds = new Set(updated.filter(d => d.isSelected).map(d => d.id));
|
|
2598
|
+
// Rules 已对促销组完成互斥报价,不能再移除其选中的卡而留下已取消的促销。
|
|
2599
|
+
const promotionCardIds = new Set((result.productList || []).filter(product => (0, _promotionSelection.getExclusivePromotion)(product)?.excludedByDiscountCard).flatMap(product => (product.discount_list || []).filter(_promotionSelection.isPromotionDiscountCard).map(discount => String(discount.discount?.resource_id ?? discount.id))));
|
|
2515
2600
|
for (const d of nextDiscountList) {
|
|
2516
|
-
if (d.isSelected && !beforeSelectedIds.has(d.id)) {
|
|
2601
|
+
if (d.isSelected && !beforeSelectedIds.has(d.id) && !promotionCardIds.has(String(d.id))) {
|
|
2517
2602
|
d.isSelected = false;
|
|
2518
2603
|
d.isManualSelect = true;
|
|
2519
2604
|
d.appliedProductDetails = [];
|
|
@@ -2524,6 +2609,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2524
2609
|
}
|
|
2525
2610
|
const selectedResourceIds = new Set(nextDiscountList.filter(d => d.isSelected).map(d => d.id));
|
|
2526
2611
|
const filterSelectedDiscountDetails = discountList => (discountList || []).filter(pd => {
|
|
2612
|
+
// 互斥计算保留/恢复的系统促销没有钱包 resource_id,不能按已选卡列表移除。
|
|
2613
|
+
if (pd.type === 'promotion' || pd.type === 'product' && pd.metadata?.source === 'promotion') return true;
|
|
2527
2614
|
const rid = pd.discount?.resource_id ?? pd.id;
|
|
2528
2615
|
return rid != null && selectedResourceIds.has(rid);
|
|
2529
2616
|
});
|
|
@@ -2550,7 +2637,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2550
2637
|
|
|
2551
2638
|
// 券作用于 source(不含 option、不含 bundle);算出新 source 折后价后补回 options
|
|
2552
2639
|
// 写入含 option 的 main_product_selling_price,再合成 composite 回写 selling_price。
|
|
2553
|
-
const totalPerUnitDiscount = (product.discount_list || []).reduce((sum, pd) => sum + (pd.amount || 0), 0);
|
|
2640
|
+
const totalPerUnitDiscount = (product.discount_list || []).reduce((sum, pd) => sum + Number(pd.amount || 0), 0);
|
|
2554
2641
|
// TODO 这块逻辑需要拿掉
|
|
2555
2642
|
const optionSum = (0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(product));
|
|
2556
2643
|
const sourcePrice = product.metadata?.source_product_price ?? (product.metadata?.main_product_original_price != null ? new _decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? '0');
|
|
@@ -4250,6 +4337,13 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4250
4337
|
});
|
|
4251
4338
|
});
|
|
4252
4339
|
}
|
|
4340
|
+
setProductVoucherGroups(groups) {
|
|
4341
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
4342
|
+
this.store.order.setProductVoucherGroups(groups);
|
|
4343
|
+
}
|
|
4344
|
+
validateProductVoucherSelection() {
|
|
4345
|
+
this.store.order?.validateProductVoucherSelection();
|
|
4346
|
+
}
|
|
4253
4347
|
async addProductToOrder(product, booking, options) {
|
|
4254
4348
|
try {
|
|
4255
4349
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
@@ -245,7 +245,10 @@ function resolveXItemsExpectedUnitPrice(promotion, sourceCartNum) {
|
|
|
245
245
|
const y = Number(detail?.price);
|
|
246
246
|
if (!Number.isFinite(x) || x <= 0 || !Number.isFinite(y)) return undefined;
|
|
247
247
|
if (sourceCartNum < x) return undefined;
|
|
248
|
-
|
|
248
|
+
const originalPrice = Number(promotion?.originalPrice);
|
|
249
|
+
const expectedUnit = new _decimal.default(y).div(x);
|
|
250
|
+
// 归并拆分行时沿用评估器的原价上限,避免重新按 Y / X 把原价抬高。
|
|
251
|
+
return (Number.isFinite(originalPrice) && originalPrice >= 0 ? _decimal.default.min(expectedUnit, originalPrice) : expectedUnit).toDecimalPlaces(2).toNumber();
|
|
249
252
|
}
|
|
250
253
|
|
|
251
254
|
/**
|
|
@@ -756,7 +759,7 @@ function calculateUnfulfilledPromotions(processedProducts, applicableStrategiesR
|
|
|
756
759
|
for (let i = 0; i < processedProducts.length; i++) {
|
|
757
760
|
const product = processedProducts[i];
|
|
758
761
|
const promotion = product?.metadata?._promotion;
|
|
759
|
-
if (!promotion || promotion.inPromotion !== false) continue;
|
|
762
|
+
if (!promotion || promotion.inPromotion !== false || promotion.excludedByDiscountCard) continue;
|
|
760
763
|
const strategyId = promotion.strategyId;
|
|
761
764
|
if (!strategyId) continue;
|
|
762
765
|
const lookupUid = String(product?._originalProductUid ?? product?.metadata?.unique_identification_number ?? '');
|