班级管理
This commit is contained in:
1 parent
5f41723c79
commit
9e4636eaaa
15 files changed
+831
-41
No files matched your search
@@ -14,18 +14,7 @@ class Index extends Base
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
//实例化数据模型
|
||||
$sysbasemod = new sysbasemod();
|
||||
|
||||
// 查询数据
|
||||
$list = $sysbasemod
|
||||
->where('id','>',0)
|
||||
->find();
|
||||
|
||||
if( $list == null )
|
||||
{
|
||||
$this->error('在地址栏中输入 域名或IP + /firstlogin 并回车,进行初始化');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,32 +1,58 @@
|
||||
<?php
|
||||
|
||||
function nianjiList()
|
||||
{
|
||||
// 定义学年时间节点日期为每年的8月10日
|
||||
// $yd = '8-10';
|
||||
$jiedian = strtotime(date('Y').'-8-10');
|
||||
|
||||
$time = new think\helper\Time();
|
||||
|
||||
$thisday = $time->today();
|
||||
|
||||
if($thisday[0]<=$jiedian)
|
||||
function nianjiList()
|
||||
{
|
||||
$str = 1;
|
||||
}else{
|
||||
$str = 0;
|
||||
// 定义学年时间节点日期为每年的8月10日
|
||||
// $yd = '8-10';
|
||||
$jiedian = strtotime(date('Y').'-8-10');
|
||||
|
||||
$time = new think\helper\Time();
|
||||
|
||||
$thisday = $time->today();
|
||||
|
||||
if($thisday[0]<=$jiedian)
|
||||
{
|
||||
$str = 1;
|
||||
}else{
|
||||
$str = 0;
|
||||
}
|
||||
|
||||
$nian = date('Y') - $str;
|
||||
|
||||
$njlist = array();
|
||||
|
||||
$njlist[$nian]='一年级';
|
||||
$njlist[$nian-1]='二年级';
|
||||
$njlist[$nian-2]='三年级';
|
||||
$njlist[$nian-3]='四年级';
|
||||
$njlist[$nian-4]='五年级';
|
||||
$njlist[$nian-5]='六年级';
|
||||
|
||||
return $njlist;
|
||||
}
|
||||
|
||||
$nian = date('Y') - $str;
|
||||
|
||||
$njlist = array();
|
||||
// 班级列表
|
||||
function banjinamelist()
|
||||
{
|
||||
$bjarr = array(
|
||||
'1'=>'一班',
|
||||
'2'=>'二班',
|
||||
'3'=>'三班',
|
||||
'4'=>'四班',
|
||||
'5'=>'五班',
|
||||
'6'=>'六班',
|
||||
'7'=>'七班',
|
||||
'8'=>'八班',
|
||||
'9'=>'九班',
|
||||
'10'=>'十班',
|
||||
'11'=>'十一班',
|
||||
'12'=>'十二班',
|
||||
'13'=>'十三班',
|
||||
'14'=>'十四班',
|
||||
'15'=>'十五班',
|
||||
);
|
||||
|
||||
$njlist[$nian]='一年级';
|
||||
$njlist[$nian-1]='二年级';
|
||||
$njlist[$nian-2]='三年级';
|
||||
$njlist[$nian-3]='四年级';
|
||||
$njlist[$nian-4]='五年级';
|
||||
$njlist[$nian-5]='六年级';
|
||||
return $bjarr;
|
||||
}
|
||||
|
||||
return $njlist;
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
|
||||
namespace app\teach\controller;
|
||||
|
||||
// 引用控制器基类
|
||||
use app\common\controller\Base;
|
||||
// 引用班级数据模型类
|
||||
use app\teach\model\Banji as BJ;
|
||||
|
||||
class Banji extends Base
|
||||
{
|
||||
// 显示班级列表
|
||||
public function index()
|
||||
{
|
||||
|
||||
// 设置数据总数
|
||||
$list['count'] = BJ::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 = BJ::count();
|
||||
//查询数据
|
||||
$data =BJ::field('id,school,ruxuenian,paixu,status')
|
||||
->order([$order_field=>$order])
|
||||
->limit($limit_start,$limit_length)
|
||||
->all();
|
||||
|
||||
|
||||
// 如果需要查询
|
||||
if($search){
|
||||
$data = BJ::field('id,school,ruxuenian,paixu,status')
|
||||
->order([$order_field=>$order])
|
||||
->limit($limit_start,$limit_length)
|
||||
->whereOr('title','like','%'.$search.'%')
|
||||
->whereOr('school','in',function($query) use($search)
|
||||
{
|
||||
$query->table('school')
|
||||
->where('title','like','%'.$search.'%')
|
||||
->field('id');
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
$datacnt = $data->count();
|
||||
//追加班级名称
|
||||
$data = $data->append(['title','stusum']);
|
||||
|
||||
|
||||
|
||||
|
||||
$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\Banji;
|
||||
|
||||
|
||||
// 获取表单数据
|
||||
$list = request()->only(['school','ruxuenian','bjsum'],'post');
|
||||
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
|
||||
|
||||
// 如果验证不通过则停止保存
|
||||
if(!$result){
|
||||
return json(['msg'=>$msg,'val'=>0]);
|
||||
}
|
||||
|
||||
$paixumax = BJ::where('school',$list['school'])
|
||||
->where('ruxuenian',$list['ruxuenian'])
|
||||
->max('paixu');
|
||||
|
||||
$i = 1;
|
||||
while($i<=$list['bjsum'])
|
||||
{
|
||||
$bjarr[] = array(
|
||||
'school'=>$list['school'],
|
||||
'ruxuenian'=>$list['ruxuenian'],
|
||||
'paixu'=>$paixumax+$i
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
|
||||
// 实例化班级数据模型类
|
||||
$bj = new BJ();
|
||||
|
||||
// 保存数据
|
||||
$data = $bj->saveAll($bjarr);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
}
|
||||
|
||||
//
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 修改班级信息
|
||||
public function edit($id)
|
||||
{
|
||||
|
||||
// 获取班级信息
|
||||
$list = BJ::field('id,school,ruxuenian,paixu')
|
||||
->get($id);
|
||||
|
||||
|
||||
$this->assign('list',$list);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 更新班级信息
|
||||
public function update($id)
|
||||
{
|
||||
$validate = new \app\teach\validate\Xueqi;
|
||||
|
||||
// 获取表单数据
|
||||
$list = request()->only(['title','xuenian','category','bfdate','enddate'],'put');
|
||||
|
||||
// 验证表单数据
|
||||
$result = $validate->check($list);
|
||||
$msg = $validate->getError();
|
||||
|
||||
// 如果验证不通过则停止保存
|
||||
if(!$result){
|
||||
return json(['msg'=>$msg,'val'=>0]);;
|
||||
}
|
||||
|
||||
|
||||
// 更新数据
|
||||
$xq = new XQ();
|
||||
$data = $xq->save($list,['id'=>$id]);
|
||||
// $data = BJ::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 = BJ::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 = BJ::where('id',$id)->update(['status'=>$value]);
|
||||
|
||||
// 根据更新结果设置返回提示信息
|
||||
$data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
|
||||
|
||||
// 返回信息
|
||||
return json($data);
|
||||
}
|
||||
|
||||
|
||||
public function yidong($id)
|
||||
{
|
||||
// 获取操作参数
|
||||
$caozuo = input('post.cz');
|
||||
|
||||
// 获取当前班级信息
|
||||
$thisbj = BJ::get($id);
|
||||
|
||||
// 获取别一个班级信息
|
||||
if( $caozuo > 0 )
|
||||
{
|
||||
$bjinfo = BJ::where('school',$thisbj->getData('school'))
|
||||
->where('ruxuenian',$thisbj->ruxuenian)
|
||||
->where('paixu','>=',$thisbj->paixu)
|
||||
->order(['paixu'])
|
||||
->limit('2')
|
||||
->field('id,paixu')
|
||||
->select();
|
||||
}else{
|
||||
$bjinfo = BJ::where('school',$thisbj->getData('school'))
|
||||
->where('ruxuenian',$thisbj->ruxuenian)
|
||||
->where('paixu','<=',$thisbj->paixu)
|
||||
->order(['paixu'=>'desc'])
|
||||
->limit('2')
|
||||
->field('id,paixu')
|
||||
->select();
|
||||
}
|
||||
if($bjinfo->count() == 2)
|
||||
{
|
||||
// 更改班级位置
|
||||
foreach ($bjinfo as $key => $value) {
|
||||
$value->paixu = $value->paixu + $caozuo;
|
||||
$caozuo = $caozuo * -1;
|
||||
}
|
||||
$bjinfo = $bjinfo->toArray();
|
||||
|
||||
// 实例化班级数据模型
|
||||
$bj = new BJ();
|
||||
// 更新数据
|
||||
$data = $bj->saveAll($bjinfo);
|
||||
$data ? $data = ['msg'=>'移动成功','val'=>true] : $data = ['msg'=>'数据处理错误','val'=>false];
|
||||
}else{
|
||||
$data = ['msg'=>'已经到头啦~','val'=>true];
|
||||
}
|
||||
|
||||
// 返回处理结果
|
||||
return json($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loaded 3 of 15 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user