Explorar o código

feat: easypay 3-6 转账

max hai 5 meses
pai
achega
2a192b572d

+ 40 - 0
src/modules/api/controller/admin/openPayee.ts

@@ -0,0 +1,40 @@
+import { CoolController, BaseController } from '@cool-midway/core';
+import {
+  ALL,
+  Body,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Provide,
+  Query,
+} from '@midwayjs/decorator';
+import { Context } from '@midwayjs/koa';
+import {OpenPayeeService} from "../../service/admin/OpenPayee";
+import {PayeeEntity} from "../../../payment/entity/payee";
+
+/**
+ * 收款人
+ */
+@Provide()
+@CoolController({
+  api: ['add', 'delete', 'update', 'info', 'page', 'list'],
+  entity: PayeeEntity,
+  service: OpenPayeeService,
+  pageQueryOp: {
+    where: async (ctx: Context) => {
+      const { merchant, roleId } = ctx.admin;
+      if ([1, 3].includes(roleId)) {
+        return [['merchantId=:merchantId', { merchantId: merchant.id }]];
+      }
+      return [];
+    },
+  },
+})
+export class OpenPayeeController extends BaseController {
+  @Inject()
+  openPayeeService: OpenPayeeService;
+
+  @Inject()
+  ctx: Context;
+}

+ 45 - 0
src/modules/api/controller/admin/openPayeeAddress.ts

@@ -0,0 +1,45 @@
+import { CoolController, BaseController } from '@cool-midway/core';
+import {
+  ALL,
+  Body,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Provide,
+  Query,
+} from '@midwayjs/decorator';
+import { Context } from '@midwayjs/koa';
+import {OpenPayeeAddressService} from "../../service/admin/OpenPayeeAddress";
+import {PayeeAddressEntity} from "../../../payment/entity/payee_address";
+
+/**
+ * 收款人地址
+ */
+@Provide()
+@CoolController({
+  api: ['add', 'delete', 'update', 'info', 'page', 'list'],
+  entity: PayeeAddressEntity,
+  service: OpenPayeeAddressService,
+  pageQueryOp: {
+    where: async (ctx: Context) => {
+      const { merchant, roleId } = ctx.admin;
+      if ([1, 3].includes(roleId)) {
+        return [['merchantId=:merchantId', { merchantId: merchant.id }]];
+      }
+      return [{
+        merchantId: merchant.id
+      },
+        {
+          channel: "EASYPAY"
+        }];
+    },
+  },
+})
+export class OpenPayeeAddressController extends BaseController {
+  @Inject()
+  openPayeeAddressService: OpenPayeeAddressService;
+
+  @Inject()
+  ctx: Context;
+}

+ 85 - 0
src/modules/api/service/admin/OpenPayee.ts

@@ -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;
+  }
+}

+ 78 - 0
src/modules/api/service/admin/OpenPayeeAddress.ts

@@ -0,0 +1,78 @@
+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;
+  }
+
+}

+ 2 - 2
src/modules/api/service/admin/applications.ts

@@ -205,11 +205,11 @@ export class applicationsService extends BaseService {
   async getMerchantInfo(mch_id= 'ep001@fusion.com') {
     const merchantInfo = await this.openAccountEntity.findOne({
       where: {
-        // mch_id: this.ctx.admin.merchant.mchId,
+        mch_id: this.ctx.admin.merchant.mchId,
         // mch_id: 'easypay@qq.com',
         // mch_id: 'ep001@fusion.com',
         // mch_id: 'easypay003@fusion.com',
-        mch_id
+        // mch_id
       },
     });
     return merchantInfo

+ 11 - 0
src/modules/base/controller/admin/sys/user.ts

@@ -27,4 +27,15 @@ export class BaseSysUserController extends BaseController {
     await this.baseSysUserService.move(departmentId, userIds);
     return this.ok();
   }
+  /**
+   * 根据姓名移动部门
+   */
+  @Post('/moveByUserName', { summary: '移动部门' })
+  async moveByUserName(
+    @Body('departmentId') departmentId: number,
+    @Body('mchId') mchId: string
+  ) {
+    await this.baseSysUserService.moveByUserName(departmentId, mchId);
+    return this.ok();
+  }
 }

+ 25 - 0
src/modules/base/service/sys/user.ts

@@ -109,6 +109,31 @@ export class BaseSysUserService extends BaseService {
     await this.baseSysUserEntity.update({ id: In(userIds) }, { departmentId });
   }
 
+  /**
+   * 移动部门
+   * @param departmentId
+   * @param mchId
+   */
+  async moveByUserName(departmentId, mchId) {
+    const mchInfo = await this.merchantEntity.findOne({
+      where: {
+        mchId: mchId
+      }
+    })
+    if (mchInfo.userId) {
+      console.log(124, mchInfo.userId)
+      const userInfo = await this.baseSysUserEntity.findOne({
+        where: {
+          id: Number(mchInfo.userId)
+        }
+      })
+      console.log(130, departmentId)
+      console.log(130, userInfo)
+      await this.baseSysUserEntity.update({ id: Number(mchInfo.userId) }, { departmentId });
+    }
+
+  }
+
   /**
    * 获得个人信息
    */