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.
220 lines
7.3 KiB
220 lines
7.3 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\customer_resources\CustomerResources;
|
|
use app\model\student_courses\StudentCourses;
|
|
use app\model\person_course_schedule\PersonCourseSchedule;
|
|
use app\model\student_course_usage\StudentCourseUsage;
|
|
use app\model\course\Course;
|
|
use app\model\campus\Campus;
|
|
use app\model\venue\Venue;
|
|
use app\model\personnel\Personnel;
|
|
use core\base\BaseApiService;
|
|
use think\facade\Log;
|
|
|
|
/**
|
|
* 学员课程服务类
|
|
* Class StudentCourseService
|
|
* @package app\service\api\apiService
|
|
*/
|
|
class StudentCourseService extends BaseApiService
|
|
{
|
|
/**
|
|
* 获取课程详情
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getCourseDetail(array $where)
|
|
{
|
|
try {
|
|
Log::debug('StudentCourseService::getCourseDetail - 查询条件: ' . json_encode($where));
|
|
|
|
$course_id = $where['course_id'] ?? '';
|
|
$resource_id = $where['resource_id'] ?? '';
|
|
|
|
if (empty($course_id) || empty($resource_id)) {
|
|
return ['code' => 0, 'msg' => '参数不完整'];
|
|
}
|
|
|
|
// 1. 获取学员课程基本信息
|
|
$courseInfo = $this->getCourseInfo($course_id, $resource_id);
|
|
if (!$courseInfo) {
|
|
return ['code' => 0, 'msg' => '课程信息不存在'];
|
|
}
|
|
|
|
// 2. 获取课程安排列表
|
|
$scheduleList = $this->getScheduleList($course_id, $resource_id);
|
|
|
|
// 3. 获取课程使用记录
|
|
$usageList = $this->getUsageList($course_id, $resource_id);
|
|
|
|
$result = [
|
|
'course_info' => $courseInfo,
|
|
'schedule_list' => $scheduleList,
|
|
'usage_list' => $usageList
|
|
];
|
|
|
|
Log::debug('StudentCourseService::getCourseDetail - 返回数据: ' . json_encode($result));
|
|
|
|
return ['code' => 1, 'data' => $result];
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error('StudentCourseService::getCourseDetail - 异常: ' . $e->getMessage());
|
|
return ['code' => 0, 'msg' => '获取课程详情失败: ' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取课程基本信息
|
|
* @param int $course_id
|
|
* @param int $resource_id
|
|
* @return array|null
|
|
*/
|
|
private function getCourseInfo($course_id, $resource_id)
|
|
{
|
|
$studentCourse = new StudentCourses();
|
|
|
|
$info = $studentCourse
|
|
->alias('sc')
|
|
->join(['school_course' => 'c'], 'sc.course_id = c.id', 'left')
|
|
->join(['school_campus' => 'campus'], 'sc.campus_id = campus.id', 'left')
|
|
->join(['school_personnel' => 'coach'], 'sc.main_coach_id = coach.id', 'left')
|
|
->join(['school_personnel' => 'education'], 'sc.education_id = education.id', 'left')
|
|
->where([
|
|
'sc.course_id' => $course_id,
|
|
'sc.resource_id' => $resource_id
|
|
])
|
|
->field([
|
|
'sc.id',
|
|
'sc.course_id',
|
|
'sc.resource_id',
|
|
'sc.total_hours',
|
|
'sc.gift_hours',
|
|
'sc.start_date',
|
|
'sc.end_date',
|
|
'sc.use_total_hours',
|
|
'sc.use_gift_hours',
|
|
'sc.status',
|
|
'sc.single_session_count',
|
|
'c.course_name',
|
|
'campus.campus_name',
|
|
'coach.name as main_coach_name',
|
|
'education.name as education_name'
|
|
])
|
|
->find();
|
|
|
|
return $info ? $info->toArray() : null;
|
|
}
|
|
|
|
/**
|
|
* 获取课程安排列表
|
|
* @param int $course_id
|
|
* @param int $resource_id
|
|
* @return array
|
|
*/
|
|
private function getScheduleList($course_id, $resource_id)
|
|
{
|
|
// 首先获取学员课程ID
|
|
$studentCourseId = $this->getStudentCourseId($course_id, $resource_id);
|
|
if (!$studentCourseId) {
|
|
return [];
|
|
}
|
|
|
|
$personCourseSchedule = new PersonCourseSchedule();
|
|
|
|
$list = $personCourseSchedule
|
|
->alias('pcs')
|
|
->join(['school_course_schedule' => 'cs'], 'pcs.schedule_id = cs.id', 'left')
|
|
->join(['school_venue' => 'v'], 'cs.venue_id = v.id', 'left')
|
|
->join(['school_personnel' => 'coach'], 'cs.coach_id = coach.id', 'left')
|
|
->where([
|
|
'pcs.student_course_id' => $studentCourseId,
|
|
'pcs.resources_id' => $resource_id
|
|
])
|
|
->field([
|
|
'pcs.id',
|
|
'pcs.schedule_id',
|
|
'pcs.course_date',
|
|
'pcs.time_slot',
|
|
'pcs.schedule_type',
|
|
'pcs.course_type',
|
|
'pcs.status',
|
|
'pcs.remark',
|
|
'v.venue_name',
|
|
'coach.name as coach_name'
|
|
])
|
|
->order('pcs.course_date desc, pcs.time_slot desc')
|
|
->select();
|
|
|
|
return $list ? $list->toArray() : [];
|
|
}
|
|
|
|
/**
|
|
* 获取课程使用记录
|
|
* @param int $course_id
|
|
* @param int $resource_id
|
|
* @return array
|
|
*/
|
|
private function getUsageList($course_id, $resource_id)
|
|
{
|
|
// 首先获取学员课程ID
|
|
$studentCourseId = $this->getStudentCourseId($course_id, $resource_id);
|
|
if (!$studentCourseId) {
|
|
return [];
|
|
}
|
|
|
|
$studentCourseUsage = new StudentCourseUsage();
|
|
|
|
$list = $studentCourseUsage
|
|
->alias('scu')
|
|
->join(['school_course_schedule' => 'cs'], 'scu.schedule_id = cs.id', 'left')
|
|
->join(['school_venue' => 'v'], 'cs.venue_id = v.id', 'left')
|
|
->where([
|
|
'scu.student_course_id' => $studentCourseId,
|
|
'scu.resource_id' => $resource_id
|
|
])
|
|
->field([
|
|
'scu.id',
|
|
'scu.usage_date',
|
|
'scu.hours_used',
|
|
'scu.usage_type',
|
|
'scu.remark',
|
|
'cs.time_slot',
|
|
'v.venue_name'
|
|
])
|
|
->order('scu.usage_date desc')
|
|
->select();
|
|
|
|
return $list ? $list->toArray() : [];
|
|
}
|
|
|
|
/**
|
|
* 获取学员课程ID
|
|
* @param int $course_id
|
|
* @param int $resource_id
|
|
* @return int|null
|
|
*/
|
|
private function getStudentCourseId($course_id, $resource_id)
|
|
{
|
|
$studentCourse = new StudentCourses();
|
|
|
|
$info = $studentCourse
|
|
->where([
|
|
'course_id' => $course_id,
|
|
'resource_id' => $resource_id
|
|
])
|
|
->find();
|
|
|
|
return $info ? $info->id : null;
|
|
}
|
|
}
|