@pisell/pisellos 2.2.265 → 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 (66) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  3. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  4. package/dist/modules/Order/index.d.ts +8 -27
  5. package/dist/modules/Order/index.js +490 -743
  6. package/dist/modules/Order/types.d.ts +1 -33
  7. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  8. package/dist/modules/Order/utils.js +5 -8
  9. package/dist/modules/Payment/index.d.ts +0 -2
  10. package/dist/modules/Payment/index.js +50 -79
  11. package/dist/modules/Payment/types.d.ts +27 -29
  12. package/dist/modules/Payment/types.js +3 -5
  13. package/dist/server/index.d.ts +0 -16
  14. package/dist/server/index.js +1036 -1933
  15. package/dist/server/modules/order/index.d.ts +4 -49
  16. package/dist/server/modules/order/index.js +695 -1574
  17. package/dist/server/modules/order/types.d.ts +3 -11
  18. package/dist/server/modules/order/types.js +1 -1
  19. package/dist/solution/BaseSales/index.d.ts +11 -42
  20. package/dist/solution/BaseSales/index.js +385 -676
  21. package/dist/solution/BaseSales/utils/cartPromotion.js +5 -3
  22. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  23. package/dist/solution/BookingTicket/index.d.ts +1 -1
  24. package/dist/solution/BookingTicket/index.js +1 -2
  25. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  26. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  27. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  28. package/dist/solution/Sales/index.d.ts +0 -1
  29. package/dist/solution/Sales/index.js +2 -10
  30. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  31. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  32. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  33. package/lib/modules/Order/index.d.ts +8 -27
  34. package/lib/modules/Order/index.js +69 -184
  35. package/lib/modules/Order/types.d.ts +1 -33
  36. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  37. package/lib/modules/Order/utils.js +3 -5
  38. package/lib/modules/Payment/index.d.ts +0 -2
  39. package/lib/modules/Payment/index.js +13 -34
  40. package/lib/modules/Payment/types.d.ts +27 -29
  41. package/lib/modules/Payment/types.js +3 -3
  42. package/lib/server/index.d.ts +0 -16
  43. package/lib/server/index.js +18 -670
  44. package/lib/server/modules/order/index.d.ts +4 -49
  45. package/lib/server/modules/order/index.js +66 -657
  46. package/lib/server/modules/order/types.d.ts +3 -11
  47. package/lib/solution/BaseSales/index.d.ts +11 -42
  48. package/lib/solution/BaseSales/index.js +35 -214
  49. package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
  50. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  51. package/lib/solution/BookingTicket/index.d.ts +1 -1
  52. package/lib/solution/BookingTicket/index.js +1 -2
  53. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  54. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  55. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  56. package/lib/solution/Sales/index.d.ts +0 -1
  57. package/lib/solution/Sales/index.js +3 -5
  58. package/package.json +2 -2
  59. package/dist/modules/Order/payment-utils.d.ts +0 -26
  60. package/dist/modules/Order/payment-utils.js +0 -225
  61. package/dist/utils/payment-number.d.ts +0 -9
  62. package/dist/utils/payment-number.js +0 -69
  63. package/lib/modules/Order/payment-utils.d.ts +0 -26
  64. package/lib/modules/Order/payment-utils.js +0 -224
  65. package/lib/utils/payment-number.d.ts +0 -9
  66. 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");
@@ -315,11 +313,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
315
313
  this.store.availableWalletIds = [];
316
314
  }
317
315
  this.request = this.core.getPlugin("request");
318
- this.appPlugin = this.core.getPlugin("app");
319
- if (!this.appPlugin) {
316
+ const appPlugin = this.core.getPlugin("app");
317
+ if (!appPlugin) {
320
318
  throw new Error("Order 模块需要 app 插件支持");
321
319
  }
322
- const app = this.appPlugin.getApp();
320
+ const app = appPlugin.getApp();
323
321
  this.logger = app.logger;
324
322
  this.window = this.core.getPlugin("window");
325
323
  const otherParams = options.otherParams || {};
@@ -1055,40 +1053,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1055
1053
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1056
1054
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1057
1055
  }
