setting_controller.js 62 KB

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