教师排课添加日期获取

This commit is contained in:
Dai 2024-07-24 14:31:09 +08:00
parent 48c1e511ef
commit 6c7f894636
2 changed files with 14 additions and 7 deletions

View File

@ -37,7 +37,7 @@ class TeacherScheduleTimeService
foreach ($free_time as $free_date => $times) { foreach ($free_time as $free_date => $times) {
if ($times) { if ($times) {
foreach ($times as $time) { foreach ($times as $time) {
$time_period = explode( ' - ' , $time); $time_period = explode(' - ', $time);
$firstDate = new DateTime($free_date . ' ' . $time_period[0]); $firstDate = new DateTime($free_date . ' ' . $time_period[0]);
$secondDate = new DateTime($free_date . ' ' . $time_period[1]); $secondDate = new DateTime($free_date . ' ' . $time_period[1]);
$diff = $secondDate->diff($firstDate); $diff = $secondDate->diff($firstDate);
@ -55,7 +55,7 @@ class TeacherScheduleTimeService
]; ];
//@todo:判断是否已经存在 //@todo:判断是否已经存在
$res = TeacherScheduleTime::create($free_data); $res = TeacherScheduleTime::create($free_data);
if(!$res){ if (!$res) {
throw new Exception('保存失败'); throw new Exception('保存失败');
} }
} }
@ -92,8 +92,15 @@ class TeacherScheduleTimeService
} }
$data = $request->get(); $data = $request->get();
$schedule = TeacherScheduleTime::where(['teacher_id'=>$teacher->id, 'month'=>$data['month']]) $schedule = TeacherScheduleTime::order('id desc')->where(['teacher_id' => $teacher->id]);
->field('id,teacher_id,date,time,hour,month,subject_id,is_publish') if (isset($data['month']) && !empty($data['month'])) {
$schedule->where('month', $data['month']);
}
if (isset($data['date']) && !empty($data['date'])) {
$schedule->where('date', $data['date']);
}
$list = $schedule->field('id,teacher_id,date,time,hour,month,subject_id,is_publish')
->with(['subject']) ->with(['subject'])
->select(); ->select();
@ -106,10 +113,10 @@ class TeacherScheduleTimeService
return [ return [
'code' => ResponseCode::SUCCESS, 'code' => ResponseCode::SUCCESS,
'data'=>$schedule, 'data' => $list,
'msg' => 'success', 'msg' => 'success',
]; ];
}catch (Exception $e){ } catch (Exception $e) {
return [ return [
'code' => ResponseCode::FAIL, 'code' => ResponseCode::FAIL,
'msg' => $e->getMessage() 'msg' => $e->getMessage()