学生数据同步

This commit is contained in:
cxdbz committed 2019-12-22 19:26:48 +08:00
1 parent 0a65685e7a
commit bc1f32f12e
3 files changed
+87 -37

No files matched your search

+12 -4
View File
@@ -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;
}
+74 -30
View File
@@ -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');
+1 -3
View File
@@ -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){