2024-07-21 18:13:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
use app\common\model\Student;
|
2024-07-21 18:13:26 +08:00
|
|
|
use app\common\model\StudentHomework;
|
2024-07-21 19:19:00 +08:00
|
|
|
use app\common\model\SubjectHomework;
|
|
|
|
use app\common\model\TeacherScheduleTime;
|
|
|
|
use app\constant\ResponseCode;
|
2024-07-21 18:13:26 +08:00
|
|
|
use think\Exception;
|
|
|
|
|
|
|
|
class StudentHomeworkService
|
|
|
|
{
|
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
/**
|
|
|
|
* @desc 添加学生家庭作业
|
|
|
|
* @param $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function addStudentHomework($request)
|
|
|
|
{
|
|
|
|
try {
|
2024-07-27 10:35:57 +08:00
|
|
|
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
2024-07-21 19:19:00 +08:00
|
|
|
throw new Exception('请登陆后再查看');
|
|
|
|
}
|
2024-07-27 10:35:57 +08:00
|
|
|
if (!empty((array)$request->student)) {
|
|
|
|
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
|
|
|
if ($student->isEmpty()) {
|
|
|
|
throw new Exception('未找到用户信息');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty((array)$request->parent)) {
|
|
|
|
$student = Student::where(['parent_id' => $request->parent->id])->findOrEmpty();
|
|
|
|
if ($student->isEmpty()) {
|
|
|
|
throw new Exception('未找到用户信息');
|
|
|
|
}
|
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$data = $request->post();
|
|
|
|
|
2024-07-27 10:35:57 +08:00
|
|
|
$subject_homework = SubjectHomework::where(['teacher_schedule_time_id' => $data['subject_homework_id'], 'is_publish' => 1])->findOrEmpty();
|
2024-07-26 23:37:31 +08:00
|
|
|
if ($subject_homework->isEmpty()) {
|
2024-07-27 10:35:57 +08:00
|
|
|
throw new Exception('老师还未布置课程作业');
|
|
|
|
}
|
|
|
|
$feedback_file_url = '';
|
2024-08-08 15:08:08 +08:00
|
|
|
if (isset($data['feedback_file_url'])) {
|
|
|
|
if (!empty(json_decode($data['feedback_file_url'], true))) {
|
2024-07-27 10:35:57 +08:00
|
|
|
$feedback_file_url = $data['feedback_file_url'];
|
|
|
|
}
|
2024-07-21 19:19:00 +08:00
|
|
|
}
|
|
|
|
|
2024-08-08 15:08:08 +08:00
|
|
|
$homework = StudentHomework::where(['student_id' => $student->id, 'subject_homework_id' => $subject_homework->id])->findOrEmpty();
|
|
|
|
if ($homework->isEmpty()) {
|
2024-07-27 15:14:38 +08:00
|
|
|
$homework = new StudentHomework();
|
|
|
|
}
|
|
|
|
|
|
|
|
$homework->save([
|
2024-07-21 19:19:00 +08:00
|
|
|
'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,
|
2024-08-08 15:08:08 +08:00
|
|
|
'date' => $subject_homework->date,
|
|
|
|
'time' => $subject_homework->time,
|
|
|
|
'en_time' => $subject_homework->en_time,
|
|
|
|
'hour' => $subject_homework->hour,
|
|
|
|
'start_time' => $subject_homework->start_time,
|
|
|
|
'end_time' => $subject_homework->end_time,
|
|
|
|
'en_start_time' => $subject_homework->start_time,
|
|
|
|
'en_end_time' => $subject_homework->end_time,
|
|
|
|
'month' => $subject_homework->month,
|
2024-07-27 10:35:57 +08:00
|
|
|
'feedback_file_url' => $feedback_file_url,
|
2024-07-21 19:19:00 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::SUCCESS,
|
|
|
|
'msg' => '操作成功'
|
|
|
|
];
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::FAIL,
|
|
|
|
'msg' => $e->getMessage()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-21 18:13:26 +08:00
|
|
|
/**
|
|
|
|
* @desc 获取学生的课程作业
|
|
|
|
* @param $request
|
|
|
|
* @return array|void
|
|
|
|
*/
|
2024-07-21 19:19:00 +08:00
|
|
|
public function getStudentSubjectHomework($request)
|
2024-07-21 18:13:26 +08:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$data = $request->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()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-08 15:08:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @desc 获取学生作业
|
|
|
|
* @param $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getStudentHomework($request)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
|
|
|
throw new Exception('请登陆后再查看');
|
|
|
|
}
|
|
|
|
if (!empty((array)$request->student)) {
|
|
|
|
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
|
|
|
if ($student->isEmpty()) {
|
|
|
|
throw new Exception('未找到用户信息');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty((array)$request->parent)) {
|
|
|
|
$student = Student::where(['parent_id' => $request->parent->id])->findOrEmpty();
|
|
|
|
if ($student->isEmpty()) {
|
|
|
|
throw new Exception('未找到用户信息');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data = $request->all();
|
|
|
|
|
|
|
|
$page = isset($data['page']) ? $data['page'] : 1;
|
|
|
|
$limit = isset($data['limit']) ? $data['limit'] : 10;
|
2024-08-15 16:42:48 +08:00
|
|
|
|
|
|
|
$student_homework = StudentHomework::where(['student_id' => $student->id])->order('start_time desc');
|
2024-08-08 15:08:08 +08:00
|
|
|
if ($data['status']) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$total = $student_homework->count();
|
|
|
|
$list = $student_homework->with(['student', 'subject', 'teacher'])
|
|
|
|
->page($page, $limit)
|
2024-08-15 16:42:48 +08:00
|
|
|
->select()->toArray();
|
2024-08-08 15:08:08 +08:00
|
|
|
}
|
|
|
|
|
2024-08-15 16:44:11 +08:00
|
|
|
foreach ($list as &$item){
|
2024-08-15 16:42:48 +08:00
|
|
|
if($item['feedback_file_url']){
|
|
|
|
$item['feedback_file_url'] = json_decode($item['feedback_file_url'],true);
|
|
|
|
}else{
|
|
|
|
$item['feedback_file_url'] = [];
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 15:08:08 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::SUCCESS,
|
|
|
|
'data' => [
|
|
|
|
'list' => $list,
|
|
|
|
'total' => $total,
|
|
|
|
],
|
|
|
|
'msg' => 'success',
|
|
|
|
];
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::FAIL,
|
|
|
|
'msg' => $e->getMessage()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @desc 获取课程的家庭作业
|
|
|
|
* @param $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function checkSubjectHomework($request)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
|
|
|
|
$data = $request->get();
|
|
|
|
$subject_homework = SubjectHomework::where(['teacher_schedule_time_id' => $data['teacher_schedule_time_id'], 'is_publish' => 1])
|
|
|
|
->with(['teacher', 'subject'])
|
|
|
|
->findOrEmpty();
|
|
|
|
|
|
|
|
if ($subject_homework->isEmpty()) {
|
|
|
|
throw new Exception('课程作业未布置');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subject_homework->homework_file_url) {
|
|
|
|
$subject_homework->homework_file_url = json_decode($subject_homework->homework_file_url, true);
|
|
|
|
} else {
|
|
|
|
$subject_homework->homework_file_url = [];
|
|
|
|
}
|
|
|
|
if ($subject_homework->homework_version_file_url) {
|
|
|
|
$subject_homework->homework_version_file_url = json_decode($subject_homework->homework_version_file_url, true);
|
|
|
|
} else {
|
|
|
|
$subject_homework->homework_version_file_url = [];
|
|
|
|
}
|
|
|
|
if ($subject_homework->last_homework_feedback_url) {
|
|
|
|
$subject_homework->last_homework_feedback_url = json_decode($subject_homework->last_homework_feedback_url, true);
|
|
|
|
} else {
|
|
|
|
$subject_homework->last_homework_feedback_url = [];
|
|
|
|
}
|
|
|
|
if ($subject_homework->subject_report_url) {
|
|
|
|
$subject_homework->subject_report_url = json_decode($subject_homework->subject_report_url, true);
|
|
|
|
} else {
|
|
|
|
$subject_homework->subject_report_url = [];
|
|
|
|
}
|
|
|
|
if ($subject_homework->subject_file_url) {
|
|
|
|
$subject_homework->subject_file_url = json_decode($subject_homework->subject_file_url, true);
|
|
|
|
} else {
|
|
|
|
$subject_homework->subject_file_url = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$student_homework = StudentHomework::where(['teacher_schedule_time_id' => $data['teacher_schedule_time_id'], 'student_id' => $request->student->id])
|
|
|
|
->field('id,student_id,subject_homework_id,teacher_id,teacher_schedule_time_id,feedback_file_url')
|
|
|
|
->findOrEmpty()->toArray();
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($student_homework)) {
|
|
|
|
$student_homework = [
|
|
|
|
'id' => '',
|
|
|
|
'student_id' => $request->student->id,
|
|
|
|
'subject_homework_id' => $subject_homework->id,
|
|
|
|
'teacher_id' => $subject_homework->teacher_id,
|
|
|
|
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
|
|
|
|
'feedback_file_url' => [],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::SUCCESS,
|
|
|
|
'data' => [
|
|
|
|
'subject_homework' => $subject_homework,
|
|
|
|
'student_homework' => $student_homework,
|
|
|
|
],
|
|
|
|
'msg' => 'success'
|
|
|
|
];
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::FAIL,
|
|
|
|
'msg' => $e->getMessage()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|