laravel 老師管理

<?php

namespace App\Http\Controllers;
use App\Models\TbMajor;
use App\Service\TestService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class TeacherController extends Controller{
    public function bindTeacher(Request $request){
        $data = $request->all();
        $job_no = array_key_exists("job_no", $data)?$data["job_no"]:null;
        $user_id = array_key_exists("user_id", $data)?$data["user_id"]:null;

        $time=Carbon::now()->toDateTimeString();
        $res = DB::table('tb_teacher')
            ->where('job_no', $job_no)
            ->update([
                'user_id' => $data['user_id'],
                'bind_time' => $time
            ])
            ->update(['user_id' => $user_id]);
        if($res){
            return response()->json([
                'msg' => '登錄成功',
                'code' => 0,
            ]);
        }else{
            return response()->json([
                'msg' => '綁定失敗',
                'code' => 1,
            ]);
        }
    }
    public function Info(Request $request){
        $data = $request->all();
        $user_id = array_key_exists("user_id", $data)?$data["user_id"]:null;
        $users = DB::table('tb_teacher')->where('user_id', '=', $user_id)->get()->first();
        $data = json_decode(json_encode($users), true);
        return response()->json([
            'data' => $data,
            'code' => 0,
            'msg' => '成功'
        ]);

    }
    // 參數 教師 teacher_id  專業 major_id   record學歷1研究生  2 本科生
    // audit_status 審覈狀態 1: 待初審 2:初審駁回  3:待複審 4:複審駁回 5:待終審 6: 待組織關係審 7:終審駁回   8:組織關係通過 9:組織審覈不過
//['apply_id','apply_time','apply_dtl','tb_student.student_id','student_name','student_no','tb_major.major_id','major_name','tb_student.teacher_id']
    public function auditList(Request $request){
        $data = $request->all();
        $arr = DB::table('tb_teacher')->where('user_id','=',$data['user_id'])->get()->first();
        $arr = json_decode(json_encode($arr), true);
//        print_r($arr);die;
        if($arr['role_id'] == 1){
           $data['audit_status'] = 1;
        }
        if($arr['role_id'] == 2){
           $data['audit_status'] = 3;
        }
        if($arr['role_id'] == 3){
           $data['audit_status'] = 5;
        }
        if($arr['role_id'] == 4){
           $data['audit_status'] = 8;
        }
        $student = DB::table('tb_student_apply')
            ->join('tb_student', 'tb_student.student_id', '=', 'tb_student_apply.student_id')
            ->join('tb_audit_process','tb_audit_process.major_id','=','tb_student.major_id')
            ->join('tb_major', 'tb_student.major_id', '=', 'tb_major.major_id')
            ->where('tb_student_apply.audit_status','=',$data['audit_status'])//老師id
            ->get([
                'tb_student.student_id','tb_student_apply.apply_id','apply_time','tb_student.student_id','tb_student.student_name','tb_student.student_no',
                'tb_audit_process.major_id','tb_major.major_name','tb_audit_process.biye_time','tb_audit_process.record'
            ])->toArray();
        $data = json_decode(json_encode($student), true);
        foreach ($data as $k=> $v){
            $data[$k]['teacher_name'] = $arr['teacher_name'];
            $data[$k]['teacher_id'] = $arr['teacher_id'];
        }
        return response()->json([
            'data' => $data,
            'code' => 0,
            'msg' => '申請列表'
        ]);
        die;
        $data = $request->all();
        $arr = DB::table('tb_teacher')->where('user_id','=',$data['user_id'])->get(['teacher_id','role_id'])->first();
        $arr = json_decode(json_encode($arr), true);
        if($arr['role_id'] == 1){
           $data['audit_status'] = 1;
        }
        if($arr['role_id'] == 2){
           $data['audit_status'] = 3;
        }
        if($arr['role_id'] == 3){
           $data['c'] = 5;
        }
        if($arr['role_id'] == 4){
           $data['audit_status'] = 8;
        }
        $data['teacher_id'] = $arr['teacher_id'];
        $data['role_id'] = $arr['role_id'];
        if($arr['role_id'] == 1){
            $str = DB::table('tb_audit_process')->where('fd_roleid','=', $data['teacher_id'])->get(['major_id'])->first();
            $str = json_decode(json_encode($str), true);
            $data['major_id'] = $str['major_id'];
        }
        if($arr['role_id'] == 2){
            $str = DB::table('tb_audit_process')->where('sy_roleid','=', $data['teacher_id'])->get(['major_id'])->first();
            $str = json_decode(json_encode($str), true);
            $data['major_id'] = $str['major_id'];
        }
        if($arr['role_id'] == 3){
            $str = DB::table('tb_audit_process')->where('jw_roleid','=', $data['teacher_id'])->get(['major_id'])->first();
            $str = json_decode(json_encode($str), true);
            $data['major_id'] = $str['major_id'];
        }
        if($arr['role_id'] == 4){
            $str = DB::table('tb_audit_process')->where('zh_roleid','=', $data['teacher_id'])->get(['major_id'])->first();
            $str = json_decode(json_encode($str), true);
            $data['major_id'] = $str['major_id'];
        }
        $arrs = DB::table('tb_audit_process')->where('major_id','=',$data['major_id'])->get(['biye_time','record'])->first();
        $arrs = json_decode(json_encode($arrs), true);
        $data['biye_time'] = $arrs['biye_time'];
        $data['record'] = $arrs['record'];
//        print_r($data);die;
        $student = DB::table('tb_student_apply')
            ->join('tb_student', 'tb_student.student_id', '=', 'tb_student_apply.student_id')
            ->join('tb_major', 'tb_student.major_id', '=', 'tb_major.major_id')
            ->join('tb_teacher','tb_student.teacher_id','=','tb_teacher.teacher_id')
            ->join('tb_role','tb_role.role_id','=','tb_teacher.role_id')
            ->join('tb_audit_process','tb_major.major_id','=','tb_audit_process.major_id')
            ->where('tb_student.teacher_id','=',$data['teacher_id'])//老師id
            ->where('tb_audit_process.major_id','=',$data['major_id'])//專業id
            ->where('tb_teacher.role_id','=',$data['role_id'])//角色
            ->where('tb_audit_process.biye_time','=',$data['biye_time'])//畢業時間
            ->where('tb_audit_process.record','=',$data['record'])//學歷
            ->where('tb_student_apply.audit_status','=',$data['audit_status'])
            ->get([
                'apply_id','apply_time','apply_dtl','tb_student.student_id','student_name','student_no','tb_major.major_id','major_name','tb_student.teacher_id',
                'tb_teacher.teacher_name','tb_teacher.role_id','tb_audit_process.record','tb_audit_process.biye_time'

            ])->toArray();
        $data = json_decode(json_encode($student), true);
        return response()->json([
            'data' => $data,
            'code' => 0,
            'msg' => '申請列表'
        ]);
    }
    //role_id 角色id
    // audit_status 審覈狀態 1: 待初審 2:初審駁回  3:待複審 4:複審駁回 5:待終審 6: 待組織關係審 7:終審駁回   8:組織關係通過 9:組織審覈不過
    public function studentApply(Request $request){
        $data = $request->all();
        $arr = $request->all();
        $time=Carbon::now()->toDateTimeString();
        $data['audit_time']=$time;
        unset($arr['audit_id']);
        unset($arr['register']);
        unset($arr['com_reg']);
        $res = DB::table("tb_teacher")->where('teacher_id',$data['audit_teacher_id'])->first();
        $data['audit_id'] = $res->role_id;
        $this->
        $data['id'] = DB::table('tb_student_apply_audit')->insertGetId($arr);//插入審覈信息  獲取這一條插入的id
        if($data['audit_id'] == 1){
            if($data['audit_status'] == 1){//輔導員審覈
                if($data['register'] == 1 && $data['com_reg'] == 1){
                    $data['audit_status'] = 3;
                    $this->update($data);
                    return response()->json([
                        'msg' => '審覈成功狀態修改OK',
                        'code' => 0,
                    ]);
                }else{
                    $this->update($data);
                    return response()->json([
                        'msg' => '輔導員審覈未通過,審覈材料缺少',
                        'code' => 1,
                    ]);
                }
            }else{
                $data['audit_status'] = 2;
                $this->update($data);
                return response()->json([
                    'msg' => '審覈失敗狀態修改OK',
                    'code' => 1,
                ]);
            }
        }
        if($data['audit_id'] == 2){
            if($data['audit_status'] == 1){//實驗員審覈
                $data['audit_status'] = 5;
                $this->update($data);
                return response()->json([
                    'msg' => '審覈成功狀態修改OK',
                    'code' => 0,
                ]);
            }else{
                $data['audit_status'] = 3;
                $this->update($data);
                return response()->json([
                    'msg' => '審覈失敗狀態修改OK',
                    'code' => 1,
                ]);
            }
        }
        if($data['audit_id'] == 3){
            if($data['audit_status'] == 1){//教務員審覈
                $data['audit_status'] = 6;
                $this->update($data);
                return response()->json([
                    'msg' => '審覈成功狀態修改OK',
                    'code' => 0,
                ]);
            }else{
                $data['audit_status'] = 7;
                $this->update($data);
                return response()->json([
                    'msg' => '審覈失敗狀態修改OK',
                    'code' => 1,
                ]);
            }
        }
        if($data['audit_id'] == 4){
            if($data['audit_status'] == 1){//組織關係審覈
                if($data['party_name'] == 1 && $data['unit_info'] ){
                    $data['audit_status'] = 8;
                    $this->update($data);
                    return response()->json([
                        'msg' => '審覈成功狀態修改OK',
                        'code' => 0,
                    ]);
                }else{
                    $this->update($data);
                    return response()->json([
                        'msg' => '組織關係審覈未通過,審覈材料缺少',
                        'code' => 1,
                    ]);
                }

            }else{
                $data['audit_status'] = 9;
                $this->update($data);
                return response()->json([
                    'msg' => '審覈失敗狀態修改OK',
                    'code' => 1,
                ]);
            }
        }
    }
    public function update($data){
        if($data['register'] == 0 || $data['com_reg'] == 0){
            DB::table("tb_student_apply_audit")->where('id',$data['id'])->update(['audit_status'=>0]);
        }
        if($data['audit_status'] == 0){
            DB::table("tb_student_apply_audit")->where('id',$data['id'])->update(['audit_status'=>0]);
        }
        DB::table("tb_student_apply")->where('apply_id',$data['apply_id'])->update(['audit_status'=>$data['audit_status']]);
    }
    public function majorName(){
        $data = TbMajor::all()->toArray();
        return response()->json([
            'msg' => '專業列表',
            'code' => 0,
            'data' => $data
        ]);
    }
    public function statistics(Request $request){
        $data = $request->all();
        $arr['yjs'] = DB::table('tb_student_apply')
            ->join('tb_student', 'tb_student.student_id', '=', 'tb_student_apply.student_id')
            ->join('tb_major', 'tb_major.major_id', '=', 'tb_student.major_id')
            ->join('tb_teacher', 'tb_teacher.teacher_id', '=', 'tb_student.teacher_id')
            ->where('tb_student.major_id','=',$data['major_id'])//專業id
            ->where('tb_student.record','=',1)//專業id
            ->count();
        $arr['bks'] = DB::table('tb_student_apply')
            ->join('tb_student', 'tb_student.student_id', '=', 'tb_student_apply.student_id')
            ->join('tb_major', 'tb_major.major_id', '=', 'tb_student.major_id')
            ->join('tb_teacher', 'tb_teacher.teacher_id', '=', 'tb_student.teacher_id')
            ->where('tb_student.major_id','=',$data['major_id'])//專業id
            ->where('tb_student.record','=',2)//專業id
            ->count();
        return response()->json([
            'msg' => '審覈列表',
            'code' => 0,
            'data' => $arr
        ]);
    }
    public function upImg(Request $request){
        $url = $request->server('HTTP_HOST');
        $data = $request->all();
        $image = $data['img'];
        $image = str_replace('data:image/png;base64,', '', $image);
        $image = str_replace(' ', '+', $image);
        $imagePath= rand(1,1000) . $data['imgType'];
        $imagePath= date('Ym',time()).'/'.$imagePath;
        $url='http://'.$url.'/storage/'.$imagePath;
        // http://school.chansnet.cn/storage/202006/281.jpg
        Storage::disk('public')->put($imagePath, base64_decode($image));
        $path='/static/images/school/'.date('Ym',time()).'/'.$imagePath;
        DB::table("tb_student_apply")->where('apply_id',$data['apply_id'])->update(['book_img'=>$url]);
        return response()->json([
            'msg' => '上傳成功',
            'code' => 0,
            'data' =>  $url
        ]);
    }
    public function grant(Request $request){
        $data = $request->all();
        $time=time();
        $start=date('Y',$time);
        $res = DB::table("tb_student_apply")->where('apply_id',$data['apply_id'])->first();
        if($res->audit_status == 8){
            DB::table("tb_student_apply")->where('apply_id',$data['apply_id'])->update(['is_grant_cert'=>1,'grant_time'=>$start]);
        }
        return response()->json([
            'msg' => '證書發送成功',
            'code' => 0,
        ]);
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章