customer.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { BaseService, CoolCommException } from '@cool-midway/core';
  2. import { Provide } from '@midwayjs/core';
  3. import { Inject } from '@midwayjs/decorator';
  4. import { BusinessService } from '../../payment/service/business';
  5. import { SunPayAdapter } from '../../payment/adapter/sunpay.adapter';
  6. import { IndividualService } from '../../payment/service/individual';
  7. /**
  8. * 描述
  9. */
  10. @Provide()
  11. export class CustomerService extends BaseService {
  12. @Inject()
  13. sunPayAdapter: SunPayAdapter;
  14. @Inject()
  15. businessService: BusinessService; // 公司
  16. @Inject()
  17. individualService: IndividualService; // 个人
  18. async createCustomer(params) {
  19. const isIndividual = params.customer_type === 'INDIVIDUAL';
  20. // const isCompany = params.customer_type === 'COMPANY';
  21. if (!params?.individual && !params?.company) {
  22. throw new CoolCommException('company或individual必须传一个');
  23. }
  24. params.isOpenApi = true;
  25. if (isIndividual) {
  26. return await this.individualService.add(params);
  27. }
  28. return await this.businessService.add(params);
  29. // TODO 过滤sunpay返回
  30. }
  31. async updateCustomer(params) {
  32. const isIndividual = params.customer_type === 'INDIVIDUAL';
  33. // const isCompany = params.customer_type === 'COMPANY';
  34. if (!params?.individual && !params?.company) {
  35. throw new CoolCommException('company或individual必须传一个');
  36. }
  37. params.isOpenApi = true;
  38. if (isIndividual) {
  39. return await this.individualService.update(params);
  40. }
  41. return await this.businessService.update(params);
  42. // TODO 过滤sunpay返回
  43. }
  44. }