瀏覽代碼

孵化基地联系申请

lrf 7 月之前
父節點
當前提交
a976df3f0e

+ 7 - 4
src/controller/users/contactApply.controller.ts

@@ -34,7 +34,7 @@ export class ContactApplyController {
     // 需要查询当前管理员所在部门是否有审核的能力,再查询可见的数据
     const source = await this.service.checkUserSourceRange();
     const hasPermission = source.find(f => f === get(originData, 'source'));
-    if (!hasPermission) throw new ServiceError(ErrorCode.ADMIN_NOT_LOGIN); // 抛出异常,当前管理人员无审核该数据的权限
+    if (!hasPermission) throw new ServiceError(ErrorCode.CONTACTAPPLY_ADMIN_NO_PERMISSION); // 抛出异常,当前管理人员无审核该数据的权限
     const result = await this.service.update({ id }, { status, exam_admin });
     if (status === '1') {
       try {
@@ -83,9 +83,12 @@ export class ContactApplyController {
     if (user_id === source_user) throw new ServiceError(ErrorCode.CONTACTAPPLY_IS_THIS_USER_DATA); // 抛出异常: 来源数据是当前用户的数据
     /**组织数据,填充联系方式申请表:将被申请方的id填充 */
     const userData = get(otherData, 'userData');
-    if (!userData) throw new ServiceError(ErrorCode.CONTACTAPPLY_TARGET_USER_NOT_FOUND);
-    const target_user = get(userData, 'id');
-    data['target_user'] = target_user;
+    // 如果是孵化器的申请,则不需要target_user.直接由管理员审核
+    if (source !== 'incubator'){
+      if (!userData) throw new ServiceError(ErrorCode.CONTACTAPPLY_TARGET_USER_NOT_FOUND);
+      const target_user = get(userData, 'id');
+      data['target_user'] = target_user;
+    }
     // 检查是否有未审核的申请
     await this.service.checkHasApply(data);
     // 判断是否是 孵化基地 数据,如果是孵化基地,则不需要计算匹配度,就是单纯要信息

+ 2 - 1
src/error/service.error.ts

@@ -30,13 +30,14 @@ export enum ErrorCode {
   ADMIN_BODY_PASSWORD = 'ADMIN_BODY_PASSWORD',
 
   // contactApply
-  CONTACTAPPLY_TARGET_USER_NOT_FOUND = 'TARGET_USER_NOT_FOUND',
+  CONTACTAPPLY_TARGET_USER_NOT_FOUND = 'CONTACTAPPLY_TARGET_USER_NOT_FOUND',
   CONTACTAPPLY_HAS_APPLY_NOT_STATUS = 'CONTACTAPPLY_HAS_APPLY_NOT_STATUS',
   CONTACTAPPLY_NO_PERMISSION = 'CONTACTAPPLY_NO_PERMISSION',
   CONTACTAPPLY_NO_KEYWORD = 'CONTACTAPPLY_NO_KEYWORD',
   CONTACTAPPLY_MATCHING_NOT_ENOUGH = 'CONTACTAPPLY_MATCHING_NOT_ENOUGH',
   CONTACTAPPLY_IS_THIS_USER_DATA = 'CONTACTAPPLY_IS_THIS_USER_DATA',
   CONTACTAPPLY_DEPT_NO_ADMIN = 'CONTACTAPPLY_DEPT_NO_ADMIN',
+  CONTACTAPPLY_ADMIN_NO_PERMISSION = 'CONTACTAPPLY_ADMIN_NO_PERMISSION',
   SERVICE_APPLY = 'SERVICE_APPLY',
 
   DATA_NOT_FOUND = 'DATA_NOT_FOUND',

+ 20 - 5
src/service/users/contactApply.service.ts

@@ -12,6 +12,7 @@ import { ErrorCode, ServiceError } from '../../error/service.error';
 import { MessageUserType } from '../../public/var';
 import { Admin } from '../../entity/system/admin.entity';
 import { Design } from '../../entity/platform/design.entity';
+import { Incubator } from '../../entity/users/incubator.entity';
 
 @Provide()
 export class ContactApplyService extends BaseServiceV2 {
@@ -37,6 +38,8 @@ export class ContactApplyService extends BaseServiceV2 {
   user: Repository<User>;
   @InjectEntityModel(Admin)
   admin: Repository<Admin>;
+  @InjectEntityModel(Incubator)
+  incubator: Repository<Incubator>;
 
   /**
    * 审核成功后,返回给申请人申请的 联系方式
@@ -127,15 +130,18 @@ export class ContactApplyService extends BaseServiceV2 {
   async checkUserSourceRange() {
     const user = get(this.ctx, 'user', {});
     const is_super = get(user, 'is_super');
+    const config = await this.design.createQueryBuilder().getOne();
+    if (!config) throw new ServiceError(ErrorCode.DATA_NOT_FOUND);
+    const setting = get(config, 'contactApplyConfig', {});
     // 超级管理员都查
-    if (is_super === '0') return [];
+    if (is_super === '0') {
+      const keys = Object.keys(setting)
+      return keys;
+    }
     // 接下来取出部门
     const dept = get(user, 'dept');
     // 抛出异常: 本管理员无部门,无法查询预约申请
     if (!dept) throw new ServiceError(ErrorCode.CONTACTAPPLY_DEPT_NO_ADMIN);
-    const config = await this.design.createQueryBuilder().getOne();
-    if (!config) throw new ServiceError(ErrorCode.DATA_NOT_FOUND);
-    const setting = get(config, 'contactApplyConfig', {});
     // 整理出本部门管理的数据来源
     const sources: Array<string> = [];
     for (const key in setting) {
@@ -204,7 +210,10 @@ export class ContactApplyService extends BaseServiceV2 {
   async checkHasApply(data) {
     const apply_user = get(data, 'apply_user');
     const target_user = get(data, 'target_user');
-    const builder = this.model.createQueryBuilder().where(`"apply_user" = :apply_user`, { apply_user }).andWhere(`"target_user" = :target_user`, { target_user });
+    const source = get(data, 'source');
+    const builder = this.model.createQueryBuilder().where(`"apply_user" = :apply_user`, { apply_user });
+    if (source !== 'incubator') builder.andWhere(`"target_user" = :target_user`, { target_user });
+    else builder.andWhere(`"source" =:source`, { source });
     // const apply = await builder.andWhere(`"status" = :status`, { status: '1' }).getOne();
     // 查询是不是有其他状态的申请: 未审核,已拒绝,如果有,就根据状态返回提示语
     const othersApply = await builder.getOne();
@@ -228,6 +237,12 @@ export class ContactApplyService extends BaseServiceV2 {
       const sourceData = get(data, 'sourceData');
       if (get(sourceData, 'tel')) contacts.phone = get(sourceData, 'tel');
       if (get(sourceData, 'contacts')) contacts.person = get(sourceData, 'contacts');
+    } else if (source === 'incubator') {
+      const sourceData = get(data, 'sourceData');
+      const person = get(sourceData, 'person');
+      const phone = get(sourceData, 'person_phone');
+      if (person) contacts.person = person;
+      if (phone) contacts.phone = phone;
     }
     if (Object.keys(contacts).length <= 0) {
       const user = get(data, 'userData');