lrf 3 年之前
父節點
當前提交
4c5610e941
共有 2 個文件被更改,包括 88 次插入84 次删除
  1. 77 76
      app/controller/users/.personal.js
  2. 11 8
      app/service/users/personal.js

+ 77 - 76
app/controller/users/.personal.js

@@ -1,118 +1,119 @@
 module.exports = {
   create: {
     requestBody: [
-      "!name",
-      "!password",
-      "!phone",
-      "email",
-      "addr",
-      "office_phone",
-      "profession",
-      "code",
-      "openid",
-      "status",
-      "remark",
-      "juris",
-      "create_time",
-      "is_expert",
-      "school",
-      "major",
-      "card",
-      "zwzc",
+      '!name',
+      '!password',
+      '!phone',
+      'email',
+      'addr',
+      'office_phone',
+      'profession',
+      'code',
+      'openid',
+      'status',
+      'remark',
+      'juris',
+      'create_time',
+      'is_expert',
+      'school',
+      'major',
+      'card',
+      'zwzc',
     ],
   },
   destroy: {
-    params: ["!id"],
-    service: "delete",
+    params: ['!id'],
+    service: 'delete',
   },
   update: {
-    params: ["!id"],
+    params: ['!id'],
     requestBody: [
-      "name",
-      "phone",
-      "email",
-      "addr",
-      "office_phone",
-      "profession",
-      "code",
-      "openid",
-      "status",
-      "remark",
-      "juris",
-      "create_time",
-      "is_expert",
-      "school",
-      "major",
-      "card",
-      "zwzc",
+      'name',
+      'phone',
+      'email',
+      'addr',
+      'office_phone',
+      'profession',
+      'code',
+      'openid',
+      'status',
+      'remark',
+      'juris',
+      'create_time',
+      'is_expert',
+      'school',
+      'major',
+      'card',
+      'zwzc',
     ],
   },
   show: {
     parameters: {
-      params: ["!id"],
+      params: ['!id'],
     },
-    service: "fetch",
+    service: 'fetch',
   },
   index: {
     parameters: {
       query: {
-        name: "name",
-        phone: "phone",
-        code: "code",
-        juris: "juris",
-        status: "status",
-        profession: "profession",
-        "create_time@start": "create_time@start",
-        "create_time@end": "create_time@end",
+        name: 'name',
+        phone: 'phone',
+        code: 'code',
+        juris: 'juris',
+        status: 'status',
+        profession: 'profession',
+        role: 'role',
+        'create_time@start': 'create_time@start',
+        'create_time@end': 'create_time@end',
       },
       options: {
-        isdel: "0", // 默认条件
+        isdel: '0', // 默认条件
       },
     },
-    service: "query",
+    service: 'query',
     options: {
-      query: ["skip", "limit"],
-      sort: ["meta.createdAt"],
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
       desc: true,
       count: true,
     },
   },
   //修改密码
   password: {
-    params: ["!id"],
-    requestBody: ["password"],
-    service: "password",
+    params: ['!id'],
+    requestBody: ['password'],
+    service: 'password',
   },
   // 登陆
   login: {
-    requestBody: ["phone", "password", "!code"],
-    service: "login",
+    requestBody: ['phone', 'password', '!code'],
+    service: 'login',
   },
   upgrade: {
     requestBody: [
-      "education",
-      "school",
-      "birthDate",
-      "qqwx",
-      "email",
-      "company",
-      "zwzc",
-      "expertise",
-      "img_path",
-      "workexperience",
-      "scientific",
-      "undertakingproject",
-      "scienceaward",
-      "social",
-      "status",
-      "remark",
-      "!id",
+      'education',
+      'school',
+      'birthDate',
+      'qqwx',
+      'email',
+      'company',
+      'zwzc',
+      'expertise',
+      'img_path',
+      'workexperience',
+      'scientific',
+      'undertakingproject',
+      'scienceaward',
+      'social',
+      'status',
+      'remark',
+      '!id',
     ],
-    service: "upgrade",
+    service: 'upgrade',
   },
 
   import: {
-    requestBody: ["uri"],
+    requestBody: ['uri'],
   },
   export: {
     requestBody: [],

+ 11 - 8
app/service/users/personal.js

@@ -19,13 +19,14 @@ class PersonalService extends CrudService {
     this.util = this.ctx.service.util.util;
   }
   async query(condition, { skip = 0, limit = 0 }) {
-    condition = await this.dealQueryCondition(condition);
-    const res = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
+    const query = await this.dealQueryCondition(_.cloneDeep(condition));
+    console.log(query);
+    const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
     return res;
   }
-  async count({ role, code, ...condition }) {
-    condition = await this.dealQueryCondition(condition);
-    const res = await this.model.count(condition);
+  async count(condition) {
+    const query = await this.dealQueryCondition(_.cloneDeep(condition));
+    const res = await this.model.count(query);
     return res;
   }
 
@@ -33,10 +34,12 @@ class PersonalService extends CrudService {
     condition = this.util.dealQuery(condition);
     if (role === '1') {
       //code查询机构,取出机构的code,用code到model(个人用户)里查询用户,合为一个数组,返回
-      const orgRes = await this.adminModel.find({ code }, { code: 1 });
-      const codes = orgRes.map((i) => i.code);
+      const orgRes = await this.adminModel.find({ code }, { _id: 1 });
+      const ids = orgRes.map((i) => i._id);
+      const res2 = await this.adminModel.find({ pid: ids, role: '2' }, { code });
+      const codes = res2.map((i) => i.code);
       condition.code = codes;
-    } else {
+    } else if (code) {
       //code直接查询用户返回即可
       condition.code = code;
     }