lrf 2 years ago
parent
commit
4edb66f0d1
2 changed files with 35 additions and 4 deletions
  1. 32 1
      app/service/matchTeamGroup.js
  2. 3 3
      app/z_router/bill.js

+ 32 - 1
app/service/matchTeamGroup.js

@@ -3,6 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
+const user = require('../model/race/user');
 
 //
 class MatchTeamGroupService extends CrudService {
@@ -23,8 +24,38 @@ class MatchTeamGroupService extends CrudService {
    */
   async findGroupPersonSelects({ project_id, person_type, team_id }) {
     // 1.查找所有报名的选手/小队
-
+    let allPerson;
+    if (person_type === 'TeamApply') {
+      allPerson = await this.teamApplyModel.find({ project_id, status: '1' });
+    } else {
+      allPerson = await this.matchSignModel.find({ project_id, pay_status: '1' });
+    }
     // 2.查找该项目下已经分完组的成员
+    const teamGroups = await this.model.find({ project_id });
+    // 已经有分组的成员id集合
+    let personList = _.flattenDeep(teamGroups.map(i => i.person));
+    // 3.如果有team_id,则将team_id内的组员从上面有分组的成员id集合中剔除
+    if (team_id) {
+      const teamGroup = await this.model.findById(team_id);
+      const thisTeamPerson = _.flattenDeep(teamGroup.map(i => i.person));
+      personList = personList.filter(f => !thisTeamPerson.includes(f));
+    }
+    // 过滤掉 allPerson 中 在personList中的数据
+    if (person_type === 'TeamApply') {
+      allPerson = allPerson.filter(f => !personList.includes(f._id));
+      return allPerson;
+    }
+    // 找人的信息
+    allPerson = allPerson.filter(f => !personList.includes(f.user_id));
+    const users = [];
+    for (const i of allPerson) {
+      const { user_id } = i;
+      const r = await this.ctx.service.user.fetch({ id: user_id });
+      users.push(r);
+    }
+    return users;
+
+
   }
 
 

+ 3 - 3
app/z_router/bill.js

@@ -9,9 +9,9 @@ const keyZh = '账单';
 const routes = [
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
-  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
-  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
-  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+  // { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
+  // { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  // { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
 ];
 
 module.exports = app => {