liuyu 5 rokov pred
rodič
commit
b5fb62d54a
4 zmenil súbory, kde vykonal 16 pridanie a 1 odobranie
  1. 5 0
      app/controller/user.js
  2. 0 1
      app/controller/weixin.js
  3. 1 0
      app/router.js
  4. 10 0
      app/service/user.js

+ 5 - 0
app/controller/user.js

@@ -27,6 +27,11 @@ class UserController extends Controller {
     const res = await this.service.updatebyuid(this.ctx.params, this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
+
+  async bind() {
+    const res = await this.service.bind(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = CrudController(UserController, meta);

+ 0 - 1
app/controller/weixin.js

@@ -4,7 +4,6 @@ const assert = require('assert');
 const _ = require('lodash');
 const uuid = require('uuid');
 const urljoin = require('url-join');
-const stringRandom = require('string-random');
 const Controller = require('egg').Controller;
 
 /**

+ 1 - 0
app/router.js

@@ -19,6 +19,7 @@ module.exports = app => {
   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/user/updatebyuid/:id', controller.user.updatebyuid);
+  router.post('/api/auth/user/bind', controller.user.bind);
 
   // 机构表设置路由
   router.resources('dept', '/api/auth/dept', controller.dept); // index、create、show、destroy

+ 10 - 0
app/service/user.js

@@ -125,6 +125,16 @@ class UserService extends CrudService {
     await user.save();
   }
 
+  // 按条件更新方法
+  async bind(data) {
+    const user = await this.model.findById(data.uid);
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    user.openid = data.openid;
+    await user.save();
+  }
+
   async findByOpenid(openid) {
     const user = await this.model.findOne({ openid });
     return user;