diff --git a/application/common/view/list.html b/application/common/view/list.html
index ed505100..ee638621 100644
--- a/application/common/view/list.html
+++ b/application/common/view/list.html
@@ -173,7 +173,7 @@ function start(obj,id){
if(data.val == 1 || data.val == 0)
{
$(obj).parents("tr").find("span").parents("td").html('
已启用');
- $(obj).replaceWith('
');
+ $(obj).replaceWith('
');
layer.msg('已启用!',{icon: 6,time:1000});
}else{
layer.msg(data.msg);
diff --git a/application/system/controller/Category.php b/application/system/controller/Category.php
index bb2eeb17..9999ed6d 100644
--- a/application/system/controller/Category.php
+++ b/application/system/controller/Category.php
@@ -100,7 +100,7 @@ class Category extends Base
- //
+ // 保存信息
public function save()
{
@@ -133,26 +133,12 @@ class Category extends Base
return json($data);
}
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- //
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
+
+ // 编辑类别
public function edit($id)
{
- // 获取权限信息
+ // 获取类别信息
$list = CG::field('id,title,pid,paixu')
->get($id);
@@ -161,19 +147,13 @@ class Category extends Base
return $this->fetch();
}
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
+ // 更新类别信息
public function update($id)
{
$validate = new \app\system\validate\Category;
// 获取表单数据
- $list = request()->only(['title','pid','paixu'],'put');;
+ $list = request()->only(['title','pid','paixu'],'put');
// 验证表单数据
$result = $validate->check($list);
@@ -194,12 +174,8 @@ class Category extends Base
return json($data);
}
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
+
+ // 删除类别
public function delete($id)
{
if($id == 'm')
@@ -216,7 +192,7 @@ class Category extends Base
return json($data);
}
- // 设置权限状态
+ // 设置类别状态
public function setStatus()
{
@@ -224,7 +200,7 @@ class Category extends Base
$id = request()->post('id');
$value = request()->post('value');
- // 获取权限信息
+ // 获取类别信息
$data = CG::where('id',$id)->update(['status'=>$value]);
// 根据更新结果设置返回提示信息
diff --git a/application/system/controller/School.php b/application/system/controller/School.php
index ad46618c..308a5204 100644
--- a/application/system/controller/School.php
+++ b/application/system/controller/School.php
@@ -2,84 +2,210 @@
namespace app\system\controller;
-use think\Controller;
-use think\Request;
+// 引用控制器基类
+use app\common\controller\Base;
+// 引用单位数据模型类
+use app\system\model\School as sch;
-class School extends Controller
+class School extends Base
{
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
+ // 单位列表
public function index()
{
- //
+ $count = sch::count();
+
+ // 设置要给模板赋值的信息
+ $list['title'] = '单位列表';
+ $list['count'] = $count;
+
+ // 模板赋值
+ $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 = sch::count();
+ //查询数据
+ $data =sch::field('id,title,jiancheng,biaoshi,xingzhi,jibie,status,xueduan,paixu')
+ ->order([$order_field=>$order])
+ ->limit($limit_start,$limit_length)
+ ->all();
+
+
+ // 如果需要查询
+ if($search){
+ $data =sch::field('id,title,jiancheng,biaoshi,xingzhi,jibie,status,xueduan,paixu')
+ ->whereOr('title','like','%'.$search.'%')
+ ->whereOr('pid','in',function($query) use ($search){
+ $query->name('category')->where('title','like','%'.$search.'%')->field('id');
+ })
+ ->order([$order_field=>$order])
+ ->limit($limit_start,$limit_length)
+ ->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\system\validate\School;
+
+
+ // 获取表单数据
+ $list = request()
+ ->only(['title','jiancheng','biaoshi','xingzhi','jibie','xueduan','paixu'],'post');
+
+
+ // 验证表单数据
+ $result = $validate->check($list);
+ $msg = $validate->getError();
+
+
+ // 如果验证不通过则停止保存
+ if(!$result){
+ return json(['msg'=>$msg,'val'=>0]);;
+ }
+
+ // 保存数据
+ $data = sch::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 = sch::field('id,title,jiancheng,biaoshi,xingzhi,jibie,status,xueduan,paixu')
+ ->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\system\validate\School;
+
+ // 获取表单数据
+ $list = request()
+ ->only(['title','jiancheng','biaoshi','xingzhi','jibie','xueduan','paixu'],'put');
+
+
+ // 验证表单数据
+ $result = $validate->check($list);
+ $msg = $validate->getError();
+
+ // 如果验证不通过则停止保存
+ if(!$result){
+ return json(['msg'=>$msg,'val'=>0]);;
+ }
+
+
+ $data = sch::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');
+ }
+
+ $data = sch::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 = sch::where('id',$id)->update(['status'=>$value]);
+
+ // 根据更新结果设置返回提示信息
+ $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0];
+
+ // 返回信息
+ return json($data);
}
}
diff --git a/application/system/model/School.php b/application/system/model/School.php
index bf777891..152b73fd 100644
--- a/application/system/model/School.php
+++ b/application/system/model/School.php
@@ -2,9 +2,34 @@
namespace app\system\model;
-use think\Model;
+use app\common\model\Base;
-class School extends Model
+class School extends Base
{
- //
+ // 单位性质获取器
+ public function getXingzhiAttr($value)
+ {
+ return $this->getcategory($value);
+ }
+
+ // 单位级别获取器
+ public function getJibieAttr($value)
+ {
+ return $this->getcategory($value);
+ }
+
+ // 单位学段获取器
+ public function getXueduanAttr($value)
+ {
+ return $this->getcategory($value);
+ }
+
+
+ // category查询
+ public function getcategory($id)
+ {
+ return db('category')
+ ->where('id',$id)
+ ->value('title');
+ }
}
diff --git a/application/system/validate/School.php b/application/system/validate/School.php
new file mode 100644
index 00000000..8e465c26
--- /dev/null
+++ b/application/system/validate/School.php
@@ -0,0 +1,33 @@
+ ['规则1','规则2'...]
+ *
+ * @var array
+ */
+ protected $rule = [
+ 'title|单位名称' => 'require|chs|length:2,25',
+ 'jiancheng|单位简称' => 'require|chs|length:1,6',
+ 'biaoshi|单位标识' => 'number',
+ 'jibie|级别 ' => 'number',
+ 'xingzhi|性质' => 'number',
+ 'xueduan|学段' => 'number',
+ 'paixu|排序 ' => 'number|max:999',
+
+ ];
+
+ /**
+ * 定义错误信息
+ * 格式:'字段名.规则名' => '错误信息'
+ *
+ * @var array
+ */
+ protected $message = [];
+}
diff --git a/application/system/view/school/create.html b/application/system/view/school/create.html
new file mode 100644
index 00000000..f4a4efca
--- /dev/null
+++ b/application/system/view/school/create.html
@@ -0,0 +1,108 @@
+{extend name="common@create" /}
+{block name="formaa"}
+
+
+{/block}
+{block name="yanzheng"}
+
+{/block}
\ No newline at end of file
diff --git a/application/system/view/school/edit.html b/application/system/view/school/edit.html
new file mode 100644
index 00000000..2a695fe8
--- /dev/null
+++ b/application/system/view/school/edit.html
@@ -0,0 +1,108 @@
+{extend name="common@create" /}
+{block name="formaa"}
+
+
+{/block}
+{block name="yanzheng"}
+
+{/block}
\ No newline at end of file
diff --git a/application/system/view/school/index.html b/application/system/view/school/index.html
new file mode 100644
index 00000000..a0d1d7a0
--- /dev/null
+++ b/application/system/view/school/index.html
@@ -0,0 +1,130 @@
+{extend name="common@list" /}
+{block name="topnav"}
+
+{/block}
+{block name="bouttons"}
+
+{/block}
+{block name="tables"}
+
+
+
+{/block}
+{block name="myjs"}
+
+{/block}
\ No newline at end of file
diff --git a/database/migrations/20181025041505_category.php b/database/migrations/20181025041505_category.php
index 5cb91d73..60e1b0aa 100644
--- a/database/migrations/20181025041505_category.php
+++ b/database/migrations/20181025041505_category.php
@@ -39,7 +39,6 @@ class Category extends Migrator
->addColumn('paixu','integer',['limit'=>4,'default'=>'999','null'=>false,'comment'=>'排序'])
->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间'])
->addColumn('beizhu','string',['limit'=>80,'null'=>true,'comment'=>'备注'])
- ->addIndex(array('title'), array('unique' => true))
->create();
}
}
diff --git a/database/migrations/20181026002455_school.php b/database/migrations/20181026002455_school.php
index d5ec20a5..052ef7e0 100644
--- a/database/migrations/20181026002455_school.php
+++ b/database/migrations/20181026002455_school.php
@@ -28,6 +28,24 @@ class School extends Migrator
*/
public function change()
{
+ // 定义数据表名称
+ $table = $this->table('school');
+ // 添加当前表字段
+ $table
+ ->addColumn('title','string',['limit'=>25,'null'=>false,'comment'=>'单位名称'])
+ ->addColumn('jiancheng','string',['limit'=>6,'null'=>false,'comment'=>'单位简称'])
+ ->addColumn('biaoshi','string',['limit'=>11,'null'=>true,'comment'=>'单位标识'])
+ ->addColumn('xingzhi','integer',['limit'=>11,'null'=>true,'comment'=>'单位性质'])
+ ->addColumn('jibie','integer',['limit'=>11,'null'=>true,'comment'=>'单位级别'])
+ ->addColumn('xueduan','integer',['limit'=>11,'null'=>true,'comment'=>'学段'])
+ ->addColumn('status','boolean',['limit'=>1,'default'=>'1','null'=>false,'comment'=>'0=禁用,1=正常'])
+ ->addColumn('paixu','integer',['limit'=>4,'default'=>'999','null'=>false,'comment'=>'排序'])
+ ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间'])
+ ->addColumn('create_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间'])
+ ->addColumn('update_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间'])
+ ->addColumn('beizhu','string',['limit'=>80,'null'=>true,'comment'=>'备注'])
+ ->addIndex(array('title','jiancheng','biaoshi'), array('unique' => true))
+ ->create();
}
}
diff --git a/database/seeds/Category.php b/database/seeds/Category.php
index ba72e054..fe745c72 100644
--- a/database/seeds/Category.php
+++ b/database/seeds/Category.php
@@ -19,6 +19,9 @@ class Category extends Seeder
// 一级类别
['id'=>1,'title'=>'单位性质','pid'=>0,'paixu' =>1],
['id'=>2,'title'=>'单位级别','pid'=>0,'paixu' =>2],
+ ['id'=>3,'title'=>'大学段','pid'=>0,'paixu' =>3],
+ ['id'=>4,'title'=>'小学段','pid'=>0,'paixu' =>4],
+
// 二级类别
// 单位性质
['title'=>'幼儿园','pid'=>1,'paixu'=>1],
@@ -30,6 +33,25 @@ class Category extends Seeder
['title'=>'科研机构(教师进修学校)','pid'=>1,'paixu'=>7],
['title'=>'教育行政部门','pid'=>1,'paixu'=>8],
['title'=>'其他教育机构','pid'=>1,'paixu'=>9],
+ // 单位级别
+ ['title'=>'学校','pid'=>2,'paixu'=>1],
+ ['title'=>'区级','pid'=>2,'paixu'=>2],
+ ['title'=>'市级','pid'=>2,'paixu'=>3],
+ ['title'=>'省级','pid'=>2,'paixu'=>4],
+ ['title'=>'部级','pid'=>2,'paixu'=>5],
+ ['title'=>'其它级','pid'=>2,'paixu'=>6],
+ // 大学段
+ ['title'=>'幼儿园','pid'=>3,'paixu'=>1],
+ ['title'=>'小学','pid'=>3,'paixu'=>2],
+ ['title'=>'中小学','pid'=>3,'paixu'=>3],
+ ['title'=>'初中','pid'=>3,'paixu'=>4],
+ ['title'=>'高中','pid'=>3,'paixu'=>5],
+ ['title'=>'其他学段','pid'=>3,'paixu'=>6],
+ // 大学段
+ ['title'=>'低年级','pid'=>4,'paixu'=>1],
+ ['title'=>'中年级','pid'=>4,'paixu'=>2],
+ ['title'=>'高级年','pid'=>4,'paixu'=>3],
+ ['title'=>'其他学段','pid'=>4,'paixu'=>4],
];
// 保存数据
$this->table('category')->insert($rows)->save();
diff --git a/database/seeds/Rule.php b/database/seeds/Rule.php
index 7b6d60f5..0ed0e968 100644
--- a/database/seeds/Rule.php
+++ b/database/seeds/Rule.php
@@ -36,12 +36,14 @@ class Rule extends Seeder
['title'=>'编辑','name'=>'system/Category/edit','paixu'=>3,'pid'=>11,],
['title'=>'查看','name'=>'system/Category/read','paixu'=>4,'pid'=>11,],
['title'=>'状态','name'=>'system/Category/status','paixu'=>5,'pid'=>11],
- // 类别管理权限
+ // 单位管理权限
['title'=>'添加','name'=>'system/School/create','paixu' =>1,'pid'=>12],
['title'=>'删除','name'=>'system/School/delete','paixu'=>2,'pid'=>12],
['title'=>'编辑','name'=>'system/School/edit','paixu'=>3,'pid'=>12,],
['title'=>'查看','name'=>'system/School/read','paixu'=>4,'pid'=>12,],
['title'=>'状态','name'=>'system/School/status','paixu'=>5,'pid'=>12],
+ // 系统设置权限
+ ['title'=>'编辑','name'=>'system/SystemBase/edit','paixu'=>1,'pid'=>13,],
//管理员管理