Browse Source

修复余额计算

test 7 months ago
parent
commit
d6c5420876

+ 8 - 0
src/modules/dj/service/channels/sunpay.ts

@@ -306,6 +306,14 @@ export class SunPayService extends BaseService {
     });
     this.logger.info('退款接口查询返回', param, JSON.stringify(res.data));
     const { is_success, msg, data = {} } = res.data;
+    if(!is_success) {
+      return {
+        status: 1,
+        refundTraceNo: refund.refundNo,
+        date: new Date(),
+        message: ''
+      }
+    }
     if (is_success) {
       const { refund_detail = [] } = data;
       const bean = refund_detail.find(item => {

+ 1 - 1
src/modules/dj/service/refund.ts

@@ -60,7 +60,7 @@ export class RefundService extends BaseService {
     const wallet = await this.walletService.queryByMchIdAndCurrency(refund.mchId, refund.currency);
     const { balance = 0, freeze = 0 } = wallet;
     const totalAmount = +refund.amount + +refund.charge
-    const withdrawAmount = +balance - +freeze
+    const withdrawAmount = +balance - Math.abs(+freeze)
     if (+totalAmount > +withdrawAmount) {
       throw new Error('当前商户余额不足,无法发起退款!当前商户可提现余额:' + withdrawAmount);
     }

+ 2 - 2
src/modules/dj/service/repay.ts

@@ -65,7 +65,7 @@ export class RepayService extends BaseService {
       return {
         currency: item.currency,
         balance: item.balance,
-        withdrawBalance: (+item.balance - +item.freeze).toFixed(2),
+        withdrawBalance: (+item.balance - Math.abs(+item.freeze)).toFixed(2),
         freeze: item.freeze,
       }
     })
@@ -299,7 +299,7 @@ export class RepayService extends BaseService {
   async validBalance(merchant, currency, amount) {
     const wallet = await this.walletService.queryByMchIdAndCurrency(merchant.mchId, currency);
     const { balance = 0, freeze = 0 } = wallet;
-    if (+amount > +balance - +freeze) {
+    if (+amount > +balance - Math.abs(+freeze)) {
       throw new Error('当前商户余额不足,请确认!当前商户可提现余额:' + (+balance - +freeze));
     }
   }