diff --git a/app/api/controller/ParentController.php b/app/api/controller/ParentController.php new file mode 100644 index 0000000..ad3ed7e --- /dev/null +++ b/app/api/controller/ParentController.php @@ -0,0 +1,16 @@ +getSubjectHomework($request); + return $this->json($result); + + } +} \ No newline at end of file diff --git a/app/api/controller/SubjectHomeworkController.php b/app/api/controller/SubjectHomeworkController.php new file mode 100644 index 0000000..0336abb --- /dev/null +++ b/app/api/controller/SubjectHomeworkController.php @@ -0,0 +1,19 @@ +publish($request); + return $this->json($result); + } +} \ No newline at end of file diff --git a/app/api/controller/UploadController.php b/app/api/controller/UploadController.php index b2738e7..1aeb554 100644 --- a/app/api/controller/UploadController.php +++ b/app/api/controller/UploadController.php @@ -31,7 +31,7 @@ class UploadController extends BaseController public function uploadFile(Request $request) { $service = new UploadService(); - $res = $service->uploadImg($request->file('image')); + $res = $service->uploadFile($request->file('file')); return $this->json($res); } diff --git a/app/common/model/StudentHomework.php b/app/common/model/StudentHomework.php new file mode 100644 index 0000000..8450143 --- /dev/null +++ b/app/common/model/StudentHomework.php @@ -0,0 +1,56 @@ +hasOne(Student::class, 'id', 'student_id')->bind([ + 'student_name', + 'student_account' => 'account' + ]); + } + + public function teacher() + { + return $this->hasOne(Teacher::class, 'id', 'teacher_id')->bind([ + 'teacher_name', + 'teacher_account' => 'account' + ]); + } + + public function subject() + { + return $this->hasOne(Subject::class, 'id', 'subject_id')->bind([ + 'teacher_name', + 'teacher_account' => 'account' + ]); + } + +} diff --git a/app/common/model/SubjectHomework.php b/app/common/model/SubjectHomework.php new file mode 100644 index 0000000..e77c246 --- /dev/null +++ b/app/common/model/SubjectHomework.php @@ -0,0 +1,27 @@ +hasOne(Teacher::class,'id','teacher_id')->bind(['teacher_name','teacher_account'=>"account"]); } + /** + * @desc 教师排课时间 + * @return \think\model\relation\HasMany + */ + public function teacherScheduleTime() + { + return $this->hasMany(TeacherScheduleTime::class,'free_time_id','id'); + } + } diff --git a/app/common/model/TeacherScheduleTime.php b/app/common/model/TeacherScheduleTime.php index f3ba403..839752b 100644 --- a/app/common/model/TeacherScheduleTime.php +++ b/app/common/model/TeacherScheduleTime.php @@ -43,4 +43,14 @@ class TeacherScheduleTime extends BaseModel return $this->hasOne(Subject::class, 'id', 'subject_id'); } + + /** + * @desc 安排学生 + * @return \think\model\relation\HasMany + */ + public function studentSchedule() + { + return $this->hasMany(StudentSchedule::class, 'teacher_schedule_time_id', 'id'); + } + } diff --git a/app/common/service/StudentHomeworkService.php b/app/common/service/StudentHomeworkService.php new file mode 100644 index 0000000..f48c0ea --- /dev/null +++ b/app/common/service/StudentHomeworkService.php @@ -0,0 +1,45 @@ +get(); + $homework = StudentHomework::where(['teacher_schedule_time_id' => $data['teacher_schedule_time_id']])->order('id asc'); + $page = isset($data['page']) ? $data['page'] : 1; + $limit = isset($data['limit']) ? $data['limit'] : 10; + $total = $homework->count(); + + $list = $homework->page($page, $limit)->bind(['student', 'subject'])->select(); + + return [ + 'code' => ResponseCode::SUCCESS, + 'data' => [ + 'list' => $list, + 'total' => $total, + 'page' => $page, + ], + 'msg' => 'success' + ]; + + } catch (Exception $e) { + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + +} \ No newline at end of file diff --git a/app/common/service/SubjectHomeworkService.php b/app/common/service/SubjectHomeworkService.php new file mode 100644 index 0000000..28c06da --- /dev/null +++ b/app/common/service/SubjectHomeworkService.php @@ -0,0 +1,63 @@ +teacher)) { + throw new Exception('请教师登陆后再设置'); + } + $teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty(); + + if ($teacher->isEmpty()) { + throw new Exception('未找到教师信息,设置失败'); + } + $data = $request->post(); + $teacher_schedule_time = TeacherScheduleTime::where(['id'=> $data['teacher_schedule_time_id']])->findOrEmpty(); + + if($teacher_schedule_time->isEmpty()){ + throw new Exception('未找到教师课程安排'); + } + + $subject_homework = SubjectHomework::where(['teacher_id' => $teacher->id, 'teacher_schedule_time_id' => $data['teacher_schedule_time_id'], 'subject_id' => $data['subject_id']])->findOrEmpty(); + + if(!$subject_homework->isEmpty()){ + throw new Exception('家庭作业已存在,请勿重复提交'); + } + + $res = SubjectHomework::create([ + 'teacher_id' => $teacher->id, + 'teacher_schedule_time_id' => $data['teacher_schedule_time_id'], + 'subject_id' => $teacher_schedule_time->subject_id, + 'homework_file_url' => $data['homework_file_url'], + 'homework_file_name' => $data['homework_file_name'], + ]); + + return [ + 'code' => ResponseCode::SUCCESS, + 'msg' => '操作成功' + ]; + } catch (Exception $e) { + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + +} \ No newline at end of file diff --git a/app/common/service/TeacherFreeTimeService.php b/app/common/service/TeacherFreeTimeService.php index 3eb0903..b77d3c7 100644 --- a/app/common/service/TeacherFreeTimeService.php +++ b/app/common/service/TeacherFreeTimeService.php @@ -43,7 +43,7 @@ class TeacherFreeTimeService foreach ($free_time as $free_date => $times) { if ($times) { foreach ($times as $time) { - $time_period = explode('-', $time); + $time_period = explode(' - ', $time); $firstDate = new DateTime($free_date . ' ' . trim($time_period[0])); $secondDate = new DateTime($free_date . ' ' . trim($time_period[1])); $diff = $secondDate->diff($firstDate); diff --git a/app/common/service/TeacherScheduleTimeService.php b/app/common/service/TeacherScheduleTimeService.php index 6018069..8a52aca 100644 --- a/app/common/service/TeacherScheduleTimeService.php +++ b/app/common/service/TeacherScheduleTimeService.php @@ -37,7 +37,7 @@ class TeacherScheduleTimeService foreach ($free_time as $free_date => $times) { if ($times) { foreach ($times as $time) { - $time_period = explode('-', $time); + $time_period = explode( ' - ' , $time); $firstDate = new DateTime($free_date . ' ' . $time_period[0]); $secondDate = new DateTime($free_date . ' ' . $time_period[1]); $diff = $secondDate->diff($firstDate); diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index 8580a01..2cf7d57 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -67,12 +67,13 @@ class UploadService if ($file && $file->isValid()) { $ext = $file->getUploadExtension(); - if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG', 'PBG'])) { - $type = 'images'; + if (in_array($ext, ['pdf', 'doc', 'docx', 'xlsx', 'xls', 'csv', 'pptx', 'ppt', 'zip', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG', 'PBG'])) { + $type = 'files'; } else { $type = 'other'; } $fileSize = $file->getSize(); + $origin_name = $file->getUploadName(); $uploadDir = '/files/' . $type . '/' . date('Ym') . '/'; $filename = date('YmdHis') . rand(999, 99999); @@ -91,12 +92,16 @@ class UploadService if ($res['code'] == ResponseCode::FAIL) { throw new Exception($res['msg']); } + //删除本地图片 unlink($filePath); return [ 'code' => ResponseCode::SUCCESS, 'msg' => '上传成功', - 'data' => $res['data'] + 'data' => [ + 'url' => $res['data'], + 'origin_name' => $origin_name + ] ]; } else { throw new Exception('文件无效'); diff --git a/plugin/admin/app/controller/StudentScheduleController.php b/plugin/admin/app/controller/StudentScheduleController.php index c9ddb80..cccdfa5 100644 --- a/plugin/admin/app/controller/StudentScheduleController.php +++ b/plugin/admin/app/controller/StudentScheduleController.php @@ -258,7 +258,7 @@ class StudentScheduleController extends Crud ->select() ->toArray(); - $free_time = []; + $schedule_time = []; foreach ($list as $item) { $time_period = explode('-', $item['time']); if ($item['subject_id']) { @@ -272,17 +272,17 @@ class StudentScheduleController extends Crud $color = 'red'; $title = $item['time']; } - $free_time[] = [ - 'free_time_id' => $item['id'], + $schedule_time[] = [ + 'schedule_time_id' => $item['id'], 'title' => $title, - 'start' => $item['date'] . ' ' . $time_period[0], + 'start' => $item['date'] . ' ' . trim($time_period[0]), 'color' => $color, ]; } return json([ 'code' => ResponseCode::WEB_API_SUCCESS, - 'data' => $free_time, + 'data' => $schedule_time, 'msg' => 'success' ]); } catch (Exception $e) { @@ -293,4 +293,54 @@ class StudentScheduleController extends Crud } } + + /** + * @desc 设置学生排课 + * @param Request $request + * @return Response + */ + public function studentScheduleTimeSet(Request $request) + { + + $data = $request->get(); + $schedule_time = \app\common\model\StudentSchedule::where(['id'=>$data['schedule_time_id']])->with(['teacher', 'subject', 'student'])->findOrEmpty()->toArray(); + + return view('student/schedule_time_setting', ['schedule_time' => $schedule_time]); + } + + + /** + * @desc 更改学生排课信息 + * @param Request $request + * @return Response + */ + public function changeScheduleData(Request $request) + { + try { + $data = $request->post(); + $teacher_schedule_time = \app\common\model\StudentSchedule::where(['id' => $data['schedule_time_id']])->findOrEmpty(); + if ($teacher_schedule_time->isEmpty()) { + throw new Exception('未找到排课时间'); + } + $changeData = []; + if(isset($data['is_publish'])){ + $teacher_schedule_time->is_publish = $data['is_publish']; + } + + $teacher_schedule_time->save(); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'data' => [], + 'msg' => 'success' + ]); + }catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'data' => [], + 'msg' => 'success' + ]); + } + } + } diff --git a/plugin/admin/app/controller/TeacherFreeTimeController.php b/plugin/admin/app/controller/TeacherFreeTimeController.php index 5b96bfb..53c48c9 100644 --- a/plugin/admin/app/controller/TeacherFreeTimeController.php +++ b/plugin/admin/app/controller/TeacherFreeTimeController.php @@ -6,6 +6,7 @@ use app\common\model\Student; use app\common\model\StudentSchedule; use app\common\model\Subject; use app\common\model\Teacher; +use app\common\model\TeacherScheduleTime; use app\constant\ResponseCode; use support\Request; use support\Response; @@ -187,18 +188,23 @@ class TeacherFreeTimeController extends Crud $end_date = date('Y-m-d 23:59:59', strtotime($request->post('end_date'))); $list = \app\common\model\TeacherFreeTime::where(['teacher_id' => $teacher_id]) ->whereBetweenTime('start_time', $start_date, $end_date) -// ->with(['subject']) + ->with(['teacherScheduleTime']) ->select() ->toArray(); + $free_time = []; foreach ($list as $item) { - $title = $item['time'] . ' - ' . $item['hour'] . '/h'; + $title = $item['time'] . '-' . $item['hour'] . '/h'; + $color = 'red'; + if(isset($item['teacherScheduleTime']) && !empty($item['teacherScheduleTime'])){ + $color = 'green'; + } $free_time[] = [ 'free_time_id' => $item['id'], 'title' => $title, 'start' => date('Y-m-d H:i', strtotime($item['start_time'])), - 'color' => 'green', + 'color' => $color, ]; } @@ -242,10 +248,13 @@ class TeacherFreeTimeController extends Crud $time_period = explode(' - ', $free_time['time']); $limit_time = [ - 'start_time' => date('H:i:s', strtotime($time_period[0])), - 'end_time' => date('H:i:s', strtotime($time_period[1])), + 'start_time' => date('H:i', strtotime($time_period[0])), + 'end_time' => date('H:i', strtotime($time_period[1])), ]; + //获取已排课时间 + $teacher_schedule_time = TeacherScheduleTime::where(['free_time_id' => $free_time_id])->select()->toArray(); + // $student_schedule = StudentSchedule::where(['teacher_schedule_time_id' => $free_time_id])->select()->toArray(); // $student_schedule_id = []; @@ -254,7 +263,8 @@ class TeacherFreeTimeController extends Crud // } return view('teacher/free_time_setting', [ - 'schedule_time' => $free_time, + 'free_time' => $free_time, + 'teacher_schedule_time' => $teacher_schedule_time, 'project' => $project, 'student' => $student, 'limit_time' => $limit_time, diff --git a/plugin/admin/app/controller/TeacherScheduleTimeController.php b/plugin/admin/app/controller/TeacherScheduleTimeController.php index 250b691..14ba804 100644 --- a/plugin/admin/app/controller/TeacherScheduleTimeController.php +++ b/plugin/admin/app/controller/TeacherScheduleTimeController.php @@ -107,6 +107,12 @@ class TeacherScheduleTimeController extends Crud } + /** + * @desc 添加教师排课时间 + * @param Request $request + * @return Response + * @throws \Exception + */ public function addTeacherScheduleTime(Request $request) { try { @@ -138,7 +144,7 @@ class TeacherScheduleTimeController extends Crud $h = $diff->h; $m = round($diff->i / 60, 2); $hour = round($h + $m, 2); - $time = $time_period[0] . ' - ' . $time_period[1]; + $time = trim($time_period[0]) . ' - ' . trim($time_period[1]); \app\common\model\TeacherScheduleTime::create([ 'teacher_id' => $free_time->teacher_id, @@ -176,12 +182,14 @@ class TeacherScheduleTimeController extends Crud return parent::update($request); } $teacher = []; - + $init_date = ''; if ($request->get('id')) { - $teacher_free_time = \app\common\model\TeacherScheduleTime::where(['id' => $request->get('id')])->findOrEmpty(); - $teacher = Teacher::where(['id' => $teacher_free_time->teacher_id])->field('id,teacher_name,account')->findOrEmpty()->toArray(); + $teacher_schedule_time = \app\common\model\TeacherScheduleTime::where(['id' => $request->get('id')])->findOrEmpty(); + $init_date = $teacher_schedule_time->date; + $teacher = Teacher::where(['id' => $teacher_schedule_time->teacher_id])->field('id,teacher_name,account')->findOrEmpty()->toArray(); } - return view('teacher-schedule-time/update', ['teacher' => $teacher]); + + return view('teacher-schedule-time/update', ['teacher' => $teacher, 'init_date' => $init_date]); } @@ -198,11 +206,12 @@ class TeacherScheduleTimeController extends Crud $end_date = date('Y-m-d 23:59:59', strtotime($request->post('end_date'))); $list = \app\common\model\TeacherScheduleTime::where(['teacher_id' => $teacher_id]) ->whereBetweenTime('start_time', $start_date, $end_date) - ->with(['subject']) + ->with(['subject', 'studentSchedule']) ->select() ->toArray(); - $free_time = []; + + $schedule_time = []; foreach ($list as $item) { $time_period = explode('-', $item['time']); if ($item['subject_id']) { @@ -216,17 +225,92 @@ class TeacherScheduleTimeController extends Crud $color = 'red'; $title = $item['time']; } - $free_time[] = [ - 'free_time_id' => $item['id'], + $schedule_time[] = [ + 'schedule_time_id' => $item['id'], 'title' => $title, - 'start' => $item['date'] . ' ' . $time_period[0], + 'start' => $item['date'] . ' ' . trim($time_period[0]), 'color' => $color, ]; } return json([ 'code' => ResponseCode::WEB_API_SUCCESS, - 'data' => $free_time, + 'data' => $schedule_time, + 'msg' => 'success' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + + + /** + * 更新 + * @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); + } + $schedule_time_id = $request->get('schedule_time_id'); + $schedule_time = \app\common\model\TeacherScheduleTime::where(['id' => $schedule_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' => $schedule_time_id])->select()->toArray(); + $student_schedule_id = []; + if ($student_schedule) { + $student_schedule_id = array_column($student_schedule, 'student_id'); + } + + return view('teacher-schedule-time/schedule_time_setting', [ + 'schedule_time' => $schedule_time, + 'project' => $project, + 'student' => $student, + 'student_schedule_id' => $student_schedule_id + ]); + } + + + /** + * @desc 更改教师排课数据 + * @param Request $request + * @return Response + */ + public function changeScheduleData(Request $request) + { + try { + $data = $request->post(); + $teacher_schedule_time = \app\common\model\TeacherScheduleTime::where(['id' => $data['teacher_schedule_time_id']])->findOrEmpty(); + if ($teacher_schedule_time->isEmpty()) { + throw new Exception('未找到教师排课时间'); + } + $changeData = []; + if(isset($data['subject_id'])){ + $teacher_schedule_time->subject_id = $data['subject_id']; + } + if(isset($data['is_publish'])){ + $teacher_schedule_time->is_publish = $data['is_publish']; + } + + $teacher_schedule_time->save(); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'data' => [], 'msg' => 'success' ]); } catch (Exception $e) { diff --git a/plugin/admin/app/view/student/check_schedule.html b/plugin/admin/app/view/student/check_schedule.html index 0f4f3b1..fa57811 100644 --- a/plugin/admin/app/view/student/check_schedule.html +++ b/plugin/admin/app/view/student/check_schedule.html @@ -18,18 +18,12 @@ @@ -130,8 +124,8 @@ remove(obj); } else if (obj.event === "edit") { edit(obj); - }else if (obj.event === "check_schedule") { - check_schedule(obj); + }else if (obj.event === "student_schedule") { + student_schedule(obj); } else if (obj.event === "rest_password") { rest_password(obj); } @@ -213,7 +207,7 @@ }); } // 老师课程安排 - let check_schedule = function(obj) { + let student_schedule = function(obj) { console.log(21312,obj); let student_id = obj.data['student_id']; let month = obj.data['month']; diff --git a/plugin/admin/app/view/student/schedule_time_setting.html b/plugin/admin/app/view/student/schedule_time_setting.html new file mode 100644 index 0000000..2eebcfb --- /dev/null +++ b/plugin/admin/app/view/student/schedule_time_setting.html @@ -0,0 +1,226 @@ + + +
+ +