From 30acbd887b80a8a2a40224c0a6fae6736e7981ac Mon Sep 17 00:00:00 2001 From: Dai Date: Sat, 27 Jul 2024 15:14:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E8=AF=BE=E7=A8=8B=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/StudentHomework.php | 4 +- app/common/service/StudentHomeworkService.php | 15 +- app/common/service/SubjectHomeworkService.php | 1 + .../controller/StudentHomeworkController.php | 192 +++++++++ plugin/admin/app/model/StudentHomework.php | 45 ++ .../app/view/student-homework/index.html | 386 ++++++++++++++++++ .../app/view/student-homework/insert.html | 144 +++++++ .../app/view/student-homework/update.html | 260 ++++++++++++ 8 files changed, 1042 insertions(+), 5 deletions(-) create mode 100644 plugin/admin/app/controller/StudentHomeworkController.php create mode 100644 plugin/admin/app/model/StudentHomework.php create mode 100644 plugin/admin/app/view/student-homework/index.html create mode 100644 plugin/admin/app/view/student-homework/insert.html create mode 100644 plugin/admin/app/view/student-homework/update.html diff --git a/app/common/model/StudentHomework.php b/app/common/model/StudentHomework.php index 8450143..6191dd4 100644 --- a/app/common/model/StudentHomework.php +++ b/app/common/model/StudentHomework.php @@ -48,8 +48,8 @@ class StudentHomework extends BaseModel public function subject() { return $this->hasOne(Subject::class, 'id', 'subject_id')->bind([ - 'teacher_name', - 'teacher_account' => 'account' + 'subject_name', + 'english_name' ]); } diff --git a/app/common/service/StudentHomeworkService.php b/app/common/service/StudentHomeworkService.php index 7b5d392..83bb63d 100644 --- a/app/common/service/StudentHomeworkService.php +++ b/app/common/service/StudentHomeworkService.php @@ -39,8 +39,6 @@ class StudentHomeworkService $data = $request->post(); -// $teacher_schedule_time = TeacherScheduleTime::where(['id' => $data['subject_homework_id']])->findOrEmpty(); - $subject_homework = SubjectHomework::where(['teacher_schedule_time_id' => $data['subject_homework_id'], 'is_publish' => 1])->findOrEmpty(); if ($subject_homework->isEmpty()) { @@ -53,12 +51,23 @@ class StudentHomeworkService } } - StudentHomework::create([ + $homework = StudentHomework::where(['student_id' => $student->id, 'subject_homework_id'=> $subject_homework->id])->findOrEmpty(); + if($homework->isEmpty()){ + $homework = new StudentHomework(); + } + + $homework->save([ 'student_id' => $student->id, 'subject_homework_id' => $subject_homework->id, 'teacher_id' => $subject_homework->teacher_id, 'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id, 'subject_id' => $subject_homework->subject_id, + 'date'=> $subject_homework->date, + 'time'=> $subject_homework->time, + 'hour'=> $subject_homework->hour, + 'start_time'=> $subject_homework->start_time, + 'end_time'=> $subject_homework->end_time, + 'month'=> $subject_homework->month, 'feedback_file_url' => $feedback_file_url, ]); diff --git a/app/common/service/SubjectHomeworkService.php b/app/common/service/SubjectHomeworkService.php index ee44242..88cd21a 100644 --- a/app/common/service/SubjectHomeworkService.php +++ b/app/common/service/SubjectHomeworkService.php @@ -79,6 +79,7 @@ class SubjectHomeworkService 'teacher_schedule_time_id' => $data['teacher_schedule_time_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, diff --git a/plugin/admin/app/controller/StudentHomeworkController.php b/plugin/admin/app/controller/StudentHomeworkController.php new file mode 100644 index 0000000..3e6dfc9 --- /dev/null +++ b/plugin/admin/app/controller/StudentHomeworkController.php @@ -0,0 +1,192 @@ +model = new StudentHomework; + } + + /** + * 浏览 + * @return Response + */ + public function index(): Response + { + //获取所有老师 + $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-homework/index', [ + 'teacher' => $teacher, + 'subject' => $subject, + 'student' => $student, + ]); + } + + + public function select(Request $request): Response + { + try { + $homework = \app\common\model\StudentHomework::order('id desc'); + $data = $request->get(); + if (isset($data['student_id']) && !empty($data['student_id'])) { + $homework->where('student_id', $data['student_id']); + } + if (isset($data['teacher_id']) && !empty($data['teacher_id'])) { + $homework->where('teacher_id', $data['teacher_id']); + } + if (isset($data['teacher_id']) && !empty($data['teacher_id'])) { + $homework->where('teacher_id', $data['teacher_id']); + } + if (isset($data['is_publish']) && $data['is_publish'] !== '') { + $homework->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 = $homework->count(); + $list = $homework->with(['student', 'subject', 'teacher'])->page($page, $limit)->select()->toArray(); + + foreach ($list as &$item) { + if ($item['feedback_file_url']) { + $item['feedback_file_url'] = json_decode($item['feedback_file_url'], true); + } + if ($item['feedback_version_file_url']) { + $item['feedback_version_file_url'] = json_decode($item['feedback_version_file_url'], true); + } + } + + 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() + ]); + } + } + + /** + * 插入 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function insert(Request $request): Response + { + if ($request->method() === 'POST') { + return parent::insert($request); + } + return view('student-homework/insert'); + } + + /** + * 更新 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function update(Request $request): Response + { + if ($request->method() === 'POST') { + $data = $request->post(); + $feedback_file_url = []; + if (isset($data['feedback_file_url'])) { + foreach ($data['feedback_file_url'] as $key => $value) { + $feedback_file_url[] = [ + 'url' => $value, + 'name' => $data['feedback_file_url_name'][$key] + ]; + } + } + $feedback_version_file_url = []; + if (isset($data['feedback_version_file_url'])) { + foreach ($data['feedback_version_file_url'] as $key => $value) { + $feedback_version_file_url[] = [ + 'url' => $value, + 'name' => $data['feedback_version_file_url_name'][$key] + ]; + } + } + + + $homework = \app\common\model\StudentHomework::where(['id'=>$data['id']])->findOrEmpty(); + $homework->save([ + 'is_publish' => $data['is_publish'], + 'feedback_file_url' => empty($feedback_file_url) ? '' : json_encode($feedback_file_url, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'feedback_version_file_url' => empty($feedback_version_file_url) ? '' : json_encode($feedback_version_file_url, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + ]); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => 'success' + ]); + } + $homework = \app\common\model\StudentHomework::where('id', $request->get('id'))->with(['student', 'subject', 'teacher'])->findOrEmpty()->toArray(); + + if($homework['feedback_file_url']){ + $homework['feedback_file_url'] = json_decode($homework['feedback_file_url'], true); + } + if($homework['feedback_version_file_url']){ + $homework['feedback_version_file_url'] = json_decode($homework['feedback_version_file_url'], true); + } + + return view('student-homework/update', ['homework' => $homework]); + } + + /** + * @desc 更改作业状态 + * @param Request $request + * @return Response + */ + public function changePublishStatus(Request $request) + { + $subject_homework = \app\common\model\StudentHomework::where('id', $request->post('id'))->findOrEmpty(); + $subject_homework->save([ + 'is_publish' => $request->post('is_publish') + ]); + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'msg' => 'success' + ]); + + } + + +} diff --git a/plugin/admin/app/model/StudentHomework.php b/plugin/admin/app/model/StudentHomework.php new file mode 100644 index 0000000..462c5a7 --- /dev/null +++ b/plugin/admin/app/model/StudentHomework.php @@ -0,0 +1,45 @@ + + + + + 浏览页面 + + + + + + +
+
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ + + +
+
+ 展开 + 收起 +
+
+
+
+ + +
+
+
+
+
+ + + + + + + + + + + + + + + diff --git a/plugin/admin/app/view/student-homework/insert.html b/plugin/admin/app/view/student-homework/insert.html new file mode 100644 index 0000000..7d08086 --- /dev/null +++ b/plugin/admin/app/view/student-homework/insert.html @@ -0,0 +1,144 @@ + + + + + 新增页面 + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+ +
+
+ + +
+
+ +
+ + + + + + + + + + diff --git a/plugin/admin/app/view/student-homework/update.html b/plugin/admin/app/view/student-homework/update.html new file mode 100644 index 0000000..805c56e --- /dev/null +++ b/plugin/admin/app/view/student-homework/update.html @@ -0,0 +1,260 @@ + + + + + 更新页面 + + + + + + + +
+ +
+
+ +
+ +
+ + +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+ {if !empty($homework['feedback_file_url'])} + {foreach $homework['feedback_file_url'] as $index => $item} +
+
+ {$item['name']} + + + +
+
+ {/foreach} + {/if} + +
+
+ +
+
+
+ +
+ +
+
+ {if !empty($homework['feedback_version_file_url'])} + {foreach $homework['feedback_version_file_url'] as $index => $item} +
+
+ {$item['name']} + + + +
+
+ {/foreach} + {/if} + +
+
+ +
+
+ + +
+ +
+ +
+ + +
+
+ +
+
+ +
+
+ + +
+
+ +
+ + + + + + + + + + +