@pisell/pisellos 2.3.127 → 2.3.128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
  6. package/dist/modules/Customer/index.js +3 -6
  7. package/dist/modules/Customer/types.d.ts +0 -2
  8. package/dist/modules/Discount/index.d.ts +2 -2
  9. package/dist/modules/Discount/index.js +151 -37
  10. package/dist/modules/Discount/types.d.ts +5 -36
  11. package/dist/modules/Order/index.d.ts +2 -7
  12. package/dist/modules/Order/index.js +331 -480
  13. package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
  14. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  15. package/dist/modules/Order/utils/weighedProduct.js +94 -0
  16. package/dist/modules/Order/utils.d.ts +1 -1
  17. package/dist/modules/Order/utils.js +65 -104
  18. package/dist/modules/Payment/types.d.ts +1 -21
  19. package/dist/modules/Payment/types.js +0 -2
  20. package/dist/modules/Payment/walletpass.d.ts +1 -1
  21. package/dist/modules/Payment/walletpass.js +47 -80
  22. package/dist/modules/Rules/index.d.ts +2 -2
  23. package/dist/modules/Rules/index.js +190 -482
  24. package/dist/modules/Rules/types.d.ts +2 -4
  25. package/dist/server/modules/order/types.d.ts +0 -2
  26. package/dist/server/utils/small-ticket.js +1 -1
  27. package/dist/solution/BaseSales/index.d.ts +2 -3
  28. package/dist/solution/BaseSales/index.js +77 -44
  29. package/dist/solution/BaseSales/types.d.ts +7 -3
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
  31. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
  32. package/dist/solution/BaseSales/utils.js +3 -2
  33. package/dist/solution/BookingByStep/index.d.ts +1 -1
  34. package/dist/solution/BookingTicket/index.d.ts +3 -2
  35. package/dist/solution/BookingTicket/index.js +63 -60
  36. package/dist/solution/BookingTicket/types.d.ts +1 -5
  37. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  38. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
  39. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  40. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  41. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
  42. package/dist/solution/ScanOrder/utils.js +3 -2
  43. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  44. package/dist/solution/ShopDiscount/index.js +42 -99
  45. package/dist/solution/ShopDiscount/utils.d.ts +2 -4
  46. package/dist/solution/ShopDiscount/utils.js +23 -43
  47. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  48. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  49. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  50. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  51. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
  52. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
  53. package/lib/modules/Customer/index.js +1 -5
  54. package/lib/modules/Customer/types.d.ts +0 -2
  55. package/lib/modules/Discount/index.d.ts +2 -2
  56. package/lib/modules/Discount/index.js +129 -23
  57. package/lib/modules/Discount/types.d.ts +5 -36
  58. package/lib/modules/Order/index.d.ts +2 -7
  59. package/lib/modules/Order/index.js +109 -222
  60. package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
  61. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  62. package/lib/modules/Order/utils/weighedProduct.js +89 -0
  63. package/lib/modules/Order/utils.d.ts +1 -1
  64. package/lib/modules/Order/utils.js +6 -41
  65. package/lib/modules/Payment/types.d.ts +1 -21
  66. package/lib/modules/Payment/types.js +0 -1
  67. package/lib/modules/Payment/walletpass.d.ts +1 -1
  68. package/lib/modules/Payment/walletpass.js +9 -29
  69. package/lib/modules/Rules/index.d.ts +2 -2
  70. package/lib/modules/Rules/index.js +114 -359
  71. package/lib/modules/Rules/types.d.ts +2 -4
  72. package/lib/server/modules/order/types.d.ts +0 -2
  73. package/lib/server/utils/small-ticket.js +1 -1
  74. package/lib/solution/BaseSales/index.d.ts +2 -3
  75. package/lib/solution/BaseSales/index.js +17 -11
  76. package/lib/solution/BaseSales/types.d.ts +7 -3
  77. package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
  78. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
  79. package/lib/solution/BaseSales/utils.js +2 -1
  80. package/lib/solution/BookingByStep/index.d.ts +1 -1
  81. package/lib/solution/BookingTicket/index.d.ts +3 -2
  82. package/lib/solution/BookingTicket/index.js +33 -36
  83. package/lib/solution/BookingTicket/types.d.ts +1 -5
  84. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  85. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
  86. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  87. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  88. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
  89. package/lib/solution/ScanOrder/utils.js +2 -1
  90. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  91. package/lib/solution/ShopDiscount/index.js +9 -55
  92. package/lib/solution/ShopDiscount/utils.d.ts +2 -4
  93. package/lib/solution/ShopDiscount/utils.js +25 -42
  94. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  95. package/package.json +1 -1
  96. package/dist/modules/Discount/availability.d.ts +0 -7
  97. package/dist/modules/Discount/availability.js +0 -49
  98. package/dist/modules/Discount/entitlementPass.d.ts +0 -34
  99. package/dist/modules/Discount/entitlementPass.js +0 -147
  100. package/lib/modules/Discount/availability.d.ts +0 -7
  101. package/lib/modules/Discount/availability.js +0 -43
  102. package/lib/modules/Discount/entitlementPass.d.ts +0 -34
  103. package/lib/modules/Discount/entitlementPass.js +0 -141
