1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const tenderConst = require('../const/tender');
- const auditConst = require('../const/audit');
- const officeList = require('../const/cld_office').list;
- const settingConst = require('../const/setting.js');
- const scheduleConst = require('../const/schedule');
- const settingMenu = require('../../config/menu').settingMenu;
- const accountGroup = require('../const/account_group').group;
- const permission = require('../const/account_permission').permission;
- const noticeAgainConst = require('../const/account_permission').noticeAgain;
- const projectLog = require('../const/project_log');
- const imType = require('../const/tender').imType;
- const S2b = require('../lib/s2b');
- const measureType = require('../const/tender').measureType;
- const sendToWormhole = require('stream-wormhole');
- const path = require('path');
- const funSet = require('../const/fun_set');
- const projectSettingConst = require('../const/project_setting');
- const SpreadConst = require('../const/spread');
- const shenpiConst = require('../const/shenpi');
- module.exports = app => {
- class SettingController extends app.BaseController {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局context
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- ctx.subMenu = settingMenu;
- }
- async _checkMenu(pid) {
- const ctx = this.ctx;
- await this.ctx.service.s2bProj.refreshSessionS2b(pid);
- ctx.subMenu.s2b.display = !!ctx.session.sessionProject.gxby || !!ctx.session.sessionProject.dagl;
- }
- /**
- * 项目信息页面(Get)
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async info(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- // 获取销售人员数据
- const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
- // 数据规则
- const rule = ctx.service.project.rule('saveInfo');
- const jsValidator = await this.jsValidator.convert(rule).build();
- const officeName = officeList[salesmanData.office];
- const date = new Date(projectData.create_time * 1000);// 如果date为10位不需要乘1000
- const Y = date.getFullYear() + '-';
- const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
- const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
- const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
- const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
- const dateStr = Y + M + D + h + m + s;
- const renderData = {
- projectData,
- salesmanData,
- officeName,
- officeList,
- jsValidator,
- dateStr,
- };
- await this.layout('setting/info.ejs', renderData);
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号设置(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async user(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- let keyword = '';
- if (ctx.query.keyword) {
- keyword = ctx.query.keyword;
- }
- let company = '';
- if (ctx.query.company) {
- company = ctx.query.company;
- }
- const page = ctx.page;
- const pageSize = ctx.pageSize;
- // 过滤数据
- ctx.service.projectAccount.searchFilter(ctx.request.query, projectId);
- ctx.sort = ['id', 'desc'];
- const total = await ctx.service.projectAccount.getCountWithBuilder();
- // 获取数据规则
- // const rule = ctx.service.projectAccount.rule('updateUser');
- // const frontRule = ctx.helper.validateConvert(rule);
- // const total = await ctx.service.projectAccount.count({ project_id: projectId });
- // 获取项目用户列表
- // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
- // where: { project_id: projectId },
- // columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
- // limit: (app.config.pageSize * (page - 1)),
- // offset: app.config.pageSize,
- // });
- // const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group', 'bind'];
- // const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
- const accountData = await ctx.service.projectAccount.getListWithBuilder();
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({project_id: projectId});
- // 分页相关
- const pageInfo = {
- page,
- pageSizeSelect: 1,
- pageSize,
- total_num: total,
- total: Math.ceil(total / pageSize),
- queryData: JSON.stringify(ctx.urlInfo.query),
- };
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
- const renderData = {
- projectData,
- accountData,
- accountGroup,
- permission,
- pageInfo,
- keyword,
- user_total,
- unitList,
- company,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
- // rule: JSON.stringify(frontRule),
- };
- await this.layout('setting/user.ejs', renderData, 'setting/user_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号解绑设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnbind(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '非管理员无权解绑账号';
- }
- const accountId = parseInt(ctx.request.body.id);
- const result = await ctx.service.projectAccount.update({bind: 0}, {id: accountId});
- if (!result) {
- throw '解绑失败';
- }
- this.setMessage('解绑成功', this.messageType.SUCCESS);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- }
- ctx.redirect(ctx.request.header.referer);
- }
- /**
- * 项目权限 -- 账号设置(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async userPermissionSet(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- let keyword = '';
- if (ctx.query.keyword) {
- keyword = ctx.query.keyword;
- }
- let company = '';
- if (ctx.query.company) {
- company = ctx.query.company;
- }
- // 获取数据规则
- const page = ctx.page;
- const pageSize = ctx.pageSize;
- const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'bind', 'account_group', 'permission', 'cooperation', 'notice_again'];
- // 过滤数据
- ctx.service.projectAccount.searchFilter(ctx.request.query, projectId, columns);
- ctx.sort = ['id', 'desc'];
- const total = await ctx.service.projectAccount.getCountWithBuilder();
- const accountData = await ctx.service.projectAccount.getListWithBuilder();
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({project_id: projectId});
- // 分页相关
- const pageInfo = {
- page,
- pageSizeSelect: 1,
- pageSize,
- total_num: total,
- total: Math.ceil(total / pageSize),
- queryData: JSON.stringify(ctx.urlInfo.query),
- };
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
- const noticeSet = projectData.notice_setting ? JSON.parse(projectData.notice_setting) : ctx.helper._.cloneDeep(projectSettingConst.noticeSetting);
- const renderData = {
- projectData,
- accountData,
- accountGroup,
- permission,
- keyword,
- permissionStr: JSON.stringify(permission),
- pageInfo,
- user_total,
- unitList,
- company,
- noticeAgainConst,
- noticeSet,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
- // rule: JSON.stringify(frontRule),
- };
- await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目权限 -- 参建单位(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnit(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
- for (const u of unitList) {
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {
- project_id: projectId,
- company: u.name
- }
- });
- u.account_num = accountList.length;
- }
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({project_id: projectId});
- const renderData = {
- projectData,
- accountGroup,
- unitList,
- user_total,
- company: null,
- fujianOssPath: ctx.app.config.fujianOssPath,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
- };
- await this.layout('setting/user_unit.ejs', renderData, 'setting/user_unit_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 单位新增设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnitAdd(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.constructionUnit.rule('add');
- ctx.validate(rule);
- ctx.request.body.pid = projectData.id;
- const result = await ctx.service.constructionUnit.save(ctx.request.body);
- if (!result) {
- throw '保存单位失败';
- }
- this.setMessage('保存单位成功', this.messageType.SUCCESS);
- ctx.redirect('/' + ctx.controllerName + '/user/unit');
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 单位编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnitSave(ctx) {
- const projectData = ctx.session.sessionProject;
- const responseData = {
- err: 0, msg: '', data: {},
- };
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- const data = JSON.parse(ctx.request.body.data);
- switch (data.type) {
- case 'update':
- const post_data = {
- pid: projectData.id,
- id: data.id,
- };
- post_data[data.val_name] = data.val;
- if (data.name) post_data.name = data.name;
- const result = await ctx.service.constructionUnit.save(post_data);
- if (!result) {
- throw '保存单位失败';
- }
- if (post_data.name) {
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {
- project_id: projectData.id,
- company: post_data.name
- }
- });
- responseData.data = {account_num: accountList.length};
- }
- break;
- case 'delete':
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {
- project_id: projectData.id,
- company: data.name
- }
- });
- if (accountList.length > 0) {
- throw '该单位下还存在账号,无法删除';
- }
- await ctx.service.constructionUnit.del(data.id);
- break;
- case 'del-sign':
- const info = await ctx.service.constructionUnit.getDataById(data.id);
- if (info.sign_path) {
- // 不删除地址,只删除数据库数据,防止已签章的报表丢失
- // await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + info.sign_path);
- }
- await ctx.service.constructionUnit.update({sign_path: null}, {id: info.id});
- break;
- case 'import-users':
- responseData.data = await ctx.service.projectAccount.addUsers(projectData.id, data.users);
- break;
- default:
- break;
- }
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async userUnitUpload(ctx) {
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- const stream = await ctx.getFileStream();
- const create_time = Date.parse(new Date()) / 1000;
- const fileInfo = path.parse(stream.filename);
- const filepath = `app/public/upload/sign/unit/qianzhang_${create_time + fileInfo.ext}`;
- await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
- await sendToWormhole(stream);
- const result = await ctx.service.constructionUnit.update({sign_path: filepath}, {id: stream.fields.id});
- if (result) {
- responseData.data = {sign_path: filepath};
- } else {
- throw '添加数据库失败';
- }
- } catch (err) {
- this.log(err);
- responseData.err = 1;
- responseData.msg = err;
- }
- ctx.body = responseData;
- }
- /**
- * 项目设置 -- 账号启用和停用设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userSwitch(ctx) {
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const data = JSON.parse(ctx.request.body.data);
- const result = await ctx.service.projectAccount.update(data, {id: data.id});
- if (!result) {
- throw '提交数据失败';
- }
- } catch (err) {
- this.log(err);
- responseData.err = 1;
- responseData.msg = err;
- }
- ctx.body = responseData;
- }
- /**
- * 项目设置 -- 账号添加(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async addUser(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.projectAccount.rule('add');
- ctx.validate(rule);
- // 判断新密码的强度
- const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
- if (!reg.test(ctx.request.body.password)) {
- throw '请设置至少包含数字和字母的密码';
- }
- ctx.request.body.project_id = projectData.id;
- const result = await ctx.service.projectAccount.save(ctx.request.body);
- if (!result) {
- throw '保存账号数据失败';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect('/' + ctx.controllerName + '/user');
- } catch (error) {
- console.log(error);
- ctx.session.postError = error.toString();
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 账号编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async updateUser(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.projectAccount.rule('modify');
- ctx.validate(rule);
- const result = await ctx.service.projectAccount.save(ctx.request.body);
- if (!result) {
- throw '保存账号数据失败';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- async resetUserPassword(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const accountId = parseInt(ctx.request.body.id);
- let password = ctx.request.body.reset_password;
- password = password.toString();
- const account = ctx.request.body.account !== undefined ? ctx.request.body.account : '';
- if (isNaN(accountId) || accountId <= 0 || password.length < 6) {
- throw '参数错误';
- }
- // 判断新密码的强度
- const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
- if (!reg.test(password)) {
- throw '请设置至少包含数字和字母的密码';
- }
- const result = await ctx.service.projectAccount.resetPassword(accountId, password, account);
- if (!result) {
- throw '重置密码失败!';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 账号权限编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async permission(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- const accountId = parseInt(ctx.request.body.id);
- const accountInfo = await ctx.service.projectAccount.getDataById(accountId);
- if (accountInfo === null) {
- throw '不存在该客户';
- }
- const result = await ctx.service.projectAccount.permissionSave(accountId, ctx.request.body);
- if (!result) {
- throw '修改权限失败!';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- // todo 暂时保留,如果支付审批不需要,则取消
- /**
- * 项目设置 -- 自定义标段分类(Get)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async category(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const categoryData = await ctx.service.category.getAllCategory(projectId);
- const tenderData = await ctx.service.tender.getList('', null, 1);
- const renderData = {
- projectData,
- categoryType: settingConst.cType,
- categoryData,
- tenderData,
- };
- await this.layout('setting/category.ejs', renderData, 'setting/category_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 新增分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async addCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.name) {
- throw '提交数据错误';
- }
- responseData.data = await ctx.service.category.addCategory(projectId, data.name, settingConst.cType.key.dropDown);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- /**
- * 编辑分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async updateCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {err: 0, msg: '', data: null};
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- if (data.name) {
- const count = await ctx.service.category.count({pid: projectId, name: data.name});
- if (count >= 1) {
- throw '存在同名类别';
- }
- }
- const result = await ctx.service.category.update(data, {id: data.id});
- if (!result) {
- throw '提交数据失败';
- }
- responseData.data = await ctx.service.category.getCategory(data.id);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async setCategoryValue(ctx) {
- try {
- const responseData = {err: 0, msg: '', data: {}};
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- await ctx.service.categoryValue.setCategoryValue(data.id, data.updateValue);
- responseData.data.category = await ctx.service.category.getCategory(data.id);
- responseData.data.tenders = await ctx.service.tender.getList('', null, 1);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err instanceof String ? err : '提交数据失败', data: null};
- }
- }
- /**
- * 删除分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async deleteCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- await ctx.service.category.deleteCategory(projectId, data.id);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- /**
- * 调整分类层次排序(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async resetCategoryLevel(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- await ctx.service.category.resetCategoryLevel(data);
- responseData.data = await ctx.service.category.getAllCategory(projectId);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async selfCategoryLevel(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- await ctx.service.projectAccount.defaultUpdate({
- id: ctx.session.sessionUser.accountId,
- self_category_level: data.self_category_level || ''
- });
- ctx.body = {
- err: 0, msg: '', data: null,
- };
- } catch (err) {
- ctx.log(err);
- ctx.ajaxErrorBody(err, '保存自定义分类失败');
- }
- }
- /** update porject info
- * @author wangfeng
- * @date 2018-10-12 15:48:05
- * @param ctx
- * @return {Promise<void>}
- */
- async updateinfo(ctx) {
- try {
- const projectId = ctx.params.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const conditionData = {
- id: projectId,
- };
- const data = ctx.request.body;
- const result = await ctx.service.project.update(data, conditionData);
- if (!result) {
- throw '提交数据失败';
- }
- ctx.redirect('/setting/info');
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async updateProjectSet(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- const allowField = ['notice_setting']; // 暂时只一个
- if (!ctx.helper._.includes(allowField, data.field)) {
- throw '非配置的字段无法使用本方法';
- }
- const result = await ctx.service.project.updateProjectSet(projectId, data.field, data.pData);
- if (!result) {
- throw '提交数据失败';
- }
- ctx.body = { err: 0, msg: '', data: result };
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- /**
- * 检测账户是否存在
- *
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async accountExist(ctx) {
- const projectData = ctx.session.sessionProject;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- const data = JSON.parse(ctx.request.body.data);
- const account = data.account;
- if (projectData.id === undefined) {
- throw '不存在对应项目';
- }
- responseData.data = await ctx.service.projectAccount.isAccountExist(account, projectData.id);
- ctx.body = responseData;
- } catch (error) {
- ctx.body = {err: 1, msg: error.toString(), data: null};
- }
- }
- /**
- * 显示设置(Get)
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async show(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (!projectData) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const showList = await ctx.service.settingShow.getList(projectData.page_path);
- const sjsRela = await ctx.service.project.getSjsRela(projectId);
- const projectSpread = await ctx.service.projectSpread.getProjectSpreadType(projectId);
- const renderData = {projectData, showList, sjsRela, settingConst, projectSpread};
- await this.layout('setting/show.ejs', renderData);
- } catch (error) {
- this.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 更新显示设置列表
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async showListUpdate(ctx) {
- try {
- // 获取项目id
- const projectId = ctx.session.sessionProject.id;
- const {data} = ctx.request.body;
- const {id} = JSON.parse(data);
- const result = await ctx.service.settingShow.setDefaultLabel(id, projectId);
- const responseData = {err: 0, msg: '', data: result};
- ctx.body = responseData;
- } catch (error) {
- this.log(error);
- ctx.body = {err: 1, msg: error.toString(), data: null};
- }
- }
- async showSjsUpdate(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- const result = await ctx.service.project.updateSjsRela(projectId, data.sub, data.field, data.key, data.value);
- ctx.body = {err: 0, msg: '', data: result};
- } catch (err) {
- this.log(err);
- this.ajaxErrorBody(err, '保存数据失败');
- }
- }
- async logs(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const settingType = ctx.params.type ? parseInt(ctx.params.type) : 0;
- const logs = await ctx.service.projectLog.getLogs(projectId, settingType);
- const renderData = {
- projectData,
- officeList,
- projectLog,
- settingType,
- logs,
- };
- await this.layout('setting/logs.ejs', renderData);
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async fun(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- const funRela = await ctx.service.project.getFunRela(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
- await this.layout('setting/fun.ejs', {
- projectData,
- funRela,
- imType,
- endMonth: funSet.endMonth,
- funSet: fun_set,
- }, 'setting/fun_modal.ejs');
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 保存功能设置相关
- * @param ctx
- * @returns {Promise<void>}
- */
- async updateFun(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const data = JSON.parse(ctx.request.body.data);
- if (data) ctx.request.body = data;
- const rule = ctx.service.project.rule('fun');
- ctx.validate(rule);
- const result = await ctx.service.project.updateFunRela(projectId, ctx.request.body);
- if (!result) throw '保存数据失败';
- this.ctx.session.sessionProject.page_show.openChangeProject = data.openChangeProject ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangeApply = data.openChangeApply ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangePlan = data.openChangePlan ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangeWhiteList = data.openChangeWhiteList ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangeState = data.openChangeState ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialTax = data.openMaterialTax ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialChecklist = data.openMaterialChecklist ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialSelf = data.openMaterialSelf ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialEditForAudit = data.openMaterialEditForAudit ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openStageStart = data.openStageStart ? 1 : 0;
- const result2 = await ctx.service.project.updatePageshow(projectId);
- if (!result2) throw '保存数据失败';
- if (data.addFunSet) {
- const funSet = projectData.fun_set ? JSON.parse(projectData.fun_set) : {};
- ctx.helper._.defaultsDeep(data.addFunSet, funSet);
- const result3 = await ctx.service.project.updateFunSet(projectId, data.addFunSet);
- if (!result3) throw '保存数据失败';
- }
- ctx.body = {err: 0, msg: '', data: null};
- } catch (error) {
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async s2b(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const tenders = await ctx.service.tender.getAllDataByCondition({where: {project_id: projectId}});
- for (const t of tenders) {
- t.measure_type_str = t.measure_type === measureType.tz.value ? measureType.tz.title : measureType.gcl.title;
- const stages = await ctx.service.stage.getAllDataByCondition({where: {tid: t.id}});
- t.stage_count_str = `第${stages.length || 0}期`;
- const user = await ctx.service.projectAccount.getAccountInfoById(t.user_id);
- t.user_str = user.name + '-' + user.company;
- t.show_time = stages.length > 0 ? stages[stages.length - 1].cache_time_r || stages[stages.length - 1].in_time : t.create_time;
- }
- await this.layout('setting/s2b.ejs', {
- projectData,
- tenders,
- });
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async s2bUpdate(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const data = JSON.parse(ctx.request.body.data);
- if (!data.tid) throw '提交数据错误';
- const updateData = {};
- if (data.gxby_limit !== undefined) updateData.s2b_gxby_limit = data.gxby_limit;
- if (data.gxby_check !== undefined) updateData.s2b_gxby_check = data.gxby_check;
- if (data.dagl_limit !== undefined) updateData.s2b_dagl_limit = data.dagl_limit;
- if (data.dagl_check !== undefined) updateData.s2b_dagl_check = data.dagl_check;
- await ctx.service.tender.saveApiRela(data.tid, updateData);
- ctx.body = {err: 0, msg: '', data: null};
- } catch (error) {
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async s2bUpdateStatus(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const data = JSON.parse(ctx.request.body.data);
- if (!data.type || data.status === undefined) throw '提交数据错误';
- const responseData = {err: 0, msg: '', data: null};
- switch (data.type) {
- case 'gxby':
- responseData.data = await this.ctx.service.s2bProj.updateGxbyStatus(projectId, data.status, data.limit, data.ratio);
- break;
- case 'dagl':
- responseData.data = await this.ctx.service.s2bProj.updateDaglStatus(projectId, data.status, data.limit, data.ratio);
- break;
- default:
- throw '提交数据错误';
- }
- ctx.body = responseData;
- } catch (error) {
- console.log(error);
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async manage(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const tenderList = await ctx.service.tender.getList('', null, 1);
- const removeTenders = await ctx.service.shenpiAudit.getRemoveTenders(tenderList);
- if (removeTenders.length > 0) {
- ctx.helper._.remove(tenderList, function(n) {
- return removeTenders.indexOf(n.id) !== -1;
- });
- }
- for (const t of tenderList) {
- t.visitor = (await this.ctx.service.tenderTourist.getTourists(t.id)).map(x => { return x.user_name; });
- await this.ctx.service.tenderCache.loadTenderCache(t, this.ctx.session.sessionUser.accountId);
- }
- // todo 自定义分类移动到子项目内部后,在整个项目上没有分类了
- const categoryData = []; // await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
- // 获取所有项目参与者
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {project_id: ctx.session.sessionProject.id, enable: 1},
- columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
- });
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
- const accountGroupList = unitList.map(item => {
- const groupList = accountList.filter(item1 => item1.company === item.name);
- return {groupName: item.name, groupList};
- });
- const renderData = {
- projectData,
- tenderList,
- auditConst,
- auditType: auditConst.auditType,
- accountList,
- accountGroup: accountGroupList,
- categoryData,
- settingConst,
- measureType: tenderConst.measureType,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.manage),
- uid: this.ctx.session.sessionUser.accountId,
- pid: this.ctx.session.sessionProject.id,
- scPermission: scheduleConst.permission,
- change_type_list: shenpiConst.change_type_list,
- };
- renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
- await this.layout('setting/manage.ejs', renderData, 'setting/manage_modal.ejs');
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async manageTenderSave(ctx) {
- try {
- if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: {},
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.type) {
- throw '提交数据错误';
- }
- if (!data.tid) {
- throw '参数有误';
- }
- const tender = await ctx.service.tender.getDataById(data.tid);
- if (!tender) {
- throw '标段不存在';
- }
- const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(tender.id);
- switch (data.type) {
- case 'msg':
- const lastRevise = await ctx.service.ledgerRevise.getLastestRevise(tender.id);
- const revising = (lastRevise && lastRevise.status !== auditConst.revise.status.checked) || false;
- // 获取审批流,游客账号,及投资进度账号信息
- responseData.data.tender = tender;
- responseData.data.revising = revising;
- responseData.data.shenpi = await ctx.service.shenpiAudit.getShenpi(tender.id, tenderInfo);
- const tourists = await ctx.service.tenderTourist.getTourists(tender.id);
- for (const t of tourists) {
- t.permission = await ctx.service.tenderTourist.getTouristPermission(t);
- }
- responseData.data.tourists = tourists;
- responseData.data.scheduleAuditList = ctx.session.sessionProject.page_show.xxjd ? await ctx.service.scheduleAudit.getAllDataByCondition({ where: { tid: tender.id } }) : [];
- responseData.data.constructionAuditList = ctx.session.sessionProject.page_show.openConstruction ? await ctx.service.constructionAudit.getList(tender.id) : [];
- break;
- case 'copy2otu':
- if (data.userType === 'tourist') {
- await ctx.service.tenderTourist.setOtherTender(data.tidList, data.auditList);
- } else if (data.userType === 'schedule') {
- await ctx.service.scheduleAudit.setOtherTender(data.tidList, data.auditList);
- } else if (data.userType === 'construction') {
- await ctx.service.constructionAudit.setOtherTender(data.tidList, data.auditList);
- } else {
- throw '参数有误';
- }
- break;
- default:
- throw '参数有误';
- }
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- async spread(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (!projectData) throw '没有对应的项目数据';
- const sType = ctx.query.stype;
- const code = ctx.query.code;
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectData.id, code);
- const renderData = {
- BaseSetCol: SpreadConst.BaseSetCol[sType],
- sType,
- code,
- colSet: projectSpread[sType],
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.spread),
- };
- await this.layout('setting/spread.ejs', renderData, 'setting/spread_modal.ejs');
- } catch (error) {
- this.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async saveSpread(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, data.colSet);
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
- ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- async previewSpread(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const [billsSpread, posSpread] = this.ctx.service.projectSpread.generateRelaSpread(data.sType, data.colSet);
- ctx.body = { err: 0, msg: '', data: { billsSpread, posSpread } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- async resetSpread(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- const spreadTemplate = SpreadConst.ProjectSpreadTemplate.find(x => { return x.code === data.code; });
- const colSet = spreadTemplate.template[data.sType];
- await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, colSet);
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
- ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- }
- return SettingController;
- };
|