guhongwei 4 år sedan
förälder
incheckning
486208d1f4
3 ändrade filer med 47 tillägg och 12 borttagningar
  1. 8 2
      app/controller/user.js
  2. 2 0
      app/router.js
  3. 37 10
      app/service/user.js

+ 8 - 2
app/controller/user.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 管理
 class UserController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.user;
@@ -24,7 +23,10 @@ class UserController extends Controller {
   }
 
   async updatebyuid() {
-    const res = await this.service.updatebyuid(this.ctx.params, this.ctx.request.body);
+    const res = await this.service.updatebyuid(
+      this.ctx.params,
+      this.ctx.request.body
+    );
     this.ctx.ok({ data: res });
   }
 
@@ -37,6 +39,10 @@ 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);
+    this.ctx.ok({ ...res });
+  }
 }
 
 module.exports = CrudController(UserController, meta);

+ 2 - 0
app/router.js

@@ -20,6 +20,8 @@ module.exports = app => {
   router.post('user', '/api/auth/user/uppasswd', controller.user.uppasswd);
   router.post('/api/auth/user/updatebyuid/:id', controller.user.updatebyuid);
   router.post('/api/auth/user/bind', controller.user.bind);
+  // 查询业务管理员
+  router.post("/api/auth/businessuser", controller.user.businessuser);
 
   // 机构表设置路由
   router.resources('dept', '/api/auth/dept', controller.dept); // index、create、show、destroy

+ 37 - 10
app/service/user.js

@@ -9,7 +9,7 @@ const jwt = require('jsonwebtoken');
 
 class UserService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'user');
+    super(ctx, "user");
     this.model = this.ctx.model.User;
     this.rmodel = this.ctx.model.Role;
   }
@@ -18,8 +18,8 @@ class UserService extends CrudService {
   async create(data) {
     const { name, phone, passwd } = data;
     console.log(data);
-    assert(name && phone && passwd, '缺少部分信息项');
-    assert(/^\d{11}$/i.test(phone), 'phone无效');
+    assert(name && phone && passwd, "缺少部分信息项");
+    assert(/^\d{11}$/i.test(phone), "phone无效");
     // const user = await this.model.findOne({ phone });
     // if (user) {
     //   throw new BusinessError(ErrorCode.DATA_EXISTED);
@@ -40,8 +40,20 @@ class UserService extends CrudService {
 
   // 重写修改方法
   async update({ id }, data) {
-    const { name, phone, passwd, openid, role, menus, remark, uid, deptid, deptname, pid } = data;
-    const user = await this.model.findById(id, '+passwd');
+    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;
     }
@@ -82,9 +94,9 @@ class UserService extends CrudService {
   // 用户修改密码
   async uppasswd(data) {
     const { id, oldpasswd, newpasswd } = data;
-    assert(id && oldpasswd && newpasswd, '缺少部分信息项');
+    assert(id && oldpasswd && newpasswd, "缺少部分信息项");
     // 根据用户id查询其他用户表中是否存在相应数据
-    const user = await this.model.findById(id, '+passwd');
+    const user = await this.model.findById(id, "+passwd");
     // 如果用户不存在抛出异常
     if (!user) {
       throw new BusinessError(ErrorCode.USER_NOT_EXIST);
@@ -141,12 +153,27 @@ 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 }) {
+    const query = { code: { $regex: /^.{9}$/ } };
+    pid ? (query.pid = pid) : "";
+    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;