@pisell/pisellos 2.3.33 → 2.3.35

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 (33) hide show
  1. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  2. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  3. package/dist/modules/Order/index.d.ts +1 -1
  4. package/dist/modules/Order/index.js +84 -34
  5. package/dist/modules/Order/payment-utils.d.ts +3 -0
  6. package/dist/modules/Order/payment-utils.js +25 -3
  7. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  8. package/dist/server/index.d.ts +2 -0
  9. package/dist/server/index.js +73 -10
  10. package/dist/server/modules/order/index.d.ts +4 -1
  11. package/dist/server/modules/order/index.js +108 -18
  12. package/dist/solution/BaseSales/index.js +10 -1
  13. package/dist/solution/BaseSales/utils/cartPromotion.js +19 -7
  14. package/dist/solution/BookingByStep/index.d.ts +1 -1
  15. package/dist/solution/Sales/index.d.ts +1 -0
  16. package/dist/solution/Sales/index.js +10 -2
  17. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  18. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  19. package/lib/modules/Order/index.d.ts +1 -1
  20. package/lib/modules/Order/index.js +75 -11
  21. package/lib/modules/Order/payment-utils.d.ts +3 -0
  22. package/lib/modules/Order/payment-utils.js +33 -2
  23. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  24. package/lib/server/index.d.ts +2 -0
  25. package/lib/server/index.js +60 -10
  26. package/lib/server/modules/order/index.d.ts +4 -1
  27. package/lib/server/modules/order/index.js +89 -10
  28. package/lib/solution/BaseSales/index.js +9 -0
  29. package/lib/solution/BaseSales/utils/cartPromotion.js +13 -1
  30. package/lib/solution/BookingByStep/index.d.ts +1 -1
  31. package/lib/solution/Sales/index.d.ts +1 -0
  32. package/lib/solution/Sales/index.js +5 -3
  33. package/package.json +1 -1
@@ -48,7 +48,7 @@ export interface BookingResourceInput {
48
48
  capacity?: number;
49
49
  like_status?: string;
50
50
  metadata?: Record<string, any>;
51
- children?: any[];
51
+ children?: BookingResourceInput[];
52
52
  }
53
53
  /** custom / package 人数维度快照,与 info2 `_extend.capacity` / `metadata.capacity` 对齐。 */
