diff --git a/app/login/controller/Index.php b/app/login/controller/Index.php index a2fdc472..c88ec87e 100755 --- a/app/login/controller/Index.php +++ b/app/login/controller/Index.php @@ -128,12 +128,14 @@ class Index extends BaseController // 错误页面 - public function myerror() + public function myerror($msg = "") { // 获取系统名称和版本号 $list['webtitle'] = config('shangma.webtitle'); $list['version'] = config('shangma.version'); + $list['msg'] = $msg; + $this->view->assign('list',$list); // 渲染输出 diff --git a/app/login/route/login.php b/app/login/route/login.php index 6f172aee..c58b5710 100755 --- a/app/login/route/login.php +++ b/app/login/route/login.php @@ -17,6 +17,6 @@ Route::group('', function () { Route::rule('', 'Index/admin', 'post'); Route::rule('student', 'Index/student', 'post'); Route::rule('log', 'Index/shangmaLog', 'get'); # 配置更新 - Route::rule('err', 'Index/myerror', 'get'); //错误页 + Route::rule('err/', 'Index/myerror', 'get'); //错误页 Route::rule('weihu', 'Index/weihu', 'get'); //错误页 }); \ No newline at end of file diff --git a/app/login/view/index/myerror.html b/app/login/view/index/myerror.html index 7a4ab6de..1f809d06 100755 --- a/app/login/view/index/myerror.html +++ b/app/login/view/index/myerror.html @@ -24,7 +24,7 @@

-

页面或者数据被 纸飞机 运到火星了,啥都看不到了…

+

{$list.msg}

