@pisell/pisellos 2.2.192 → 2.2.194

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 (41) hide show
  1. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  2. package/dist/modules/Order/index.d.ts +12 -9
  3. package/dist/modules/Order/index.js +503 -580
  4. package/dist/modules/Order/types.d.ts +5 -5
  5. package/dist/modules/Order/utils/manualProductDiscount.js +1 -1
  6. package/dist/modules/Order/utils.js +3 -3
  7. package/dist/modules/Payment/utils.js +2 -1
  8. package/dist/modules/SalesSummary/index.d.ts +0 -25
  9. package/dist/modules/SalesSummary/types.d.ts +1 -0
  10. package/dist/modules/SalesSummary/utils.d.ts +2 -25
  11. package/dist/modules/SalesSummary/utils.js +529 -160
  12. package/dist/server/index.d.ts +8 -1
  13. package/dist/server/index.js +653 -466
  14. package/dist/server/modules/order/index.d.ts +3 -2
  15. package/dist/server/modules/order/index.js +68 -52
  16. package/dist/server/modules/products/index.js +4 -4
  17. package/dist/solution/BaseSales/index.d.ts +2 -1
  18. package/dist/solution/BaseSales/index.js +116 -122
  19. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  20. package/dist/solution/ScanOrder/index.js +3 -1
  21. package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
  22. package/lib/modules/Order/index.d.ts +12 -9
  23. package/lib/modules/Order/index.js +124 -120
  24. package/lib/modules/Order/types.d.ts +5 -5
  25. package/lib/modules/Order/utils/manualProductDiscount.js +1 -1
  26. package/lib/modules/Order/utils.js +4 -4
  27. package/lib/modules/Payment/utils.js +2 -1
  28. package/lib/modules/SalesSummary/index.d.ts +0 -25
  29. package/lib/modules/SalesSummary/types.d.ts +1 -0
  30. package/lib/modules/SalesSummary/utils.d.ts +2 -25
  31. package/lib/modules/SalesSummary/utils.js +420 -92
  32. package/lib/server/index.d.ts +8 -1
  33. package/lib/server/index.js +145 -26
  34. package/lib/server/modules/order/index.d.ts +3 -2
  35. package/lib/server/modules/order/index.js +25 -15
  36. package/lib/server/modules/products/index.js +0 -4
  37. package/lib/solution/BaseSales/index.d.ts +2 -1
  38. package/lib/solution/BaseSales/index.js +53 -16
  39. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  40. package/lib/solution/ScanOrder/index.js +3 -1
  41. package/package.json +1 -1
@@ -45,7 +45,21 @@ var import_Rules = require("../Rules");
45
45
  var import_types2 = require("../Rules/types");
46
46
  var import_decimal = __toESM(require("decimal.js"));
47
47
  var import_lodash_es = require("lodash-es");
