setting_controller.js 63 KB

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