@pisell/pisellos 2.2.276 → 2.2.800

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 (119) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +0 -7
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  4. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  8. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  12. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  13. package/dist/modules/OpenData/index.d.ts +0 -2
  14. package/dist/modules/OpenData/index.js +0 -8
  15. package/dist/modules/Order/index.d.ts +8 -28
  16. package/dist/modules/Order/index.js +496 -808
  17. package/dist/modules/Order/types.d.ts +1 -35
  18. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  19. package/dist/modules/Order/utils.js +6 -10
  20. package/dist/modules/Payment/index.d.ts +0 -2
  21. package/dist/modules/Payment/index.js +49 -78
  22. package/dist/modules/Payment/types.d.ts +25 -104
  23. package/dist/modules/Payment/types.js +0 -17
  24. package/dist/modules/Payment/walletpass.d.ts +1 -38
  25. package/dist/modules/Payment/walletpass.js +114 -917
  26. package/dist/modules/Rules/index.d.ts +0 -3
  27. package/dist/modules/Rules/index.js +70 -100
  28. package/dist/server/index.d.ts +0 -25
  29. package/dist/server/index.js +1069 -2001
  30. package/dist/server/modules/index.d.ts +1 -1
  31. package/dist/server/modules/order/index.d.ts +4 -70
  32. package/dist/server/modules/order/index.js +728 -1816
  33. package/dist/server/modules/order/types.d.ts +3 -25
  34. package/dist/server/modules/order/types.js +1 -7
  35. package/dist/server/utils/small-ticket.js +2 -1
  36. package/dist/solution/BaseSales/index.d.ts +5 -104
  37. package/dist/solution/BaseSales/index.js +436 -1767
  38. package/dist/solution/BaseSales/types.d.ts +1 -55
  39. package/dist/solution/BaseSales/types.js +1 -2
  40. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  41. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  42. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  43. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -7
  44. package/dist/solution/BookingByStep/index.d.ts +1 -1
  45. package/dist/solution/BookingTicket/index.d.ts +5 -21
  46. package/dist/solution/BookingTicket/index.js +56 -139
  47. package/dist/solution/BookingTicket/types.d.ts +0 -1
  48. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +83 -173
  50. package/dist/solution/Sales/index.d.ts +0 -2
  51. package/dist/solution/Sales/index.js +4 -26
  52. package/dist/solution/ScanOrder/index.js +20 -31
  53. package/dist/solution/VenueBooking/index.d.ts +0 -1
  54. package/dist/solution/VenueBooking/index.js +19 -30
  55. package/dist/types/index.d.ts +0 -1
  56. package/lib/core/index.d.ts +0 -2
  57. package/lib/core/index.js +0 -4
  58. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  59. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  60. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  61. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  62. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  63. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  64. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  65. package/lib/model/strategy/adapter/promotion/index.js +0 -2
  66. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  67. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  68. package/lib/modules/OpenData/index.d.ts +0 -2
  69. package/lib/modules/OpenData/index.js +0 -5
  70. package/lib/modules/Order/index.d.ts +8 -28
  71. package/lib/modules/Order/index.js +69 -231
  72. package/lib/modules/Order/types.d.ts +1 -35
  73. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  74. package/lib/modules/Order/utils.js +4 -11
  75. package/lib/modules/Payment/index.d.ts +0 -2
  76. package/lib/modules/Payment/index.js +12 -33
  77. package/lib/modules/Payment/types.d.ts +25 -104
  78. package/lib/modules/Payment/types.js +0 -1
  79. package/lib/modules/Payment/walletpass.d.ts +1 -38
  80. package/lib/modules/Payment/walletpass.js +21 -730
  81. package/lib/modules/Rules/index.d.ts +0 -3
  82. package/lib/modules/Rules/index.js +9 -38
  83. package/lib/server/index.d.ts +0 -25
  84. package/lib/server/index.js +31 -726
  85. package/lib/server/modules/index.d.ts +1 -1
  86. package/lib/server/modules/order/index.d.ts +4 -70
  87. package/lib/server/modules/order/index.js +69 -818
  88. package/lib/server/modules/order/types.d.ts +3 -25
  89. package/lib/server/modules/order/types.js +0 -1
  90. package/lib/server/utils/small-ticket.js +1 -1
  91. package/lib/solution/BaseSales/index.d.ts +5 -104
  92. package/lib/solution/BaseSales/index.js +27 -858
  93. package/lib/solution/BaseSales/types.d.ts +1 -55
  94. package/lib/solution/BaseSales/types.js +1 -2
  95. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  96. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  97. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  98. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -4
  99. package/lib/solution/BookingByStep/index.d.ts +1 -1
  100. package/lib/solution/BookingTicket/index.d.ts +5 -21
  101. package/lib/solution/BookingTicket/index.js +13 -64
  102. package/lib/solution/BookingTicket/types.d.ts +0 -1
  103. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  104. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +5 -37
  105. package/lib/solution/Sales/index.d.ts +0 -2
  106. package/lib/solution/Sales/index.js +6 -20
  107. package/lib/solution/ScanOrder/index.js +0 -8
  108. package/lib/solution/VenueBooking/index.d.ts +0 -1
  109. package/lib/solution/VenueBooking/index.js +0 -8
  110. package/lib/types/index.d.ts +0 -1
  111. package/package.json +1 -1
  112. package/dist/modules/Order/payment-utils.d.ts +0 -26
  113. package/dist/modules/Order/payment-utils.js +0 -225
  114. package/dist/utils/payment-number.d.ts +0 -9
  115. package/dist/utils/payment-number.js +0 -69
  116. package/lib/modules/Order/payment-utils.d.ts +0 -26
  117. package/lib/modules/Order/payment-utils.js +0 -224
  118. package/lib/utils/payment-number.d.ts +0 -9
  119. 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");
