setting_controller.js 55 KB

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