@pisell/pisellos 2.2.266 → 2.2.267

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 (93) hide show
  1. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  2. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  3. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  5. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  6. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  7. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  8. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  9. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  10. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  11. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  12. package/dist/modules/Order/index.d.ts +8 -27
  13. package/dist/modules/Order/index.js +493 -753
  14. package/dist/modules/Order/types.d.ts +1 -33
  15. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  16. package/dist/modules/Order/utils.js +6 -10
  17. package/dist/modules/Payment/index.d.ts +0 -2
  18. package/dist/modules/Payment/index.js +50 -79
  19. package/dist/modules/Payment/types.d.ts +27 -29
  20. package/dist/modules/Payment/types.js +3 -5
  21. package/dist/modules/Rules/index.d.ts +0 -1
  22. package/dist/modules/Rules/index.js +14 -34
  23. package/dist/server/index.d.ts +0 -16
  24. package/dist/server/index.js +1036 -1933
  25. package/dist/server/modules/order/index.d.ts +4 -49
  26. package/dist/server/modules/order/index.js +695 -1574
  27. package/dist/server/modules/order/types.d.ts +3 -11
  28. package/dist/server/modules/order/types.js +1 -1
  29. package/dist/solution/BaseSales/index.d.ts +11 -55
  30. package/dist/solution/BaseSales/index.js +396 -711
  31. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  32. package/dist/solution/BaseSales/utils/cartPromotion.js +36 -93
  33. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  34. package/dist/solution/BookingTicket/index.d.ts +1 -1
  35. package/dist/solution/BookingTicket/index.js +29 -35
  36. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  37. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  38. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  39. package/dist/solution/Sales/index.d.ts +0 -1
  40. package/dist/solution/Sales/index.js +2 -10
  41. package/dist/solution/ScanOrder/index.js +20 -31
  42. package/dist/solution/VenueBooking/index.js +19 -30
  43. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  44. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  45. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  46. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  47. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  48. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  49. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  50. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  51. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  52. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  53. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  54. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  55. package/lib/modules/Order/index.d.ts +8 -27
  56. package/lib/modules/Order/index.js +72 -193
  57. package/lib/modules/Order/types.d.ts +1 -33
  58. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  59. package/lib/modules/Order/utils.js +4 -11
  60. package/lib/modules/Payment/index.d.ts +0 -2
  61. package/lib/modules/Payment/index.js +13 -34
  62. package/lib/modules/Payment/types.d.ts +27 -29
  63. package/lib/modules/Payment/types.js +3 -3
  64. package/lib/modules/Rules/index.d.ts +0 -1
  65. package/lib/modules/Rules/index.js +4 -23
  66. package/lib/server/index.d.ts +0 -16
  67. package/lib/server/index.js +18 -670
  68. package/lib/server/modules/order/index.d.ts +4 -49
  69. package/lib/server/modules/order/index.js +66 -657
  70. package/lib/server/modules/order/types.d.ts +3 -11
  71. package/lib/solution/BaseSales/index.d.ts +11 -55
  72. package/lib/solution/BaseSales/index.js +35 -235
  73. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  74. package/lib/solution/BaseSales/utils/cartPromotion.js +17 -65
  75. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  76. package/lib/solution/BookingTicket/index.d.ts +1 -1
  77. package/lib/solution/BookingTicket/index.js +3 -6
  78. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  79. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  80. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  81. package/lib/solution/Sales/index.d.ts +0 -1
  82. package/lib/solution/Sales/index.js +3 -5
  83. package/lib/solution/ScanOrder/index.js +0 -8
  84. package/lib/solution/VenueBooking/index.js +0 -8
  85. package/package.json +2 -2
  86. package/dist/modules/Order/payment-utils.d.ts +0 -26
  87. package/dist/modules/Order/payment-utils.js +0 -225
  88. package/dist/utils/payment-number.d.ts +0 -9
  89. package/dist/utils/payment-number.js +0 -69
  90. package/lib/modules/Order/payment-utils.d.ts +0 -26
  91. package/lib/modules/Order/payment-utils.js +0 -224
  92. package/lib/utils/payment-number.d.ts +0 -9
  93. package/lib/utils/payment-number.js +0 -64