@@ -70,24 +68,6 @@ function isManualProductDiscountProduct(product) {
70
68
  }
71
69
  var ORDER_PAYMENT_STATUS_PAID = "paid";
72
70
  var ORDER_PAYMENT_STATUS_PENDING = "payment_pending";
73
- var CUSTOMER_PROMOTION_DISCOUNT_TAGS = /* @__PURE__ */ new Set([
74
- "good_pass",
75
- "product_discount_card",
76
- "discount_card"
77
- ]);
78
- function isCustomerPromotionDiscount(discount) {
79
- return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(
80
- String((discount == null ? void 0 : discount.tag) || (discount == null ? void 0 : discount.type) || "").toLowerCase()
81
- );
82
- }
83
- function markScannedDiscounts(discountList, scannedDiscountList) {
84
- const scannedIds = new Set(
85
- scannedDiscountList.map((discount) => discount == null ? void 0 : discount.id).filter((id) => id !== void 0 && id !== null).map(String)
86
- );
87
- return discountList.map(
88
- (discount) => scannedIds.has(String(discount == null ? void 0 : discount.id)) ? { ...discount, isScan: true } : discount
89
- );
90
- }
91
71
  function isVoucherPaymentRecord(payment) {
92
72
  return (payment == null ? void 0 : payment.voucher_id) !== void 0 && Number(payment.voucher_id) !== 0;
93
73
  }
@@ -103,11 +83,6 @@ function isPaidPaymentRecord(payment) {
103
83
  function isCommittedVoucherPaymentRecord(payment) {
104
84
  return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
105
85
  }
106
- function getVoucherPaymentLifecycleKey(payment) {
107
- if (!isVoucherPaymentRecord(payment))
108
- return null;
109
- return `${String(payment.voucher_id)}::${String(payment.status || "")}`;
110
- }
111
86
  var OrderModule = class extends import_BaseModule.BaseModule {
112
87
  constructor(name, version) {
113
88
  super(name || "order", version);
@@ -343,11 +318,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
343
318
  this.store.availableWalletIds = [];
344
319
  }
345
320
  this.request = this.core.getPlugin("request");
346
- this.appPlugin = this.core.getPlugin("app");
347
- if (!this.appPlugin) {
321
+ const appPlugin = this.core.getPlugin("app");
322
+ if (!appPlugin) {
348
323
  throw new Error("Order 模块需要 app 插件支持");
349
324
  }
350
- const app = this.appPlugin.getApp();
325
+ const app = appPlugin.getApp();
351
326
  this.logger = app.logger;
352
327
  this.window = this.core.getPlugin("window");
353
328
  const otherParams = options.otherParams || {};
@@ -551,7 +526,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
551
526
  });
552
527
  }
