lrf %!s(int64=2) %!d(string=hai) anos
pai
achega
7728357bbe

+ 2 - 0
app/controller/config/.eliminate.js

@@ -67,6 +67,8 @@ module.exports = {
         player_two: 'player_two',
         is_change: 'is_change',
         status: 'status',
+        user_id: 'user_id',
+        user_name: 'user_name',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 9 - 0
app/controller/config/.match.js

@@ -80,4 +80,13 @@ module.exports = {
   getAll: {
     params: ['!id'],
   },
+  getSchedule: {
+    parameters: {
+      query: {
+        match_id: 'match_id',
+        group_id: 'group_id',
+        project_id: 'project_id',
+      },
+    },
+  },
 };

+ 35 - 0
app/service/eliminate.js

@@ -520,6 +520,41 @@ class EliminateService extends CrudService {
       break;
     }
   }
+
+  async beforeQuery(filter) {
+    const user_name = _.get(filter, 'user_name');
+    let user_id = _.get(filter, 'user_id');
+    // 没有user_id就不需要处理查询条件
+    if (!user_id && !user_name) return filter;
+    const usualCondition = _.pick(filter, [ 'match_id', 'group_id', 'project_id' ]);
+
+    if (user_name) {
+      // 要先找比赛用户模块的数据id
+      const baseUser = await this.baseUserModel.findOne({ name: new RegExp(user_name) }, { _id: 1 });
+      if (!baseUser) delete filter.user_name;
+      delete filter.user_name;
+      const baseUserId = baseUser._id;
+      const raceUser = await this.userModel.findOne({ user_id: baseUserId, type: '0' });
+      if (raceUser) user_id = raceUser._id;
+    }
+    if (user_id) {
+      // 需要查:该用户是 单打 和 双打 的情况
+      // 单打,直接user_id 为player_one/two 就可以,双打需要查teamApply
+      // 所以先把user_id添加进查询范围里
+      let probablyList = [ user_id ];
+      // 尽可能的缩小查询范围
+      // 接着找组队申请中和该用户有关的人
+      const teamApplyList = await this.teamApplyModel.find({ ...usualCondition, status: '1', $or: [{ one_member_id: user_id }, { two_member_id: user_id }] }, { _id: 1 });
+      const teamApplyIds = teamApplyList.map(i => i._id);
+      probablyList.push(...teamApplyIds);
+      // 删除user_id.会造成错误
+      delete filter.user_id;
+      // 添加该用户正确的范围条件
+      probablyList = probablyList.map(i => ObjectId(i).toString());
+      filter.$or = [{ player_one: { $in: probablyList } }, { player_two: { $in: probablyList } }];
+    }
+    return filter;
+  }
 }
 
 module.exports = EliminateService;

+ 7 - 1
app/service/match.js

@@ -42,7 +42,7 @@ class MatchService extends CrudService {
         const users = [];
         for (const sign of signs) {
           const userObj = _.get(sign, 'user_id.user_id');
-          const user = _.pick(userObj, ['icon', 'name']);
+          const user = _.pick(userObj, [ 'icon', 'name' ]);
           user._id = _.get(sign, 'user_id._id');
           users.push(user);
         }
@@ -54,6 +54,12 @@ class MatchService extends CrudService {
     return data;
   }
 
+
+  async getSchedule(query) {
+    const groupRace = await this.ctx.service.matchSmallGroupSchedule.query(query);
+    const eliminateRace = await this.ctx.service.eliminate.query(query);
+    return [ ...groupRace, ...eliminateRace ];
+  }
 }
 
 module.exports = MatchService;

+ 2 - 1
app/z_router/match.js

@@ -7,10 +7,11 @@ const rkey = 'match';
 const ckey = 'match';
 const keyZh = '比赛信息';
 const routes = [
+  { method: 'get', path: `${rkey}/getSchedule`, controller: `${ckey}.getSchedule`, name: `${ckey}getSchedule`, zh: `${keyZh}查询赛事的赛程` },
   { method: 'get', path: `${rkey}/getAll/:id`, controller: `${ckey}.getAll`, name: `${ckey}getAll`, zh: `${keyZh}查询所有信息` },
   { 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}`, 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}` },
 ];