diff --git a/app/common/model/StudentSchedule.php b/app/common/model/StudentSchedule.php index 9bf7f79..f0f12dc 100644 --- a/app/common/model/StudentSchedule.php +++ b/app/common/model/StudentSchedule.php @@ -23,5 +23,19 @@ use support\Model; class StudentSchedule extends BaseModel { - + public function teacher() + { + return $this->hasOne(Teacher::class, 'id', 'teacher_id')->bind(['teacher_account'=>'account', 'teacher_name']); + } + + public function subject() + { + return $this->hasOne(Subject::class, 'id', 'subject_id')->bind(['subject_name', 'english_name']); + } + + public function student() + { + return $this->hasOne(Student::class, 'id', 'student_id')->bind(['student_name', 'student_account'=>'account']); + } + } diff --git a/plugin/admin/app/controller/StudentScheduleController.php b/plugin/admin/app/controller/StudentScheduleController.php index e16567e..fe2f42f 100644 --- a/plugin/admin/app/controller/StudentScheduleController.php +++ b/plugin/admin/app/controller/StudentScheduleController.php @@ -2,6 +2,9 @@ namespace plugin\admin\app\controller; +use app\common\model\Student; +use app\common\model\Subject; +use app\common\model\Teacher; use app\common\model\TeacherScheduleTime; use app\constant\ResponseCode; use support\Request; @@ -37,7 +40,92 @@ class StudentScheduleController extends Crud */ public function index(): Response { - return view('student-schedule/index'); + //获取所有老师 + $teacher = Teacher::order('id asc')->field('id,teacher_name,account')->select()->toArray(); + //所有课程 + $subject = Subject::order('sort desc,id asc')->field('id,subject_name,english_name')->select()->toArray(); + $student = Student::order('id asc')->field('id,student_name,account')->select()->toArray(); + + return view('student-schedule/index', ['teacher' => $teacher, 'subject' => $subject, 'student' => $student]); + } + + + public function select(Request $request): Response + { + try { + $data = $request->get(); + $student_schedule = \app\common\model\StudentSchedule::order('id desc'); + + if (isset($data['student_id']) && $data['student_id']) { + $student_schedule->where(['student_id' => $data['student_id']]); + } + if (isset($data['teacher_id']) && $data['teacher_id']) { + $student_schedule->where(['teacher_id' => $data['teacher_id']]); + } + if (isset($data['subject_id']) && $data['subject_id']) { + $student_schedule->where(['subject_id' => $data['subject_id']]); + } + if (isset($data['date']) && $data['date']) { + if ($data['date'][0] && $data['date'][1]) { + $student_schedule->whereBetweenTime('date', $data['date'][0], $data['date'][1]); + } + } + if (isset($data['month']) && $data['month']) { + $student_schedule->where(['month' => $data['month']]); + } + if (isset($data['is_publish']) && $data['is_publish'] !== '') { + $student_schedule->where(['is_publish' => $data['is_publish']]); + } + + + $limit = (int)$request->get('limit', 10); + $limit = $limit <= 0 ? 10 : $limit; + $page = (int)$request->get('page'); + $page = $page > 0 ? $page : 1; + + $total = $student_schedule->count(); + $list = $student_schedule->with(['teacher', 'student', 'subject'])->page($page, $limit)->select(); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'data' => $list, + 'count' => $total, + 'msg' => 'success' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + + + /** + * @desc 更改学生课表状态 + * @param Request $request + * @return Response + */ + public function changePublishStatus(Request $request) + { + try { + $data = $request->post(); + $res = \app\common\model\StudentSchedule::where(['id' => $data['ids']])->save([ + 'is_publish' => $data['status'] + ]); + if (!$res) { + throw new Exception('操作失败'); + } + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => 'success' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } } /** @@ -84,7 +172,7 @@ class StudentScheduleController extends Crud throw new Exception('未找到教师排课,添加失败'); } - if($data['type'] == 'add'){ + if ($data['type'] == 'add') { if (empty($teacher_schedule_time->subject_id)) { throw new Exception('请先排课再添加学生'); } @@ -96,10 +184,10 @@ class StudentScheduleController extends Crud ", [$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(); + ])->with(['teacher', 'subject'])->findOrEmpty(); if (!$conflict->isEmpty()) { - throw new Exception('该学生课程和其他课程有冲突'); + throw new Exception("该学生课程和【{$conflict->teacher_name}】的【{$conflict->subject_name} {$conflict->date} {$conflict->time} 】有冲突"); } $res = \app\common\model\StudentSchedule::create([ @@ -119,7 +207,7 @@ class StudentScheduleController extends Crud throw new Exception('添加失败'); } - }else{ + } 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(); diff --git a/plugin/admin/app/controller/TeacherController.php b/plugin/admin/app/controller/TeacherController.php index 1ff8e42..226a480 100644 --- a/plugin/admin/app/controller/TeacherController.php +++ b/plugin/admin/app/controller/TeacherController.php @@ -2,6 +2,9 @@ namespace plugin\admin\app\controller; +use app\common\model\Student; +use app\common\model\StudentSchedule; +use app\common\model\Subject; use app\common\model\TeacherScheduleTime; use app\constant\ResponseCode; use support\Request; @@ -162,23 +165,6 @@ 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 @@ -229,6 +215,63 @@ 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(); + //获取该老师当前分配学生 +// $student_schedule = StudentSchedule::where(['']) + + return view('teacher/teacher_schedule_time', ['teacher' => $teacher, 'month' => $month]); + } + + + /** + * 更新 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function scheduleTimeSet(Request $request): Response + { + if ($request->method() === 'POST') { + + if ($request->post('is_publish')) { + $request->post('is_publish', 0); + } +// parent::update($request); + + return parent::update($request); + } + $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(); + $student_schedule = StudentSchedule::where(['teacher_schedule_time_id' => $free_time_id])->select()->toArray(); + $student_schedule_id = []; + if ($student_schedule) { + $student_schedule_id = array_column($student_schedule, 'student_id'); + } + + + return view('teacher/schedule_time_setting', [ + 'schedule_time' => $schedule_time, + 'project' => $project, + 'student' => $student, + 'student_schedule_id' => $student_schedule_id]); + } + /** * @desc 重置密码 * @param Request $request diff --git a/plugin/admin/app/controller/TeacherScheduleTimeController.php b/plugin/admin/app/controller/TeacherScheduleTimeController.php index bfb7622..f678d2a 100644 --- a/plugin/admin/app/controller/TeacherScheduleTimeController.php +++ b/plugin/admin/app/controller/TeacherScheduleTimeController.php @@ -3,6 +3,7 @@ namespace plugin\admin\app\controller; use app\common\model\Student; +use app\common\model\StudentSchedule; use app\common\model\Subject; use app\common\model\Teacher; use app\constant\ResponseCode; @@ -123,32 +124,6 @@ class TeacherScheduleTimeController extends Crud return view('teacher-schedule-time/update', ['teacher' => $teacher]); } - /** - * 更新 - * @param Request $request - * @return Response - * @throws BusinessException - */ - public function scheduleTimeSet(Request $request): Response - { - if ($request->method() === 'POST') { - - if ($request->post('is_publish')) { - $request->post('is_publish', 0); - } -// parent::update($request); - - return parent::update($request); - } - $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, 'student' => $student]); - } /** * @desc 时间列表 diff --git a/plugin/admin/app/model/StudentSchedule.php b/plugin/admin/app/model/StudentSchedule.php index 91b94cf..46c5593 100644 --- a/plugin/admin/app/model/StudentSchedule.php +++ b/plugin/admin/app/model/StudentSchedule.php @@ -11,9 +11,13 @@ use plugin\admin\app\model\Base; * @property mixed $teacher_schedule_time_detail 排课详情 * @property integer $teacher_id 教师 * @property integer $subject_id 学科 - * @property string $date_time 课程时间 - * @property string $date_start_time 课程开始时间 - * @property string $date_end_time 课程结束时间 + * @property string $date 日期 + * @property string $time 时间段 + * @property mixed $hour 课时 + * @property string $start_time 课程开始时间 + * @property string $end_time 课程结束时间 + * @property string $month 月份 + * @property integer $is_public 是否发布0:未发布 1:已发布 * @property mixed $created_at 创建时间 * @property string $updated_at 更新时间 * @property string $deleted_at diff --git a/plugin/admin/app/view/student-schedule/index.html b/plugin/admin/app/view/student-schedule/index.html index 851c6dc..7e58be7 100644 --- a/plugin/admin/app/view/student-schedule/index.html +++ b/plugin/admin/app/view/student-schedule/index.html @@ -1,341 +1,487 @@ - -
- -