|
@@ -10,7 +10,7 @@
|
|
const URL = require('url');
|
|
const URL = require('url');
|
|
const maintainConst = require('../const/maintain');
|
|
const maintainConst = require('../const/maintain');
|
|
const OAuth = require('co-wechat-oauth');
|
|
const OAuth = require('co-wechat-oauth');
|
|
-
|
|
|
|
|
|
+const office = require('../const/cld_office')
|
|
module.exports = app => {
|
|
module.exports = app => {
|
|
|
|
|
|
class LoginController extends app.BaseController {
|
|
class LoginController extends app.BaseController {
|
|
@@ -154,7 +154,6 @@ module.exports = app => {
|
|
*/
|
|
*/
|
|
async login(ctx) {
|
|
async login(ctx) {
|
|
let loginType = ctx.request.body.type;
|
|
let loginType = ctx.request.body.type;
|
|
-
|
|
|
|
try {
|
|
try {
|
|
loginType = parseInt(loginType);
|
|
loginType = parseInt(loginType);
|
|
const result = await ctx.service.projectAccount.accountLogin(ctx.request.body, loginType);
|
|
const result = await ctx.service.projectAccount.accountLogin(ctx.request.body, loginType);
|
|
@@ -279,7 +278,6 @@ module.exports = app => {
|
|
async port(ctx) {
|
|
async port(ctx) {
|
|
// 获取系统维护信息
|
|
// 获取系统维护信息
|
|
const maintainData = await ctx.service.maintain.getDataById(1);
|
|
const maintainData = await ctx.service.maintain.getDataById(1);
|
|
-
|
|
|
|
if (!ctx.app.config.is_debug) {
|
|
if (!ctx.app.config.is_debug) {
|
|
await ctx.service.maintain.syncMaintainData();
|
|
await ctx.service.maintain.syncMaintainData();
|
|
}
|
|
}
|
|
@@ -369,6 +367,119 @@ module.exports = app => {
|
|
ctx.redirect('/login');
|
|
ctx.redirect('/login');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * (项目管理)获取账号
|
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
|
+ */
|
|
|
|
+ async account(ctx) {
|
|
|
|
+ const data = ctx.data;
|
|
|
|
+ const response = {
|
|
|
|
+ code: 0,
|
|
|
|
+ data: 0,
|
|
|
|
+ msg: '',
|
|
|
|
+ };
|
|
|
|
+ try {
|
|
|
|
+ const project = await ctx.service.project.getProjectByCode(data.code);
|
|
|
|
+ if (!project) throw '未找到该项目';
|
|
|
|
+ const pa = await ctx.service.projectAccount.getAccountInfoByAccountWithPid(data.account, project.id);
|
|
|
|
+ if (!pa ) throw '该账号不存在,请联系管理员';
|
|
|
|
+ const manager = await ctx.service.manager.getDataById(project.manager_id)
|
|
|
|
+ const { is_admin: isAdmin, account_group: accountGroup, ...otherObj} = pa
|
|
|
|
+ response.data = {
|
|
|
|
+ account: { ...otherObj, accountGroup, isAdmin},
|
|
|
|
+ project: {
|
|
|
|
+ code: project.code,
|
|
|
|
+ name: project.name,
|
|
|
|
+ categoryId: project.manager_office,
|
|
|
|
+ category: office.list[project.manager_office],
|
|
|
|
+ staff: manager.real_name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error);
|
|
|
|
+ response.code = -1;
|
|
|
|
+ response.msg = error.toString();
|
|
|
|
+ }
|
|
|
|
+ ctx.body = response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * (项目管理)获取项目
|
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
|
+ */
|
|
|
|
+ async project(ctx) {
|
|
|
|
+ const data = ctx.data;
|
|
|
|
+ const response = {
|
|
|
|
+ code: 0,
|
|
|
|
+ data: 0,
|
|
|
|
+ msg: '',
|
|
|
|
+ };
|
|
|
|
+ try {
|
|
|
|
+ const project = await ctx.service.project.getProjectByCode(data.code);
|
|
|
|
+ if (!project) throw '未找到该项目';
|
|
|
|
+ response.data = project;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ response.code = -1;
|
|
|
|
+ response.msg = error.toString();
|
|
|
|
+ }
|
|
|
|
+ ctx.body = response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * (项目管理)校验项目
|
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
|
+ */
|
|
|
|
+ async vertifyProject(ctx) {
|
|
|
|
+ const response = {
|
|
|
|
+ code: 0,
|
|
|
|
+ data: 0,
|
|
|
|
+ msg: '',
|
|
|
|
+ };
|
|
|
|
+ try {
|
|
|
|
+ const code = ctx.session.sessionProject.code
|
|
|
|
+ const account = ctx.session.sessionUser.account
|
|
|
|
+ if (!code || !account) {
|
|
|
|
+ throw new Error('参数错误')
|
|
|
|
+ }
|
|
|
|
+ const result = await ctx.service.project.verifyManagementProject(ctx.helper.createJWT({ code }));
|
|
|
|
+ const token = ctx.helper.createJWT({ code, account })
|
|
|
|
+ const redirect = `${app.config.env === 'local' ? 'http://pmqa.smartcost.com.cn/auth' : 'http://pm.6jlzf.cn/auth'}?token=${token}`
|
|
|
|
+ response.data = { ...result, is_admin: ctx.session.sessionUser.account === ctx.session.sessionProject.userAccount, redirect};
|
|
|
|
+ } catch (error) {
|
|
|
|
+ response.code = -1;
|
|
|
|
+ response.msg = error.toString();
|
|
|
|
+ }
|
|
|
|
+ ctx.body = response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * (项目管理)新增项目
|
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
|
+ */
|
|
|
|
+ async addProject(ctx) {
|
|
|
|
+ const response = {
|
|
|
|
+ code: 0,
|
|
|
|
+ data: {},
|
|
|
|
+ msg: '',
|
|
|
|
+ };
|
|
|
|
+ try {
|
|
|
|
+ const result = await ctx.service.project.addProjectFromManagement()
|
|
|
|
+ if (!result) {
|
|
|
|
+ throw new Error('请求失败')
|
|
|
|
+ }
|
|
|
|
+ const { code = -1, data = {}, msg = '请求失败' } = result
|
|
|
|
+ if ( code === 0 ) {
|
|
|
|
+ response.data = data
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(msg)
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ response.code = -1;
|
|
|
|
+ response.msg = error.toString();
|
|
|
|
+ }
|
|
|
|
+ ctx.body = response;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return LoginController;
|
|
return LoginController;
|