setting_controller.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const tenderConst = require('../const/tender');
  10. const auditConst = require('../const/audit');
  11. const officeList = require('../const/cld_office').list;
  12. const settingConst = require('../const/setting.js');
  13. const scheduleConst = require('../const/schedule');
  14. const settingMenu = require('../../config/menu').settingMenu;
  15. const accountGroup = require('../const/account_group').group;
  16. const permission = require('../const/account_permission').permission;
  17. const noticeAgainConst = require('../const/account_permission').noticeAgain;
  18. const projectLog = require('../const/project_log');
  19. const imType = require('../const/tender').imType;
  20. const S2b = require('../lib/s2b');
  21. const measureType = require('../const/tender').measureType;
  22. const sendToWormhole = require('stream-wormhole');
  23. const path = require('path');
  24. const funSet = require('../const/fun_set');
  25. const projectSettingConst = require('../const/project_setting');
  26. const SpreadConst = require('../const/spread');
  27. const shenpiConst = require('../const/shenpi');
  28. module.exports = app => {
  29. class SettingController extends app.BaseController {
  30. /**
  31. * 构造函数
  32. *
  33. * @param {Object} ctx - egg全局context
  34. * @return {void}
  35. */
  36. constructor(ctx) {
  37. super(ctx);
  38. ctx.subMenu = settingMenu;
  39. }
  40. async _checkMenu(pid) {
  41. const ctx = this.ctx;
  42. await this.ctx.service.s2bProj.refreshSessionS2b(pid);
  43. ctx.subMenu.s2b.display = !!ctx.session.sessionProject.gxby || !!ctx.session.sessionProject.dagl;
  44. ctx.subMenu.datacollect.display = ctx.session.sessionProject.page_show.openDataCollect;
  45. // this.ctx.subMenu.s2b.display = false;
  46. }
  47. /**
  48. * 项目信息页面(Get)
  49. *
  50. * @param {Object} ctx - egg全局变量
  51. * @return {void}
  52. */
  53. async info(ctx) {
  54. try {
  55. // 获取项目数据
  56. const projectId = ctx.session.sessionProject.id;
  57. await this._checkMenu(projectId);
  58. const projectData = await ctx.service.project.getDataById(projectId);
  59. if (projectData === null) {
  60. throw '没有对应的项目数据';
  61. }
  62. // 获取销售人员数据
  63. const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
  64. // 数据规则
  65. const rule = ctx.service.project.rule('saveInfo');
  66. const jsValidator = await this.jsValidator.convert(rule).build();
  67. const officeName = officeList[salesmanData.office];
  68. const date = new Date(projectData.create_time * 1000);// 如果date为10位不需要乘1000
  69. const Y = date.getFullYear() + '-';
  70. const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  71. const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  72. const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  73. const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  74. const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  75. const dateStr = Y + M + D + h + m + s;
  76. const renderData = {
  77. projectData,
  78. salesmanData,
  79. officeName,
  80. officeList,
  81. jsValidator,
  82. dateStr,
  83. };
  84. await this.layout('setting/info.ejs', renderData);
  85. } catch (error) {
  86. console.log(error);
  87. ctx.redirect('/dashboard');
  88. }
  89. }
  90. /**
  91. * 项目设置 -- 账号设置(Get)
  92. * @param ctx
  93. * @return {Promise<void>}
  94. */
  95. async user(ctx) {
  96. try {
  97. // 获取项目数据
  98. const projectId = ctx.session.sessionProject.id;
  99. await this._checkMenu(projectId);
  100. const projectData = await ctx.service.project.getDataById(projectId);
  101. if (projectData === null) {
  102. throw '没有对应的项目数据';
  103. }
  104. if (ctx.session.sessionUser.is_admin === 0) {
  105. throw '没有访问权限';
  106. }
  107. let keyword = '';
  108. if (ctx.query.keyword) {
  109. keyword = ctx.query.keyword;
  110. }
  111. let company = '';
  112. if (ctx.query.company) {
  113. company = ctx.query.company;
  114. }
  115. const page = ctx.page;
  116. const pageSize = ctx.pageSize;
  117. // 过滤数据
  118. ctx.service.projectAccount.searchFilter(ctx.request.query, projectId);
  119. ctx.sort = ['id', 'desc'];
  120. const total = await ctx.service.projectAccount.getCountWithBuilder();
  121. // 获取数据规则
  122. // const rule = ctx.service.projectAccount.rule('updateUser');
  123. // const frontRule = ctx.helper.validateConvert(rule);
  124. // const total = await ctx.service.projectAccount.count({ project_id: projectId });
  125. // 获取项目用户列表
  126. // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
  127. // where: { project_id: projectId },
  128. // columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
  129. // limit: (app.config.pageSize * (page - 1)),
  130. // offset: app.config.pageSize,
  131. // });
  132. // const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group', 'bind'];
  133. // const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
  134. const accountData = await ctx.service.projectAccount.getListWithBuilder();
  135. // 获取账号个数
  136. const user_total = await ctx.service.projectAccount.count({project_id: projectId});
  137. // 分页相关
  138. const pageInfo = {
  139. page,
  140. pageSizeSelect: 1,
  141. pageSize,
  142. total_num: total,
  143. total: Math.ceil(total / pageSize),
  144. queryData: JSON.stringify(ctx.urlInfo.query),
  145. };
  146. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
  147. const renderData = {
  148. projectData,
  149. accountData,
  150. accountGroup,
  151. permission,
  152. pageInfo,
  153. keyword,
  154. user_total,
  155. unitList,
  156. company,
  157. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
  158. // rule: JSON.stringify(frontRule),
  159. };
  160. await this.layout('setting/user.ejs', renderData, 'setting/user_modal.ejs');
  161. } catch (error) {
  162. console.log(error);
  163. ctx.redirect('/dashboard');
  164. }
  165. }
  166. /**
  167. * 项目设置 -- 账号解绑设置(Post)
  168. * @param ctx
  169. * @return {Promise<void>}
  170. */
  171. async userUnbind(ctx) {
  172. const projectData = ctx.session.sessionProject;
  173. try {
  174. if (projectData.id === undefined) {
  175. throw '不存在对应的项目数据';
  176. }
  177. if (ctx.session.sessionUser.is_admin === 0) {
  178. throw '非管理员无权解绑账号';
  179. }
  180. const accountId = parseInt(ctx.request.body.id);
  181. const result = await ctx.service.projectAccount.update({bind: 0}, {id: accountId});
  182. if (!result) {
  183. throw '解绑失败';
  184. }
  185. this.setMessage('解绑成功', this.messageType.SUCCESS);
  186. } catch (error) {
  187. console.log(error);
  188. this.setMessage(error.toString(), this.messageType.ERROR);
  189. }
  190. ctx.redirect(ctx.request.header.referer);
  191. }
  192. /**
  193. * 项目权限 -- 账号设置(Get)
  194. * @param ctx
  195. * @return {Promise<void>}
  196. */
  197. async userPermissionSet(ctx) {
  198. try {
  199. // 获取项目数据
  200. const projectId = ctx.session.sessionProject.id;
  201. const projectData = await ctx.service.project.getDataById(projectId);
  202. if (projectData === null) {
  203. throw '没有对应的项目数据';
  204. }
  205. if (ctx.session.sessionUser.is_admin === 0) {
  206. throw '没有访问权限';
  207. }
  208. let keyword = '';
  209. if (ctx.query.keyword) {
  210. keyword = ctx.query.keyword;
  211. }
  212. let company = '';
  213. if (ctx.query.company) {
  214. company = ctx.query.company;
  215. }
  216. // 获取数据规则
  217. const page = ctx.page;
  218. const pageSize = ctx.pageSize;
  219. const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'bind', 'account_group', 'permission', 'cooperation', 'notice_again'];
  220. // 过滤数据
  221. ctx.service.projectAccount.searchFilter(ctx.request.query, projectId, columns);
  222. ctx.sort = ['id', 'desc'];
  223. const total = await ctx.service.projectAccount.getCountWithBuilder();
  224. const accountData = await ctx.service.projectAccount.getListWithBuilder();
  225. // 获取账号个数
  226. const user_total = await ctx.service.projectAccount.count({project_id: projectId});
  227. // 分页相关
  228. const pageInfo = {
  229. page,
  230. pageSizeSelect: 1,
  231. pageSize,
  232. total_num: total,
  233. total: Math.ceil(total / pageSize),
  234. queryData: JSON.stringify(ctx.urlInfo.query),
  235. };
  236. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
  237. const noticeSet = projectData.notice_setting ? JSON.parse(projectData.notice_setting) : ctx.helper._.cloneDeep(projectSettingConst.noticeSetting);
  238. const renderData = {
  239. projectData,
  240. accountData,
  241. accountGroup,
  242. permission,
  243. keyword,
  244. permissionStr: JSON.stringify(permission),
  245. pageInfo,
  246. user_total,
  247. unitList,
  248. company,
  249. noticeAgainConst,
  250. noticeSet,
  251. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
  252. // rule: JSON.stringify(frontRule),
  253. };
  254. await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');
  255. } catch (error) {
  256. console.log(error);
  257. ctx.redirect('/dashboard');
  258. }
  259. }
  260. /**
  261. * 项目权限 -- 参建单位(Get)
  262. * @param ctx
  263. * @return {Promise<void>}
  264. */
  265. async userUnit(ctx) {
  266. try {
  267. // 获取项目数据
  268. const projectId = ctx.session.sessionProject.id;
  269. const projectData = await ctx.service.project.getDataById(projectId);
  270. if (projectData === null) {
  271. throw '没有对应的项目数据';
  272. }
  273. if (ctx.session.sessionUser.is_admin === 0) {
  274. throw '没有访问权限';
  275. }
  276. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
  277. for (const u of unitList) {
  278. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  279. where: {
  280. project_id: projectId,
  281. company: u.name
  282. }
  283. });
  284. u.account_num = accountList.length;
  285. }
  286. // 获取账号个数
  287. const user_total = await ctx.service.projectAccount.count({project_id: projectId});
  288. const renderData = {
  289. projectData,
  290. accountGroup,
  291. unitList,
  292. user_total,
  293. company: null,
  294. fujianOssPath: ctx.app.config.fujianOssPath,
  295. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
  296. };
  297. await this.layout('setting/user_unit.ejs', renderData, 'setting/user_unit_modal.ejs');
  298. } catch (error) {
  299. console.log(error);
  300. ctx.redirect('/dashboard');
  301. }
  302. }
  303. /**
  304. * 项目设置 -- 单位新增设置(Post)
  305. * @param ctx
  306. * @return {Promise<void>}
  307. */
  308. async userUnitAdd(ctx) {
  309. const projectData = ctx.session.sessionProject;
  310. try {
  311. // 验证数据
  312. if (projectData.id === undefined) {
  313. throw '不存在对应的项目数据';
  314. }
  315. // 获取验证规则
  316. const rule = ctx.service.constructionUnit.rule('add');
  317. ctx.validate(rule);
  318. ctx.request.body.pid = projectData.id;
  319. const result = await ctx.service.constructionUnit.save(ctx.request.body);
  320. if (!result) {
  321. throw '保存单位失败';
  322. }
  323. this.setMessage('保存单位成功', this.messageType.SUCCESS);
  324. ctx.redirect('/' + ctx.controllerName + '/user/unit');
  325. } catch (error) {
  326. console.log(error);
  327. this.setMessage(error.toString(), this.messageType.ERROR);
  328. ctx.redirect(ctx.request.header.referer);
  329. }
  330. }
  331. /**
  332. * 项目设置 -- 单位编辑(Post)
  333. * @param ctx
  334. * @return {Promise<void>}
  335. */
  336. async userUnitSave(ctx) {
  337. const projectData = ctx.session.sessionProject;
  338. const responseData = {
  339. err: 0, msg: '', data: {},
  340. };
  341. try {
  342. // 验证数据
  343. if (projectData.id === undefined) {
  344. throw '不存在对应的项目数据';
  345. }
  346. const data = JSON.parse(ctx.request.body.data);
  347. switch (data.type) {
  348. case 'update':
  349. const post_data = {
  350. pid: projectData.id,
  351. id: data.id,
  352. };
  353. post_data[data.val_name] = data.val;
  354. if (data.name) post_data.name = data.name;
  355. const result = await ctx.service.constructionUnit.save(post_data);
  356. if (!result) {
  357. throw '保存单位失败';
  358. }
  359. if (post_data.name) {
  360. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  361. where: {
  362. project_id: projectData.id,
  363. company: post_data.name
  364. }
  365. });
  366. responseData.data = {account_num: accountList.length};
  367. }
  368. break;
  369. case 'delete':
  370. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  371. where: {
  372. project_id: projectData.id,
  373. company: data.name
  374. }
  375. });
  376. if (accountList.length > 0) {
  377. throw '该单位下还存在账号,无法删除';
  378. }
  379. await ctx.service.constructionUnit.del(data.id);
  380. break;
  381. case 'del-sign':
  382. const info = await ctx.service.constructionUnit.getDataById(data.id);
  383. if (info.sign_path) {
  384. // 不删除地址,只删除数据库数据,防止已签章的报表丢失
  385. // await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + info.sign_path);
  386. }
  387. await ctx.service.constructionUnit.update({sign_path: null}, {id: info.id});
  388. break;
  389. case 'import-users':
  390. responseData.data = await ctx.service.projectAccount.addUsers(projectData.id, data.users);
  391. break;
  392. default:
  393. break;
  394. }
  395. ctx.body = responseData;
  396. } catch (err) {
  397. this.log(err);
  398. ctx.body = {err: 1, msg: err.toString(), data: null};
  399. }
  400. }
  401. async userUnitUpload(ctx) {
  402. const responseData = {
  403. err: 0, msg: '', data: null,
  404. };
  405. try {
  406. const stream = await ctx.getFileStream();
  407. const create_time = Date.parse(new Date()) / 1000;
  408. const fileInfo = path.parse(stream.filename);
  409. const filepath = `app/public/upload/sign/unit/qianzhang_${create_time + fileInfo.ext}`;
  410. await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
  411. await sendToWormhole(stream);
  412. const result = await ctx.service.constructionUnit.update({sign_path: filepath}, {id: stream.fields.id});
  413. if (result) {
  414. responseData.data = {sign_path: filepath};
  415. } else {
  416. throw '添加数据库失败';
  417. }
  418. } catch (err) {
  419. this.log(err);
  420. responseData.err = 1;
  421. responseData.msg = err;
  422. }
  423. ctx.body = responseData;
  424. }
  425. /**
  426. * 项目设置 -- 账号启用和停用设置(Post)
  427. * @param ctx
  428. * @return {Promise<void>}
  429. */
  430. async userSwitch(ctx) {
  431. const responseData = {
  432. err: 0, msg: '', data: null,
  433. };
  434. try {
  435. // 获取项目数据
  436. const projectId = ctx.session.sessionProject.id;
  437. const projectData = await ctx.service.project.getDataById(projectId);
  438. if (projectData === null) {
  439. throw '没有对应的项目数据';
  440. }
  441. if (ctx.session.sessionUser.is_admin === 0) {
  442. throw '没有访问权限';
  443. }
  444. const data = JSON.parse(ctx.request.body.data);
  445. const result = await ctx.service.projectAccount.update(data, {id: data.id});
  446. if (!result) {
  447. throw '提交数据失败';
  448. }
  449. } catch (err) {
  450. this.log(err);
  451. responseData.err = 1;
  452. responseData.msg = err;
  453. }
  454. ctx.body = responseData;
  455. }
  456. /**
  457. * 项目设置 -- 账号添加(Post)
  458. * @param ctx
  459. * @return {Promise<void>}
  460. */
  461. async addUser(ctx) {
  462. const projectData = ctx.session.sessionProject;
  463. try {
  464. // 验证数据
  465. if (projectData.id === undefined) {
  466. throw '不存在对应的项目数据';
  467. }
  468. // 获取验证规则
  469. const rule = ctx.service.projectAccount.rule('add');
  470. ctx.validate(rule);
  471. // 判断新密码的强度
  472. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  473. if (!reg.test(ctx.request.body.password)) {
  474. throw '请设置至少包含数字和字母的密码';
  475. }
  476. ctx.request.body.project_id = projectData.id;
  477. const result = await ctx.service.projectAccount.save(ctx.request.body);
  478. if (!result) {
  479. throw '保存账号数据失败';
  480. }
  481. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  482. ctx.redirect('/' + ctx.controllerName + '/user');
  483. } catch (error) {
  484. console.log(error);
  485. ctx.session.postError = error.toString();
  486. this.setMessage(error.toString(), this.messageType.ERROR);
  487. ctx.redirect(ctx.request.header.referer);
  488. }
  489. }
  490. /**
  491. * 项目设置 -- 账号编辑(Post)
  492. * @param ctx
  493. * @return {Promise<void>}
  494. */
  495. async updateUser(ctx) {
  496. const projectData = ctx.session.sessionProject;
  497. try {
  498. // 验证数据
  499. if (projectData.id === undefined) {
  500. throw '不存在对应的项目数据';
  501. }
  502. // 获取验证规则
  503. const rule = ctx.service.projectAccount.rule('modify');
  504. ctx.validate(rule);
  505. const result = await ctx.service.projectAccount.save(ctx.request.body);
  506. if (!result) {
  507. throw '保存账号数据失败';
  508. }
  509. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  510. ctx.redirect(ctx.request.header.referer);
  511. } catch (error) {
  512. console.log(error);
  513. this.setMessage(error.toString(), this.messageType.ERROR);
  514. ctx.redirect(ctx.request.header.referer);
  515. }
  516. }
  517. async resetUserPassword(ctx) {
  518. try {
  519. // 获取项目数据
  520. const projectId = ctx.session.sessionProject.id;
  521. const projectData = await ctx.service.project.getDataById(projectId);
  522. if (projectData === null) {
  523. throw '没有对应的项目数据';
  524. }
  525. if (ctx.session.sessionUser.is_admin === 0) {
  526. throw '没有访问权限';
  527. }
  528. const accountId = parseInt(ctx.request.body.id);
  529. let password = ctx.request.body.reset_password;
  530. password = password.toString();
  531. const account = ctx.request.body.account !== undefined ? ctx.request.body.account : '';
  532. if (isNaN(accountId) || accountId <= 0 || password.length < 6) {
  533. throw '参数错误';
  534. }
  535. // 判断新密码的强度
  536. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  537. if (!reg.test(password)) {
  538. throw '请设置至少包含数字和字母的密码';
  539. }
  540. const result = await ctx.service.projectAccount.resetPassword(accountId, password, account);
  541. if (!result) {
  542. throw '重置密码失败!';
  543. }
  544. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  545. ctx.redirect(ctx.request.header.referer);
  546. } catch (error) {
  547. console.log(error);
  548. this.setMessage(error.toString(), this.messageType.ERROR);
  549. ctx.redirect(ctx.request.header.referer);
  550. }
  551. }
  552. /**
  553. * 项目设置 -- 账号权限编辑(Post)
  554. * @param ctx
  555. * @return {Promise<void>}
  556. */
  557. async permission(ctx) {
  558. const projectData = ctx.session.sessionProject;
  559. try {
  560. // 验证数据
  561. if (projectData.id === undefined) {
  562. throw '不存在对应的项目数据';
  563. }
  564. const accountId = parseInt(ctx.request.body.id);
  565. const accountInfo = await ctx.service.projectAccount.getDataById(accountId);
  566. if (accountInfo === null) {
  567. throw '不存在该客户';
  568. }
  569. const result = await ctx.service.projectAccount.permissionSave(accountId, ctx.request.body);
  570. if (!result) {
  571. throw '修改权限失败!';
  572. }
  573. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  574. ctx.redirect(ctx.request.header.referer);
  575. } catch (error) {
  576. console.log(error);
  577. this.setMessage(error.toString(), this.messageType.ERROR);
  578. ctx.redirect(ctx.request.header.referer);
  579. }
  580. }
  581. /**
  582. * 项目设置 -- 自定义标段分类(Get)
  583. *
  584. * @param ctx
  585. * @return {Promise<void>}
  586. */
  587. async category(ctx) {
  588. try {
  589. // 获取项目数据
  590. const projectId = ctx.session.sessionProject.id;
  591. await this._checkMenu(projectId);
  592. const projectData = await ctx.service.project.getDataById(projectId);
  593. if (projectData === null) {
  594. throw '没有对应的项目数据';
  595. }
  596. if (ctx.session.sessionUser.is_admin === 0) {
  597. throw '没有访问权限';
  598. }
  599. const categoryData = await ctx.service.category.getAllCategory(projectId);
  600. const tenderData = await ctx.service.tender.getList('', null, 1);
  601. const renderData = {
  602. projectData,
  603. categoryType: settingConst.cType,
  604. categoryData,
  605. tenderData,
  606. };
  607. await this.layout('setting/category.ejs', renderData, 'setting/category_modal.ejs');
  608. } catch (error) {
  609. console.log(error);
  610. ctx.redirect('/dashboard');
  611. }
  612. }
  613. /**
  614. * 新增分类(Ajax)
  615. *
  616. * @param ctx
  617. * @return {Promise<void>}
  618. */
  619. async addCategory(ctx) {
  620. try {
  621. const projectId = ctx.session.sessionProject.id;
  622. const responseData = {
  623. err: 0, msg: '', data: null,
  624. };
  625. const data = JSON.parse(ctx.request.body.data);
  626. if (!data.name) {
  627. throw '提交数据错误';
  628. }
  629. responseData.data = await ctx.service.category.addCategory(projectId, data.name, settingConst.cType.key.dropDown);
  630. ctx.body = responseData;
  631. } catch (err) {
  632. this.log(err);
  633. ctx.body = {err: 1, msg: err.toString(), data: null};
  634. }
  635. }
  636. /**
  637. * 编辑分类(Ajax)
  638. *
  639. * @param ctx
  640. * @return {Promise<void>}
  641. */
  642. async updateCategory(ctx) {
  643. try {
  644. const projectId = ctx.session.sessionProject.id;
  645. const responseData = {err: 0, msg: '', data: null};
  646. const data = JSON.parse(ctx.request.body.data);
  647. if (!data.id) {
  648. throw '提交数据错误';
  649. }
  650. if (data.name) {
  651. const count = await ctx.service.category.count({pid: projectId, name: data.name});
  652. if (count >= 1) {
  653. throw '存在同名类别';
  654. }
  655. }
  656. const result = await ctx.service.category.update(data, {id: data.id});
  657. if (!result) {
  658. throw '提交数据失败';
  659. }
  660. responseData.data = await ctx.service.category.getCategory(data.id);
  661. ctx.body = responseData;
  662. } catch (err) {
  663. this.log(err);
  664. ctx.body = {err: 1, msg: err.toString(), data: null};
  665. }
  666. }
  667. async setCategoryValue(ctx) {
  668. try {
  669. const responseData = {err: 0, msg: '', data: {}};
  670. const data = JSON.parse(ctx.request.body.data);
  671. if (!data.id) {
  672. throw '提交数据错误';
  673. }
  674. await ctx.service.categoryValue.setCategoryValue(data.id, data.updateValue);
  675. responseData.data.category = await ctx.service.category.getCategory(data.id);
  676. responseData.data.tenders = await ctx.service.tender.getList('', null, 1);
  677. ctx.body = responseData;
  678. } catch (err) {
  679. this.log(err);
  680. ctx.body = {err: 1, msg: err instanceof String ? err : '提交数据失败', data: null};
  681. }
  682. }
  683. /**
  684. * 删除分类(Ajax)
  685. *
  686. * @param ctx
  687. * @return {Promise<void>}
  688. */
  689. async deleteCategory(ctx) {
  690. try {
  691. const projectId = ctx.session.sessionProject.id;
  692. const responseData = {
  693. err: 0, msg: '', data: null,
  694. };
  695. const data = JSON.parse(ctx.request.body.data);
  696. if (!data.id) {
  697. throw '提交数据错误';
  698. }
  699. await ctx.service.category.deleteCategory(projectId, data.id);
  700. ctx.body = responseData;
  701. } catch (err) {
  702. this.log(err);
  703. ctx.body = {err: 1, msg: err.toString(), data: null};
  704. }
  705. }
  706. /**
  707. * 调整分类层次排序(Ajax)
  708. *
  709. * @param ctx
  710. * @return {Promise<void>}
  711. */
  712. async resetCategoryLevel(ctx) {
  713. try {
  714. const projectId = ctx.session.sessionProject.id;
  715. const responseData = {
  716. err: 0, msg: '', data: null,
  717. };
  718. const data = JSON.parse(ctx.request.body.data);
  719. await ctx.service.category.resetCategoryLevel(data);
  720. responseData.data = await ctx.service.category.getAllCategory(projectId);
  721. ctx.body = responseData;
  722. } catch (err) {
  723. this.log(err);
  724. ctx.body = {err: 1, msg: err.toString(), data: null};
  725. }
  726. }
  727. async selfCategoryLevel(ctx) {
  728. try {
  729. const data = JSON.parse(ctx.request.body.data);
  730. await ctx.service.projectAccount.defaultUpdate({
  731. id: ctx.session.sessionUser.accountId,
  732. self_category_level: data.self_category_level || ''
  733. });
  734. ctx.body = {
  735. err: 0, msg: '', data: null,
  736. };
  737. } catch (err) {
  738. ctx.log(err);
  739. ctx.ajaxErrorBody(err, '保存自定义分类失败');
  740. }
  741. }
  742. /** update porject info
  743. * @author wangfeng
  744. * @date 2018-10-12 15:48:05
  745. * @param ctx
  746. * @return {Promise<void>}
  747. */
  748. async updateinfo(ctx) {
  749. try {
  750. const projectId = ctx.params.id;
  751. const responseData = {
  752. err: 0, msg: '', data: null,
  753. };
  754. const conditionData = {
  755. id: projectId,
  756. };
  757. const data = ctx.request.body;
  758. const result = await ctx.service.project.update(data, conditionData);
  759. if (!result) {
  760. throw '提交数据失败';
  761. }
  762. ctx.redirect('/setting/info');
  763. } catch (err) {
  764. this.log(err);
  765. ctx.body = {err: 1, msg: err.toString(), data: null};
  766. }
  767. }
  768. async updateProjectSet(ctx) {
  769. try {
  770. const projectId = ctx.session.sessionProject.id;
  771. const data = JSON.parse(ctx.request.body.data);
  772. const allowField = ['notice_setting']; // 暂时只一个
  773. if (!ctx.helper._.includes(allowField, data.field)) {
  774. throw '非配置的字段无法使用本方法';
  775. }
  776. const result = await ctx.service.project.updateProjectSet(projectId, data.field, data.pData);
  777. if (!result) {
  778. throw '提交数据失败';
  779. }
  780. ctx.body = { err: 0, msg: '', data: result };
  781. } catch (err) {
  782. this.log(err);
  783. ctx.body = { err: 1, msg: err.toString(), data: null };
  784. }
  785. }
  786. /**
  787. * 检测账户是否存在
  788. *
  789. * @param {Object} ctx -egg全局变量
  790. * @return {void}
  791. */
  792. async accountExist(ctx) {
  793. const projectData = ctx.session.sessionProject;
  794. const responseData = {
  795. err: 0, msg: '', data: null,
  796. };
  797. try {
  798. const data = JSON.parse(ctx.request.body.data);
  799. const account = data.account;
  800. if (projectData.id === undefined) {
  801. throw '不存在对应项目';
  802. }
  803. responseData.data = await ctx.service.projectAccount.isAccountExist(account, projectData.id);
  804. ctx.body = responseData;
  805. } catch (error) {
  806. ctx.body = {err: 1, msg: error.toString(), data: null};
  807. }
  808. }
  809. /**
  810. * 显示设置(Get)
  811. * @param {Object} ctx -egg全局变量
  812. * @return {void}
  813. */
  814. async show(ctx) {
  815. try {
  816. // 获取项目数据
  817. const projectId = ctx.session.sessionProject.id;
  818. await this._checkMenu(projectId);
  819. const projectData = await ctx.service.project.getDataById(projectId);
  820. if (!projectData) {
  821. throw '没有对应的项目数据';
  822. }
  823. if (ctx.session.sessionUser.is_admin === 0) {
  824. throw '没有访问权限';
  825. }
  826. const showList = await ctx.service.settingShow.getList(projectData.page_path);
  827. const sjsRela = await ctx.service.project.getSjsRela(projectId);
  828. const projectSpread = await ctx.service.projectSpread.getProjectSpreadType(projectId);
  829. const renderData = {projectData, showList, sjsRela, settingConst, projectSpread};
  830. await this.layout('setting/show.ejs', renderData);
  831. } catch (error) {
  832. this.log(error);
  833. ctx.redirect('/dashboard');
  834. }
  835. }
  836. /**
  837. * 更新显示设置列表
  838. * @param {Object} ctx -egg全局变量
  839. * @return {void}
  840. */
  841. async showListUpdate(ctx) {
  842. try {
  843. // 获取项目id
  844. const projectId = ctx.session.sessionProject.id;
  845. const {data} = ctx.request.body;
  846. const {id} = JSON.parse(data);
  847. const result = await ctx.service.settingShow.setDefaultLabel(id, projectId);
  848. const responseData = {err: 0, msg: '', data: result};
  849. ctx.body = responseData;
  850. } catch (error) {
  851. this.log(error);
  852. ctx.body = {err: 1, msg: error.toString(), data: null};
  853. }
  854. }
  855. async showSjsUpdate(ctx) {
  856. try {
  857. const projectId = ctx.session.sessionProject.id;
  858. const data = JSON.parse(ctx.request.body.data);
  859. const result = await ctx.service.project.updateSjsRela(projectId, data.sub, data.field, data.key, data.value);
  860. ctx.body = {err: 0, msg: '', data: result};
  861. } catch (err) {
  862. this.log(err);
  863. this.ajaxErrorBody(err, '保存数据失败');
  864. }
  865. }
  866. async logs(ctx) {
  867. try {
  868. // 获取项目数据
  869. const projectId = ctx.session.sessionProject.id;
  870. await this._checkMenu(projectId);
  871. const projectData = await ctx.service.project.getDataById(projectId);
  872. if (projectData === null) {
  873. throw '没有对应的项目数据';
  874. }
  875. if (ctx.session.sessionUser.is_admin === 0) {
  876. throw '没有访问权限';
  877. }
  878. const settingType = ctx.params.type ? parseInt(ctx.params.type) : 0;
  879. const logs = await ctx.service.projectLog.getLogs(projectId, settingType);
  880. const renderData = {
  881. projectData,
  882. officeList,
  883. projectLog,
  884. settingType,
  885. logs,
  886. };
  887. await this.layout('setting/logs.ejs', renderData);
  888. } catch (error) {
  889. console.log(error);
  890. ctx.redirect('/dashboard');
  891. }
  892. }
  893. async fun(ctx) {
  894. try {
  895. const projectId = ctx.session.sessionProject.id;
  896. await this._checkMenu(projectId);
  897. const projectData = await ctx.service.project.getDataById(projectId);
  898. const funRela = await ctx.service.project.getFunRela(projectId);
  899. if (projectData === null) {
  900. throw '没有对应的项目数据';
  901. }
  902. if (ctx.session.sessionUser.is_admin === 0) {
  903. throw '没有访问权限';
  904. }
  905. const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
  906. console.log(fun_set);
  907. await this.layout('setting/fun.ejs', {
  908. projectData,
  909. funRela,
  910. imType,
  911. endMonth: funSet.endMonth,
  912. funSet: fun_set,
  913. }, 'setting/fun_modal.ejs');
  914. } catch (error) {
  915. ctx.helper.log(error);
  916. ctx.redirect('/dashboard');
  917. }
  918. }
  919. /**
  920. * 保存功能设置相关
  921. * @param ctx
  922. * @returns {Promise<void>}
  923. */
  924. async updateFun(ctx) {
  925. try {
  926. const projectId = ctx.session.sessionProject.id;
  927. const projectData = await ctx.service.project.getDataById(projectId);
  928. if (projectData === null) {
  929. throw '没有对应的项目数据';
  930. }
  931. if (ctx.session.sessionUser.is_admin === 0) {
  932. throw '没有访问权限';
  933. }
  934. const data = JSON.parse(ctx.request.body.data);
  935. if (data) ctx.request.body = data;
  936. const rule = ctx.service.project.rule('fun');
  937. ctx.validate(rule);
  938. const result = await ctx.service.project.updateFunRela(projectId, ctx.request.body);
  939. if (!result) throw '保存数据失败';
  940. this.ctx.session.sessionProject.page_show.openChangeProject = data.openChangeProject ? 1 : 0;
  941. this.ctx.session.sessionProject.page_show.openChangeApply = data.openChangeApply ? 1 : 0;
  942. this.ctx.session.sessionProject.page_show.openChangePlan = data.openChangePlan ? 1 : 0;
  943. this.ctx.session.sessionProject.page_show.openChangeWhiteList = data.openChangeWhiteList ? 1 : 0;
  944. this.ctx.session.sessionProject.page_show.openChangeState = data.openChangeState ? 1 : 0;
  945. this.ctx.session.sessionProject.page_show.openMaterialTax = data.openMaterialTax ? 1 : 0;
  946. this.ctx.session.sessionProject.page_show.openMaterialChecklist = data.openMaterialChecklist ? 1 : 0;
  947. this.ctx.session.sessionProject.page_show.openMaterialSelf = data.openMaterialSelf ? 1 : 0;
  948. this.ctx.session.sessionProject.page_show.openMaterialEditForAudit = data.openMaterialEditForAudit ? 1 : 0;
  949. this.ctx.session.sessionProject.page_show.openStageStart = data.openStageStart ? 1 : 0;
  950. const result2 = await ctx.service.project.updatePageshow(projectId);
  951. if (!result2) throw '保存数据失败';
  952. if (data.addFunSet) {
  953. const funSet = projectData.fun_set ? JSON.parse(projectData.fun_set) : {};
  954. ctx.helper._.defaultsDeep(data.addFunSet, funSet);
  955. const result3 = await ctx.service.project.updateFunSet(projectId, data.addFunSet);
  956. if (!result3) throw '保存数据失败';
  957. }
  958. ctx.body = {err: 0, msg: '', data: null};
  959. } catch (error) {
  960. ctx.helper.log(error);
  961. this.ajaxErrorBody(error, '保存数据失败');
  962. }
  963. }
  964. async s2b(ctx) {
  965. try {
  966. const projectId = ctx.session.sessionProject.id;
  967. await this._checkMenu(projectId);
  968. const projectData = await ctx.service.project.getDataById(projectId);
  969. if (projectData === null) throw '没有对应的项目数据';
  970. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  971. const tenders = await ctx.service.tender.getAllDataByCondition({where: {project_id: projectId}});
  972. for (const t of tenders) {
  973. t.measure_type_str = t.measure_type === measureType.tz.value ? measureType.tz.title : measureType.gcl.title;
  974. const stages = await ctx.service.stage.getAllDataByCondition({where: {tid: t.id}});
  975. t.stage_count_str = `第${stages.length || 0}期`;
  976. const user = await ctx.service.projectAccount.getAccountInfoById(t.user_id);
  977. t.user_str = user.name + '-' + user.company;
  978. t.show_time = stages.length > 0 ? stages[stages.length - 1].cache_time_r || stages[stages.length - 1].in_time : t.create_time;
  979. }
  980. await this.layout('setting/s2b.ejs', {
  981. projectData,
  982. tenders,
  983. });
  984. } catch (error) {
  985. ctx.helper.log(error);
  986. ctx.redirect('/dashboard');
  987. }
  988. }
  989. async s2bUpdate(ctx) {
  990. try {
  991. const projectId = ctx.session.sessionProject.id;
  992. const projectData = await ctx.service.project.getDataById(projectId);
  993. if (projectData === null) throw '没有对应的项目数据';
  994. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  995. const data = JSON.parse(ctx.request.body.data);
  996. if (!data.tid) throw '提交数据错误';
  997. const updateData = {};
  998. if (data.gxby_limit !== undefined) updateData.s2b_gxby_limit = data.gxby_limit;
  999. if (data.gxby_check !== undefined) updateData.s2b_gxby_check = data.gxby_check;
  1000. if (data.dagl_limit !== undefined) updateData.s2b_dagl_limit = data.dagl_limit;
  1001. if (data.dagl_check !== undefined) updateData.s2b_dagl_check = data.dagl_check;
  1002. await ctx.service.tender.saveApiRela(data.tid, updateData);
  1003. ctx.body = {err: 0, msg: '', data: null};
  1004. } catch (error) {
  1005. ctx.helper.log(error);
  1006. this.ajaxErrorBody(error, '保存数据失败');
  1007. }
  1008. }
  1009. async s2bUpdateStatus(ctx) {
  1010. try {
  1011. const projectId = ctx.session.sessionProject.id;
  1012. const projectData = await ctx.service.project.getDataById(projectId);
  1013. if (projectData === null) throw '没有对应的项目数据';
  1014. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  1015. const data = JSON.parse(ctx.request.body.data);
  1016. if (!data.type || data.status === undefined) throw '提交数据错误';
  1017. const responseData = {err: 0, msg: '', data: null};
  1018. switch (data.type) {
  1019. case 'gxby':
  1020. responseData.data = await this.ctx.service.s2bProj.updateGxbyStatus(projectId, data.status, data.limit, data.ratio);
  1021. break;
  1022. case 'dagl':
  1023. responseData.data = await this.ctx.service.s2bProj.updateDaglStatus(projectId, data.status, data.limit, data.ratio);
  1024. break;
  1025. default:
  1026. throw '提交数据错误';
  1027. }
  1028. ctx.body = responseData;
  1029. } catch (error) {
  1030. console.log(error);
  1031. ctx.helper.log(error);
  1032. this.ajaxErrorBody(error, '保存数据失败');
  1033. }
  1034. }
  1035. async dataCollect(ctx) {
  1036. try {
  1037. if (!ctx.session.sessionProject.page_show.openDataCollect) {
  1038. throw '该功能已关闭或无法查看';
  1039. }
  1040. const projectId = ctx.session.sessionProject.id;
  1041. await this._checkMenu(projectId);
  1042. const projectData = await ctx.service.project.getDataById(projectId);
  1043. if (projectData === null) throw '没有对应的项目数据';
  1044. projectData.data_collect_pages = projectData.data_collect_pages ? projectData.data_collect_pages.split(',') : [];
  1045. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  1046. const dataCollectAudits = await ctx.service.datacollectAudit.getList(projectId);
  1047. // 获取所有项目参与者
  1048. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  1049. where: {project_id: ctx.session.sessionProject.id, enable: 1},
  1050. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  1051. });
  1052. // const accountGroupList = accountGroup.map((item, idx) => {
  1053. // const groupList = accountList.filter(item => item.account_group === idx);
  1054. // return { groupName: item, groupList };
  1055. // });
  1056. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
  1057. const accountGroupList = unitList.map(item => {
  1058. const groupList = accountList.filter(item1 => item1.company === item.name);
  1059. return {groupName: item.name, companyId: item.id, groupList};
  1060. });
  1061. const categoryData = await ctx.service.category.getAllCategory(ctx.session.sessionProject.id);
  1062. const tenders = await ctx.service.tender.getList('', null, 1);
  1063. const dcTenders = await ctx.service.datacollectTender.getList(projectId);
  1064. await this.layout('setting/datacollect.ejs', {
  1065. projectData,
  1066. dataCollectAudits,
  1067. accountList,
  1068. accountGroup: accountGroupList,
  1069. categoryData,
  1070. tenders,
  1071. dcTenders,
  1072. is_dz1: ['P0505', 'MI22U'].indexOf(ctx.session.sessionProject.code) !== -1 ? 5 : false,
  1073. }, 'setting/datacollect_modal.ejs');
  1074. } catch (error) {
  1075. ctx.helper.log(error);
  1076. ctx.session.postError = error.toString();
  1077. ctx.redirect('/dashboard');
  1078. }
  1079. }
  1080. async dataCollectSave(ctx) {
  1081. try {
  1082. if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
  1083. const projectId = ctx.session.sessionProject.id;
  1084. const responseData = {
  1085. err: 0, msg: '', data: null,
  1086. };
  1087. const data = JSON.parse(ctx.request.body.data);
  1088. if (!data.type) {
  1089. throw '提交数据错误';
  1090. }
  1091. switch (data.type) {
  1092. case 'show':
  1093. responseData.data = await ctx.service.project.update({
  1094. data_collect: data.data_collect,
  1095. data_collect_pages: data.data_collect_pages.join(',')
  1096. }, {id: projectId});
  1097. ctx.session.sessionProject.dataCollect = data.data_collect;
  1098. ctx.session.sessionProject.showDataCollect = data.data_collect ? 1 : 0;
  1099. break;
  1100. case 'add-audit':
  1101. // 判断该用户是否已加入到表中,已加入则提示无需添加
  1102. const auditInfo = await ctx.service.datacollectAudit.getDataByCondition({
  1103. pid: projectId,
  1104. uid: data.id
  1105. });
  1106. if (auditInfo) {
  1107. throw '该用户已存在权限中,无需重复添加';
  1108. }
  1109. // const accountInfo = await ctx.service.projectAccount.getDataById(data.id);
  1110. // const companyInfo = await ctx.service.datacollectAudit.getCompanyInfo(projectId, accountInfo.company_id);
  1111. // if (companyInfo) {
  1112. // throw '该用户所在单位已存在权限中,无需单独添加';
  1113. // }
  1114. await ctx.service.datacollectAudit.saveAudit(projectId, data.id);
  1115. responseData.data = await ctx.service.datacollectAudit.getList(projectId);
  1116. break;
  1117. case 'add-company':
  1118. const companyInfo = await ctx.service.datacollectAudit.getCompanyInfo(projectId, data.id);
  1119. if (companyInfo) {
  1120. throw '该单位已存在权限中,无需重复添加';
  1121. }
  1122. await ctx.service.datacollectAudit.saveCompany(projectId, data.id);
  1123. responseData.data = await ctx.service.datacollectAudit.getList(projectId);
  1124. break;
  1125. case 'del-audit':
  1126. const auditInfo2 = await ctx.service.datacollectAudit.getDataById(data.id);
  1127. if (!auditInfo2) {
  1128. throw '该用户已不存在权限中,移除失败';
  1129. }
  1130. await ctx.service.datacollectAudit.delAudit(data.id);
  1131. responseData.data = await ctx.service.datacollectAudit.getList(projectId);
  1132. break;
  1133. case 'del-group':
  1134. const groupInfo3 = await ctx.service.datacollectAudit.getDataById(data.id);
  1135. if (!groupInfo3) {
  1136. throw '该单位已不存在权限中,移除失败';
  1137. }
  1138. await ctx.service.datacollectAudit.delAudit(data.id);
  1139. responseData.data = await ctx.service.datacollectAudit.getList(projectId);
  1140. break;
  1141. case 'del-company':
  1142. const companyInfo2 = await ctx.service.datacollectAudit.getDataById(data.id);
  1143. if (!companyInfo2) {
  1144. throw '该单位已不存在权限中,移除失败';
  1145. }
  1146. await ctx.service.datacollectAudit.delAudit(data.id);
  1147. responseData.data = await ctx.service.datacollectAudit.getList(projectId);
  1148. break;
  1149. case 'tender':
  1150. if (ctx.session.sessionProject.page_show.addDataCollect !== parseInt(data.add_datacollect)) {
  1151. ctx.session.sessionProject.page_show.addDataCollect = parseInt(data.add_datacollect);
  1152. await ctx.service.project.updatePageshow(projectId);
  1153. }
  1154. await ctx.service.datacollectTender.updateList(projectId, data.tids);
  1155. responseData.data = {
  1156. dcTenders: await ctx.service.datacollectTender.getList(projectId),
  1157. addDatacollect: ctx.session.sessionProject.page_show.addDataCollect,
  1158. };
  1159. break;
  1160. default:
  1161. throw '参数有误';
  1162. }
  1163. ctx.body = responseData;
  1164. } catch (err) {
  1165. this.log(err);
  1166. ctx.body = {err: 1, msg: err.toString(), data: null};
  1167. }
  1168. }
  1169. async manage(ctx) {
  1170. try {
  1171. const projectId = ctx.session.sessionProject.id;
  1172. await this._checkMenu(projectId);
  1173. const projectData = await ctx.service.project.getDataById(projectId);
  1174. if (projectData === null) throw '没有对应的项目数据';
  1175. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  1176. const tenderList = await ctx.service.tender.getList('', null, 1);
  1177. const removeTenders = await ctx.service.shenpiAudit.getRemoveTenders(tenderList);
  1178. if (removeTenders.length > 0) {
  1179. ctx.helper._.remove(tenderList, function(n) {
  1180. return removeTenders.indexOf(n.id) !== -1;
  1181. });
  1182. }
  1183. for (const t of tenderList) {
  1184. t.visitor = (await this.ctx.service.tenderTourist.getTourists(t.id)).map(x => { return x.user_name; });
  1185. await this.ctx.service.tenderCache.loadTenderCache(t, this.ctx.session.sessionUser.accountId);
  1186. }
  1187. const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  1188. // 获取所有项目参与者
  1189. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  1190. where: {project_id: ctx.session.sessionProject.id, enable: 1},
  1191. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  1192. });
  1193. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
  1194. const accountGroupList = unitList.map(item => {
  1195. const groupList = accountList.filter(item1 => item1.company === item.name);
  1196. return {groupName: item.name, groupList};
  1197. });
  1198. const renderData = {
  1199. projectData,
  1200. tenderList,
  1201. auditConst,
  1202. auditType: auditConst.auditType,
  1203. accountList,
  1204. accountGroup: accountGroupList,
  1205. categoryData,
  1206. settingConst,
  1207. measureType: tenderConst.measureType,
  1208. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.manage),
  1209. uid: this.ctx.session.sessionUser.accountId,
  1210. pid: this.ctx.session.sessionProject.id,
  1211. scPermission: scheduleConst.permission,
  1212. change_type_list: shenpiConst.change_type_list,
  1213. };
  1214. renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
  1215. await this.layout('setting/manage.ejs', renderData, 'setting/manage_modal.ejs');
  1216. } catch (error) {
  1217. ctx.helper.log(error);
  1218. ctx.redirect('/dashboard');
  1219. }
  1220. }
  1221. async manageTenderSave(ctx) {
  1222. try {
  1223. if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
  1224. const projectId = ctx.session.sessionProject.id;
  1225. const responseData = {
  1226. err: 0, msg: '', data: {},
  1227. };
  1228. const data = JSON.parse(ctx.request.body.data);
  1229. if (!data.type) {
  1230. throw '提交数据错误';
  1231. }
  1232. if (!data.tid) {
  1233. throw '参数有误';
  1234. }
  1235. const tender = await ctx.service.tender.getDataById(data.tid);
  1236. if (!tender) {
  1237. throw '标段不存在';
  1238. }
  1239. const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(tender.id);
  1240. switch (data.type) {
  1241. case 'msg':
  1242. const lastRevise = await ctx.service.ledgerRevise.getLastestRevise(tender.id);
  1243. const revising = (lastRevise && lastRevise.status !== auditConst.revise.status.checked) || false;
  1244. // 获取审批流,游客账号,及投资进度账号信息
  1245. responseData.data.tender = tender;
  1246. responseData.data.revising = revising;
  1247. responseData.data.shenpi = await ctx.service.shenpiAudit.getShenpi(tender.id, tenderInfo);
  1248. const tourists = await ctx.service.tenderTourist.getTourists(tender.id);
  1249. for (const t of tourists) {
  1250. t.permission = await ctx.service.tenderTourist.getTouristPermission(t);
  1251. }
  1252. responseData.data.tourists = tourists;
  1253. responseData.data.scheduleAuditList = ctx.session.sessionProject.page_show.xxjd ? await ctx.service.scheduleAudit.getAllDataByCondition({ where: { tid: tender.id } }) : [];
  1254. responseData.data.constructionAuditList = ctx.session.sessionProject.page_show.openConstruction ? await ctx.service.constructionAudit.getList(tender.id) : [];
  1255. break;
  1256. case 'copy2otu':
  1257. if (data.userType === 'tourist') {
  1258. await ctx.service.tenderTourist.setOtherTender(data.tidList, data.auditList);
  1259. } else if (data.userType === 'schedule') {
  1260. await ctx.service.scheduleAudit.setOtherTender(data.tidList, data.auditList);
  1261. } else if (data.userType === 'construction') {
  1262. await ctx.service.constructionAudit.setOtherTender(data.tidList, data.auditList);
  1263. } else {
  1264. throw '参数有误';
  1265. }
  1266. break;
  1267. default:
  1268. throw '参数有误';
  1269. }
  1270. ctx.body = responseData;
  1271. } catch (err) {
  1272. this.log(err);
  1273. ctx.body = { err: 1, msg: err.toString(), data: null };
  1274. }
  1275. }
  1276. async spread(ctx) {
  1277. try {
  1278. // 获取项目数据
  1279. const projectId = ctx.session.sessionProject.id;
  1280. await this._checkMenu(projectId);
  1281. const projectData = await ctx.service.project.getDataById(projectId);
  1282. if (!projectData) throw '没有对应的项目数据';
  1283. const sType = ctx.query.stype;
  1284. const code = ctx.query.code;
  1285. const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectData.id, code);
  1286. const renderData = {
  1287. BaseSetCol: SpreadConst.BaseSetCol[sType],
  1288. sType,
  1289. code,
  1290. colSet: projectSpread[sType],
  1291. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.spread),
  1292. };
  1293. await this.layout('setting/spread.ejs', renderData, 'setting/spread_modal.ejs');
  1294. } catch (error) {
  1295. this.log(error);
  1296. ctx.redirect('/dashboard');
  1297. }
  1298. }
  1299. async saveSpread(ctx) {
  1300. try {
  1301. const projectId = ctx.session.sessionProject.id;
  1302. const data = JSON.parse(ctx.request.body.data);
  1303. await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, data.colSet);
  1304. const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
  1305. ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
  1306. } catch (error) {
  1307. ctx.log(error);
  1308. ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
  1309. }
  1310. }
  1311. async previewSpread(ctx) {
  1312. try {
  1313. const data = JSON.parse(ctx.request.body.data);
  1314. const [billsSpread, posSpread] = this.ctx.service.projectSpread.generateRelaSpread(data.sType, data.colSet);
  1315. ctx.body = { err: 0, msg: '', data: { billsSpread, posSpread } };
  1316. } catch (error) {
  1317. ctx.log(error);
  1318. ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
  1319. }
  1320. }
  1321. async resetSpread(ctx) {
  1322. try {
  1323. const projectId = ctx.session.sessionProject.id;
  1324. const data = JSON.parse(ctx.request.body.data);
  1325. const spreadTemplate = SpreadConst.ProjectSpreadTemplate.find(x => { return x.code === data.code; });
  1326. const colSet = spreadTemplate.template[data.sType];
  1327. await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, colSet);
  1328. const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
  1329. ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
  1330. } catch (error) {
  1331. ctx.log(error);
  1332. ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
  1333. }
  1334. }
  1335. }
  1336. return SettingController;
  1337. };