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.
251 lines
8.4 KiB
251 lines
8.4 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\class_grade\ClassGrade;
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use app\model\student\Student;
|
|
use app\model\assignment\Assignment;
|
|
use app\model\course\Course;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 考勤管理服务层
|
|
* Class MemberService
|
|
* @package app\service\api\member
|
|
*/
|
|
class jlClassService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = (new ClassGrade());
|
|
}
|
|
|
|
//列表
|
|
public function list($id,$data)
|
|
{
|
|
$order = 'id desc';
|
|
$where = [];
|
|
if ($data['name'] !== '') {
|
|
$where[] = ['name','like','%'.$data['name'].'%'];
|
|
}
|
|
$search_model = $this->model->where('head_coach', $id)->where($where)->order($order)
|
|
->with(['classPersonnelRel' => function($query) {
|
|
$query->with(['student' => function($query) {
|
|
$query->with(['customerResources' => function($query) {
|
|
$query->with(['member' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
}]);
|
|
},'studentCourses']);
|
|
|
|
},'personnelAll']);
|
|
$list = $this->pageQuery($search_model);
|
|
foreach ($list['data'] as &$v){
|
|
if (count($v['classPersonnelRel']) > 0) {
|
|
$now = time();
|
|
$count = 0;
|
|
foreach ($v['classPersonnelRel'] as $item) {
|
|
if (isset($item['end_date'])) {
|
|
$endTime = strtotime($item['end_date']);
|
|
if ($endTime > $now && $endTime <= $now + 7 * 86400) {
|
|
$count++;
|
|
}
|
|
}
|
|
}
|
|
$v['end_count'] = $count;
|
|
} else {
|
|
$v['end_count'] = 0;
|
|
}
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
|
|
public function info($data)
|
|
{
|
|
$search_model = $this->model->where('id', $data)
|
|
->with(['classPersonnelRel' => function($query) {
|
|
$query->with(['student' => function($query) {
|
|
$query->with(['customerResources' => function($query) {
|
|
$query->with(['member' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
}]);
|
|
},'studentCourses','studentCoursesInfo']);
|
|
},'personnelAll', 'personnelName']);
|
|
$list = $search_model->find();
|
|
if (count($list['classPersonnelRel']) > 0) {
|
|
$now = time();
|
|
$count = 0;
|
|
foreach ($list['classPersonnelRel'] as $item) {
|
|
if (isset($item['end_date'])) {
|
|
$endTime = strtotime($item['end_date']);
|
|
if ($endTime > $now && $endTime <= $now + 7 * 86400) {
|
|
$count++;
|
|
}
|
|
}
|
|
}
|
|
$v['end_count'] = $count;
|
|
} else {
|
|
$v['end_count'] = 0;
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
public function jlStudentsInfo($data)
|
|
{
|
|
$Student = new Student();
|
|
$res = $Student->where('id',$data)->with(['customerResources' => function($query) {
|
|
$query->with(['member' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
}]);
|
|
$res = $res->find();
|
|
return $res;
|
|
}
|
|
|
|
public function PhysicalTestList($data)
|
|
{
|
|
$resource_id = $data;
|
|
$where = [
|
|
'resource_id' => $resource_id,
|
|
];
|
|
$physical_test = (new PhysicalTestService())->getList($where);
|
|
$res['physical_test'] = $physical_test;
|
|
return $res;
|
|
}
|
|
|
|
public function GetClassesList()
|
|
{
|
|
$res = $this->model->where('status',1)->select()->toArray();
|
|
return $res;
|
|
}
|
|
|
|
public function GetCoursesList()
|
|
{
|
|
$Course = new Course();
|
|
$res = $Course->select()->toArray();
|
|
return $res;
|
|
}
|
|
|
|
public function GetStudentList()
|
|
{
|
|
$Student = new Student();
|
|
$res = $Student->where('status', 1)->select()->toArray();
|
|
return $res;
|
|
}
|
|
|
|
public function addPublishJob($data)
|
|
{
|
|
$Assignment = new Assignment();
|
|
// foreach ($data['student_id'] as $v) {
|
|
// $data['student_id'] = $v;
|
|
// $Assignment->create($data);
|
|
// }
|
|
$Assignment->create($data);
|
|
return true;
|
|
}
|
|
|
|
public function getStatisticsInfo($id)
|
|
{
|
|
$CourseSchedule = new CourseSchedule();
|
|
$courseNum = $CourseSchedule->where('coach_id', $id)->count();
|
|
$classNum = $this->model->where('head_coach', $id)->count();
|
|
$studentInfo = $this->model->where('head_coach', $id)
|
|
->with(['classPersonnelRel' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
$studentInfo = $studentInfo->select()->toArray();
|
|
$studentNum = 0;
|
|
foreach ($studentInfo as $v){
|
|
$studentNum += count($v['classPersonnelRel']);
|
|
}
|
|
// 获取当前时间戳
|
|
$now = time();
|
|
$firstDayOfMonth = date('Y-m-01', $now);
|
|
$lastDayOfMonth = date('Y-m-t', $now);
|
|
$classMonthNum = $this->model->where('head_coach', $id)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])->count();
|
|
$courseMonthNum = $CourseSchedule->where('coach_id', $id)->whereBetween('course_date', [$firstDayOfMonth, $lastDayOfMonth])->count();
|
|
|
|
$studentMonthInfo = $this->model->where('head_coach', $id)->whereBetween('created_at', [$firstDayOfMonth, $lastDayOfMonth])
|
|
->with(['classPersonnelRel' => function($query) {
|
|
$query->select();
|
|
}]);
|
|
$studentMonthInfo = $studentMonthInfo->select()->toArray();
|
|
$studentMonthNum = 0;
|
|
foreach ($studentMonthInfo as $v){
|
|
$studentMonthNum += count($v['classPersonnelRel']);
|
|
}
|
|
$arr = [
|
|
'courseNum' => $courseNum,
|
|
'classNum' => $classNum,
|
|
'studentNum' => $studentNum,
|
|
'classMonthNum' => $classMonthNum,
|
|
'courseMonthNum' => $courseMonthNum,
|
|
'studentMonthNum' => $studentMonthNum,
|
|
];
|
|
return $arr;
|
|
}
|
|
|
|
/**
|
|
* 获取班级列表(用于添加课程安排)
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
public function getClassListForSchedule(array $data)
|
|
{
|
|
try {
|
|
$where = [];
|
|
|
|
// 班级名称关键词搜索
|
|
if (!empty($data['keyword'])) {
|
|
$where[] = ['class_name', 'like', '%' . $data['keyword'] . '%'];
|
|
}
|
|
|
|
// 校区筛选
|
|
if (!empty($data['campus_id'])) {
|
|
$where[] = ['campus_id', '=', $data['campus_id']];
|
|
}
|
|
|
|
// 状态筛选,默认获取开启状态的班级
|
|
if (isset($data['status'])) {
|
|
$where[] = ['status', '=', $data['status']];
|
|
}
|
|
|
|
// 只获取未逻辑删除的班级
|
|
$where[] = ['deleted_at', '=', 0];
|
|
|
|
// 使用正确的模型来查询班级数据
|
|
$classList = \think\facade\Db::name('class')
|
|
->where($where)
|
|
->field('id, class_name, campus_id, campus_name, head_coach, assistant_coach, age_group, class_type, status')
|
|
->order('created_at DESC')
|
|
->select()
|
|
->toArray();
|
|
|
|
return [
|
|
'code' => 1,
|
|
'msg' => '获取成功',
|
|
'data' => $classList
|
|
];
|
|
|
|
} catch (\Exception $e) {
|
|
return [
|
|
'code' => 0,
|
|
'msg' => '获取班级列表失败:' . $e->getMessage(),
|
|
'data' => []
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|