studentMeetingService.js
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var sutudentMeeting = require('../model/studentMeetingModel');
var userModel = require('../model/userModel');
var status = require('../util/resTemplate');
var saitMd5 = require('../util/saltMD5');
var sequelize = require('../config');
var tokenUtil = require('../util/tokenUtil');
var meetingModel = require('../model/meetingModel');
var co = require('co');
function sutudentMeetingService(){
}
sutudentMeetingService.prototype.addStudentMeeting = async(body)=>{
try {
var t = await sequelize.transaction({ autocommit: true })
let user = await userModel.findOne({where:{id:body.studentId}});
if(!user){
t.rollback();
return {code:300,msg:'用户不存在'}
}
let oldSutudentMeeting = await sutudentMeeting.findOne({where:{studentId:body.studentId,meetingId:body.meetingId}});
if(oldSutudentMeeting){
t.rollback();
return {code:300,msg:'您已预约这堂课'}
}
let Meeting = await meetingModel.findOne({where:{id:body.meetingId}});
if(!Meeting){
t.rollback();
return {code:300,msg:'课堂不存在'}
}
let sm = await sutudentMeeting.create(body,{transaction: t});
// let MeetingBack = await meetingModel.update(
// {reservationNumber:Meeting.reservationNumber+1},
// {where:{id:body.meetingId}},
// {transaction: t});
t.commit();
return sm;
} catch (error) {
t.rollback();
throw error;
}
}
sutudentMeetingService.prototype.getStudentMeetingCount = async(meetingId) =>{
try {
let sm = await sutudentMeeting.count({where:{meetingId:meetingId}})
return sm;
} catch (error) {
console.log(error)
throw error;
}
}
sutudentMeetingService.prototype.queryStudentMeeting = async(teacherName,page=1,pageno=8)=>{
try {
let querySql = `SELECT
3u.*, 3meet.meeting_name,
3meet.create_user teacherName
FROM
3m_student_meeting 3sm
LEFT JOIN 3m_user 3u ON 3u.id = 3sm.student_id
LEFT JOIN 3m_meeting 3meet ON 3meet.id = 3sm.meeting_id
WHERE
3meet.create_user = '` +teacherName+"'";;
querySql += ' ORDER BY 3sm.create_time DESC LIMIT '+(page-1)*pageno+' , ' +pageno
let sm = await sequelize.query(querySql);
return sm[0];
} catch (error) {
console.log(error)
throw error;
}
}
module.exports = new sutudentMeetingService();