2024-07-21 18:13:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
|
|
|
use app\common\model\SubjectHomework;
|
|
|
|
use app\common\model\Teacher;
|
|
|
|
use app\common\model\TeacherScheduleTime;
|
|
|
|
use app\constant\ResponseCode;
|
|
|
|
use think\Exception;
|
|
|
|
|
|
|
|
class SubjectHomeworkService
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @desc 发布课程作业
|
|
|
|
* @param $request
|
|
|
|
* @return array|void
|
|
|
|
*/
|
|
|
|
public function publish($request)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($request->teacher)) {
|
|
|
|
throw new Exception('请教师登陆后再设置');
|
|
|
|
}
|
|
|
|
$teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty();
|
|
|
|
|
|
|
|
if ($teacher->isEmpty()) {
|
|
|
|
throw new Exception('未找到教师信息,设置失败');
|
|
|
|
}
|
|
|
|
$data = $request->post();
|
2024-07-21 19:19:00 +08:00
|
|
|
$teacher_schedule_time = TeacherScheduleTime::where(['id' => $data['teacher_schedule_time_id']])->findOrEmpty();
|
2024-07-21 18:13:26 +08:00
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
if ($teacher_schedule_time->isEmpty()) {
|
2024-07-21 18:13:26 +08:00
|
|
|
throw new Exception('未找到教师课程安排');
|
|
|
|
}
|
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
$subject_homework = SubjectHomework::where([
|
|
|
|
'teacher_id' => $teacher->id,
|
|
|
|
'teacher_schedule_time_id' => $data['teacher_schedule_time_id'],
|
|
|
|
'subject_id' => $teacher_schedule_time->subject_id
|
|
|
|
])->findOrEmpty();
|
2024-07-21 18:13:26 +08:00
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
if (!$subject_homework->isEmpty()) {
|
2024-07-21 18:13:26 +08:00
|
|
|
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()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-21 19:19:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @desc 获取课程的家庭作业
|
|
|
|
* @param $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getSubjectHomework($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();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::SUCCESS,
|
|
|
|
'data' => $subject_homework,
|
|
|
|
'msg' => 'success'
|
|
|
|
];
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return [
|
|
|
|
'code' => ResponseCode::FAIL,
|
|
|
|
'msg' => $e->getMessage()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-21 18:13:26 +08:00
|
|
|
}
|