lrf 2 年之前
父節點
當前提交
3034c414a4
共有 4 個文件被更改,包括 41 次插入3 次删除
  1. 8 0
      app/controller/config/.teamApply.js
  2. 1 1
      app/model/race/matchSign.js
  3. 30 1
      app/service/teamApply.js
  4. 2 1
      app/z_router/teamApply.js

+ 8 - 0
app/controller/config/.teamApply.js

@@ -43,4 +43,12 @@ module.exports = {
       count: true,
     },
   },
+  findPartner: {
+    parameters: {
+      query: {
+        project_id: 'project_id',
+        user_id: 'user_id',
+      },
+    },
+  },
 };

+ 1 - 1
app/model/race/matchSign.js

@@ -7,7 +7,7 @@ const match_sign = {
   match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name', 'status', 'contact' ] }, // 比赛信息中的名称
   group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
   project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称
-  user_id: { type: String, required: true, zh: '用户id' }, //
+  user_id: { type: String, required: true, zh: '用户id', ref: 'User' }, //
   is_share: { type: Boolean, required: false, zh: '是否转发' }, //
   pay_id: { type: String, required: false, zh: '账单id', ref: 'PayOrder' }, //
   pay_status: { type: String, required: false, zh: '账单状态', default: '0' }, // 0:未支付;1支付成功;-1:支付失败;-2:申请退款(退赛);-3:已退款(退赛)

+ 30 - 1
app/service/teamApply.js

@@ -4,11 +4,40 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-// 
+//
 class TeamApplyService extends CrudService {
   constructor(ctx) {
     super(ctx, 'teamapply');
     this.model = this.ctx.model.Race.TeamApply;
+    this.matchSignModel = this.ctx.model.Race.MatchSign;
+  }
+  /**
+   * 查询项目下可以组队的人
+   * @param {Object} query 地址栏查询条件
+   * @property {String} project_id 项目地址
+   * @property {String} user_id 项目地址
+   */
+  async findPartner({ project_id, user_id }) {
+    // 多层嵌套populate
+    console.log('line 22 in function:');
+    const conn = this.app.mongooseDB.get('base');
+    const schema = _.get(this.ctx.model, 'Base.User.schema');
+    const m = conn.model('User', schema);
+    let list = await this.matchSignModel.find({ user_id: { $ne: user_id }, pay_status: '1', project_id }).populate({
+      path: 'user_id',
+      select: 'user_id',
+      populate: { path: 'user_id', model: m, select: 'name' },
+    });
+    if (list.length > 0) {
+      list = JSON.parse(JSON.stringify(list));
+      list = list.map(i => {
+        i.user_name = _.get(i, 'user_id.user_id.name');
+        i.user_id = _.get(i, 'user_id._id');
+        return i;
+      });
+    }
+
+    return list;
   }
 }
 

+ 2 - 1
app/z_router/teamApply.js

@@ -7,9 +7,10 @@ const rkey = 'teamApply';
 const ckey = 'teamApply';
 const keyZh = '组队申请';
 const routes = [
+  { method: 'get', path: `${rkey}/findPartner`, controller: `${ckey}.findPartner`, name: `${ckey}findPartner`, 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}` },
 ];