course/app/common/service/StudentScheduleService.php
2024-08-07 10:51:00 +08:00

63 lines
1.9 KiB
PHP

<?php
namespace app\common\service;
use app\common\model\Student;
use app\common\model\StudentParent;
use app\common\model\StudentSchedule;
use app\constant\ResponseCode;
use think\Exception;
class StudentScheduleService
{
/**
* @desc 获取课表
* @param $request
* @return array|void
*/
public function getScheduleTime($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->get();
$schedule_time = StudentSchedule::where(['student_id' => $student->id, 'is_publish' => 1]);
if (isset($data['month']) && $data['month']) {
$schedule_time->where('month', $data['month']);
}
if (isset($data['date']) && $data['date']) {
$schedule_time->where('date', $data['date']);
}
$list = $schedule_time->with(['teacher', 'subject'])->select()->toArray();
return [
'code' => ResponseCode::SUCCESS,
'data' => $list,
'msg' => 'success'
];
} catch (Exception $e) {
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
}