123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { BaseService } from '@cool-midway/core';
- import { ILogger, Provide } from '@midwayjs/core';
- import { Inject } from '@midwayjs/decorator';
- import { InjectEntityModel } from '@midwayjs/typeorm';
- import { Repository } from 'typeorm';
- import {PayeeAddressEntity} from "../../../payment/entity/payee_address";
- import {OpenAccountEntity} from "../../entity/open_account";
- /**
- * 描述
- */
- @Provide()
- export class OpenPayeeAddressService extends BaseService {
- @InjectEntityModel(PayeeAddressEntity)
- payeeAddressEntity: Repository<PayeeAddressEntity>;
- @Inject()
- ctx;
- @InjectEntityModel(OpenAccountEntity)
- openAccountEntity: Repository<OpenAccountEntity>;
- @Inject()
- logger: ILogger;
- async add(param: any): Promise<Object> {
- const merchantInfo = await this.getMerchantInfo();
- return super.add({
- ...param,
- channel: 'EASYPAY',
- type: 'COMPANY',
- merchantId: merchantInfo.mch_id,
- customerId: merchantInfo.account_id,
- });
- }
- // async page(query) {
- // console.log(this.ctx.admin)
- // this.ctx.admin.roleIds
- // const find = this.payeeAddressEntity.createQueryBuilder();
- // if (this.ctx.admin.roleIds.includes(1) ||this.ctx.admin.roleIds.includes(1)) {
- //
- // } else {
- // find.where("merchantId = :merchantId", { merchantId: this.ctx.admin.merchant.mchId });
- // }
- // return this.entityRenderPage(find, query);
- // }
- async page(query) {
- let isMerchantId = ''
- if (this.ctx.admin.roleIds.includes(1) ||this.ctx.admin.roleIds.includes(3)) {
- isMerchantId = ''
- } else {
- isMerchantId = `WHERE merchantId = '${this.ctx.admin.merchant.mchId}'`
- }
- return this.sqlRenderPage(
- `select * from payee_address ${isMerchantId} ORDER BY id ASC`,
- query,
- false
- );
- }
- // 获取商户信息
- async getMerchantInfo(mch_id = 'ep001@fusion.com') {
- const merchantInfo = await this.openAccountEntity.findOne({
- where: {
- mch_id: this.ctx.admin.merchant.mchId,
- // mch_id: 'easypay@qq.com',
- // mch_id: 'ep001@fusion.com',
- // mch_id: 'easypay003@fusion.com',
- // mch_id
- },
- });
- return merchantInfo;
- }
- }
|