customer.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { BaseService, CoolCommException } from '@cool-midway/core';
  2. import { Provide } from '@midwayjs/core';
  3. import {ALL, Config, 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. import {CustomerEntity} from "../../payment/entity/customer";
  8. /**
  9. * 描述
  10. */
  11. @Provide()
  12. export class CustomerService extends BaseService {
  13. @Inject()
  14. sunPayAdapter: SunPayAdapter;
  15. @Inject()
  16. customerEntity: CustomerEntity;
  17. @Inject()
  18. businessService: BusinessService; // 公司
  19. @Inject()
  20. individualService: IndividualService; // 个人
  21. @Config(ALL)
  22. config;
  23. async createCustomer(params) {
  24. const isIndividual = params.customer_type === 'INDIVIDUAL';
  25. // const isCompany = params.customer_type === 'COMPANY';
  26. // if (!params?.individual && !params?.company) {
  27. // throw new CoolCommException('company或individual必须传一个');
  28. // }
  29. if (isIndividual) {
  30. this.individualService.setIsOpenApi(true)
  31. return await this.individualService.add(params);
  32. }
  33. this.businessService.setIsOpenApi(true)
  34. return await this.businessService.add(params);
  35. // TODO 过滤sunpay返回
  36. }
  37. async updateCustomer(params) {
  38. const isIndividual = params.customer_type === 'INDIVIDUAL';
  39. // const isCompany = params.customer_type === 'COMPANY';
  40. if (!params?.individual && !params?.company) {
  41. throw new CoolCommException('company或individual必须传一个');
  42. }
  43. if (isIndividual) {
  44. this.individualService.setIsOpenApi(true)
  45. return await this.individualService.update(params);
  46. }
  47. this.businessService.setIsOpenApi(true)
  48. return await this.businessService.update(params);
  49. // TODO 过滤sunpay返回
  50. }
  51. }