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.
381 lines
14 KiB
381 lines
14 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\campus_person_role\CampusPersonRole;
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use app\model\person_course_schedule\PersonCourseSchedule;
|
|
use app\model\six_speed\SixSpeed;
|
|
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 DateTime;
|
|
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)
|
|
{
|
|
$campus_person_role = new CampusPersonRole();
|
|
$where = [];
|
|
if ($data['schedule_date']) {
|
|
$where[] = ['course_date','=', $data['schedule_date']];
|
|
}
|
|
|
|
$campus_id = $campus_person_role->where(['person_id' => $id])->column('campus_id');
|
|
|
|
$CourseSchedule = new CourseSchedule();
|
|
$search_model = $CourseSchedule
|
|
->where('campus_id','in',$campus_id)
|
|
->where($where)
|
|
->with(['course' => function($query) {
|
|
$query->select();
|
|
},'venue' => function($query) {
|
|
$query->select();
|
|
},'campus','studentCourses']);
|
|
$list = $this->pageQuery($search_model);
|
|
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)
|
|
{
|
|
$school_six_speed = new SixSpeed();
|
|
$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,sc.end_date,sc.start_date,sc.course_id')
|
|
->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,cr.id as resources_id,cr.source')
|
|
->find();
|
|
if($student){
|
|
$v['school_six_speed'] = $school_six_speed->where(['staff_id' => $student['resources_id']])->find();
|
|
|
|
}else{
|
|
$v['school_six_speed'] = [];
|
|
}
|
|
$v['source'] = get_dict_value("source",$student['source']);
|
|
$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 classList($data)
|
|
{
|
|
$CourseSchedule = new CourseSchedule();
|
|
$search_model = $CourseSchedule
|
|
->where('coach_id', $data)
|
|
->with(['course' => function($query) {
|
|
$query->with(['studentCourses' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
},'venue' => function($query) {
|
|
$query->select();
|
|
},'coach' => function($query) {
|
|
$query->select();
|
|
},'campus']);
|
|
$list = $this->pageQuery($search_model);
|
|
foreach ($list['data'] as &$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();
|
|
$v['student'] = $student;
|
|
}
|
|
foreach ($list['data'] as &$v) {
|
|
$student_courses = Db::name('student_courses')
|
|
->alias('sc')
|
|
->where('sc.course_id', $v['id'])
|
|
->join('school_student_course_usage sscu', 'sc.id = sscu.student_course_id')
|
|
->field('sc.student_id,sc.end_date,sc.end_date,sc.start_date,sc.course_id')
|
|
->select()->toArray();
|
|
$v['student_courses'] = $student_courses;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
public function getDate(array $baseDate)
|
|
{
|
|
$dates = [];
|
|
|
|
$this_date = $baseDate['date'] ?: date('Y-m-d');
|
|
|
|
$date = new DateTime($this_date);
|
|
|
|
for ($i = -2; $i <= 4; $i++) {
|
|
$tempDate = clone $date; // 避免修改原始对象
|
|
$tempDate->modify("$i days");
|
|
|
|
$status = false;
|
|
if($baseDate['day'] == $tempDate->format('d')){
|
|
$status = true;
|
|
}else if(empty($baseDate['day'])){
|
|
if($tempDate->format('Y-m-d') === date('Y-m-d')){
|
|
$status = true;
|
|
}
|
|
}
|
|
$dates[] = [
|
|
'date' => $tempDate->format('Y-m-d'),
|
|
'day' => $tempDate->format('d'),
|
|
'week' => getChineseWeekday($tempDate),
|
|
'status' => $status
|
|
];
|
|
}
|
|
|
|
return ['dates' => $dates,'date' => $this_date];
|
|
}
|
|
|
|
|
|
public function listAll($data)
|
|
{
|
|
$where = [];
|
|
if ($data['schedule_date']) {
|
|
$where[] = ['course_date','=', $data['schedule_date']];
|
|
}
|
|
$CourseSchedule = new CourseSchedule();
|
|
$list = $CourseSchedule
|
|
->where($where)
|
|
->with(['course' => function($query) {
|
|
$query->select();
|
|
},'venue' => function($query) {
|
|
$query->select();
|
|
},'campus','studentCourses'])
|
|
->select()->toArray();
|
|
foreach ($list 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[$k]['student'] = $student;
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
|
|
public function addSchedule(array $data){
|
|
$CourseSchedule = new CourseSchedule();
|
|
$personCourseSchedule = new PersonCourseSchedule();
|
|
if($personCourseSchedule->where([
|
|
'resources_id' => $data['resources_id'],
|
|
'schedule_id' => $data['schedule_id']
|
|
])->find()){
|
|
return fail("重复添加");
|
|
}
|
|
|
|
$personCourseSchedule->insert([
|
|
'resources_id' => $data['resources_id'],
|
|
'person_id' => $this->member_id,
|
|
'person_type' => $data['person_type'],
|
|
'schedule_id' => $data['schedule_id'],
|
|
'course_date' => $data['course_date'],
|
|
'time_slot' => $data['time_slot'],
|
|
]);
|
|
$CourseSchedule->where(['id' => $data['schedule_id']])->dec("available_capacity")->update();
|
|
return success("添加成功");
|
|
|
|
}
|
|
|
|
public function schedule_list(array $data){
|
|
$personCourseSchedule = new PersonCourseSchedule();
|
|
$list = $personCourseSchedule
|
|
->alias('a')
|
|
->join(['school_customer_resources' => 'b'],'a.resources_id = b.id','left')
|
|
->join(['school_course_schedule' => 'c'],'c.id = a.schedule_id','left')
|
|
->where('a.schedule_id',$data['schedule_id'])
|
|
->field("b.name,a.status,a.person_type,c.campus_id,b.id as resources_id,a.schedule_type,a.course_type")
|
|
->select()
|
|
->toArray();
|
|
|
|
return $list;
|
|
}
|
|
|
|
public function schedule_del(array $data)
|
|
{
|
|
$personCourseSchedule = new PersonCourseSchedule();
|
|
|
|
// 查询记录
|
|
$record = $personCourseSchedule->where([
|
|
'schedule_id' => $data['id'],
|
|
'resources_id' => $data['resources_id']
|
|
])->find();
|
|
|
|
if (!$record) {
|
|
return fail('未找到相关记录');
|
|
}
|
|
|
|
// 根据person_type执行不同操作
|
|
if ($record['person_type'] == 'customer_resource') {
|
|
// 如果是客户资源类型,直接删除记录
|
|
$personCourseSchedule->where([
|
|
'schedule_id' => $data['id'],
|
|
'resources_id' => $data['resources_id']
|
|
])->delete();
|
|
|
|
// 更新课程安排表的可用容量
|
|
$CourseSchedule = new CourseSchedule();
|
|
$CourseSchedule->where(['id' => $record['schedule_id']])->inc("available_capacity")->update();
|
|
|
|
return success('删除成功');
|
|
} else if ($record['person_type'] == 'student') {
|
|
// 如果是学生类型,更新状态为2并更新备注
|
|
$personCourseSchedule->where([
|
|
'id' => $data['id'],
|
|
'resources_id' => $data['resources_id']
|
|
])->update([
|
|
'status' => 2,
|
|
'remark' => $data['remark']
|
|
]);
|
|
|
|
return success('更新成功');
|
|
} else {
|
|
return fail('未知的人员类型');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|