553
528
  async scanCode(code, customerId) {
554
- var _a, _b, _c, _d, _e;
529
+ var _a, _b, _c, _d;
555
530
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
556
531
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
557
532
  const rulesModule = this.store.rules;
@@ -559,7 +534,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
559
534
  return {
560
535
  type: "clientCalc",
561
536
  isAvailable: false,
562
- isAccepted: false,
563
537
  discountList: this.getDiscountList(),
564
538
  scannedDiscountList: resultDiscountList,
565
539
  unavailableReason: import_types2.UnavailableReason.Unknown
@@ -569,7 +543,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
569
543
  return {
570
544
  type: "server",
571
545
  isAvailable: false,
572
- isAccepted: false,
573
546
  discountList: this.getDiscountList(),
574
547
  scannedDiscountList: resultDiscountList,
575
548
  unavailableReasonKey
@@ -585,19 +558,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
585
558
  return {
586
559
  type: "clientCalc",
587
560
  isAvailable: true,
588
- isAccepted: true,
589
561
  discountList: this.getDiscountList(),
590
562
  scannedDiscountList: resultDiscountList
591
563
  };
592
564
  }
593
565
  const tempOrder = this.store.tempOrder;
594
566
  const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
595
- const {
596
- isAvailable,
597
- discountList: newDiscountList,
598
- evaluatedDiscountList,
599
- unavailableReason
600
- } = rulesModule.isDiscountListAvailable({
567
+ const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
601
568
  productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
602
569
  oldDiscountList: this.getDiscountList(),
603
570
  newDiscountList: withScanList,
@@ -605,25 +572,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
605
572
  holders,
606
573
  isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
607
574
  }) || { isAvailable: false, discountList: this.getDiscountList() };
608
- const shouldRetainForLater = !isAvailable && unavailableReason === import_types2.UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
609
- const normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : void 0;
610
- const retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
611
- let resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
612
- if (isAvailable && normalizedNewDiscountList) {
613
- await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(normalizedNewDiscountList));
575
+ if (isAvailable && newDiscountList) {
576
+ (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
614
577
  this.applyDiscount();
615
578
  await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
616
- resolvedDiscountList = this.getDiscountList();
617
- } else if (shouldRetainForLater && retainedDiscountList) {
618
- await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(retainedDiscountList));
619
- await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
620
- resolvedDiscountList = this.getDiscountList();
621
579
  }
622
580
  return {
623
581
  type: "clientCalc",
624
582
  isAvailable: isAvailable || false,
625
- isAccepted: Boolean(isAvailable || shouldRetainForLater),
626
- discountList: resolvedDiscountList,
583
+ discountList: newDiscountList || this.getDiscountList(),
627
584
  scannedDiscountList: resultDiscountList,
628
585
  unavailableReason
629
586
  };
@@ -1101,40 +1058,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1101
1058
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1102
1059
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1103
1060
  }
1104
- getPaymentNumberAppData(key) {
1105
- var _a, _b, _c, _d, _e;
1106
- const appPlugin = this.appPlugin;
1107
- if (!appPlugin)
1108
- return void 0;
1109
- const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1110
- if (typeof getData === "function")
1111
- return getData(key);
1112
- const app = appPlugin.getApp();
1113
- 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");
1114
- return coreData == null ? void 0 : coreData[key];
1115
- }
1116
- getPaymentNumberDevicePrefixSync() {
1117
- return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1118
- (key) => this.getPaymentNumberAppData(key)
1119
- );
1120
- }
1121
- getPaymentNumberDevicePrefixAsync() {
1122
- return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1123
- (key) => this.getPaymentNumberAppData(key)
1124
- );
1125
- }
1126
1061
  normalizePaymentSource(payment, options) {
1127
1062
  const paymentRecord = payment;
1128
1063
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1129
- const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1130
- {
1131
- ...paymentRecord,
1132
- metadata,
1133
- origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1134
- },
1135
- (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1136
- import_utils.createUuidV4
1137
- );
1064
+ if (!metadata.unique_payment_number) {
1065
+ metadata.unique_payment_number = (0, import_utils.createUuidV4)();
1066
+ }
1067
+ const normalized = {
1068
+ ...paymentRecord,
1069
+ metadata,
1070
+ origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1071
+ };
1138
1072
  if (paymentRecord.status !== void 0) {
1139
1073
  normalized.status = paymentRecord.status;
1140
1074
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -2555,36 +2489,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2555
2489
  * 用一组支付来源覆盖当前订单支付项。
2556
2490
  *
2557
2491
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2558
- * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2492
+ * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2559
2493
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2560
2494
  */
2561
2495
  setOrderPayments(payments) {
2562
2496
  const tempOrder = this.ensureTempOrder();
2563
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2564
- (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2565
- );
2497
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2566
2498
  this.persistTempOrder();
2567
2499
  return tempOrder.payments;
2568
2500
  }
2569
- /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2501
+ /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2570
2502
  addOrderPayment(payment) {
2571
- const hasPaymentNumber = String(
2572
- payment.payment_number || ""
2573
- ).trim() !== "";
2574
- return this.addOrderPaymentWithDevicePrefix(
2575
- payment,
2576
- hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2577
- );
2578
- }
2579
- /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2580
- async addOrderPaymentAsync(payment) {
2581
- const hasPaymentNumber = String(
2582
- payment.payment_number || ""
2583
- ).trim() !== "";
2584
- const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2585
- return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2586
- }
2587
- addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2588
2503
  this.logInfo("addOrderPayment", {
2589
2504
  payment
2590
2505
  });
@@ -2597,7 +2512,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2597
2512
  type: orderPaymentType,
2598
2513
  order_payment_type: orderPaymentType
2599
2514
  },
2600
- { defaultPaid: true, devicePrefix }
2515
+ { defaultPaid: true }
2601
2516
  )