1058
- getPaymentNumberAppData(key) {
1059
- var _a, _b, _c, _d, _e;
1060
- const appPlugin = this.appPlugin;
1061
- if (!appPlugin)
1062
- return void 0;
1063
- const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1064
- if (typeof getData === "function")
1065
- return getData(key);
1066
- const app = appPlugin.getApp();
1067
- 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");
1068
- return coreData == null ? void 0 : coreData[key];
1069
- }
1070
- getPaymentNumberDevicePrefixSync() {
1071
- return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1072
- (key) => this.getPaymentNumberAppData(key)
1073
- );
1074
- }
1075
- getPaymentNumberDevicePrefixAsync() {
1076
- return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1077
- (key) => this.getPaymentNumberAppData(key)
1078
- );
1079
- }
1080
1056
  normalizePaymentSource(payment, options) {
1081
1057
  const paymentRecord = payment;
1082
1058
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1083
- const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1084
- {
1085
- ...paymentRecord,
1086
- metadata,
1087
- origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1088
- },
1089
- (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1090
- import_utils.createUuidV4
1091
- );
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
+ };
1092
1067
  if (paymentRecord.status !== void 0) {
1093
1068
  normalized.status = paymentRecord.status;
1094
1069
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -2509,36 +2484,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2509
2484
  * 用一组支付来源覆盖当前订单支付项。
2510
2485
  *
2511
2486
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2512
- * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2487
+ * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2513
2488
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2514
2489
  */
2515
2490
  setOrderPayments(payments) {
2516
2491
  const tempOrder = this.ensureTempOrder();
2517
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2518
- (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2519
- );
2492
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2520
2493
  this.persistTempOrder();
2521
2494
  return tempOrder.payments;
2522
2495
  }
2523
- /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2496
+ /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2524
2497
  addOrderPayment(payment) {
2525
- const hasPaymentNumber = String(
2526
- payment.payment_number || ""
2527
- ).trim() !== "";
2528
- return this.addOrderPaymentWithDevicePrefix(
2529
- payment,
2530
- hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2531
- );
2532
- }
2533
- /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2534
- async addOrderPaymentAsync(payment) {
2535
- const hasPaymentNumber = String(
2536
- payment.payment_number || ""
2537
- ).trim() !== "";
2538
- const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2539
- return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2540
- }
2541
- addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2542
2498
  this.logInfo("addOrderPayment", {
2543
2499
  payment
2544
2500
  });
@@ -2551,7 +2507,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2551
2507
  type: orderPaymentType,
2552
2508
  order_payment_type: orderPaymentType
2553
2509
  },
2554
- { defaultPaid: true, devicePrefix }
2510
+ { defaultPaid: true }
2555
2511
  )
2556
2512
  ]);
2557
2513
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2564,55 +2520,57 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2564
2520
  return tempOrder.payments;
2565
2521
  }
2566
2522
  /**
2567
- * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2568
- * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2523
+ * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2524
+ *
2525
+ * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2526
+ * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2569
2527
  */
2570
- async updateOrderPayment(paymentIdentity, updates, options = {}) {
2528
+ updateOrderPayment(paymentIdentity, updates) {
2571
2529
  const tempOrder = this.ensureTempOrder();
2572
2530
  const identity = String(paymentIdentity);
2573
- const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2574
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2575
- tempOrder.payments || [],
2576
- identity,
2577
- matchMode
2578
- );
2579
- if (!matchedPayment) {
2580
- throw new Error(`未找到支付项: ${identity}`);
2581
- }
2582
- let updatedPayment = null;
2583
- tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2584
- 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)
2585
2544
  return payment;