@@ -37,8 +37,6 @@ var import_types = require("./types");
37
37
  var import_utils = require("./utils");
38
38
  var import_utils2 = require("../Product/utils");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
- var import_payment_utils = require("./payment-utils");
41
- var import_payment_number = require("../../utils/payment-number");
42
40
  var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
43
41
  var import_utils3 = require("../../solution/ScanOrder/utils");
44
42
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
@@ -85,11 +83,6 @@ function isPaidPaymentRecord(payment) {
85
83
  function isCommittedVoucherPaymentRecord(payment) {
86
84
  return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
87
85
  }
88
- function getVoucherPaymentLifecycleKey(payment) {
89
- if (!isVoucherPaymentRecord(payment))
90
- return null;
91
- return `${String(payment.voucher_id)}::${String(payment.status || "")}`;
92
- }
93
86
  var OrderModule = class extends import_BaseModule.BaseModule {
94
87
  constructor(name, version) {
95
88
  super(name || "order", version);
@@ -320,11 +313,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
320
313
  this.store.availableWalletIds = [];
321
314
  }
322
315
  this.request = this.core.getPlugin("request");
323
- this.appPlugin = this.core.getPlugin("app");
324
- if (!this.appPlugin) {
316
+ const appPlugin = this.core.getPlugin("app");
317
+ if (!appPlugin) {
325
318
  throw new Error("Order 模块需要 app 插件支持");
326
319
  }
327
- const app = this.appPlugin.getApp();
320
+ const app = appPlugin.getApp();
328
321
  this.logger = app.logger;
329
322
  this.window = this.core.getPlugin("window");
330
323
  const otherParams = options.otherParams || {};
@@ -1060,40 +1053,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1060
1053
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1061
1054
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1062
1055
  }
1063
- getPaymentNumberAppData(key) {
1064
- var _a, _b, _c, _d, _e;
1065
- const appPlugin = this.appPlugin;
1066
- if (!appPlugin)
1067
- return void 0;
1068
- const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1069
- if (typeof getData === "function")
1070
- return getData(key);
1071
- const app = appPlugin.getApp();
1072
- const coreData = (_e = (_c = (_b = app == null ? void 0 : app.models) == null ? void 0 : _b.getStore) == null ? void 0 : (_d = _c.call(_b)).getDataByModel) == null ? void 0 : _e.call(_d, "core", "core");
1073
- return coreData == null ? void 0 : coreData[key];
1074
- }
1075
- getPaymentNumberDevicePrefixSync() {
1076
- return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1077
- (key) => this.getPaymentNumberAppData(key)
1078
- );
1079
- }
1080
- getPaymentNumberDevicePrefixAsync() {
1081
- return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1082
- (key) => this.getPaymentNumberAppData(key)
1083
- );
1084
- }
1085
1056
  normalizePaymentSource(payment, options) {
1086
1057
  const paymentRecord = payment;
1087
1058
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1088
- const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1089
- {
1090
- ...paymentRecord,
1091
- metadata,
1092
- origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1093
- },
1094
- (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1095
- import_utils.createUuidV4
1096
- );
1059
+ if (!metadata.unique_payment_number) {
1060
+ metadata.unique_payment_number = (0, import_utils.createUuidV4)();
1061
+ }
1062
+ const normalized = {
1063
+ ...paymentRecord,
1064
+ metadata,
1065
+ origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1066
+ };
1097
1067
  if (paymentRecord.status !== void 0) {
1098
1068
  normalized.status = paymentRecord.status;
1099
1069
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -2514,36 +2484,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2514
2484
  * 用一组支付来源覆盖当前订单支付项。
2515
2485
  *
2516
2486
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2517
- * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2487
+ * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2518
2488
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2519
2489
  */
2520
2490
  setOrderPayments(payments) {
2521
2491
  const tempOrder = this.ensureTempOrder();
2522
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2523
- (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2524
- );
2492
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2525
2493
  this.persistTempOrder();
2526
2494
  return tempOrder.payments;
2527
2495
  }
2528
- /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2496
+ /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2529
2497
  addOrderPayment(payment) {
2530
- const hasPaymentNumber = String(
2531
- payment.payment_number || ""
2532
- ).trim() !== "";
2533
- return this.addOrderPaymentWithDevicePrefix(
2534
- payment,
2535
- hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2536
- );
2537
- }
2538
- /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2539
- async addOrderPaymentAsync(payment) {
2540
- const hasPaymentNumber = String(
2541
- payment.payment_number || ""
2542
- ).trim() !== "";
2543
- const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2544
- return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2545
- }
2546
- addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2547
2498
  this.logInfo("addOrderPayment", {
2548
2499
  payment
2549
2500
  });
@@ -2556,7 +2507,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2556
2507
  type: orderPaymentType,
2557
2508
  order_payment_type: orderPaymentType
2558
2509
  },
2559
- { defaultPaid: true, devicePrefix }
2510
+ { defaultPaid: true }
2560
2511
  )
