Time扩展添加教务管理表编写教务管理修改用户角色添加方式
This commit is contained in:
1 parent
8f7868665b
commit
8c1fbfd00a
56 files changed
+2564
-299
No files matched your search
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace app\teach\controller;
|
||||
|
||||
// 引用控制器基类
|
||||
use app\common\controller\Base;
|
||||
// 引用学期数据模型类
|
||||
use app\teach\model\Subject as SJ;
|
||||
|
||||
class Subject extends Base
|
||||
{
|
||||
// 显示学期列表
|
||||
public function index()
|
||||
{
|
||||
|
||||
// 设置数据总数
|
||||
$list['count'] = SJ::count();
|
||||
// 设置页面标题
|
||||
$list['title'] = '学科列表';
|
||||
|
||||
|
||||
// 模板赋值
|
||||
$this->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 = SJ::count();
|
||||
//查询数据
|
||||
$data =SJ::field('id,title,jiancheng,category,paixu,status')
|
||||
->order([$order_field=>$order])
|
||||
->limit($limit_start,$limit_length)
|
||||
->all();
|
||||
|
||||
|
||||
// 如果需要查询
|
||||
if($search){
|
||||
$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)
|
||||
{
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 保存信息
|
||||
public function save()
|
||||
{
|
||||
// 实例化验证模型
|
||||
$validate = new \app\teach\validate\Subject;
|
||||
|
||||
|
||||
// 获取表单数据
|
||||
$list = request()->only(['title','jiancheng','category','paixu'],'post');
|
||||
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
|
||||
|
||||
// 如果验证不通过则停止保存
|
||||
if(!$result){
|
||||
return json(['msg'=>$msg,'val'=>0]);
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
$data = SJ::create($list);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
}
|
||||
|
||||
//
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 修改学期信息
|
||||
public function edit($id)
|
||||
{
|
||||
|
||||
// 获取学期信息
|
||||
$list = SJ::field('id,title,jiancheng,category,paixu,status')
|
||||
->get($id);
|
||||
|
||||
|
||||
$this->assign('list',$list);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 更新学期信息
|
||||
public function update($id)
|
||||
{
|
||||
$validate = new \app\teach\validate\Subject;
|
||||
|
||||
// 获取表单数据
|
||||
$list = request()->only(['title','jiancheng','category','paixu'],'put');
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
|
||||
// 如果验证不通过则停止保存
|
||||
if(!$result){
|
||||
return json(['msg'=>$msg,'val'=>0]);;
|
||||
}
|
||||
|
||||
|
||||
// 更新数据
|
||||
$data = SJ::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 = SJ::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 = SJ::where('id',$id)->update(['status'=>$value]);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user