|
@@ -5,8 +5,9 @@ import { BaseService } from '@cool-midway/core';
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { CustomerEntity } from '../entity/customer';
|
|
import { CustomerEntity } from '../entity/customer';
|
|
|
|
+import axios from "axios";
|
|
/**
|
|
/**
|
|
- * 描述
|
|
|
|
|
|
+ * 客户管理
|
|
*/
|
|
*/
|
|
@Provide()
|
|
@Provide()
|
|
export class CustomerService extends BaseService {
|
|
export class CustomerService extends BaseService {
|
|
@@ -41,19 +42,30 @@ export class CustomerService extends BaseService {
|
|
},
|
|
},
|
|
});
|
|
});
|
|
if (!customer) {
|
|
if (!customer) {
|
|
|
|
+ // 获取商户的回调
|
|
|
|
+ await this.request(customer.webhook_url, {
|
|
|
|
+ biz_status: 'FAIL',
|
|
|
|
+ biz_type: 'CREATECUSTOMER',
|
|
|
|
+ data: data
|
|
|
|
+ })
|
|
return {
|
|
return {
|
|
is_success: false,
|
|
is_success: false,
|
|
message: '客户不存在',
|
|
message: '客户不存在',
|
|
};
|
|
};
|
|
}
|
|
}
|
|
if (customer.status == 'SUCCESS') {
|
|
if (customer.status == 'SUCCESS') {
|
|
|
|
+ // 获取商户的回调
|
|
|
|
+ await this.request(customer.webhook_url, {
|
|
|
|
+ biz_status: 'SUCCESS',
|
|
|
|
+ biz_type: 'CREATECUSTOMER',
|
|
|
|
+ data: data
|
|
|
|
+ })
|
|
return {
|
|
return {
|
|
is_success: true,
|
|
is_success: true,
|
|
message: '成功',
|
|
message: '成功',
|
|
};
|
|
};
|
|
}
|
|
}
|
|
const status = biz_status === 'FAIL' ? -1 : 1;
|
|
const status = biz_status === 'FAIL' ? -1 : 1;
|
|
-
|
|
|
|
customer.status = biz_status;
|
|
customer.status = biz_status;
|
|
const business = await this.businessEntity.findOne({
|
|
const business = await this.businessEntity.findOne({
|
|
where: {
|
|
where: {
|
|
@@ -89,9 +101,36 @@ export class CustomerService extends BaseService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
await this.customerEntity.save(customer);
|
|
await this.customerEntity.save(customer);
|
|
|
|
+ // 获取商户的回调
|
|
|
|
+ await this.request(customer.webhook_url, {
|
|
|
|
+ biz_status: 'SUCCESS',
|
|
|
|
+ biz_type: 'CREATECUSTOMER',
|
|
|
|
+ data: data
|
|
|
|
+ })
|
|
return {
|
|
return {
|
|
is_success: true,
|
|
is_success: true,
|
|
message: '成功',
|
|
message: '成功',
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发送请求到 商户 API
|
|
|
|
+ */
|
|
|
|
+ private async request( url, data?: any) {
|
|
|
|
+ try {
|
|
|
|
+ if (url) {
|
|
|
|
+ await axios({
|
|
|
|
+ method: 'post',
|
|
|
|
+ url,
|
|
|
|
+ data
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error);
|
|
|
|
+ // if (axios.isAxiosError(error) && error.response) {
|
|
|
|
+ // throw new Error(`FUSIONPay API Error2: ${error.response.data.msg}`);
|
|
|
|
+ // }
|
|
|
|
+ // throw error;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|