教师排课添加日期获取

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