@pisell/pisellos 2.3.231 → 2.3.233

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 (46) hide show
  1. package/dist/modules/Customer/types.d.ts +4 -0
  2. package/dist/modules/Order/index.d.ts +10 -1
  3. package/dist/modules/Order/index.js +1350 -1133
  4. package/dist/modules/Order/types.d.ts +3 -0
  5. package/dist/modules/Order/utils/bookingUuid.d.ts +4 -0
  6. package/dist/modules/Order/utils/bookingUuid.js +24 -0
  7. package/dist/modules/Order/utils/virtualSettlement.d.ts +4 -0
  8. package/dist/modules/Order/utils/virtualSettlement.js +13 -0
  9. package/dist/modules/Order/utils.js +11 -6
  10. package/dist/modules/Product/index.d.ts +1 -1
  11. package/dist/shared/payment/loadPaymentMethods.d.ts +4 -1
  12. package/dist/shared/payment/loadPaymentMethods.js +35 -2
  13. package/dist/solution/BaseSales/index.d.ts +1 -0
  14. package/dist/solution/BaseSales/index.js +516 -423
  15. package/dist/solution/BookingByStep/index.d.ts +2 -2
  16. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +14 -13
  17. package/dist/solution/Checkout/index.js +104 -69
  18. package/dist/solution/Checkout/types.d.ts +1 -0
  19. package/dist/solution/ScanOrder/index.js +10 -2
  20. package/dist/solution/VenueBooking/index.js +522 -490
  21. package/dist/utils/platform.d.ts +1 -0
  22. package/dist/utils/platform.js +4 -0
  23. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  24. package/lib/modules/Customer/types.d.ts +4 -0
  25. package/lib/modules/Order/index.d.ts +10 -1
  26. package/lib/modules/Order/index.js +141 -20
  27. package/lib/modules/Order/types.d.ts +3 -0
  28. package/lib/modules/Order/utils/bookingUuid.d.ts +4 -0
  29. package/lib/modules/Order/utils/bookingUuid.js +25 -0
  30. package/lib/modules/Order/utils/virtualSettlement.d.ts +4 -0
  31. package/lib/modules/Order/utils/virtualSettlement.js +9 -1
  32. package/lib/modules/Order/utils.js +13 -5
  33. package/lib/modules/Product/index.d.ts +1 -1
  34. package/lib/shared/payment/loadPaymentMethods.d.ts +4 -1
  35. package/lib/shared/payment/loadPaymentMethods.js +13 -0
  36. package/lib/solution/BaseSales/index.d.ts +1 -0
  37. package/lib/solution/BaseSales/index.js +49 -10
  38. package/lib/solution/BookingByStep/index.d.ts +2 -2
  39. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +14 -13
  40. package/lib/solution/Checkout/index.js +21 -0
  41. package/lib/solution/Checkout/types.d.ts +1 -0
  42. package/lib/solution/ScanOrder/index.js +6 -0
  43. package/lib/solution/VenueBooking/index.js +6 -1
  44. package/lib/utils/platform.d.ts +1 -0
  45. package/lib/utils/platform.js +5 -0
  46. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  * Normalize the runtime platform passed through solution/module otherParams.
3
3
  */
4
4
  export declare function normalizeRuntimePlatform(platform: unknown): string;
5
+ export declare function isPosTerminalPlatform(platform: unknown): boolean;
5
6
  /**
6
7
  * PC and H5 are authenticated-customer clients rather than staff terminals.
7
8
  */
@@ -7,6 +7,10 @@ var SELF_SERVICE_PLATFORMS = new Set(['kiosk', 'vending']);
7
7
  export function normalizeRuntimePlatform(platform) {
8
8
  return String(platform !== null && platform !== void 0 ? platform : '').trim().toLowerCase();
9
9
  }
10
+ export function isPosTerminalPlatform(platform) {
11
+ var normalized = normalizeRuntimePlatform(platform);
12
+ return normalized === 'pos' || normalized === 'webpos';
13
+ }
10
14
 
11
15
  /**
12
16
  * PC and H5 are authenticated-customer clients rather than staff terminals.
@@ -1 +1,46 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _examples.BUY_X_GET_Y_FREE_STRATEGY;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _examples.ITEM_REWARD_STRATEGY;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "PromotionAdapter", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _adapter.PromotionAdapter;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "PromotionEvaluator", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _evaluator.PromotionEvaluator;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "default", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _adapter.default;
40
+ }
41
+ });
42
+ var _evaluator = require("./evaluator");
43
+ var _adapter = _interopRequireWildcard(require("./adapter"));
44
+ var _examples = require("./examples");
45
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
46
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -44,6 +44,10 @@ export interface ShopGetCustomerListParams {
44
44
  num?: number;
45
45
  /** 搜索关键词 */
46
46
  search?: string;
47
+ /** Full national phone number, without the international calling code. */
48
+ phone?: string;
49
+ /** Exact email lookup, independent from the generic search keyword. */
50
+ email?: string;
47
51
  /** 关联查询参数 */
48
52
  with?: CustomerWith[];
49
53
  /** wallet搜索标识 */
@@ -7,6 +7,7 @@ import { type PickupTimingBooking, type PickupTimingBookingInput } from './picku
7
7
  import { type ProductVoucherGroup } from './utils/productVoucherGroups';
