付智勇

上传轮播

... ... @@ -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)
... ...
... ... @@ -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
... ...
... ... @@ -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
... ...
... ... @@ -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>
... ...