Bladeren bron

feat(): 创建钱包、获取钱包信息、获取钱包币种余额api转发

zerogo 7 maanden geleden
bovenliggende
commit
f02078f7a4

+ 16 - 8
src/modules/api/controller/wallet.ts

@@ -1,6 +1,7 @@
 import { CoolController, BaseController } from '@cool-midway/core';
-import { ALL, Body, Get, Inject, Post, Provide } from '@midwayjs/decorator';
+import { ALL, Body, Get, Inject, Post, Provide, Query } from '@midwayjs/decorator';
 import { BusinessEntity } from '../../payment/entity/business';
+import { WalletService } from "../../payment/service/wallet";
 
 /**
  * 钱包
@@ -8,6 +9,8 @@ import { BusinessEntity } from '../../payment/entity/business';
 @Provide()
 @CoolController('/api/v1/Fiat')
 export class WalletController extends BaseController {
+  @Inject()
+  walletService: WalletService;
   /**
    * 创建钱包
    * /api/v3/Fiat/Wallet
@@ -21,7 +24,7 @@ export class WalletController extends BaseController {
     // 数据落库
     // 回调
     console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    return this.ok(await this.walletService.add(business));
   }
   /**
    * TODO 创建钱包回调通知
@@ -43,29 +46,34 @@ export class WalletController extends BaseController {
    *
    */
   @Get('/GetWalletAccounts', { summary: '获取钱包信息' })
-  async GetWalletAccounts(@Body(ALL) business: BusinessEntity) {
+  async GetWalletAccounts(@Query('customer_id') customer_id: string,) {
     // if (!this.allowKeys.includes(key)) {
     //   return this.fail('非法操作');
     // }
     // 关键参数校验
     // 数据落库
     // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    console.log('GetWalletAccounts', customer_id);
+    return this.ok(await this.walletService.getWallet(customer_id));
   }
 
   /**
    * 获取账户币种余额
    */
   @Get('/AccountBalance', { summary: '获取账户币种余额' })
-  async AccountBalance(@Body(ALL) business: BusinessEntity) {
+  async AccountBalance(
+    @Query('customer_id') customer_id: string,
+    @Query('currency') currency: string,) {
     // if (!this.allowKeys.includes(key)) {
     //   return this.fail('非法操作');
     // }
     // 关键参数校验
     // 数据落库
     // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    console.log(customer_id,currency);
+    return this.ok(await this.walletService.getWalletBalance({
+      customer_id: customer_id,
+      currency: currency
+    }));
   }
 }

+ 13 - 0
src/modules/payment/adapter/sunpay.adapter.ts

@@ -177,6 +177,7 @@ export class SunPayAdapter implements ChannelAdapter {
    * 创建钱包
    */
   async createWallet(params: any): Promise<string> {
+    console.log('createWallet-=-=-',params)
     const { data } = await this.request('POST', '/Fiat/Wallet', params);
     return data;
   }
@@ -194,12 +195,24 @@ export class SunPayAdapter implements ChannelAdapter {
     return data;
   }
 
+  /**
+   * 获取钱包信息
+   * @param params
+   * @returns
+   */
   async getWallet(params: any): Promise<any> {
+    console.log('GetWalletAccounts-=-=-=',params)
     const res = await this.request('GET', '/Fiat/GetWalletAccounts', params);
     console.log(res);
     return res;
   }
+   /**
+   * 获取账户钱包币种余额信息
+   * @param params
+   * @returns
+   */
   async getWalletBalance(params: any): Promise<any> {
+    console.log('getWalletBalance-=-=-=',params)
     const res = await this.request('GET', '/Fiat/AccountBalance', params);
     console.log(res);
     return res;

+ 23 - 0
src/modules/payment/service/wallet.ts

@@ -102,6 +102,29 @@ export class WalletService extends BaseService {
       message: '成功',
     };
   }
+
+    /**
+   * 获取钱包信息
+   */
+  async getWallet(param: any) {
+    console.log('getWallet',param)
+    const res = await this.paymentService.setChannel('SUNPAY').getWallet({
+      customer_id: param,
+    });
+    return res;
+  }
+
+  /**
+   * 获取钱包币种余额
+   */
+  async getWalletBalance(param: any) {
+    console.log('getWalletBalance',param)
+    const res = await this.paymentService.setChannel('SUNPAY').getWalletBalance({
+      customer_id: param,
+    });
+    return res;
+  }
+
   async list(params: any, option: any, connectionName?: any) {
     const { merchant } = this.ctx.admin;
     const res = await this.walletEntity.find({