|
@@ -0,0 +1,85 @@
|
|
|
+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 {PayeeEntity} from '../../../payment/entity/payee';
|
|
|
+import {OpenAccountEntity} from '../../entity/open_account';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 描述
|
|
|
+ */
|
|
|
+@Provide()
|
|
|
+export class OpenPayeeService extends BaseService {
|
|
|
+ @InjectEntityModel(PayeeEntity)
|
|
|
+ payeeEntity: Repository<PayeeEntity>;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ ctx;
|
|
|
+
|
|
|
+ @Inject()
|
|
|
+ logger: ILogger;
|
|
|
+
|
|
|
+ @InjectEntityModel(OpenAccountEntity)
|
|
|
+ openAccountEntity: Repository<OpenAccountEntity>;
|
|
|
+
|
|
|
+ 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 list(query) {
|
|
|
+ // console.log(this.ctx.admin)
|
|
|
+ // this.ctx.admin.roleIds
|
|
|
+ // const find = this.payeeEntity.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);
|
|
|
+ // 查找多个
|
|
|
+ return await this.payeeEntity.findBy({
|
|
|
+ merchantId: this.ctx.admin.merchant.mchId,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 ${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;
|
|
|
+ }
|
|
|
+}
|