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; + } }