getStudentList(); return success($result, '获取学员列表成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 测试方法 - 直接获取用户64的学员数据 * @return Response */ public function testStudentList() { try { // 直接查询数据库获取用户64的学员数据 $studentList = \think\facade\Db::table('school_student') ->where('user_id', 64) ->where('deleted_at', 0) ->field('id,name,gender,birthday,headimg,create_time') ->order('create_time desc') ->select() ->toArray(); // 计算年龄和格式化数据 foreach ($studentList as &$student) { $age = 0; if ($student['birthday']) { $birthTime = strtotime($student['birthday']); if ($birthTime) { $age = date('Y') - date('Y', $birthTime); if (date('md') < date('md', $birthTime)) { $age--; } } } $student['age'] = max(0, $age); $student['gender_text'] = $student['gender'] == 1 ? '男' : '女'; $student['headimg'] = $student['headimg'] ? get_image_url($student['headimg']) : ''; } return success([ 'list' => $studentList, 'total' => count($studentList) ], '获取学员列表成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取学员概览信息(用于首页落地页) * @return Response */ public function getStudentSummary() { $data = $this->request->params([ ['student_id', 0] ]); $this->validate($data, [ 'student_id' => 'require|integer|gt:0' ]); try { $service = new StudentService(); $result = $service->getStudentSummary($data['student_id']); return success($result, '获取学员概览成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取学员详细信息(包含体测信息) * @return Response */ public function getStudentInfo() { $data = $this->request->params([ ['student_id', 0] ]); $this->validate($data, [ 'student_id' => 'require|integer|gt:0' ]); try { $service = new StudentService(); $result = $service->getStudentInfoWithPhysicalTest($data['student_id']); return success($result, '获取学员信息成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 更新学员基本信息 * @return Response */ public function updateStudentInfo() { $data = $this->request->params([ ['student_id', 0], ['name', ''], ['gender', ''], ['birthday', ''], ['headimg', ''], ['emergency_contact', ''], ['contact_phone', ''], ['note', ''] ]); $this->validate($data, [ 'student_id' => 'require|integer|gt:0', 'name' => 'require|length:2,20', 'gender' => 'in:1,2', 'birthday' => 'date', 'contact_phone' => 'mobile' ]); try { $service = new StudentService(); $result = $service->updateStudentInfo($data); return success($result, '更新学员信息成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 上传学员头像 * @return Response */ public function uploadAvatar() { $data = $this->request->params([ ['student_id', 0] ]); $this->validate($data, [ 'student_id' => 'require|integer|gt:0' ]); try { $service = new StudentService(); $result = $service->uploadAvatar($data['student_id']); return success($result, '头像上传成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 新增孩子信息 * @return Response */ public function addChild() { $data = $this->request->params([ ['name', ''], ['gender', '1'], ['birthday', ''], ['headimg', ''], ['emergency_contact', ''], ['contact_phone', ''], ['note', ''] ]); $this->validate($data, [ 'name' => 'require|length:2,20', 'gender' => 'require|in:1,2', 'birthday' => 'require|date', 'contact_phone' => 'mobile', 'emergency_contact' => 'max:20' ]); try { $service = new StudentService(); $result = $service->addChild($data); return success($result, '添加孩子成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取学员课程安排列表 * @return Response */ public function getCourseScheduleList($student_id) { $data = $this->request->params([ ['date', ''], ['status', ''], ['start_date', ''], ['end_date', ''] ]); $data['student_id'] = $student_id; try { $service = new StudentService(); $result = $service->getCourseScheduleList($data); return success($result, '获取课程安排成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取课程安排详情 * @return Response */ public function getCourseScheduleDetail() { $data = $this->request->params([ ['schedule_id', 0] ]); $this->validate($data, [ 'schedule_id' => 'require|integer|gt:0' ]); try { $service = new StudentService(); $result = $service->getCourseScheduleDetail($data['schedule_id']); return success($result, '获取课程详情成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 申请课程请假 * @return Response */ public function requestCourseLeave() { $data = $this->request->params([ ['schedule_id', 0], ['reason', ''] ]); $this->validate($data, [ 'schedule_id' => 'require|integer|gt:0', 'reason' => 'max:255' ]); try { $service = new StudentService(); $result = $service->requestCourseLeave($data); return success($result, '请假申请成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取学员标签列表 * @param Request $request */ public function getStudentTagList(Request $request) { try { $service = new StudentService(); $result = $service->getStudentTagList(); return success($result); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取学员课程统计 * @param int $student_id * @return Response */ public function getCourseStatistics($student_id) { $data = $this->request->params([ ['start_date', ''], ['end_date', ''] ]); $data['student_id'] = $student_id; try { $service = new StudentService(); $result = $service->getCourseStatistics($data); return success($result, '获取课程统计成功'); } catch (\Exception $e) { return fail($e->getMessage()); } } public function is_pass(Request $request){ //获取员工信息 $old_password = $request->param('password',''); if(empty($old_password)){ return fail('请输入旧密码'); } $res = (new StudentService())->checkMemberOldPwd($old_password); if(!$res['code']){ return fail('旧密码不正确'); } return success($res['data']); } public function set_pass(Request $request){ $new_password = $request->param('old_password',''); $password = $request->param('password',''); if($new_password != $password){ return fail('二次密码输入不正确'); } $res = (new StudentService())->updatePassword($new_password); if(!$res['code']){ return fail('旧密码不正确'); } return success($res['data']); } }