From bc1f32f12e76df1070f76367d3772be30f95d612 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Sun, 22 Dec 2019 19:26:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=95=B0=E6=8D=AE=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/renshi/common.php | 16 +++-- app/renshi/controller/Student.php | 104 +++++++++++++++++++++--------- app/renshi/model/Student.php | 4 +- 3 files changed, 87 insertions(+), 37 deletions(-) diff --git a/app/renshi/common.php b/app/renshi/common.php index 214a917c..6e533c83 100644 --- a/app/renshi/common.php +++ b/app/renshi/common.php @@ -99,7 +99,7 @@ function smDownload($url,$newname='') * $str是原文件格式 * $data['ruxuenian'=>'',paixu=>''] */ -function strBjmArray($str) +function strBjmArray($str,$school) { if(stristr($str,'年级',true)==false || stristr($str,'班',true)==false) @@ -116,8 +116,16 @@ function strBjmArray($str) $nj = substr($str,0,9); $bj = substr($str,9,strlen($str)-9); - $data['ruxuenian'] = array_search($nj,$njlist); - $data['paixu'] = array_search($bj, $bjlist); + $nj = array_search($nj,$njlist); + $bj = array_search($bj, $bjlist); - return $data; + + // 查询班级id + $banji = new \app\teach\model\Banji; + $id = $banji->where('ruxuenian',$nj) + ->where('paixu',$bj) + ->where('school',$school) + ->value('id'); + + return $id; } \ No newline at end of file diff --git a/app/renshi/controller/Student.php b/app/renshi/controller/Student.php index 801be5c3..efac1dc6 100644 --- a/app/renshi/controller/Student.php +++ b/app/renshi/controller/Student.php @@ -422,6 +422,7 @@ class Student extends BaseController // 读取表格数据 $stuinfo = $excel->readXls(public_path().'public\\uploads\\'.$list['url']); + // 判断表格是否正确 if($stuinfo[0][2] != "序号" && $stuinfo[1][2] != "姓名" && $stuinfo[2][2] != "身份证号") { @@ -432,41 +433,84 @@ class Student extends BaseController // 删除标题行 array_splice($stuinfo,0,3); + $stuinfo = array_filter($stuinfo,function($q){ + return $q[1] != null && $q[2] != null && $q[3] != null; + }); + + + // 获取班级对应的入学年和排序 $bj = array_column($stuinfo, 3); - $bj = array_unique($bj); - foreach ($bj as $key => $value) { - if($value==null) - { - unset($bj[$key]); - }else{ - $bj[$key] = strBjmArray($value); - } + + // 获取班级名 + $bjStrName = array_unique($bj); + + + // 循环班级数组,查询数据,进行对比,并返回结果。 + foreach ($bjStrName as $key => $value) { + $myStuList = array(); + // 获取电子表格中本班级学生名单 + $myStuList = array_filter($stuinfo,function($q) use ($value){ + return $q[3] == $value; + }); + + $xlsStuList = array_column($myStuList, 2,0); + + + $bjid = strBjmArray($value,$list['school']); + + $serStulist = STU::withTrashed() + ->where('banji',$bjid) + ->field('id,xingming,shenfenzhenghao') + ->select(); + $sfzh = $serStulist->column('shenfenzhenghao','id'); + + // 返回数据对比结果 + $jiaoji = array_intersect($xlsStuList, $sfzh); #返回交集 + $add = array_diff($xlsStuList, $sfzh); + $del = array_diff($sfzh, $xlsStuList); + + dump($jiaoji); + dump($add); + halt($del); + + + halt($sfzh); + + + + + + halt($serStulist); + } + + foreach ($stuinfo as $key => $value) { + + } + + $sfzh = array_column($stuinfo, 2); +# code... + + + // 实例化班级数据模型 - $banji = new \app\teach\model\Banji; + // $banji = new \app\teach\model\Banji; - $djdata=array(); - foreach ($bj as $key => $value) { - $bjid = ''; - foreach ($stuinfo as $k => $val) { - // 如果姓名、身份证号为空则跳过 - if(empty($value[1]) || empty($value[2])) - { - $djdata[] = [ - 'row'=>$k, - 'msg'=>'缺少信息' - ]; - } - } - - - - - - - - } + // $djdata=array(); + // foreach ($bj as $key => $value) { + // $bjid = ''; + // foreach ($stuinfo as $k => $val) { + // // 如果姓名、身份证号为空则跳过 + // if(empty($value[1]) || empty($value[2])) + // { + // $djdata[] = [ + // 'row'=>$k, + // 'msg'=>'缺少信息' + // ]; + // } + // } + // } halt('aa'); diff --git a/app/renshi/model/Student.php b/app/renshi/model/Student.php index fee15ea5..f35db4fb 100644 --- a/app/renshi/model/Student.php +++ b/app/renshi/model/Student.php @@ -63,17 +63,15 @@ class Student extends Base 'banji'=>array(), 'searchval'=>'' ]; + // 用新值替换初始值 $src = array_cover( $srcfrom , $src ) ; - - // 获取参数 $school = $src['school']; $banji = $src['banji']; $searchval = $src['searchval']; - $data = $this ->order([$src['field'] =>$src['type']]) ->when(count($school)>0,function($query) use($school){