54
54
  export interface BookingCapacityMetadataItem {
@@ -76,6 +76,33 @@ function resolveDurationMinutes(value) {
76
76
  return Number.isNaN(n) ? undefined : n;
77
77
  }
78
78
 
79
+ /**
80
+ * 将组合资源子项收敛为 checkout resources 协议。
81
+ *
82
+ * resourcesOriginMap 中的子资源是 UI 运行态结构,通常只有 id / main_field / form_id,
83
+ * 不保证携带后端必填的 relation_type。这里不能原样透传,否则会触发
84
+ * `bookings.*.resources.*.children.*.relation_type` 校验错误。
85
+ */
86
+ function normalizeChildResource(child, parentFormId) {
87
+ var _child$form_id, _child$relation_id;
88
+ var item = {
89
+ form_id: (_child$form_id = child === null || child === void 0 ? void 0 : child.form_id) !== null && _child$form_id !== void 0 ? _child$form_id : parentFormId,
90
+ relation_type: (child === null || child === void 0 ? void 0 : child.relation_type) || 'form',
91
+ relation_id: (_child$relation_id = child === null || child === void 0 ? void 0 : child.relation_id) !== null && _child$relation_id !== void 0 ? _child$relation_id : child === null || child === void 0 ? void 0 : child.id,
92
+ capacity: child === null || child === void 0 ? void 0 : child.capacity,
93
+ like_status: (child === null || child === void 0 ? void 0 : child.like_status) || 'common'
94
+ };
95
+ if ((child === null || child === void 0 ? void 0 : child.metadata) !== undefined) {
96
+ item.metadata = _objectSpread({}, child.metadata);
97
+ }
98
+ if (Array.isArray(child === null || child === void 0 ? void 0 : child.children)) {
99
+ item.children = child.children.map(function (nestedChild) {
100
+ return normalizeChildResource(nestedChild, item.form_id);
101
+ });
102
+ }
103
+ return item;
104
+ }
105
+
79
106
  /**
80
107
  * cacheItem._extend.resource 形如 `{ [form_id]: [{ relation_id, form_id, like_status, metadata, children }] }`。
81
108
  * 这里扁平化为符合协议的 resources[] 数组;id=0 的「无资源」占位行**保留**(与 info2 业务等价;协议 `relation_id=0` 合法)。
@@ -101,7 +128,11 @@ function flattenResources(cacheItem) {
101
128
  // 协议允许 metadata 自由透传;为了与 info2 行为等价,把 form_name / resource_name / combined_resource 一并保留。
102
129
  item.metadata = _objectSpread({}, r.metadata);
103
130
  }
104
- if ((r === null || r === void 0 ? void 0 : r.children) !== undefined) item.children = r.children;
131
+ if (Array.isArray(r === null || r === void 0 ? void 0 : r.children)) {
132
+ item.children = r.children.map(function (child) {
133
+ return normalizeChildResource(child, item.form_id);
134
+ });
135
+ }
105
136
  result.push(item);
106
137
  });
107
138
  });
@@ -485,7 +485,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
485
485
  generateIdempotencyToken(): string;
486
486
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
487
487
  createOrder(params: CommitOrderParams['query']): {
488
- type: "appointment_booking" | "virtual";
488
+ type: "virtual" | "appointment_booking";
489
489
  platform: string;
490
490
  sales_channel: string;
491
491
  order_sales_channel: string;
@@ -3852,9 +3852,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3852
3852
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3853
3853
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3854
3854
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3855
+ var _item$metadata3;
3855
3856
  if (_this26.hasGoodPassDiscount(item)) return false;
3856
3857
  if (_this26.hasOrderProductLineNote(item)) return false;
3857
3858
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3859
+ if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3858
3860
  if (item.product_id !== productToAdd.product_id) return false;
3859
3861
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
3860
3862
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -4177,7 +4179,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4177
4179
  }, {
4178
4180
  key: "applyOrderProductUpdateToTempOrder",
4179
4181
  value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
4180
- var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p, _tempOrder$products$p2;
4182
+ var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata, _targetProduct$metada15, _tempOrder$products$p, _tempOrder$products$p2;
4181
4183
  var product_id = params.product_id,
4182
4184
  product_variant_id = params.product_variant_id,
4183
4185
  updates = params.updates,
@@ -4205,8 +4207,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4205
4207
  if (unique_identification_number !== undefined) {
4206
4208
  var targetUid = String(unique_identification_number);
4207
4209
  productIndex = tempOrder.products.findIndex(function (item) {
4208
- var _item$metadata3;
4209
- return String(((_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4210
+ var _item$metadata4;
4211
+ return String(((_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4210
4212
  });
4211
4213
  }
4212
4214
  if (productIndex === -1) {
@@ -4237,9 +4239,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4237
4239
  // 如果 caller 走推荐路径(updates.metadata.* 显式指定主价),保留 metadata 由 normalize 认它。
4238
4240
  var callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
4239
4241
  var callerUpdatesMainMeta = (updates === null || updates === void 0 || (_metadata2 = updates.metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.main_product_selling_price) !== undefined || (updates === null || updates === void 0 || (_metadata3 = updates.metadata) === null || _metadata3 === void 0 ? void 0 : _metadata3.main_product_original_price) !== undefined || (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.source_product_price) !== undefined;
4242
+ var callerUpdatesSourcePrice = (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.source_product_price) !== undefined;
4243
+ var callerUpdatesMainSellingPrice = (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.main_product_selling_price) !== undefined;
4244
+ var callerUpdatesMainOriginalPrice = (updates === null || updates === void 0 || (_metadata7 = updates.metadata) === null || _metadata7 === void 0 ? void 0 : _metadata7.main_product_original_price) !== undefined;
4245
+ var previousLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(targetProduct), targetProduct.product_bundle);
4246
+ var nextLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(nextProduct), nextProduct.product_bundle);
4247
+ var callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
4248
+ var callerChangesLineConfiguration = callerChangesVariant || previousLineFingerprint !== nextLineFingerprint;
4240
4249
  var isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
4241
4250
  var callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
4242
- var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata7 = updates.metadata) === null || _metadata7 === void 0 ? void 0 : _metadata7.product_discount_reason) !== undefined || callerChangesDiscountList;
4251
+ var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata8 = updates.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata9 = updates.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata10 = updates.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_discount_reason) !== undefined || callerChangesDiscountList;
4243
4252
  var callerAllowsBookingReprice = function () {
4244
4253
  if (params.allow_booking_reprice !== true || !booking || !callerUpdatesTopPrice || !callerUpdatesMainMeta) {
4245
4254
  return false;
@@ -4252,7 +4261,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4252
4261
  };
4253
4262
  return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
4254
4263
  }();
4255
- if (isPersistedOrderLine && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
4264
+ if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
4256
4265
  var _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, _targetProduct$metada7;
4257
4266
  nextProduct.selling_price = targetProduct.selling_price;
4258
4267
  nextProduct.original_price = targetProduct.original_price;
@@ -4264,19 +4273,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4264
4273
  price_schema_version: (_targetProduct$metada6 = (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.price_schema_version) !== null && _targetProduct$metada6 !== void 0 ? _targetProduct$metada6 : 2
4265
4274
  });
4266
4275
  nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
4267
- } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4276
+ } else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
4277
+ var _targetProduct$metada8, _targetProduct$metada9;
4278
+ // 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
4279
+ // 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
4280
+ var previousMainOriginal = new Decimal(Number((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_original_price) || 0);
4281
+ var previousMainSelling = new Decimal(Number((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_selling_price) || previousMainOriginal.toNumber());
4282
+ var preservedDiscount = previousMainOriginal.minus(previousMainSelling);
4283
+ var nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
4284
+ nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
4285
+ source_product_price: String(updates.metadata.source_product_price),
4286
+ main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : nextMainOriginal.toDecimalPlaces(2).toFixed(2),
4287
+ main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
4288
+ price_schema_version: 2
4289
+ });
4290
+ } else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4291
+ // variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
4292
+ // 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
4293
+ // 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
4268
4294
  var existedMeta = nextProduct.metadata || {};
4269
4295
  nextProduct.metadata = _objectSpread({}, existedMeta);
4270
4296
  delete nextProduct.metadata.source_product_price;
4271
4297
  delete nextProduct.metadata.main_product_selling_price;
4272
4298
  delete nextProduct.metadata.main_product_original_price;
4273
4299
  delete nextProduct.metadata.price_schema_version;
4300
+ } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4301
+ var _ref68, _targetProduct$metada10, _targetProduct$metada11, _ref69, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4302
+ // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
4303
+ // 但必须让 original 与 selling 一起随新的 option 金额移动。
4304
+ var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
4305
+ var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
4306
+ var _previousMainOriginal = new Decimal(Number((_ref68 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref68 !== void 0 ? _ref68 : 0) || 0);
4307
+ var _previousMainSelling = new Decimal(Number((_ref69 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref69 !== void 0 ? _ref69 : _previousMainOriginal.toNumber()) || 0);
4308
+ var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
4309
+ var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
4310
+ var _nextMainOriginal = previousSource.plus(nextOptionSum);
4311
+ nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
4312
+ source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
4313
+ main_product_original_price: _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
4314
+ main_product_selling_price: _nextMainOriginal.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
4315
+ price_schema_version: 2
4316
+ });
4317
+ } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4318
+ var _existedMeta = nextProduct.metadata || {};
4319
+ nextProduct.metadata = _objectSpread({}, _existedMeta);
4320
+ delete nextProduct.metadata.source_product_price;
4321
+ delete nextProduct.metadata.main_product_selling_price;
4322
+ delete nextProduct.metadata.main_product_original_price;
4323
+ delete nextProduct.metadata.price_schema_version;
4274
4324
  }
4275
4325
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
4276
4326
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
4277
4327
  var normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
4278
4328
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4279
- var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.booking_uid);
4329
+ var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada15 = targetProduct.metadata) === null || _targetProduct$metada15 === void 0 ? void 0 : _targetProduct$metada15.booking_uid);
4280
4330
  if (!booking && preservedBookingUid) {
4281
4331
  normalizedProduct.booking_uid = preservedBookingUid;
4282
4332
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
@@ -4284,8 +4334,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4284
4334
  });
4285
4335
  }
4286
4336
  if (booking) {
4287
- var _normalizedProduct$me, _targetProduct$metada9;
4288
- var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number || createUuidV4());
4337
+ var _normalizedProduct$me, _targetProduct$metada16;
4338
+ var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.unique_identification_number) || unique_identification_number || createUuidV4());
4289
4339
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
4290
4340
  unique_identification_number: productUid
4291
4341
  });
@@ -4396,7 +4446,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4396
4446
  key: "updateOrderProductQuantity",
4397
4447
  value: function () {
4398
4448
  var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4399
- var _targetProduct$metada10;
4449
+ var _targetProduct$metada17;
4400
4450
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4401
4451
  return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4402
4452
  while (1) switch (_context27.prev = _context27.next) {
@@ -4420,8 +4470,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4420
4470
  if (unique_identification_number !== undefined) {
4421
4471
  targetUid = String(unique_identification_number);
4422
4472
  productIndex = tempOrder.products.findIndex(function (item) {
4423
- var _item$metadata4;
4424
- return String(((_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4473
+ var _item$metadata5;
4474
+ return String(((_item$metadata5 = item.metadata) === null || _item$metadata5 === void 0 ? void 0 : _item$metadata5.unique_identification_number) || item.unique_identification_number || '') === targetUid;
4425
4475
  });
4426
4476
  }
4427
4477
  if (productIndex === -1) {
@@ -4437,7 +4487,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4437
4487
  normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4438
4488
  num: getSafeProductNum(num),
4439
4489
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
4440
- unique_identification_number: ((_targetProduct$metada10 = targetProduct.metadata) === null || _targetProduct$metada10 === void 0 ? void 0 : _targetProduct$metada10.unique_identification_number) || unique_identification_number
4490
+ unique_identification_number: ((_targetProduct$metada17 = targetProduct.metadata) === null || _targetProduct$metada17 === void 0 ? void 0 : _targetProduct$metada17.unique_identification_number) || unique_identification_number
4441
4491
  })
4442
4492
  }));
4443
4493
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
@@ -4579,15 +4629,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4579
4629
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4580
4630
  _context30.prev = 11;
4581
4631
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4582
- var _metadata8, _metadata9, _metadata10, _metadata11;
4632
+ var _metadata11, _metadata12, _metadata13, _metadata14;
4583
4633
  var product, productUid, productBookingUid, isAddTimeProduct;
4584
4634
  return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4585
4635
  while (1) switch (_context29.prev = _context29.next) {
4586
4636
  case 0:
4587
4637
  product = _step21.value;
4588
- productUid = (product === null || product === void 0 || (_metadata8 = product.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4589
- productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata9 = product.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.booking_uid);
4590
- isAddTimeProduct = (product === null || product === void 0 || (_metadata10 = product.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.product_add_schedule_time) !== null;
4638
+ productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4639
+ productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
4640
+ isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
4591
4641
  if (!isAddTimeProduct) {
4592
4642
  _context29.next = 6;
4593
4643
  break;
@@ -4734,23 +4784,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4734
4784
  }, {
4735
4785
  key: "buildCurrentSubmitPayloadForLocalPrint",
4736
4786
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
4737
- var _params$cacheId, _this$otherParams3, _ref68, _params$businessCode, _this$otherParams4, _this$otherParams5;
4787
+ var _params$cacheId, _this$otherParams3, _ref70, _params$businessCode, _this$otherParams4, _this$otherParams5;
4738
4788
  var tempOrder = this.ensureTempOrder();
4739
4789
  this.persistTempOrder();
4740
4790
  var payload = buildSubmitPayload({
4741
4791
  tempOrder: tempOrder,
4742
4792
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
4743
4793
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.platform),
4744
- businessCode: (_ref68 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) !== null && _ref68 !== void 0 ? _ref68 : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.business_code,
4794
+ businessCode: (_ref70 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) !== null && _ref70 !== void 0 ? _ref70 : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.business_code,
4745
4795
  channel: params === null || params === void 0 ? void 0 : params.channel,
4746
4796
  type: params === null || params === void 0 ? void 0 : params.type,
4747
4797
  summary: this.store.summary || createEmptySummary(),
4748
4798
  enhance: function enhance(nextPayload) {
4749
- var _ref69, _tempOrder$order_numb, _ref70, _tempOrder$shop_order, _ref71, _tempOrder$shop_full_;
4799
+ var _ref71, _tempOrder$order_numb, _ref72, _tempOrder$shop_order, _ref73, _tempOrder$shop_full_;
4750
4800
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
4751
- order_number: (_ref69 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref69 !== void 0 ? _ref69 : null,
4752
- shop_order_number: (_ref70 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref70 !== void 0 ? _ref70 : null,
4753
- shop_full_order_number: (_ref71 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
4801
+ order_number: (_ref71 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
4802
+ shop_order_number: (_ref72 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
4803
+ shop_full_order_number: (_ref73 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref73 !== void 0 ? _ref73 : null,
4754
4804
  small_ticket_data_flag: 1
4755
4805
  });
4756
4806
  }
@@ -4801,7 +4851,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4801
4851
  key: "saveTempOrderAsDraft",
4802
4852
  value: function () {
4803
4853
  var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4804
- var _params$cacheId2, _this$otherParams6, _ref72, _params$businessCode2, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4854
+ var _params$cacheId2, _this$otherParams6, _ref74, _params$businessCode2, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4805
4855
  var tempOrder, latestSummary, payload;
4806
4856
  return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4807
4857
  while (1) switch (_context34.prev = _context34.next) {
@@ -4833,7 +4883,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4833
4883
  tempOrder: tempOrder,
4834
4884
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4835
4885
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4836
- businessCode: (_ref72 = (_params$businessCode2 = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4886
+ businessCode: (_ref74 = (_params$businessCode2 = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4837
4887
  channel: params === null || params === void 0 ? void 0 : params.channel,
4838
4888
  type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
4839
4889
  summary: latestSummary,
@@ -4914,7 +4964,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4914
4964
  key: "runSubmitTempOrder",
4915
4965
  value: function () {
4916
4966
  var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
4917
- var _params$cacheId3, _this$otherParams10, _ref73, _ref74, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4967
+ var _params$cacheId3, _this$otherParams10, _ref75, _ref76, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4918
4968
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4919
4969
  return _regeneratorRuntime().wrap(function _callee34$(_context37) {
4920
4970
  while (1) switch (_context37.prev = _context37.next) {
@@ -4976,7 +5026,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4976
5026
  tempOrder: tempOrder,
4977
5027
  cacheId: effectiveCacheId,
4978
5028
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
4979
- businessCode: (_ref73 = (_ref74 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
5029
+ businessCode: (_ref75 = (_ref76 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref76 !== void 0 ? _ref76 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4980
5030
  channel: params === null || params === void 0 ? void 0 : params.channel,
4981
5031
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4982
5032
  summary: latestSummary,
@@ -6008,7 +6058,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6008
6058
  _step24;
6009
6059
  try {
6010
6060
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6011
- var _product$metadata11, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
6061
+ var _product$metadata11, _ref77, _ref78, _existed$origin, _rawProduct$metadata;
6012
6062
  var _step24$value = _slicedToArray(_step24.value, 2),
6013
6063
  index = _step24$value[0],
6014
6064
  product = _step24$value[1];
@@ -6016,7 +6066,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6016
6066
  if (!uid) continue;
6017
6067
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
6018
6068
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
6019
- var origin = (_ref75 = (_ref76 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref76 !== void 0 ? _ref76 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref75 !== void 0 ? _ref75 : rawProduct;
6069
+ var origin = (_ref77 = (_ref78 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref78 !== void 0 ? _ref78 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref77 !== void 0 ? _ref77 : rawProduct;
6020
6070
  var originSnapshot = cloneDeep(origin);
6021
6071
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
6022
6072
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -6145,10 +6195,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6145
6195
  }, {
6146
6196
  key: "normalizeHydratedProductOptionItem",
6147
6197
  value: function normalizeHydratedProductOptionItem(optionItem) {
6148
- var _ref77, _optionItem$num, _ref78, _optionItem$add_price;
6149
- var rawNum = (_ref77 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref77 !== void 0 ? _ref77 : 1;
6198
+ var _ref79, _optionItem$num, _ref80, _optionItem$add_price;
6199
+ var rawNum = (_ref79 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1;
6150
6200
  var parsedNum = Number(rawNum);
6151
- var rawPrice = (_ref78 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref78 !== void 0 ? _ref78 : 0;
6201
+ var rawPrice = (_ref80 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref80 !== void 0 ? _ref80 : 0;
6152
6202
  var parsedPrice = Number(rawPrice);
6153
6203
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
6154
6204
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -6289,10 +6339,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6289
6339
  _step29;
6290
6340
  try {
6291
6341
  for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
6292
- var _ref79, _bundle$num3;
6342
+ var _ref81, _bundle$num3;
6293
6343
  var bundle = _step29.value;
6294
6344
  var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
6295
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref79 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1) || 1).toNumber();
6345
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref81 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref81 !== void 0 ? _ref81 : 1) || 1).toNumber();
6296
6346
  var _iterator30 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
6297
6347
  _step30;
6298
6348
  try {
@@ -10,6 +10,8 @@ export interface OrderPaymentIdentityMatch<T> {
10
10
  matchedBy: OrderPaymentIdentityType;
11
11
  }
12
12
  export declare function getOrderPaymentIdentityKeys(payment: unknown): string[];
13
+ export declare function isPendingOrderPayment(payment: unknown): boolean;
14
+ export declare function isIdentifiedPendingOrderPayment(payment: unknown): boolean;
13
15
  export declare function hasOrderPaymentIdentityOverlap(left: unknown, right: unknown): boolean;
14
16
  export declare function resolveOrderPaymentIdentity<T extends Record<string, any>>(payments: T[] | null | undefined, identity: string | number, mode?: 'payment_number' | 'compat'): OrderPaymentIdentityMatch<T> | null;
15
17
  export declare function ensureOrderPaymentNumber<T extends Record<string, any>>(payment: T, devicePrefix: string, createPaymentNumber: () => string): T & {
@@ -20,4 +22,5 @@ export declare function mergeOrderPaymentRecord<T extends Record<string, any>>(p
20
22
  export declare function mergeOrderPaymentSnapshot<T extends Record<string, any>>(current: T, incoming: T): T;
21
23
  export declare function mergeOrderPaymentListsByIdentity<T extends Record<string, any>>(existing: T[] | null | undefined, incoming: T[] | null | undefined, options?: {
22
24
  preserveUnmatchedExisting?: boolean;
25
+ preserveUnmatchedExistingWhen?: (payment: T) => boolean;
23
26
  }): T[];
@@ -31,6 +31,13 @@ export function getOrderPaymentIdentityKeys(payment) {
31
31
  return value === null ? [] : ["".concat(type, ":").concat(value)];
32
32
  });
33
33
  }
34
+ export function isPendingOrderPayment(payment) {
35
+ var record = payment;
36
+ return String((record === null || record === void 0 ? void 0 : record.status) || '').toLowerCase() === 'payment_pending';
37
+ }
38
+ export function isIdentifiedPendingOrderPayment(payment) {
39
+ return isPendingOrderPayment(payment) && getOrderPaymentIdentityKeys(payment).length > 0;
40
+ }
34
41
  export function hasOrderPaymentIdentityOverlap(left, right) {
35
42
  var leftKeys = new Set(getOrderPaymentIdentityKeys(left));
36
43
  if (leftKeys.size === 0) return false;
@@ -123,10 +130,18 @@ export function mergeOrderPaymentRecord(payment, updates) {
123
130
  export function mergeOrderPaymentSnapshot(current, incoming) {
124
131
  var currentMetadata = current.metadata || {};
125
132
  var incomingMetadata = incoming.metadata || {};
133
+ var currentUniquePaymentNumber = normalizePaymentIdentityValue(currentMetadata.unique_payment_number);
134
+ var incomingUniquePaymentNumber = normalizePaymentIdentityValue(incomingMetadata.unique_payment_number);
135
+ var incomingOrderPaymentId = normalizePaymentIdentityValue(incoming.order_payment_id);
136
+ var incomingFallbackPrefix = incomingOrderPaymentId ? "os-fallback:payment:order-payment:".concat(incomingOrderPaymentId) : null;
137
+ var incomingUsesDerivedUniquePaymentNumber = Boolean(incomingUniquePaymentNumber && incomingFallbackPrefix && (incomingUniquePaymentNumber === incomingFallbackPrefix || incomingUniquePaymentNumber.startsWith("".concat(incomingFallbackPrefix, ":conflict:"))));
126
138
  var transactions = mergeOrderPaymentTransactions(currentMetadata.transactions, incomingMetadata.transactions);
127
139
  return _objectSpread(_objectSpread(_objectSpread({}, current), incoming), {}, {
140
+ order_payment_id: normalizePaymentIdentityValue(incoming.order_payment_id) !== null ? incoming.order_payment_id : current.order_payment_id,
128
141
  payment_number: incoming.payment_number || current.payment_number,
129
- metadata: _objectSpread(_objectSpread(_objectSpread({}, currentMetadata), incomingMetadata), transactions.length > 0 ? {
142
+ metadata: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, currentMetadata), incomingMetadata), incomingUsesDerivedUniquePaymentNumber && currentUniquePaymentNumber ? {
143
+ unique_payment_number: currentUniquePaymentNumber
144
+ } : {}), transactions.length > 0 ? {
130
145
  transactions: transactions
131
146
  } : {})
132
147
  });
@@ -192,12 +207,19 @@ export function mergeOrderPaymentListsByIdentity(existing, incoming) {
192
207
  if (options.preserveUnmatchedExisting) {
193
208
  return compactOrderPaymentList([].concat(_toConsumableArray(existingList), _toConsumableArray(incomingList)));
194
209
  }
195
- return compactOrderPaymentList(incomingList.map(function (incomingPayment) {
210
+ var mergedIncoming = incomingList.map(function (incomingPayment) {
196
211
  var matchingExisting = existingList.filter(function (existingPayment) {
197
212
  return hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment);
198
213
  });
199
214
  return matchingExisting.reduce(function (merged, existingPayment) {
200
215
  return mergeOrderPaymentSnapshot(existingPayment, merged);
201
216
  }, incomingPayment);
202
- }));
217
+ });
218
+ var preservedExisting = options.preserveUnmatchedExistingWhen ? existingList.filter(function (existingPayment) {
219
+ var _options$preserveUnma;
220
+ return !incomingList.some(function (incomingPayment) {
221
+ return hasOrderPaymentIdentityOverlap(existingPayment, incomingPayment);
222
+ }) && ((_options$preserveUnma = options.preserveUnmatchedExistingWhen) === null || _options$preserveUnma === void 0 ? void 0 : _options$preserveUnma.call(options, existingPayment));
223
+ }) : [];
224
+ return compactOrderPaymentList([].concat(_toConsumableArray(mergedIncoming), _toConsumableArray(preservedExisting)));
203
225
  }
@@ -209,6 +209,11 @@ export function normalizeOrderCollection(kind, items, options) {
209
209
  var persistentId = getOrderCollectionPersistentId(kind, item);
210
210
  var uid = getOrderCollectionUid(kind, item);
211
211
  if (!uid) {
212
+ var _item;
213
+ if (kind === 'payment' && !isBlankOrderCollectionIdentity((_item = item) === null || _item === void 0 ? void 0 : _item.payment_number)) {
214
+ // payment_number 已提供稳定身份,不占用真实交易流水字段作为内部 UID。
215
+ continue;
216
+ }
212
217
  uid = persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
213
218
  item = setOrderCollectionUid(kind, item, uid);
214
219
  result[index] = item;
@@ -216,7 +221,7 @@ export function normalizeOrderCollection(kind, items, options) {
216
221
  if (!persistentId) stats.anonymousRowCount += 1;
217
222
  }
218
223
  if (occupiedUids.has(uid)) {
219
- var _item, _item2, _item3, _item4;
224
+ var _item2, _item3, _item4, _item5;
220
225
  var replacementUid = persistentId ? allocatePersistentConflictUid(kind, persistentId, occupiedUids) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
221
226
  result[index] = setOrderCollectionUid(kind, item, replacementUid);
222
227
  uidRemaps.push({
@@ -225,7 +230,7 @@ export function normalizeOrderCollection(kind, items, options) {
225
230
  to: replacementUid,
226
231
  persistentId: persistentId,
227
232
  scope: 'linked-owner',
228
- referenceOwnerUid: kind === 'product' ? String(((_item = item) === null || _item === void 0 ? void 0 : _item.booking_uid) || ((_item2 = item) === null || _item2 === void 0 || (_item2 = _item2.metadata) === null || _item2 === void 0 ? void 0 : _item2.booking_uid) || '') || null : kind === 'booking' ? String(((_item3 = item) === null || _item3 === void 0 ? void 0 : _item3.product_uid) || ((_item4 = item) === null || _item4 === void 0 || (_item4 = _item4.metadata) === null || _item4 === void 0 ? void 0 : _item4.product_uid) || '') || null : null
233
+ referenceOwnerUid: kind === 'product' ? String(((_item2 = item) === null || _item2 === void 0 ? void 0 : _item2.booking_uid) || ((_item3 = item) === null || _item3 === void 0 || (_item3 = _item3.metadata) === null || _item3 === void 0 ? void 0 : _item3.booking_uid) || '') || null : kind === 'booking' ? String(((_item4 = item) === null || _item4 === void 0 ? void 0 : _item4.product_uid) || ((_item5 = item) === null || _item5 === void 0 || (_item5 = _item5.metadata) === null || _item5 === void 0 ? void 0 : _item5.product_uid) || '') || null : null
229
234
  });
230
235
  uid = replacementUid;
231
236
  stats.uidConflictCount += 1;
@@ -121,6 +121,8 @@ declare class Server {
121
121
  private handleSyncSalesTask;
122
122
  private runCheckoutSync;
123
123
  private omitCheckoutSyncMode;
124
+ private buildRemoteCheckoutData;
125
+ private mergeCheckoutSyncPayments;
124
126
  private persistSyncedCheckoutOrder;
125
127
  /**
126
128
  * 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。