48
- var LOCAL_ORDER_STORE_NAME = "orders";
48
+ function normalizeDiscountListSignature(discountList) {
49
+ return (discountList || []).map((item) => ({
50
+ type: (item == null ? void 0 : item.type) ?? "",
51
+ discount_id: (item == null ? void 0 : item.discount_id) ?? null,
52
+ order_discount_id: (item == null ? void 0 : item.order_discount_id) ?? null,
53
+ amount: new import_decimal.default(Number(item == null ? void 0 : item.amount) || 0).toFixed(2)
54
+ }));
55
+ }
56
+ function isSameDiscountList(left, right) {
57
+ if (!Array.isArray(left) || !Array.isArray(right))
58
+ return false;
59
+ return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(
60
+ normalizeDiscountListSignature(right)
61
+ );
62
+ }
49
63
  var OrderModule = class extends import_BaseModule.BaseModule {
50
64
  constructor(name, version) {
51
65
  super(name || "order", version);
@@ -108,6 +122,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
108
122
  var _a, _b, _c;
109
123
  if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
110
124
  return product;
125
+ const discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
126
+ const hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== void 0 && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every((discount) => (discount == null ? void 0 : discount.order_discount_id) !== void 0 && (discount == null ? void 0 : discount.order_discount_id) !== null);
127
+ if (hasOnlyPersistedDiscountSnapshots) {
128
+ return product;
129
+ }
111
130
  const totalPerUnitDiscount = (0, import_utils.resolveEffectivePerUnitDiscount)(product);
112
131
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
113
132
  const sourcePrice = ((_b = product.metadata) == null ? void 0 : _b.source_product_price) ?? (((_c = product.metadata) == null ? void 0 : _c.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
@@ -141,7 +160,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
141
160
  }
142
161
  const app = appPlugin.getApp();
143
162
  this.logger = app.logger;
144
- this.dbManager = app.sqlite;
145
163
  this.window = this.core.getPlugin("window");
146
164
  const otherParams = options.otherParams || {};
147
165
  this.cacheId = otherParams.cacheId;
@@ -577,108 +595,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
577
595
  const paidCount = paidPaymentsCount > 0 ? paidPaymentsCount : payments.length;
578
596
  return `${baseToken}_payment_${paidCount}`;
579
597
  }
580
- hasLocalDatabase() {
581
- return !!this.dbManager;
582
- }
583
- buildLocalOrderRecord(tempOrder) {
584
- const externalSaleNumber = this.ensureExternalSaleNumber(tempOrder);
585
- return {
586
- ...tempOrder,
587
- id: tempOrder.order_id ?? externalSaleNumber,
588
- external_sale_number: externalSaleNumber,
589
- summary: this.store.summary || (0, import_utils.createEmptySummary)(),
590
- lastOrderInfo: this.store.lastOrderInfo
591
- };
592
- }
593
- async getLocalOrderByOrderId(orderId) {
594
- var _a, _b, _c, _d;
595
- if (!this.dbManager || orderId === void 0 || orderId === null)
596
- return null;
597
- try {
598
- const direct = await ((_b = (_a = this.dbManager).get) == null ? void 0 : _b.call(
599
- _a,
600
- LOCAL_ORDER_STORE_NAME,
601
- orderId
602
- ));
603
- if (direct)
604
- return direct;
605
- const orders = await ((_d = (_c = this.dbManager).getAll) == null ? void 0 : _d.call(_c, LOCAL_ORDER_STORE_NAME));
606
- return (orders || []).find(
607
- (order) => String(order == null ? void 0 : order.order_id) === String(orderId)
608
- ) || null;
609
- } catch (error) {
610
- this.logWarning("getLocalOrderByOrderId failed", {
611
- orderId,
612
- error: error instanceof Error ? error.message : String(error)
613
- });
614
- return null;
615
- }
616
- }
617
- async getLocalOrderByOrderNumber(orderNumber) {
618
- var _a, _b, _c, _d;
619
- if (!this.dbManager || !orderNumber)
620
- return null;
621
- try {
622
- const direct = await ((_b = (_a = this.dbManager).get) == null ? void 0 : _b.call(
623
- _a,
624
- LOCAL_ORDER_STORE_NAME,
625
- orderNumber
626
- ));
627
- if (direct)
628
- return direct;
629
- const orders = await ((_d = (_c = this.dbManager).getAll) == null ? void 0 : _d.call(_c, LOCAL_ORDER_STORE_NAME));
630
- return (orders || []).find(
631
- (order) => String(order == null ? void 0 : order.order_number) === String(orderNumber)
632
- ) || null;
633
- } catch (error) {
634
- this.logWarning("getLocalOrderByOrderNumber failed", {
635
- orderNumber,
636
- error: error instanceof Error ? error.message : String(error)
637
- });
638
- return null;
639
- }
640
- }
641
- async getLocalOrderByExternalSaleNumber(externalSaleNumber) {
642
- var _a, _b, _c, _d;
643
- if (!this.dbManager || !externalSaleNumber)
644
- return null;
645
- try {
646
- const direct = await ((_b = (_a = this.dbManager).get) == null ? void 0 : _b.call(
647
- _a,
648
- LOCAL_ORDER_STORE_NAME,
649
- externalSaleNumber
650
- ));
651
- if (direct)
652
- return direct;
653
- const orders = await ((_d = (_c = this.dbManager).getAll) == null ? void 0 : _d.call(_c, LOCAL_ORDER_STORE_NAME));
654
- return (orders || []).find(
655
- (order) => String(order == null ? void 0 : order.external_sale_number) === String(externalSaleNumber)
656
- ) || null;
657
- } catch (error) {
658
- this.logWarning("getLocalOrderByExternalSaleNumber failed", {
659
- externalSaleNumber,
660
- error: error instanceof Error ? error.message : String(error)
661
- });
662
- return null;
663
- }
664
- }
665
598
  async saveDraft() {
666
- var _a, _b;
667
- if (!this.draftPersistEnabled || !this.dbManager) {
668
- return;
669
- }
670
- const tempOrder = this.ensureTempOrder();
671
- const record = this.buildLocalOrderRecord(tempOrder);
672
- try {
673
- await ((_b = (_a = this.dbManager).update) == null ? void 0 : _b.call(_a, LOCAL_ORDER_STORE_NAME, record));
674
- } catch (error) {
675
- this.logWarning("saveDraft failed", {
676
- externalSaleNumber: tempOrder.external_sale_number,
677
- orderNumber: tempOrder.order_number,
678
- orderId: tempOrder.order_id,
679
- error: error instanceof Error ? error.message : String(error)
680
- });
681
- }
682
599
  }
683
600
  saveDraftInBackground() {
684
601
  void this.saveDraft();
@@ -721,6 +638,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
721
638
  return normalized;
722
639
  }
723
640
  updateTempOrderPaymentStatus(tempOrder) {
641
+ if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
642
+ return;
643
+ }
724
644
  const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
725
645
  const targetAmount = this.getPaymentTargetAmount();
726
646
  if (targetAmount.lte(0)) {
@@ -728,11 +648,56 @@ var OrderModule = class extends import_BaseModule.BaseModule {
728
648
  return;
729
649
  }
730
650
  if (paymentTotal.lte(0)) {
731
- tempOrder.payment_status = tempOrder.payment_status || "payment_processing";
651
+ tempOrder.payment_status = "payment_processing";
732
652
  return;
733
653
  }
734
654
  tempOrder.payment_status = paymentTotal.gte(targetAmount) ? "paid" : "partially_paid";
735
655
  }
656
+ shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
657
+ const normalizedStatus = String(paymentStatus || "").trim().toLowerCase();
658
+ return normalizedStatus === "refunded" || normalizedStatus === "partially_refunded";
659
+ }
660
+ resolveWalletPassUseValue(payment, amount) {
661
+ const usageUnit = payment.wallet_pass_usage_unit && typeof payment.wallet_pass_usage_unit === "object" ? payment.wallet_pass_usage_unit : null;
662
+ if (!usageUnit)
663
+ return payment.wallet_pass_use_value;
664
+ const price = new import_decimal.default(usageUnit.price || 0);
665
+ const points = new import_decimal.default(usageUnit.points || 0);
666
+ if (price.lte(0) || points.lte(0))
667
+ return payment.wallet_pass_use_value;
668
+ return amount.div(price).times(points).toDecimalPlaces(2).toFixed(2);
669
+ }
670
+ capVoucherPaymentsByRemainingAmount(params) {
671
+ const targetAmount = this.getPaymentTargetAmount();
672
+ const nonVoucherTotal = this.calculatePaymentTotal(params.nonVoucherPayments);
673
+ if (targetAmount.lte(0))
674
+ return [];
675
+ let remainingAmount = import_decimal.default.max(
676
+ targetAmount.minus(nonVoucherTotal),
677
+ 0
678
+ );
679
+ const cappedVouchers = [];
680
+ for (const voucher of params.vouchers) {
681
+ if (remainingAmount.lte(0))
682
+ break;
683
+ const voucherAmount = import_decimal.default.max(new import_decimal.default(voucher.amount || 0), 0);
684
+ if (voucherAmount.lte(0))
685
+ continue;
686
+ const cappedAmount = import_decimal.default.min(voucherAmount, remainingAmount);
687
+ const amountText = cappedAmount.toDecimalPlaces(2).toFixed(2);
688
+ cappedVouchers.push({
689
+ ...voucher,
690
+ amount: amountText,
691
+ origin_amount: amountText,
692
+ wallet_pass_use_value: this.resolveWalletPassUseValue(
693
+ voucher,
694
+ cappedAmount
695
+ )
696
+ });
697
+ remainingAmount = remainingAmount.minus(cappedAmount);
698
+ }
699
+ return cappedVouchers;
700
+ }
736
701
  calculatePaidPaymentSummary(payments) {
737
702
  return (payments || []).reduce(
738
703
  (summary, payment) => {
@@ -742,7 +707,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
742
707
  return {
743
708
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
744
709
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
745
- gapPaidAmount: summary.gapPaidAmount.plus(this.calculatePaymentEffectiveAmount(paymentRecord)),
710
+ gapPaidAmount: summary.gapPaidAmount.plus(this.calculatePaymentGapAmount(paymentRecord)),
746
711
  payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord))
747
712
  };
748
713
  },
@@ -763,6 +728,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
763
728
  const fixedAmount = new import_decimal.default(serviceCharge.amount || 0);
764
729
  return new import_decimal.default(payment.amount || 0).times(percentage).plus(fixedAmount);
765
730
  }
