Răsfoiți Sursa

feat: 费率接口调整

max 7 luni în urmă
părinte
comite
f397b71336

+ 2 - 2
src/config/config.max.ts

@@ -15,8 +15,8 @@ export default {
         // password: 'admin',
         host: '127.0.0.1',
         port: 3306,
-        username: 'va',
-        password: 'FHZ36dP527GacTty',
+        username: 'root',
+        password: '12345678',
         database: 'va',
         // 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
         synchronize: true,

+ 10 - 2
src/modules/payment/controller/admin/rate.ts

@@ -1,12 +1,13 @@
 import { CoolController, BaseController } from '@cool-midway/core';
 import { RateEntity } from '../../entity/rate';
-import { Get, Inject, Query } from '@midwayjs/core';
+import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
 import { RateService } from '../../service/rate';
+import { RateDTO } from '../../dto/rate';
 /**
  * 描述
  */
 @CoolController({
-  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
+  api: ['delete', 'update', 'info', 'list', 'page'],
   entity: RateEntity,
 })
 export class RateController extends BaseController {
@@ -21,4 +22,11 @@ export class RateController extends BaseController {
     );
     return res;
   }
+  /**
+   * 创建客户
+   */
+  @Post('/add', { summary: '创建客户' })
+  async addRate(@Body() params: RateDTO) {
+    return this.ok(await this.rateService.addRate(params));
+  }
 }

+ 41 - 0
src/modules/payment/dto/rate.ts

@@ -0,0 +1,41 @@
+import { ApiProperty } from '@midwayjs/swagger';
+import { Rule, RuleType } from '@midwayjs/validate';
+
+export class RateDTO {
+  @ApiProperty({ description: '商户编号' })
+  @Rule(RuleType.string().required())
+  merchantId: string;
+
+  @ApiProperty({ description: '渠道' })
+  @Rule(RuleType.string().required())
+  channelId: string;
+
+  @ApiProperty({ description: '币种' })
+  @Rule(RuleType.string().required())
+  currency: string;
+  
+  @ApiProperty({ description: '入金费率' })
+  @Rule(RuleType.number().required())
+  DEPOSIT_rate: string;
+  
+  
+  @ApiProperty({ description: '入金方式' })
+  @Rule(RuleType.string().required())
+  DEPOSIT_method: string;
+  
+  @ApiProperty({ description: '出金费率' })
+  @Rule(RuleType.number().required())
+  WITHDRAWAL_rate: string;
+
+  @ApiProperty({ description: '出金方式' })
+  @Rule(RuleType.string().required())
+  WITHDRAWAL_method: string;
+
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType.number().required())
+  status: string;
+
+  @ApiProperty({ description: '备注' })
+  @Rule(RuleType.string().optional())
+  remark: string;
+}

+ 35 - 1
src/modules/payment/service/rate.ts

@@ -1,4 +1,4 @@
-import { Init, Inject, Provide } from '@midwayjs/decorator';
+import { Inject, Provide } from '@midwayjs/decorator';
 import { BaseService } from '@cool-midway/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
@@ -37,4 +37,38 @@ export class RateService extends BaseService {
       select: ['method'],
     });
   }
+  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,
+      currency: params.currency,
+      status: params.status, 
+      remark: params.remark
+    }
+    // 入金
+    const depositInfo = {
+      rate: params.DEPOSIT_rate,
+      type: 'DEPOSIT',
+      method: params.DEPOSIT_method,
+    }
+
+    // 出金
+    const withdrawalInfo = {
+      rate: params.WITHDRAWAL_rate,
+      type: 'WITHDRAWAL',
+      method: params.WITHDRAWAL_method,
+    } 
+    const addRes = await Promise.allSettled([
+      await this.rateEntity.insert({
+        ...commonParams,
+        ...depositInfo
+      }),
+      await this.rateEntity.insert({
+        ...commonParams,
+        ...withdrawalInfo
+      })
+    ])
+    return addRes
+  }
 }