|  | @@ -336,7 +336,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      const fileInfo = path.parse(stream.filename);
 | 
	
		
			
				|  |  |                      const filepath = `public/upload/${this.ctx.tender.id.toString()}/yfk/fujian_${create_time + idx.toString() + fileInfo.ext}`;
 | 
	
		
			
				|  |  |                      await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
 | 
	
		
			
				|  |  | -                    files.push({ filepath, name: `fujian_${create_time + idx.toString() + fileInfo.ext}` });
 | 
	
		
			
				|  |  | +                    files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
 | 
	
		
			
				|  |  |                      ++idx;
 | 
	
		
			
				|  |  |                      stream && (await sendToWormhole(stream));
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -355,6 +355,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                          filepath: file.filepath,
 | 
	
		
			
				|  |  |                          filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
 | 
	
		
			
				|  |  |                          filename: file.name,
 | 
	
		
			
				|  |  | +                        fileext: file.ext,
 | 
	
		
			
				|  |  |                      };
 | 
	
		
			
				|  |  |                      return newFile;
 | 
	
		
			
				|  |  |                  });
 | 
	
	
		
			
				|  | @@ -393,6 +394,45 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  ctx.body = { err: 1, msg: err.toString(), data: null };
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /**
 | 
	
		
			
				|  |  | +         * 下载附件
 | 
	
		
			
				|  |  | +         * @param {Object} ctx - egg全局变量
 | 
	
		
			
				|  |  | +         * @return {void}
 | 
	
		
			
				|  |  | +         */
 | 
	
		
			
				|  |  | +        async downloadFile(ctx) {
 | 
	
		
			
				|  |  | +            const id = ctx.params.fid;
 | 
	
		
			
				|  |  | +            if (id) {
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    const fileInfo = await ctx.service.advanceFile.getDataById(id);
 | 
	
		
			
				|  |  | +                    if (fileInfo !== undefined && fileInfo !== '') {
 | 
	
		
			
				|  |  | +                        const fileName = path.join(this.app.baseDir, 'app', fileInfo.filepath);
 | 
	
		
			
				|  |  | +                        // 解决中文无法下载问题
 | 
	
		
			
				|  |  | +                        const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
 | 
	
		
			
				|  |  | +                        let disposition = '';
 | 
	
		
			
				|  |  | +                        if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
 | 
	
		
			
				|  |  | +                            disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename);
 | 
	
		
			
				|  |  | +                        } else if (userAgent.indexOf('firefox') >= 0) {
 | 
	
		
			
				|  |  | +                            disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename) + '"';
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            /* safari等其他非主流浏览器只能自求多福了 */
 | 
	
		
			
				|  |  | +                            disposition = 'attachment; filename=' + new Buffer(fileInfo.filename).toString('binary');
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        ctx.response.set({
 | 
	
		
			
				|  |  | +                            'Content-Type': 'application/octet-stream',
 | 
	
		
			
				|  |  | +                            'Content-Disposition': disposition,
 | 
	
		
			
				|  |  | +                            'Content-Length': fileInfo.filesize,
 | 
	
		
			
				|  |  | +                        });
 | 
	
		
			
				|  |  | +                        ctx.body = await fs.createReadStream(fileName);
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        throw '不存在该文件';
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } catch (err) {
 | 
	
		
			
				|  |  | +                    this.log(err);
 | 
	
		
			
				|  |  | +                    this.setMessage(err.toString(), this.messageType.ERROR);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      return advanceController;
 | 
	
		
			
				|  |  |  };
 |