731
+ calculatePaymentGapAmount(payment) {
732
+ if (payment.origin_amount === void 0 || payment.origin_amount === null || payment.origin_amount === "") {
733
+ return new import_decimal.default(0);
734
+ }
735
+ const rounding = new import_decimal.default(payment.rounding_amount || 0);
736
+ return new import_decimal.default(payment.origin_amount || 0).minus(rounding);
737
+ }
766
738
  formatSummaryMetadataMoney(value) {
767
739
  if (value === void 0 || value === null || value === "")
768
740
  return void 0;
@@ -978,6 +950,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
978
950
  product.metadata = metadata;
979
951
  return String(uid);
980
952
  }
953
+ sanitizeOrderProductForTempOrder(product) {
954
+ if (product.metadata && typeof product.metadata === "object") {
955
+ delete product.metadata.origin;
956
+ }
957
+ return product;
958
+ }
959
+ sanitizeTempOrderProducts(tempOrder) {
960
+ tempOrder.products = (tempOrder.products || []).map(
961
+ (product) => this.sanitizeOrderProductForTempOrder(product)
962
+ );
963
+ }
981
964
  ensureExtend(tempOrder) {
982
965
  if (!tempOrder._extend || typeof tempOrder._extend !== "object") {
983
966
  tempOrder._extend = { productsByUid: {} };
@@ -1069,6 +1052,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1069
1052
  const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
1070
1053
  if (!tempOrder)
1071
1054
  return null;
1055
+ this.sanitizeTempOrderProducts(tempOrder);
1072
1056
  const salesSummary = this.getSalesSummary();
1073
1057
  const existedSummary = this.store.summary || (0, import_utils.createEmptySummary)();
1074
1058
  const paidPaymentSummary = this.calculatePaidPaymentSummary(
@@ -1087,8 +1071,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1087
1071
  }),
1088
1072
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1089
1073
  };
