'use strict'; const Controller = require('egg').Controller; class AppletsController extends Controller { async isExist() { const { ctx, service } = this; const query = ctx.query; const { appletsId } = query; const result = await service.sysUserService.oneData({ appletsId }); if (result) { // ctx.logger.info('isExist--result=============>' + result); // 添加log const addQuery = {}; addQuery.dept1 = result.dept1; addQuery.dept2 = result.dept2; addQuery.dept3 = result.dept3; addQuery.dept4 = result.dept4; addQuery.dept5 = result.dept5; addQuery.role = result.role; addQuery.loginName = result.loginName; // addQuery.tableName = 'user'; addQuery.type = '登录'; addQuery.detail = 'appletsId是否存在'; addQuery.state = 'Applets'; await this.service.sysLogService.add(addQuery); } ctx.logic(result, ' '); } async bing() { const { ctx, service } = this; const query = ctx.query; const result = await service.appletsService.bing(query); if (result) { ctx.error(result); } else { // 添加log const addQuery = {}; const user = await service.sysUserService.oneData({ loginName: query.name, loginPwd: query.pwd }); ctx.logger.info('user===================>' + user); addQuery.dept1 = user.dept1; addQuery.dept2 = user.dept2; addQuery.dept3 = user.dept3; addQuery.dept4 = user.dept4; addQuery.dept5 = user.dept5; addQuery.role = user.role; addQuery.loginName = query.name; // addQuery.tableName = 'user'; addQuery.type = '绑定'; addQuery.detail = JSON.stringify(query); addQuery.state = 'Applets'; await this.service.sysLogService.add(addQuery); ctx.success(); } } async unbind() { const { ctx, service } = this; const user = ctx.user; const result = await service.sysUserService.update(user._id, { appletsId: '' }); ctx.success(result); } async updatePwd() { const { ctx, service } = this; const query = ctx.query; const result = await service.appletsService.updatePwdWithAppletsId(query); ctx.logic(result, '修改密码失败,原密码错误'); } async homeStatistics() { const { ctx, service } = this; const query = ctx.query; const result = await service.appletsService.deptStatistics(query); ctx.success(result); } async suppleUserInfo() { const { ctx, service } = this; const user = ctx.user; const query = ctx.request.body; query.time = Date.now(); const result = await service.sysUserService.update(user._id, query); ctx.success(result); } async findUserInfo() { const { ctx } = this; const user = ctx.user; ctx.success(user); } // 积分排名 async userValue() { const { ctx, service } = this; const result = await service.appletsService.userValue(); ctx.success(result); } async getToken() { const { ctx } = this; const result = await this.ctx.service.appletsService.getToken({ key: 'NgkKVL2KIyGTOqAs4FBKl8tW', secret: 'v4C8G72bREjtdWGScQAWLKlHhpoNb3u6' }); ctx.success(result); } } module.exports = AppletsController;