wxInfoController.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class WxInfoController extends Controller {
  4. async isExist() {
  5. const { ctx, service } = this;
  6. const query = ctx.query;
  7. const { openId } = query;
  8. const result = await service.sysUserService.oneData({ openId });
  9. if (result) {
  10. // 添加log
  11. const addQuery = {};
  12. addQuery.dept1 = result.dept1;
  13. addQuery.dept2 = result.dept2;
  14. addQuery.dept3 = result.dept3;
  15. addQuery.dept4 = result.dept4;
  16. addQuery.dept5 = result.dept5;
  17. addQuery.role = result.role;
  18. addQuery.loginName = result.loginName;
  19. // addQuery.tableName = 'user';
  20. addQuery.type = '登录';
  21. addQuery.detail = 'openid是否存在';
  22. addQuery.state = 'WeiXin';
  23. await this.service.sysLogService.add(addQuery);
  24. }
  25. ctx.logic(result, ' ');
  26. }
  27. async bing() {
  28. const { ctx, service } = this;
  29. const query = ctx.query;
  30. const result = await service.sysUserService.bing(query);
  31. if (result) {
  32. ctx.error(result);
  33. } else {
  34. // 添加log
  35. const addQuery = {};
  36. const user = await service.sysUserService.oneData({ loginName: query.name, loginPwd: query.pwd });
  37. ctx.logger.info('user===================>' + user);
  38. addQuery.dept1 = user.dept1;
  39. addQuery.dept2 = user.dept2;
  40. addQuery.dept3 = user.dept3;
  41. addQuery.dept4 = user.dept4;
  42. addQuery.dept5 = user.dept5;
  43. addQuery.role = user.role;
  44. addQuery.loginName = query.name;
  45. // addQuery.tableName = 'user';
  46. addQuery.type = '绑定';
  47. addQuery.detail = JSON.stringify(query);
  48. addQuery.state = 'WeiXin';
  49. await this.service.sysLogService.add(addQuery);
  50. ctx.success();
  51. }
  52. }
  53. async unbind() {
  54. const { ctx, service } = this;
  55. const user = ctx.user;
  56. const result = await service.sysUserService.update(user._id, { openId: '' });
  57. ctx.success(result);
  58. }
  59. async updatePwd() {
  60. const { ctx, service } = this;
  61. const query = ctx.request.body;
  62. const result = await service.sysUserService.updatePwdWithOpenId(query);
  63. ctx.logic(result, '修改密码失败,原密码错误');
  64. }
  65. }
  66. module.exports = WxInfoController;