diff --git a/app/student/controller/Index.php b/app/student/controller/Index.php index 00fe0b1e..66a0ef67 100755 --- a/app/student/controller/Index.php +++ b/app/student/controller/Index.php @@ -447,16 +447,18 @@ class Index extends AdminBase $fengefu = DIRECTORY_SEPARATOR; // 读取表格数据 $stuinfo = \app\facade\File::readXls(public_path() . 'uploads' . $fengefu . $list['url']); - if($stuinfo[0][2] != "序号" && $stuinfo[1][2] != "姓名" && $stuinfo[2][2] != "身份证号") + if($stuinfo[0][2] != "序号" && $stuinfo[1][2] != "姓名" && $stuinfo[2][2] != "学号" && $stuinfo[3][2] != "身份证号") { - $data = array('msg'=>'请使用模板上传','val'=>0,'url'=>''); - return json($data); + \app\facade\OnLine::jump('/login/err', '请使用模板上传'); + return true; } // 同步学生信息并返回数据库中多的信息 $stu = new STU; $delStuList = $stu->tongBu($stuinfo, $list['school_id']); + halt('同步完成'); + // 获取学校名称 $sch = new \app\system\model\School; $sch = $sch->where('id', $list['school_id'])->value('jiancheng'); diff --git a/app/student/model/Student.php b/app/student/model/Student.php index 87723b8c..862fb229 100755 --- a/app/student/model/Student.php +++ b/app/student/model/Student.php @@ -263,14 +263,16 @@ class Student extends BaseModel // 同步表格数据 public function tongBu($stuinfo, $school_id) { + // 实例验证 + $validate = new \app\student\validate\Student; // 整理数据 array_splice($stuinfo, 0, 4); # 删除标题行 $stuinfo = array_filter($stuinfo, function($q){ ## 过滤姓名、身份证号或班级为空的数据 - return $q[1] != null && strlen($q[2]) >=6 && $q[3] != null; + return $q[1] != null && strlen($q[3]) >=6 && $q[4] != null; }); // 获取班级信息 - $bj = array_column($stuinfo, 3); + $bj = array_column($stuinfo, 4); $arr = array_unique($bj); $bjStrName = array(); # 找不同班级 $bjmod = new \app\teach\model\Banji; @@ -297,7 +299,7 @@ class Student extends BaseModel $arr = array(); foreach ($bjStrName as $sbj_k => $sbj_val) { foreach ($stuinfo as $stu_k => $stu_val) { - if($stu_val[3] == $sbj_val) + if($stu_val[4] == $sbj_val) { $arr[$sbj_k][] = $stu_val; unset($stuinfo[$stu_k]); @@ -309,8 +311,9 @@ class Student extends BaseModel $pinyin = new \Overtrue\Pinyin\Pinyin; // 循环班级数组,查询数据,进行对比,并返回结果。 foreach ($arr as $key => $value) { + $ruxuenian = $bjmod->where('id', $key)->value('ruxuenian'); // 获取电子表格中身份证号 - $xlsStuList = array_column($value, 2); + $xlsStuList = array_column($value, 3); $xlsStuList = array_map('strtoupper', $xlsStuList); # 将小写字母转换成大写字母 $xlsStuList = array_map('trim', $xlsStuList); # 过滤空格 @@ -344,7 +347,7 @@ class Student extends BaseModel foreach ($jiaoji as $jj_k => $jj_val) { $oneStu = self::withTrashed() ->where('shenfenzhenghao', $jj_val) - ->field('id, xingming, banji_id, quanpin, shoupin, delete_time') + ->field('id, xingming, sex, xuehao, banji_id, quanpin, shoupin, shenfenzhenghao, kaoshi, delete_time') ->find(); if($oneStu->delete_time > 0) { @@ -354,41 +357,90 @@ class Student extends BaseModel $quanpin = $pinyin->sentence($value[$jj_k][1]); $shoupin = $pinyin->abbr($value[$jj_k][1]); - $oneStu->xingming = $value[$jj_k][1]; - $oneStu->banji_id = $key; - $oneStu->quanpin = trim(strtolower(str_replace(' ', '', $quanpin))); - $oneStu->shoupin = trim(strtolower(str_replace(' ', '', $shoupin))); - $oneStu->save(); + $upTemp = array(); + $upTemp = [ + 'id' => $oneStu->id + ,'xingming' => $value[$jj_k][1] + ,'sex' => $oneStu->getdata('sex') + ,'banji_id' => $key + ,'shenfenzhenghao' => $oneStu->shenfenzhenghao + ,'kaoshi' => $oneStu->getdata('kaoshi') + ,'xuehao' => $value[$jj_k][2] + ,'quanpin' => trim(strtolower(str_replace(' ', '', $quanpin))) + ,'shoupin' => trim(strtolower(str_replace(' ', '', $shoupin))) + ,'delete_time' => null + ]; + + $result = $validate->scene('edit')->check($upTemp); + $msg = $validate->getError(); + if($result){ + self::update($upTemp); + } } // 新增数据 $pinyin = new \Overtrue\Pinyin\Pinyin; $list = array(); foreach ($add as $add_k => $add_val) { - $sfzhval = strtoupper(trim($value[$add_k][2])); + $sfzhval = strtoupper(trim($value[$add_k][3])); $quanpin = $pinyin->sentence($value[$add_k][1]); $shoupin = $pinyin->abbr($value[$add_k][1]); + if(strlen($sfzhval) == 18) + { + $shengri = substr($sfzhval, 6, 4) . '-' . substr($sfzhval, 10, 2) . '-' . substr($sfzhval, 12, 2); + if(is_numeric(substr($sfzhval,16,1))){ + $sex = substr($sfzhval,16,1) % 2; + } else { + $sex = 2; + } + }else{ + $shengri = '1970-1-1'; + $sex = 2; + } + $list[$add_k] = [ 'xingming' => $value[$add_k][1] + ,'sex' => $sex + ,'shengri' => $shengri ,'shenfenzhenghao' => $sfzhval + ,'ruxuenian' => $ruxuenian ,'banji_id' => $key + ,'kaoshi' => 1 + ,'xuehao' => $value[$add_k][2] ,'quanpin' => trim(strtolower(str_replace(' ', '', $quanpin))) ,'shoupin' => trim(strtolower(str_replace(' ', '', $shoupin))) ]; - - - if(strlen($sfzhval) == 18) - { - $list[$add_k]['shengri'] = substr($sfzhval, 6, 4) . '-' . substr($sfzhval, 10, 2) . '-' . substr($sfzhval, 12, 2); - intval(substr($sfzhval,16,1) )% 2 ? $sex = 1 :$sex = 0 ; - $list[$add_k]['sex'] = $sex; - }else{ - $list[$add_k]['shengri'] = '1970-1-1'; - $list[$add_k]['sex'] = 2; + $result = $validate->scene('create')->check($list[$add_k]); + if(!$result){ + unset($list[$add_k]); } } + + // 获取去掉重复数据的数组 + $sfzh = array_column($list,'shenfenzhenghao'); + $unique_arr = array_unique($sfzh); + // 获取重复数据的数组 + $repeat_arr = array_diff_assoc($sfzh, $unique_arr); + if(count($repeat_arr) > 0) + { + $data = "电子表中身份证号:"; + $i = 0; + foreach ($repeat_arr as $repeat_k => $repeat_v) { + if($i == 0) + { + $data = $data . $repeat_v; + } else { + $data = $data . '、' . $repeat_v; + } + $i ++; + } + $data = $data . '重复。'; + \app\facade\OnLine::jump('/login/err', ""); + halt($data); + } + self::saveAll($list); // 删除数据 @@ -401,6 +453,7 @@ class Student extends BaseModel ]; } } + return $delarr; } diff --git a/app/student/validate/Student.php b/app/student/validate/Student.php index f9d677cc..a9921d9c 100755 --- a/app/student/validate/Student.php +++ b/app/student/validate/Student.php @@ -16,13 +16,13 @@ class Student extends Validate 'id|ID' => 'require|number', 'xingming|姓名' => 'require|chs|length:2,8', 'sex|性别' => 'require|boolean', - 'shengri|出生日期' => 'date', - 'shenfenzhenghao|身份证号' => "require|idCard", + 'shengri|出生日期' => 'require|date', + 'shenfenzhenghao|身份证号' => "require|idCard|unique:student", 'ruxuenian|年级' => 'require|number', 'banji_id|班级' => 'require|number', 'kaoshi|是否参加考试' => 'require|number', 'quanpin|姓名全拼' => 'require', - 'xuehao|考号' => 'alphaNum|max:25' + 'xuehao|学号' => 'alphaNum|max:25' ]; /** @@ -36,6 +36,7 @@ class Student extends Validate protected $scene = [ 'create' => [ 'xingming' + ,'shengri' ,'sex' ,'shenfenzhenghao' ,'ruxuenian' diff --git a/app/student/view/index/create.html b/app/student/view/index/create.html index c85ef7ac..03a68a8d 100755 --- a/app/student/view/index/create.html +++ b/app/student/view/index/create.html @@ -54,14 +54,16 @@
- +
- +
@@ -76,10 +78,10 @@
- +
diff --git a/app/teach/model/Banji.php b/app/teach/model/Banji.php index 11082803..b489875b 100755 --- a/app/teach/model/Banji.php +++ b/app/teach/model/Banji.php @@ -275,9 +275,15 @@ class Banji extends BaseModel // 查询班级id $banji = new \app\teach\model\Banji; $id = $banji->where('ruxuenian', $nj) - ->when($alias->classalias === 1, function ($query) use($str) { + ->when($alias->classalias === 1, function ($query) use($str, $bj) { $query - ->where('alias', substr_replace($str, '', strlen($str) - 3)); + ->when($bj === -1, function ($q) use($str) { + $q + ->where('alias', substr_replace($str, '', strlen($str) - 3)); + }, function ($q) use($bj) { + $q + ->where('paixu', $bj); + }); }, function ($query) use($bj) { $query->where('paixu', $bj); }) diff --git a/app/tools/controller/OnLine.php b/app/tools/controller/OnLine.php index dd4a6c76..c52343b9 100755 --- a/app/tools/controller/OnLine.php +++ b/app/tools/controller/OnLine.php @@ -7,19 +7,25 @@ class OnLine { use \liliuwei\think\Jump; // 将关联学生成绩转换成以学科列名为key得分为value的数组 - public function jump($url = '', $msg = '') + public function jump($url = '/login/err', $msg = '') { + $ser = request()->domain(); + if($msg == "") + { + $msg = "页面或者数据被 纸飞机 运到火星了,啥都看不到了…"; + } + $isajax = request()->isAjax(); if($isajax) { - $this->error($msg, '/login/err'); + $this->error($msg, $url); }else{ + $url = $ser . $url . '/' . $msg; echo ""; } return true; } - // 获取用户信息 public function myInfo() { diff --git a/database/migrations/20181102003411_student.php b/database/migrations/20181102003411_student.php index c87c2bb8..f3dbc82f 100755 --- a/database/migrations/20181102003411_student.php +++ b/database/migrations/20181102003411_student.php @@ -34,7 +34,7 @@ class Student extends Migrator // 添加当前表字段 $table ->addColumn('xingming','string',['limit'=>5,'default'=>'a','null'=>false,'comment'=>'姓名']) - ->addColumn('sex','boolean',['limit'=>1,'default'=>1,'null'=>false,'comment'=>'性别']) + ->addColumn('sex','boolean',['limit'=>1,'default'=>1,'null'=>false,'comment'=>'性别 0=女,1=男,2=未知']) ->addColumn('shengri','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'生日']) ->addColumn('shenfenzhenghao','string',['limit'=>18,'default'=>'N1539158918','null'=>false,'comment'=>'身份证号']) ->addColumn('password','string',['limit'=>137,'null'=>false,'default'=>'$apr1$oz6tgaAl$ix4GBv0VxcnVJPIiodXUY/','comment'=>'登录密码'])