2561
2512
  ]);
2562
2513
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2569,55 +2520,57 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2569
2520
  return tempOrder.payments;
2570
2521
  }
2571
2522
  /**
2572
- * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2573
- * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2523
+ * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2524
+ *
2525
+ * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2526
+ * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2574
2527
  */
2575
- async updateOrderPayment(paymentIdentity, updates, options = {}) {
2528
+ updateOrderPayment(paymentIdentity, updates) {
2576
2529
  const tempOrder = this.ensureTempOrder();
2577
2530
  const identity = String(paymentIdentity);
2578
- const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2579
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2580
- tempOrder.payments || [],
2581
- identity,
2582
- matchMode
2583
- );
2584
- if (!matchedPayment) {
2585
- throw new Error(`未找到支付项: ${identity}`);
2586
- }
2587
- let updatedPayment = null;
2588
- tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2589
- if (index !== matchedPayment.index)
2531
+ tempOrder.payments = (tempOrder.payments || []).map((payment) => {
2532
+ var _a;
2533
+ const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2534
+ const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2535
+ const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2536
+ const uuid = payment == null ? void 0 : payment.uuid;
2537
+ const matched = [
2538
+ uniquePaymentNumber,
2539
+ orderPaymentId,
2540
+ customPaymentId,
2541
+ uuid
2542
+ ].some((value) => value !== void 0 && String(value) === identity);
2543
+ if (!matched)
2590
2544
  return payment;
2591
- const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2545
+ return {
2546
+ ...payment,
2592
2547
  ...updates,
2593
- updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2594
- });
2595
- updatedPayment = nextPayment;
2596
- return nextPayment;
2548
+ metadata: {
2549
+ ...payment.metadata || {},
2550
+ ...updates.metadata || {}
2551
+ }
2552
+ };
2597
2553
  });
2598
2554
  this.persistTempOrder();
2599
- const summary = await this.recalculateSummary({ createIfMissing: true });
2600
- this.persistTempOrder();
2601
- const payments = tempOrder.payments;
2602
- return {
2603
- updated: true,
2604
- payment: payments[matchedPayment.index] || updatedPayment,
2605
- payments,
2606
- summary
2607
- };
2555
+ return tempOrder.payments;
2608
2556
  }
2609
2557
  /** 从当前订单支付项中移除指定支付项。 */
2610
2558
  deleteOrderPayment(paymentIdentity) {
2611
2559
  const tempOrder = this.ensureTempOrder();
2612
2560
  const identity = String(paymentIdentity);
2613
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2614
- tempOrder.payments || [],
2615
- identity,
2616
- "compat"
2617
- );
2618
- if (!matchedPayment)
2619
- return tempOrder.payments;
2620
- tempOrder.payments = (tempOrder.payments || []).filter((_, index) => index !== matchedPayment.index);
2561
+ tempOrder.payments = (tempOrder.payments || []).filter((payment) => {
2562
+ var _a;
2563
+ const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2564
+ const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2565
+ const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2566
+ const uuid = payment == null ? void 0 : payment.uuid;
2567
+ return ![
2568
+ uniquePaymentNumber,
2569
+ orderPaymentId,
2570
+ customPaymentId,
2571
+ uuid
2572
+ ].some((value) => value !== void 0 && String(value) === identity);
2573
+ });
2621
2574
  this.persistTempOrder();
2622
2575
  return tempOrder.payments;
2623
2576
  }