1090
- this.store.summary = emptySummary;
1091
1074
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1075
+ this.updateTempOrderPaymentStatus(tempOrder);
1076
+ this.store.summary = emptySummary;
1092
1077
  return this.store.summary;
1093
1078
  }
1094
1079
  const salesSummaryResult = await salesSummary.getSummary({
@@ -1120,6 +1105,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1120
1105
  tempOrder.surcharges = summary.surcharges || [];
1121
1106
  tempOrder.deposit_amount = summary.deposit_amount || "0.00";
1122
1107
  tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
1108
+ this.updateTempOrderPaymentStatus(tempOrder);
1123
1109
  return this.store.summary;
1124
1110
  }
1125
1111
  async getOrderSummary() {
@@ -1416,7 +1402,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1416
1402
  const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
1417
1403
  return payment.voucher_id === void 0 || Number(payment.voucher_id) === 0;
1418
1404
  });
1419
- tempOrder.payments = [...nonVoucherPayments, ...mappedVouchers];
1405
+ const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
1406
+ vouchers: mappedVouchers,
1407
+ nonVoucherPayments
1408
+ });
1409
+ tempOrder.payments = [...nonVoucherPayments, ...cappedVouchers];
1420
1410
  this.updateTempOrderPaymentStatus(tempOrder);
