Kaynağa Gözat

feat(): 增加客户列表接口

max 7 ay önce
ebeveyn
işleme
036e0c6953

+ 13 - 0
src/modules/payment/controller/admin/customer.ts

@@ -0,0 +1,13 @@
+import { CoolController, BaseController } from '@cool-midway/core';
+import {CustomerEntity} from "../../entity/customer";
+import {CustomerService} from "../../service/customer";
+
+/**
+ * 支付渠道管理
+ */
+@CoolController({
+  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
+  entity: CustomerEntity,
+  service: CustomerService,
+})
+export class AdminPaymentChannelController extends BaseController {}

+ 31 - 1
src/modules/payment/service/customer.ts

@@ -1,6 +1,6 @@
 import { IndividualEntity } from './../entity/individual';
 import { BusinessEntity } from './../entity/business';
-import { Init, Provide } from '@midwayjs/decorator';
+import {ALL, Config, Init, Inject, Provide} from '@midwayjs/decorator';
 import { BaseService } from '@cool-midway/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
@@ -22,6 +22,10 @@ export class CustomerService extends BaseService {
     await super.init();
     this.setEntity(this.customerEntity);
   }
+  @Config(ALL)
+  config;
+  @Inject()
+  ctx;
 
   /**
    * 描述
@@ -113,6 +117,12 @@ export class CustomerService extends BaseService {
     };
   }
 
+  private _isOpenApi: boolean = false
+
+  setIsOpenApi(payload = false) {
+    this._isOpenApi = payload
+  }
+
   /**
    * 发送请求到 商户 API
    */
@@ -133,4 +143,24 @@ export class CustomerService extends BaseService {
       // throw error;
     }
   }
+
+  async list(params: any = {}) {
+    const merchantId = await this.getMerchantId(params);
+    return await this.customerEntity.findBy({
+      merchantId: `${merchantId}`
+    })
+  }
+
+  private async getMerchantId(params) {
+    let merchantId;
+    if (this._isOpenApi) {
+      merchantId = params.out_user_id;
+    } else if (params?.mch_id || params?.mchId || params?.merchantId) {
+      merchantId = params?.mch_id || params?.mchId || params?.merchantId
+    } else {
+      const { merchant } = this.ctx.admin;
+      merchantId = merchant.mchId;
+    }
+    return merchantId
+  }
 }