8
8
  import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, ReplaceBookingProductWithRelatedRetailParams, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, OrderHooksConfig, OrderCartIntentCommitContext, ReplaceTempOrderOptions, HydrateTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, PointCardSnapshotMergeContext, PointCardSnapshotItem, ShopServiceData, ShopServiceType } from './types';
9
9
  import type { ICustomer } from '../AccountList/types';
10
+ import type { PaymentMethod } from '../Payment/types';
10
11
  import type { Discount } from '../Discount/types';
11
12
  import { UnavailableReason } from '../Rules/types';
12
13
  export declare class OrderModule extends BaseModule implements Module, OrderModuleAPI {
@@ -35,6 +36,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
35
36
  private moduleHooksOverride?;
36
37
  private orderHooks?;
37
38
  private cartCommandQueue;
39
+ private posVirtualPaymentRevision;
40
+ private posVirtualPaymentSnapshot?;
38
41
  private queueCartCommand;
39
42
  /** Use the exact Order normalizers/merge rules on a private draft, not a second projection. */
40
43
  private beginCartMutation;
@@ -477,6 +480,12 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
477
480
  */
478
481
  private hasLinkedBookingUid;
479
482
  private isMultiCurrencySettlementEnabled;
483
+ private requiresPosVirtualCurrencyPayment;
484
+ private getPosVirtualPaymentShopId;
485
+ syncPosVirtualCurrencyPaymentMethods(methods: readonly PaymentMethod[]): void;
486
+ getPosVirtualCurrencyPaymentMethod(initialMethods?: readonly PaymentMethod[]): PaymentMethod;
487
+ refreshPosVirtualCurrencyPaymentMethod(): Promise<PaymentMethod>;
488
+ private validatePosVirtualCurrencyCart;
480
489
  private isActiveVirtualSettlementOrder;
481
490
  private shouldUseVirtualSettlementSummary;
482
491
  private normalizeVirtualSettlementProductIfEnabled;
@@ -644,7 +653,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
644
653
  generateIdempotencyToken(): string;
645
654
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
646
655
  createOrder(params: CommitOrderParams['query']): {
647
- type: "virtual" | "appointment_booking";
656
+ type: "appointment_booking" | "virtual";
648
657
  platform: string;
649
658
  sales_channel: string;
650
659
  order_sales_channel: string;
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "isFulfillmentTimingBooking", {
11
11
  }
12
12
  });
13
13
  var _loadSalesOrderSnapshot = require("../../shared/sales/loadSalesOrderSnapshot");
14
+ var _bookingUuid = require("./utils/bookingUuid");
14
15
  var _localEftposState = require("./localEftposState");
15
16
  var _BaseModule = require("../BaseModule");
16
17
  var _types = require("./types");
@@ -34,6 +35,8 @@ var _bundleDiscountHydration = require("./utils/bundleDiscountHydration");
34
35
  var _orderCollectionIdentity = require("./utils/orderCollectionIdentity");
35
36
  var _discountProductLineIdentity = require("./utils/discountProductLineIdentity");
36
37
  var _virtualSettlement = require("./utils/virtualSettlement");
38
+ var _loadPaymentMethods = require("../../shared/payment/loadPaymentMethods");
39
+ var _platform = require("../../utils/platform");
37
40
  var _Discount = require("../Discount");
38
41
  var _Rules = require("../Rules");
39
42
  var _entitlementPass = require("../Discount/entitlementPass");
@@ -41,6 +44,19 @@ var _types2 = require("../Rules/types");
41
44
  var _decimal = _interopRequireDefault(require("decimal.js"));
42
45
  var _lodashEs = require("lodash-es");
