123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import { Init, Inject, Provide } from '@midwayjs/decorator';
- import { BaseService, CoolCommException } from '@cool-midway/core';
- import { InjectEntityModel } from '@midwayjs/typeorm';
- import { Repository } from 'typeorm';
- import { PayeeAddressEntity } from '../entity/payee_address';
- import { CustomerEntity } from '../entity/customer';
- import { PaymentService } from './payment';
- /**
- * 描述
- */
- @Provide()
- export class PayeeAddressService extends BaseService {
- @InjectEntityModel(PayeeAddressEntity)
- payeeAddressEntity: Repository<PayeeAddressEntity>;
- @InjectEntityModel(CustomerEntity)
- customerEntity: Repository<CustomerEntity>;
- @Inject()
- paymentService: PaymentService;
- @Inject()
- ctx;
- private _isOpenApi: boolean = false
- setIsOpenApi(payload = false) {
- this._isOpenApi = payload
- }
- /**
- * 添加收款人
- * @param params
- * @returns
- */
- async add(params: any) {
- const { merchant } = this.ctx.admin;
- const merchantId = merchant.mchId;
- if (!['TRC20', 'ERC20'].includes(params.currency)) {
- const res = await this.paymentService
- .setChannel(params.channel)
- .createBeneficiaryAddress(params);
- params.beneficiary_address_id = res.data.id;
- }
- params.merchantId = merchantId;
- const payee = await super.add(params);
- return payee;
- }
- async update(params: any) {
- const payee = await this.payeeAddressEntity.findOneBy({
- id: params.id,
- });
- if (payee.beneficiary_address_id) {
- await this.paymentService
- .setChannel(payee.channel)
- .updateBeneficiaryAddress(params);
- }
- await super.update(params);
- return params;
- }
- async delete(params: any) {
- const payee = await this.payeeAddressEntity.findOneBy({
- id: params.id,
- });
- if (payee.beneficiary_address_id) {
- await this.paymentService
- .setChannel(payee.channel)
- .deleteBeneficiaryAddress({
- id: payee.beneficiary_address_id,
- });
- }
- await super.delete(params);
- }
- async list(params: any, option: any, connectionName?: any) {
- const { channel, currency } = params;
- const { merchant } = this.ctx.admin;
- const merchantId = merchant.mchId;
- const res = await this.payeeAddressEntity.find({
- where: {
- merchantId: merchantId,
- channel,
- currency,
- },
- select: ['id', 'address', 'currency'],
- });
- return res;
- }
- async page(params: any) {
- const { merchant } = this.ctx.admin;
- const merchantId = merchant.mchId;
- const query = `SELECT * FROM payee WHERE merchantId = '${merchantId}' ORDER BY merchantId ASC`;
- return this.sqlRenderPage(query, params, false);
- }
- }
|