1421
1411
  this.persistTempOrder();
1422
1412
  void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
@@ -1550,6 +1540,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1550
1540
  }
1551
1541
  await this.applyPromotion();
1552
1542
  this.applyDiscount();
1543
+ this.sanitizeTempOrderProducts(tempOrder);
1553
1544
  await this.recalculateSummary({ createIfMissing: true });
1554
1545
  this.persistTempOrder();
1555
1546
  return tempOrder.products;
@@ -1639,7 +1630,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1639
1630
  const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
1640
1631
  const callerUpdatesMainMeta = ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_selling_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.main_product_original_price) !== void 0 || ((_e = updates == null ? void 0 : updates.metadata) == null ? void 0 : _e.source_product_price) !== void 0;
1641
1632
  const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
1642
- const callerUpdatesManualPrice = ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.price_override) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.is_manual_discount) !== void 0 || ((_h = updates == null ? void 0 : updates.metadata) == null ? void 0 : _h.product_discount_reason) !== void 0 || Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
1633
+ const callerChangesDiscountList = Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
1634
+ const callerUpdatesManualPrice = ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.price_override) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.is_manual_discount) !== void 0 || ((_h = updates == null ? void 0 : updates.metadata) == null ? void 0 : _h.product_discount_reason) !== void 0 || callerChangesDiscountList;
1643
1635
  if (isPersistedOrderLine && !callerUpdatesManualPrice) {
1644
1636
  nextProduct.selling_price = targetProduct.selling_price;
1645
1637
  nextProduct.original_price = targetProduct.original_price;
@@ -1649,7 +1641,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1649
1641
  source_product_price: (_i = targetProduct.metadata) == null ? void 0 : _i.source_product_price,
1650
1642
  main_product_selling_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_selling_price,
1651
1643
  main_product_original_price: (_k = targetProduct.metadata) == null ? void 0 : _k.main_product_original_price,
1652
- price_schema_version: (_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version
1644
+ price_schema_version: ((_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version) ?? 2
1653
1645
  };
1654
1646
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
1655
1647
  const existedMeta = nextProduct.metadata || {};
@@ -1710,6 +1702,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1710
1702
  );
1711
1703
  await this.applyPromotion();
1712
1704
  this.applyDiscount();
1705
+ this.sanitizeTempOrderProducts(tempOrder);
1713
1706
  await this.recalculateSummary({ createIfMissing: true });
1714
1707
  this.persistTempOrder();
1715
1708
  return tempOrder.products;
@@ -1773,6 +1766,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1773
1766
  tempOrder.products[productIndex] = normalizedProduct;
1774
1767
  await this.applyPromotion();
1775
1768
  this.applyDiscount();
1769
+ this.sanitizeTempOrderProducts(tempOrder);
1776
1770
  await this.recalculateSummary({ createIfMissing: true });
1777
1771
  this.persistTempOrder();
1778
1772
  return tempOrder.products;
@@ -1818,6 +1812,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1818
1812
  }
1819
1813
  await this.applyPromotion();
1820
1814
  this.applyDiscount();
1815
+ this.sanitizeTempOrderProducts(tempOrder);
1821
1816
  await this.recalculateSummary({ createIfMissing: true });
1822
1817
  this.persistTempOrder();
1823
1818
  return tempOrder.products;
