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.
231 lines
7.2 KiB
231 lines
7.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\classroom;
|
|
|
|
use app\model\class_grade\ClassGrade;
|
|
use app\model\campus\Campus;
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use app\model\personnel\Personnel;
|
|
|
|
use app\model\rel\ClassPersonnelRel;
|
|
use app\model\student\Student;
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 场地管理服务层
|
|
* Class ClassroomService
|
|
* @package app\service\admin\classroom
|
|
*/
|
|
class ClassroomService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new ClassGrade();
|
|
}
|
|
|
|
/**
|
|
* 获取场地管理列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPage(array $where = [])
|
|
{
|
|
$field = 'id,campus_id,campus_name,class_name,educational_id,head_coach,age_group,class_type,assistant_coach,created_at,updated_at,deleted_at,status,sort_order,remarks';
|
|
$order = 'id desc';
|
|
|
|
$search_model = $this->model->withSearch(["campus_id", "class_name", "head_coach", "class_type", "assistant_coach", "created_at", "status"], $where)->with(['campus', 'personnel', 'personnel'])->field($field)->order($order);
|
|
$list = $this->pageQuery($search_model);
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取场地管理信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,campus_id,campus_name,class_name,educational_id,head_coach,age_group,class_type,assistant_coach,created_at,updated_at,deleted_at,status,sort_order,remarks';
|
|
|
|
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['campus', 'personnel', 'personnel'])->findOrEmpty()->toArray();
|
|
$info['status'] = strval($info['status']);
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 添加场地管理
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
$res = $this->model->create($data);
|
|
return $res->id;
|
|
|
|
}
|
|
|
|
/**
|
|
* 场地管理编辑
|
|
* @param int $id
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function edit(int $id, array $data)
|
|
{
|
|
|
|
$this->model->where([['id', '=', $id]])->update($data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除场地管理
|
|
* @param int $id
|
|
*/
|
|
public function del(int $id)
|
|
{
|
|
$student = new Student();
|
|
if($student->where(['class_id' => $id])->find()){
|
|
return fail("班级下有学员禁止删除");
|
|
}
|
|
$model = $this->model->where([['id', '=', $id]])->find();
|
|
$res = $model->delete();
|
|
return success('DELETE_SUCCESS');
|
|
}
|
|
|
|
|
|
public function getCampusAll()
|
|
{
|
|
$campusModel = new Campus();
|
|
return $campusModel->select()->toArray();
|
|
}
|
|
|
|
public function getPersonnelAll($params = [])
|
|
{
|
|
$campus_id = $params['campus_id'] ?? 0;
|
|
|
|
// 如果没有传校区ID,返回所有人员
|
|
if (empty($campus_id)) {
|
|
$personnelModel = new Personnel();
|
|
return $personnelModel->field('id, name, phone')->select()->toArray();
|
|
}
|
|
|
|
// 根据校区ID获取对应的教练、教务、市场人员
|
|
// 部门ID: 1=市场, 2=教务, 23=教练(实际系统中教练角色的dept_id是23)
|
|
$dept_ids = [1, 2, 23];
|
|
$personnel_list = get_personnel_by_campus_dept($campus_id, $dept_ids);
|
|
|
|
// 格式化返回数据,保持与原接口一致
|
|
$result = [];
|
|
foreach ($personnel_list as $person) {
|
|
$result[] = [
|
|
'id' => $person['person_id'],
|
|
'name' => $person['name'],
|
|
'phone' => $person['phone'],
|
|
'role_id' => $person['role_id'],
|
|
'dept_id' => $person['dept_id']
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 获取教练人员(主教练、助教)
|
|
*/
|
|
public function getCoachPersonnel($params = [])
|
|
{
|
|
$campus_id = $params['campus_id'] ?? 0;
|
|
|
|
// 如果没有传校区ID,返回所有教练人员
|
|
if (empty($campus_id)) {
|
|
// 这里可以直接查询所有教练角色的人员,但为了保持一致性,我们使用公共方法
|
|
$personnelModel = new Personnel();
|
|
return $personnelModel->field('id, name, phone')->select()->toArray();
|
|
}
|
|
|
|
// 根据校区ID获取教练人员(角色ID: 1=教练主管, 5=普通教练)
|
|
$role_ids = [1, 5];
|
|
$personnel_list = get_personnel_by_campus_role($campus_id, $role_ids);
|
|
|
|
// 格式化返回数据
|
|
$result = [];
|
|
foreach ($personnel_list as $person) {
|
|
$result[] = [
|
|
'id' => $person['person_id'],
|
|
'name' => $person['name'],
|
|
'phone' => $person['phone'],
|
|
'role_id' => $person['role_id'],
|
|
'dept_id' => $person['dept_id']
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 获取教务人员
|
|
*/
|
|
public function getEducationalPersonnel($params = [])
|
|
{
|
|
$campus_id = $params['campus_id'] ?? 0;
|
|
|
|
// 如果没有传校区ID,返回所有教务人员
|
|
if (empty($campus_id)) {
|
|
$personnelModel = new Personnel();
|
|
return $personnelModel->field('id, name, phone')->select()->toArray();
|
|
}
|
|
|
|
// 根据校区ID获取教务人员(部门ID: 2=教务)
|
|
$dept_ids = [2];
|
|
$personnel_list = get_personnel_by_campus_dept($campus_id, $dept_ids);
|
|
|
|
// 格式化返回数据
|
|
$result = [];
|
|
foreach ($personnel_list as $person) {
|
|
$result[] = [
|
|
'id' => $person['person_id'],
|
|
'name' => $person['name'],
|
|
'phone' => $person['phone'],
|
|
'role_id' => $person['role_id'],
|
|
'dept_id' => $person['dept_id']
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function classroom_all()
|
|
{
|
|
$data = $this->model->where('status', 1)->order('sort_order desc')->select()->toArray();
|
|
return $data;
|
|
}
|
|
|
|
public function getClassroompeople($class_id)
|
|
{
|
|
$listmodel = new ClassPersonnelRel();
|
|
return $listmodel->with(['student','personnel'])->where('class_id', $class_id)->select()->toArray();
|
|
}
|
|
|
|
/**
|
|
* 获取班级当前时段人员安排情况
|
|
*/
|
|
public function getClassroompeopleCount($venue_id,$where = [])
|
|
{
|
|
$listmodel = new CourseSchedule();
|
|
return $listmodel->where('venue_id', $venue_id)
|
|
->where($where)
|
|
->select()
|
|
->toArray();
|
|
}
|
|
}
|
|
|