lrf 2 rokov pred
rodič
commit
1ae9b058fd

+ 5 - 5
app/model/race/bill.js

@@ -6,11 +6,11 @@ const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-pl
 
 // 账单
 const bill = {
-  match_id: { type: String, required: false, zh: '赛事id', ref: 'Match' }, //
-  group_id: { type: String, required: false, zh: '组别id', ref: 'MatchGroup' }, //
-  project_id: { type: String, required: false, zh: '组别项目id', ref: 'MatchProject' }, //
-  payer_id: { type: String, required: false, zh: '支付人id', ref: 'User' }, // 比赛模块用户数据id
-  pay_id: { type: String, required: false, zh: '支付id', ref: 'PayOrder' }, //
+  match_id: { type: String, required: false, zh: '赛事id', ref: 'Race.Match' }, //
+  group_id: { type: String, required: false, zh: '组别id', ref: 'Race.MatchGroup' }, //
+  project_id: { type: String, required: false, zh: '组别项目id', ref: 'Race.MatchProject' }, //
+  payer_id: { type: String, required: false, zh: '支付人id', ref: 'Race.User' }, // 比赛模块用户数据id
+  pay_id: { type: String, required: false, zh: '支付id', ref: 'Race.PayOrder' }, //
   is_pay: { type: String, required: false, zh: '是否支付' }, //  0:未支付;1:支付成功;-1:支付失败;-3:已退款
   time: { type: String, required: false, zh: '时间' }, //
   type: { type: String, required: false, zh: '来源' }, // 1:报名缴费;-1退赛

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

@@ -4,7 +4,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
 // 比赛信息
 const match = {
-  belong_id: { type: String, zh: '属于id', ref: 'User', getProp: [ 'name' ] }, // 比赛系统中用户的数据id
+  belong_id: { type: String, zh: '属于id', ref: 'Race.User', getProp: [ 'name', 'user_id.name' ] }, // 比赛系统中用户的数据id
   type: { type: String, zh: '赛事类别' },
   logo: { type: Array, required: true, zh: '比赛logo' }, // 比赛logo
   name: { type: String, required: true, zh: '比赛名称' }, // 比赛名称

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

@@ -4,7 +4,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 赛事场地
 const match_address = {
-  belong_id: { type: String, required: true, zh: '归属id', ref: 'User', getProp: [ 'name' ] }, // 用户表中的名称
+  belong_id: { type: String, required: true, zh: '归属id', ref: 'Race.User', getProp: ['name'] }, // 用户表中的名称
   name: { type: String, required: true, zh: '名称' }, //
   remark: { type: String, required: false, zh: '备注' }, //
   is_use: { type: String, required: false, default: '0', zh: '是否使用' }, // 0:启用,1:禁用

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

@@ -5,7 +5,7 @@ const source = 'race';
 
 // 赛事组别
 const match_group = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
   name: { type: String, required: true, zh: '名称' }, //
   age: { type: String, required: false, zh: '年龄限制' }, // 12-16 / null(不限)
   explain: { type: String, required: false, zh: '说明' }, //

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

@@ -4,7 +4,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 组别项目
 const match_project = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的比赛名称
   group_id: { type: String, required: true, zh: '赛事分组id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事分组中的组名称
   type: { type: String, required: true, zh: '项目类别' }, // 字典表中的标签
   name: { type: String, required: true, zh: '名称' }, //

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

@@ -4,12 +4,12 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 赛事报名
 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', ref: 'User' }, //
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name', 'status', 'contact' ] }, // 比赛信息中的名称
+  group_id: { type: String, required: true, zh: '组别id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
+  project_id: { type: String, required: true, zh: '项目id', ref: 'Race.MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称
+  user_id: { type: String, required: true, zh: '用户id', ref: 'Race.User' }, //
   is_share: { type: Boolean, required: false, zh: '是否转发' }, //
-  pay_id: { type: String, required: false, zh: '账单id', ref: 'PayOrder' }, //
+  pay_id: { type: String, required: false, zh: '账单id', ref: 'Race.PayOrder' }, //
   pay_status: { type: String, required: false, zh: '账单状态', default: '0' }, // 0:未支付;1支付成功;-1:支付失败;-2:申请退款(退赛);-3:已退款(退赛)
 };
 const schema = new Schema(match_sign, { toJSON: { getters: true, virtuals: true } });

+ 6 - 6
app/model/race/matchSmallGroupSchedule.js

@@ -4,12 +4,12 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 小组赛赛程设置
 const match_small_group_schedule = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 赛事信息中的名称
-  group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
-  project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组内项目中的名称
-  team_id: { type: String, required: true, zh: '小组id', ref: 'MatchTeamGroup', getProp: [ 'name' ] }, // 小组赛组设置中的name
-  address_id: { type: String, required: true, zh: '场地id', ref: 'MatchAddress', getProp: [ 'name' ] }, // 赛事场地中name
-  referee_id: { type: String, required: true, zh: '裁判id', ref: 'User', getProp: [ 'name' ] }, // 用户表中的name
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 赛事信息中的名称
+  group_id: { type: String, required: true, zh: '组别id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
+  project_id: { type: String, required: true, zh: '项目id', ref: 'Race.MatchProject', getProp: [ 'name' ] }, // 组内项目中的名称
+  team_id: { type: String, required: true, zh: '小组id', ref: 'Race.MatchTeamGroup', getProp: [ 'name' ] }, // 小组赛组设置中的name
+  address_id: { type: String, required: true, zh: '场地id', ref: 'Race.MatchAddress', getProp: [ 'name' ] }, // 赛事场地中name
+  referee_id: { type: String, required: true, zh: '裁判id', ref: 'Race.User', getProp: [ 'name' ] }, // 用户表中的name
   match_time: { type: String, required: true, zh: '比赛时间' }, //
   player_type: { type: String, required: true, zh: '选手类型' }, // 0:单打,user;1:双打,teamApply
   player_one: { type: String, required: true, zh: '选手一', refPath: 'player_type' }, //

+ 3 - 3
app/model/race/matchTeamGroup.js

@@ -4,9 +4,9 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 小组赛组设置
 const match_team_group = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 比赛信息中的名称
-  group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
-  project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组内项目中的名称
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息中的名称
+  group_id: { type: String, required: true, zh: '组别id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
+  project_id: { type: String, required: true, zh: '项目id', ref: 'Race.MatchProject', getProp: [ 'name' ] }, // 组内项目中的名称
   name: { type: String, required: true, zh: '分组名称' }, //
   person_type: { type: String, required: false, zh: '人员类型' }, // 单打:user;双打:teamApply
   person: { type: Array, required: false, zh: '组内人员' }, // refPath: 'person_type'

+ 4 - 4
app/model/race/payOrder.js

@@ -7,10 +7,10 @@ const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-pl
 // 付款订单表
 const payOrder = {
   openid: { type: String, required: false, zh: '微信id' }, //
-  match_id: { type: String, required: false, zh: '赛事id', ref: 'Match' }, //
-  group_id: { type: String, required: false, zh: '组别id', ref: 'MatchGroup' }, //
-  project_id: { type: String, required: false, zh: '组别项目id', ref: 'MatchProject' }, //
-  payer_id: { type: String, required: false, zh: '支付用户id', ref: 'User' }, // 比赛模块用户数据id
+  match_id: { type: String, required: false, zh: '赛事id', ref: 'Race.Match' }, //
+  group_id: { type: String, required: false, zh: '组别id', ref: 'Race.MatchGroup' }, //
+  project_id: { type: String, required: false, zh: '组别项目id', ref: 'Race.MatchProject' }, //
+  payer_id: { type: String, required: false, zh: '支付用户id', ref: 'Race.User' }, // 比赛模块用户数据id
   order_no: { type: String, required: false, zh: '订单号' }, //
   time: { type: String, required: false, zh: '时间' }, //
   desc: { type: String, required: false, zh: '支付说明' }, //

+ 3 - 3
app/model/race/teamApply.js

@@ -4,9 +4,9 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 组队申请
 const team_apply = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 比赛信息表中的名称
-  group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
-  project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Race.Match', getProp: [ 'name' ] }, // 比赛信息表中的名称
+  group_id: { type: String, required: true, zh: '组别id', ref: 'Race.MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
+  project_id: { type: String, required: true, zh: '项目id', ref: 'Race.MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称
   one_member_id: { type: String, required: true, zh: '成员一id' }, //
   one_member_name: { type: String, required: true, zh: '成员一姓名' }, //
   two_member_id: { type: String, required: true, zh: '成员二id' }, //

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

@@ -5,7 +5,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 // 用户表
 const user = {
   openid: { type: String, required: false, zh: '微信id' }, //
-  user_id: { type: String, required: false, zh: '用户id', ref: 'base.User' }, //
+  user_id: { type: String, required: false, zh: '用户id', ref: 'Base.User' }, //
   type: { type: String, required: false, default: '0', zh: '用户类别' }, // 0:普通用户;-1:超级管理员;1比赛管理员;2裁判
   parent_id: { type: String, required: false, zh: '所属id' }, // 裁判需要填写管理员的数据id
 };

+ 1 - 0
app/service/match.js

@@ -57,6 +57,7 @@ class MatchService extends CrudService {
     data.group = groups;
     return data;
   }
+
 }
 
 module.exports = MatchService;

+ 50 - 69
app/service/matchSmallGroupSchedule.js

@@ -152,8 +152,7 @@ class MatchSmallGroupScheduleService extends CrudService {
     } else if (sort && _.isArray(sort)) {
       sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
     }
-    const { refMods, populate } = await this.getRefMods();
-
+    const { refMods, populate } = this.getRefMods();
     let res = await this.model.findOne(filter, projection).populate(populate).exec();
     res = JSON.parse(JSON.stringify(res));
     for (const obj of refMods) {
@@ -205,79 +204,61 @@ class MatchSmallGroupScheduleService extends CrudService {
     return d;
   }
 
-  // async getRefMods() {
-  //   const mod = await this.getModel();
-  //   const refMods = [];
-  //   const populate = [];
-  //   for (const key in mod) {
-  //     const { ref, refPath } = mod[key];
-  //     if (!ref && !refPath) continue;
-  //     const obj = { col: key, prop: mod[key].getProp, type: mod[key].type.name };
-  //     refMods.push(obj);
-  //     // 检查ref/refPath是否还有嵌套
-  //     if (ref) {
-  //       // 递归查找ref的关系,构造ref关系树图
-  //       const res = this.checkSchema(ref);
-  //       // console.log(res);
-  //     }
-  //   }
-  //   return { refMods, populate };
-  // }
-  // 组成子 populate => {path,model}
-  checkSchema(thisRef, path) {
-    const { schema } = this.findModel(thisRef, path);
+  getRefMods() {
+    // 找到该表的schema(表结构)
+    const mod = this.getSchema();
+    const populate = this.resetPopulate(mod);
+    const refMods = [];
+    for (const key in mod) {
+      if (!mod[key].ref && !mod[key].refPath) continue;
+      const obj = { col: key, prop: mod[key].getProp, type: mod[key].type.name };
+      refMods.push(obj);
+    }
+    return { refMods, populate };
+  }
+
+  // 针对每个表进行检查
+  resetPopulate(schema) {
+    const arr = [];
     for (const key in schema) {
-      const { ref, refPath } = schema[key];
-      if (!ref && !refPath) continue;
-      const obj = {};
-      if (ref) {
-        const arr = ref.split('.').map(i => _.upperFirst(i));
-        obj.ref = _.upperFirst(_.last(arr));
-        let mpath = path;
-        // 如果有path,就应该不会有arr.length>0的情况
-        if (arr.length > 0) {
-          // 说明是有路径的,需要将路径也填充
-          arr.pop();
-          mpath = arr.join('.');
-        }
-        // 递归寻找ref
-        const { schema: sch } = this.checkSchema(obj.ref, mpath);
-        console.log(key, ref);
-        console.log(sch);
-        // for (const key in sch) {
-        //   const obj = sch[key];
-        //   const populate = this.dealSchema(obj);
-        // }
-      }
+      const e = schema[key];
+      const { ref } = e;
+      if (!ref) continue;
+      const obj = { path: key };
+      const modelPath = this.formatModelPath(ref);
+      const model = this.getModel(modelPath);
+      obj.model = model;
+      const msch = this.getSchema(modelPath);
+      const popu = this.resetPopulate(msch);
+      if (popu.length > 0) obj.populate = popu;
+      arr.push(obj);
     }
-    return schema;
+    return arr;
   }
 
-  // dealSchema(schema) {
-  // }
+  // 格式化model路径
+  formatModelPath(str) {
+    let arr = str.split('.');
+    arr = arr.map(i => _.upperFirst(i));
+    const modelPath = arr.join('.');
+    return modelPath;
+  }
 
-  findModel(modelName, path = this.defaultModule) {
-    // 有没有默认路径,将路径整合进去
-    const modelPath = [];
-    if (path) modelPath.push(...path.split('.'));
-    modelPath.push(_.upperFirst(modelName));
-    const modelPathStr = modelPath.join('.');
-    const m = _.get(this.ctx.model, modelPathStr);
-    if (m) return { schema: _.get(m, 'prototype.schema.obj'), path: modelPathStr };
-    let returnData;
-    // 去掉要找到的目标model
-    modelPath.pop();
-    const dir = modelPath.join('.');
-    const rootModel = _.get(this.ctx.model, dir, this.ctx.model);
-    for (const mn in rootModel) {
-      const type = typeof rootModel[mn];
-      if (type === 'object') {
-        // rootModel[mn] 是目录,要进入目录里面找内容
-        returnData = this.findModel(modelName, mn);
-      }
-      // 没有 else 的原因是,对于model来说;路径是object类型,model是function类型,而model在 上面 有关m变量 部分已经处理完,不会有其他形式
+  // 获取model的模式
+  getSchema(path) {
+    const model = this.getModel(path);
+    return _.get(model, 'prototype.schema.obj');
+  }
+
+  // 获取model实例
+  getModel(path) {
+    if (!path) return this.model;
+    let model = _.get(this.ctx.model, path);
+    const clients = this.app.mongooseDB.clients;
+    if (clients && !model) {
+      model = _.get(this.ctx.model, `${this.defaultModule}.${path}`);
     }
-    return returnData;
+    return model;
   }
 }
 

+ 1 - 0
config/config.default.js

@@ -109,6 +109,7 @@ module.exports = appInfo => {
   // 数据库设置
   config.dbName = 'court_race_v2';
   config.baseDbName = 'court_v2';
+  config.defaultModule = 'Race';
   config.mongoose = {
     clients: {
       base: {

+ 1 - 1
package.json

@@ -14,7 +14,7 @@
     "egg-scripts": "^2.11.0",
     "lodash": "^4.17.21",
     "moment": "^2.29.1",
-    "naf-framework-mongoose-free": "^0.0.34"
+    "naf-framework-mongoose-free": "^0.0.35"
   },
   "devDependencies": {
     "autod": "^3.0.1",