Pārlūkot izejas kodu

fix: 新增受益人异常修复

max 7 mēneši atpakaļ
vecāks
revīzija
12d6e47f2e
1 mainītis faili ar 32 papildinājumiem un 10 dzēšanām
  1. 32 10
      src/modules/payment/service/payee.ts

+ 32 - 10
src/modules/payment/service/payee.ts

@@ -14,14 +14,24 @@ import { MerchantEntity } from '../entity/merchant';
 export class PayeeService extends BaseService {
   @InjectEntityModel(PayeeEntity)
   payeeEntity: Repository<PayeeEntity>;
+
   @InjectEntityModel(CustomerEntity)
   customerEntity: Repository<CustomerEntity>;
+
   @InjectEntityModel(MerchantEntity)
   merchantEntity: Repository<MerchantEntity>;
+
   @Inject()
   paymentService: PaymentService;
   @Inject()
   ctx;
+
+  @Init()
+  async init() {
+    await super.init();
+    this.setEntity(this.payeeEntity);
+  }
+
   /**
    * 添加收款人
    * @param params
@@ -29,15 +39,18 @@ export class PayeeService extends BaseService {
    */
   async add(params: any) {
     let customer = await this.getCustomer(params);
-    const merchant = await  this.getMerchant(customer.merchantId);
     if (!customer) {
-      throw new CoolCommException('客户不存在');
+      throw new CoolCommException('客户不存在, 请先提交认证');
     }
+    const merchant = await  this.getMerchant(customer.merchantId);
     const custom = {
       ...params,
       customer_id: customer.customer_id,
       beneficiary_type: customer.type ? 'COMPANY' : 'INDIVIDUAL',
     };
+    if(custom.beneficiary_type === 'COMPANY') {
+      custom.company_name = params.friendly_name
+    }
     const res = await this.paymentService
       .setChannel(customer.channel)
       .addPayee(custom);
@@ -46,7 +59,15 @@ export class PayeeService extends BaseService {
     params.merchantId = merchant.mchId;
     params.channel = customer.channel;
     params.type = customer.type ? 'COMPANY' : 'INDIVIDUAL';
-    const payee = await super.add(params);
+    let payee;
+    try {
+      payee = await super.add(params);
+    } catch (err) {
+      console.log(err)
+    }
+    if(this.ctx.admin?.openApi) {
+      return res
+    }
     return payee;
   }
   async update(params: any) {
@@ -97,13 +118,14 @@ export class PayeeService extends BaseService {
 
   async getMerchant(id) {
     let merchant: MerchantEntity;
-    if (this._isOpenApi) {
-      merchant = await this.merchantEntity.findOneBy({
-        id: id,
-      });
-    } else {
-      merchant = this.ctx.admin.merchant
-    }
+    // if (this._isOpenApi) {
+    //   merchant = await this.merchantEntity.findOneBy({
+    //     id: id,
+    //   });
+    // } else {
+    //   merchant = this.ctx.admin.merchant
+    // }
+    merchant = this.ctx.admin.merchant
     return merchant
   }