@pisell/pisellos 0.0.307 → 0.0.309

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.
@@ -677,7 +677,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
677
677
  value: (function () {
678
678
  var _updateLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
679
679
  var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8;
680
- var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, isNeedDeposit, created;
680
+ var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, syncedAmount, remainingExpectAmount, isNeedDeposit, created;
681
681
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
682
682
  while (1) switch (_context10.prev = _context10.next) {
683
683
  case 0:
@@ -730,7 +730,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
730
730
  return String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId);
731
731
  });
732
732
  if (!existingOrder) {
733
- _context10.next = 40;
733
+ _context10.next = 42;
734
734
  break;
735
735
  }
736
736
  // 基于现有支付项计算新的 expect_amount
@@ -792,14 +792,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
792
792
  timestamp: Date.now()
793
793
  });
794
794
  case 38:
795
+ // 需要减去已经同步给后端的支付过的钱
796
+ syncedAmount = activePayments.reduce(function (sum, p) {
797
+ var amt = new Decimal(p.amount || '0');
798
+ var rounding = new Decimal(p.rounding_amount || '0').abs();
799
+ return sum.plus(amt).plus(rounding);
800
+ }, new Decimal(0));
801
+ remainingExpectAmount = Decimal.max(0, totalAmount.minus(syncedAmount)).toFixed(2);
795
802
  this.initWalletData({
796
- order_wait_pay_amount: Number(updated.expect_amount)
803
+ order_wait_pay_amount: Number(remainingExpectAmount)
797
804
  });
798
805
  return _context10.abrupt("return", updated);
799
- case 40:
806
+ case 42:
800
807
  // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
801
808
  isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 没找到现有订单时,回退为创建逻辑(用于异常兜底)
802
- _context10.next = 43;
809
+ _context10.next = 45;
803
810
  return this.payment.createPaymentOrderAsync({
804
811
  order_id: String(params.orderId),
805
812
  total_amount: amountInfo.totalAmount,
@@ -816,15 +823,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
816
823
  amount_breakdown: amountInfo
817
824
  }
818
825
  });
819
- case 43:
826
+ case 45:
820
827
  created = _context10.sent;
821
828
  this.store.currentOrder = created;
822
- _context10.next = 47;
829
+ _context10.next = 49;
823
830
  return this.updateStateAmountToRemaining();
824
- case 47:
831
+ case 49:
825
832
  this.initWalletData();
826
833
  return _context10.abrupt("return", created);
827
- case 49:
834
+ case 51:
828
835
  case "end":
829
836
  return _context10.stop();
830
837
  }
@@ -522,8 +522,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
522
522
  order: updated,
523
523
  timestamp: Date.now()
524
524
  });
525
+ const syncedAmount = activePayments.reduce((sum, p) => {
526
+ const amt = new import_decimal.default(p.amount || "0");
527
+ const rounding = new import_decimal.default(p.rounding_amount || "0").abs();
528
+ return sum.plus(amt).plus(rounding);
529
+ }, new import_decimal.default(0));
530
+ const remainingExpectAmount = import_decimal.default.max(0, totalAmount.minus(syncedAmount)).toFixed(
531
+ 2
532
+ );
525
533
  this.initWalletData({
526
- order_wait_pay_amount: Number(updated.expect_amount)
534
+ order_wait_pay_amount: Number(remainingExpectAmount)
527
535
  });
528
536
  return updated;
529
537
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.307",
4
+ "version": "0.0.309",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",