max 4 месяцев назад
Родитель
Сommit
0aeb587094

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

@@ -10,10 +10,10 @@ export default {
     dataSource: {
       default: {
         type: 'mysql',
-        host: '124.221.51.4',
-        // host: '192.168.2.105',
-        // port: 3306,
-        port: 6806,
+        host: '192.168.2.105',
+        port: 3306,
+        // host: '124.221.51.4',
+        // port: 6806,
         username: 'va_sandBox',
         password: 'asAf12u7YuszdHgfdVneq!',
         // host: '127.0.0.1',

+ 8 - 0
src/modules/api/controller/admin/accounts.ts

@@ -89,4 +89,12 @@ export class AccountsController extends BaseController {
     const res = await this.easyPayAdapter.request("GET", "/v3/accounts", params);
     return res;
   }
+
+  /**
+   * 获取用户详情
+   */
+  @Get('/getInfoByMchId', { summary: '账户列表' })
+  async getInfoByMchId(@Query(ALL) params: any) {
+    return await this.accountsService.getInfoByMchId(params.mchId);
+  }
 }

+ 28 - 3
src/modules/api/service/admin/accounts.ts

@@ -8,7 +8,8 @@ import {CustomerEntity} from '../../../payment/entity/customer';
 import {PaymentService} from '../../../payment/service/payment';
 import {SunPayAdapter} from '../../../payment/adapter/sunpay.adapter';
 import {OpenPaymentAccountEntity} from '../../entity/open_payment_account';
-import {OpenAccountEntity} from "../../entity/open_account";
+import {OpenAccountEntity} from '../../entity/open_account';
+import {EasyPayAdapter} from '../../../payment/adapter/easypay.adapter';
 
 /**
  * 描述
@@ -34,10 +35,12 @@ export class accountsService extends BaseService {
   @InjectEntityModel(OpenPaymentAccountEntity)
   openPaymentAccountEntity: Repository<OpenPaymentAccountEntity>;
 
-
   @InjectEntityModel(OpenAccountEntity)
   openAccountEntity: Repository<OpenAccountEntity>;
 
+  @Inject()
+  easyPayAdapter: EasyPayAdapter;
+
   async addAccounts(params, res) {
     // openPaymentAccountEntity.
     const openUserObj = {
@@ -48,8 +51,30 @@ export class accountsService extends BaseService {
       status: res.data.status || '',
       source: 'EASYPAY',
     };
-    this.ctx.logger.info(`添加va账户,${JSON.stringify(openUserObj)}`)
+    this.ctx.logger.info(`添加va账户,${JSON.stringify(openUserObj)}`);
     delete openUserObj.id;
     return await this.openAccountEntity.insert(openUserObj);
   }
+
+  async getInfoByMchId(mchId) {
+    const res = await this.openAccountEntity.findOne({
+      where: {
+        mch_id: mchId,
+      },
+    });
+    let account_info = {};
+    // 如果已经申请过的话,请求渠道的详情数据
+    if (res?.account_id && res.status !== 'ACTIVE') {
+      account_info = await this.easyPayAdapter.request(
+        'GET',
+        `/v3/accounts/${res?.account_id}`
+      );
+    }
+    console.log(6262626262, res);
+    console.log(6262626262, account_info);
+    return {
+      ...res,
+      account_info,
+    };
+  }
 }

+ 9 - 4
src/modules/api/service/webhook.ts

@@ -6,6 +6,8 @@ import { WebHookCommonService } from './webhook_utils/common';
 import { DepositSuccessService } from './webhook_utils/deposit_success';
 import { ExchangeSuccessService } from './webhook_utils/exchange_success';
 import { TransferSuccessService } from './webhook_utils/transfer_success';
+import { WebHookAccountService } from './webhook_utils/account';
+
 
 /**
  * 描述
@@ -27,6 +29,9 @@ export class OpenApiWebhookService extends BaseService {
   @Inject()
   transferSuccessService: TransferSuccessService;
 
+  @Inject()
+  webHookAccountService: WebHookAccountService;
+
   @Inject()
   ctx;
 
@@ -44,16 +49,16 @@ export class OpenApiWebhookService extends BaseService {
       switch (params.type) {
         case 'account_approved':
           // 账户审核通过   account_approved
-          break;
+          return await this.webHookAccountService.run(params);
         case 'account_rejected':
           // 账户审核驳回   account_rejected
-          break;
+          return await this.webHookAccountService.run(params);
         case 'legal_entity_request_created':
           // 实名待更新     legal_entity_request_created
-          break;
+          return await this.webHookAccountService.run(params);
         case 'legal_entity_request_success':
           // 实名更新审核通过 legal_entity_request_success
-          break;
+          return await this.webHookAccountService.run(params);
         case 'legal_entity_request_rejected':
           // 实名更新审核驳回 legal_entity_request_rejected
           break;

+ 67 - 0
src/modules/api/service/webhook_utils/account.ts

@@ -0,0 +1,67 @@
+import { BaseService } from '@cool-midway/core';
+import {ILogger, Inject, Provide} from '@midwayjs/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { OpenAccountEntity } from '../../entity/open_account';
+import { Repository } from 'typeorm';
+import { OpenUserEntity } from '../../entity/open_user';
+import { WithdrawChannelEntity } from '../../entity/withdrawChannel';
+import { applicationsService } from '../admin/applications';
+import {OpenPaymentOrderEntity, OrderType} from '../../entity/open_payment_order';
+import { EasyPayAdapter } from '../../../payment/adapter/easypay.adapter';
+import {WebHookCommonService} from "./common";
+
+/**
+ * webhook的公共方法
+ */
+@Provide()
+export class WebHookAccountService extends BaseService {
+  @InjectEntityModel(OpenAccountEntity)
+  openAccountEntity: Repository<OpenAccountEntity>;
+
+  @InjectEntityModel(OpenUserEntity)
+  openUserEntity: Repository<OpenUserEntity>;
+
+  @InjectEntityModel(WithdrawChannelEntity)
+  withdrawChannelEntity: Repository<WithdrawChannelEntity>;
+
+  @Inject()
+  applicationsService: applicationsService;
+
+  @Inject()
+  easyPayAdapter: EasyPayAdapter;
+
+  @Inject()
+  webHookCommonService: WebHookCommonService;
+
+  @InjectEntityModel(OpenPaymentOrderEntity)
+  openPaymentOrderEntity: Repository<OpenPaymentOrderEntity>;
+
+  @Inject()
+  ctx;
+
+  @Inject()
+  logger: ILogger;
+
+
+  async run(params) {
+    const accountInfo = await this.openAccountEntity.findOne({
+      where: {
+        account_id: params.data.account_id,
+      },
+    });
+    if (!accountInfo) {
+      // TODO 如果不存在的话,则为白标用户,目前不处理白标用户
+      // 转账延迟4秒处理
+      await this.webHookCommonService.waitByTime(4000);
+      this.ctx.status = 400;
+      this.ctx.body = {};
+      return;
+    }
+    await this.openAccountEntity.update(accountInfo.id, {
+      status: params.data.status
+    })
+    this.ctx.status = 200;
+    this.ctx.body = {};
+    return;
+  }
+}

+ 7 - 3
src/modules/api/service/webhook_utils/common.ts

@@ -30,7 +30,7 @@ export class WebHookCommonService extends BaseService {
     easyPayAdapter: EasyPayAdapter;
 
   // 如果查询都是空的延迟处理
-  async getAccountInfo(account_id) {
+  async getAccountInfo(account_id, isAll = true) {
     const openAccount = await this.openAccountEntity.findOne({
       where: {
         account_id,
@@ -39,6 +39,10 @@ export class WebHookCommonService extends BaseService {
     if (openAccount) {
       return openAccount;
     }
+    // 如果是直客的账户申请的话,不走后续的逻辑
+    if (!isAll) {
+      return null;
+    }
     const openUser = await this.openUserEntity.findOne({
       where: {
         account_id,
@@ -106,12 +110,12 @@ export class WebHookCommonService extends BaseService {
       }, settime);
     });
   }
-  // 获取汇率 
+  // 获取汇率
   async exchange_rates_buy_amount(params: any) {
     const exchange_rates = await this.easyPayAdapter.request("GET", "/v1/exchange_rates", params);
     if ( exchange_rates.data.length ) {
       return params.buy_amount / exchange_rates.data[0].exchange_rate
     }
-    return 0 
+    return 0
   }
 }