contract_controller.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. 'use strict';
  2. const auditConst = require('../const/audit');
  3. const contractConst = require('../const/contract');
  4. const moment = require('moment');
  5. const sendToWormhole = require('stream-wormhole');
  6. const fs = require('fs');
  7. const path = require('path');
  8. module.exports = app => {
  9. class ContractController extends app.BaseController {
  10. /**
  11. * 构造函数
  12. *
  13. * @param {Object} ctx - egg全局变量
  14. * @return {void}
  15. */
  16. constructor(ctx) {
  17. super(ctx);
  18. ctx.showProject = true;
  19. // ctx.showTitle = true;
  20. }
  21. /**
  22. * 项目合同列表页
  23. *
  24. * @param {Object} ctx - egg全局页面
  25. * @return {void}
  26. */
  27. async index(ctx) {
  28. try {
  29. if (!ctx.session.sessionProject.page_show.openContract) {
  30. throw '该功能已关闭或无法查看';
  31. }
  32. const renderData = {
  33. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.contract.index),
  34. auditConst,
  35. };
  36. // renderData.budgetStd = await ctx.service.budgetStd.getDataByProjectId(ctx.session.sessionProject.id);
  37. renderData.projectList = await ctx.service.subProject.getSubProjectByContract(ctx.session.sessionProject.id, ctx.session.sessionUser.accountId, ctx.session.sessionUser.is_admin);
  38. for (const t of renderData.projectList) {
  39. if (!t.is_folder) {
  40. const expensessList = await ctx.service.contract.getListByUsers({ spid: t.id, contract_type: contractConst.type.expenses }, ctx.session.sessionUser);
  41. t.expenses_count = expensessList.length;
  42. t.expenses_total_price = expensessList.reduce((total, item) => ctx.helper.add(total, item.total_price), 0);
  43. t.expenses_yf_price = expensessList.reduce((total, item) => ctx.helper.add(total, item.yf_price), 0);
  44. const incomeList = await ctx.service.contract.getListByUsers({ spid: t.id, contract_type: contractConst.type.income }, ctx.session.sessionUser);
  45. t.income_count = incomeList.length;
  46. t.income_total_price = incomeList.reduce((total, item) => ctx.helper.add(total, item.total_price), 0);
  47. t.income_yf_price = incomeList.reduce((total, item) => ctx.helper.add(total, item.yf_price), 0);
  48. }
  49. }
  50. renderData.tenderList = await ctx.service.tender.getList4Select('stage');
  51. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  52. where: { project_id: ctx.session.sessionProject.id, enable: 1 },
  53. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  54. });
  55. renderData.accountList = accountList;
  56. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
  57. renderData.accountGroup = unitList.map(item => {
  58. const groupList = accountList.filter(item1 => item1.company === item.name);
  59. return { groupName: item.name, groupList };
  60. });
  61. // renderData.permissionConst = ctx.service.subProjPermission.PermissionConst;
  62. renderData.categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
  63. renderData.companys = await this.ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
  64. // renderData.templates = await this.ctx.service.filingTemplateList.getAllTemplate(ctx.session.sessionProject.id);
  65. await this.layout('contract/index.ejs', renderData, 'contract/modal.ejs');
  66. } catch (err) {
  67. ctx.log(err);
  68. ctx.session.postError = err.toString();
  69. ctx.redirect(this.menu.menu.dashboard.url);
  70. }
  71. }
  72. /**
  73. * 标段合同列表页
  74. *
  75. * @param {Object} ctx - egg全局页面
  76. * @return {void}
  77. */
  78. async tender(ctx) {
  79. try {
  80. if (!ctx.session.sessionProject.page_show.openContract) {
  81. throw '该功能已关闭或无法查看';
  82. }
  83. // 获取用户新建标段权利
  84. const accountInfo = await this.ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
  85. const userPermission = accountInfo !== undefined && accountInfo.permission !== ''
  86. ? JSON.parse(accountInfo.permission) : null;
  87. const tenderList = await ctx.service.tender.getContractList('', userPermission, ctx.session.sessionUser.is_admin);
  88. for (const t of tenderList) {
  89. const expensessList = await ctx.service.contract.getListByUsers({ tid: t.id, contract_type: contractConst.type.expenses }, ctx.session.sessionUser);
  90. t.expenses_count = expensessList.length;
  91. t.expenses_total_price = expensessList.reduce((total, item) => ctx.helper.add(total, item.total_price), 0);
  92. t.expenses_yf_price = expensessList.reduce((total, item) => ctx.helper.add(total, item.yf_price), 0);
  93. const incomeList = await ctx.service.contract.getListByUsers({ tid: t.id, contract_type: contractConst.type.income }, ctx.session.sessionUser);
  94. t.income_count = incomeList.length;
  95. t.income_total_price = incomeList.reduce((total, item) => ctx.helper.add(total, item.total_price), 0);
  96. t.income_yf_price = incomeList.reduce((total, item) => ctx.helper.add(total, item.yf_price), 0);
  97. }
  98. const categoryData = await ctx.service.category.getAllCategory(ctx.session.sessionProject.id);
  99. const renderData = {
  100. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.contract.tender),
  101. tenderList,
  102. categoryData,
  103. // selfCategoryLevel: accountInfo ? accountInfo.self_category_level : '',
  104. selfCategoryLevel: '',
  105. pid: ctx.session.sessionProject.id,
  106. uid: ctx.session.sessionUser.accountId,
  107. };
  108. if (ctx.session.sessionUser.is_admin) {
  109. const projectId = ctx.session.sessionProject.id;
  110. // 获取所有项目参与者
  111. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  112. where: { project_id: ctx.session.sessionProject.id, enable: 1 },
  113. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  114. });
  115. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: projectId } });
  116. const accountGroupList = unitList.map(item => {
  117. const groupList = accountList.filter(item1 => item1.company === item.name);
  118. return { groupName: item.name, groupList };
  119. });
  120. renderData.accountList = accountList;
  121. renderData.accountGroup = accountGroupList;
  122. }
  123. await this.layout('contract/tender.ejs', renderData, 'contract/modal.ejs');
  124. } catch (err) {
  125. ctx.log(err);
  126. ctx.session.postError = err.toString();
  127. ctx.redirect(this.menu.menu.dashboard.url);
  128. }
  129. }
  130. async auditSave(ctx) {
  131. try {
  132. if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
  133. const responseData = {
  134. err: 0, msg: '', data: null,
  135. };
  136. const data = JSON.parse(ctx.request.body.data);
  137. if (!data.type) {
  138. throw '提交数据错误';
  139. }
  140. const info = ctx.contract;
  141. const options = ctx.contractOptions;
  142. let uids;
  143. let result = false;
  144. let auditList = [];
  145. switch (data.type) {
  146. case 'check':
  147. await ctx.service.contractTree.insertTree(options, info);
  148. // 新建合同信息
  149. break;
  150. case 'add-audit':
  151. // 判断用户是单个还是数组
  152. uids = data.id instanceof Array ? data.id : [data.id];
  153. // 判断该用户的组是否已加入到表中,已加入则提示无需添加
  154. auditList = await ctx.service.contractAudit.getAllDataByCondition({ where: options });
  155. const addAidList = ctx.helper._.difference(uids, ctx.helper._.map(auditList, 'uid'));
  156. if (addAidList.length === 0) {
  157. throw '用户已存在成员管理中,无需重复添加';
  158. }
  159. const accountList = await ctx.service.projectAccount.getAllDataByCondition({ where: { id: addAidList } });
  160. await ctx.service.contractAudit.saveAudits(options, accountList);
  161. responseData.data = await ctx.service.contractAudit.getList(options);
  162. break;
  163. case 'del-audit':
  164. uids = data.id instanceof Array ? data.id : [data.id];
  165. const cloneOptions = ctx.helper._.cloneDeep(options);
  166. cloneOptions.id = uids;
  167. auditList = await ctx.service.contractAudit.getAllDataByCondition({ where: cloneOptions });
  168. if (auditList.length !== uids.length) {
  169. throw '该用户已不存在成员管理中,移除失败';
  170. }
  171. await ctx.service.contractAudit.delAudit(uids);
  172. responseData.data = await ctx.service.contractAudit.getList(options);
  173. break;
  174. case 'save-permission':
  175. result = await ctx.service.contractAudit.updatePermission(data.updateData);
  176. if (!result) {
  177. throw '修改权限失败';
  178. }
  179. break;
  180. case 'list':
  181. responseData.data = await ctx.service.contractAudit.getList(options);
  182. break;
  183. default: throw '参数有误';
  184. }
  185. ctx.body = responseData;
  186. } catch (err) {
  187. this.log(err);
  188. ctx.body = { err: 1, msg: err.toString(), data: null };
  189. }
  190. }
  191. async detail(ctx) {
  192. try {
  193. const whiteList = ctx.app.config.multipart.whitelist;
  194. const contractOptions = ctx.helper._.cloneDeep(ctx.contractOptions);
  195. contractOptions.contract_type = ctx.contract_type;
  196. const contractTreeAudits = await ctx.service.contractTreeAudit.getAllDataByCondition({ where: contractOptions });
  197. const renderData = {
  198. contractTreeAudits,
  199. audit_permission: ctx.contract_audit_permission,
  200. preUrl: ctx.contractOptions.tid ? '/contract/tender' : '/contract',
  201. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.contract.detail),
  202. contract_type: ctx.contract_type,
  203. contractConst,
  204. whiteList,
  205. };
  206. if (ctx.session.sessionUser.is_admin) {
  207. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  208. where: { project_id: ctx.session.sessionProject.id, enable: 1 },
  209. columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
  210. });
  211. renderData.accountList = accountList;
  212. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  213. renderData.accountGroup = unitList.map(item => {
  214. const groupList = accountList.filter(item1 => item1.company === item.name);
  215. return { groupName: item.name, groupList };
  216. });
  217. }
  218. await this.layout('contract/detail.ejs', renderData, 'contract/detail_modal.ejs');
  219. } catch (err) {
  220. ctx.log(err);
  221. ctx.session.postError = err.toString();
  222. ctx.redirect(ctx.contractOptions.spid ? '/contract' : '/contract/tender');
  223. }
  224. }
  225. async loadDetail(ctx) {
  226. try {
  227. const responseData = {
  228. err: 0, msg: '', data: {},
  229. };
  230. const contractOptions = ctx.helper._.cloneDeep(ctx.contractOptions);
  231. contractOptions.contract_type = ctx.contract_type;
  232. // const data = JSON.parse(ctx.request.body.data);
  233. // ctx.contractOptions.contract_type = ctx.contract_type;
  234. responseData.data.contractTree = await ctx.service.contractTree.getAllDataByCondition({ where: contractOptions });
  235. // 获取权限并展示对应合同
  236. responseData.data.contractList = await ctx.service.contract.getListByUsers(contractOptions, ctx.session.sessionUser);
  237. // responseData.data.contractList = await ctx.service.contract.getAllDataByCondition({ where: contractOptions });
  238. // const userOptions = ctx.helper._.cloneDeep(ctx.contractOptions);
  239. // // userOptions.uid = ctx.session.sessionUser.id;
  240. // const permissionEdit = ctx.session.sessionUser.is_admin ? true : await ctx.service.contractAudit.getUserPermissionEdit(userOptions);
  241. // responseData.data.auditContractTreePermission = permissionEdit ? [] : await ctx.service.contractTreeAudit.getAllDataByCondition({ where: contractOptions });
  242. // responseData.data.contractAttList = await ctx.service.contractAtt.getAllDataByCondition({ where: ctx.contractOptions });
  243. if (ctx.session.sessionUser.is_admin) {
  244. const contractAudits = await ctx.service.contractAudit.getList(ctx.contractOptions);
  245. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  246. const accountGroup = unitList.map(item => {
  247. const groupList = contractAudits.filter(item1 => item1.company === item.name);
  248. return { groupName: item.name, groupList };
  249. });
  250. responseData.data.contractAudits = contractAudits;
  251. responseData.data.accountGroup = ctx.helper._.filter(accountGroup, function (item) {
  252. return item.groupList.length > 0;
  253. });
  254. }
  255. ctx.body = responseData;
  256. } catch (err) {
  257. this.log(err);
  258. ctx.body = { err: 1, msg: err.toString(), data: null };
  259. }
  260. }
  261. async updateBills(ctx) {
  262. try {
  263. const data = JSON.parse(ctx.request.body.data);
  264. if (!data.postType || !data.postData) throw '数据错误';
  265. const responseData = { err: 0, msg: '', data: {} };
  266. const options = ctx.helper._.cloneDeep(ctx.contractOptions);
  267. options.contract_type = ctx.contract_type;
  268. switch (data.postType) {
  269. case 'add':
  270. case 'add-child':
  271. case 'delete':
  272. case 'up-move':
  273. case 'down-move':
  274. case 'up-level':
  275. case 'down-level':
  276. responseData.data = await this._billsBase(ctx, data.postType, data.postData, options);
  277. break;
  278. case 'update':
  279. responseData.data = await ctx.service.contractTree.updateCalc(options, data.postData);
  280. break;
  281. case 'update-contract':
  282. responseData.data = await ctx.service.contract.updateCalc(options, data.postData);
  283. break;
  284. case 'paste-block':
  285. responseData.data = await this._pasteBlock(ctx, data.postData, options);
  286. break;
  287. case 'add-contract':
  288. responseData.data = await ctx.service.contract.add(options, data.postData.select, data.postData.contract);
  289. break;
  290. case 'add-tree-audit':
  291. responseData.data = await ctx.service.contractTreeAudit.add(options, data.postData.select, data.postData.auditId);
  292. break;
  293. case 'del-tree-audit':
  294. responseData.data = await ctx.service.contractTreeAudit.dels(options, data.postData.select, data.postData.auditIds);
  295. break;
  296. case 'get-contract':
  297. responseData.data.pays = await ctx.service.contractPay.getPays(options, data.postData);
  298. responseData.data.files = await ctx.service.contractAtt.getAtt(data.postData);
  299. break;
  300. case 'add-contract-pay':
  301. responseData.data = await ctx.service.contractPay.add(options, data.postData.select, data.postData.pay);
  302. break;
  303. case 'save-contract-pay':
  304. responseData.data = await ctx.service.contractPay.save(options, data.postData.select, data.postData.pay);
  305. break;
  306. case 'del-contract-pay':
  307. responseData.data = await ctx.service.contractPay.del(options, data.postData.select, data.postData.pay);
  308. break;
  309. default:
  310. throw '未知操作';
  311. }
  312. ctx.body = responseData;
  313. } catch (err) {
  314. console.log(err);
  315. this.log(err);
  316. ctx.body = this.ajaxErrorBody(err, '数据错误');
  317. }
  318. }
  319. async _billsBase(ctx, type, data, options) {
  320. if (isNaN(data.id) || data.id <= 0) throw '数据错误';
  321. if (type !== 'add') {
  322. if (isNaN(data.count) || data.count <= 0) data.count = 1;
  323. }
  324. switch (type) {
  325. case 'add':
  326. return await ctx.service.contractTree.addNodeBatch(options, data.id, data.count);
  327. case 'add-child':
  328. return await ctx.service.contractTree.addChildNode(options, data.id, data.count);
  329. case 'delete':
  330. return await ctx.service.contractTree.delete(options, data.id, data.count);
  331. case 'up-move':
  332. return await ctx.service.contractTree.upMoveNode(options, data.id, data.count);
  333. case 'down-move':
  334. return await ctx.service.contractTree.downMoveNode(options, data.id, data.count);
  335. case 'up-level':
  336. return await ctx.service.contractTree.upLevelNode(options, data.id, data.count);
  337. case 'down-level':
  338. return await ctx.service.contractTree.downLevelNode(options, data.id, data.count);
  339. default:
  340. throw '未知操作';
  341. }
  342. }
  343. /**
  344. * 复制粘贴整块
  345. *
  346. * @param ctx
  347. * @return {Promise<void>}
  348. */
  349. async _pasteBlock(ctx, data, options) {
  350. if ((isNaN(data.id) || data.id <= 0) ||
  351. (!data.block || data.block.length <= 0)) throw '参数错误';
  352. return await ctx.service.contractTree.pasteBlockData(options, data.id, data.block);
  353. }
  354. /**
  355. * 上传附件
  356. * @param {*} ctx 上下文
  357. */
  358. async uploadFile(ctx) {
  359. let stream;
  360. try {
  361. const responseData = { err: 0, msg: '', data: {} };
  362. const cid = ctx.params.cid;
  363. if (!cid) throw '参数有误';
  364. const cpid = parseInt(ctx.params.cpid);
  365. const parts = this.ctx.multipart({
  366. autoFields: true,
  367. });
  368. const files = [];
  369. const create_time = Date.parse(new Date()) / 1000;
  370. let idx = 0;
  371. while ((stream = await parts()) !== undefined) {
  372. if (!stream.filename) {
  373. // 如果没有传入直接返回
  374. return;
  375. }
  376. const fileInfo = path.parse(stream.filename);
  377. const headpath = ctx.contractOptions.spid ? `sp/contract/${ctx.contractOptions.spid}` : `app/public/upload/${ctx.contractOptions.tid}`;
  378. const filepath = `${headpath}/contract/${cid}${cpid ? '/pay/' + cpid : ''}/fujian_${create_time + idx.toString() + fileInfo.ext}`;
  379. // await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
  380. await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
  381. files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
  382. ++idx;
  383. stream && (await sendToWormhole(stream));
  384. }
  385. const in_time = new Date();
  386. const payload = files.map(file => {
  387. let idx;
  388. if (Array.isArray(parts.field.name)) {
  389. idx = parts.field.name.findIndex(name => name === file.name);
  390. } else {
  391. idx = 'isString';
  392. }
  393. const newFile = {
  394. spid: ctx.contractOptions.spid || null,
  395. tid: ctx.contractOptions.tid || null,
  396. contract_type: ctx.contract_type,
  397. cid,
  398. uid: ctx.session.sessionUser.accountId,
  399. filename: file.name,
  400. fileext: file.ext,
  401. filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
  402. filepath: file.filepath,
  403. upload_time: in_time,
  404. };
  405. if (cpid) {
  406. newFile.cpid = cpid;
  407. }
  408. return newFile;
  409. });
  410. if (cpid) {
  411. // 执行文件信息写入数据库
  412. await ctx.service.contractPayAtt.saveFileMsgToDb(payload);
  413. // 将最新的当前标段的所有文件信息返回
  414. responseData.data = await ctx.service.contractPayAtt.getAtt(cpid);
  415. } else {
  416. // 执行文件信息写入数据库
  417. await ctx.service.contractAtt.saveFileMsgToDb(payload);
  418. // 将最新的当前标段的所有文件信息返回
  419. responseData.data = await ctx.service.contractAtt.getAtt(cid);
  420. }
  421. ctx.body = responseData;
  422. } catch (err) {
  423. stream && (await sendToWormhole(stream));
  424. this.log(err);
  425. ctx.body = { err: 1, msg: err.toString(), data: null };
  426. }
  427. }
  428. /**
  429. * 删除附件
  430. * @param {Ojbect} ctx 上下文
  431. */
  432. async deleteFile(ctx) {
  433. try {
  434. const cpid = ctx.params.cpid;
  435. const cid = ctx.params.cid;
  436. const responseData = { err: 0, msg: '', data: {} };
  437. const data = JSON.parse(ctx.request.body.data);
  438. let fileInfo = null;
  439. if (cpid) {
  440. fileInfo = await ctx.service.contractPayAtt.getDataById(data.id);
  441. } else if (cid) {
  442. fileInfo = await ctx.service.contractAtt.getDataById(data.id);
  443. } else {
  444. throw '参数错误';
  445. }
  446. if (fileInfo || Object.keys(fileInfo).length) {
  447. // 先删除文件
  448. // await fs.unlinkSync(path.resolve(this.app.baseDir, './app', fileInfo.filepath));
  449. await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + fileInfo.filepath);
  450. // 再删除数据库
  451. if (cpid) {
  452. await ctx.service.contractPayAtt.delete(data.id);
  453. } else {
  454. await ctx.service.contractAtt.delete(data.id);
  455. }
  456. } else {
  457. throw '不存在该文件';
  458. }
  459. if (cpid) {
  460. responseData.data = await ctx.service.contractPayAtt.getAtt(cpid);
  461. } else {
  462. responseData.data = await ctx.service.contractAtt.getAtt(cid);
  463. }
  464. ctx.body = responseData;
  465. } catch (err) {
  466. this.log(err);
  467. ctx.body = { err: 1, msg: err.toString(), data: null };
  468. }
  469. }
  470. /**
  471. * 下载附件
  472. * @param {Object} ctx - egg全局变量
  473. * @return {void}
  474. */
  475. async downloadFile(ctx) {
  476. const id = ctx.params.fid;
  477. if (id) {
  478. try {
  479. const cpid = ctx.params.cpid;
  480. const cid = ctx.params.cid;
  481. let fileInfo = null;
  482. if (cpid) {
  483. fileInfo = await ctx.service.contractPayAtt.getDataById(id);
  484. } else if (cid) {
  485. fileInfo = await ctx.service.contractAtt.getDataById(id);
  486. } else {
  487. throw '参数错误';
  488. }
  489. if (fileInfo || Object.keys(fileInfo).length) {
  490. // const fileName = path.join(__dirname, '../', fileInfo.filepath);
  491. // 解决中文无法下载问题
  492. const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
  493. let disposition = '';
  494. if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
  495. disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename);
  496. } else if (userAgent.indexOf('firefox') >= 0) {
  497. disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename) + '"';
  498. } else {
  499. /* safari等其他非主流浏览器只能自求多福了 */
  500. disposition = 'attachment; filename=' + new Buffer(fileInfo.filename).toString('binary');
  501. }
  502. ctx.response.set({
  503. 'Content-Type': 'application/octet-stream',
  504. 'Content-Disposition': disposition,
  505. 'Content-Length': fileInfo.filesize,
  506. });
  507. // ctx.body = await fs.createReadStream(fileName);
  508. ctx.body = await ctx.helper.ossFileGet(fileInfo.filepath);
  509. } else {
  510. throw '不存在该文件';
  511. }
  512. } catch (err) {
  513. this.log(err);
  514. this.setMessage(err.toString(), this.messageType.ERROR);
  515. }
  516. }
  517. }
  518. }
  519. return ContractController;
  520. };