OpenPayeeAddress.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { BaseService } from '@cool-midway/core';
  2. import { ILogger, Provide } from '@midwayjs/core';
  3. import { Inject } from '@midwayjs/decorator';
  4. import { InjectEntityModel } from '@midwayjs/typeorm';
  5. import { Repository } from 'typeorm';
  6. import {PayeeAddressEntity} from "../../../payment/entity/payee_address";
  7. import {OpenAccountEntity} from "../../entity/open_account";
  8. /**
  9. * 描述
  10. */
  11. @Provide()
  12. export class OpenPayeeAddressService extends BaseService {
  13. @InjectEntityModel(PayeeAddressEntity)
  14. payeeAddressEntity: Repository<PayeeAddressEntity>;
  15. @Inject()
  16. ctx;
  17. @InjectEntityModel(OpenAccountEntity)
  18. openAccountEntity: Repository<OpenAccountEntity>;
  19. @Inject()
  20. logger: ILogger;
  21. async add(param: any): Promise<Object> {
  22. const merchantInfo = await this.getMerchantInfo();
  23. return super.add({
  24. ...param,
  25. channel: 'EASYPAY',
  26. type: 'COMPANY',
  27. merchantId: merchantInfo.mch_id,
  28. customerId: merchantInfo.account_id,
  29. });
  30. }
  31. // async page(query) {
  32. // console.log(this.ctx.admin)
  33. // this.ctx.admin.roleIds
  34. // const find = this.payeeAddressEntity.createQueryBuilder();
  35. // if (this.ctx.admin.roleIds.includes(1) ||this.ctx.admin.roleIds.includes(1)) {
  36. //
  37. // } else {
  38. // find.where("merchantId = :merchantId", { merchantId: this.ctx.admin.merchant.mchId });
  39. // }
  40. // return this.entityRenderPage(find, query);
  41. // }
  42. async page(query) {
  43. let isMerchantId = ''
  44. if (this.ctx.admin.roleIds.includes(1) ||this.ctx.admin.roleIds.includes(3)) {
  45. isMerchantId = ''
  46. } else {
  47. isMerchantId = `WHERE merchantId = '${this.ctx.admin.merchant.mchId}'`
  48. }
  49. return this.sqlRenderPage(
  50. `select * from payee_address ${isMerchantId} ORDER BY id ASC`,
  51. query,
  52. false
  53. );
  54. }
  55. // 获取商户信息
  56. async getMerchantInfo(mch_id = 'ep001@fusion.com') {
  57. const merchantInfo = await this.openAccountEntity.findOne({
  58. where: {
  59. mch_id: this.ctx.admin.merchant.mchId,
  60. // mch_id: 'easypay@qq.com',
  61. // mch_id: 'ep001@fusion.com',
  62. // mch_id: 'easypay003@fusion.com',
  63. // mch_id
  64. },
  65. });
  66. return merchantInfo;
  67. }
  68. }