@@ -29,12 +29,10 @@ 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[];
34
+ /** Reweighed order lines only: reapply selected wallet discounts against their new amount. */
35
+ reapplyWeighedDiscountProductUids?: string[];
38
36
  }
39
37
  export interface RulesModuleAPI {
40
38
  setRulesList: (rulesList: Rules[]) => Promise<void>;
@@ -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
  /**
@@ -952,7 +952,7 @@ function resolveVariantItem(group, itemPositionId) {
952
952
  }
953
953
  function getProductTitleSource(source, locale) {
954
954
  if (!source || typeof source !== 'object') return '';
955
- return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
955
+ return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name_i18n, locale) || resolveTitleValue(source.name, locale);
956
956
  }
957
957
  function getBundleProductTitleSource(source, locale) {
958
958
  if (!source || typeof source !== 'object') return '';
@@ -1,6 +1,6 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
- import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, BaseSalesUpdateOrderProductQuantityParams, BaseSalesCalculateProductBookingPriceParams, BaseSalesPriceRecalculationContextChange, BaseSalesProductBookingPriceResult, BaseSalesQuotationCustomerScopeInfo, BaseSalesScanCodeResult, BaseSalesCashPaymentConfig, BaseSalesPayCashParams, BaseSalesPayCashResult, BaseSalesCommitPaymentMethodParams, BaseSalesCommitPaymentMethodResult, BaseSalesConfirmWalletPaymentResult } from './types';
3
+ import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, BaseSalesUpdateOrderProductQuantityParams, BaseSalesCalculateProductBookingPriceParams, BaseSalesPriceRecalculationContextChange, BaseSalesProductBookingPriceResult, BaseSalesQuotationCustomerScopeInfo, BaseSalesScanCodeResult, BaseSalesCashPaymentOptions, BaseSalesCashPaymentConfig, BaseSalesPayCashParams, BaseSalesPayCashResult, BaseSalesCommitPaymentMethodParams, BaseSalesCommitPaymentMethodResult, BaseSalesConfirmWalletPaymentResult } from './types';
4
4
  import { OrderModule } from '../../modules/Order';
5
5
  import type { AddProductBookingInput, AddProductToOrderOptions, LoadSalesDetailParams, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, OrderPaymentSource, SendCustomerPayLinkParams, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, UpdateTempOrderCustomerInput, UpdateOrderBookingParams, UpdateOrderProductParams, OrderTempOrder, OrderSummary, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, ReplaceTempOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, ShopServiceData, ShopServiceType } from '../../modules/Order/types';
6
6
  import type { SubmitPayloadEnhancer } from '../../modules/Order/utils';
@@ -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: {
@@ -451,7 +450,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
451
450
  private findCashPaymentMethod;
452
451
  private getPendingWalletPaymentAmount;
453
452
  /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
454
- getCashPaymentConfig(): Promise<BaseSalesCashPaymentConfig>;
453
+ getCashPaymentConfig(options?: BaseSalesCashPaymentOptions): Promise<BaseSalesCashPaymentConfig>;
455
454
  /**
456
455
  * 确认足额覆盖订单的 pending Wallet 支付并提交订单。
457
456
  *
@@ -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 || !['entitlement_pass', 'good_pass', 'discount_card'].includes(discount.type)) return;
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);
@@ -3247,8 +3245,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3247
3245
  await this.publishWalletAssetsState(clearedState);
3248
3246
  }
3249
3247
  const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
3250
- preserveSelection: params?.preserveSelection !== false && !customerChanged,
3251
- retainSearchResultCodes: params?.retainSearchResultCodes
3248
+ preserveSelection: params?.preserveSelection !== false && !customerChanged
3252
3249
  });
3253
3250
  await this.publishWalletAssetsState(wallet.getWalletAssetsState());
3254
3251
  let state = await refreshTask;
@@ -3356,10 +3353,14 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3356
3353
  getPaymentMethods() {
3357
3354
  return [...this.paymentMethodsCache];
3358
3355
  }
3359
- findCashPaymentMethod(paymentMethods) {
3356
+ findCashPaymentMethod(paymentMethods, paymentMethodId) {
3360
3357
  return paymentMethods.find(method => {
3358
+ if (method?.enabled === false || method?.enable === false) return false;
3361
3359
  const identifiers = [method?.code, method?.type, method?.tag].map(value => String(value || '').toUpperCase());
3362
- return identifiers.includes('CASHMANUAL') && method?.enabled !== false && method?.enable !== false;
3360
+ const isDefaultCash = identifiers.includes('CASHMANUAL');
3361
+ if (paymentMethodId === undefined) return isDefaultCash;
3362
+ const isCustomCash = String(method?.type || '').trim().toLowerCase() === 'custom' && [method?.name, method?.nameEn].some(name => typeof name === 'string' && /现金|現金|cash/i.test(name));
3363
+ return String(method?.id) === String(paymentMethodId) && (isDefaultCash || isCustomCash);
3363
3364
  });
3364
3365
  }
3365
3366
  getPendingWalletPaymentAmount(payments = this.store.order?.getOrderPayments?.() || []) {
@@ -3376,13 +3377,16 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3376
3377
  }
3377
3378
 
3378
3379
  /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */
3379
- async getCashPaymentConfig() {
3380
+ async getCashPaymentConfig(options = {}) {
3380
3381
  if (!this.store.payment) throw new Error('payment 模块未初始化');
3381
3382
  let paymentMethods = this.getPaymentMethods();
3382
- let paymentMethod = this.findCashPaymentMethod(paymentMethods);
3383
+ let paymentMethod = this.findCashPaymentMethod(paymentMethods, options.paymentMethodId);
3383
3384
  if (!paymentMethod) {
3384
3385
  paymentMethods = await this.getPaymentMethodsAsync();
3385
- paymentMethod = this.findCashPaymentMethod(paymentMethods);
3386
+ paymentMethod = this.findCashPaymentMethod(paymentMethods, options.paymentMethodId);
3387
+ }
3388
+ if (!paymentMethod && options.paymentMethodId !== undefined) {
3389
+ throw new Error(`未找到可用的现金支付方式:${options.paymentMethodId}`);
3386
3390
  }
3387
3391
  const amountSnapshot = this.store.order?.getOrderAmountSnapshot?.();
3388
3392
  const pendingWalletAmount = this.getPendingWalletPaymentAmount();
@@ -3480,7 +3484,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3480
3484
  if (!Number.isFinite(amount) || amount <= 0) {
3481
3485
  throw new Error('现金支付金额必须大于 0');
3482
3486
  }
3483
- const config = await this.getCashPaymentConfig();
3487
+ const config = params.paymentMethodId === undefined ? await this.getCashPaymentConfig() : await this.getCashPaymentConfig({
3488
+ paymentMethodId: params.paymentMethodId
3489
+ });
3484
3490
  const paymentMethod = config.paymentMethod;
3485
3491
  if (!paymentMethod) throw new Error('未找到可用的 CASHMANUAL 支付方式');
3486
3492
  if (config.amountDue <= 0) throw new Error('当前订单没有待支付金额');
@@ -23,13 +23,17 @@ export type BaseSalesHookName = typeof BaseSalesHookNames[keyof typeof BaseSales
23
23
  export declare function createBaseSalesHook(moduleName: string, hookName: BaseSalesHookName): string;
24
24
  export type BaseSalesStatus = 'idle' | 'initializing' | 'ready' | 'error';
25
25
  export type BaseSalesPaymentStatus = 'paid' | 'partially_paid' | 'unpaid' | 'payment_processing' | string;
26
+ export interface BaseSalesCashPaymentOptions {
27
+ /** 指定现金支付方式;省略时使用默认 CASHMANUAL。 */
28
+ paymentMethodId?: number | string;
29
+ }
26
30
  export interface BaseSalesCashPaymentConfig {
27
31
  available: boolean;
28
32
  paymentMethod?: PaymentMethod;
29
33
  amountDue: number;
30
34
  recommendedAmounts: number[];
31
35
  }
32
- export interface BaseSalesPayCashParams {
36
+ export interface BaseSalesPayCashParams extends BaseSalesCashPaymentOptions {
33
37
  /** 实际计入订单的现金支付金额(部分支付时小于待付金额)。 */
34
38
  amount: number;
35
39
  /** 顾客实际交付现金;可大于 amount。 */
@@ -441,10 +445,10 @@ export interface BaseSalesAddLogParams extends BaseSalesLogInput {
441
445
  /** BaseSales.scanPromotionCode 对外的轻量结果(UI 可用 getDiscountList 或 scannedDiscountList 补 Holder) */
442
446
  export interface BaseSalesScanCodeResult {
443
447
  isAvailable: boolean;
444
- /** 卡券已加入 Promotion;可能因次数、时间或当前订单条件而暂时无法应用。 */
448
+ /** 卡券已加入 Promotion;false 时可能是无效、过期或已使用。 */
445
449
  isAccepted?: boolean;
446
450
  type?: 'server' | string;
447
451
  unavailableReason?: 'time_limit' | string;
448
- /** 扫码卡券资料及最新可用状态,供 Holder 补全等流程使用。 */
452
+ /** batchSearch 原始结果;Holder 补全等流程可从这里读取原始卡券。 */
449
453
  scannedDiscountList?: Discount[];
450
454
  }
@@ -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 getFullCoveragePassDiscountType(product) {
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
- for (const discountList of discountLists) {
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
- const fullCoveragePassType = getFullCoveragePassDiscountType(product);
422
- if (fullCoveragePassType) {
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)}`;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.transformBaseProductToOrderProduct = transformBaseProductToOrderProduct;
7
+ var _weighedProduct = require("../../../modules/Order/utils/weighedProduct");
7
8
  var _utils = require("../../../modules/Order/utils");
8
9
  var _manualProductDiscount = require("../../../modules/Order/utils/manualProductDiscount");
9
10
  function toNumber(value, fallback = 0) {
@@ -65,11 +66,11 @@ function appendDataVariantIds(base, ...values) {
65
66
  }
66
67
  return Array.isArray(base) || result.length ? result : undefined;
67
68
  }
68
- function normalizeOptionItems(optionItems) {
69
+ function normalizeOptionItems(optionItems, useOriginalPrice = false) {
69
70
  if (!Array.isArray(optionItems)) return [];
70
71
  return optionItems.map(optionItem => {
71
72
  const optionGroupItemId = toNumber(optionItem?.option_group_item_id ?? optionItem?.id);
72
- const price = optionItem?.price ?? optionItem?.add_price ?? 0;
73
+ const price = (useOriginalPrice ? optionItem?.original_price : undefined) ?? optionItem?.price ?? optionItem?.add_price ?? 0;
73
74
  return {
74
75
  ...optionItem,
75
76
  option_group_item_id: optionGroupItemId,
@@ -80,10 +81,12 @@ function normalizeOptionItems(optionItems) {
80
81
  };
81
82
  });
82
83
  }
83
- function normalizeBundleItems(bundleItems, preferPriceField = false) {
84
+ function normalizeBundleItems(bundleItems, preferPriceField = false, preferBundleSellingPrice = false) {
84
85
  if (!Array.isArray(bundleItems)) return [];
85
86
  return bundleItems.map(bundleItem => {
86
- const unitSelling = preferPriceField ? bundleItem.price ?? bundleItem.bundle_selling_price ?? bundleItem.custom_price ?? bundleItem.product_price ?? '0' : bundleItem.bundle_selling_price ?? bundleItem.price ?? bundleItem.custom_price ?? bundleItem.product_price ?? '0';
87
+ // Weighed manual prices distribute the bundle base and nested options separately.
88
+ // Its explicit selling amount already includes those options.
89
+ const unitSelling = preferPriceField && !preferBundleSellingPrice ? bundleItem.price ?? bundleItem.bundle_selling_price ?? bundleItem.custom_price ?? bundleItem.product_price ?? '0' : bundleItem.bundle_selling_price ?? bundleItem.price ?? bundleItem.custom_price ?? bundleItem.product_price ?? '0';
87
90
  const unitStr = toPriceString(unitSelling, '0.00');
88
91
  const num = toSafePositiveInt(bundleItem?.num ?? bundleItem?.quantity, 1);
89
92
  const magnitudeSource = {
@@ -147,19 +150,25 @@ function transformBaseProductToOrderProduct(params) {
147
150
  const productionCode = normalizeProductionCode(Object.prototype.hasOwnProperty.call(payload, 'production_code') ? payload.production_code : productVariantId > 0 ? matchedVariant?.production_code : origin?.production_code ?? sourceProduct?.production_code);
148
151
  const hasPriceOverride = payload.price_override !== undefined && payload.price_override !== null && payload.price_override !== '';
149
152
  // 手动改价后 payload.price 是分摊后的主商品售价,不能再作为券前 source。
150
- // 此时优先从商品/variant 快照读取目录价;售价仍由 line_total - bundle 推导。
153
+ // 称重商品使用改价前净重金额;其它商品从商品/variant 快照读取目录价。
154
+ // 售价仍由 line_total - bundle 推导。
151
155
  const catalogSourcePrice = matchedVariant?.price ?? matchedVariant?.base_price ?? origin?.price ?? origin?.base_price ?? sourceProduct?.price ?? sourceProduct?.selling_price ?? sourceProduct?.base_price;
152
- const sourceProductPrice = toPriceString(hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice, '0.00');
156
+ const weighedSourcePrice = (0, _weighedProduct.resolveWeighedSourcePrice)(payload.product_sku ?? origin.product_sku, payload._extend?.weighing ?? origin._extend?.weighing);
157
+ const sourceProductPrice = toPriceString(weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
153
158
  const explicitLineTotal = payload.line_total ?? payload.total ?? payload._extend?.total;
154
159
  const hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
155
160
  const lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
156
- const productOptionItem = (0, _utils.normalizeProductSkuOptions)(normalizeOptionItems(payload.product_sku?.option ?? payload.option ?? payload.options ?? payload.product_option_item));
157
- const productBundle = normalizeBundleItems(payload.bundle ?? payload.product_bundle, hasPriceOverride);
161
+ const productOptionItem = (0, _utils.normalizeProductSkuOptions)(normalizeOptionItems(payload.product_sku?.option ?? payload.option ?? payload.options ?? payload.product_option_item, hasPriceOverride || weighedSourcePrice !== undefined));
162
+ const productBundle = normalizeBundleItems(payload.bundle ?? payload.product_bundle, hasPriceOverride, hasPriceOverride && weighedSourcePrice !== undefined);
158
163
  // `payload.unique` 是业务侧商品/票务标识,可能在连续加同一商品时重复;
159
164
  // 行级唯一值只接受显式协议字段,缺省交给 OrderModule 生成。
160
165
  const uniqueIdentificationNumber = payload.unique_identification_number;
161
166
  const resolvedQuantity = toSafePositiveInt(payload.quantity ?? payload.num, 1);
162
- const originTotal = (0, _manualProductDiscount.resolveManualDiscountOriginTotal)({
167
+ const originTotal = weighedSourcePrice !== undefined ? Number((0, _utils.composeLinePrice)({
168
+ mainPrice: Number(weighedSourcePrice) + (0, _utils.sumOptionUnitPrice)(productOptionItem).toNumber(),
169
+ bundle: hasPriceOverride ? (0, _weighedProduct.withOriginalBundleOptionPrices)(productBundle) : productBundle,
170
+ useOriginalBundle: true
171
+ })) : (0, _manualProductDiscount.resolveManualDiscountOriginTotal)({
163
172
  originTotal: payload.origin_total,
164
173
  extendOriginTotal: payload._extend?.origin_total,
165
174
  originExtendOriginTotal: origin?._extend?.origin_total,
@@ -260,6 +269,12 @@ function transformBaseProductToOrderProduct(params) {
260
269
  product_cover: firstNonBlank(matchedVariant?.cover, sourceProduct?.cover),
261
270
  _origin: {
262
271
  ...(sourceProduct || {}),
272
+ ...(weighedSourcePrice !== undefined && hasPriceOverride ? {
273
+ _extend: {
274
+ ...sourceProduct?._extend,
275
+ origin_total: originTotal
276
+ }
277
+ } : {}),
263
278
  callbackData: payload
264
279
  }
265
280
  };
@@ -8,6 +8,7 @@ exports.createEmptySummary = createEmptySummary;
8
8
  exports.getSafeProductNum = getSafeProductNum;
9
9
  exports.isSkuOnlyDeleteIdentity = isSkuOnlyDeleteIdentity;
10
10
  exports.normalizeOrderProduct = normalizeOrderProduct;
11
+ var _weighedProduct = require("../../modules/Order/utils/weighedProduct");
11
12
  var _decimal = _interopRequireDefault(require("decimal.js"));
12
13
  var _utils = require("../../modules/Order/utils");
13
14
  var _manualProductDiscount = require("../../modules/Order/utils/manualProductDiscount");
@@ -237,7 +238,7 @@ function normalizeOrderProduct(product) {
237
238
  });
238
239
  const composedOriginalPrice = (0, _utils.composeLinePrice)({
239
240
  mainPrice: mainOriginalStr,
240
- bundle: normalizedBundle,
241
+ bundle: Number(productSku.open_sold_weight) === 1 && (0, _manualProductDiscount.hasManualProductDiscountFlag)(metadata) ? (0, _weighedProduct.withOriginalBundleOptionPrices)(normalizedBundle) : normalizedBundle,
241
242
  useOriginalBundle: true
242
243
  });
243
244
  const finalOriginalPrice = (0, _utils.resolveManualOverrideLineOriginalPrice)({
@@ -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 | 1 | 2 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
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
  *
@@ -346,7 +347,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
346
347
  * 获取当前的客户搜索条件
347
348
  * @returns 当前搜索条件
348
349
  */
349
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
350
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
350
351
  /**
351
352
  * 获取客户列表状态(包含滚动加载相关状态)
352
353
  * @returns 客户状态
@@ -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
- try {
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 rawCustomerId = String(customerId ?? '').trim();
507
- const numericCustomerId = Number(rawCustomerId);
508
- if (!rawCustomerId || !Number.isInteger(numericCustomerId) || numericCustomerId <= 1) {
509
- return null;
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 normalizedCustomerId = String(numericCustomerId);
512
- const existingRequest = this.customerResolveRequests.get(normalizedCustomerId);
513
- if (existingRequest) return existingRequest;
514
- const request = this.request.post(`/customer/resolve/${encodeURIComponent(normalizedCustomerId)}`, {
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.customerResolveRequests.set(normalizedCustomerId, request);
532
- return request;
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, options?: {
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';