diff --git a/app/api/controller/TeacherFreeTimeController.php b/app/api/controller/TeacherFreeTimeController.php index 3df52fb..b81b1b5 100644 --- a/app/api/controller/TeacherFreeTimeController.php +++ b/app/api/controller/TeacherFreeTimeController.php @@ -33,6 +33,18 @@ class TeacherFreeTimeController extends BaseController return $this->json($res); } + /** + * @desc 获取教师一个月的空闲时间 + * @param Request $request + * @return \support\Response + */ + public function getTeacherFreeTimeOfMonth(Request $request) + { + $service = new TeacherFreeTimeService(); + $res = $service->getTeacherFreeTimeOfMonth($request); + return $this->json($res); + } + public function updateFreeTime(Request $request) { $service = new TeacherFreeTimeService(); diff --git a/app/common/service/TeacherFreeTimeService.php b/app/common/service/TeacherFreeTimeService.php index 23fa31b..a934d8a 100644 --- a/app/common/service/TeacherFreeTimeService.php +++ b/app/common/service/TeacherFreeTimeService.php @@ -21,7 +21,7 @@ class TeacherFreeTimeService public function addFreeTime($request) { try { - if (empty($request->teacher)) { + if (empty((array)$request->teacher)) { throw new Exception('请教师登陆后再设置'); } $teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty(); @@ -168,6 +168,32 @@ class TeacherFreeTimeService } } + /** + * @desc 获取教师一个月的空闲时间 + * @param $request + * @return array + */ + public function getTeacherFreeTimeOfMonth($request) + { + try { + if (empty((array)$request->teacher)) { + throw new Exception('请教师登陆后再设置'); + } + + $free_time = TeacherFreeTime::where(['month' => $request->get('month'), 'teacher_id' => $request->teacher->id])->select(); + + return [ + 'code' => ResponseCode::SUCCESS, + 'data' => $free_time, + ]; + }catch (Exception $e){ + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + public function updateFreeTime($request) { try {