diff --git a/app/common/model/StudentSchedule.php b/app/common/model/StudentSchedule.php new file mode 100644 index 0000000..9bf7f79 --- /dev/null +++ b/app/common/model/StudentSchedule.php @@ -0,0 +1,27 @@ +post(); $salt = random_str(16); if (empty($request_data['password'])) { - $password = trim(explode('', $request_data['account'])[0]) . '001'; + $password = trim(explode(' ', $request_data['account'])[0]) . '001'; $password = md5($password . $salt); } else { $password = md5($request_data['password'] . $salt); diff --git a/plugin/admin/app/controller/StudentScheduleController.php b/plugin/admin/app/controller/StudentScheduleController.php new file mode 100644 index 0000000..e16567e --- /dev/null +++ b/plugin/admin/app/controller/StudentScheduleController.php @@ -0,0 +1,141 @@ +model = new StudentSchedule; + } + + /** + * 浏览 + * @return Response + */ + public function index(): Response + { + return view('student-schedule/index'); + } + + /** + * 插入 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function insert(Request $request): Response + { + if ($request->method() === 'POST') { + return parent::insert($request); + } + return view('student-schedule/insert'); + } + + /** + * 更新 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function update(Request $request): Response + { + if ($request->method() === 'POST') { + return parent::update($request); + } + return view('student-schedule/update'); + } + + + /** + * @desc 添加学生排课 + * @param Request $request + * @return Response + */ + public function addStudentSchedule(Request $request) + { + try { + $data = $request->post(); + $teacher_schedule_time = TeacherScheduleTime::where(['id' => $data['teacher_schedule_time_id']])->findOrEmpty(); + + if ($teacher_schedule_time->isEmpty()) { + throw new Exception('未找到教师排课,添加失败'); + } + + if($data['type'] == 'add'){ + if (empty($teacher_schedule_time->subject_id)) { + throw new Exception('请先排课再添加学生'); + } + //判断学生时间和教师时间是否冲突 + $conflict = \app\common\model\StudentSchedule::where(['student_id' => $data['student_id']])->whereRaw(" + (start_time <= ? AND end_time >= ?) OR + (start_time <= ? AND end_time >= ?) OR + (? <= start_time AND ? >= end_time) + ", [$teacher_schedule_time->start_time, $teacher_schedule_time->start_time, + $teacher_schedule_time->end_time, $teacher_schedule_time->end_time, + $teacher_schedule_time->start_time, $teacher_schedule_time->end_time, + ])->findOrEmpty(); + + if (!$conflict->isEmpty()) { + throw new Exception('该学生课程和其他课程有冲突'); + } + + $res = \app\common\model\StudentSchedule::create([ + 'student_id' => $data['student_id'], + 'teacher_schedule_time_id' => $teacher_schedule_time->id, + 'teacher_schedule_time_detail' => '', + 'teacher_id' => $teacher_schedule_time->teacher_id, + 'subject_id' => $teacher_schedule_time->subject_id, + 'date' => $teacher_schedule_time->date, + 'time' => $teacher_schedule_time->time, + 'hour' => $teacher_schedule_time->hour, + 'start_time' => $teacher_schedule_time->start_time, + 'end_time' => $teacher_schedule_time->end_time, + 'month' => $teacher_schedule_time->month, + ]); + if (!$res) { + throw new Exception('添加失败'); + } + + }else{ + $student_schedule = \app\common\model\StudentSchedule::where(['student_id' => $data['student_id'], 'teacher_schedule_time_id' => $teacher_schedule_time->id])->findOrEmpty(); + + $student_schedule->delete(); + } + + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => '添加成功', + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + +} diff --git a/plugin/admin/app/controller/TeacherController.php b/plugin/admin/app/controller/TeacherController.php index e000db9..1ff8e42 100644 --- a/plugin/admin/app/controller/TeacherController.php +++ b/plugin/admin/app/controller/TeacherController.php @@ -162,6 +162,23 @@ class TeacherController extends Crud } + /** + * @desc 教师月份课程安排 + * @param Request $request + * @return Response + */ + public function teacherScheduleTime(Request $request) + { + + $data = $request->get(); + $teacher_id = $data['teacher_id']; + $month = $data['month']; + $teacher = \app\common\model\Teacher::where(['id'=>$teacher_id])->findOrEmpty(); + + return view('teacher/teacher_schedule_time', ['teacher' => $teacher, 'month' => $month]); + } + + /** * @desc 获取教师课程安排统计 * @param Request $request diff --git a/plugin/admin/app/controller/TeacherScheduleTimeController.php b/plugin/admin/app/controller/TeacherScheduleTimeController.php index 79c2b89..bfb7622 100644 --- a/plugin/admin/app/controller/TeacherScheduleTimeController.php +++ b/plugin/admin/app/controller/TeacherScheduleTimeController.php @@ -2,6 +2,7 @@ namespace plugin\admin\app\controller; +use app\common\model\Student; use app\common\model\Subject; use app\common\model\Teacher; use app\constant\ResponseCode; @@ -141,9 +142,12 @@ class TeacherScheduleTimeController extends Crud } $free_time_id = $request->get('free_time_id'); $schedule_time = \app\common\model\TeacherScheduleTime::where(['id' => $free_time_id])->with(['teacher'])->findOrEmpty()->toArray(); + //课程 $project = Subject::order('sort desc, id asc')->select()->toArray(); + //学生 + $student = Student::order('id asc')->field('id,account,student_name')->select()->toArray(); - return view('teacher-schedule-time/schedule_time_setting', ['schedule_time' => $schedule_time, 'project' => $project]); + return view('teacher-schedule-time/schedule_time_setting', ['schedule_time' => $schedule_time, 'project' => $project, 'student' => $student]); } /** diff --git a/plugin/admin/app/model/StudentSchedule.php b/plugin/admin/app/model/StudentSchedule.php new file mode 100644 index 0000000..91b94cf --- /dev/null +++ b/plugin/admin/app/model/StudentSchedule.php @@ -0,0 +1,39 @@ + + +
+ +