From 7915a89a3485a9763abfae145f5cb7294665aa9c Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Tue, 10 Jun 2025 15:33:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E8=AF=BE=E6=97=B6=E6=B6=88=E8=B4=B9=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 getStudentCourseUsageList 接口,用于获取学生课时消费记录列表- 在 PersonCourseSchedule 控制器中添加对应的处理方法 - 在 route 中配置新的路由 - 在 StudentCourseUsage 模型中添加与学员课程表的关联关系- 在 PersonCourseScheduleService 服务中实现获取学生课时消费记录的逻辑 --- .../apiController/PersonCourseSchedule.php | 16 ++++++ niucloud/app/api/route/route.php | 2 + .../StudentCourseUsage.php | 10 +++- .../PersonCourseScheduleService.php | 49 +++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/niucloud/app/api/controller/apiController/PersonCourseSchedule.php b/niucloud/app/api/controller/apiController/PersonCourseSchedule.php index e593fe17..6b5cae24 100644 --- a/niucloud/app/api/controller/apiController/PersonCourseSchedule.php +++ b/niucloud/app/api/controller/apiController/PersonCourseSchedule.php @@ -139,4 +139,20 @@ class PersonCourseSchedule extends BaseApiService } return success($res['data']); } + + //获取学生课时消费记录列表 + public function getStudentCourseUsageList(Request $request){ + $resources_id = $request->param('resources_id', '');//客户资源ID + if (empty($resources_id)) { + return fail('缺少参数'); + } + $where = [ + 'resources_id'=>$resources_id, + ]; + $res = (new PersonCourseScheduleService())->getStudentCourseUsageList($where); + if(!$res['code']){ + return fail($res['msg']); + } + return success($res['data']); + } } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 20b6179b..9bd2d779 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -371,6 +371,8 @@ Route::group(function () { Route::get('xy/personCourseSchedule/getVenueListAll', 'apiController.PersonCourseSchedule/getVenueListAll'); //学生端-学生课程安排-我的教练列表 Route::get('xy/personCourseSchedule/getMyCoach', 'apiController.PersonCourseSchedule/getMyCoach'); + //学生端-学生课程安排-学员课时消费记录 + Route::get('xy/personCourseSchedule/getStudentCourseUsageList', 'apiController.PersonCourseSchedule/getStudentCourseUsageList'); diff --git a/niucloud/app/model/student_course_usage/StudentCourseUsage.php b/niucloud/app/model/student_course_usage/StudentCourseUsage.php index 95278a65..f18c1cf0 100644 --- a/niucloud/app/model/student_course_usage/StudentCourseUsage.php +++ b/niucloud/app/model/student_course_usage/StudentCourseUsage.php @@ -11,6 +11,7 @@ namespace app\model\student_course_usage; +use app\model\student_courses\StudentCourses; use core\base\BaseModel; use think\model\concern\SoftDelete; use think\model\relation\HasMany; @@ -89,9 +90,14 @@ class StudentCourseUsage extends BaseModel $query->where("usage_date", $value); } } - - + /** + * 关联到学员课程表(多对一) + */ + public function studentCourseHasOne() + { + return $this->hasOne(StudentCourses::class, 'id', 'student_course_id'); + } diff --git a/niucloud/app/service/api/apiService/PersonCourseScheduleService.php b/niucloud/app/service/api/apiService/PersonCourseScheduleService.php index 3a553dd3..c65da781 100644 --- a/niucloud/app/service/api/apiService/PersonCourseScheduleService.php +++ b/niucloud/app/service/api/apiService/PersonCourseScheduleService.php @@ -15,6 +15,7 @@ use app\model\chat_friends\ChatFriends; use app\model\course_schedule\CourseSchedule; use app\model\person_course_schedule\PersonCourseSchedule; use app\model\personnel\Personnel; +use app\model\student_course_usage\StudentCourseUsage; use app\model\venue\Venue; use core\base\BaseApiService; use think\facade\Db; @@ -303,4 +304,52 @@ class PersonCourseScheduleService extends BaseApiService return $res; } + + //获取学生课时消费记录列表 + public function getStudentCourseUsageList(array $where) + { + $page_params = $this->getPageParam();//获取请求参数中的页码+分页数 + $page = $page_params['page']; + $limit = $page_params['limit']; + + $res = [ + 'code' => 0, + 'msg' => '暂无更多', + 'data' => [] + ]; + + $schedule_id = PersonCourseSchedule::where('resources_id',$where['resources_id']) + ->where('status',1) + ->distinct(true) + ->column('schedule_id'); + + if(!$schedule_id){ + return $res; + } + + $data = StudentCourseUsage::whereIn('student_course_id',$schedule_id) + ->order('usage_date', 'desc') + ->with([ + 'studentCourseHasOne' => function ($query) { + $query->append(['course']); + } + ]) + ->paginate([ + 'list_rows' => $limit, + 'page' => $page, + ]) + ->toArray(); + + if(!count($data['data'])){ + return $res; + } + + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => $data + ]; + + return $res; + } }