diff --git a/application/renshi/common.php b/application/renshi/common.php index b3d9bbc7..a4abe2da 100644 --- a/application/renshi/common.php +++ b/application/renshi/common.php @@ -1 +1,2 @@ only(['danwei','url'],'post'); + $list = request()->only(['school','url'],'post'); // 实例化操作表格类 $excel = new Myexcel(); // 读取表格数据 $stuinfo = $excel->readXls($list['url']); + // 删除标题行 + array_splice($stuinfo,0,3); + // $upcnt = count($stuinfo); - dump($stuinfo); + // 实例化班级数据模型 + $banji = new \app\teach\model\Banji; + $njlist = nianjilist(); + $bjlist = banjinamelist(); + + + $i = 0; + $bfbanji = ''; + $bj = ''; + $students = array(); + // 重新计算组合数据,如果存在数据则更新数据 + foreach ($stuinfo as $key => $value) { + // 判断本行班级与上行班级数据是否相等,如果不相等则从数据库查询班级ID + if($bfbanji != $value[3]) + { + // 获取入学年与排序 + $paixu = array_search(substr($value[3],9),$bjlist); + $ruxuenian = array_search(substr($value[3],0,9),$njlist); + // 查询班级ID + $bj = $banji::where('school',$list['school']) + ->where('ruxuenian',$ruxuenian) + ->where('paixu',$paixu) + ->value('id'); + } + $bfbanji = $value[3]; + // 如果班级ID为空,删除数据并跳出当前循环 + if($bj == null || $bj =='' ) + { + continue; + } + + + $students[$i]['banji'] = $bj; + $students[$i]['xingming'] = $value[1]; + $students[$i]['shenfenzhenghao'] = $value[2]; + substr($value[2],16,17)%2 == 1 ? $students[$i]['sex']=1 :$students[$i]['sex']=0; + $students[$i]['shengri'] = substr($value[2],6,4).'-'.substr($value[2],10,2).'-'.substr($value[2],12,2); + + $students[$i]['school'] = $list['school']; + $stuid = STU::where('shenfenzhenghao',$value[2])->value('id'); + $stuid > 1 ? $students[$i]['id'] = $stuid : true; + // 销毁无用变量 + $i++; + } + + + // 实例化学生信息数据模型 + $student = new STU(); + + // 保存或更新信息 + $data = $student->saveAll($students); + // $cnt = $data->count(); + + $data ? $data = ['msg'=>'数据同步成功','val'=>true] : ['msg'=>'数据同步失败','val'=>false]; diff --git a/application/renshi/model/Student.php b/application/renshi/model/Student.php index f0ba8be0..fd04b3ac 100644 --- a/application/renshi/model/Student.php +++ b/application/renshi/model/Student.php @@ -46,13 +46,5 @@ class Student extends Base return $sex[$value]; } - // 性别获取器 - public function setSexAttr($value) - { - $sex = array('0'=>'女','1'=>'男','2'=>'保密'); - $val = array_search($value,$sex); - return $val; - } - - + } diff --git a/application/renshi/validate/Student.php b/application/renshi/validate/Student.php index 485d26f4..ed6c5440 100644 --- a/application/renshi/validate/Student.php +++ b/application/renshi/validate/Student.php @@ -14,7 +14,7 @@ class Student extends Validate */ protected $rule = [ 'xingming|姓名' => 'require|chs|length:2,8', - 'sex|性别' => 'require|chs|max:2', + 'sex|性别' => 'require|number', 'shengri|出生日期' => 'date', 'shenfenzhenghao|身份证号' => "require|idCard", 'school|学校' => 'require|number', diff --git a/application/renshi/view/student/create.html b/application/renshi/view/student/create.html index fe3e9764..208e6758 100644 --- a/application/renshi/view/student/create.html +++ b/application/renshi/view/student/create.html @@ -17,15 +17,15 @@