cuiyebiao
2021-03-03 fc890ece322f708cfc7bd55e84fa77f0db7e8426
班级管理
1 files added
2 files modified
285 ■■■■■ changed files
app/Http/Controllers/Api/v1/ClassController.php 273 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/UsreController.php 2 ●●● patch | view | raw | blame | history
routes/api.php 10 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/Api/v1/ClassController.php
New file
@@ -0,0 +1,273 @@
<?php
namespace App\Http\Controllers\Api\v1;
use App\Http\Controllers\ApiController;
use App\Common\ResponseCode;
use Illuminate\Http\Request;
use Validator;
use Illuminate\Support\Facades\DB;
class ClassController extends ApiController
{
    /*
     * 班级列表
     * isCoursePlan 是否排课  0 否 1是
     * classstatus 1 开课中  2 结课 3 等课
     */
    public function classList(Request $request){
        $date = date("Y-m-d H:i:s");
        $page = (int)$request->input('page') ? :1;
        $pageSize = (int)$request->input('pageSize') ?: 10;
        $offset = ($page-1)*$pageSize;
        $orgId = $request->input('orgId');#馆id
        $UserId = $request->input('teacherId');#获取登陆人id
        $roleId = $request->input('roleId');#身份 2026 馆长
        $accurateRoleId = strstr($roleId, '2026');
        $soso = $request->input('soso');#搜搜
        $classstatus = $request->input('classstatus');#状态筛选 0 全部 1 开课中  2 结课 3 等课
        if ($classstatus == 0){
            $classstatus = '1,2,3';
        }
        $where = "a.isDelete = 0 and a.classMode >1 and a.status = 1 and a.orgId = '{$orgId}'";
        if ($accurateRoleId == 2026){
            $list = DB::select("
                select a.id,a.className,a.classCode,a.classstatus,a.hometeacherId,a.isCoursePlan,a.teacherName,
                (SELECT RealCnName FROM annieportal.sys_user WHERE UserId = a.hometeacherId) as RealCnName,
                (SELECT COUNT(1) FROM anni_classstudent WHERE classCode = a.classCode and isDelete = 0 and isDeleteReason = 0) as userCount
                from anni_class as a
                where $where and (a.className like '%$soso%' or a.classCode like '%$soso%' or a.teacherName like '%$soso%')
                and a.classstatus in ($classstatus)
                ORDER BY field(a.classstatus,3,1,2) asc
                limit $offset,$pageSize
            ");
            $total = DB::select("select a.id,a.className,a.classCode,a.classstatus,a.teacherName
                from anni_class as a
                where $where and (a.className like '%$soso%' or a.classCode like '%$soso%' or a.teacherName like '%$soso%')
                and a.classstatus in ($classstatus)");
            $total = count($total);
        }else{
            $list = DB::select("
                select DISTINCT a.id,a.className,a.classCode,a.classstatus,a.hometeacherId,a.isCoursePlan,a.teacherName,
                (SELECT RealCnName FROM annieportal.sys_user WHERE UserId = a.hometeacherId) as RealCnName,
                (SELECT COUNT(1) FROM anni_classstudent WHERE classCode = a.classCode and isDelete = 0 and isDeleteReason = 0) as userCount
                from anni_class as a
                LEFT JOIN anni_classteachermodule as b on b.classCode = a.classCode
                where a.isDelete = 0 and a.classMode >1 and a.status = 1 and a.orgId = '{$orgId}'
                and (b.UserId = '{$UserId}' or a.teacherheadId = '{$UserId}' or a.hometeacherId = '{$UserId}' or a.hometeacherheadId = '{$UserId}')
                and b.isDelete = 0
                and (a.className like '%$soso%' or a.classCode like '%$soso%' or a.teacherName like '%$soso%')
                and a.classstatus in ($classstatus)
                ORDER BY field(a.classstatus,3,1,2) asc
                limit $offset,$pageSize
            ");
            $total = DB::select("select DISTINCT a.id,a.className,a.classCode,a.classstatus,a.teacherName
                from anni_class as a
                LEFT JOIN anni_classteachermodule as b on b.classCode = a.classCode
                where a.isDelete = 0 and a.classMode >1 and a.status = 1 and a.orgId = '{$orgId}'
                and (b.UserId = '{$UserId}' or a.teacherheadId = '{$UserId}' or a.hometeacherId = '{$UserId}' or a.hometeacherheadId = '{$UserId}')
                and b.isDelete = 0
                and (a.className like '%$soso%' or a.classCode like '%$soso%' or a.teacherName like '%$soso%')
                and a.classstatus in ($classstatus)");
            $total = count($total);
        }
        foreach ($list as $k=>$v){
            #已排课课时
            if ($v['isCoursePlan'] == 1){
                $list[$k]['coursetableclassHour'] = DB::table('anni_coursetable')
                    ->where(array('classCode'=>$v['classCode'],'isDelete'=>0))
                    ->sum('classHour');
                #班级已上课时
                $whereConsumed['classCode'] = $v['classCode'];
                $whereConsumed['isDelete'] = 0;
                $whereConsumed[] = ['startTime','<=',"$date"];
                $list[$k]['ConsumedclassHour'] = DB::table('anni_coursetable')
                    ->where($whereConsumed)
                    ->sum('classHour');
            }else{
                $list[$k]['coursetableclassHour'] = 0;
                $list[$k]['ConsumedclassHour'] = 0;
            }
        }
        $result = [];
        $result['page'] = $page;
        $result['pageSize'] = $pageSize;
        $result['total'] = $total;
        $result['list'] = $list;
        return $this->_response($result);
    }
    /*
     * 班级信息
     */
    public function classInfo(Request $request){
        $date = date("Y-m-d H:i:s");
        $id = $request->input('id');
        $info = DB::table('anni_class as a')
            ->select('a.id','a.classCode','a.className','a.classstatus','a.courseId',
                'a.openclassTime','a.onlineclassTime','a.teacherName','a.isCoursePlan',
                'b.RealCnName')
            ->leftJoin('annieportal.sys_user as b','b.UserId','=','a.hometeacherId')
            ->where(array('a.id'=>$id))
            ->first();
        #已排课课时
        if ($info['isCoursePlan'] == 1){
            $info['coursetableclassHour'] = DB::table('anni_coursetable')
                ->where(array('classCode'=>$info['classCode'],'isDelete'=>0))
                ->sum('classHour');
            #班级已上课时
            $whereConsumed['classCode'] = $info['classCode'];
            $whereConsumed['isDelete'] = 0;
            $whereConsumed[] = ['startTime','<=',"$date"];
            $info['ConsumedclassHour'] = DB::table('anni_coursetable')
                ->where($whereConsumed)
                ->sum('classHour');
        }else{
            $info['coursetableclassHour'] = 0;
            $info['ConsumedclassHour'] = 0;
        }
        #教师去重
        $teacherArr = explode(',', $info['teacherName']);
        $arrTeacher = array_unique($teacherArr);
        $teacherName = implode(',', $arrTeacher);
        $info['teacherName'] = trim($teacherName,',');
        return $this->_response($info);
    }
    /*
     * 班级学员列表
     */
    public function classUserList(Request $request){
        $classCode = $request->input('classCode');
        $page = (int)$request->input('page');
        $pageSize = (int)$request->input('pageSize') ?: 10;
        $offset = ($page-1)*$pageSize;
        $where['a.isDelete'] = 0;
        $where['a.status'] = 1;
        $where['a.classCode'] = $classCode;
        $List = DB::table('anni_classstudent as a')
            ->select('a.id','a.username','a.classcode','b.name','b.englishName','b.faceImg','b.headPhoto',
                DB::raw("(select sum(classHour) from anni_attendrecord
                      where status = 1 and isDelete=0 and username = a.username and classStatus in (1,5,6) ) as HourSum"),
                DB::raw("(select sum(cl.courseHour) from anni_classstudent as ct
                      left join anni_class as cl on cl.classCode = ct.classCode
                      where ct.username = a.username and ct.isDelete = 0 and cl.classstatus !=2) as courseHourSum"),
                DB::raw("(select parentid from anni_combineorders
                      where classcode = a.classcode and isDelete = 0 and status =1 limit 1) as parentid")
                )
            ->leftjoin('anni_students as b','b.username','=','a.username')
            ->where($where)
            ->offset($offset)
            ->limit($pageSize)
            ->get()->toArray();
        foreach ($List as $k=>$v){
            if ($v['parentid'] >0){
                $List[$k]['isActivation'] = 1;
            }else{
                $List[$k]['isActivation'] = 0;
            }
            $List[$k]['name'] = $v['englishName'].'('.$v['name'].')';
            if (!empty($v['faceImg'])){
                $List[$k]['faceImg'] = $this->fun->getFacePath($v['faceImg']);
            }else{
                $List[$k]['faceImg'] = $this->fun->stitchingPath($v['headPhoto']);
            }
            $List[$k]['surplusSum'] = $v['courseHourSum'] - $v['HourSum'];
        }
        $total = DB::table('anni_classstudent as a')->where($where)->count();
        $result = [];
        $result['page'] = $page;
        $result['pageSize'] = $pageSize;
        $result['total'] = $total;
        $result['list'] = $List;
        return $this->_response($result);
    }
    /*
     * 排课安排
     */
    public function classCoursetableList(Request $request){
        $date = date("Y-m-d H:i:s");
        $page = (int)$request->input('page') ?: 1;
        $pageSize = (int)$request->input('pageSize') ?: 10;
        $offset = ($page-1)*$pageSize;
        $classCode = $request->input('classCode');
        $List = DB::select("SELECT a.id,a.classNumber,a.week,a.startTime,
            a.classCode,a.classHour,a.courseStatus
            FROM anni_coursetable as a
            WHERE a.classCode = '{$classCode}' and a.isDelete = 0
            order by a.startTime asc
            limit $offset,$pageSize");
        foreach ($List as $k=>$v){
            #排课时间段
            $info = DB::table('anni_coursetabletime')
                ->select('contentTime')
                ->where(array('classCode'=>$v['classCode'],'week'=>$v['week'],'isDelete'=>0))
                ->first();
            if (!empty($info)){
                $List[$k]['contentTime'] = $info['contentTime'];
                $List[$k]['Time'] = date("Y-m-d",strtotime(date("Y-m-d",strtotime($v['startTime']))));
                $starthours = substr($List[$k]['contentTime'],0,5);
                $endhours = substr($List[$k]['contentTime'],6);
                $List[$k]['startTime'] = date("Y-m-d",strtotime(date("Y-m-d",strtotime($v['startTime']))))." $starthours";
                $List[$k]['endTime'] = date("Y-m-d",strtotime(date("Y-m-d",strtotime($v['startTime']))))." $endhours";
                if ($date > $List[$k]['endTime']){
                    $List[$k]['status'] = 1;
                }elseif ($date>$List[$k]['startTime'] && $date < $List[$k]['endTime']){
                    $List[$k]['status'] = 3;
                }else{
                    $List[$k]['status'] = 2;
                }
            }
        }
        $userCount = DB::select("SELECT id FROM anni_coursetable as a WHERE a.classCode = '{$classCode}' and a.isDelete = 0");
        $userCount = count($userCount);
        $totalPage =  ceil($userCount / $pageSize);
        if ($totalPage == 0){
            $totalPage = 1;
        }
        return $this->_response(['list' => $List, 'page' => (int)$page, 'pageSize' => (int)$pageSize, 'totalPage' => $totalPage, 'total' => $userCount]);
    }
    /*
     * 排课安排详情
     * 本次的
     * 状态1 出勤 2 缺勤 3 移除班级 4 请假 5 补课  6 迟到
     */
    public function calssAttendrecordList(Request $request){
        $classCode = $request->input('classCode');
        $classNumber = $request->input('classNumber');
        $where['a.classCode'] = $classCode;
        $where['a.classNumber'] = $classNumber;
        $where['a.isDelete'] = 0;
        $List = DB::table('anni_attendrecord as a')
            ->select('a.id','b.name','a.username','a.classStatus')
            ->leftjoin('anni_students as b','b.username','=','a.username')
            ->where($where)
            ->get();
        return $this->_response($List);
    }
    /*
     * 修改考勤状态
     * 状态1 出勤 2 缺勤 3 移除班级 4 请假 5 补课  6 迟到
     */
    public function attendrecordSave(Request $request){
        $id = $request->input('id');
        $classStatus = $request->input('classStatus');
        $explain = $request->input('explain');#备注
        if (!empty($explain)){
            $data['remark'] = $explain;
        }
        $repairTime = $request->input('repairTime');#补课时间
        $staffId = $request->input('staffId');#教师
        if (!empty($repairTime)){
            $data['repairTime'] = $repairTime;
        }
        if (!empty($staffId)){
            $data['staffId'] = $staffId;
        }
        $data['classStatus'] = $classStatus;
        $data['updateTime'] = date("Y-m-d H:i:s");
        DB::table('anni_attendrecord')->where("id",$id)
            ->update($data);
        return $this->_response(null, ResponseCode::SUCCESS, '成功');
    }
}
app/Http/Controllers/Api/v1/UsreController.php
@@ -28,7 +28,7 @@
        $orgId = $request->input('orgId');#获取馆id
        $UserId = $request->input('teacherId');#获取登陆人id
        $courseStatus = $request->input('courseStatus');#状态筛选 -1 全部 0 无课 1 在读 2 停课 3 结课
        if ($courseStatus == -1 || empty($courseStatus)){
        if ($courseStatus == -1){
            $courseStatus = '0,1,2,3';
        }
        $soso = $request->input('soso');#搜搜
routes/api.php
@@ -75,10 +75,20 @@
        /*******************************  end  lium ****************************************/
        /******************************* start Cuiyb ****************************************/
        ### 学员
        $api->post('/Usre/userList', 'UsreController@userList');#学员列表
        $api->post('/Usre/myUserList', 'UsreController@myUserList');#我的-学员列表
        $api->post('/Usre/userInfo', 'UsreController@userInfo');#学员详情
        $api->post('/Usre/userClassList', 'UsreController@userClassList');#学员班级列表
        ### 班级
        $api->post('/Class/classList', 'ClassController@classList');#班级列表
        $api->post('/Class/classInfo', 'ClassController@classInfo');#班级详情
        $api->post('/Class/classUserList', 'ClassController@classUserList');#班级学员列表
        $api->post('/Class/classCoursetableList', 'ClassController@classCoursetableList');#排课安排
        $api->post('/Class/calssAttendrecordList', 'ClassController@calssAttendrecordList');#排课安排详情
        $api->post('/Class/attendrecordSave', 'ClassController@attendrecordSave');#修改考勤状态
        /******************************* end Cuiyb ****************************************/
    });
});