264 lines
6.2 KiB
PHP
264 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace app\keti\controller;
|
|
|
|
// 引用控制器基类
|
|
use app\common\controller\Base;
|
|
|
|
// 引用课题数据模型
|
|
use app\keti\model\Keti as keti;
|
|
|
|
class Index extends Base
|
|
{
|
|
/**
|
|
* 显示资源列表
|
|
*
|
|
* @return \think\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
// 设置数据总数
|
|
$list['count'] = keti::count();
|
|
// 设置页面标题
|
|
$list['title'] = '课题列表';
|
|
|
|
// 模板赋值
|
|
$this->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'],
|
|
'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);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 显示创建资源表单页.
|
|
*
|
|
* @return \think\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
// 设置页面标题
|
|
$list['title'] = '添加课题册';
|
|
|
|
// 模板赋值
|
|
$this->assign('list',$list);
|
|
|
|
// 渲染
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* 保存新建的资源
|
|
*
|
|
* @param \think\Request $request
|
|
* @return \think\Response
|
|
*/
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 显示指定的资源
|
|
*
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function read($id)
|
|
{
|
|
|
|
// 获取变量
|
|
$list['id'] = $id;
|
|
// 设置页面标题
|
|
$list['title'] = '课题信息';
|
|
// 设置数据总数
|
|
$ktinfo = new \app\keti\model\KetiInfo;
|
|
$list['count'] = $ktinfo->where('ketice',$id)->count();
|
|
|
|
// 模板赋值
|
|
$this->assign('list',$list);
|
|
|
|
return $this->fetch('keti_info/read');
|
|
}
|
|
|
|
/**
|
|
* 显示编辑资源表单页.
|
|
*
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
// 获取荣誉册信息
|
|
$list = keti::where('id',$id)
|
|
->field('id,title,category,lxshijian,lxdanweiid')
|
|
->find();
|
|
|
|
|
|
$this->assign('list',$list);
|
|
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* 保存更新的资源
|
|
*
|
|
* @param \think\Request $request
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 删除指定资源
|
|
*
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
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);
|
|
}
|
|
|
|
|
|
}
|