@@ -2726,10 +2679,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2726
2679
  payments.map(
2727
2680
  (payment) => this.normalizePaymentSource(
2728
2681
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2729
- {
2730
- defaultPaid: false,
2731
- devicePrefix: options == null ? void 0 : options.devicePrefix
2732
- }
2682
+ { defaultPaid: false }
2733
2683
  )
2734
2684
  )
2735
2685
  ).filter((payment) => {
@@ -2751,15 +2701,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2751
2701
  const committedVoucherPaymentIds = new Set(
2752
2702
  committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2753
2703
  );
2754
- const committedVoucherLifecycleKeys = new Set(
2755
- committedVoucherPayments.map((payment) => getVoucherPaymentLifecycleKey(payment)).filter((key) => key !== null)
2704
+ const committedVoucherIds = new Set(
2705
+ committedVoucherPayments.map((payment) => String(payment.voucher_id))
2756
2706
  );
2757
2707
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2758
2708
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2759
2709
  return false;
2760
2710
  }
2761
- const lifecycleKey = getVoucherPaymentLifecycleKey(payment);
2762
- if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
2711
+ if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2763
2712
  return false;
2764
2713
  }
2765
2714
  return true;
@@ -2781,14 +2730,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2781
2730
  });
2782
2731
  return tempOrder.payments;
2783
2732
  }
