diff --git a/controller/studentMeetingController.js b/controller/studentMeetingController.js index 0844876..071bb83 100644 --- a/controller/studentMeetingController.js +++ b/controller/studentMeetingController.js @@ -2,6 +2,7 @@ var status = require('../util/resTemplate') var studentMeetingService = require('../services/studentMeetingService') var uuid = require('../util/UuidUtil') +const moment = require('moment') var emailUtil = require('../util/emailUtil') @@ -24,6 +25,7 @@ studentMeetingController.prototype.addStudentMeeting = async(ctx, next)=>{ var id32 = await uuid.db32(); body.id = id32; body.status = 0; + body.createTime = moment(new Date()).format("YYYY-MM-DD HH:MM:SS "); let studentMeetings= await studentMeetingService.addStudentMeeting(body); return studentMeetings; } catch (error) { diff --git a/model/studentMeetingModel.js b/model/studentMeetingModel.js index 850ac3c..2d5fbc6 100644 --- a/model/studentMeetingModel.js +++ b/model/studentMeetingModel.js @@ -25,6 +25,11 @@ var studentMeeting = sequelize.define('3m_student_meeting', { allowNull: false, type:Sequelize.STRING(32), field: "status" + }, + createTime: { + allowNull: false, + type:Sequelize.STRING(32), + field: "create_time" } },{ timestamps: false, diff --git a/services/studentMeetingService.js b/services/studentMeetingService.js index 0752fa4..7639e7e 100644 --- a/services/studentMeetingService.js +++ b/services/studentMeetingService.js @@ -1,4 +1,5 @@ var sutudentMeeting = require('../model/studentMeetingModel'); +var userModel = require('../model/userModel'); var status = require('../util/resTemplate'); var saitMd5 = require('../util/saltMD5'); var sequelize = require('../config'); @@ -13,7 +14,17 @@ function sutudentMeetingService(){ sutudentMeetingService.prototype.addStudentMeeting = async(body)=>{ try { - var t = await sequelize.transaction({ autocommit: true }) + 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:'您已预约这堂课',data:oldSutudentMeeting} + } let Meeting = await meetingModel.findOne({where:{id:body.meetingId}}); if(!Meeting){ t.rollback();