@pisell/pisellos 2.3.124 → 2.3.126
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
- package/dist/modules/Customer/index.js +3 -6
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +151 -37
- package/dist/modules/Discount/types.d.ts +5 -36
- package/dist/modules/Order/index.d.ts +12 -7
- package/dist/modules/Order/index.js +307 -432
- package/dist/modules/Order/types.d.ts +5 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
- package/dist/modules/Order/utils.d.ts +11 -1
- package/dist/modules/Order/utils.js +127 -122
- package/dist/modules/Payment/types.d.ts +1 -21
- package/dist/modules/Payment/types.js +0 -2
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +47 -80
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +186 -480
- package/dist/modules/Rules/types.d.ts +0 -4
- package/dist/server/modules/order/types.d.ts +0 -2
- package/dist/solution/BaseSales/index.d.ts +0 -1
- package/dist/solution/BaseSales/index.js +59 -51
- package/dist/solution/BaseSales/types.d.ts +2 -2
- package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +2 -1
- package/dist/solution/BookingTicket/index.js +63 -60
- package/dist/solution/BookingTicket/types.d.ts +1 -5
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +42 -99
- package/dist/solution/ShopDiscount/utils.d.ts +2 -4
- package/dist/solution/ShopDiscount/utils.js +23 -43
- package/dist/solution/UnifiedBookingSales/index.js +2 -2
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
- package/lib/modules/Customer/index.js +1 -5
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +129 -23
- package/lib/modules/Discount/types.d.ts +5 -36
- package/lib/modules/Order/index.d.ts +12 -7
- package/lib/modules/Order/index.js +107 -215
- package/lib/modules/Order/types.d.ts +5 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
- package/lib/modules/Order/utils.d.ts +11 -1
- package/lib/modules/Order/utils.js +45 -39
- package/lib/modules/Payment/types.d.ts +1 -21
- package/lib/modules/Payment/types.js +0 -1
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +9 -29
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +110 -357
- package/lib/modules/Rules/types.d.ts +0 -4
- package/lib/server/modules/order/types.d.ts +0 -2
- package/lib/solution/BaseSales/index.d.ts +0 -1
- package/lib/solution/BaseSales/index.js +12 -5
- package/lib/solution/BaseSales/types.d.ts +2 -2
- package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +2 -1
- package/lib/solution/BookingTicket/index.js +33 -36
- package/lib/solution/BookingTicket/types.d.ts +1 -5
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +9 -55
- package/lib/solution/ShopDiscount/utils.d.ts +2 -4
- package/lib/solution/ShopDiscount/utils.js +25 -42
- package/lib/solution/UnifiedBookingSales/index.js +2 -2
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -49
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -43
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -141
|
@@ -29,10 +29,6 @@ export interface RulesCalcDiscountOptions {
|
|
|
29
29
|
discountId?: number;
|
|
30
30
|
selectedList?: SetDiscountSelectedParams[];
|
|
31
31
|
scan?: boolean;
|
|
32
|
-
/** 本次扫码优先使用的次卡实例;普通重算不传,继续保留商品行当前选择。 */
|
|
33
|
-
preferredEntitlementPassIds?: number[];
|
|
34
|
-
/** 普通重算保留商品行已应用的次卡;最优选择传 false 恢复自动排序。 */
|
|
35
|
-
preserveEntitlementSelection?: boolean;
|
|
36
32
|
/** Change time 重报价目标行:允许已选编辑态折扣卡重新应用到这些 booking 商品。 */
|
|
37
33
|
reapplyBookingDiscountProductUids?: string[];
|
|
38
34
|
}
|
|
@@ -36,8 +36,6 @@ export type OrderSurchargeType = string;
|
|
|
36
36
|
export interface OrderProductDiscountMetadata {
|
|
37
37
|
/** 设备端本地唯一标识,用于与服务端记录对齐 */
|
|
38
38
|
unique_identification_number?: string;
|
|
39
|
-
/** 月卡扣除本单新增使用后的剩余次数;不限次数时为 null。 */
|
|
40
|
-
balance?: number | null;
|
|
41
39
|
[key: string]: unknown;
|
|
42
40
|
}
|
|
43
41
|
/**
|
|
@@ -415,7 +415,6 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
415
415
|
refreshWalletAssets(params?: {
|
|
416
416
|
order_wait_pay_amount?: number;
|
|
417
417
|
preserveSelection?: boolean;
|
|
418
|
-
retainSearchResultCodes?: string[];
|
|
419
418
|
}): Promise<WalletAssetsState>;
|
|
420
419
|
/** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */
|
|
421
420
|
selectWalletAsset(params: {
|
|
@@ -1849,7 +1849,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1849
1849
|
if (!this.isPersistedOrderProduct(item)) return;
|
|
1850
1850
|
(item.discount_list || []).forEach(discount => {
|
|
1851
1851
|
const discountId = discount.discount?.resource_id || discount.id;
|
|
1852
|
-
if (!discountId || !['
|
|
1852
|
+
if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
|
|
1853
1853
|
const quantity = item.quantity || item.num || item.product_quantity || 1;
|
|
1854
1854
|
const savedAmount = new _decimal.default(discount.amount || 0).times(quantity).plus(discount?.metadata?.product_discount_difference || 0);
|
|
1855
1855
|
const index = historyDiscountList.findIndex(n => n.id === discountId);
|
|
@@ -2163,8 +2163,6 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2163
2163
|
holders: [],
|
|
2164
2164
|
isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
|
|
2165
2165
|
orderTotalAmount
|
|
2166
|
-
}, {
|
|
2167
|
-
preserveEntitlementSelection: false
|
|
2168
2166
|
}) || result;
|
|
2169
2167
|
if (result.productList) {
|
|
2170
2168
|
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
@@ -3080,6 +3078,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
3080
3078
|
};
|
|
3081
3079
|
}
|
|
3082
3080
|
const result = await this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
|
|
3081
|
+
this.store.order.mergePointCardSnapshotCodes?.(result.userIdentificationCodes, {
|
|
3082
|
+
customerId: walletBusinessData.customer_id,
|
|
3083
|
+
orderIdentity: snapshot?.identity
|
|
3084
|
+
});
|
|
3083
3085
|
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
3084
3086
|
orderId: snapshot?.identity?.orderId,
|
|
3085
3087
|
customerId: walletBusinessData.customer_id,
|
|
@@ -3206,6 +3208,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
3206
3208
|
async importWalletAssetsSnapshot(snapshot) {
|
|
3207
3209
|
if (!this.store.payment) throw new Error('payment 模块未初始化');
|
|
3208
3210
|
const state = this.store.payment.wallet.importWalletAssetsSnapshot(snapshot);
|
|
3211
|
+
this.store.order?.mergePointCardSnapshotCodes?.(state.items);
|
|
3209
3212
|
await this.syncSelectedWalletAssets(state);
|
|
3210
3213
|
return this.publishWalletAssetsState(state);
|
|
3211
3214
|
}
|
|
@@ -3227,6 +3230,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
3227
3230
|
});
|
|
3228
3231
|
return this.publishWalletAssetsState(emptyState);
|
|
3229
3232
|
}
|
|
3233
|
+
const pointCardSnapshotMergeContext = {
|
|
3234
|
+
customerId: businessData.customer_id,
|
|
3235
|
+
orderIdentity: this.store.order.getOrderSnapshot()?.identity
|
|
3236
|
+
};
|
|
3230
3237
|
const previousState = wallet.getWalletAssetsState();
|
|
3231
3238
|
const hasPreviousWalletContext = previousState.status !== 'idle' || previousState.items.length > 0 || previousState.selectedIds.length > 0 || previousState.customerId !== undefined;
|
|
3232
3239
|
const customerChanged = hasPreviousWalletContext && String(previousState.customerId ?? '') !== String(businessData.customer_id ?? '');
|
|
@@ -3238,8 +3245,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
3238
3245
|
await this.publishWalletAssetsState(clearedState);
|
|
3239
3246
|
}
|
|
3240
3247
|
const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
|
|
3241
|
-
preserveSelection: params?.preserveSelection !== false && !customerChanged
|
|
3242
|
-
retainSearchResultCodes: params?.retainSearchResultCodes
|
|
3248
|
+
preserveSelection: params?.preserveSelection !== false && !customerChanged
|
|
3243
3249
|
});
|
|
3244
3250
|
await this.publishWalletAssetsState(wallet.getWalletAssetsState());
|
|
3245
3251
|
let state = await refreshTask;
|
|
@@ -3249,6 +3255,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
3249
3255
|
if (state.status !== 'error') {
|
|
3250
3256
|
const committed = this.getCommittedWalletAssets();
|
|
3251
3257
|
state = wallet.setCommittedWalletAssets(committed.ids, committed.assets);
|
|
3258
|
+
this.store.order.mergePointCardSnapshotCodes?.(wallet.getUserIdentificationCodes?.() || [], pointCardSnapshotMergeContext);
|
|
3252
3259
|
}
|
|
3253
3260
|
await this.syncSelectedWalletAssets(state);
|
|
3254
3261
|
return this.publishWalletAssetsState(state);
|
|
@@ -441,10 +441,10 @@ export interface BaseSalesAddLogParams extends BaseSalesLogInput {
|
|
|
441
441
|
/** BaseSales.scanPromotionCode 对外的轻量结果(UI 可用 getDiscountList 或 scannedDiscountList 补 Holder) */
|
|
442
442
|
export interface BaseSalesScanCodeResult {
|
|
443
443
|
isAvailable: boolean;
|
|
444
|
-
/** 卡券已加入 Promotion
|
|
444
|
+
/** 卡券已加入 Promotion;false 时可能是无效、过期或已使用。 */
|
|
445
445
|
isAccepted?: boolean;
|
|
446
446
|
type?: 'server' | string;
|
|
447
447
|
unavailableReason?: 'time_limit' | string;
|
|
448
|
-
/**
|
|
448
|
+
/** batchSearch 原始结果;Holder 补全等流程可从这里读取原始卡券。 */
|
|
449
449
|
scannedDiscountList?: Discount[];
|
|
450
450
|
}
|
|
@@ -17,7 +17,6 @@ exports.resolveStrategyEligibleProducts = resolveStrategyEligibleProducts;
|
|
|
17
17
|
exports.resolveStrategyRequiredQuantity = resolveStrategyRequiredQuantity;
|
|
18
18
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
19
19
|
var _lodashEs = require("lodash-es");
|
|
20
|
-
var _entitlementPass = require("../../../modules/Discount/entitlementPass");
|
|
21
20
|
var _utils = require("../../../modules/Order/utils");
|
|
22
21
|
var _utils2 = require("../../ScanOrder/utils");
|
|
23
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -396,16 +395,11 @@ function getProductLineNoteSignature(product) {
|
|
|
396
395
|
const uid = getOrderProductUid(product);
|
|
397
396
|
return uid ? `note:${uid}` : `note:${normalizedNote}`;
|
|
398
397
|
}
|
|
399
|
-
function
|
|
398
|
+
function hasGoodPassDiscount(product) {
|
|
400
399
|
const productBundle = Array.isArray(product?.product_bundle) ? product.product_bundle : [];
|
|
401
400
|
const extendedBundle = Array.isArray(product?._extend?.other?.bundle) ? product._extend.other.bundle : [];
|
|
402
401
|
const discountLists = [product?.discount_list, ...productBundle.map(item => item?.discount_list), ...extendedBundle.map(item => item?.discount_list)];
|
|
403
|
-
|
|
404
|
-
if (!Array.isArray(discountList)) continue;
|
|
405
|
-
const pass = discountList.find(item => (0, _entitlementPass.isFullCoveragePass)(item));
|
|
406
|
-
if (pass) return String(pass.type || pass.tag);
|
|
407
|
-
}
|
|
408
|
-
return null;
|
|
402
|
+
return discountLists.some(discountList => Array.isArray(discountList) && discountList.some(item => item?.type === 'good_pass' || item?.tag === 'good_pass'));
|
|
409
403
|
}
|
|
410
404
|
|
|
411
405
|
/**
|
|
@@ -418,10 +412,8 @@ function getPromotionLineMergeBoundary(product) {
|
|
|
418
412
|
if (product?.product_id === undefined || product?.product_id === null) {
|
|
419
413
|
return `custom:${getOrderProductUid(product)}`;
|
|
420
414
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const boundary = fullCoveragePassType === 'good_pass' ? 'good-pass' : 'entitlement-pass';
|
|
424
|
-
return `${boundary}:${getOrderProductUid(product)}`;
|
|
415
|
+
if (hasGoodPassDiscount(product)) {
|
|
416
|
+
return `good-pass:${getOrderProductUid(product)}`;
|
|
425
417
|
}
|
|
426
418
|
if (Number(product?.product_sku?.open_sold_weight || 0) === 1) {
|
|
427
419
|
return `weighing:${getOrderProductUid(product)}`;
|
|
@@ -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 |
|
|
329
|
+
weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
|
|
330
330
|
}[]>;
|
|
331
331
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
332
332
|
private getScheduleDataByIds;
|
|
@@ -32,7 +32,6 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
32
32
|
private orderCustomerDiscountRefreshCustomerId;
|
|
33
33
|
private orderCustomerDiscountRefreshTarget;
|
|
34
34
|
private orderCustomerPromotionRefreshInFlight;
|
|
35
|
-
private readonly customerResolveRequests;
|
|
36
35
|
protected loadOpenDataInFlight: Promise<OpenDataConfig> | null;
|
|
37
36
|
protected loadOpenDataInFlightTarget: string | null;
|
|
38
37
|
protected openDataTarget: string | null;
|
|
@@ -81,8 +80,10 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
81
80
|
resolveCustomerById(customerId: string | number): Promise<ICustomer | null>;
|
|
82
81
|
/** 兼容既有优惠码扫码逻辑。 */
|
|
83
82
|
private resolveCustomerByDiscountCustomerId;
|
|
83
|
+
private findCustomerById;
|
|
84
84
|
private normalizeCustomer;
|
|
85
85
|
private getRawCustomerId;
|
|
86
|
+
private hasUsableCustomerDetails;
|
|
86
87
|
/**
|
|
87
88
|
* 更新当前预约的 appointment_status。
|
|
88
89
|
*
|
|
@@ -162,7 +162,6 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
162
162
|
orderCustomerDiscountRefreshCustomerId = null;
|
|
163
163
|
orderCustomerDiscountRefreshTarget = null;
|
|
164
164
|
orderCustomerPromotionRefreshInFlight = null;
|
|
165
|
-
customerResolveRequests = new Map();
|
|
166
165
|
loadOpenDataInFlight = null;
|
|
167
166
|
loadOpenDataInFlightTarget = null;
|
|
168
167
|
openDataTarget = null;
|
|
@@ -444,15 +443,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
444
443
|
|
|
445
444
|
// 缺 Holder 等场景 isAvailable=false,但仍需把 Pass 归属客户带入订单,供 Holder 弹窗使用。
|
|
446
445
|
if (!hasOrderCustomer && extractedCustomerId && !isUserPlatform) {
|
|
447
|
-
|
|
448
|
-
await this.hydrateOrderCustomerFromScanDiscounts(scannedList);
|
|
449
|
-
} catch (error) {
|
|
450
|
-
// 客户映射失败不能阻断原有 Pass 的可用性、展示或优惠处理。
|
|
451
|
-
console.warn('[BookingTicket] scan discount customer resolve failed', {
|
|
452
|
-
customerId: extractedCustomerId,
|
|
453
|
-
error
|
|
454
|
-
});
|
|
455
|
-
}
|
|
446
|
+
await this.hydrateOrderCustomerFromScanDiscounts(scannedList);
|
|
456
447
|
}
|
|
457
448
|
if (raw.isAvailable) {
|
|
458
449
|
await this.store.order.recalculateSummary({
|
|
@@ -503,39 +494,43 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
503
494
|
return null;
|
|
504
495
|
}
|
|
505
496
|
async resolveCustomerById(customerId) {
|
|
506
|
-
const
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
497
|
+
const localCustomers = this.store.customer.getCustomers();
|
|
498
|
+
const localCustomer = this.findCustomerById(localCustomers, customerId);
|
|
499
|
+
const normalizedLocalCustomer = localCustomer ? this.normalizeCustomer(localCustomer) : null;
|
|
500
|
+
if (normalizedLocalCustomer && this.hasUsableCustomerDetails(normalizedLocalCustomer)) {
|
|
501
|
+
return normalizedLocalCustomer;
|
|
510
502
|
}
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
with_franchisor_data: 1,
|
|
516
|
-
with: ['latestWalletDetail.wallet', 'contactsInfo', 'formRecord']
|
|
517
|
-
}).then(result => {
|
|
518
|
-
const customer = result?.data;
|
|
519
|
-
const resolvedCustomerId = Number(customer && typeof customer === 'object' && !Array.isArray(customer) ? this.getRawCustomerId(customer) : NaN);
|
|
520
|
-
if (result?.status !== true || result?.code !== 200 || !customer || typeof customer !== 'object' || Array.isArray(customer) || !Number.isInteger(resolvedCustomerId) || resolvedCustomerId <= 1) {
|
|
521
|
-
const error = new Error(result?.message || 'Customer resolve failed');
|
|
522
|
-
error.code = result?.code;
|
|
523
|
-
throw error;
|
|
524
|
-
}
|
|
525
|
-
return this.normalizeCustomer(customer);
|
|
526
|
-
}).finally(() => {
|
|
527
|
-
if (this.customerResolveRequests.get(normalizedCustomerId) === request) {
|
|
528
|
-
this.customerResolveRequests.delete(normalizedCustomerId);
|
|
529
|
-
}
|
|
503
|
+
const result = await this.store.customer.queryCustomerList({
|
|
504
|
+
ids: [customerId],
|
|
505
|
+
skip: 1,
|
|
506
|
+
num: 1
|
|
530
507
|
});
|
|
531
|
-
this.
|
|
532
|
-
|
|
508
|
+
const remoteCustomer = this.findCustomerById(result?.list || [], customerId) || result?.list?.[0] || null;
|
|
509
|
+
if (remoteCustomer) {
|
|
510
|
+
return this.normalizeCustomer(remoteCustomer);
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const detailCustomer = await this.store.customer.queryCustomerDetail(customerId);
|
|
514
|
+
return detailCustomer ? this.normalizeCustomer(detailCustomer) : null;
|
|
515
|
+
} catch (error) {
|
|
516
|
+
console.warn('[BookingTicket] resolveCustomerById detail request failed', {
|
|
517
|
+
customerId,
|
|
518
|
+
error
|
|
519
|
+
});
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
533
522
|
}
|
|
534
523
|
|
|
535
524
|
/** 兼容既有优惠码扫码逻辑。 */
|
|
536
525
|
resolveCustomerByDiscountCustomerId(customerId) {
|
|
537
526
|
return this.resolveCustomerById(customerId);
|
|
538
527
|
}
|
|
528
|
+
findCustomerById(customers = [], customerId) {
|
|
529
|
+
return customers.find(customer => {
|
|
530
|
+
const rawId = this.getRawCustomerId(customer);
|
|
531
|
+
return rawId !== null && String(rawId) === String(customerId);
|
|
532
|
+
}) || null;
|
|
533
|
+
}
|
|
539
534
|
normalizeCustomer(customer) {
|
|
540
535
|
const raw = customer;
|
|
541
536
|
const rawId = this.getRawCustomerId(customer);
|
|
@@ -553,6 +548,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
553
548
|
const raw = customer;
|
|
554
549
|
return customer.id ?? raw.customer_id ?? raw.customerId ?? null;
|
|
555
550
|
}
|
|
551
|
+
hasUsableCustomerDetails(customer) {
|
|
552
|
+
return !!(customer.name || customer.phone || customer.email || customer.display_name || customer.customer_name);
|
|
553
|
+
}
|
|
556
554
|
|
|
557
555
|
/**
|
|
558
556
|
* 更新当前预约的 appointment_status。
|
|
@@ -1689,7 +1687,6 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
|
|
|
1689
1687
|
const result = await (0, _applyGlobalScan.applyGlobalScan)({
|
|
1690
1688
|
setOrderCustomer: customer => this.setOrderCustomer(customer),
|
|
1691
1689
|
getOrderCustomerSnapshot: () => this.getOrderCustomerSnapshot(),
|
|
1692
|
-
resolveCustomerById: customerId => this.resolveCustomerById(customerId),
|
|
1693
1690
|
getBusinessCode: () => this.otherParams?.businessCode,
|
|
1694
1691
|
buildAddProductCtx: extra => this.buildAddProductCtx(extra),
|
|
1695
1692
|
decideAddProduct: (item, options) => this.decideAddProduct(item, options),
|
|
@@ -230,16 +230,12 @@ export interface GlobalScanHostBridge {
|
|
|
230
230
|
/**
|
|
231
231
|
* walk-in 扫 walletPass:直接核销优惠码(对齐 SaleDetail Voucher.handleApplyCode / cart.scanCode)。
|
|
232
232
|
*/
|
|
233
|
-
applyPromotionCode?: (code: string, customerId?: number
|
|
234
|
-
suppressFailureNotification?: boolean;
|
|
235
|
-
}) => Promise<{
|
|
233
|
+
applyPromotionCode?: (code: string, customerId?: number) => Promise<{
|
|
236
234
|
isAvailable?: boolean;
|
|
237
235
|
isAccepted?: boolean;
|
|
238
236
|
type?: string;
|
|
239
237
|
unavailableReason?: string;
|
|
240
238
|
}>;
|
|
241
|
-
/** 当前订单已有其他客户时,由宿主复用客户组件完成确认及切换。 */
|
|
242
|
-
requestCustomerSwitch?: (customer: ICustomer) => Promise<boolean | null>;
|
|
243
239
|
onNotify?: (type: 'success' | 'fail' | 'info', messageKey?: string) => void;
|
|
244
240
|
refresh?: () => void;
|
|
245
241
|
}
|
|
@@ -5,7 +5,6 @@ import { GlobalScanFormattedResult } from './formatGlobalScan';
|
|
|
5
5
|
export interface GlobalScanApplyHost {
|
|
6
6
|
setOrderCustomer(customer: ICustomer | null): void;
|
|
7
7
|
getOrderCustomerSnapshot(): ICustomer | null;
|
|
8
|
-
resolveCustomerById?(customerId: string | number): Promise<ICustomer | null>;
|
|
9
8
|
getBusinessCode(): string | undefined;
|
|
10
9
|
buildAddProductCtx(extra?: Record<string, any>): Record<string, any>;
|
|
11
10
|
decideAddProduct(item: any, options?: Record<string, any>): AddProductDecision;
|
|
@@ -27,7 +26,6 @@ export interface GlobalScanApplyHost {
|
|
|
27
26
|
addProductToOrder(product: any, booking?: any): Promise<any>;
|
|
28
27
|
refreshWalletAssets?(params?: {
|
|
29
28
|
preserveSelection?: boolean;
|
|
30
|
-
retainSearchResultCodes?: string[];
|
|
31
29
|
}): Promise<any>;
|
|
32
30
|
scanWalletAsset?(code: string): Promise<{
|
|
33
31
|
type: 'walletCode' | 'normalCode';
|
|
@@ -5,21 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.applyGlobalScan = applyGlobalScan;
|
|
7
7
|
var _addProductDecision = require("../addProductDecision");
|
|
8
|
+
var _cartView = require("../cartView");
|
|
8
9
|
var _scanProductValues = require("./scanProductValues");
|
|
9
10
|
/** applyGlobalScan 所需的 BookingTicket 运行时能力 */
|
|
10
11
|
|
|
11
|
-
function getRealCustomerId(customer) {
|
|
12
|
-
const customerId = Number(customer?.id ?? customer?.customer_id);
|
|
13
|
-
return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
|
|
14
|
-
}
|
|
15
|
-
function getWalletAssetCustomerId(asset) {
|
|
16
|
-
const customerId = Number(asset?.customer_id ?? asset?.holder?.customer_id);
|
|
17
|
-
return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
|
|
18
|
-
}
|
|
19
|
-
function getErrorMessage(error) {
|
|
20
|
-
return error instanceof Error ? error.message : String(error || '');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
12
|
/**
|
|
24
13
|
* 处理单条扫码商品的加车决策(含弹窗链)。
|
|
25
14
|
*/
|
|
@@ -104,81 +93,17 @@ async function applyGlobalScan(host, formatted, bridge) {
|
|
|
104
93
|
const {
|
|
105
94
|
searchType,
|
|
106
95
|
data,
|
|
107
|
-
scanCode
|
|
108
|
-
customerId: formattedCustomerId,
|
|
109
|
-
isCrossShopWallet,
|
|
110
|
-
isWalletPassUnavailableAtStore
|
|
96
|
+
scanCode
|
|
111
97
|
} = formatted;
|
|
112
98
|
if (searchType === 'wallet') {
|
|
113
|
-
|
|
114
|
-
const currentCustomerId = getRealCustomerId(currentCustomer);
|
|
115
|
-
let customer = data;
|
|
116
|
-
if (isCrossShopWallet) {
|
|
117
|
-
const sourceCustomerId = getRealCustomerId({
|
|
118
|
-
id: formattedCustomerId
|
|
119
|
-
});
|
|
120
|
-
if (sourceCustomerId === undefined || !host.resolveCustomerById) {
|
|
121
|
-
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
122
|
-
return {
|
|
123
|
-
status: 'failed',
|
|
124
|
-
reason: 'invalid_data'
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
customer = await host.resolveCustomerById(sourceCustomerId);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
|
|
131
|
-
return {
|
|
132
|
-
status: 'failed',
|
|
133
|
-
reason: 'invalid_data'
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const customerId = getRealCustomerId(customer) ?? (!isCrossShopWallet ? getRealCustomerId({
|
|
138
|
-
id: formattedCustomerId
|
|
139
|
-
}) : undefined);
|
|
140
|
-
if (!customer || customerId === undefined) {
|
|
99
|
+
if (!data) {
|
|
141
100
|
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
142
101
|
return {
|
|
143
102
|
status: 'failed',
|
|
144
103
|
reason: 'invalid_data'
|
|
145
104
|
};
|
|
146
105
|
}
|
|
147
|
-
|
|
148
|
-
...customer,
|
|
149
|
-
id: customerId
|
|
150
|
-
} : customer;
|
|
151
|
-
if (currentCustomerId === customerId) {
|
|
152
|
-
return {
|
|
153
|
-
status: 'success',
|
|
154
|
-
kind: 'customer'
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
if (currentCustomerId !== undefined) {
|
|
158
|
-
// 未接入新桥接的宿主保持原行为:已有客户时不直接覆盖。
|
|
159
|
-
if (!bridge?.requestCustomerSwitch) {
|
|
160
|
-
return {
|
|
161
|
-
status: 'success',
|
|
162
|
-
kind: 'customer'
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
const switched = await bridge.requestCustomerSwitch(orderCustomer);
|
|
167
|
-
return switched ? {
|
|
168
|
-
status: 'success',
|
|
169
|
-
kind: 'customer'
|
|
170
|
-
} : {
|
|
171
|
-
status: 'cancelled'
|
|
172
|
-
};
|
|
173
|
-
} catch (error) {
|
|
174
|
-
bridge.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
|
|
175
|
-
return {
|
|
176
|
-
status: 'failed',
|
|
177
|
-
reason: 'invalid_data'
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
host.setOrderCustomer(orderCustomer);
|
|
106
|
+
host.setOrderCustomer(data);
|
|
182
107
|
bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
|
|
183
108
|
return {
|
|
184
109
|
status: 'success',
|
|
@@ -186,70 +111,8 @@ async function applyGlobalScan(host, formatted, bridge) {
|
|
|
186
111
|
};
|
|
187
112
|
}
|
|
188
113
|
if (searchType === 'walletPass') {
|
|
189
|
-
if (isWalletPassUnavailableAtStore) {
|
|
190
|
-
bridge?.onNotify?.('fail', 'pisell2.text.wallet-pass-not-available-at-store');
|
|
191
|
-
return {
|
|
192
|
-
status: 'failed',
|
|
193
|
-
reason: 'invalid_data'
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
114
|
const snapshot = host.getOrderCustomerSnapshot();
|
|
197
|
-
|
|
198
|
-
const bindWalletPassCustomer = async asset => {
|
|
199
|
-
if (getRealCustomerId(activeCustomer) !== undefined) {
|
|
200
|
-
return {
|
|
201
|
-
resolveFailed: false,
|
|
202
|
-
customerBound: false
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
const assetCustomerId = getWalletAssetCustomerId(asset) ?? getRealCustomerId({
|
|
206
|
-
id: formattedCustomerId
|
|
207
|
-
});
|
|
208
|
-
let customer = null;
|
|
209
|
-
if (assetCustomerId !== undefined) {
|
|
210
|
-
if (!host.resolveCustomerById) {
|
|
211
|
-
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
212
|
-
return {
|
|
213
|
-
resolveFailed: true,
|
|
214
|
-
customerBound: false
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
try {
|
|
218
|
-
customer = await host.resolveCustomerById(assetCustomerId);
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.warn('[GlobalScan] Wallet asset customer lookup failed', error);
|
|
221
|
-
bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
|
|
222
|
-
return {
|
|
223
|
-
resolveFailed: true,
|
|
224
|
-
customerBound: false
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const customerId = getRealCustomerId(customer);
|
|
229
|
-
if (!customer || customerId === undefined) {
|
|
230
|
-
if (assetCustomerId !== undefined) {
|
|
231
|
-
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
resolveFailed: assetCustomerId !== undefined,
|
|
235
|
-
customerBound: false
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
const orderCustomer = customer.id === undefined || customer.id === null ? {
|
|
239
|
-
...customer,
|
|
240
|
-
id: customerId
|
|
241
|
-
} : customer;
|
|
242
|
-
host.setOrderCustomer(orderCustomer);
|
|
243
|
-
activeCustomer = orderCustomer;
|
|
244
|
-
await host.refreshWalletAssets?.({
|
|
245
|
-
preserveSelection: false,
|
|
246
|
-
retainSearchResultCodes: [scanCode]
|
|
247
|
-
});
|
|
248
|
-
return {
|
|
249
|
-
resolveFailed: false,
|
|
250
|
-
customerBound: true
|
|
251
|
-
};
|
|
252
|
-
};
|
|
115
|
+
const scannedCustomerIsWalkIn = (0, _cartView.isWalkInCustomer)(data);
|
|
253
116
|
const trySelectWalletAsset = async () => {
|
|
254
117
|
if (!host.scanWalletAsset) return null;
|
|
255
118
|
const walletResult = await host.scanWalletAsset(scanCode).catch(error => {
|
|
@@ -260,56 +123,61 @@ async function applyGlobalScan(host, formatted, bridge) {
|
|
|
260
123
|
if (walletResult.type !== 'normalCode' || !walletResult.asset) {
|
|
261
124
|
return null;
|
|
262
125
|
}
|
|
263
|
-
const bindResult = await bindWalletPassCustomer(walletResult.asset);
|
|
264
126
|
if (walletResult.selected) {
|
|
265
|
-
|
|
266
|
-
bridge?.onNotify?.('success');
|
|
267
|
-
}
|
|
127
|
+
bridge?.onNotify?.('success');
|
|
268
128
|
return {
|
|
269
129
|
status: 'success',
|
|
270
130
|
kind: 'promotion'
|
|
271
131
|
};
|
|
272
132
|
}
|
|
273
133
|
// 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
|
|
274
|
-
|
|
275
|
-
bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
|
|
276
|
-
}
|
|
134
|
+
bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
|
|
277
135
|
return {
|
|
278
136
|
status: 'failed',
|
|
279
137
|
reason: 'invalid_data'
|
|
280
138
|
};
|
|
281
139
|
};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
140
|
+
if ((0, _cartView.isWalkInCustomer)(snapshot) || scannedCustomerIsWalkIn) {
|
|
141
|
+
// 当前购物车或 walletPass 绑定客户为 walk-in 时不绑客户,避免覆盖已有下单客户。
|
|
142
|
+
const walletSelection = await trySelectWalletAsset();
|
|
143
|
+
if (walletSelection) return walletSelection;
|
|
144
|
+
if (!bridge?.applyPromotionCode) {
|
|
145
|
+
return {
|
|
146
|
+
status: 'failed',
|
|
147
|
+
reason: 'no_bridge'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const result = await bridge.applyPromotionCode(scanCode);
|
|
151
|
+
if (result?.isAccepted ?? result?.isAvailable) {
|
|
152
|
+
return {
|
|
153
|
+
status: 'success',
|
|
154
|
+
kind: 'promotion'
|
|
155
|
+
};
|
|
156
|
+
}
|
|
289
157
|
return {
|
|
290
158
|
status: 'failed',
|
|
291
|
-
reason: '
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
const promotionCustomerId = getRealCustomerId(activeCustomer);
|
|
295
|
-
const promotionResult = bindResult.customerBound ? await bridge.applyPromotionCode(scanCode, promotionCustomerId, {
|
|
296
|
-
suppressFailureNotification: true
|
|
297
|
-
}) : await bridge.applyPromotionCode(scanCode, promotionCustomerId);
|
|
298
|
-
if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
|
|
299
|
-
return {
|
|
300
|
-
status: 'success',
|
|
301
|
-
kind: 'promotion'
|
|
159
|
+
reason: 'invalid_data'
|
|
302
160
|
};
|
|
303
161
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
162
|
+
host.setOrderCustomer(data);
|
|
163
|
+
await host.refreshWalletAssets?.({
|
|
164
|
+
preserveSelection: false
|
|
165
|
+
});
|
|
166
|
+
const walletSelection = await trySelectWalletAsset();
|
|
167
|
+
if (walletSelection) return walletSelection;
|
|
168
|
+
if (bridge?.applyPromotionCode) {
|
|
169
|
+
const promotionResult = await bridge.applyPromotionCode(scanCode, Number(data?.id ?? data?.customer_id) || undefined);
|
|
170
|
+
if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
|
|
171
|
+
return {
|
|
172
|
+
status: 'success',
|
|
173
|
+
kind: 'promotion'
|
|
174
|
+
};
|
|
175
|
+
}
|
|
309
176
|
}
|
|
177
|
+
bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
|
|
310
178
|
return {
|
|
311
|
-
status: '
|
|
312
|
-
|
|
179
|
+
status: 'success',
|
|
180
|
+
kind: 'customer'
|
|
313
181
|
};
|
|
314
182
|
}
|
|
315
183
|
if (searchType === 'product' || searchType === 'local_product') {
|
|
@@ -14,8 +14,7 @@ const searchWalletPass = async (request, code) => {
|
|
|
14
14
|
// 翻译识别码名称 0:不翻译 1:翻译
|
|
15
15
|
relation_product: 1,
|
|
16
16
|
// 组装关联商品: 0不处理 1处理
|
|
17
|
-
|
|
18
|
-
with: ['customer', 'franchiseeWalletPass:shop_id,source_shop_id,product_id,use'],
|
|
17
|
+
with: ['customer'],
|
|
19
18
|
tags: ['point_card',
|
|
20
19
|
// 积分卡
|
|
21
20
|
'gift_card',
|
|
@@ -26,8 +25,6 @@ const searchWalletPass = async (request, code) => {
|
|
|
26
25
|
// 折扣卡
|
|
27
26
|
'good_pass',
|
|
28
27
|
// 商品券
|
|
29
|
-
'entitlement_pass',
|
|
30
|
-
// 月卡 / 年卡 / 多次使用卡
|
|
31
28
|
'session_ticket',
|
|
32
29
|
// 场次票
|
|
33
30
|
'appointment_ticket' // 预约类门票
|
|
@@ -54,18 +51,17 @@ exports.searchWalletPass = searchWalletPass;
|
|
|
54
51
|
const searchWallet = async (request, code) => {
|
|
55
52
|
const params = {
|
|
56
53
|
code,
|
|
57
|
-
with_customer: 1
|
|
58
|
-
with_franchisor_data: 1
|
|
54
|
+
with_customer: 1
|
|
59
55
|
};
|
|
60
56
|
try {
|
|
61
57
|
const res = await request?.post('/wallet/detail/search', params);
|
|
62
|
-
if (res?.
|
|
58
|
+
if (res?.code == 200 && !!res?.data) {
|
|
63
59
|
return {
|
|
64
60
|
searchType: 'wallet',
|
|
65
61
|
response: res
|
|
66
62
|
};
|
|
67
63
|
}
|
|
68
|
-
throw new Error(
|
|
64
|
+
throw new Error('没有找到对应的识别码');
|
|
69
65
|
} catch (error) {
|
|
70
66
|
throw error;
|
|
71
67
|
}
|
|
@@ -6,12 +6,6 @@ export interface GlobalScanFormattedResult {
|
|
|
6
6
|
searchType: GlobalScanSearchType;
|
|
7
7
|
data: any;
|
|
8
8
|
scanCode: string;
|
|
9
|
-
/** Wallet / Wallet Pass 来源客户 ID;跨店时必须先解析为当前店客户。 */
|
|
10
|
-
customerId?: string | number;
|
|
11
|
-
/** 仅 Wallet 返回;true 时禁止直接使用响应内的来源客户。 */
|
|
12
|
-
isCrossShopWallet?: boolean;
|
|
13
|
-
/** 总店 Wallet Pass 未共享给当前子店。 */
|
|
14
|
-
isWalletPassUnavailableAtStore?: boolean;
|
|
15
9
|
}
|
|
16
10
|
interface RawScanSearchResult {
|
|
17
11
|
searchType?: GlobalScanSearchType;
|