2586
- const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2545
+ return {
2546
+ ...payment,
2587
2547
  ...updates,
2588
- updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2589
- });
2590
- updatedPayment = nextPayment;
2591
- return nextPayment;
2548
+ metadata: {
2549
+ ...payment.metadata || {},
2550
+ ...updates.metadata || {}
2551
+ }
2552
+ };
2592
2553
  });
2593
2554
  this.persistTempOrder();
2594
- const summary = await this.recalculateSummary({ createIfMissing: true });
2595
- this.persistTempOrder();
2596
- const payments = tempOrder.payments;
2597
- return {
2598
- updated: true,
2599
- payment: payments[matchedPayment.index] || updatedPayment,
2600
- payments,
2601
- summary
2602
- };
2555
+ return tempOrder.payments;
2603
2556
  }
2604
2557
  /** 从当前订单支付项中移除指定支付项。 */
2605
2558
  deleteOrderPayment(paymentIdentity) {
2606
2559
  const tempOrder = this.ensureTempOrder();
2607
2560
  const identity = String(paymentIdentity);
2608
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2609
- tempOrder.payments || [],
2610
- identity,
2611
- "compat"
2612
- );
2613
- if (!matchedPayment)
2614
- return tempOrder.payments;
2615
- 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
+ });
2616
2574
  this.persistTempOrder();
2617
2575
  return tempOrder.payments;
2618
2576
  }
@@ -2721,10 +2679,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2721
2679
  payments.map(
2722
2680
  (payment) => this.normalizePaymentSource(
2723
2681
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2724
- {
2725
- defaultPaid: false,
2726
- devicePrefix: options == null ? void 0 : options.devicePrefix
2727
- }
2682
+ { defaultPaid: false }
2728
2683
  )
2729
2684
  )
2730
2685
  ).filter((payment) => {
@@ -2775,14 +2730,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2775
2730
  });
2776
2731
  return tempOrder.payments;
2777
2732
  }
