lrf402788946 %!s(int64=4) %!d(string=hai) anos
pai
achega
b7fb60e63d
Modificáronse 3 ficheiros con 39 adicións e 3 borrados
  1. 6 0
      app/controller/user.js
  2. 2 0
      app/router.js
  3. 31 3
      app/service/user.js

+ 6 - 0
app/controller/user.js

@@ -37,6 +37,12 @@ class UserController extends Controller {
     const res = await this.service.finduserlist(this.ctx.query);
     this.ctx.ok({ ...res });
   }
+
+  async businessuser() {
+    const res = await this.service.businessuser(this.ctx.query);
+    console.log(res);
+    this.ctx.ok({ ...res });
+  }
 }
 
 module.exports = CrudController(UserController, meta);

+ 2 - 0
app/router.js

@@ -18,6 +18,8 @@ module.exports = app => {
   router.resources('user', '/api/auth/user', controller.user); // index、create、show、destroy
   router.post('user', '/api/auth/user/update/:id', controller.user.update);
   router.post('user', '/api/auth/user/uppasswd', controller.user.uppasswd);
+  // 业务管理员查询
+  router.post('/api/auth/businessuser', controller.user.businessuser);
   router.post('/api/auth/user/updatebyuid/:id', controller.user.updatebyuid);
   router.post('/api/auth/user/bind', controller.user.bind);
 

+ 31 - 3
app/service/user.js

@@ -40,7 +40,19 @@ class UserService extends CrudService {
 
   // 重写修改方法
   async update({ id }, data) {
-    const { name, phone, passwd, openid, role, menus, remark, uid, deptid, deptname, pid } = data;
+    const {
+      name,
+      phone,
+      passwd,
+      openid,
+      role,
+      menus,
+      remark,
+      uid,
+      deptid,
+      deptname,
+      pid,
+    } = data;
     const user = await this.model.findById(id, '+passwd');
     if (name) {
       user.name = name;
@@ -141,12 +153,28 @@ class UserService extends CrudService {
   }
 
   async finduserlist({ skip, limit, ...info }) {
-    const query = { ...info, $or: [{ role: '4' }, { role: '5' }, { role: '6' }] };
+    const query = {
+      ...info,
+      $or: [{ role: '4' }, { role: '5' }, { role: '6' }],
+    };
     const total = await this.model.count(query);
-    const data = await this.model.find(query).skip(Number(skip)).limit(Number(limit));
+    const data = await this.model
+      .find(query)
+      .skip(Number(skip))
+      .limit(Number(limit));
     return { data, total };
   }
 
+  async businessuser({ pid, skip, limit }) {
+    assert(pid, '数据错误,缺少pid');
+    const query = { pid, code: { $regex: /^.{9}$/ } };
+    const total = await this.model.count(query);
+    const data = await this.model
+      .find(query)
+      .skip(Number(skip))
+      .limit(Number(limit));
+    return { data, total };
+  }
 }
 
 module.exports = UserService;