43
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
+ const SUMMARY_LINE_FIELDS = ['tax_fee', 'original_tax_fee', 'tax_fee_rounding_remainder', 'original_tax_fee_rounding_remainder', 'surcharge_fee', 'surcharge_rounding_remainder', 'relation_surcharge_ids'];
48
+ const SUMMARY_LINE_METADATA_FIELDS = ['tax_fee_rounding_remainder', 'surcharge_rounding_remainder', 'relation_surcharge_ids'];
49
+ function getFixedGiftProductSnapshot(product) {
50
+ // 赠品预约等待期间,recalculateSummary 可以更新金额字段。赠品写回后会重新计算这些金额。
51
+ return {
52
+ ...(0, _lodashEs.omit)(product, [...SUMMARY_LINE_FIELDS, 'main_product_attached_bundle_tax_fee', 'main_product_attached_bundle_surcharge_fee', 'payment_price', 'deposit']),
53
+ metadata: (0, _lodashEs.omit)(product.metadata, [...SUMMARY_LINE_METADATA_FIELDS, 'main_product_attached_bundle_tax_fee', 'main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_selling_price', 'main_product_attached_bundle_payment_price', 'average_discount_amount_rate']),
54
+ product_bundle: Array.isArray(product.product_bundle) ? product.product_bundle.map(bundle => ({
55
+ ...(0, _lodashEs.omit)(bundle, [...SUMMARY_LINE_FIELDS, 'bundle_payment_price']),
56
+ metadata: (0, _lodashEs.omit)(bundle?.metadata, [...SUMMARY_LINE_METADATA_FIELDS, 'surcharge_fee'])
57
+ })) : product.product_bundle
58
+ };
59
+ }
44
60
  function normalizeDiscountListSignature(discountList) {
45
61
  return (discountList || []).map(item => ({
46
62
  type: item?.type ?? '',
@@ -154,6 +170,8 @@ class OrderModule extends _BaseModule.BaseModule {
154
170
  moduleHooksOverride;
155
171
  orderHooks;
156
172
  cartCommandQueue = Promise.resolve();
173
+ posVirtualPaymentRevision = 0;
174
+ posVirtualPaymentSnapshot;
157
175
  queueCartCommand(run) {
158
176
  if (!this.orderHooks?.onBeforeCartCommit && !this.store.tempOrder?._extend?.productVoucherGroups?.length) return run();
159
177
  const pending = this.cartCommandQueue.then(run, run);
@@ -1112,10 +1130,16 @@ class OrderModule extends _BaseModule.BaseModule {
1112
1130
  // 唯一候选也可能有规格/套餐。每次补赠都交给 SDK 判断,不能复用旧赠品的选择。
1113
1131
 
1114
1132
  const fixedGiftQuotas = addAction.giftQuotas;
1115
- const giftMutationBaseline = options?.isCurrentOrder || fixedGiftQuotas ? (0, _lodashEs.cloneDeep)({
1116
- products: tempOrder.products,
1117
- bookings: tempOrder.bookings
1118
- }) : null;
1133
+ const getGiftMutationState = () => ({
1134
+ products: fixedGiftQuotas ? tempOrder.products.map(getFixedGiftProductSnapshot) : tempOrder.products,
1135
+ bookings: tempOrder.bookings,
1136
+ ...(fixedGiftQuotas && {
1137
+ holderRelations: tempOrder.holder_relations,
1138
+ shopDiscount: tempOrder.shop_discount
1139
+ })
1140
+ });
1141
+ const giftMutationBaseline = options?.isCurrentOrder || fixedGiftQuotas ? (0, _lodashEs.cloneDeep)(getGiftMutationState()) : null;
1142
+ const isGiftDraftCurrent = () => isCurrentOrder() && (!giftMutationBaseline || (0, _lodashEs.isEqual)(getGiftMutationState(), giftMutationBaseline));
1119
1143
  try {
1120
1144
  const inventoryProducts = fixedGiftQuotas ? nextOrder.products : tempOrder.products;
1121
1145
  const giftResult = await giftSelectResolver({
@@ -1126,11 +1150,7 @@ class OrderModule extends _BaseModule.BaseModule {
1126
1150
  quantity: Number(line.num) || 0
1127
1151
  }))
1128
1152
  });
1129
- if (!isCurrentOrder()) return null;
1130
- if (giftMutationBaseline && !(0, _lodashEs.isEqual)({
1131
- products: tempOrder.products,
1132
- bookings: tempOrder.bookings
1133
- }, giftMutationBaseline)) return null;
1153
+ if (!isGiftDraftCurrent()) return null;
1134
1154
  const giftProducts = Array.isArray(giftResult) ? giftResult : giftResult?.products;
1135
1155
  const giftBookings = Array.isArray(giftResult) ? [] : giftResult?.bookings || [];
1136
1156
  if (Array.isArray(giftProducts) && giftProducts.length > 0) {
@@ -1179,11 +1199,7 @@ class OrderModule extends _BaseModule.BaseModule {
1179
1199
  publishGiftChanges();
1180
1200
  }
1181
1201
  } catch (error) {
1182
- if (!isCurrentOrder()) return null;
1183
- if (giftMutationBaseline && !(0, _lodashEs.isEqual)({
1184
- products: tempOrder.products,
1185
- bookings: tempOrder.bookings
1186
- }, giftMutationBaseline)) return null;
1202
+ if (!isGiftDraftCurrent()) return null;
1187
1203
  // 用户取消 / 选择失败 → 视为放弃本次新增
1188
1204
  console.warn('[OrderModule] giftSelectResolver rejected, skip add gift', addAction.strategyId, error);
1189
1205
  }
@@ -2655,7 +2671,7 @@ class OrderModule extends _BaseModule.BaseModule {
2655
2671
  booking_uid: bookingUid
2656
2672
  },
2657
2673
  booking: {
2658
- ...params.booking,
2674
+ ...(0, _bookingUuid.ensureBookingUuid)(params.booking),
2659
2675
  is_all: (0, _utils.normalizeBookingIsAll)(params.booking),
2660
2676
  product_uid: productUid,
2661
2677
  sub_type: (0, _utils.normalizeBookingSubType)(params.booking),
@@ -3270,7 +3286,7 @@ class OrderModule extends _BaseModule.BaseModule {
3270
3286
  const tempOrder = this.ensureTempOrder();
3271
3287
  const bookings = tempOrder.bookings || [];
3272
3288
  const firstIndex = bookings.findIndex(_pickupTiming.isFulfillmentTimingBooking);
3273
- const nextBooking = (0, _pickupTiming.buildPickupTimingBooking)(input, bookings[firstIndex]);
3289
+ const nextBooking = (0, _bookingUuid.ensureBookingUuid)((0, _pickupTiming.buildPickupTimingBooking)(input, bookings[firstIndex]));
3274
3290
  // Keep the first row's identity and position; repair duplicate marked rows only.
3275
3291
  tempOrder.bookings = firstIndex === -1 ? [...bookings, nextBooking] : bookings.flatMap((booking, index) => index === firstIndex ? [nextBooking] : (0, _pickupTiming.isFulfillmentTimingBooking)(booking) ? [] : [booking]);
3276
3292
  this.notifyTempOrderChanged();
@@ -3802,6 +3818,54 @@ class OrderModule extends _BaseModule.BaseModule {
3802
3818
  isMultiCurrencySettlementEnabled() {
3803
3819
  return this.otherParams?.enableMultiCurrencySettlement === true;
3804
3820
  }
3821
+ requiresPosVirtualCurrencyPayment(product) {
3822
+ return this.isMultiCurrencySettlementEnabled() && (0, _platform.isPosTerminalPlatform)(this.otherParams?.platform) && (0, _virtualSettlement.isVirtualSettlementProduct)(product);
3823
+ }
3824
+ getPosVirtualPaymentShopId() {
3825
+ return String(this.core?.context?.getData?.('shop_id') ?? '');
3826
+ }
3827
+ syncPosVirtualCurrencyPaymentMethods(methods) {
3828
+ const shopId = this.getPosVirtualPaymentShopId();
3829
+ const sourceShopId = methods.find(method => Number(method?.shop_id) > 0)?.shop_id;
3830
+ if (shopId && sourceShopId != null && String(sourceShopId) !== shopId) return;
3831
+ this.posVirtualPaymentSnapshot = {
3832
+ shopId,
3833
+ methods,
3834
+ revision: ++this.posVirtualPaymentRevision
3835
+ };
3836
+ }
3837
+ getPosVirtualCurrencyPaymentMethod(initialMethods = []) {
3838
+ const shopId = this.getPosVirtualPaymentShopId();
3839
+ const snapshot = this.posVirtualPaymentSnapshot;
3840
+ return (0, _loadPaymentMethods.requirePosVirtualCurrencyPaymentMethod)(snapshot?.shopId === shopId ? snapshot.methods : initialMethods, shopId);
3841
+ }
3842
+ async refreshPosVirtualCurrencyPaymentMethod() {
3843
+ const shopId = this.getPosVirtualPaymentShopId();
3844
+ const revision = ++this.posVirtualPaymentRevision;
3845
+ const methods = await (0, _loadPaymentMethods.loadPaymentMethods)(this.request, {
3846
+ transport: 'remote',
3847
+ filterPaymentMethods: false
3848
+ });
3849
+ if (shopId !== this.getPosVirtualPaymentShopId()) {
3850
+ throw new Error('[Order] Payment methods belong to a previous shop');
3851
+ }
3852
+ const snapshot = this.posVirtualPaymentSnapshot;
3853
+ // Slow reads must not overwrite a newer lookup or a payment methods sync event.
3854
+ if (snapshot?.shopId !== shopId || snapshot.revision < revision) {
3855
+ this.posVirtualPaymentSnapshot = {
3856
+ shopId,
3857
+ methods,
3858
+ revision
3859
+ };
3860
+ }
3861
+ return this.getPosVirtualCurrencyPaymentMethod();
3862
+ }
3863
+ async validatePosVirtualCurrencyCart(order) {
3864
+ await this.refreshPosVirtualCurrencyPaymentMethod();
3865
+ if (this.getTempOrder() !== order) {
3866
+ throw new Error('[Order] Cart intent belongs to a previous order or business');
3867
+ }
3868
+ }
3805
3869
  isActiveVirtualSettlementOrder(tempOrder) {
3806
3870
  return this.isMultiCurrencySettlementEnabled() && (0, _virtualSettlement.isVirtualSettlementOrder)(tempOrder);
3807
3871
  }
@@ -3922,6 +3986,16 @@ class OrderModule extends _BaseModule.BaseModule {
3922
3986
  * if (pending) await pending;
3923
3987
  */
3924
3988
  appendProductLineToTempOrder(tempOrder, product, booking, options) {
3989
+ const incomingBookingUuid = booking?.uuid;
3990
+ if (booking && incomingBookingUuid && tempOrder.bookings?.some(item => item.uuid === incomingBookingUuid)) {
3991
+ // Appending a copy creates a different booking; editing uses the update path below.
3992
+ booking = {
3993
+ ...booking,
3994
+ uuid: (0, _utils.createUuidV4)(),
3995
+ id: undefined,
3996
+ schedule_event_id: undefined
3997
+ };
3998
+ }
3925
3999
  const linked = booking ? this.createLinkedProductAndBooking({
3926
4000
  product,
3927
4001
  booking
@@ -4086,6 +4160,12 @@ class OrderModule extends _BaseModule.BaseModule {
4086
4160
  singleLine.num = 1;
4087
4161
  delete singleLine.product_quantity;
4088
4162
  const singleBooking = (0, _lodashEs.cloneDeep)(booking);
4163
+ if (index > 0) {
4164
+ // Both single-add and batch-add quantity splits create separate appointments.
4165
+ delete singleBooking.uuid;
4166
+ delete singleBooking.schedule_event_id;
4167
+ delete singleBooking.id;
4168
+ }
4089
4169
  const bookingHolder = booking?.holder && typeof booking.holder === 'object' ? booking.holder : null;
4090
4170
  const metadataHolder = booking?.metadata?.holder && typeof booking.metadata.holder === 'object' ? booking.metadata.holder : null;
4091
4171
  const rawHolderIds = bookingHolder?.form_record ?? booking?.metadata?.holder_id ?? metadataHolder?.form_record ?? product?.metadata?.holder_id;
@@ -4153,6 +4233,10 @@ class OrderModule extends _BaseModule.BaseModule {
4153
4233
  availabilityCommitGuard?.();
4154
4234
  const liveTempOrder = this.ensureTempOrder();
4155
4235
  const beforeCommit = this.createCartIntentCommitGuard('add_product', liveTempOrder);
4236
+ if (this.requiresPosVirtualCurrencyPayment(product)) {
4237
+ await this.validatePosVirtualCurrencyCart(liveTempOrder);
4238
+ availabilityCommitGuard?.();
4239
+ }
4156
4240
  const mutation = this.beginCartMutation();
4157
4241
  // 库存/商品券校验与自动预约共用草稿,全部门禁通过后才发布完整批次。
4158
4242
  const tempOrder = availabilityCommitGuard && !mutation.commit ? (0, _lodashEs.cloneDeep)(liveTempOrder) : mutation.draft;
@@ -4336,7 +4420,8 @@ class OrderModule extends _BaseModule.BaseModule {
4336
4420
  const target = live.products[targetIndex];
4337
4421
  const scopeKey = String(target?.metadata?.venue_booking_scope_key || '');
4338
4422
  const targetBookingUid = String(target?.booking_uid || target?.metadata?.booking_uid || '');
4339
- if (!uid || !target || !scopeKey || live.order_id || target.order_detail_id != null || Number(target.num) !== 1 || Number(params.product.num ?? 1) !== 1 || target.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_scope_key !== scopeKey || !Array.isArray(params.relatedRetailProducts) || (live.payments || []).length > 0 || !targetBookingUid || String(params.booking.metadata?.unique_identification_number || '') !== targetBookingUid || (live.bookings || []).filter(booking => this.getBookingUniqueIdentificationNumber(booking) === targetBookingUid).length !== 1 || live.products.filter(line => line.metadata?.venue_booking_role === 'party_main' && line.metadata?.venue_booking_scope_key === scopeKey).length !== 1) {
4423
+ const targetBookings = (live.bookings || []).filter(row => this.getBookingUniqueIdentificationNumber(row) === targetBookingUid);
4424
+ if (!uid || !target || !scopeKey || live.order_id || target.order_detail_id != null || Number(target.num) !== 1 || Number(params.product.num ?? 1) !== 1 || target.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_scope_key !== scopeKey || !Array.isArray(params.relatedRetailProducts) || (live.payments || []).length > 0 || !targetBookingUid || String(params.booking.metadata?.unique_identification_number || '') !== targetBookingUid || targetBookings.length !== 1 || live.products.filter(line => line.metadata?.venue_booking_role === 'party_main' && line.metadata?.venue_booking_scope_key === scopeKey).length !== 1) {
4340
4425
  throw new Error('[Order] Party replacement requires one unsubmitted, unpaid main booking in the same scope');
4341
4426
  }
4342
4427
  const children = live.products.filter(line => line.metadata?.venue_booking_role === 'party_extra' && String(line.metadata?.venue_booking_parent_uid || '') === uid);
@@ -4396,7 +4481,9 @@ class OrderModule extends _BaseModule.BaseModule {
4396
4481
  venue_booking_service_datetime: serviceDatetime
4397
4482
  };
4398
4483
  replacement.unique_identification_number = uid;
4399
- await this.appendProductLineToTempOrder(draft, replacement, (0, _lodashEs.cloneDeep)(params.booking), {
4484
+ const replacementBooking = (0, _lodashEs.cloneDeep)(params.booking);
4485
+ replacementBooking.uuid = targetBookings[0].uuid || replacementBooking.uuid;
4486
+ await this.appendProductLineToTempOrder(draft, replacement, replacementBooking, {
4400
4487
  insertAtIndex: targetIndex,
4401
4488
  disableMerge: true,
4402
4489
  beforeCommit
@@ -4463,6 +4550,11 @@ class OrderModule extends _BaseModule.BaseModule {
4463
4550
  if (!Array.isArray(items) || items.length === 0) return tempOrder.products;
4464
4551
  const beforeCommit = this.createCartIntentCommitGuard('add_product');
4465
4552
  const beforeAppend = mutation.commit ? undefined : beforeCommit;
4553
+ if (items.some(({
4554
+ product
4555
+ }) => product && this.requiresPosVirtualCurrencyPayment(product))) {
4556
+ await this.validatePosVirtualCurrencyCart(this.ensureTempOrder());
4557
+ }
4466
4558
  for (const item of items || []) {
4467
4559
  const {
4468
4560
  product,
@@ -4804,12 +4896,22 @@ class OrderModule extends _BaseModule.BaseModule {
4804
4896
  ...(normalizedProduct.metadata || {}),
4805
4897
  unique_identification_number: productUid
4806
4898
  };
4899
+ const originalBookingUid = targetProduct.booking_uid || targetProduct.metadata?.booking_uid || preservedBookingUid;
4900
+ const bookings = tempOrder.bookings || [];
4901
+ const eventId = booking.schedule_event_id;
4902
+ const originalBooking = bookings.find(row => Number(eventId) > 0 && String(row.schedule_event_id) === String(eventId)) ?? bookings.find(row => originalBookingUid && row.metadata?.unique_identification_number === originalBookingUid);
4903
+ const {
4904
+ uuid: incomingUuid = originalBooking?.uuid
4905
+ } = booking;
4807
4906
  const linked = this.createLinkedProductAndBooking({
4808
4907
  product: {
4809
4908
  ...normalizedProduct,
4810
4909
  unique_identification_number: productUid
4811
4910
  },
4812
- booking
4911
+ booking: {
4912
+ ...booking,
4913
+ uuid: originalBooking?.uuid || incomingUuid
4914
+ }
4813
4915
  });
4814
4916
  this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
4815
4917
  normalizedProduct = {
@@ -5026,6 +5128,17 @@ class OrderModule extends _BaseModule.BaseModule {
5026
5128
  }
5027
5129
  }
5028
5130
  const beforeCommit = normalizedProduct.num > targetProduct.num ? this.createCartIntentCommitGuard('increase_quantity') : undefined;
5131
+ if (beforeCommit && this.requiresPosVirtualCurrencyPayment(normalizedProduct)) {
5132
+ const liveOrder = this.ensureTempOrder();
5133
+ const products = (0, _lodashEs.cloneDeep)(liveOrder.products);
5134
+ const customerId = liveOrder.customer_id;
5135
+ await this.validatePosVirtualCurrencyCart(liveOrder);
5136
+ if (liveOrder.customer_id !== customerId || !(0, _lodashEs.isEqual)(liveOrder.products, products)) {
5137
+ throw Object.assign(new Error('The cart changed. Please try again.'), {
5138
+ code: 'SALES_GUARD_REJECTED'
5139
+ });
5140
+ }
5141
+ }
5029
5142
  if (!mutation.commit) beforeCommit?.();
5030
5143
  if (isCurrentOrder && !isCurrentOrder()) return tempOrder.products;
5031
5144
  tempOrder.products[productIndex] = normalizedProduct;
@@ -5071,9 +5184,13 @@ class OrderModule extends _BaseModule.BaseModule {
5071
5184
  throw new Error('[Order] 目标 booking 不存在,无法更新');
5072
5185
  }
5073
5186
  const targetBooking = tempOrder.bookings[bookingIndex] || {};
5187
+ const {
5188
+ uuid: incomingUuid = targetBooking.uuid
5189
+ } = updates;
5074
5190
  const nextBooking = {
5075
5191
  ...targetBooking,
5076
5192
  ...updates,
5193
+ uuid: targetBooking.uuid || incomingUuid,
5077
5194
  metadata: {
5078
5195
  ...(targetBooking.metadata || {}),
5079
5196
  ...(updates.metadata || {}),
@@ -5083,6 +5200,7 @@ class OrderModule extends _BaseModule.BaseModule {
5083
5200
  unique_identification_number: bookingUid
5084
5201
  }
5085
5202
  };
5203
+ (0, _bookingUuid.assignBookingUuid)(nextBooking);
5086
5204
  this.syncBookingMetadataHolder(nextBooking, nextBooking.metadata);
5087
5205
  nextBooking.is_all = (0, _utils.normalizeBookingIsAll)(nextBooking);
5088
5206
  nextBooking.sub_type = (0, _utils.normalizeBookingSubType)(nextBooking);
@@ -5784,6 +5902,7 @@ class OrderModule extends _BaseModule.BaseModule {
5784
5902
  * @returns 后端返回的订单数据(包含订单ID等)
5785
5903
  */
5786
5904
  async createOrderByCheckout(params) {
5905
+ params.bookings?.forEach(_bookingUuid.assignBookingUuid);
5787
5906
  // 过滤掉由在线店铺下单的 payment 支付数据
5788
5907
  const onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
5789
5908
  params.payments = params.payments?.filter(p => !onlineStorePaymentCodeList.includes(p.code));
@@ -5871,6 +5990,7 @@ class OrderModule extends _BaseModule.BaseModule {
5871
5990
  url,
5872
5991
  query
5873
5992
  } = params;
5993
+ query.bookings?.forEach(_bookingUuid.assignBookingUuid);
5874
5994
  const fetchUrl = url || '/order/sales/checkout';
5875
5995
  const handledByOsServer = this.isSalesCheckoutHandledByOsServer(fetchUrl);
5876
5996
  const requestQuery = handledByOsServer ? query : (0, _localEftposState.stripLocalEftposState)((0, _osPrivatePayload.stripOsPrivatePayloadFields)(query));
@@ -6225,8 +6345,9 @@ class OrderModule extends _BaseModule.BaseModule {
6225
6345
  })) : [];
6226
6346
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(b => {
6227
6347
  const booking = this.normalizeHydratedBookingHolder(b || {});
6348
+ const submitted = (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || Number(booking.parent_id) !== 0;
6228
6349
  return {
6229
- ...booking,
6350
+ ...(submitted ? (0, _bookingUuid.ensureBookingUuid)(booking) : booking),
6230
6351
  is_all: (0, _utils.normalizeBookingIsAll)(booking),
6231
6352
  sub_type: (0, _utils.normalizeBookingSubType)(booking)
6232
6353
  };
@@ -419,6 +419,7 @@ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'p
419
419
  products: OrderSubmitProduct[];
420
420
  notes?: SalesNoteProtocol[];
421
421
  summary?: OrderSummary;
422
+ product_tax_fee?: string;
422
423
  small_ticket_data_flag?: number;
423
424
  }
424
425
  export interface OrderState {
@@ -596,6 +597,8 @@ export interface CommitOrderParams {
596
597
  };
597
598
  }
598
599
  export interface OrderSubmitBooking {
600
+ /** Stable booking identity, created once and shared with external allocations. */
601
+ uuid?: string | null;
599
602
  relation_id?: string;
600
603
  form_id?: string;
601
604
  collect_pax?: number;
@@ -0,0 +1,4 @@
1
+ /** Cross-system booking identity; independent from the legacy cart-line UID. */
2
+ export declare function ensureBookingUuid<T extends Record<string, any>>(booking: T): T;
3
+ /** Retain a generated UUID on the draft so a checkout retry sends the same value. */
4
+ export declare function assignBookingUuid(booking: Record<string, any> | null | undefined): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignBookingUuid = assignBookingUuid;
7
+ exports.ensureBookingUuid = ensureBookingUuid;
8
+ var _orderCollectionIdentity = require("./orderCollectionIdentity");
9
+ /** Cross-system booking identity; independent from the legacy cart-line UID. */
10
+ function ensureBookingUuid(booking) {
11
+ if (booking.uuid) return booking;
12
+ // Only an explicit null confirms that an existing booking needs a UUID when saved.
13
+ if (booking.uuid !== null && Number(booking.schedule_event_id || booking.id) > 0) return booking;
14
+ return {
15
+ ...booking,
16
+ uuid: (0, _orderCollectionIdentity.createUuidV4)()
17
+ };
18
+ }
19
+
20
+ /** Retain a generated UUID on the draft so a checkout retry sends the same value. */
21
+ function assignBookingUuid(booking) {
22
+ if (!booking) return;
23
+ const resolved = ensureBookingUuid(booking);
24
+ if (resolved !== booking) booking.uuid = resolved.uuid;
25
+ }
@@ -36,6 +36,10 @@ export declare class VirtualCurrencyBalanceError extends Error {
36
36
  readonly code = "VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT";
37
37
  constructor(balance: string, requiredAmount: string);
38
38
  }
39
+ export declare class VirtualCurrencyCustomerRequiredError extends Error {
40
+ readonly code = "VIRTUAL_CURRENCY_CUSTOMER_REQUIRED";
41
+ constructor();
42
+ }
39
43
  export declare function getSelectedSettlementSnapshot(product: Partial<OrderProduct> | null | undefined): SelectedSettlementSnapshot | null;
40
44
  export declare function getTempOrderSettlementSnapshot(tempOrder: OrderTempOrder | null | undefined): SelectedSettlementSnapshot | null;
41
45
  export declare function isVirtualSettlementProduct(product: Partial<OrderProduct> | null | undefined): boolean;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VirtualCurrencyBalanceError = exports.VirtualCurrencyAssetNotFoundError = exports.OrderSettlementConflictError = void 0;
6
+ exports.VirtualCurrencyCustomerRequiredError = exports.VirtualCurrencyBalanceError = exports.VirtualCurrencyAssetNotFoundError = exports.OrderSettlementConflictError = void 0;
7
7
  exports.applyTempOrderSettlementState = applyTempOrderSettlementState;
8
8
  exports.buildCurrencyDisplaySnapshot = buildCurrencyDisplaySnapshot;
9
9
  exports.getSelectedSettlementSnapshot = getSelectedSettlementSnapshot;
@@ -64,6 +64,14 @@ class VirtualCurrencyBalanceError extends Error {
64
64
  }
65
65
  }
66
66
  exports.VirtualCurrencyBalanceError = VirtualCurrencyBalanceError;
67
+ class VirtualCurrencyCustomerRequiredError extends Error {
68
+ code = 'VIRTUAL_CURRENCY_CUSTOMER_REQUIRED';
69
+ constructor() {
70
+ super('Select a customer before paying with virtual currency.');
71
+ this.name = 'VirtualCurrencyCustomerRequiredError';
72
+ }
73
+ }
74
+ exports.VirtualCurrencyCustomerRequiredError = VirtualCurrencyCustomerRequiredError;
67
75
  function getSelectedSettlementSnapshot(product) {
68
76
  const snapshot = product?.metadata?.selected_settlement_snapshot;
69
77
  if (!snapshot || typeof snapshot !== 'object') return null;
@@ -138,8 +138,10 @@ var _decimal = _interopRequireDefault(require("decimal.js"));
138
138
  var _weighedProduct = require("./utils/weighedProduct");
139
139
  var _manualProductDiscount = require("./utils/manualProductDiscount");
140
140
  var _utils = require("../Holder/utils");
141
+ var _platform = require("../../utils/platform");
141
142
  var _utils2 = require("../../solution/ScanOrder/utils");
142
143
  var _orderCollectionIdentity = require("./utils/orderCollectionIdentity");
144
+ var _bookingUuid = require("./utils/bookingUuid");
143
145
  var _salesNotes = require("./salesNotes");
144
146
  var _pickupTiming = require("./pickupTiming");
145
147
  var _holderRelations = require("./holderRelations");
@@ -1664,7 +1666,10 @@ function buildSubmitPayload(params) {
1664
1666
  delivery_type: tempOrder.delivery_type || 'shop_service',
1665
1667
  schedule_date: scheduleDate,
1666
1668
  // created_at: tempOrder.created_at || formatDateTime(now), 和后端协定这个字段先不提交到接口
1667
- bookings: (tempOrder.bookings || []).filter(booking => (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || Number(booking.parent_id) !== 0).map(booking => normalizeSubmitBooking(booking)),
1669
+ bookings: (tempOrder.bookings || []).filter(booking => (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || Number(booking.parent_id) !== 0).map(booking => {
1670
+ (0, _bookingUuid.assignBookingUuid)(booking);
1671
+ return normalizeSubmitBooking(booking);
1672
+ }),
1668
1673
  payments: tempOrder.payments || [],
1669
1674
  relation_forms: tempOrder.relation_forms || [],
1670
1675
  // contacts: tempOrder.contacts || [],
@@ -1696,15 +1701,18 @@ function buildSubmitPayload(params) {
1696
1701
  order_meta_list: normalizedOrderMetaList
1697
1702
  } : {})
1698
1703
  };
1699
- if (!enhance) return payload;
1700
- const enhancedPayload = enhance(payload, {
1704
+ const enhancedPayload = enhance?.(payload, {
1701
1705
  tempOrder,
1702
1706
  bookingUuid,
1703
1707
  now
1704
- });
1708
+ }) ?? payload;
1709
+ const submitSummary = enhancedPayload.summary ?? payload.summary;
1705
1710
  return {
1706
1711
  ...enhancedPayload,
1707
- summary: enhancedPayload.summary ?? payload.summary
1712
+ summary: submitSummary,
1713
+ ...((0, _platform.isPosTerminalPlatform)(enhancedPayload.platform) ? {
1714
+ product_tax_fee: virtualSettlementMode ? '0.00' : submitSummary?.tax_fee ?? '0.00'
1715
+ } : {})
1708
1716
  };
1709
1717
  }
1710
1718
  function mapPaymentItemToOrderPayment(paymentItem) {
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "normal" | "session";
53
53
  }
@@ -1,9 +1,12 @@
1
1
  import type { RequestPlugin } from '../../plugins/request';
2
2
  import type { PaymentMethod } from '../../modules/Payment/types';
3
+ type PaymentMethodsTransport = 'remote' | 'os-server';
3
4
  /** Shared read-only transport; customer hosts route the remote path under /h5. */
4
5
  export declare function loadPaymentMethods(request: RequestPlugin, options: {
5
- transport: 'remote' | 'os-server';
6
+ transport: PaymentMethodsTransport;
6
7
  filterPaymentMethods: boolean;
7
8
  }): Promise<PaymentMethod[]>;
9
+ export declare function requirePosVirtualCurrencyPaymentMethod(methods: readonly PaymentMethod[], shopId?: string): PaymentMethod;
8
10
  /** Enrich a copy: never overwrite historical names or change payment amounts. */
9
11
  export declare function withPaymentMethodNames(order: Record<string, any>, methods: PaymentMethod[]): Record<string, any>;
12
+ export {};
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.loadPaymentMethods = loadPaymentMethods;
7
+ exports.requirePosVirtualCurrencyPaymentMethod = requirePosVirtualCurrencyPaymentMethod;
7
8
  exports.withPaymentMethodNames = withPaymentMethodNames;
8
9
  /** Shared read-only transport; customer hosts route the remote path under /h5. */
9
10
  async function loadPaymentMethods(request, options) {
@@ -19,6 +20,18 @@ async function loadPaymentMethods(request, options) {
19
20
  if (!Array.isArray(methods)) throw new Error('Payment methods are unavailable');
20
21
  return methods;
21
22
  }
23
+ class PosVirtualCurrencyPaymentUnavailableError extends Error {
24
+ code = 'POS_VIRTUAL_CURRENCY_PAYMENT_UNAVAILABLE';
25
+ constructor() {
26
+ super('Virtual currency payment is not enabled on this POS.');
27
+ this.name = 'PosVirtualCurrencyPaymentUnavailableError';
28
+ }
29
+ }
30
+ function requirePosVirtualCurrencyPaymentMethod(methods, shopId) {
31
+ const method = methods.find(candidate => candidate?.code === 'VIRTUALCURRENCY' && (!shopId || candidate.shop_id == null || String(candidate.shop_id) === shopId) && candidate.status === 1 && candidate.disable === 0 && Array.isArray(candidate.channel_application) && candidate.channel_application.includes('pos'));
32
+ if (!method) throw new PosVirtualCurrencyPaymentUnavailableError();
33
+ return method;
34
+ }
22
35
 
23
36
  /** Enrich a copy: never overwrite historical names or change payment amounts. */
24
37
  function withPaymentMethodNames(order, methods) {
@@ -503,6 +503,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
503
503
  getPaymentMethodsAsync(): Promise<PaymentMethod[]>;
504
504
  /** 同步读取初始化时缓存的支付方式列表。 */
505
505
  getPaymentMethods(): PaymentMethod[];
506
+ hasPosVirtualCurrencyPaymentMethod(): Promise<boolean>;
506
507
  private findCashPaymentMethod;
507
508
  private getPendingWalletPaymentAmount;
508
509
  /** 读取现金 action 所需的支付方式、待付金额和快捷金额。 */