@@ -1838,6 +1833,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1838
1833
  }
1839
1834
  await this.applyPromotion();
1840
1835
  this.applyDiscount();
1836
+ this.sanitizeTempOrderProducts(tempOrder);
1841
1837
  await this.recalculateSummary({ createIfMissing: true });
1842
1838
  this.persistTempOrder();
1843
1839
  return tempOrder;
@@ -1847,7 +1843,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1847
1843
  * 提交当前 Sales tempOrder。
1848
1844
  *
1849
1845
  * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
1850
- * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
1846
+ * 应传 1,确保 /shop/order/sales/checkout 返回打印所需数据。
1851
1847
  */
1852
1848
  async submitTempOrder(params) {
1853
1849
  var _a, _b, _c, _d, _e;
@@ -2141,7 +2137,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2141
2137
  * Checkout 专用:创建订单到后端
2142
2138
  *
2143
2139
  * 专门为 Checkout 模块设计的订单创建方法,
2144
- * 直接调用 /order/checkout 接口创建订单
2140
+ * 通过 OS Server 调用 checkout 接口创建订单
2145
2141
  * 接收已经处理好的订单数据,无需再处理购物车
2146
2142
  *
2147
2143
  * @param params Checkout 订单参数(已处理的订单数据)
@@ -2210,7 +2206,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2210
2206
  orderData.schedule_date = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
2211
2207
  }
2212
2208
  console.log("[Order] 调用后端接口创建订单:", {
2213
- url: "/order/checkout",
2209
+ url: "/shop/order/checkout",
2214
2210
  orderType: orderData.type,
2215
2211
  platform: orderData.platform,
2216
2212
  isDeposit: orderData.is_deposit,
@@ -2221,7 +2217,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2221
2217
  paymentsMethods: ((_m = orderData.payments) == null ? void 0 : _m.map((p) => p.code)) || []
2222
2218
  });
2223
2219
  this.logInfo("Calling backend checkout API", {
2224
- url: "/order/checkout",
2220
+ url: "/shop/order/checkout",
2225
2221
  orderType: orderData.type,
2226
2222
  platform: orderData.platform,
2227
2223
  isDeposit: orderData.is_deposit,
@@ -2243,7 +2239,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2243
2239
  hasOrderId: !!orderData.order_id,
2244
2240
  smallTicketDataFlag: orderData.small_ticket_data_flag
2245
2241
  });
2246
- const response = await this.request.post("/order/checkout", orderData);
2242
+ const response = await this.request.post("/shop/order/checkout", orderData, {
2243
+ osServer: true,
2244
+ customToast: () => {
2245
+ }
2246
+ });
2247
2247
  this.logInfo("Order API called successfully", {
2248
2248
  response
2249
2249
  });
