diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 869c099a..fc18b8b1 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -14,18 +14,7 @@ class Index extends Base // 初始化 protected function initialize() { - //实例化数据模型 - $sysbasemod = new sysbasemod(); - // 查询数据 - $list = $sysbasemod - ->where('id','>',0) - ->find(); - - if( $list == null ) - { - $this->error('在地址栏中输入 域名或IP + /firstlogin 并回车,进行初始化'); - } } diff --git a/application/teach/common.php b/application/teach/common.php index 84b1f8a7..578f2eb8 100644 --- a/application/teach/common.php +++ b/application/teach/common.php @@ -1,32 +1,58 @@ today(); - - if($thisday[0]<=$jiedian) + function nianjiList() { - $str = 1; - }else{ - $str = 0; + // 定义学年时间节点日期为每年的8月10日 + // $yd = '8-10'; + $jiedian = strtotime(date('Y').'-8-10'); + + $time = new think\helper\Time(); + + $thisday = $time->today(); + + if($thisday[0]<=$jiedian) + { + $str = 1; + }else{ + $str = 0; + } + + $nian = date('Y') - $str; + + $njlist = array(); + + $njlist[$nian]='一年级'; + $njlist[$nian-1]='二年级'; + $njlist[$nian-2]='三年级'; + $njlist[$nian-3]='四年级'; + $njlist[$nian-4]='五年级'; + $njlist[$nian-5]='六年级'; + + return $njlist; } - $nian = date('Y') - $str; - $njlist = array(); + // 班级列表 + function banjinamelist() + { + $bjarr = array( + '1'=>'一班', + '2'=>'二班', + '3'=>'三班', + '4'=>'四班', + '5'=>'五班', + '6'=>'六班', + '7'=>'七班', + '8'=>'八班', + '9'=>'九班', + '10'=>'十班', + '11'=>'十一班', + '12'=>'十二班', + '13'=>'十三班', + '14'=>'十四班', + '15'=>'十五班', + ); - $njlist[$nian]='一年级'; - $njlist[$nian-1]='二年级'; - $njlist[$nian-2]='三年级'; - $njlist[$nian-3]='四年级'; - $njlist[$nian-4]='五年级'; - $njlist[$nian-5]='六年级'; + return $bjarr; + } - return $njlist; -} diff --git a/application/teach/controller/Banji.php b/application/teach/controller/Banji.php new file mode 100644 index 00000000..afa95989 --- /dev/null +++ b/application/teach/controller/Banji.php @@ -0,0 +1,309 @@ +assign('list', $list); + + // 渲染模板 + return $this->fetch(); + } + + + // 获取班级信息列表 + public function ajaxData() + { + + // 获取DT的传值 + $getdt = request()->param(); + + //得到排序的方式 + $order = $getdt['order'][0]['dir']; + //得到排序字段的下标 + $order_column = $getdt['order'][0]['column']; + //根据排序字段的下标得到排序字段 + $order_field = $getdt['columns'][$order_column]['data']; + //得到limit参数 + $limit_start = $getdt['start']; + $limit_length = $getdt['length']; + //得到搜索的关键词 + $search = $getdt['search']['value']; + + + // 获取记录集总数 + $cnt = BJ::count(); + //查询数据 + $data =BJ::field('id,school,ruxuenian,paixu,status') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->all(); + + + // 如果需要查询 + if($search){ + $data = BJ::field('id,school,ruxuenian,paixu,status') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->whereOr('title','like','%'.$search.'%') + ->whereOr('school','in',function($query) use($search) + { + $query->table('school') + ->where('title','like','%'.$search.'%') + ->field('id'); + }) + ->all(); + } + + $datacnt = $data->count(); + //追加班级名称 + $data = $data->append(['title','stusum']); + + + + + $data = [ + 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 + 'recordsTotal'=>$datacnt, // 获取到的结果数(每页显示数量) + 'recordsFiltered'=>$cnt, // 符合条件的总数据量 + 'data'=>$data, //获取到的数据结果 + ]; + + return json($data); + } + + + + // 创建班级 + public function create() + { + // 设置页面标题 + $list['title'] = '添加班级'; + + // 模板赋值 + $this->assign('list',$list); + + // 渲染 + return $this->fetch(); + } + + + + // 保存信息 + public function save() + { + // 实例化验证模型 + $validate = new \app\teach\validate\Banji; + + + // 获取表单数据 + $list = request()->only(['school','ruxuenian','bjsum'],'post'); + + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]); + } + + $paixumax = BJ::where('school',$list['school']) + ->where('ruxuenian',$list['ruxuenian']) + ->max('paixu'); + + $i = 1; + while($i<=$list['bjsum']) + { + $bjarr[] = array( + 'school'=>$list['school'], + 'ruxuenian'=>$list['ruxuenian'], + 'paixu'=>$paixumax+$i + ); + $i++; + } + + // 实例化班级数据模型类 + $bj = new BJ(); + + // 保存数据 + $data = $bj->saveAll($bjarr); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + // + public function read($id) + { + // + } + + + + + // 修改班级信息 + public function edit($id) + { + + // 获取班级信息 + $list = BJ::field('id,school,ruxuenian,paixu') + ->get($id); + + + $this->assign('list',$list); + + return $this->fetch(); + } + + + + + + // 更新班级信息 + public function update($id) + { + $validate = new \app\teach\validate\Xueqi; + + // 获取表单数据 + $list = request()->only(['title','xuenian','category','bfdate','enddate'],'put'); + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + + // 更新数据 + $xq = new XQ(); + $data = $xq->save($list,['id'=>$id]); + // $data = BJ::where('id',$id)->update($list); + + // 根据更新结果设置返回提示信息 + $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + + + + + // 删除班级 + public function delete($id) + { + + if($id == 'm') + { + $id = request()->delete('ids/a');// 获取delete请求方式传送过来的数据并转换成数据 + } + + $data = BJ::destroy($id); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'删除成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + + + // 设置班级状态 + public function setStatus() + { + + // 获取id变量 + $id = request()->post('id'); + $value = request()->post('value'); + + // 获取班级信息 + $data = BJ::where('id',$id)->update(['status'=>$value]); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + + public function yidong($id) + { + // 获取操作参数 + $caozuo = input('post.cz'); + + // 获取当前班级信息 + $thisbj = BJ::get($id); + + // 获取别一个班级信息 + if( $caozuo > 0 ) + { + $bjinfo = BJ::where('school',$thisbj->getData('school')) + ->where('ruxuenian',$thisbj->ruxuenian) + ->where('paixu','>=',$thisbj->paixu) + ->order(['paixu']) + ->limit('2') + ->field('id,paixu') + ->select(); + }else{ + $bjinfo = BJ::where('school',$thisbj->getData('school')) + ->where('ruxuenian',$thisbj->ruxuenian) + ->where('paixu','<=',$thisbj->paixu) + ->order(['paixu'=>'desc']) + ->limit('2') + ->field('id,paixu') + ->select(); + } + if($bjinfo->count() == 2) + { + // 更改班级位置 + foreach ($bjinfo as $key => $value) { + $value->paixu = $value->paixu + $caozuo; + $caozuo = $caozuo * -1; + } + $bjinfo = $bjinfo->toArray(); + + // 实例化班级数据模型 + $bj = new BJ(); + // 更新数据 + $data = $bj->saveAll($bjinfo); + $data ? $data = ['msg'=>'移动成功','val'=>true] : $data = ['msg'=>'数据处理错误','val'=>false]; + }else{ + $data = ['msg'=>'已经到头啦~','val'=>true]; + } + + // 返回处理结果 + return json($data); + + } + + + +} diff --git a/application/teach/controller/Kaoshi.php b/application/teach/controller/Kaoshi.php index 15f5797a..72f11067 100644 --- a/application/teach/controller/Kaoshi.php +++ b/application/teach/controller/Kaoshi.php @@ -60,8 +60,8 @@ class Kaoshi extends Base $data = KS::field('id,title,xueqi,category,bfdate,enddate,status') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) - ->where('title','like','%'.$search.'%') - ->where('category','in',function($query) use($search) + ->whereOr('title','like','%'.$search.'%') + ->whereOr('category','in',function($query) use($search) { $query->table('catagory') ->where('title','like','%'.$search.'%') diff --git a/application/teach/controller/Subject.php b/application/teach/controller/Subject.php index b1a53f18..d2a6b8e2 100644 --- a/application/teach/controller/Subject.php +++ b/application/teach/controller/Subject.php @@ -61,8 +61,8 @@ class Subject extends Base $data = SJ::field('id,title,jiancheng,category,paixu,status') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) - ->where('title','like','%'.$search.'%') - ->where('category','in',function($query) use($search) + ->whereOr('title','like','%'.$search.'%') + ->whereOr('category','in',function($query) use($search) { $query->table('catagory') ->where('title','like','%'.$search.'%') diff --git a/application/teach/controller/Xueqi.php b/application/teach/controller/Xueqi.php index a1252462..f56c542e 100644 --- a/application/teach/controller/Xueqi.php +++ b/application/teach/controller/Xueqi.php @@ -61,8 +61,8 @@ class Xueqi extends Base $data = XQ::field('id,title,xuenian,category,bfdate,enddate,status') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) - ->where('title|xuenian','like','%'.$search.'%') - ->where('category','in',function($query) use($search) + ->whereOr('title|xuenian','like','%'.$search.'%') + ->whereOr('category','in',function($query) use($search) { $query->table('catagory') ->where('title','like','%'.$search.'%') diff --git a/application/teach/model/Banji.php b/application/teach/model/Banji.php new file mode 100644 index 00000000..26dd2706 --- /dev/null +++ b/application/teach/model/Banji.php @@ -0,0 +1,43 @@ +getAttr('ruxuenian'); + $bj = $this->getAttr('paixu'); + + $njkeys = array_keys($njname); + $bjkeys = array_keys($bjname); + + in_array($nj,$njkeys) ? $title = $njname[$nj] : $title = $nj.'届'; + in_array($bj,$bjkeys) ? $title = $title.$bjname[$bj] : $title = $title.$bj.'班'; + + return $title; + } + + // 学校获取器 + public function getSchoolAttr($value) + { + // 查询学校名称 + $schoolname = db('school')->where('id',$value)->value('title'); + // 返回学校名称 + return $schoolname; + } + + + + // 班级学生数 + public function getStusumAttr($value) + { + // 返回学校名称 + return 25; + } +} diff --git a/application/teach/validate/Banji.php b/application/teach/validate/Banji.php new file mode 100644 index 00000000..1bd80124 --- /dev/null +++ b/application/teach/validate/Banji.php @@ -0,0 +1,28 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'school|学校' => 'require|number', + 'ruxuenian|年级' => 'require|number', + 'bjsum|班级数' => 'require|number' + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; +} diff --git a/application/teach/view/banji/create.html b/application/teach/view/banji/create.html new file mode 100644 index 00000000..9632dc1a --- /dev/null +++ b/application/teach/view/banji/create.html @@ -0,0 +1,71 @@ +{extend name="common@create" /} +{block name="formaa"} +
+{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/teach/view/banji/edit.html b/application/teach/view/banji/edit.html new file mode 100644 index 00000000..c4ac5c9c --- /dev/null +++ b/application/teach/view/banji/edit.html @@ -0,0 +1,74 @@ +{extend name="common@create" /} +{block name="formaa"} + +{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/teach/view/banji/index.html b/application/teach/view/banji/index.html new file mode 100644 index 00000000..bde601a7 --- /dev/null +++ b/application/teach/view/banji/index.html @@ -0,0 +1,148 @@ +{extend name="common@list" /} +{block name="topnav"} + +{/block} +{block name="bouttons"} +| + | 班级名称 | +学校 | +入学年 | +排序 | +学生人数 | +状态 | +操作 | +
|---|