2602
2517
  ]);
2603
2518
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2610,55 +2525,57 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2610
2525
  return tempOrder.payments;
2611
2526
  }
2612
2527
  /**
2613
- * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2614
- * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2528
+ * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2529
+ *
2530
+ * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2531
+ * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2615
2532
  */
2616
- async updateOrderPayment(paymentIdentity, updates, options = {}) {
2533
+ updateOrderPayment(paymentIdentity, updates) {
2617
2534
  const tempOrder = this.ensureTempOrder();
2618
2535
  const identity = String(paymentIdentity);
2619
- const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2620
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2621
- tempOrder.payments || [],
2622
- identity,
2623
- matchMode
2624
- );
2625
- if (!matchedPayment) {
2626
- throw new Error(`未找到支付项: ${identity}`);
2627
- }
2628
- let updatedPayment = null;
2629
- tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2630
- if (index !== matchedPayment.index)
2536
+ tempOrder.payments = (tempOrder.payments || []).map((payment) => {
2537
+ var _a;
2538
+ const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2539
+ const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2540
+ const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2541
+ const uuid = payment == null ? void 0 : payment.uuid;
2542
+ const matched = [
2543
+ uniquePaymentNumber,
2544
+ orderPaymentId,
2545
+ customPaymentId,
2546
+ uuid
2547
+ ].some((value) => value !== void 0 && String(value) === identity);
2548
+ if (!matched)
2631
2549
  return payment;
2632
- const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2550
+ return {
2551
+ ...payment,
2633
2552
  ...updates,
2634
- updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2635
- });
2636
- updatedPayment = nextPayment;
2637
- return nextPayment;
2553
+ metadata: {
2554
+ ...payment.metadata || {},
2555
+ ...updates.metadata || {}
2556
+ }
2557
+ };
2638
2558
  });
2639
2559
  this.persistTempOrder();
2640
- const summary = await this.recalculateSummary({ createIfMissing: true });
2641
- this.persistTempOrder();
2642
- const payments = tempOrder.payments;
2643
- return {
2644
- updated: true,
2645
- payment: payments[matchedPayment.index] || updatedPayment,
2646
- payments,
2647
- summary
2648
- };
2560
+ return tempOrder.payments;
2649
2561
  }
