request->params([ ["name", ""], ["gender", 0], ["age", 0.00], ["birthday", ""], ["user_id", 0], ["campus_id", 0], ["class_id", 0], ["note", ""], ["status", 1], ["emergency_contact", ""], ["contact_phone", ""], ["member_label", ""], ["consultant_id", ""], ["coach_id", ""], ["trial_class_count", 2] ]); // 表单验证 if (empty($data['name'])) { return fail('学员姓名不能为空'); } if ($data['gender'] == 0) { return fail('请选择学员性别'); } if (empty($data['birthday'])) { return fail('请选择学员出生日期'); } $result = (new StudentService())->add($data); if ($result['code'] === 1) { return success('添加成功', $result['data']); } else { return fail($result['msg']); } } catch (\Exception $e) { return fail('添加学员失败:' . $e->getMessage()); } } /** * 获取学员列表 * @param Request $request * @return \think\Response */ public function list(Request $request) { try { $data = $this->request->params([ ["parent_resource_id", 0], ["user_id", 0], ["campus_id", 0], ["status", 0], ["name", ""], // 学员姓名搜索 ["phone", ""], // 联系电话搜索 ["lessonCount", ""], // 课时数量搜索 ["leaveCount", ""], // 请假次数搜索 ["courseId", 0], // 课程ID搜索 ["classId", 0], // 班级ID搜索 ["type", ""], // 查询类型 ["debug", false] // 调试模式 ]); $result = (new StudentService())->getList($data); if ($result['code'] === 1) { return success('获取成功', $result['data']); } else { return fail($result['msg']); } } catch (\Exception $e) { return fail('获取学员列表失败:' . $e->getMessage()); } } public function edit() { try { $data = $this->request->params([ ["id", ""], ["name", ""], ["gender", 0], ["age", 0.00], ["birthday", ""], ["user_id", 0], ["campus_id", 0], ["class_id", 0], ["note", ""], ["status", 1], ["emergency_contact", ""], ["contact_phone", ""], ["member_label", ""], ["consultant_id", ""], ["coach_id", ""], ["trial_class_count", 2] ]); // 表单验证 if (empty($data['name'])) { return fail('学员姓名不能为空'); } if ($data['gender'] == 0) { return fail('请选择学员性别'); } if (empty($data['birthday'])) { return fail('请选择学员出生日期'); } $result = (new StudentService())->edit($data); if ($result['code'] === 1) { return success('修改成功', $result['data']); } else { return fail($result['msg']); } } catch (\Exception $e) { return fail('添加学员失败:' . $e->getMessage()); } } /** * 获取学员基本信息(员工端) * @param int $id 学员ID * @return \think\Response */ public function info($id) { // 验证参数 if (empty($id) || !is_numeric($id)) { return fail('学员ID无效'); } try { // 直接查询学员基本信息,不需要权限验证 $student = \think\facade\Db::table('school_student') ->where('id', $id) ->where('deleted_at', 0) ->find(); if (!$student) { return fail('学员信息不存在'); } // 返回学员基本信息 $studentInfo = [ 'id' => $student['id'], 'name' => $student['name'], 'gender' => $student['gender'], 'gender_text' => $student['gender'] == 1 ? '男' : '女', 'birthday' => $student['birthday'], 'campus_id' => $student['campus_id'] ?? null, 'headimg' => $student['headimg'] ? get_image_url($student['headimg']) : '', 'emergency_contact' => $student['emergency_contact'], 'contact_phone' => $student['contact_phone'] ]; return success($studentInfo, '获取学员信息成功'); } catch (\Exception $e) { return fail('获取学员信息失败:' . $e->getMessage()); } } }