From 69bca29056cb5aa665b428bbebb4adbf2a8f06c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8E=8C?= Date: Sun, 20 Sep 2020 21:05:49 +0800 Subject: [PATCH] 0 --- app/admin/controller/AuthGroup.php | 1 + app/teach/controller/BanZhuRen.php | 176 ++++++++++++++++++ app/teach/controller/Banji.php | 59 ------ app/teach/model/BanZhuRen.php | 82 ++++++++ app/teach/model/Banji.php | 30 ++- app/teach/route/teach.php | 15 +- app/teach/view/ban_zhu_ren/create.html | 86 +++++++++ app/teach/view/ban_zhu_ren/index.html | 123 ++++++++++++ app/teach/view/banji/banzhuren.html | 122 ------------ app/teach/view/banji/index.html | 24 ++- database/migrations/20181102004156_banji.php | 1 - .../migrations/20200911063240_ban_zhu_ren.php | 4 +- database/seeds/Rule.php | 62 ++++-- 13 files changed, 564 insertions(+), 221 deletions(-) create mode 100644 app/teach/controller/BanZhuRen.php create mode 100644 app/teach/model/BanZhuRen.php create mode 100644 app/teach/view/ban_zhu_ren/create.html create mode 100644 app/teach/view/ban_zhu_ren/index.html delete mode 100644 app/teach/view/banji/banzhuren.html diff --git a/app/admin/controller/AuthGroup.php b/app/admin/controller/AuthGroup.php index 8349c60f..1abfb052 100644 --- a/app/admin/controller/AuthGroup.php +++ b/app/admin/controller/AuthGroup.php @@ -65,6 +65,7 @@ class AuthGroup extends AdminBase $ruleSelect = array(); $auth = $rule->digui($ruleList, $ruleSelect); # 递归获取所有权限 $list['auth'] = $auth; + // halt($auth); // 模板赋值 $this->view->assign('list', $list); diff --git a/app/teach/controller/BanZhuRen.php b/app/teach/controller/BanZhuRen.php new file mode 100644 index 00000000..1548eba0 --- /dev/null +++ b/app/teach/controller/BanZhuRen.php @@ -0,0 +1,176 @@ +where('id', $banji_id) + ->append(['banjiTitle']) + ->find(); + $list['bjTitle'] = $bjInfo->banjiTitle; + + // 模板赋值 + $this->view->assign('list', $list); + + // 渲染模板 + return $this->view->fetch(); + } + + + // 获取班主任列表 + public function ajaxData() + { + // 获取参数 + $src = $this->request + ->only([ + 'page' => '1' + ,'limit' => '10' + ,'field' => 'bfdate' + ,'order' => 'desc' + ,'banji_id' => '' + ], 'POST'); + + // 查询数据 + $bzr = new bzr; + $data = $bzr->search($src) + ->visible([ + 'id' + ,'glTeacher' => ['xingming'] + ,'banji_id' + ,'teacher_id' + ,'bfdate' + ,'update_time' + ]); # 查询数据 + $data = reSetObject($data, $src); + + // 返回数据 + return json($data); + } + + + + public function create($banji_id) + { + // 设置页面标题 + $list['set'] = array( + 'webtitle' => '添加班主任' + ,'butname' => '添加' + ,'formpost' => 'POST' + ,'url' => 'save' + ,'banji_id' => $banji_id + ); + + // 模板赋值 + $this->view->assign('list', $list); + // 渲染 + return $this->view->fetch('chengji@create'); + } + + + /** + * 保存班级 + * + * @return \think\Response + */ + public function save() + { + // 获取表单数据 + $list = request()->only([ + 'school_id' + ,'ruxuenian' + ,'bjsum' + ], 'post'); + + // 验证表单数据 + $validate = new \app\teach\validate\Banji; + $result = $validate->scene('create')->check($list); + $msg = $validate->getError(); + if(!$result) + { + return json(['msg' => $msg, 'val' => 0]); + } + + // 整理要添加的数据 + $paixumax = bjmod::where('school_id', $list['school_id']) + ->where('ruxuenian', $list['ruxuenian']) + ->max('paixu'); + + // 获取班级最大数 + $cnfMax = \app\facade\System::sysClass(); + + if($paixumax + $list['bjsum'] > $cnfMax->classmax) # 如果增加班级数超过2个,则少加班级 + { + if($paixumax >= $cnfMax) + { + return json(['msg' => '已经超过同年级班级数的上线啦。', 'val' => 0]); + } + if($paixumax + $list['bjsum'] > $cnfMax) # 如果增加班级数超过2个,则少加班级 + { + $list['bjsum'] = $cnfMax - $paixumax; + } + } + + $i = 1; + while($i <= $list['bjsum']) + { + $bjarr[] = array( + 'school_id' => $list['school_id'], + 'ruxuenian' => $list['ruxuenian'], + 'paixu' => $paixumax + $i, + ); + $i ++; + } + + // 保存数据 + $bj = new bjmod(); + $data = $bj->saveAll($bjarr); + + // 根据更新结果设置返回提示信息 + $data ? $data = ['msg' => '添加成功', 'val'=>1] + : $data = ['msg' => '数据处理错误', 'val' => 0]; + + // 返回信息 + return json($data); + } + + + /** + * 删除班级 + * + * @return \think\Response + */ + public function delete($id) + { + + $id = request()->delete('id'); + $id = explode(',', $id); + + $data = bjmod::destroy($id); + + // 根据更新结果设置返回提示信息 + $data ? $data = ['msg' => '删除成功', 'val' => 1] + : $data = ['msg' => '数据处理错误', 'val' => 0]; + + // 返回信息 + return json($data); + } + + +} diff --git a/app/teach/controller/Banji.php b/app/teach/controller/Banji.php index 67957de2..fe436a77 100644 --- a/app/teach/controller/Banji.php +++ b/app/teach/controller/Banji.php @@ -381,64 +381,5 @@ class Banji extends AdminBase } - // 设置班主任 - public function banzhuren($id) - { - $list['data']['id'] = $id; - $bj = new bjmod; - $bjInfo = $bj->where('id', $id) - ->field('id, school_id, banzhuren') - ->with([ - 'glTeacher' => function ($query) { - $query->field('id, xingming'); - } - ]) - ->find(); - $list['data'] = $bjInfo; - - // 设置页面标题 - $list['set'] = array( - 'webtitle'=>'设置班主任' - ,'butname'=>'设置' - ,'formpost'=>'PUT' - ,'url'=>'/teach/banji/updatebanzhuren/' . $id, - ); - - // 模板赋值 - $this->view->assign('list', $list); - // 渲染 - return $this->view->fetch(); - } - - - // 更新班主任 - public function updatebanzhuren($id) - { - // 获取参数 - $src = $this->request - ->only([ - 'banzhuren' => '' - ,'id' => '' - ], 'POST'); - - // 验证表单数据 - $validate = new \app\teach\validate\Banji; - $result = $validate->scene('banzhuren')->check($src); - $msg = $validate->getError(); - if(!$result){ - return json(['msg'=>$msg,'val'=>0]);; - } - - // 更新数据 - $bjInfo = bjmod::find($id); - $bjInfo->banzhuren = $src['banzhuren']; - $data = $bjInfo->save(); - - $data ? $data = ['msg' => '设置成功', 'val' => 1] - : $data = ['msg' => '数据处理错误', 'val' => 0]; - - // 返回信息 - return json($data); - } } diff --git a/app/teach/model/BanZhuRen.php b/app/teach/model/BanZhuRen.php new file mode 100644 index 00000000..9cbd6a90 --- /dev/null +++ b/app/teach/model/BanZhuRen.php @@ -0,0 +1,82 @@ +belongsTo('\app\teacher\model\Teacher', 'teacher_id', 'id'); + } + + + // 教师关联模型 + public function glBanji() + { + return $this->belongsTo('\app\teach\model\Banji', 'banji_id', 'id'); + } + + + // 生日获取器 + public function getBfdateAttr($value) + { + return date('Y-m-d',$value); + } + + + // 根据条件查询学期 + public function search($srcfrom) + { + // 整理变量 + $src = [ + 'banji_id' => '' + ,'teacher_id' => '' + ,'bfdate' => '' + ,'enddate' => '' + ]; + $src = array_cover($srcfrom, $src) ; + $src['banji_id'] = strToarray($src['banji_id']); + $src['teacher_id'] = strToarray($src['teacher_id']); + if(isset($srcfrom['bfdate']) && strlen($srcfrom['bfdate']) > 0) + { + $src['bfdate'] = $srcfrom['bfdate']; + }else{ + $src['bfdate'] = date("Y-m-d", strtotime("-6 year")); + } + if(isset($srcfrom['enddate']) && strlen($srcfrom['enddate']) > 0) + { + $src['enddate'] = $srcfrom['enddate']; + }else{ + $src['enddate'] = date("Y-m-d", strtotime('now')); + } + + // 查询数据 + $data = $this + ->whereTime('bfdate', 'between', [$src['bfdate'], $src['enddate']]) + ->when(count($src['banji_id']) > 0, function($query) use($src){ + $query->where('banji_id', $src['banji_id']); + }) + ->when(count($src['teacher_id']) > 0, function($query) use($src){ + $query->where('teacher_id', $src['teacher_id']); + }) + ->with( + [ + 'glTeacher'=>function($query){ + $query->field('id, xingming'); + }, + ] + ) + ->select(); + + return $data; + } + +} diff --git a/app/teach/model/Banji.php b/app/teach/model/Banji.php index a8b66c9b..e5e11b28 100644 --- a/app/teach/model/Banji.php +++ b/app/teach/model/Banji.php @@ -39,12 +39,19 @@ class Banji extends BaseModel }) ->with( [ - 'glSchool'=>function($query){ + 'glSchool' => function($query){ $query->field('id, title, jiancheng'); }, - 'glTeacher'=>function($query){ - $query->field('id, xingming'); - }, + 'glBanZhuRen' => function ($query) { + $query->field('id, teacher_id, banji_id, bfdate') + ->with([ + 'glTeacher' => function($q) { + $q->field('id, xingming'); + } + ]) + ->withLimit(1) + ->order(['bfdate' => 'desc', 'id' => 'desc']); + } ] ) ->withCount([ @@ -105,12 +112,6 @@ class Banji extends BaseModel } - // 学校关联模型 - public function glTeacher(){ - return $this->belongsTo('\app\teacher\model\Teacher', 'banzhuren', 'id'); - } - - // 年级-班级关联表 public function njBanji() { @@ -118,6 +119,15 @@ class Banji extends BaseModel } + // 年级-班级关联表 + public function glBanZhuRen() + { + return $this->hasMany('BanZhuRen', 'banji_id', 'id') + ->limit(1) + ->order(['update_time' => 'desc']); + } + + // 班级名获取器 public function getNumTitleAttr() { diff --git a/app/teach/route/teach.php b/app/teach/route/teach.php index a6e5117a..265dd8a3 100644 --- a/app/teach/route/teach.php +++ b/app/teach/route/teach.php @@ -35,8 +35,6 @@ Route::group('banji', function () { Route::rule('mybanji','banji/mybanji','post'); # 删除信息 Route::rule('mybanjis','banji/banjiList','post'); # 删除信息 Route::rule('alias','banji/setAlias','put'); # 删除信息 - Route::rule('banzhuren/','banji/banzhuren','get'); # 修改信息 - Route::rule('updatebanzhuren/','banji/updatebanzhuren','put'); # 更新信息 }); @@ -63,4 +61,17 @@ Route::group('subject', function () { }); +// 班主任管理 +Route::group('banzhuren', function () { + Route::rule('index/','BanZhuRen/index','get'); # 信息列表 + Route::rule('data','BanZhuRen/ajaxdata','post'); # 获取数据 + Route::rule('create/','BanZhuRen/create','get'); # 添加信息 + Route::rule('save','BanZhuRen/save','post'); # 保存信息 + Route::rule('edit/','BanZhuRen/edit','get'); # 修改信息 + Route::rule('update/','BanZhuRen/update','put'); # 更新信息 + Route::rule('delete/','BanZhuRen/delete','delete'); # 删除信息 + Route::rule('status','BanZhuRen/setStatus','post'); # 删除信息 + }); + + diff --git a/app/teach/view/ban_zhu_ren/create.html b/app/teach/view/ban_zhu_ren/create.html new file mode 100644 index 00000000..15f791c9 --- /dev/null +++ b/app/teach/view/ban_zhu_ren/create.html @@ -0,0 +1,86 @@ +{extend name=".././view/create.html" /} + +{block name="form"} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {php} $category = categoryChildren('108');{/php} + +
+
+
+
+ +
+ +
+
+ +
+
+
+
+ +
+
+{/block} + +{block name="myjs"} + +{/block} + diff --git a/app/teach/view/ban_zhu_ren/index.html b/app/teach/view/ban_zhu_ren/index.html new file mode 100644 index 00000000..cc475c6a --- /dev/null +++ b/app/teach/view/ban_zhu_ren/index.html @@ -0,0 +1,123 @@ + +{extend name=".././view/list.html" /} +{block name="jsset"} + +{/block} +{block name="nav"} + + 系统管理 + 教务管理 + 班级列表 + {$list.bjTitle} + 班主任列表 + +{/block} +{block name="search"} +
+ +
+ +
+
+
+
+ +
+ +
+
+ +
+
+
+{/block} +{block name="table"} +
+{/block} +{block name="myjs"} + + + + + + +{/block} diff --git a/app/teach/view/banji/banzhuren.html b/app/teach/view/banji/banzhuren.html deleted file mode 100644 index fc7dbbb3..00000000 --- a/app/teach/view/banji/banzhuren.html +++ /dev/null @@ -1,122 +0,0 @@ -{extend name=".././view/create.html" /} - -{block name="form"} -
-
- -
- - - -
-
-
-
- -
-
-{/block} - -{block name="myjs"} - - - -{/block} - diff --git a/app/teach/view/banji/index.html b/app/teach/view/banji/index.html index 9eba37b2..8799809a 100644 --- a/app/teach/view/banji/index.html +++ b/app/teach/view/banji/index.html @@ -73,9 +73,15 @@ {field: 'alias', title: '别名', minWidth:60, edit:'text'}, {field: 'banzhuren', title: '班主任',sort: true, minWidth:60,templet:function(d){ var str=''; - if(d.glTeacher) + if(d.glBanZhuRen) { - str = d.glTeacher.xingming; + if(d.glBanZhuRen[0]) + { + if(d.glBanZhuRen[0].glTeacher) + { + str = d.glBanZhuRen[0].glTeacher.xingming; + } + } } return str; }}, @@ -109,10 +115,10 @@ layer.msg('暂时不允许删除'); break; var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值 - cjgl.delAll(checkStatus,'banji/delete','mytable'); + cjgl.delAll(checkStatus,'/teach/banji/delete','mytable'); break; case 'add': - cjgl.add('添加班级','banji/create','600','300'); + cjgl.add('添加班级','/teach/banji/create','600','300'); break; }; }); @@ -127,21 +133,21 @@ parent.xadmin.add_tab(obj.data.banjiTitle +'-考试成绩','/teach/banjicj/index/'+obj.data.id,'','',true); break; case 'befo':// 前移 - yidong(this,'banji/yidong/'+data.id,-1); + yidong(this,'/teach/banji/yidong/'+data.id,-1); break; case 'end':// 后移 - yidong(this,'banji/yidong/'+data.id,1); + yidong(this,'/teach/banji/yidong/'+data.id,1); break; case 'del':// 删除 layer.msg('暂时不允许删除'); break; - cjgl.del(obj,"banji/delete"); + cjgl.del(obj,"/teach/banji/delete"); break; case 'edit':// 编辑 - cjgl.add('编辑班级','banji/edit/'+obj.data.id,'600','300'); + cjgl.add('编辑班级','/teach/banji/edit/'+obj.data.id,'600','300'); break; case 'banzhuren': //编辑 - cjgl.add('设置班主任','banji/banzhuren/'+obj.data.id,'600','300'); + cjgl.addTab('设置班主任','/teach/banzhuren/index/'+obj.data.id,'','',true); break; }; }); diff --git a/database/migrations/20181102004156_banji.php b/database/migrations/20181102004156_banji.php index 1d4e6f61..540a927d 100644 --- a/database/migrations/20181102004156_banji.php +++ b/database/migrations/20181102004156_banji.php @@ -37,7 +37,6 @@ class Banji extends Migrator ->addColumn('ruxuenian','integer',['limit'=>4,'null'=>true,'comment'=>'入学年']) ->addColumn('xuanduan_id','integer',['limit'=>11,'null'=>true,'comment'=>'学段']) ->addColumn('paixu','integer',['limit'=>3,'default'=>'100','null'=>false,'comment'=>'排序']) - ->addColumn('banzhuren','integer',['limit'=>11,'null'=>true,'comment'=>'班主任']) ->addColumn('alias','string',['limit'=>24,'default'=>null,'null'=>true,'comment'=>'班级别名']) ->addColumn('create_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'创建时间']) ->addColumn('update_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'更新时间']) diff --git a/database/migrations/20200911063240_ban_zhu_ren.php b/database/migrations/20200911063240_ban_zhu_ren.php index 27ea7e31..3397f288 100644 --- a/database/migrations/20200911063240_ban_zhu_ren.php +++ b/database/migrations/20200911063240_ban_zhu_ren.php @@ -34,8 +34,8 @@ class BanZhuRen extends Migrator // 添加当前表字段 $table ->addColumn('teacher_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'教师ID']) - ->addColumn('zhiwu_id','integer',['limit'=>11,'null'=>true,'comment'=>'职务']) - + ->addColumn('banji_id','integer',['limit'=>11,'null'=>true,'comment'=>'职务']) + ->addColumn('bfdate','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'开始日期']) ->addColumn('create_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'创建时间']) ->addColumn('update_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'更新时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) diff --git a/database/seeds/Rule.php b/database/seeds/Rule.php index 9cfb54d3..2e7ef1e5 100644 --- a/database/seeds/Rule.php +++ b/database/seeds/Rule.php @@ -711,60 +711,90 @@ class Rule extends Seeder ,'pid' => 5 ,'url' => '/teach/banji' ], - ['id' => 500201 + ['id' => 50201 ,'title' => '添加' ,'name' => 'teach/banji/create' ,'paixu' => 1 ,'pid' => 502 ], - ['id' => 500202 + ['id' => 50202 ,'title' => '保存' ,'name' => 'teach/banji/save' ,'paixu' => 2 ,'pid' => 502 ], - ['id' => 500203 + ['id' => 50203 ,'title' => '移动' ,'name' => 'teach/banji/yidong' ,'paixu' => 3 ,'pid' => 502 ], - ['id' => 500204 + ['id' => 50204 ,'title' => '删除' ,'name' => 'teach/banji/delete' ,'paixu' => 4 ,'pid' => 502 ], - ['id' => 500205 + ['id' => 50205 ,'title' => '状态' ,'name' => 'teach/banji/setstatus' ,'paixu' => 5 ,'pid' => 502 ], - ['id' => 500206 + ['id' => 50206 ,'title' => '成绩查看' ,'name' => 'teach/banjichengji/index' ,'paixu' => 6 ,'pid' => 502 ], - ['id' => 500207 + ['id' => 50207 ,'title' => '设置别名' ,'name' => 'teach/banji/setalias' ,'paixu' => 7 ,'pid' => 502 ], - ['id' => 500208 - ,'title' => '编辑班主任' - ,'name' => 'teach/banji/banzhuren' + ['id' => 50208 + ,'title' => '班主任管理' + ,'name' => 'teach/banzhuren/index' ,'paixu' => 8 ,'pid' => 502 ], - ['id' => 500209 - ,'title' => '更新班主任' - ,'name' => 'teach/banji/updatebanzhuren' - ,'paixu' => 9 - ,'pid' => 502 - ], + ['id' => 5020801 + ,'title' => '添加' + ,'name' => 'teach/banzhuren/create' + ,'paixu' => 1 + ,'pid' => 50208 + ], + ['id' => 5020802 + ,'title' => '保存' + ,'name' => 'teach/banzhuren/save' + ,'paixu' => 2 + ,'pid' => 50208 + ], + ['id' => 5020803 + ,'title' => '编辑' + ,'name' => 'teach/banzhuren/edit' + ,'paixu' => 3 + ,'pid' => 50208 + ], + ['id' => 5020804 + ,'title' => '更新' + ,'name' => 'teach/banzhuren/update' + ,'paixu' => 4 + ,'pid' => 50208 + ], + ['id' => 5020805 + ,'title' => '删除' + ,'name' => 'teach/banzhuren/delete' + ,'paixu' => 5 + ,'pid' => 50208 + ], + ['id' => 5020806 + ,'title' => '状态' + ,'name' => 'teach/banzhuren/setstatus' + ,'paixu' => 6 + ,'pid' => 50208 + ], ['id' => 503 ,'title' => '学科列表' ,'name' => 'teach/subject/index'