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"} -
+
@@ -10,22 +10,22 @@
- +
- +
- +
- +
@@ -39,9 +39,9 @@
- + {php} $school = new app\system\model\School; $school = $school->where('jibie','>',1)->field('id,title')->all();{/php} - {volist name="school" id="vo"} @@ -86,51 +86,40 @@ {block name="yanzheng"} {/block} \ No newline at end of file diff --git a/application/renshi/view/student/edit.html b/application/renshi/view/student/edit.html index a494e0f8..0820e243 100644 --- a/application/renshi/view/student/edit.html +++ b/application/renshi/view/student/edit.html @@ -1,116 +1,93 @@ {extend name="common@create" /} {block name="formaa"} - +
- +
- +
- +
- - +
- - + +
- +
- +
- +
- +
- - {php} $school = new app\system\model\School; $category = $school->where('jibie','>',1)->field('id,title,jiancheng')->all();{/php} - - {volist name="category" id="vo"} - + {volist name="school" id="vo"} + {/volist}
- +
- {php}$category = getCategory(107);{/php} - + + {foreach $njlist as $key=>$vo} + + {/foreach}
+ {php} + $bjlist = $banji::where('ruxuenian',$bj->ruxuenian)->select(); + $bjlist = $bjlist->append(['title'])->visible(['id','title']); + {/php}
- +
- {php}$category = getCategory(106);{/php} - + + {volist name="bjlist" id="vo"} + {/volist}
-
- -
- - {php}$category = getCategory(105);{/php} - - -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
@@ -120,73 +97,79 @@ {/block} {block name="yanzheng"} {/block} \ No newline at end of file diff --git a/application/renshi/view/student/index.html b/application/renshi/view/student/index.html index 3dd96b8f..3a86c3b8 100644 --- a/application/renshi/view/student/index.html +++ b/application/renshi/view/student/index.html @@ -72,7 +72,7 @@ { "data": "sex" }, { "data": "age" ,"defaultContent": ""}, { "data": "school" }, - { "data": "banji" }, + { "data": "banjititle" }, { "data": "status" }, { "data": "id" }, ]; diff --git a/database/migrations/20181102003411_student.php b/database/migrations/20181102003411_student.php index 861711b3..bb300881 100644 --- a/database/migrations/20181102003411_student.php +++ b/database/migrations/20181102003411_student.php @@ -33,16 +33,17 @@ class Student extends Migrator // 添加当前表字段 $table - ->addColumn('xingming','string',['limit'=>8,'null'=>false,'comment'=>'姓名']) + ->addColumn('xingming','string',['limit'=>5,'null'=>false,'comment'=>'姓名']) ->addColumn('sex','boolean',['limit'=>1,'default'=>1,'null'=>false,'comment'=>'性别']) ->addColumn('shengri','integer',['limit'=>11,'null'=>false,'comment'=>'生日']) - ->addColumn('shenfenzhenghao','integer',['limit'=>18,'null'=>false,'comment'=>'身份证号']) + ->addColumn('shenfenzhenghao','string',['limit'=>18,'null'=>false,'comment'=>'身份证号']) ->addColumn('school','integer',['limit'=>11,'null'=>false,'comment'=>'学校']) ->addColumn('banji','integer',['limit'=>11,'null'=>false,'comment'=>'班级']) ->addColumn('create_time','integer',['limit'=>11,'null'=>true,'comment'=>'创建时间']) ->addColumn('update_time','integer',['limit'=>11,'null'=>true,'comment'=>'更新时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) ->addColumn('status','boolean',['limit'=>1,'default'=>'1','null'=>false,'comment'=>'0=禁用,1=正常']) + ->addIndex(array('shenfenzhenghao'), array('unique' => true)) ->create(); } } diff --git a/database/seeds/Rule.php b/database/seeds/Rule.php index 61ce2e30..3816f0c2 100644 --- a/database/seeds/Rule.php +++ b/database/seeds/Rule.php @@ -84,7 +84,7 @@ class Rule extends Seeder ['title'=>'编辑','name'=>'renshi/Student/edit','paixu'=>3,'pid'=>42,], ['title'=>'查看','name'=>'renshi/Student/read','paixu'=>4,'pid'=>42,], ['title'=>'状态','name'=>'renshi/Student/status','paixu'=>5,'pid'=>42], - ['title'=>'批传','name'=>'renshi/Student/createAll','paixu'=>,'pid'=>42], + ['title'=>'批传','name'=>'renshi/Student/createAll','paixu'=>'6','pid'=>42], // 系统设置