2650
2562
  /** 从当前订单支付项中移除指定支付项。 */
2651
2563
  deleteOrderPayment(paymentIdentity) {
2652
2564
  const tempOrder = this.ensureTempOrder();
2653
2565
  const identity = String(paymentIdentity);
2654
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2655
- tempOrder.payments || [],
2656
- identity,
2657
- "compat"
2658
- );
2659
- if (!matchedPayment)
2660
- return tempOrder.payments;
2661
- tempOrder.payments = (tempOrder.payments || []).filter((_, index) => index !== matchedPayment.index);
2566
+ tempOrder.payments = (tempOrder.payments || []).filter((payment) => {
2567
+ var _a;
2568
+ const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2569
+ const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2570
+ const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2571
+ const uuid = payment == null ? void 0 : payment.uuid;
2572
+ return ![
2573
+ uniquePaymentNumber,
2574
+ orderPaymentId,
2575
+ customPaymentId,
2576
+ uuid
2577
+ ].some((value) => value !== void 0 && String(value) === identity);
2578
+ });
2662
2579
  this.persistTempOrder();
2663
2580
  return tempOrder.payments;
2664
2581
  }
@@ -2767,10 +2684,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2767
2684
  payments.map(
2768
2685
  (payment) => this.normalizePaymentSource(
2769
2686
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2770
- {
2771
- defaultPaid: false,
2772
- devicePrefix: options == null ? void 0 : options.devicePrefix
2773
- }
2687
+ { defaultPaid: false }
2774
2688
  )
2775
2689
  )
2776
2690
  ).filter((payment) => {
@@ -2792,15 +2706,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2792
2706
  const committedVoucherPaymentIds = new Set(
2793
2707
  committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2794
2708
  );
2795
- const committedVoucherLifecycleKeys = new Set(
2796
- committedVoucherPayments.map((payment) => getVoucherPaymentLifecycleKey(payment)).filter((key) => key !== null)
2709
+ const committedVoucherIds = new Set(
2710
+ committedVoucherPayments.map((payment) => String(payment.voucher_id))
2797
2711
  );
2798
2712
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2799
2713
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2800
2714
  return false;
2801
2715
  }
2802
- const lifecycleKey = getVoucherPaymentLifecycleKey(payment);
2803
- if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
2716
+ if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2804
2717
  return false;
2805
2718
  }
2806
2719
  return true;
@@ -2822,14 +2735,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2822
2735
  });
2823
2736
  return tempOrder.payments;
2824
2737
  }
2825
- async updateVoucherOrderPaymentsAsync(payments, options) {
2826
- const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2827
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2828
- return this.updateVoucherOrderPayments(payments, {
2829
- ...options,
2830
- devicePrefix
2831
- });
2832
- }
2833
2738
  async shouldMergeProductToOrder(params) {
2834
2739
  var _a;
2835
2740
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -3728,38 +3633,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3728
3633
  await this.saveDraft();
3729
3634
  return tempOrder;
3730
3635
  }