@@ -2263,7 +2263,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2263
2263
  async submitSalesOrder(params) {
2264
2264
  const { url, query } = params;
2265
2265
  const fetchUrl = url || "/order/sales/checkout";
2266
- return this.request.post(fetchUrl, query, { customToast: () => {
2266
+ return this.request.post(fetchUrl, query, { osServer: true, customToast: () => {
2267
2267
  } });
2268
2268
  }
2269
2269
  /**
@@ -2287,10 +2287,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2287
2287
  emails: params.emails
2288
2288
  });
2289
2289
  }
2290
- // TODO 获取详情的接口
2291
- async getOrderInfoByRemote(order_id) {
2292
- const res = await this.request.get(`/order/sales/${order_id}`, {
2293
- with: ["products", "bookings", "payments", "customer", "summary", "contacts_info"]
2290
+ async getSalesOrderByLookup(params) {
2291
+ const lookup = params.lookup === void 0 || params.lookup === null ? "" : String(params.lookup).trim();
2292
+ if (!lookup) {
2293
+ throw new Error("加载销售详情需要 lookup");
2294
+ }
2295
+ const res = await this.request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
2296
+ with: ["products", "bookings", "payments", "customer", "summary", "contacts_info"],
2297
+ ...params.forceRemote ? { forceRemote: true } : {}
2294
2298
  }, { osServer: true });
2295
2299
  if (res.code === 200) {
2296
2300
  this.store.lastOrderInfo = res.data;
@@ -2473,7 +2477,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2473
2477
  };
2474
2478
  if (result.metadata)
2475
2479
  delete result.metadata.price_schema_version;
2476
- return result;
2480
+ return this.sanitizeOrderProductForTempOrder(result);
2477
2481
  }
2478
2482
  getLastOrderInfo() {
2479
2483
  var _a;
@@ -477,6 +477,10 @@ export interface LoadSalesDetailParams {
477
477
  external_sale_number?: string;
478
478
  forceRemote?: boolean;
479
479
  }
480
+ export interface SalesOrderLookupParams {
481
+ lookup: number | string;
482
+ forceRemote?: boolean;
483
+ }
480
484
  export interface SyncPaymentsToOrderParams {
481
485
  payments: OrderPaymentSource[];
482
486
  paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
@@ -635,15 +639,11 @@ export interface OrderModuleAPI {
635
639
  updateVoucherOrderPayments: (payments: OrderPaymentSource[]) => OrderPaymentData[];
636
640
  sendCustomerPayLink: <T = any>(params: SendCustomerPayLinkParams) => Promise<T>;
637
641
  saveDraft: () => Promise<void>;
638
- hasLocalDatabase: () => boolean;
639
- getLocalOrderByOrderId: (orderId: number | string) => Promise<Record<string, any> | null>;
640
- getLocalOrderByExternalSaleNumber: (externalSaleNumber: string) => Promise<Record<string, any> | null>;
641
- getLocalOrderByOrderNumber: (orderNumber: string) => Promise<Record<string, any> | null>;
642
642
  hydrateTempOrderFromRecord: (record: Record<string, any>, options?: {
643
643
  recalcOnHydrate?: boolean;
644
644
  }) => Promise<OrderTempOrder>;
645
645
  syncPaymentsToOrder: <T = any>(params: SyncPaymentsToOrderParams) => Promise<SyncPaymentsToOrderResult<T>>;
646
- getOrderInfoByRemote: (order_id: number) => Promise<any>;
646
+ getSalesOrderByLookup: (params: SalesOrderLookupParams) => Promise<any>;
647
647
  getLastOrderInfo: () => Record<string, any> | undefined;
648
648
  getOrderInfo: (order_id: number) => Promise<any>;
649
649
  /**
@@ -167,7 +167,7 @@ function buildManualProductDiscountItem(params) {
167
167
  const diff = origin.minus(selling);
168
168
  const quantity = resolveSafeProductNum(params.quantity);
169
169
  return {
170
- amount: diff.abs().toDecimalPlaces(2).toNumber(),
170
+ amount: diff.toDecimalPlaces(2).toNumber(),
171
171
  type: "product",
172
172
  discount: {
173
173
  message: params.message ?? "",
@@ -211,17 +211,17 @@ function resolveEffectivePerUnitDiscount(product) {
211
211
  if (hasPromoDiscountItem)
212
212
  return fromList;
213
213
  const metadata = (product == null ? void 0 : product.metadata) || {};
214
+ const promo = metadata._promotion;
215
+ if ((promo == null ? void 0 : promo.inPromotion) !== true)
216
+ return fromList;
214
217
  const optionSum = sumOptionUnitPrice(getProductSkuOptions(product)).toNumber();
215
- if (metadata.source_product_price != null && metadata.main_product_selling_price != null) {
218
+ if (!discountList.length && metadata.source_product_price != null && metadata.main_product_selling_price != null) {
216
219
  const source = Number(metadata.source_product_price);
217
220
  const selling = Number(metadata.main_product_selling_price) - optionSum;
218
221
  if (Number.isFinite(source) && Number.isFinite(selling) && source !== selling) {
219
222
  return fromList + (source - selling);
220
223
  }
221
224
  }
222
- const promo = metadata._promotion;
223
- if ((promo == null ? void 0 : promo.inPromotion) !== true)
224
- return fromList;
225
225
  const originalPrice = Number(promo.originalPrice);
226
226
  const finalPrice = Number(promo.finalPrice);
227
227
  if (!Number.isFinite(originalPrice) || !Number.isFinite(finalPrice))
@@ -31,7 +31,7 @@ var getAvailableMaxAmount = (data) => {
31
31
  return data.tag !== "point_card" ? data.available_max_amount : data == null ? void 0 : data.recommended_usage_amount;
32
32
  };
33
33
  var formatWalletPassList2PreparePayments = (list) => {
34
- return (list || []).map((item) => {
34
+ const formatted = (list || []).map((item) => {
35
35
  return {
36
36
  voucher_id: item.id || 0,
37
37
  amount: Number(item.edit_current_amount || getAvailableMaxAmount(item)) || 0,
@@ -40,6 +40,7 @@ var formatWalletPassList2PreparePayments = (list) => {
40
40
  wallet_pass_use_value: item.wallet_pass_use_value || void 0
41
41
  };
42
42
  });
43
+ return formatted;
43
44
  };
44
45
  var sortUserIdentificationCodeList = (list) => {
45
46
  if (!Array.isArray(list) || list.length === 0) {
@@ -43,30 +43,5 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
43
43
  rounding_amount: string;
44
44
  pay_service_charge_amount: string;
45
45
  is_price_include_tax?: number | undefined;
46
- } | {
47
- tax_title: string;
48
- tax_rate: number | undefined;
49
- product_quantity: number;
50
- product_original_amount: string;
51
- product_amount: string;
52
- product_expect_amount: string;
53
- product_tax_fee: string;
54
- shipping_fee: string;
55
- shipping_tax_fee: string;
56
- tax_fee: string;
57
- surcharge_fee: string;
58
- surcharges: any;
59
- discount_amount: string;
60
- deposit_amount: string;
61
- deposit: import("./types").DepositInfo | undefined;
62
- expect_amount: string;
63
- total_amount: string;
64
- total_refund_amount: string;
65
- customer_paid_amount: string;
66
- order_paid_amount: string;
67
- amount_gap: string;
68
- rounding_amount: string;
69
- pay_service_charge_amount: string;
70
- is_price_include_tax: number;
71
46
  }>;
72
47
  }
@@ -1,4 +1,5 @@
1
1
  export interface SalesSummaryProduct {
2
+ order_detail_id?: number | string | null;
2
3
  product_id: number | null;
3
4
  product_variant_id: number;
4
5
  num: number;
@@ -1,4 +1,4 @@
1
- import type { DepositInfo, SalesSummaryData, SalesSummaryProduct } from './types';
1
+ import type { SalesSummaryData, SalesSummaryProduct } from './types';
2
2
  export declare function createEmptySalesSummary(): SalesSummaryData;
3
3
  export declare function calculateSalesSummary(params: {
4
4
  products: SalesSummaryProduct[];
@@ -8,27 +8,4 @@ export declare function calculateSalesSummary(params: {
8
8
  scheduleById?: Record<string, any>;
9
9
  isInScheduleByDate?: any;
10
10
  shopDiscount?: string | number;
11
- }): SalesSummaryData | {
12
- product_quantity: number;
13
- product_original_amount: string;
14
- product_amount: string;
15
- product_expect_amount: string;
16
- product_tax_fee: string;
17
- shipping_fee: string;
18
- shipping_tax_fee: string;
19
- tax_fee: string;
20
- surcharge_fee: string;
21
- surcharges: any;
22
- discount_amount: string;
23
- deposit_amount: string;
24
- deposit: DepositInfo | undefined;
25
- expect_amount: string;
26
- total_amount: string;
27
- total_refund_amount: string;
28
- customer_paid_amount: string;
29
- order_paid_amount: string;
30
- amount_gap: string;
31
- rounding_amount: string;
32
- pay_service_charge_amount: string;
33
- is_price_include_tax: number;
34
- };
11
+ }): SalesSummaryData;