2778
- async updateVoucherOrderPaymentsAsync(payments, options) {
2779
- const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2780
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2781
- return this.updateVoucherOrderPayments(payments, {
2782
- ...options,
2783
- devicePrefix
2784
- });
2785
- }
2786
2733
  async shouldMergeProductToOrder(params) {
2787
2734
  var _a;
2788
2735
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -2843,7 +2790,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2843
2790
  * await this.appendProductLineToTempOrder(tempOrder, { product_id: 1, num: 1 }, booking);
2844
2791
  */
2845
2792
  async appendProductLineToTempOrder(tempOrder, product, booking) {
2846
- var _a, _b;
2793
+ var _a, _b, _c, _d;
2847
2794
  const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
2848
2795
  const productToAdd = (linked == null ? void 0 : linked.product) || product;
2849
2796
  const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
@@ -2854,7 +2801,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2854
2801
  productToAdd,
2855
2802
  (0, import_utils3.normalizeOrderProduct)(productToAdd)
2856
2803
  );
2857
- 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);
2858
2810
  if (incomingBookingUid !== void 0 && incomingBookingUid !== null && String(incomingBookingUid) !== "") {
2859
2811
  normalizedIncoming.booking_uid = String(incomingBookingUid);
2860
2812
  normalizedIncoming.metadata = {
@@ -2870,7 +2822,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2870
2822
  );
2871
2823
  const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
2872
2824
  const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
2873
- const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
2825
+ const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid || isWeighingProduct;
2874
2826
  const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
2875
2827
  var _a2;
2876
2828
  if (this.hasGoodPassDiscount(item))
@@ -2922,7 +2874,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2922
2874
  tempOrder.products = [...tempOrder.products, normalizedIncoming];
2923
2875
  } else {
2924
2876
  const targetProduct = matchedProduct;
2925
- 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;
2926
2878
  const normalizedProduct = (0, import_utils.mergeOrderProductDisplayFields)(
2927
2879
  targetProduct,
2928
2880
  (0, import_utils3.normalizeOrderProduct)({
@@ -3613,38 +3565,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3613
3565
  await this.saveDraft();
3614
3566
  return tempOrder;
3615
3567
  }
3616
- async saveTempOrderAsDraft(params) {
3617
- var _a, _b, _c, _d, _e;
3618
- const tempOrder = this.ensureTempOrder();
3619
- this.ensureExternalSaleNumber(tempOrder);
3620
- this.persistTempOrder();
3621
- const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3622
- const payload = (0, import_utils.buildSubmitPayload)({
3623
- tempOrder,
3624
- cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3625
- platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3626
- businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
3627
- channel: params == null ? void 0 : params.channel,
3628
- type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3629
- summary: latestSummary,
3630
- enhance: params == null ? void 0 : params.enhancePayload
3631
- });
3632
- if (!payload.created_at) {
3633
- payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3634
- }
3635
- payload.need_sync = 0;
3636
- payload.is_draft_order = 1;
3637
- this.logInfo("saveTempOrderAsDraft calling sales draft", {
3638
- orderId: payload.order_id,
3639
- externalSaleNumber: payload.external_sale_number,
3640
- productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3641
- });
3642
- return this.request.post("/order/sales/draft", payload, {
3643
- osServer: true,
3644
- customToast: () => {
3645
- }
3646
- });
3647
- }
3648
3568
  /**
3649
3569
  * 提交当前 Sales tempOrder。
3650
3570
  *
@@ -3845,13 +3765,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3845
3765
  }
3846
3766
  async syncPaymentsToOrder(params) {
3847
3767
  const tempOrder = this.ensureTempOrder();
3848
- const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3849
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3850
3768
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3851
- (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3852
- defaultPaid: false,
3853
- devicePrefix
3854
- }))
3769
+ params.payments || []
3855
3770
  );
3856
3771
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3857
3772
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -4227,12 +4142,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4227
4142
  }
4228
4143
  }
4229
4144
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4230
- const sourceLastOrderInfo = raw.lastOrderInfo || raw;
4231
- const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4232
- const syntheticIdentityOptions = {
4233
- isDraftOrder,
4234
- externalSaleNumber: nextTempOrder.external_sale_number
4235
- };
4236
4145
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4237
4146
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4238
4147
  this.store.tempOrder = nextTempOrder;
@@ -4253,14 +4162,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4253
4162
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4254
4163
  }
4255
4164
  };
4256
- this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4257
- sourceLastOrderInfo,
4258
- syntheticIdentityOptions
4259
- );
4260
- const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4261
- if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4262
- this.store.syncState = "local";
4263
- }
4165
+ this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4264
4166
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4265
4167
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4266
4168
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -4373,13 +4275,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4373
4275
  }
4374
4276
  normalizeTempOrderForRuntime(raw, options) {
4375
4277
  var _a, _b;
4376
- const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4377
4278
  const nextTempOrder = {
4378
4279
  ...this.createDefaultTempOrderInstance(),
4379
- ...runtimeRaw || {}
4280
+ ...raw || {}
4380
4281
  };
4381
- 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) {
4382
- 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;
4383
4284
  }
4384
4285
  delete nextTempOrder.summary;
4385
4286
  delete nextTempOrder.lastOrderInfo;
@@ -4447,22 +4348,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4447
4348
  nextTempOrder.vouchers = raw.vouchers || [];
4448
4349
  return nextTempOrder;
4449
4350
  }
4450
- isSyntheticDraftOrderIdForRuntime(record, options) {
4451
- const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4452
- const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4453
- const orderId = record == null ? void 0 : record.order_id;
4454
- return Boolean(
4455
- isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4456
- );
4457
- }
4458
- withoutSyntheticDraftOrderIdForRuntime(record, options) {
4459
- if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4460
- return record;
4461
- return {
4462
- ...record,
4463
- order_id: null
4464
- };
4465
- }
4466
4351
  hydrateLinkedBookingIdentity(tempOrder) {
4467
4352
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4468
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;
@@ -965,9 +965,6 @@ function buildSubmitPayload(params) {
965
965
  ...tempOrderRest,
966
966
  customer_id: tempOrder.customer_id ?? 1,
967
967
  customer_name: tempOrder.customer_name || "Walk-In",
968
- country_calling_code: String(tempOrder.country_calling_code ?? ""),
969
- phone: String(tempOrder.phone ?? ""),
970
- email: String(tempOrder.email ?? ""),
971
968
  order_number: tempOrder.order_number ?? null,
972
969
  shop_order_number: tempOrder.shop_order_number ?? null,
973
970
  shop_full_order_number: tempOrder.shop_full_order_number ?? null,
@@ -1023,7 +1020,9 @@ function mapPaymentItemToOrderPayment(paymentItem) {
1023
1020
  const item = paymentItem;
1024
1021
  const customPaymentId = item.custom_payment_id ?? item.id;
1025
1022
  const metadata = item.metadata && typeof item.metadata === "object" ? { ...item.metadata } : {};
1026
- const paymentNumber = item.payment_number;
1023
+ if (item.uuid && !metadata.unique_payment_number) {
1024
+ metadata.unique_payment_number = String(item.uuid);
1025
+ }
1027
1026
  const paymentMetadataKeys = [
1028
1027
  "rounding_rule",
1029
1028
  "shop_wallet_pass_id",
@@ -1040,7 +1039,6 @@ function mapPaymentItemToOrderPayment(paymentItem) {
1040
1039
  const createdAt = item.created_at ?? timestamp;
1041
1040
  return {
1042
1041
  ...item.order_payment_id !== void 0 ? { order_payment_id: item.order_payment_id } : {},
1043
- ...paymentNumber !== void 0 && paymentNumber !== null && paymentNumber !== "" ? { payment_number: String(paymentNumber) } : {},
1044
1042
  amount: String(item.amount ?? "0.00"),
1045
1043
  code: String(item.code || ""),
1046
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
  */
@@ -31,9 +31,6 @@ var import_cash = require("./cash");
31
31
  var import_eftpos = require("./eftpos");
32
32
  var import_walletpass = require("./walletpass");
33
33
  var import_decimal = require("decimal.js");
34
- var import_payment_utils = require("../Order/payment-utils");
35
- var import_utils2 = require("../Order/utils");
36
- var import_payment_number = require("../../utils/payment-number");
37
34
  __reExport(Payment_exports, require("./types"), module.exports);
38
35
  function formatAmount(amount) {
39
36
  try {
@@ -115,15 +112,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
115
112
  this.store = options.store;
116
113
  this.otherParams = options.otherParams || {};
117
114
  this.request = core.getPlugin("request");
118
- this.appPlugin = core.getPlugin("app");
115
+ const appPlugin = core.getPlugin("app");
119
116
  this.window = core.getPlugin("window");
120
117
  if (!this.request) {
121
118
  throw new Error("支付模块需要 request 插件支持");
122
119
  }
123
- if (!this.appPlugin) {
120
+ if (!appPlugin) {
124
121
  throw new Error("支付模块需要 app 插件支持");
125
122
  }
126
- this.app = this.appPlugin.getApp();
123
+ this.app = appPlugin.getApp();
127
124
  this.dbManager = this.app.dbManager;
128
125
  this.logger = this.app.logger;
129
126
  this.registerNetworkHandlers();
@@ -139,14 +136,6 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
139
136
  updateOtherParams(params) {
140
137
  this.otherParams = params || {};
141
138
  }
142
- getPaymentNumberAppData(key) {
143
- var _a, _b, _c, _d, _e, _f, _g;
144
- const getData = (_b = (_a = this.appPlugin) == null ? void 0 : _a.getData) == null ? void 0 : _b.call(_a);
145
- if (typeof getData === "function")
146
- return getData(key);
147
- const coreData = (_g = (_e = (_d = (_c = this.app) == null ? void 0 : _c.models) == null ? void 0 : _d.getStore) == null ? void 0 : (_f = _e.call(_d)).getDataByModel) == null ? void 0 : _g.call(_f, "core", "core");
148
- return coreData == null ? void 0 : coreData[key];
149
- }
150
139
  /**
151
140
  * 记录信息日志
152
141
  */
@@ -532,20 +521,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
532
521
  });
533
522
  throw new Error(warningMessage);
534
523
  }
535
- const paymentUuid = paymentItem.uuid || ((_a = paymentItem.metadata) == null ? void 0 : _a.unique_payment_number) || (0, import_utils.getUniqueId)("payment_");
524
+ let paymentUuid;
525
+ if ((_a = paymentItem.metadata) == null ? void 0 : _a.unique_payment_number) {
526
+ paymentUuid = paymentItem.metadata.unique_payment_number;
527
+ } else {
528
+ paymentUuid = (0, import_utils.getUniqueId)("payment_");
529
+ }
536
530
  const currentTime = formatDateTime(/* @__PURE__ */ new Date());
537
- const hasPaymentNumber = String(paymentItem.payment_number || "").trim() !== "";
538
- const paymentNumberDevicePrefix = hasPaymentNumber ? "LOCAL" : await (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
539
- (key) => this.getPaymentNumberAppData(key)
540
- );
541
- const paymentNumber = (0, import_payment_utils.ensureOrderPaymentNumber)(
542
- paymentItem,
543
- paymentNumberDevicePrefix,
544
- import_utils2.createUuidV4
545
- ).payment_number;
546
531
  const newPaymentItem = {
547
532
  uuid: paymentUuid,
548
- payment_number: paymentNumber,
549
533
  custom_payment_id: normalizeCustomPaymentId(paymentItem),
550
534
  name: paymentItem.name,
551
535
  code: paymentItem.code,
@@ -565,8 +549,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
565
549
  updated_at: currentTime,
566
550
  // 更新时间
567
551
  metadata: {
568
- ...paymentItem.metadata
552
+ ...paymentItem.metadata,
569
553
  // 保留传入的所有 metadata 字段
554
+ unique_payment_number: paymentUuid
555
+ // 设置唯一支付号为支付项的 uuid
570
556
  }
571
557
  };
572
558
  order.payment.push(newPaymentItem);
@@ -781,12 +767,6 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
781
767
  if ("amount" in formattedParams && formattedParams.amount !== void 0) {
782
768
  formattedParams.amount = formatAmount(formattedParams.amount);
783
769
  }
784
- if (formattedParams.metadata && typeof formattedParams.metadata === "object") {
785
- formattedParams.metadata = {
786
- ...paymentItem.metadata || {},
787
- ...formattedParams.metadata
788
- };
789
- }
790
770
  Object.assign(paymentItem, formattedParams);
791
771
  this.recalculateOrderAmount(order);
792
772
  await this.dbManager.update("order", order);
@@ -844,7 +824,6 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
844
824
  const paymentData = {
845
825
  payments: order.payment.map((payment) => ({
846
826
  uuid: payment.uuid,
847
- payment_number: payment.payment_number,
848
827
  amount: payment.amount,
849
828
  code: payment.code,
850
829
  custom_payment_id: payment.custom_payment_id,
@@ -1088,7 +1067,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
1088
1067
  roundedValue = this.standardRound(baseValue, true);
1089
1068
  break;
1090
1069
  case import_types.RoundingRule.StandardDown:
1091
- case "standard_down":
1070
+ case "standard_rounding_midpoint_down":
1092
1071
  roundedValue = this.standardRound(baseValue, false);
1093
1072
  break;
1094
1073
  case import_types.RoundingRule.AlwaysUp: