setting_controller.js 62 KB

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