sub_project.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const rootId = '-1';
  10. const imType = require('../const/tender').imType;
  11. const defaultFunRela = {
  12. banOver: true,
  13. hintOver: true,
  14. banMinusChangeBills: true,
  15. minusNoValue: true,
  16. lockPayExpr: false,
  17. showMinusCol: true,
  18. imType: imType.zl.value,
  19. needGcl: false,
  20. };
  21. const funSet = require('../const/fun_set');
  22. const defaultFunSet = funSet.defaultInfo;
  23. const pageShowConst = require('../const/page_show').defaultSetting;
  24. module.exports = app => {
  25. class SubProject extends app.BaseService {
  26. /**
  27. * 构造函数
  28. *
  29. * @param {Object} ctx - egg全局变量
  30. * @param {String} tableName - 表名
  31. * @return {void}
  32. */
  33. constructor(ctx) {
  34. super(ctx);
  35. this.tableName = 'sub_project';
  36. }
  37. /**
  38. * 数据规则
  39. *
  40. * @param {String} scene - 场景
  41. * @return {Object} - 返回数据规则
  42. */
  43. rule(scene) {
  44. let rule = {};
  45. switch (scene) {
  46. case 'fun':
  47. rule = {
  48. imType: {type: 'enum', values: [imType.tz.value, imType.zl.value, imType.bb.value, imType.bw.value], required: true},
  49. banOver: {type: 'bool', required: true,},
  50. hintOver: {type: 'bool', required: true,},
  51. banMinusChangeBills: {type: 'bool', required: true,},
  52. minusNoValue: {type: 'bool', required: true,},
  53. lockPayExpr: {type: 'bool', required: true,},
  54. showMinusCol: {type: 'bool', required: true,},
  55. };
  56. break;
  57. default:
  58. break;
  59. }
  60. return rule;
  61. }
  62. async getSubProject(pid, uid, admin, filterFolder = false) {
  63. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  64. const permission = await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
  65. result = result.filter(x => {
  66. if (x.is_folder) return !filterFolder;
  67. if (admin) return true;
  68. const pb = permission.find(y => { return x.id === y.spid});
  69. if (!pb) return false;
  70. x.user_permission = pb;
  71. // 只要项目下添加了账号,就允许看到项目
  72. return true;
  73. // return x.user_permission.budget_permission.length > 0 || x.user_permission.file_permission.length > 0 || x.user_permission.manage_permission.length > 0;
  74. });
  75. return result;
  76. }
  77. _filterEmptyFolder(data) {
  78. data.sort((a, b) => { return b.tree_level - a.tree_level});
  79. const result = [];
  80. for (const d of data) {
  81. if (!d.is_folder) result.push(d);
  82. if (result.find(x => { return x.tree_pid === d.id; })) result.push(d);
  83. }
  84. return result;
  85. }
  86. async getBudgetProject(pid, uid, admin) {
  87. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  88. const adminPermission = this.ctx.service.subProjPermission.adminPermission;
  89. const permission = admin ? [] : await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
  90. result = result.filter(x => {
  91. if (!x.is_folder && !x.budget_id) return false;
  92. if (x.is_folder) return true;
  93. if (admin) {
  94. x.permission = adminPermission.budget_permission;
  95. x.manage_permission = adminPermission.manage_permission;
  96. return true;
  97. } else {
  98. const pb = permission.find(y => { return x.id === y.spid});
  99. if (!pb) return false;
  100. x.permission = pb.budget_permission;
  101. x.manage_permission = pb.manage_permission;
  102. return x.permission.length > 0;
  103. }
  104. });
  105. return this._filterEmptyFolder(result);
  106. }
  107. async getFileProject(pid, uid, admin) {
  108. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  109. const adminPermission = this.ctx.service.subProjPermission.adminPermission;
  110. const permission = await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
  111. result = result.filter(x => {
  112. if (!x.is_folder && !x.management) return false;
  113. if (x.is_folder) return true;
  114. if (admin) {
  115. x.permission = adminPermission.file_permission;
  116. x.manage_permission = adminPermission.manage_permission;
  117. return true;
  118. } else {
  119. const pb = permission.find(y => { return x.id === y.spid});
  120. if (!pb) return false;
  121. x.permission = pb.file_permission;
  122. x.manage_permission = pb.manage_permission;
  123. return x.permission.length > 0;
  124. }
  125. });
  126. return this._filterEmptyFolder(result);
  127. }
  128. async getLastChild(tree_pid) {
  129. const result = await this.getAllDataByCondition({ where: { tree_pid, project_id: this.ctx.session.sessionProject.id }, orders: [['tree_order', 'desc']], limit: 1, offset: 0 });
  130. return result[0];
  131. }
  132. async getPosterityData(id){
  133. const result = [];
  134. let cur = await this.getAllDataByCondition({ where: { tree_pid: id, project_id: this.ctx.session.sessionProject.id } });
  135. let iLevel = 1;
  136. while (cur.length > 0 && iLevel < 6) {
  137. result.push(...cur);
  138. cur = await this.getAllDataByCondition({ where: { tree_pid: cur.map(x => { return x.id })} });
  139. iLevel += 1;
  140. }
  141. return result;
  142. }
  143. async getStepNode(node, step) {
  144. const tree_order = [];
  145. while(step) {
  146. tree_order.push(node.tree_order + step);
  147. if (step > 0) {
  148. step = step - 1;
  149. } else {
  150. step = step + 1;
  151. }
  152. }
  153. return await this.getAllDataByCondition({ where: { tree_pid: node.tree_pid, tree_order, project_id: this.ctx.session.sessionProject.id }, orders: [['tree_order', 'asc']]});
  154. }
  155. async addFolder(data) {
  156. const parent = await this.getDataById(data.tree_pid);
  157. if (parent && !parent.is_folder) throw '添加数据结构错误';
  158. const lastChild = await this.getLastChild(parent ? parent.id : rootId);
  159. const conn = await this.db.beginTransaction();
  160. try {
  161. // 获取当前用户信息
  162. const sessionUser = this.ctx.session.sessionUser;
  163. // 获取当前项目信息
  164. const sessionProject = this.ctx.session.sessionProject;
  165. const insertData = {
  166. id: this.uuid.v4(), project_id: sessionProject.id, user_id: sessionUser.accountId,
  167. tree_pid: data.tree_pid,
  168. tree_level: parent ? parent.tree_level + 1 : 1,
  169. tree_order: lastChild ? lastChild.tree_order + 1 : 1,
  170. name: data.name, is_folder: 1,
  171. };
  172. const operate = await conn.insert(this.tableName, insertData);
  173. if (operate.affectedRows === 0) throw '新增文件夹失败';
  174. await conn.commit();
  175. return await this.getSubProject(sessionProject.id, sessionUser.accountId, sessionUser.is_admin);
  176. } catch (error) {
  177. await conn.rollback();
  178. throw error;
  179. }
  180. }
  181. async addSubProject(data) {
  182. const parent = await this.getDataById(data.tree_pid);
  183. if (parent && !parent.is_folder) throw '添加数据结构错误';
  184. const lastChild = await this.getLastChild(parent ? parent.id : rootId);
  185. const conn = await this.db.beginTransaction();
  186. try {
  187. // 获取当前用户信息
  188. const sessionUser = this.ctx.session.sessionUser;
  189. // 获取当前项目信息
  190. const sessionProject = this.ctx.session.sessionProject;
  191. const insertData = {
  192. id: this.uuid.v4(), project_id: sessionProject.id, user_id: sessionUser.accountId,
  193. tree_pid: data.tree_pid,
  194. tree_level: parent ? parent.tree_level + 1 : 1,
  195. tree_order: lastChild ? lastChild.tree_order + 1 : 1,
  196. name: data.name, is_folder: 0,
  197. };
  198. const operate = await conn.insert(this.tableName, insertData);
  199. // todo 根据节点新增时的其他操作
  200. if (operate.affectedRows === 0) throw '新增文件夹失败';
  201. await conn.commit();
  202. return await this.getSubProject(sessionProject.id, sessionUser.accountId, sessionUser.is_admin);
  203. } catch (error) {
  204. await conn.rollback();
  205. throw error;
  206. }
  207. }
  208. async dragTo(data) {
  209. const dragNode = await this.getDataById(data.drag_id);
  210. const dropNode = await this.getDataById(data.drop_id);
  211. if (!dragNode || !dropNode || !dropNode.is_folder) throw '拖拽数据结构错误';
  212. const lastChild = await this.getLastChild(dropNode.id);
  213. const posterity = await this.getPosterityData(dragNode.id);
  214. const conn = await this.db.beginTransaction();
  215. try {
  216. const updateData = {
  217. id: dragNode.id, tree_pid: dropNode.id, tree_level: dropNode.tree_level + 1,
  218. tree_order: lastChild ? lastChild.tree_order + 1 : 1,
  219. };
  220. await conn.update(this.tableName, updateData);
  221. if (dragNode.tree_level !== dropNode.tree_level + 1 && posterity.length > 0) {
  222. const posterityUpdateData = posterity.map(x => {
  223. return { id: x.id, tree_level: dropNode.tree_level + 1 - dragNode.tree_level + x.tree_level }
  224. });
  225. await conn.updateRows(this.tableName, posterityUpdateData);
  226. }
  227. // 升级原来的后项的order
  228. await conn.query(`UPDATE ${this.tableName} SET tree_order = tree_order-1 WHERE tree_pid = ? AND tree_order > ?`, [dragNode.tree_pid, dragNode.tree_order]);
  229. await conn.commit();
  230. } catch (error) {
  231. await conn.rollback();
  232. throw error;
  233. }
  234. return await this.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin);
  235. }
  236. async _siblingMove(node, step) {
  237. const stepNode = await this.getStepNode(node, step);
  238. const conn = await this.db.beginTransaction();
  239. try {
  240. const updateData = [];
  241. updateData.push({ id: node.id, tree_order: node.tree_order + step });
  242. for (const sn of stepNode) {
  243. updateData.push({ id: node.id, tree_order: step > 0 ? sn.tree_order - 1 : sn.tree_order + 1 });
  244. }
  245. await conn.updateRows(this.tableName, updateData);
  246. await conn.commit();
  247. } catch (error) {
  248. await conn.rollback();
  249. throw error;
  250. }
  251. }
  252. async _siblingMoveForce(node, step) {
  253. const sibling = await this.getAllDataByCondition({ where: { tree_pid: node.tree_pid, project_id: this.ctx.session.sessionProject.id }, orders: [['tree_order', 'asc']] });
  254. const nodeIndex = sibling.findIndex(x => { return x.id === node.id });
  255. if (nodeIndex + step < 0) throw '移动数据结构错误';
  256. if (nodeIndex + step > sibling.length - 1) throw '移动数据结构错误';
  257. const conn = await this.db.beginTransaction();
  258. try {
  259. const updateData = [];
  260. updateData.push({ id: node.id, tree_order: sibling[nodeIndex + step].tree_order });
  261. while(step) {
  262. const stepNode = sibling[nodeIndex + step];
  263. if (step > 0) {
  264. updateData.push({ id: stepNode.id, tree_order: sibling[nodeIndex + step - 1].tree_order });
  265. step = step - 1;
  266. } else {
  267. updateData.push({ id: stepNode.id, tree_order: sibling[nodeIndex + step + 1].tree_order});
  268. step = step + 1;
  269. }
  270. }
  271. await conn.updateRows(this.tableName, updateData);
  272. await conn.commit();
  273. } catch (error) {
  274. await conn.rollback();
  275. throw error;
  276. }
  277. }
  278. async _topMove(node) {
  279. const lastChild = await this.getLastChild(rootId);
  280. const posterity = await this.getPosterityData(node.id);
  281. const conn = await this.db.beginTransaction();
  282. try {
  283. const updateData = { id: node.id, tree_pid: rootId, tree_level: 1, tree_order: lastChild ? lastChild.tree_order + 1 : 1 };
  284. await conn.update(this.tableName, updateData);
  285. if (node.tree_level !== 1 && posterity.length > 0) {
  286. const posterityUpdateData = posterity.map(x => {
  287. return { id: x.id, tree_level: x.tree_level - node.tree_level + 1 }
  288. });
  289. await conn.updateRows(this.tableName, posterityUpdateData);
  290. }
  291. // 升级原来的后项的order
  292. await conn.query(`UPDATE ${this.tableName} SET tree_order = tree_order-1 WHERE tree_pid = ? AND tree_order > ?`, [node.tree_pid, node.tree_order]);
  293. await conn.commit();
  294. } catch (error) {
  295. await conn.rollback();
  296. throw error;
  297. }
  298. }
  299. async move(data) {
  300. const node = await this.getDataById(data.id);
  301. if (!node) throw '移动数据结构错误';
  302. switch(data.type) {
  303. case 'up': await this._siblingMoveForce(node, -1); break;
  304. case 'down': await this._siblingMoveForce(node, 1); break;
  305. case 'top': await this._topMove(node); break;
  306. default: throw '未知移动类型';
  307. }
  308. return await this.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin);
  309. }
  310. async del(id) {
  311. const node = await this.getDataById(id);
  312. if (!node) throw '删除的数据不存在';
  313. const posterity = await this.getPosterityData(node.id);
  314. const updateData = [
  315. { id: node.id, is_delete: 1 },
  316. ];
  317. posterity.forEach(x => {
  318. updateData.push({ id: x.id, is_delete: 1});
  319. });
  320. await this.db.updateRows(this.tableName, updateData);
  321. return await this.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin);
  322. }
  323. async save(data) {
  324. const result = await this.db.update(this.tableName, data);
  325. if (result.affectedRows > 0) {
  326. return data;
  327. } else {
  328. throw '更新数据失败';
  329. }
  330. }
  331. async setBudgetStd(data) {
  332. const subProject = await this.getDataById(data.id);
  333. const budgetStd = await this.ctx.service.budgetStd.getDataById(data.std_id);
  334. if (!budgetStd) throw '选择的概算标准不存在,请刷新页面重试';
  335. const conn = await this.db.beginTransaction();
  336. try {
  337. const budget_id = await this.ctx.service.budget.add(conn, {
  338. pid: subProject.project_id, user_id: subProject.user_id, rela_tender: subProject.rela_tender
  339. }, budgetStd);
  340. const updateData = { id: data.id, std_id: budgetStd.id, std_name: budgetStd.name, budget_id };
  341. await conn.update(this.tableName, updateData);
  342. await conn.commit();
  343. return updateData;
  344. } catch (error) {
  345. await conn.rollback();
  346. throw error;
  347. }
  348. }
  349. async setRelaTender(data) {
  350. const subProject = await this.getDataById(data.id);
  351. const orgRelaTenderId = subProject.rela_tender.split(',');
  352. const conn = await this.db.beginTransaction();
  353. try {
  354. await conn.update(this.tableName, data);
  355. await conn.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender: data.rela_tender });
  356. const relaTenderId = data.rela_tender.split(',');
  357. const removeTenderId = orgRelaTenderId.filter(x => { return relaTenderId.indexOf(x) < 0});
  358. const addTenderId = relaTenderId.filter(x => { return orgRelaTenderId.indexOf(x) < 0});
  359. if (removeTenderId.length > 0) await conn.update(this.ctx.service.tender.tableName, { spid: '' }, { where: { id: removeTenderId }});
  360. if (addTenderId.length > 0) await conn.update(this.ctx.service.tender.tableName, { spid: data.id }, { where: { id: addTenderId }});
  361. await conn.commit();
  362. return data;
  363. } catch (error) {
  364. await conn.rollback();
  365. throw error;
  366. }
  367. }
  368. async addRelaTender(transaction, spid, tid) {
  369. if (!transaction) throw '未定义事务';
  370. const subProject = await this.getDataById(spid);
  371. if (!subProject) throw '所属项目不存在';
  372. const rela = subProject.rela_tender.split(',');
  373. if (rela.indexOf(tid + '') >= 0) return;
  374. rela.push(tid + '');
  375. const rela_tender = rela.join(',');
  376. await transaction.update(this.tableName, { id: spid, rela_tender});
  377. await transaction.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender});
  378. }
  379. async removeRelaTender(transaction, spid, tid) {
  380. if (!transaction) throw '未定义事务';
  381. const subProject = await this.getDataById(spid);
  382. if (!subProject) throw '所属项目不存在';
  383. const rela = subProject.rela_tender.split(',');
  384. if (rela.indexOf(tid + '') < 0) return;
  385. const rela_tender = rela.filter(x => { return x === tid + ''}).join(',');
  386. await transaction.update(this.tableName, { id: spid, rela_tender});
  387. await transaction.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender});
  388. }
  389. async setManagement(data) {
  390. const subProject = await this.getDataById(data.id);
  391. if (subProject.management === data.management) return data;
  392. const users = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { project_id: subProject.project_id, company: data.management }});
  393. const orgMember = await this.ctx.service.subProjPermission.getAllDataByCondition({ where: { spid: subProject.id } });
  394. const dm = [], um = [], im = [];
  395. const template = await this.ctx.service.filingTemplateList.getDataById(data.filingTemplate);
  396. if (!template) throw '选择的文件类别不存在';
  397. const templateFiling = await this.ctx.service.filingTemplate.getAllDataByCondition({
  398. where: { temp_id: template.id, is_fixed: 1 },
  399. });
  400. const filing_type = this.ctx.service.filing.analysisFilingType(templateFiling).map(x => { return x.value; }).join(','), file_permission = '1,2';
  401. for (const u of users) {
  402. const nm = orgMember.find(x => { return u.id === x.uid; });
  403. if (nm) {
  404. if (!nm.file_permission) um.push({ id: nm.id, file_permission, filing_type });
  405. } else {
  406. im.push({ id: this.uuid.v4(), spid: subProject.id, pid: subProject.project_id, uid: u.id, file_permission, filing_type });
  407. }
  408. }
  409. const conn = await this.db.beginTransaction();
  410. try {
  411. await conn.update(this.tableName, { id: subProject.id, management: data.management, filing_template_id: template.id, filing_template_name: template.name });
  412. await this.ctx.service.filing.initFiling(subProject.id, data.filingTemplate, conn);
  413. if (dm.length > 0) await conn.delete(this.ctx.service.subProjPermission.tableName, { id: dm });
  414. if (um.length > 0) await conn.updateRows(this.ctx.service.subProjPermission.tableName, um);
  415. if (im.length > 0) await conn.insert(this.ctx.service.subProjPermission.tableName, im);
  416. await conn.commit();
  417. return data;
  418. } catch (error) {
  419. await conn.rollback();
  420. throw error;
  421. }
  422. }
  423. async refreshManagementPermission(data) {
  424. const subProject = await this.getDataById(data.id);
  425. const users = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { project_id: subProject.project_id, company: subProject.management }});
  426. const orgMember = await this.ctx.service.subProjPermission.getAllDataByCondition({ where: { spid: subProject.id } });
  427. const dm = [], um = [], im = [];
  428. const filing_type = this.ctx.service.filing.allFilingType.join(','), file_permission = '1,2';
  429. for (const u of users) {
  430. const nm = orgMember.find(x => { return u.id === x.uid; });
  431. if (nm) {
  432. if (!nm.file_permission) um.push({ id: nm.id, file_permission, filing_type });
  433. } else {
  434. im.push({ id: this.uuid.v4(), spid: subProject.id, pid: subProject.project_id, uid: u.id, file_permission, filing_type });
  435. }
  436. }
  437. const conn = await this.db.beginTransaction();
  438. try {
  439. if (dm.length > 0) await conn.delete(this.ctx.service.subProjPermission.tableName, { id: dm });
  440. if (um.length > 0) await conn.updateRows(this.ctx.service.subProjPermission.tableName, um);
  441. if (im.length > 0) await conn.insert(this.ctx.service.subProjPermission.tableName, im);
  442. await conn.commit();
  443. return { dm: dm.length, um: um.length, im: im.length };
  444. } catch (error) {
  445. await conn.rollback();
  446. throw error;
  447. }
  448. }
  449. // 合同管理获取项目列表
  450. async getSubProjectByContract(pid, uid, admin, filterFolder = false) {
  451. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  452. if (admin) return this._filterEmptyFolder(result);
  453. const permission = await this.ctx.service.contractAudit.getAllDataByCondition({ where: { uid } });
  454. result = result.filter(x => {
  455. if (x.is_folder) return !filterFolder;
  456. const pb = permission.find(y => { return x.id === y.spid; });
  457. if (!pb) return false;
  458. return true;
  459. });
  460. return this._filterEmptyFolder(result);
  461. }
  462. async getSubProjectByTender(pid, tenders, filterFolder = false) {
  463. if (tenders.length === 0) return [];
  464. const spids = this._.uniq(this._.map(tenders, 'spid'));
  465. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  466. result = result.filter(x => {
  467. if (x.is_folder) return !filterFolder;
  468. if (!x.rela_tender) return false;
  469. return this._.includes(spids, x.id);
  470. });
  471. return this._filterEmptyFolder(result);
  472. }
  473. // 合同管理获取项目列表
  474. async getSubProjectByFinancial(pid, uid, admin, filterFolder = false) {
  475. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  476. if (admin) return this._filterEmptyFolder(result);
  477. const permission = await this.ctx.service.financialAudit.getAllDataByCondition({ where: { uid } });
  478. result = result.filter(x => {
  479. if (x.is_folder) return !filterFolder;
  480. const pb = permission.find(y => { return x.id === y.spid; });
  481. if (!pb) return false;
  482. return true;
  483. });
  484. return this._filterEmptyFolder(result);
  485. }
  486. async getFileReference(subProject) {
  487. return await this.db.query(`SELECT id, name FROM zh_file_reference_list`);
  488. };
  489. getPageShow(page_show) {
  490. const info = page_show ? JSON.parse(page_show) : {};
  491. for (const pi in pageShowConst) {
  492. info[pi] = info[pi] === undefined ? pageShowConst[pi] : parseInt(info[pi]);
  493. this.ctx.helper._.defaults(info[pi], pageShowConst[pi]);
  494. }
  495. return info;
  496. }
  497. async updatePageshow(id) {
  498. const result = await this.db.update(this.tableName, {
  499. id, page_show: JSON.stringify(this.ctx.subProject.page_show),
  500. });
  501. return result.affectedRows === 1;
  502. }
  503. /**
  504. * 功能设置
  505. * @param id
  506. * @returns {Promise<null>}
  507. */
  508. getFunRela(subProject) {
  509. const result = subProject.fun_rela ? JSON.parse(subProject.fun_rela) : {};
  510. this.ctx.helper._.defaults(result, defaultFunRela);
  511. return result;
  512. }
  513. async updateFunRela(id, data) {
  514. const result = await this.db.update(this.tableName, {
  515. id: id, fun_rela: JSON.stringify({
  516. banOver: data.banOver, hintOver: data.hintOver, banMinusChangeBills: data.banMinusChangeBills,
  517. imType: data.imType, needGcl: data.needGcl, minusNoValue: data.minusNoValue,
  518. lockPayExpr: data.lockPayExpr, showMinusCol: data.showMinusCol,
  519. }),
  520. });
  521. return result.affectedRows === 1;
  522. }
  523. getFunSet(fun_set = null) {
  524. const result = fun_set ? JSON.parse(fun_set) : {};
  525. this.ctx.helper._.defaults(result, defaultFunSet);
  526. return result;
  527. }
  528. async updateFunSet(id, funSet) {
  529. const result = await this.db.update(this.tableName, {
  530. id, fun_set: JSON.stringify(funSet),
  531. });
  532. return result.affectedRows === 1;
  533. }
  534. }
  535. return SubProject;
  536. };