|
@@ -5,6 +5,7 @@ import { BaseService, CoolCommException } from '@cool-midway/core';
|
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
import { Repository } from 'typeorm';
|
|
|
import { PayeeEntity } from '../entity/payee';
|
|
|
+import { MerchantEntity } from '../entity/merchant';
|
|
|
|
|
|
/**
|
|
|
* 描述
|
|
@@ -15,6 +16,8 @@ export class PayeeService extends BaseService {
|
|
|
payeeEntity: Repository<PayeeEntity>;
|
|
|
@InjectEntityModel(CustomerEntity)
|
|
|
customerEntity: Repository<CustomerEntity>;
|
|
|
+ @InjectEntityModel(MerchantEntity)
|
|
|
+ merchantEntity: Repository<MerchantEntity>;
|
|
|
@Inject()
|
|
|
paymentService: PaymentService;
|
|
|
@Inject()
|
|
@@ -25,41 +28,36 @@ export class PayeeService extends BaseService {
|
|
|
* @returns
|
|
|
*/
|
|
|
async add(params: any) {
|
|
|
- const admin = this.ctx.admin;
|
|
|
- const customer = await this.customerEntity.findOneBy({
|
|
|
- merchantId: admin.merchant.id,
|
|
|
- });
|
|
|
+ let customer = await this.getCustomer(params);
|
|
|
+ const merchant = await this.getMerchant(customer.merchantId);
|
|
|
if (!customer) {
|
|
|
throw new CoolCommException('客户不存在');
|
|
|
}
|
|
|
const custom = {
|
|
|
...params,
|
|
|
customer_id: customer.customer_id,
|
|
|
- beneficiary_type: admin.merchant.bussiness ? 'COMPANY' : 'INDIVIDUAL',
|
|
|
+ beneficiary_type: customer.type ? 'COMPANY' : 'INDIVIDUAL',
|
|
|
};
|
|
|
const res = await this.paymentService
|
|
|
.setChannel(customer.channel)
|
|
|
.addPayee(custom);
|
|
|
params.beneficiary_id = res.data.id;
|
|
|
params.customerId = customer.id;
|
|
|
- params.merchantId = admin.merchant.id;
|
|
|
+ params.merchantId = merchant.mchId;
|
|
|
params.channel = customer.channel;
|
|
|
- params.type = admin.merchant.bussiness ? 'COMPANY' : 'INDIVIDUAL';
|
|
|
+ params.type = customer.type ? 'COMPANY' : 'INDIVIDUAL';
|
|
|
const payee = await super.add(params);
|
|
|
return payee;
|
|
|
}
|
|
|
async update(params: any) {
|
|
|
- const admin = this.ctx.admin;
|
|
|
+ let customer = await this.getCustomer(params);
|
|
|
const payee = await this.payeeEntity.findOneBy({
|
|
|
id: params.id,
|
|
|
});
|
|
|
- const customer = await this.customerEntity.findOneBy({
|
|
|
- merchantId: admin.merchant.id,
|
|
|
- });
|
|
|
const custom = {
|
|
|
...params,
|
|
|
customer_id: customer.customer_id,
|
|
|
- beneficiary_type: admin.merchant.bussiness ? 'COMPANY' : 'INDIVIDUAL',
|
|
|
+ beneficiary_type: customer.type ? 'COMPANY' : 'INDIVIDUAL',
|
|
|
id: payee.beneficiary_id,
|
|
|
};
|
|
|
const res = await this.paymentService
|
|
@@ -75,4 +73,37 @@ export class PayeeService extends BaseService {
|
|
|
await super.delete(params);
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ private _isOpenApi: boolean = false
|
|
|
+
|
|
|
+ setIsOpenApi(payload = false) {
|
|
|
+ this._isOpenApi = payload
|
|
|
+ }
|
|
|
+
|
|
|
+ async getCustomer(params) {
|
|
|
+ let customer: CustomerEntity;
|
|
|
+ if (this._isOpenApi) {
|
|
|
+ customer = await this.customerEntity.findOneBy({
|
|
|
+ customer_id: params.customer_id,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ const { merchant } = this.ctx.admin;
|
|
|
+ customer = await this.customerEntity.findOneBy({
|
|
|
+ merchantId: merchant.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return customer
|
|
|
+ }
|
|
|
+
|
|
|
+ async getMerchant(id) {
|
|
|
+ let merchant: MerchantEntity;
|
|
|
+ if (this._isOpenApi) {
|
|
|
+ merchant = await this.merchantEntity.findOneBy({
|
|
|
+ id: id,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ merchant = this.ctx.admin.merchant
|
|
|
+ }
|
|
|
+ return merchant
|
|
|
+ }
|
|
|
}
|