appletsController.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class AppletsController extends Controller {
  4. async isExist() {
  5. const { ctx, service } = this;
  6. const query = ctx.query;
  7. const { appletsId } = query;
  8. const result = await service.sysUserService.oneData({ appletsId });
  9. if (result) {
  10. // ctx.logger.info('isExist--result=============>' + result);
  11. // 添加log
  12. const addQuery = {};
  13. addQuery.dept1 = result.dept1;
  14. addQuery.dept2 = result.dept2;
  15. addQuery.dept3 = result.dept3;
  16. addQuery.dept4 = result.dept4;
  17. addQuery.dept5 = result.dept5;
  18. addQuery.role = result.role;
  19. addQuery.loginName = result.loginName;
  20. // addQuery.tableName = 'user';
  21. addQuery.type = '登录';
  22. addQuery.detail = 'appletsId是否存在';
  23. addQuery.state = 'Applets';
  24. await this.service.sysLogService.add(addQuery);
  25. }
  26. ctx.logic(result, ' ');
  27. }
  28. async bing() {
  29. const { ctx, service } = this;
  30. const query = ctx.query;
  31. const result = await service.appletsService.bing(query);
  32. if (result) {
  33. ctx.error(result);
  34. } else {
  35. // 添加log
  36. const addQuery = {};
  37. const user = await service.sysUserService.oneData({ loginName: query.name, loginPwd: query.pwd });
  38. ctx.logger.info('user===================>' + user);
  39. addQuery.dept1 = user.dept1;
  40. addQuery.dept2 = user.dept2;
  41. addQuery.dept3 = user.dept3;
  42. addQuery.dept4 = user.dept4;
  43. addQuery.dept5 = user.dept5;
  44. addQuery.role = user.role;
  45. addQuery.loginName = query.name;
  46. // addQuery.tableName = 'user';
  47. addQuery.type = '绑定';
  48. addQuery.detail = JSON.stringify(query);
  49. addQuery.state = 'Applets';
  50. await this.service.sysLogService.add(addQuery);
  51. ctx.success();
  52. }
  53. }
  54. async unbind() {
  55. const { ctx, service } = this;
  56. const user = ctx.user;
  57. const result = await service.sysUserService.update(user._id, { appletsId: '' });
  58. ctx.success(result);
  59. }
  60. async updatePwd() {
  61. const { ctx, service } = this;
  62. const query = ctx.query;
  63. const result = await service.appletsService.updatePwdWithAppletsId(query);
  64. ctx.logic(result, '修改密码失败,原密码错误');
  65. }
  66. async homeStatistics() {
  67. const { ctx, service } = this;
  68. const query = ctx.query;
  69. const result = await service.appletsService.deptStatistics(query);
  70. ctx.success(result);
  71. }
  72. async suppleUserInfo() {
  73. const { ctx, service } = this;
  74. const user = ctx.user;
  75. const query = ctx.request.body;
  76. query.time = Date.now();
  77. const result = await service.sysUserService.update(user._id, query);
  78. ctx.success(result);
  79. }
  80. async findUserInfo() {
  81. const { ctx } = this;
  82. const user = ctx.user;
  83. ctx.success(user);
  84. }
  85. // 积分排名
  86. async userValue() {
  87. const { ctx, service } = this;
  88. const result = await service.appletsService.userValue();
  89. ctx.success(result);
  90. }
  91. async getToken() {
  92. const { ctx } = this;
  93. const result = await this.ctx.service.appletsService.getToken({ key: 'NgkKVL2KIyGTOqAs4FBKl8tW', secret: 'v4C8G72bREjtdWGScQAWLKlHhpoNb3u6' });
  94. ctx.success(result);
  95. }
  96. }
  97. module.exports = AppletsController;