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.
185 lines
6.8 KiB
185 lines
6.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use app\model\person_course_schedule\PersonCourseSchedule;
|
|
use app\model\student_course_usage\StudentCourseUsage;
|
|
use app\model\student\Student;
|
|
use app\model\assignment\Assignment;
|
|
use app\model\course\Course;
|
|
use app\model\student_courses\StudentCourses;
|
|
use core\base\BaseApiService;
|
|
use think\Model;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 员工服务层
|
|
* Class MemberService
|
|
* @package app\service\api\member
|
|
*/
|
|
class CourseService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new Course();
|
|
}
|
|
|
|
//课程列表
|
|
public function list($id,$data)
|
|
{
|
|
$where = [];
|
|
if ($data['schedule_date']) {
|
|
$where[] = ['course_date','=', $data['schedule_date']];
|
|
}
|
|
$CourseSchedule = new CourseSchedule();
|
|
$search_model = $CourseSchedule
|
|
->where('coach_id', $id)
|
|
->where($where)
|
|
->with(['course' => function($query) {
|
|
$query->select();
|
|
},'venue' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
$list = $this->pageQuery($search_model);
|
|
$PersonCourseSchedule = new PersonCourseSchedule();
|
|
foreach ($list['data'] as $k => $v) {
|
|
$student = Db::name('person_course_schedule')
|
|
->alias('pcs')
|
|
->where('pcs.schedule_id', $v['id']) // 建议加上表别名避免冲突
|
|
->join('school_student st', 'pcs.student_id = st.id')
|
|
->join('school_customer_resources cr', 'st.user_id = cr.id')
|
|
->join('school_member sm', 'cr.member_id = sm.member_id')
|
|
->field('st.name, sm.headimg as avatar') // 👈 正确方式取字段
|
|
->select();
|
|
$list['data'][$k]['student'] = $student;
|
|
}
|
|
return $list;
|
|
}
|
|
//获取课程详情
|
|
public function info($data)
|
|
{
|
|
$CourseSchedule = new CourseSchedule();
|
|
$search_model = $CourseSchedule
|
|
->where('id', $data)
|
|
->with(['course' => function($query) {
|
|
$query->select();
|
|
},'venue' => function($query) {
|
|
$query->select();
|
|
},'coach' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
$list = $search_model->find();
|
|
$student = Db::name('person_course_schedule')
|
|
->alias('pcs')
|
|
->where('pcs.schedule_id', $list['id'])
|
|
->join('school_student st', 'pcs.student_id = st.id')
|
|
->join('school_customer_resources cr', 'st.user_id = cr.id')
|
|
->join('school_member sm', 'cr.member_id = sm.member_id')
|
|
->field('st.name, sm.headimg as avatar')
|
|
->select();
|
|
$list['student'] = $student;
|
|
$student_courses = Db::name('student_courses')
|
|
->alias('sc')
|
|
->where('sc.course_id', $list['id'])
|
|
->join('school_student_course_usage sscu', 'sc.id = sscu.student_course_id')
|
|
->field('sc.student_id,sc.end_date')
|
|
->select()->toArray();
|
|
foreach ($student_courses as &$v){
|
|
$student = Db::name('student')
|
|
->alias('st')
|
|
->where('st.id', $v['student_id'])
|
|
->join('school_customer_resources cr', 'st.user_id = cr.id')
|
|
->join('school_member sm', 'cr.member_id = sm.member_id')
|
|
->field('st.name, sm.headimg as avatar')
|
|
->find();
|
|
$v['name'] = $student['name'];
|
|
$v['avatar'] = $student['avatar'];
|
|
}
|
|
$list['student_courses'] = $student_courses;
|
|
|
|
$Assignment = new Assignment();
|
|
$search_model = $Assignment->where('course_id', $data)
|
|
->with(['student' => function($query) {
|
|
$query->with(['customerResources' => function($query) {
|
|
$query->with(['member' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
}]);
|
|
}]);
|
|
$search_model_res = $search_model->select()->toArray();
|
|
$groupedByStatus1 = [];
|
|
$groupedByStatus2 = [];
|
|
$groupedByStatus3 = [];
|
|
|
|
foreach ($search_model_res as $item) {
|
|
if ($item['status'] == 1){
|
|
array_push($groupedByStatus1,$item);
|
|
} else if ($item['status'] == 2){
|
|
array_push($groupedByStatus2,$item);
|
|
} else if ($item['status'] == 3){
|
|
array_push($groupedByStatus3,$item);
|
|
}
|
|
}
|
|
$list['groupedByStatus1'] = $groupedByStatus1;
|
|
$list['groupedByStatus2'] = $groupedByStatus2;
|
|
$list['groupedByStatus3'] = $groupedByStatus3;
|
|
return $list;
|
|
}
|
|
|
|
|
|
//获取添加学员列表
|
|
public function StudentList($id)
|
|
{
|
|
$StudentCourses = new StudentCourses();
|
|
$PersonCourseSchedule = new PersonCourseSchedule();
|
|
$student_arr = $PersonCourseSchedule->where('schedule_id',$id)->column('student_id');
|
|
|
|
$query = $StudentCourses->where('course_id', $id);
|
|
if (!empty($student_arr)) {
|
|
$query->whereNotIn('student_id', $student_arr);
|
|
}
|
|
$res = $query->field('student_id as value')->select()->toArray();
|
|
$Student = new Student();
|
|
foreach ($res as $k => &$v) {
|
|
$StudentName = $Student->where('id',$v['value'])->value('name');
|
|
$v['text'] = $StudentName;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public function addStudent($data)
|
|
{
|
|
$PersonCourseSchedule = new PersonCourseSchedule();
|
|
$res = $PersonCourseSchedule->create($data);
|
|
return $res;
|
|
}
|
|
|
|
|
|
public function delStudentCourse($data)
|
|
{
|
|
$StudentCourseUsage = new StudentCourseUsage();
|
|
$StudentCourses = new StudentCourses();
|
|
$StudentCourses_id = $StudentCourses->where('student_id',$data['student_id'])->where('course_id',$data['course_id'])->value('id');
|
|
$PersonCourseSchedule_id = $StudentCourseUsage->where('student_course_id',$StudentCourses_id)->value('id');
|
|
if ($PersonCourseSchedule_id) {
|
|
$StudentCourseUsage->where('student_course_id',$StudentCourses_id)->delete();
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|