修改荣誉管理、编写课题管理

This commit is contained in:
cxdbz committed 2019-02-22 15:59:13 +08:00
1 parent 0c33aa9345
commit 81aa1b89b0
26 files changed
+1108 -89

No files matched your search

+163 -9
View File
@@ -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);
}
}