diff --git a/application/common.php b/application/common.php index 2ff5ec60..075bc13c 100644 --- a/application/common.php +++ b/application/common.php @@ -93,3 +93,33 @@ function banjinamelist() return $bjarr; } + + +/** +* $date是时间戳 +* $type为1的时候是虚岁,2的时候是周岁 +*/ +function getAgeByBirth($date,$type = 1){ + $nowYear = date("Y",time()); + $nowMonth = date("m",time()); + $nowDay = date("d",time()); + $birthYear = date("Y",$date); + $birthMonth = date("m",$date); + $birthDay = date("d",$date); + if($type == 1){ + $age = $nowYear - ($birthYear - 1); + }elseif($type == 2){ + if($nowMonth<$birthMonth){ + $age = $nowYear - $birthYear - 1; + }elseif($nowMonth==$birthMonth){ + if($nowDay<$birthDay){ + $age = $nowYear - $birthYear - 1; + }else{ + $age = $nowYear - $birthYear; + } + }else{ + $age = $nowYear - $birthYear; + } + } + return $age; +} diff --git a/application/renshi/controller/Index.php b/application/renshi/controller/Index.php index 108e8baa..c55069c0 100644 --- a/application/renshi/controller/Index.php +++ b/application/renshi/controller/Index.php @@ -69,6 +69,7 @@ class Index extends Base } $datacnt = $data->count(); + $data = $data->append(['age']); diff --git a/application/renshi/controller/Student.php b/application/renshi/controller/Student.php index 63996564..73972dc5 100644 --- a/application/renshi/controller/Student.php +++ b/application/renshi/controller/Student.php @@ -53,7 +53,7 @@ class Student extends Base // 获取记录集总数 $cnt = STU::count(); //查询数据 - $data =STU::field('id,xingming,sex,shengri,status') + $data =STU::field('id,xingming,sex,shengri,banji,school,status') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) ->all(); @@ -61,14 +61,18 @@ class Student extends Base // 如果需要查询 if($search){ - $data = STU::field('id,xingming,sex,shengri,status') + $data = STU::field('id,xingming,sex,shengri,banji,school,status') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) - ->where('xingming','like','%'.$search.'%') + ->whereOr('xingming','like','%'.$search.'%') + ->whereOr('school','in',function($query) use($search){ + $query->name('school')->where('title','like','%'.$search.'%')->field('id'); + }) ->all(); } $datacnt = $data->count(); + $data = $data->append(['banjititle','age']); @@ -108,8 +112,7 @@ class Student extends Base // 获取表单数据 - $list = request()->only(['xingming','sex','quanpin','shoupin','shengri','zhiwu','zhicheng','xueli','biye','worktime','zhuanye','danwei'],'post'); - + $list = request()->only(['xingming','sex','shenfenzhenghao','shengri','school','ruxuenian','banji'],'post'); // 验证表单数据 $result = $validate->check($list); @@ -145,7 +148,7 @@ class Student extends Base { // 获取学生信息 - $list = STU::field('id,xingming,sex,quanpin,shoupin,shengri,zhiwu,zhicheng,xueli,biye,worktime,zhuanye,danwei') + $list = STU::field('id,xingming,sex,shenfenzhenghao,shengri,banji,school,status') ->get($id); @@ -164,7 +167,7 @@ class Student extends Base $validate = new \app\renshi\validate\Student; // 获取表单数据 - $list = request()->only(['xingming','sex','quanpin','shoupin','shengri','zhiwu','zhicheng','xueli','biye','worktime','zhuanye','danwei'],'put'); + $list = request()->only(['xingming','sex','shengri','school','shenfenzhenghao','ruxuenian','banji'],'put'); // 验证表单数据 $result = $validate->check($list); @@ -177,9 +180,8 @@ class Student extends Base // 更新数据 - $teacher = new Teacher(); - $data = $teacher->save($list,['id'=>$id]); - // $data = STU::where('id',$id)->update($list); + $stu = new STU(); + $data = $stu->save($list,['id'=>$id]); // 根据更新结果设置返回提示信息 $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; diff --git a/application/renshi/model/Student.php b/application/renshi/model/Student.php index 478e1773..f0ba8be0 100644 --- a/application/renshi/model/Student.php +++ b/application/renshi/model/Student.php @@ -3,8 +3,56 @@ namespace app\renshi\model; use app\common\model\Base; +use app\teach\model\Banji; class Student extends Base { - // + // 年龄获取器 + public function getAgeAttr() + { + return getAgeByBirth($this->getdata('shengri'),2); + } + + // 班级获取器 + public function getBanjititleAttr() + { + $bj = Banji::get($this->banji); + $bj = $bj->append(['title']); + return $bj->title; + } + + // 学校获取器 + public function getSchoolAttr($value) + { + return db('school')->where('id',$value)->value('title'); + } + + // 生日修改器 + public function setShengriAttr($value) + { + return strtotime($value); + } + + // 生日获取器 + public function getShengriAttr($value) + { + return date('Y-m-d',$value); + } + + // 性别获取器 + public function getSexAttr($value) + { + $sex = array('0'=>'女','1'=>'男','2'=>'保密'); + return $sex[$value]; + } + + // 性别获取器 + public function setSexAttr($value) + { + $sex = array('0'=>'女','1'=>'男','2'=>'保密'); + $val = array_search($value,$sex); + return $val; + } + + } diff --git a/application/renshi/model/Teacher.php b/application/renshi/model/Teacher.php index d7bfc2d0..51b4301d 100644 --- a/application/renshi/model/Teacher.php +++ b/application/renshi/model/Teacher.php @@ -74,5 +74,11 @@ class Teacher extends Base return $this->getcategory($value); } + // 年龄获取器 + public function getAgeAttr() + { + return getAgeByBirth($this->getdata('shengri'),2); + } + } diff --git a/application/renshi/validate/Student.php b/application/renshi/validate/Student.php index f02288f3..485d26f4 100644 --- a/application/renshi/validate/Student.php +++ b/application/renshi/validate/Student.php @@ -12,7 +12,15 @@ class Student extends Validate * * @var array */ - protected $rule = []; + protected $rule = [ + 'xingming|姓名' => 'require|chs|length:2,8', + 'sex|性别' => 'require|chs|max:2', + 'shengri|出生日期' => 'date', + 'shenfenzhenghao|身份证号' => "require|idCard", + 'school|学校' => 'require|number', + 'ruxuenian|年级' => 'require|number', + 'banji|班级' => 'require|number' + ]; /** * 定义错误信息 diff --git a/application/renshi/view/student/create.html b/application/renshi/view/student/create.html index ec5c7ef7..fe3e9764 100644 --- a/application/renshi/view/student/create.html +++ b/application/renshi/view/student/create.html @@ -1,6 +1,6 @@ {extend name="common@create" /} {block name="formaa"} -