diff --git a/application/keti/controller/Index.php b/application/keti/controller/Index.php index 3c39fea1..bec0d710 100644 --- a/application/keti/controller/Index.php +++ b/application/keti/controller/Index.php @@ -6,7 +6,7 @@ namespace app\keti\controller; use app\common\controller\Base; // 引用课题数据模型 -use app\keti\model\Keti as kt; +use app\keti\model\Keti as keti; class Index extends Base { @@ -18,7 +18,7 @@ class Index extends Base public function index() { // 设置数据总数 - $list['count'] = kt::count(); + $list['count'] = keti::count(); // 设置页面标题 $list['title'] = '课题列表'; @@ -29,6 +29,68 @@ class Index extends Base return $this->fetch(); } + + + /** + * 显示课题册列表 + * + * @return \think\Response + */ + public function ajaxData() + { + // 获取DT的传值 + $getdt = request()->param(); + + //得到排序的方式 + $order = $getdt['order'][0]['dir']; + //得到排序字段的下标 + $order_column = $getdt['order'][0]['column']; + //根据排序字段的下标得到排序字段 + $order_field = $getdt['columns'][$order_column]['name']; + if($order_field=='') + { + $order_field = $getdt['columns'][$order_column]['data']; + } + //得到limit参数 + $limit_start = $getdt['start']; + $limit_length = $getdt['length']; + + //得到搜索的关键词 + $search = [ + 'lxdanweiid'=>$getdt['lxdanweiid'], + 'category'=>$getdt['category'], + 'search'=>$getdt['search']['value'], + 'order'=>$order, + 'order_field'=>$order_field + ]; + + // 实例化 + $keti = new keti; + + // 获取荣誉总数 + $cnt = $keti->select()->count(); + + // 查询数据 + $data = $keti->search($search); + $datacnt = $data->count(); + + // 获取当前页数据 + $data = $data->slice($limit_start,$limit_length); + + + // 重组返回内容 + $data = [ + 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 + 'recordsTotal'=>$cnt, // 获取到的结果数(每页显示数量) + 'recordsFiltered'=>$datacnt, // 符合条件的总数据量 + 'data'=>$data, //获取到的数据结果 + ]; + + return json($data); + } + + + /** * 显示创建资源表单页. * @@ -36,7 +98,14 @@ class Index extends Base */ public function create() { - // + // 设置页面标题 + $list['title'] = '添加课题册'; + + // 模板赋值 + $this->assign('list',$list); + + // 渲染 + return $this->fetch(); } /** @@ -45,9 +114,29 @@ class Index extends Base * @param \think\Request $request * @return \think\Response */ - public function save(Request $request) + public function save() { - // + // 获取表单数据 + $list = request()->only(['title','category','lxshijian','lxdanweiid'],'post'); + + // 实例化验证模型 + $validate = new \app\keti\validate\Keti; + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + // 保存数据 + $data = keti::create($list); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** @@ -69,7 +158,15 @@ class Index extends Base */ public function edit($id) { - // + // 获取荣誉册信息 + $list = keti::where('id',$id) + ->field('id,title,category,lxshijian,lxdanweiid') + ->find(); + + + $this->assign('list',$list); + + return $this->fetch(); } /** @@ -79,9 +176,33 @@ class Index extends Base * @param int $id * @return \think\Response */ - public function update(Request $request, $id) + public function update($id) { - // + // 获取表单数据 + $list = request()->only(['title','category','lxshijian','lxdanweiid'],'put'); + $list['id'] = $id; + + + // 实例化验证类 + $validate = new \app\keti\validate\Keti; + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + + // 更新数据 + $data = keti::update($list); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** @@ -92,6 +213,39 @@ class Index extends Base */ public function delete($id) { - // + if($id == 'm') + { + $id = request()->delete('ids/a');// 获取delete请求方式传送过来的数据并转换成数据 + } + + $data = keti::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 = keti::where('id',$id)->update(['status'=>$value]); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + } diff --git a/application/keti/controller/KetiInfo.php b/application/keti/controller/KetiInfo.php new file mode 100644 index 00000000..ceff9100 --- /dev/null +++ b/application/keti/controller/KetiInfo.php @@ -0,0 +1,184 @@ +assign('list', $list); + + // 渲染模板 + return $this->fetch(); + } + + + + /** + * 显示课题信息列表 + * + * @return \think\Response + */ + public function ajaxData() + { + // 获取DT的传值 + $getdt = request()->param(); + + //得到排序的方式 + $order = $getdt['order'][0]['dir']; + //得到排序字段的下标 + $order_column = $getdt['order'][0]['column']; + //根据排序字段的下标得到排序字段 + $order_field = $getdt['columns'][$order_column]['name']; + if($order_field=='') + { + $order_field = $getdt['columns'][$order_column]['data']; + } + //得到limit参数 + $limit_start = $getdt['start']; + $limit_length = $getdt['length']; + + //得到搜索的关键词 + $search = [ + 'lxdanweiid'=>$getdt['lxdanweiid'], + 'category'=>$getdt['category'], + 'fzschool'=>$getdt['fzschool'], + 'search'=>$getdt['search']['value'], + 'order'=>$order, + 'order_field'=>$order_field + ]; + + // 实例化 + $keti = new ktinfo; + + // 获取荣誉总数 + $cnt = $keti->select()->count(); + + // 查询数据 + $data = $keti->search($search); + $datacnt = $data->count(); + + // 获取当前页数据 + $data = $data->slice($limit_start,$limit_length); + + + // 重组返回内容 + $data = [ + 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 + 'recordsTotal'=>$cnt, // 获取到的结果数(每页显示数量) + 'recordsFiltered'=>$datacnt, // 符合条件的总数据量 + 'data'=>$data, //获取到的数据结果 + ]; + + return json($data); + } + + + + + /** + * 显示创建资源表单页. + * + * @return \think\Response + */ + public function create($id=0) + { + // 设置页面标题 + $list['title'] = '添加课题信息'; + $list['ketice'] = $id; + + // 模板赋值 + $this->assign('list',$list); + + // 渲染 + return $this->fetch(); + } + + /** + * 保存新建的资源 + * + * @param \think\Request $request + * @return \think\Response + */ + public function save(Request $request) + { + // + } + + + // 批量上传立项通知书 + public function createall($id){ + dump($id); + } + + + /** + * 显示指定的资源 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + // + } + + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit($id) + { + // + } + + /** + * 保存更新的资源 + * + * @param \think\Request $request + * @param int $id + * @return \think\Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + // + } + + + + // 课题册 + public function KetiCe($id) + { + dump($id); + } +} diff --git a/application/keti/model/Keti.php b/application/keti/model/Keti.php index 8886e171..ada2c6d1 100644 --- a/application/keti/model/Keti.php +++ b/application/keti/model/Keti.php @@ -5,7 +5,99 @@ namespace app\keti\model; // 引用数据模型基类 use app\common\model\Base; + class Keti extends Base { - // + //搜索课题册 + public function search($search) + { + // 获取参数 + $lxdanweiid = $search['lxdanweiid']; + $category = $search['category']; + $order_field = $search['order_field']; + $order = $search['order']; + $category = $search['category']; + $search = $search['search']; + + $data = $this->order([$order_field =>$order]) + ->when(!empty($lxdanweiid),function($query) use($lxdanweiid){ + $query->where('lxdanweiid','in',$lxdanweiid); + }) + ->when(!empty($category),function($query) use($category){ + $query->where('category','in',$category); + }) + ->when(!empty($search),function($query) use($search){ + $query->where('title','like',$search); + }) + ->with( + [ + 'ktCategory'=>function($query){ + $query->field('id,title'); + }, + 'ktLxdanwei'=>function($query){ + $query->field('id,title'); + }, + ] + ) + ->append(['ktcnt','jtcnt']) + ->select(); + + + return $data; + } + + + // 类型关联 + public function ktCategory() + { + return $this->belongsTo('\app\system\model\Category','category','id'); + } + + + // 立项单位关联 + public function ktLxdanwei() + { + return $this->belongsTo('\app\system\model\School','lxdanweiid','id'); + } + + + // 课题信息关联 + public function ktInfo() + { + return $this->hasMany('KetiInfo','ketice','id'); + } + + + // 立项时间获取器 + public function getLxshijianAttr($value) + { + if ($value>0) + { + $value = date('Y-m-d',$value); + }else{ + $value = ""; + } + return $value; + } + + + // 立项时间 + public function setLxshijianAttr($value) + { + return strtotime($value); + } + + + // 课题数量 + public function getKtcntAttr() + { + return $this->ktInfo->count(); + } + + + // 结题课题数量 + public function getJtcntAttr() + { + return $this->ktInfo->where('jddengji','>',0)->where('jtshijian','>',0)->count(); + } } diff --git a/application/keti/model/KetiCanyu.php b/application/keti/model/KetiCanyu.php new file mode 100644 index 00000000..816fdb5b --- /dev/null +++ b/application/keti/model/KetiCanyu.php @@ -0,0 +1,10 @@ +order([$order_field =>$order]) + ->when(!empty($lxdanweiid),function($query) use($lxdanweiid){ + $query->where('lxdanweiid','in',$lxdanweiid); + }) + ->when(!empty($category),function($query) use($category){ + $query->where('category','in',$category); + }) + ->when(!empty($fzschool),function($query) use($fzschool){ + $query->where('title','in',$fzschool); + }) + ->when(!empty($search),function($query) use($search){ + $query->where('title','like',$search); + }) + // ->with( + // [ + // 'ktCategory'=>function($query){ + // $query->field('id,title'); + // }, + // 'ktLxdanwei'=>function($query){ + // $query->field('id,title'); + // }, + // ] + // ) + // ->append(['ktcnt','jtcnt']) + ->select(); + + + return $data; + } +} diff --git a/application/keti/validate/Keti.php b/application/keti/validate/Keti.php index bc76e2cf..4ac222aa 100644 --- a/application/keti/validate/Keti.php +++ b/application/keti/validate/Keti.php @@ -12,7 +12,12 @@ class Keti extends Validate * * @var array */ - protected $rule = []; + protected $rule = [ + 'title|课题册标题' => 'require|length:1,30', + 'category|课题类型' => 'require|number', + 'lxshijian|立项时间' => 'require|date', + 'lxdanweiid|立项单位' => 'require|number', + ]; /** * 定义错误信息 diff --git a/application/keti/validate/KetiInfo.php b/application/keti/validate/KetiInfo.php new file mode 100644 index 00000000..9d72bc1c --- /dev/null +++ b/application/keti/validate/KetiInfo.php @@ -0,0 +1,24 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = []; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; +} diff --git a/application/keti/view/index/create.html b/application/keti/view/index/create.html index 5ffbe321..b4c30cdc 100644 --- a/application/keti/view/index/create.html +++ b/application/keti/view/index/create.html @@ -2,20 +2,20 @@ {block name="mycss"} {/block} {block name="formaa"} -