You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
8.3 KiB
304 lines
8.3 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\student;
|
|
|
|
use app\service\api\parent\ParentService;
|
|
use app\service\api\student\StudentService;
|
|
use core\base\BaseController;
|
|
use think\Response;
|
|
|
|
/**
|
|
* 学员信息管理控制器
|
|
* 用于学员端访问学员相关信息
|
|
*/
|
|
class StudentController extends BaseController
|
|
{
|
|
/**
|
|
* 获取当前用户的学员列表(支持多孩子)
|
|
* @return Response
|
|
*/
|
|
public function getStudentList()
|
|
{
|
|
try {
|
|
$service = new StudentService();
|
|
$result = $service->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());
|
|
}
|
|
}
|
|
}
|