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' => '成功'
]);
}
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);
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'])
->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'];
$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'])
->where('tb_audit_process.major_id','=',$data['major_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' => '申请列表'
]);
}
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);
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'])
->where('tb_student.record','=',1)
->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'])
->where('tb_student.record','=',2)
->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;
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,
]);
}
}