编写学期
This commit is contained in:
1 parent
0dbee995fc
commit
d81371b32c
8 files changed
+278
-137
No files matched your search
@@ -2,84 +2,234 @@
|
||||
|
||||
namespace app\teach\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
// 引用控制器基类
|
||||
use app\common\controller\Base;
|
||||
// 引用学期数据模型类
|
||||
use app\teach\model\Xueqi as XQ;
|
||||
|
||||
class Xueqi extends Controller
|
||||
class Xueqi extends Base
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
// 显示学期列表
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
// 设置数据总数
|
||||
$list['count'] = XQ::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]['data'];
|
||||
//得到limit参数
|
||||
$limit_start = $getdt['start'];
|
||||
$limit_length = $getdt['length'];
|
||||
//得到搜索的关键词
|
||||
$search = $getdt['search']['value'];
|
||||
|
||||
|
||||
// 获取记录集总数
|
||||
$cnt = XQ::count();
|
||||
//查询数据
|
||||
$data =XQ::field('id,title,xuenian,category,bfdate,enddate,status')
|
||||
->order([$order_field=>$order])
|
||||
->limit($limit_start,$limit_length)
|
||||
->all();
|
||||
|
||||
|
||||
// 如果需要查询
|
||||
if($search){
|
||||
$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)
|
||||
{
|
||||
$query->table('catagory')
|
||||
->where('title','like','%'.$search.'%')
|
||||
->field('id');
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
$datacnt = $data->count();
|
||||
|
||||
|
||||
|
||||
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
|
||||
|
||||
// 保存信息
|
||||
public function save()
|
||||
{
|
||||
//
|
||||
// 实例化验证模型
|
||||
$validate = new \app\teach\validate\Teacher;
|
||||
|
||||
|
||||
// 获取表单数据
|
||||
$list = request()->only(['xingming','sex','quanpin','shoupin','shengri','zhiwu','zhicheng','xueli','biye','worktime','zhuanye','danwei'],'post');
|
||||
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
|
||||
|
||||
// 如果验证不通过则停止保存
|
||||
if(!$result){
|
||||
return json(['msg'=>$msg,'val'=>0]);;
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
$data = XQ::create($list);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
//
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// 修改学期信息
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
// 获取学期信息
|
||||
$list = XQ::field('id,xingming,sex,quanpin,shoupin,shengri,zhiwu,zhicheng,xueli,biye,worktime,zhuanye,danwei')
|
||||
->get($id);
|
||||
|
||||
|
||||
$this->assign('list',$list);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
|
||||
|
||||
|
||||
|
||||
// 更新学期信息
|
||||
public function update($id)
|
||||
{
|
||||
//
|
||||
$validate = new \app\teach\validate\Teacher;
|
||||
|
||||
// 获取表单数据
|
||||
$list = request()->only(['xingming','sex','quanpin','shoupin','shengri','zhiwu','zhicheng','xueli','biye','worktime','zhuanye','danwei'],'put');
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
|
||||
// 如果验证不通过则停止保存
|
||||
if(!$result){
|
||||
return json(['msg'=>$msg,'val'=>0]);;
|
||||
}
|
||||
|
||||
|
||||
// 更新数据
|
||||
$teacher = new Teacher();
|
||||
$data = $teacher->save($list,['id'=>$id]);
|
||||
// $data = XQ::where('id',$id)->update($list);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data>=0 ? $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 = XQ::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 = XQ::where('id',$id)->update(['status'=>$value]);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,27 @@ use app\common\model\Base;
|
||||
|
||||
class Xueqi extends Base
|
||||
{
|
||||
//
|
||||
// 开始时间修改器
|
||||
public function setBfdateAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
|
||||
// 开始时间获取器
|
||||
public function getBfdateAttr($value)
|
||||
{
|
||||
return date('Y-m-d',$value);
|
||||
}
|
||||
|
||||
// 结束时间修改器
|
||||
public function setEnddateAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
|
||||
// 结束时间获取器
|
||||
public function getEnddateAttr($value)
|
||||
{
|
||||
return date('Y-m-d',$value);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,13 @@ class Xueqi extends Validate
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [];
|
||||
protected $rule = [
|
||||
'title|标题' => 'required|length:2,25',
|
||||
'xuenian|学年' => 'required|length:1,15',
|
||||
'category|分类' => 'required|number',
|
||||
'bfdate|时间' => 'required|date',
|
||||
'enddate|时间' => 'required|date',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
|
||||
Loaded 3 of 8 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user