3731
- async saveTempOrderAsDraft(params) {
3732
- var _a, _b, _c, _d, _e;
3733
- const tempOrder = this.ensureTempOrder();
3734
- this.ensureExternalSaleNumber(tempOrder);
3735
- this.persistTempOrder();
3736
- const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3737
- const payload = (0, import_utils.buildSubmitPayload)({
3738
- tempOrder,
3739
- cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3740
- platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3741
- businessCode: (params == null ? void 0 : params.businessCode) || ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code) || tempOrder.business_code,
3742
- channel: params == null ? void 0 : params.channel,
3743
- type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3744
- summary: latestSummary,
3745
- enhance: params == null ? void 0 : params.enhancePayload
3746
- });
3747
- if (!payload.created_at) {
3748
- payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3749
- }
3750
- payload.need_sync = 0;
3751
- payload.is_draft_order = 1;
3752
- this.logInfo("saveTempOrderAsDraft calling sales draft", {
3753
- orderId: payload.order_id,
3754
- externalSaleNumber: payload.external_sale_number,
3755
- productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3756
- });
3757
- return this.request.post("/order/sales/draft", payload, {
3758
- osServer: true,
3759
- customToast: () => {
3760
- }
3761
- });
3762
- }
3763
3636
  /**
3764
3637
  * 提交当前 Sales tempOrder。
3765
3638
  *
@@ -3960,13 +3833,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3960
3833
  }
3961
3834
  async syncPaymentsToOrder(params) {
3962
3835
  const tempOrder = this.ensureTempOrder();
3963
- const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3964
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3965
3836
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3966
- (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3967
- defaultPaid: false,
3968
- devicePrefix
3969
- }))
3837
+ params.payments || []
3970
3838
  );
3971
3839
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3972
3840
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -4296,7 +4164,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4296
4164
  params.forceRemote = false;
4297
4165
  }
4298
4166
  const res = await this.request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
4299
- with: ["products", "bookings", "payments", "customer", "summary", "contacts_info", "refunds"],
4167
+ with: ["products", "bookings", "payments", "customer", "summary", "contacts_info"],
4300
4168
  ...params.forceRemote ? { forceRemote: true } : {}
4301
4169
  }, { osServer: true });
4302
4170
  if (res.code === 200) {
@@ -4342,12 +4210,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4342
4210
  }
4343
4211
  }
4344
4212
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4345
- const sourceLastOrderInfo = raw.lastOrderInfo || raw;
4346
- const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4347
- const syntheticIdentityOptions = {
4348
- isDraftOrder,
4349
- externalSaleNumber: nextTempOrder.external_sale_number
4350
- };
4351
4213
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4352
4214
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4353
4215
  this.store.tempOrder = nextTempOrder;
@@ -4368,14 +4230,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4368
4230
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4369
4231
  }
4370
4232
  };
4371
- this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4372
- sourceLastOrderInfo,
4373
- syntheticIdentityOptions
4374
- );
4375
- const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4376
- if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4377
- this.store.syncState = "local";
4378
- }
4233
+ this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4379
4234
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4380
4235
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4381
4236
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -4488,13 +4343,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4488
4343
  }
4489
4344
  normalizeTempOrderForRuntime(raw, options) {
4490
4345
  var _a, _b;
4491
- const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4492
4346
  const nextTempOrder = {
4493
4347
  ...this.createDefaultTempOrderInstance(),
4494
- ...runtimeRaw || {}
4348
+ ...raw || {}
4495
4349
  };
4496
- 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) {
4497
- nextTempOrder.order_id = runtimeRaw.id;
4350
+ 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) {
4351
+ nextTempOrder.order_id = raw.id;
4498
4352
  }
4499
4353
  delete nextTempOrder.summary;
4500
4354
  delete nextTempOrder.lastOrderInfo;
@@ -4562,22 +4416,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4562
4416
  nextTempOrder.vouchers = raw.vouchers || [];
4563
4417
  return nextTempOrder;
4564
4418
  }
4565
- isSyntheticDraftOrderIdForRuntime(record, options) {
4566
- const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4567
- const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4568
- const orderId = record == null ? void 0 : record.order_id;
4569
- return Boolean(
4570
- isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4571
- );
4572
- }
4573
- withoutSyntheticDraftOrderIdForRuntime(record, options) {
4574
- if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4575
- return record;
4576
- return {
4577
- ...record,
4578
- order_id: null
4579
- };
4580
- }
4581
4419
  hydrateLinkedBookingIdentity(tempOrder) {
4582
4420
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4583
4421
  const productByUid = /* @__PURE__ */ new Map();
@@ -165,8 +165,6 @@ export interface OrderCustomerChangePayload {
165
165
  }
