瀏覽代碼

feat: 费率接口调整

max 7 月之前
父節點
當前提交
29028f7ce9
共有 1 個文件被更改,包括 13 次插入3 次删除
  1. 13 3
      src/modules/payment/service/rate.ts

+ 13 - 3
src/modules/payment/service/rate.ts

@@ -1,5 +1,5 @@
 import { Inject, Provide } from '@midwayjs/decorator';
-import { BaseService } from '@cool-midway/core';
+import { BaseService, CoolCommException } from '@cool-midway/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { RateEntity } from '../entity/rate';
@@ -38,7 +38,6 @@ export class RateService extends BaseService {
     });
   }
   async addRate(params) {
-    /* { merchantId: 'testd', channelId: 'SUNPAY', currency: 'EUR', DEPOSIT_rate: 2, DEPOSIT_method: 66, WITHDRAWAL_rate: 3, WITHDRAWAL_method: 67, status: 1, remark: '启用' } */
     const commonParams = {
       merchantId: params.merchantId,
       channelId: params.channelId,
@@ -46,6 +45,17 @@ export class RateService extends BaseService {
       status: params.status, 
       remark: params.remark
     }
+    // 查找
+    let rateList = await this.rateEntity.find({
+      where: {
+        currency: params.currency,
+        channelId: params.channelId,
+        merchantId: params.merchantId,
+      },
+    });
+    if(rateList.length) {
+      throw new CoolCommException('当前币种已设置费率');
+    }
     // 入金
     const depositInfo = {
       rate: params.DEPOSIT_rate,
@@ -58,7 +68,7 @@ export class RateService extends BaseService {
       rate: params.WITHDRAWAL_rate,
       type: 'WITHDRAWAL',
       method: params.WITHDRAWAL_method,
-    } 
+    }
     const addRes = await Promise.allSettled([
       await this.rateEntity.insert({
         ...commonParams,