course/app/common/service/StudentScheduleService.php

71 lines
2.1 KiB
PHP
Raw Normal View History

2024-07-21 18:40:09 +08:00
<?php
namespace app\common\service;
use app\common\model\Student;
2024-07-27 10:35:57 +08:00
use app\common\model\StudentParent;
2024-07-21 18:40:09 +08:00
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 {
2024-07-27 10:35:57 +08:00
if (empty((array)$request->student) && empty((array)$request->parent)) {
2024-07-21 18:40:09 +08:00
throw new Exception('请登陆后再查看');
}
2024-08-07 10:51:00 +08:00
if (!empty((array)$request->student)) {
2024-07-27 10:35:57 +08:00
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
if ($student->isEmpty()) {
throw new Exception('未找到用户信息');
}
}
2024-08-07 10:51:00 +08:00
if (!empty((array)$request->parent)) {
2024-07-27 10:35:57 +08:00
$student = Student::where(['parent_id' => $request->parent->id])->findOrEmpty();
if ($student->isEmpty()) {
throw new Exception('未找到用户信息');
}
2024-07-21 18:40:09 +08:00
}
$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']);
}
//添加课程作业信息
2025-01-15 21:23:29 +08:00
$list = $schedule_time->with(['teacher', 'subject', 'subjectHomeworkArr'])
->fetchSql(true)
->select();
// ->toArray();
print '<pre>';
print_r($list);
die;
2024-07-21 18:40:09 +08:00
return [
'code' => ResponseCode::SUCCESS,
'data' => $list,
'msg' => 'success'
];
} catch (Exception $e) {
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
}