166
166
  export interface OrderScanCodeResult {
167
167
  isAvailable: boolean;
168
- /** 卡券已加入当前订单折扣列表,但不一定能立即应用。 */
169
- isAccepted?: boolean;
170
168
  discountList: Discount[];
171
169
  scannedDiscountList: Discount[];
172
170
  type: 'server' | 'clientCalc';
@@ -488,8 +486,6 @@ export interface SubmitSalesOrderParams {
488
486
  export interface PaymentItemData {
489
487
  /** 当前支付项的唯一 ID */
490
488
  uuid: string;
491
- /** 支付项稳定唯一号 */
492
- payment_number?: string;
493
489
  /** 当前支付方式付出去多少钱 */
494
490
  amount: string;
495
491
  /** 支付类型代码 */
@@ -512,22 +508,13 @@ export interface PaymentItemData {
512
508
  export interface OrderPaymentMetadata {
513
509
  rounding_rule?: Record<string, any>;
514
510
  unique_payment_number?: string;
515
- /** 刷卡机设备快照;OS 不解析内部字段,仅透传并持久化 */
516
- card_reader_snapshot?: Record<string, unknown>;
517
511
  shop_wallet_pass_id?: number | string;
518
512
  actual_paid_amount?: number | string;
519
513
  change_given_amount?: number | string;
520
- transactions?: OrderPaymentTransaction[];
521
514
  [key: string]: any;
522
515
  }
523
- export interface OrderPaymentTransaction {
524
- number: string;
525
- status: 'success' | 'fail';
526
- }
527
516
  export interface OrderPaymentData {
528
517
  order_payment_id?: number | string;
529
- /** 支付项稳定唯一号;历史支付项允许缺失 */
530
- payment_number?: string;
531
518
  amount: string;
532
519
  code: string;
533
520
  custom_payment_id: number;
@@ -554,15 +541,6 @@ export interface OrderPaymentData {
554
541
  created_at?: string;
555
542
  updated_at?: string;
556
543
  }
557
- export interface OrderPaymentUpdateOptions {
558
- matchBy?: 'payment_number' | 'compat' | 'legacy';
559
- }
560
- export interface OrderPaymentUpdateResult {
561
- updated: boolean;
562
- payment: OrderPaymentData | null;
563
- payments: OrderPaymentData[];
564
- summary: OrderSummary | null;
565
- }
566
544
  export type OrderPaymentSource = PaymentItem | OrderPaymentData | Record<string, any>;
567
545
  export interface MapOrderPaymentsOptions {
568
546
  includeVoided?: boolean;
@@ -713,14 +691,6 @@ export interface OrderModuleAPI {
713
691
  channel?: string;
714
692
  type?: string;
715
693
  }) => OrderSubmitPayload;
716
- saveTempOrderAsDraft: <T = any>(params?: {
717
- cacheId?: string;
718
- platform?: string;
719
- businessCode?: string;
720
- channel?: string;
721
- type?: string;
722
- enhancePayload?: SubmitPayloadEnhancer;
723
- }) => Promise<T>;
724
694
  applyLocalPrintOrderNumbers: (order?: Record<string, any> | null) => Promise<OrderTempOrder>;
725
695
  getTempOrderNote: () => string;
726
696
  updateTempOrderNote: {
@@ -778,15 +748,11 @@ export interface OrderModuleAPI {
778
748
  getOrderPayments: () => OrderPaymentData[];
779
749
  setOrderPayments: (payments: OrderPaymentSource[]) => OrderPaymentData[];
780
750
  addOrderPayment: (payment: OrderPaymentSource) => OrderPaymentData[];
781
- addOrderPaymentAsync: (payment: OrderPaymentSource) => Promise<OrderPaymentData[]>;
782
- updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>, options?: OrderPaymentUpdateOptions) => Promise<OrderPaymentUpdateResult>;
751
+ updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>) => OrderPaymentData[];
783
752
  deleteOrderPayment: (paymentIdentity: string | number) => OrderPaymentData[];
784
753
  updateVoucherOrderPayments: (payments: OrderPaymentSource[], options?: {
785
754
  status?: 'paid' | 'payment_pending';
786
755
  }) => OrderPaymentData[];
787
- updateVoucherOrderPaymentsAsync: (payments: OrderPaymentSource[], options?: {
788
- status?: 'paid' | 'payment_pending';
789
- }) => Promise<OrderPaymentData[]>;
790
756
  confirmPendingVoucherPayments: (options?: {
791
757
  persist?: boolean;
792
758
  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
  */