2784
- async updateVoucherOrderPaymentsAsync(payments, options) {
2785
- const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2786
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2787
- return this.updateVoucherOrderPayments(payments, {
2788
- ...options,
2789
- devicePrefix
2790
- });
2791
- }
2792
2733
  async shouldMergeProductToOrder(params) {
2793
2734
  var _a;
2794
2735
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -2849,7 +2790,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2849
2790
  * await this.appendProductLineToTempOrder(tempOrder, { product_id: 1, num: 1 }, booking);
2850
2791
  */
2851
2792
  async appendProductLineToTempOrder(tempOrder, product, booking) {
2852
- var _a, _b;
2793
+ var _a, _b, _c, _d;
2853
2794
  const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
2854
2795
  const productToAdd = (linked == null ? void 0 : linked.product) || product;
2855
2796
  const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
@@ -2860,7 +2801,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2860
2801
  productToAdd,
2861
2802
  (0, import_utils3.normalizeOrderProduct)(productToAdd)
2862
2803
  );
2863
- const incomingBookingUid = productToAdd.booking_uid ?? ((_a = productToAdd.metadata) == null ? void 0 : _a.booking_uid);
2804
+ const isWeighingProduct = Number(((_a = normalizedIncoming.product_sku) == null ? void 0 : _a.open_sold_weight) || 0) === 1;
2805
+ const netWeight = Number((_b = normalizedIncoming.product_sku) == null ? void 0 : _b.net_weight);
2806
+ if (isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0)) {
2807
+ throw new Error("[Order] 称重商品净重必须大于 0");
2808
+ }
2809
+ const incomingBookingUid = productToAdd.booking_uid ?? ((_c = productToAdd.metadata) == null ? void 0 : _c.booking_uid);
2864
2810
  if (incomingBookingUid !== void 0 && incomingBookingUid !== null && String(incomingBookingUid) !== "") {
2865
2811
  normalizedIncoming.booking_uid = String(incomingBookingUid);
2866
2812
  normalizedIncoming.metadata = {
@@ -2876,7 +2822,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2876
2822
  );
2877
2823
  const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
2878
2824
  const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
2879
- const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
2825
+ const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid || isWeighingProduct;
2880
2826
  const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
2881
2827
  var _a2;
2882
2828
  if (this.hasGoodPassDiscount(item))
@@ -2928,7 +2874,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2928
2874
  tempOrder.products = [...tempOrder.products, normalizedIncoming];
2929
2875
  } else {
2930
2876
  const targetProduct = matchedProduct;
2931
- const targetUid = (_b = targetProduct.metadata) == null ? void 0 : _b.unique_identification_number;
2877
+ const targetUid = (_d = targetProduct.metadata) == null ? void 0 : _d.unique_identification_number;
2932
2878
  const normalizedProduct = (0, import_utils.mergeOrderProductDisplayFields)(
2933
2879
  targetProduct,
2934
2880
  (0, import_utils3.normalizeOrderProduct)({
@@ -3619,38 +3565,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3619
3565
  await this.saveDraft();
3620
3566
  return tempOrder;
3621
3567
  }
3622
- async saveTempOrderAsDraft(params) {
3623
- var _a, _b, _c, _d, _e;
3624
- const tempOrder = this.ensureTempOrder();
3625
- this.ensureExternalSaleNumber(tempOrder);
3626
- this.persistTempOrder();
3627
- const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3628
- const payload = (0, import_utils.buildSubmitPayload)({
3629
- tempOrder,
3630
- cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3631
- platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3632
- businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
3633
- channel: params == null ? void 0 : params.channel,
3634
- type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3635
- summary: latestSummary,
3636
- enhance: params == null ? void 0 : params.enhancePayload
3637
- });
3638
- if (!payload.created_at) {
3639
- payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3640
- }
3641
- payload.need_sync = 0;
3642
- payload.is_draft_order = 1;
3643
- this.logInfo("saveTempOrderAsDraft calling sales draft", {
3644
- orderId: payload.order_id,
3645
- externalSaleNumber: payload.external_sale_number,
3646
- productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3647
- });
3648
- return this.request.post("/order/sales/draft", payload, {
3649
- osServer: true,
3650
- customToast: () => {
3651
- }
3652
- });
3653
- }
3654
3568
  /**
3655
3569
  * 提交当前 Sales tempOrder。
3656
3570
  *
@@ -3851,13 +3765,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3851
3765
  }
3852
3766
  async syncPaymentsToOrder(params) {
3853
3767
  const tempOrder = this.ensureTempOrder();
3854
- const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3855
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3856
3768
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3857
- (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3858
- defaultPaid: false,
3859
- devicePrefix
3860
- }))
3769
+ params.payments || []
3861
3770
  );
3862
3771
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3863
3772
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -4233,12 +4142,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4233
4142
  }
4234
4143
  }
4235
4144
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4236
- const sourceLastOrderInfo = raw.lastOrderInfo || raw;
4237
- const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4238
- const syntheticIdentityOptions = {
4239
- isDraftOrder,
4240
- externalSaleNumber: nextTempOrder.external_sale_number
4241
- };
4242
4145
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4243
4146
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4244
4147
  this.store.tempOrder = nextTempOrder;
@@ -4259,14 +4162,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4259
4162
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4260
4163
  }
4261
4164
  };
4262
- this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4263
- sourceLastOrderInfo,
4264
- syntheticIdentityOptions
4265
- );
4266
- const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4267
- if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4268
- this.store.syncState = "local";
4269
- }
4165
+ this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4270
4166
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4271
4167
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4272
4168
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -4379,13 +4275,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4379
4275
  }
4380
4276
  normalizeTempOrderForRuntime(raw, options) {
4381
4277
  var _a, _b;
4382
- const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4383
4278
  const nextTempOrder = {
4384
4279
  ...this.createDefaultTempOrderInstance(),
4385
- ...runtimeRaw || {}
4280
+ ...raw || {}
4386
4281
  };
4387
- if ((nextTempOrder.order_id === void 0 || nextTempOrder.order_id === null) && (runtimeRaw == null ? void 0 : runtimeRaw.id) !== void 0 && (runtimeRaw == null ? void 0 : runtimeRaw.id) !== null) {
4388
- nextTempOrder.order_id = runtimeRaw.id;
4282
+ if ((nextTempOrder.order_id === void 0 || nextTempOrder.order_id === null) && (raw == null ? void 0 : raw.id) !== void 0 && (raw == null ? void 0 : raw.id) !== null) {
4283
+ nextTempOrder.order_id = raw.id;
4389
4284
  }
4390
4285
  delete nextTempOrder.summary;
4391
4286
  delete nextTempOrder.lastOrderInfo;
@@ -4453,22 +4348,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4453
4348
  nextTempOrder.vouchers = raw.vouchers || [];
4454
4349
  return nextTempOrder;
4455
4350
  }
4456
- isSyntheticDraftOrderIdForRuntime(record, options) {
4457
- const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4458
- const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4459
- const orderId = record == null ? void 0 : record.order_id;
4460
- return Boolean(
4461
- isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4462
- );
4463
- }
4464
- withoutSyntheticDraftOrderIdForRuntime(record, options) {
4465
- if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4466
- return record;
4467
- return {
4468
- ...record,
4469
- order_id: null
4470
- };
4471
- }
4472
4351
  hydrateLinkedBookingIdentity(tempOrder) {
4473
4352
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4474
4353
  const productByUid = /* @__PURE__ */ new Map();
@@ -468,8 +468,6 @@ export interface SubmitSalesOrderParams {
468
468
  export interface PaymentItemData {
469
469
  /** 当前支付项的唯一 ID */
470
470
  uuid: string;
471
- /** 支付项稳定唯一号 */
472
- payment_number?: string;
473
471
  /** 当前支付方式付出去多少钱 */
474
472
  amount: string;
475
473
  /** 支付类型代码 */
@@ -492,22 +490,13 @@ export interface PaymentItemData {
492
490
  export interface OrderPaymentMetadata {
493
491
  rounding_rule?: Record<string, any>;
494
492
  unique_payment_number?: string;
495
- /** 刷卡机设备快照;OS 不解析内部字段,仅透传并持久化 */
496
- card_reader_snapshot?: Record<string, unknown>;
497
493
  shop_wallet_pass_id?: number | string;
498
494
  actual_paid_amount?: number | string;
499
495
  change_given_amount?: number | string;
500
- transactions?: OrderPaymentTransaction[];
501
496
  [key: string]: any;
502
497
  }
503
- export interface OrderPaymentTransaction {
504
- number: string;
505
- status: 'success' | 'fail';
506
- }
507
498
  export interface OrderPaymentData {
508
499
  order_payment_id?: number | string;
509
- /** 支付项稳定唯一号;历史支付项允许缺失 */
510
- payment_number?: string;
511
500
  amount: string;
512
501
  code: string;
513
502
  custom_payment_id: number;
@@ -534,15 +523,6 @@ export interface OrderPaymentData {
534
523
  created_at?: string;
535
524
  updated_at?: string;
536
525
  }
537
- export interface OrderPaymentUpdateOptions {
538
- matchBy?: 'payment_number' | 'compat' | 'legacy';
539
- }
540
- export interface OrderPaymentUpdateResult {
541
- updated: boolean;
542
- payment: OrderPaymentData | null;
543
- payments: OrderPaymentData[];
544
- summary: OrderSummary | null;
545
- }
546
526
  export type OrderPaymentSource = PaymentItem | OrderPaymentData | Record<string, any>;
547
527
  export interface MapOrderPaymentsOptions {
548
528
  includeVoided?: boolean;
@@ -693,14 +673,6 @@ export interface OrderModuleAPI {
693
673
  channel?: string;
694
674
  type?: string;
695
675
  }) => OrderSubmitPayload;
696
- saveTempOrderAsDraft: <T = any>(params?: {
697
- cacheId?: string;
698
- platform?: string;
699
- businessCode?: string;
700
- channel?: string;
701
- type?: string;
702
- enhancePayload?: SubmitPayloadEnhancer;
703
- }) => Promise<T>;
704
676
  applyLocalPrintOrderNumbers: (order?: Record<string, any> | null) => Promise<OrderTempOrder>;
705
677
  getTempOrderNote: () => string;
706
678
  updateTempOrderNote: {
@@ -758,15 +730,11 @@ export interface OrderModuleAPI {
758
730
  getOrderPayments: () => OrderPaymentData[];
759
731
  setOrderPayments: (payments: OrderPaymentSource[]) => OrderPaymentData[];
760
732
  addOrderPayment: (payment: OrderPaymentSource) => OrderPaymentData[];
761
- addOrderPaymentAsync: (payment: OrderPaymentSource) => Promise<OrderPaymentData[]>;
762
- updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>, options?: OrderPaymentUpdateOptions) => Promise<OrderPaymentUpdateResult>;
733
+ updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>) => OrderPaymentData[];
763
734
  deleteOrderPayment: (paymentIdentity: string | number) => OrderPaymentData[];
764
735
  updateVoucherOrderPayments: (payments: OrderPaymentSource[], options?: {
765
736
  status?: 'paid' | 'payment_pending';
766
737
  }) => OrderPaymentData[];
767
- updateVoucherOrderPaymentsAsync: (payments: OrderPaymentSource[], options?: {
768
- status?: 'paid' | 'payment_pending';
769
- }) => Promise<OrderPaymentData[]>;
770
738
  confirmPendingVoucherPayments: (options?: {
771
739
  persist?: boolean;
772
740
  recalculateSummary?: boolean;
@@ -220,9 +220,6 @@ function normalizeOrderCollection(kind, items, options) {
220
220
  const persistentId = getOrderCollectionPersistentId(kind, item);
221
221
  let uid = getOrderCollectionUid(kind, item);
222
222
  if (!uid) {
223
- if (kind === "payment" && !isBlankOrderCollectionIdentity(item == null ? void 0 : item.payment_number)) {
224
- continue;
225
- }
226
223
  uid = persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
227
224
  item = setOrderCollectionUid(kind, item, uid);
228
225
  result[index] = item;
@@ -444,12 +444,7 @@ function resolveEffectivePerUnitDiscount(product) {
444
444
  (sum, discount) => sum + Number((discount == null ? void 0 : discount.amount) || 0),
445
445
  0
446
446
  );
447
- const hasPromoDiscountItem = discountList.some(
448
- (item) => {
449
- var _a, _b;
450
- return (item == null ? void 0 : item.type) === "promotion" || (item == null ? void 0 : item.type) === "product" && ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.actionType) === "ITEM_REWARD";
451
- }
452
- );
447
+ const hasPromoDiscountItem = discountList.some((item) => (item == null ? void 0 : item.type) === "promotion");
453
448
  if (hasPromoDiscountItem)
454
449
  return fromList;
455
450
  const metadata = (product == null ? void 0 : product.metadata) || {};
@@ -970,9 +965,6 @@ function buildSubmitPayload(params) {
970
965
  ...tempOrderRest,
971
966
  customer_id: tempOrder.customer_id ?? 1,
972
967
  customer_name: tempOrder.customer_name || "Walk-In",
973
- country_calling_code: String(tempOrder.country_calling_code ?? ""),
974
- phone: String(tempOrder.phone ?? ""),
975
- email: String(tempOrder.email ?? ""),
976
968
  order_number: tempOrder.order_number ?? null,
977
969
  shop_order_number: tempOrder.shop_order_number ?? null,
978
970
  shop_full_order_number: tempOrder.shop_full_order_number ?? null,
@@ -1028,7 +1020,9 @@ function mapPaymentItemToOrderPayment(paymentItem) {
1028
1020
  const item = paymentItem;
1029
1021
  const customPaymentId = item.custom_payment_id ?? item.id;
1030
1022
  const metadata = item.metadata && typeof item.metadata === "object" ? { ...item.metadata } : {};
1031
- const paymentNumber = item.payment_number;
1023
+ if (item.uuid && !metadata.unique_payment_number) {
1024
+ metadata.unique_payment_number = String(item.uuid);
1025
+ }
1032
1026
  const paymentMetadataKeys = [
1033
1027
  "rounding_rule",
1034
1028
  "shop_wallet_pass_id",
@@ -1045,7 +1039,6 @@ function mapPaymentItemToOrderPayment(paymentItem) {
1045
1039
  const createdAt = item.created_at ?? timestamp;
1046
1040
  return {
1047
1041
  ...item.order_payment_id !== void 0 ? { order_payment_id: item.order_payment_id } : {},
1048
- ...paymentNumber !== void 0 && paymentNumber !== null && paymentNumber !== "" ? { payment_number: String(paymentNumber) } : {},
1049
1042
  amount: String(item.amount ?? "0.00"),
1050
1043
  code: String(item.code || ""),
1051
1044
  custom_payment_id: Number(customPaymentId ?? 0),
@@ -20,7 +20,6 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
20
20
  protected defaultVersion: string;
21
21
  request: RequestPlugin;
22
22
  private app;
23
- private appPlugin;
24
23
  private store;
25
24
  window: WindowPlugin;
26
25
  private dbManager;
@@ -41,7 +40,6 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
41
40
  * paymentModule.updateOtherParams({ fatherModule: 'bookingTicket' });
42
41
  */
43
42
  updateOtherParams(params: Record<string, any>): void;
44
- private getPaymentNumberAppData;
45
43
  /**
46
44
  * 记录信息日志
47
45
  */