From 94d0ce6cd94d2741b959f55d120e19d2b934569d Mon Sep 17 00:00:00 2001 From: 付智勇 <fuzhiyong@efangtec.com> Date: Fri, 29 Sep 2017 14:55:34 +0800 Subject: [PATCH] 上传轮播 --- routes/upload.js | 40 ++++++++++++++++++++++++++++++++++------ services/meetingService.js | 2 +- services/studentMeetingService.js | 2 +- views/index.html | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/routes/upload.js b/routes/upload.js index 59f1e64..101237f 100644 --- a/routes/upload.js +++ b/routes/upload.js @@ -30,25 +30,38 @@ router.post('/upLoadDoc',uploaddemo, async (ctx, next) => { try { const businessId = ctx.query.businessId; const category = ctx.query.category; + const siteId = ctx.query.siteId; let w = await fs.rename(applacation.uploade+ctx.req.file.filename,applacation.uploade+ctx.req.file.originalname) let path = 'http://localhost:10000/'+ctx.req.file.originalname attachmentData = { id:uuid.db32(), businessId:businessId, category:category, - path:path + path:path, + siteId:siteId } - let oldAttachment = await attachmentModel.findOne({where:{businessId:businessId}}) - - if(oldAttachment){ - let oldAttachment = await attachmentModel.update({path:path},{where:{businessId:businessId}}) + let oldAttachment = await attachmentModel.findOne({where:{businessId:businessId,category:1}}) + if(category==2){ + let oldAttachment2 = await attachmentModel.findAll({where:{category:2,siteId:siteId}}) + if(oldAttachment2.length>5){ + throw new Error('最多上传5张') + }else { + let oldAttachment2one = await attachmentModel.findOne({where:{businessId:businessId,category:2,siteId:siteId}}) + if(oldAttachment2one){ + let oldAttachment = await attachmentModel.update({path:path},{where:{businessId:businessId,category:2,siteId:siteId}}) + }else{ + let attachment = await attachmentModel.create(attachmentData) + } + } + }else if(oldAttachment){ + let oldAttachment = await attachmentModel.update({path:path},{where:{businessId:businessId,category:1}}) }else{ let attachment = await attachmentModel.create(attachmentData) } ctx.response.status= 200; ctx.body = { code:200, - fileUrl:path+ctx.req.file.originalname + fileUrl:path } } catch (error) { console.log(error) @@ -58,6 +71,21 @@ router.post('/upLoadDoc',uploaddemo, async (ctx, next) => { }) +router.post('/getImgBySiteId',async(ctx, next)=>{ + try{ + let img = await attachmentModel.findAll({ + where:{ + siteId:ctx.request.body.siteId, + category:2 + } + }); + status.successTemp(ctx,200,img); + }catch(e){ + console.log(e) + status.catchError(ctx,400,e.message); + } +}) + router.post('/tgpCallback', async (ctx, next) => { //let s = await uploaddemo(ctx.req,ctx.res,next) diff --git a/services/meetingService.js b/services/meetingService.js index 436725d..7b06d58 100644 --- a/services/meetingService.js +++ b/services/meetingService.js @@ -102,7 +102,7 @@ meetingService.prototype.getMeeting = async(queryData,page = 1,pageno =12) =>{ FROM 3m_attachment WHERE - 3m_attachment.business_id = 3m_meeting.id + 3m_attachment.business_id = 3m_meeting.id and 3m_attachment.category = 1 ) meetingPhoto, ( SELECT diff --git a/services/studentMeetingService.js b/services/studentMeetingService.js index 43bb322..22c3b2d 100644 --- a/services/studentMeetingService.js +++ b/services/studentMeetingService.js @@ -140,7 +140,7 @@ studentMeetingService.prototype.getStudentMeetingByStudentId = async(id,page=1,p FROM 3m_attachment WHERE - 3m_attachment.business_id = 3meet.id + 3m_attachment.business_id = 3meet.id and 3m_attachment.category = 1 ) meetingPhoto FROM 3m_student_meeting 3sm diff --git a/views/index.html b/views/index.html index 2d92876..b44986f 100644 --- a/views/index.html +++ b/views/index.html @@ -7,7 +7,7 @@ <script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script> </head> <body> - <form action="/upload/upLoadDoc?businessId=0aJeQOYgLAo5yB1mE14Rvzb69V7mpZKD&category=1" method="post" enctype="multipart/form-data" target="http://baidu.com"> + <form action="/upload/upLoadDoc?businessId=8a9945605e7a0d74015e8388f9f022d6&category=2&siteId=networkschool" method="post" enctype="multipart/form-data" target="http://baidu.com"> <input type="file" name="file"/> <input type="submit" value="ok"/> </form> -- libgit2 0.24.0