diff --git a/application/admin/controller/AuthGroup.php b/application/admin/controller/AuthGroup.php index b715b474..27d9061c 100644 --- a/application/admin/controller/AuthGroup.php +++ b/application/admin/controller/AuthGroup.php @@ -125,7 +125,6 @@ class AuthGroup extends Base // 保存数据 $data = AG::create($list); - $msg = array(); // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -191,7 +190,7 @@ class AuthGroup extends Base $data = AG::where('id',$id)->update($list); // 根据更新结果设置返回提示信息 - $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; // 返回信息 return json($data); diff --git a/application/admin/controller/AuthRule.php b/application/admin/controller/AuthRule.php index b78cd731..abb1b154 100644 --- a/application/admin/controller/AuthRule.php +++ b/application/admin/controller/AuthRule.php @@ -58,7 +58,9 @@ class AuthRule extends Base // 如果需要查询 if($search){ - $data = $authrulemod + $data = AR::field('id,title,name,condition,paixu,ismenu,font,status,pid') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) ->where('title|name|pid','like','%'.$search.'%') ->all(); } @@ -119,8 +121,6 @@ class AuthRule extends Base // 保存数据 $data = AR::create($list); - $msg = array(); - // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -161,7 +161,7 @@ class AuthRule extends Base $validate = new \app\admin\validate\Rule; // 获取表单数据 - $list = request()->put(); + $list = request()->only(['title','name','pid','condition','paixu','ismenu','font','beizhu'],'post'); // 验证表单数据 $result = $validate->check($list); @@ -176,7 +176,7 @@ class AuthRule extends Base $data = AR::where('id',$id)->update($list); // 根据更新结果设置返回提示信息 - $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; // 返回信息 return json($data); diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 188405ac..c007c879 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -28,8 +28,6 @@ class Index extends Base // 渲染模板 return $this->fetch(); - - // 获取记录总数 } @@ -140,9 +138,6 @@ class Index extends Base $data = AGA::create(['uid'=>$data->id,'group_id'=>$group_id]); - - $msg = array(); - // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; diff --git a/application/admin/model/AuthRule.php b/application/admin/model/AuthRule.php index e1dc57a2..bebb1df8 100644 --- a/application/admin/model/AuthRule.php +++ b/application/admin/model/AuthRule.php @@ -13,6 +13,7 @@ class AuthRule extends Base { return $this ->where('pid',$pid) + ->where('status',1) ->field('id,title') ->order(['paixu']) ->select(); @@ -35,5 +36,6 @@ class AuthRule extends Base return $this->where('id',$value)->value('title'); } + } diff --git a/application/admin/view/auth_group/create.html b/application/admin/view/auth_group/create.html index ce52bc4a..66c57284 100644 --- a/application/admin/view/auth_group/create.html +++ b/application/admin/view/auth_group/create.html @@ -17,7 +17,7 @@
{php} - $rule = model('authRule'); + $rule = new app\admin\model\AuthRule;; $plist = $rule->getRule(); {/php} {volist name="plist" id="p"} diff --git a/application/admin/view/auth_group/edit.html b/application/admin/view/auth_group/edit.html index 77a866f0..0bcfc783 100644 --- a/application/admin/view/auth_group/edit.html +++ b/application/admin/view/auth_group/edit.html @@ -17,7 +17,7 @@
{php} - $rule = model('authRule'); + $rule = new app\admin\model\AuthRule;; $plist = $rule->getRule(); {/php} {volist name="plist" id="p"} diff --git a/application/admin/view/auth_rule/create.html b/application/admin/view/auth_rule/create.html index 3ac4177d..2d37d9af 100644 --- a/application/admin/view/auth_rule/create.html +++ b/application/admin/view/auth_rule/create.html @@ -17,7 +17,7 @@
- {php} $authrulemod = model('AuthRule'); $pid = $authrulemod->getRule();{/php} + {php} $authrulemod = new app\admin\model\AuthRule; $pid = $authrulemod->getRule();{/php} {volist name="pid" id="vo"} diff --git a/application/http/middleware/YanZheng.php b/application/http/middleware/YanZheng.php index f4069c6d..df826ae6 100644 --- a/application/http/middleware/YanZheng.php +++ b/application/http/middleware/YanZheng.php @@ -66,7 +66,7 @@ class YanZheng extends Controller // 验证方法 if( !$auth->check($url, session('userid')) && $except == false ){// 第一个参数是规则名称,第二个参数是用户UID $this->error('哎哟~ 权限不足'); - } + } return $next($request); } diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index abb502ce..869c099a 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -67,7 +67,7 @@ class Index extends Base // 查询最新记录 $list = $sysbasemod ->order(['id'=>'desc']) - ->field('title,copyright,thinks') + ->field('title,copyright,thinks,danwei') ->find(); // 获取版本号 diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index f186b4e8..039acbf1 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -156,7 +156,7 @@
  • 系统设置
  • -
  • 栏目管理
  • +
  • 类别管理
  • 数据字典
  • 屏蔽词
  • 系统日志
  • diff --git a/application/index/view/index/welcome.html b/application/index/view/index/welcome.html index be6f1fa3..f2c5c278 100644 --- a/application/index/view/index/welcome.html +++ b/application/index/view/index/welcome.html @@ -192,7 +192,7 @@

    感谢{$list.thinks}
    - Copyright ©{$list.copyright} {$list.title} v{$list.version} All Rights Reserved.
    + Copyright ©{$list.copyright} {$list.danwei}{$list.title} v{$list.version} All Rights Reserved.
    本系统由 大连长兴岛经济区教研科研培训中心 提供技术支持

    diff --git a/application/login/controller/Index.php b/application/login/controller/Index.php index 2d0a09fa..178c3d9a 100644 --- a/application/login/controller/Index.php +++ b/application/login/controller/Index.php @@ -5,8 +5,6 @@ namespace app\login\controller; use think\Controller; // 引用用户数据模型 use app\admin\model\Admin as AD; -// 引用权限类 -use app\admin\model\AuthRule as AR; // 引用加密类 @@ -93,9 +91,6 @@ class Index extends Controller } - // 实例化权限类 - $ar = new AR(); - //验证密码 $check = $md5->check($password,$userinfo->password); diff --git a/application/system/controller/Category.php b/application/system/controller/Category.php index 0e8a0fdf..83799339 100644 --- a/application/system/controller/Category.php +++ b/application/system/controller/Category.php @@ -2,40 +2,135 @@ namespace app\system\controller; -use think\Controller; -use think\Request; +// 引用控制器基类 +use app\common\controller\Base; +// 引用类别数据模型类 +use app\system\model\Category as CG; -class Category extends Controller +class Category extends Base { - /** - * 显示资源列表 - * - * @return \think\Response - */ + + // 开启全局自动时间戳 + protected $autoWriteTimestamp = false; + + // 类别列表 public function index() { - // + $count = CG::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 = CG::count(); + //查询数据 + $data =CG::field('id,title,pid,status,paixu') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->all(); + + + // 如果需要查询 + if($search){ + $data =CG::field('id,title,pid,status,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\Category; + + + // 获取表单数据 + $list = request()->only(['title','pid','paixu'],'post'); + + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + // 保存数据 + $data = CG::create($list); + + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** @@ -57,7 +152,15 @@ class Category extends Controller */ public function edit($id) { - // + // 获取权限信息 + $list = CG::field('id,title,pid,paixu') + ->get($id); + $list = $list->getData(); + + + $this->assign('list',$list); + + return $this->fetch(); } /** @@ -67,9 +170,30 @@ class Category extends Controller * @param int $id * @return \think\Response */ - public function update(Request $request, $id) + public function update($id) { - // + $validate = new \app\system\validate\Category; + + // 获取表单数据 + $list = request()->only(['title','pid','paixu'],'put');; + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + + $data = CG::where('id',$id)->update($list); + + // 根据更新结果设置返回提示信息 + $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** @@ -80,6 +204,35 @@ class Category extends Controller */ public function delete($id) { - // + if($id == 'm') + { + $id = request()->delete('ids/a'); + } + + $data = CG::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 = CG::where('id',$id)->update(['status'=>$value]); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } } diff --git a/application/system/controller/SystemBase.php b/application/system/controller/SystemBase.php index 1f1e85b1..a724f9eb 100644 --- a/application/system/controller/SystemBase.php +++ b/application/system/controller/SystemBase.php @@ -34,38 +34,6 @@ class SystemBase extends Base return $this->fetch(); } - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ - public function create() - { - // - } - - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - // - } - - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } - /** * 显示编辑资源表单页. * @@ -89,14 +57,5 @@ class SystemBase extends Base // } - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // - } + } diff --git a/application/system/model/Category.php b/application/system/model/Category.php index 705fc3f0..2ea00666 100644 --- a/application/system/model/Category.php +++ b/application/system/model/Category.php @@ -2,9 +2,24 @@ namespace app\system\model; -use think\Model; +use app\common\model\Base; -class Category extends Model +class Category extends Base { - // + // 获取类别列表 + public function getCategory($id = 0) + { + return $this + ->where('pid',$id) + ->where('status',1) + ->field('id,title') + ->select(); + } + + + // 父级类别获取器 + public function getPidAttr($value) + { + return $this->where('id',$value)->value('title'); + } } diff --git a/application/system/validate/Category.php b/application/system/validate/Category.php new file mode 100644 index 00000000..54c77ed9 --- /dev/null +++ b/application/system/validate/Category.php @@ -0,0 +1,24 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = []; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; +} diff --git a/application/system/view/category/create.html b/application/system/view/category/create.html new file mode 100644 index 00000000..ca710219 --- /dev/null +++ b/application/system/view/category/create.html @@ -0,0 +1,77 @@ +{extend name="common@create" /} +{block name="formaa"} + +
    +
    + +
    + +
    +
    +
    + +
    + + {php} $cgmod = new app\system\model\Category;$pid = $cgmod->getCategory();{/php} + + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    +
    +
    +{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/system/view/category/edit.html b/application/system/view/category/edit.html new file mode 100644 index 00000000..3e802178 --- /dev/null +++ b/application/system/view/category/edit.html @@ -0,0 +1,77 @@ +{extend name="common@create" /} +{block name="formaa"} + +
    +
    + +
    + +
    +
    +
    + +
    + + {php} $authrulemod = new app\system\model\Category;$pid = $authrulemod->getCategory();{/php} + + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    +
    +
    +{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/system/view/category/index.html b/application/system/view/category/index.html new file mode 100644 index 00000000..6304000c --- /dev/null +++ b/application/system/view/category/index.html @@ -0,0 +1,122 @@ +{extend name="common@list" /} +{block name="topnav"} + +{/block} +{block name="bouttons"} +
    + + + + + 批量删除 + + + + + 添加类别 + + + + 共有数据:{$list.count} 条 + +
    +{/block} +{block name="tables"} + + + + + + + + + + + + + +
    名称父级类别排序状态操作
    + + +{/block} +{block name="myjs"} + +{/block} \ No newline at end of file diff --git a/database/migrations/20181010035225_system_base.php b/database/migrations/20181010035225_system_base.php index 0482e107..f2296db8 100644 --- a/database/migrations/20181010035225_system_base.php +++ b/database/migrations/20181010035225_system_base.php @@ -40,6 +40,7 @@ class SystemBase extends Migrator ->addColumn('description','string',['limit'=>100,'null'=>false,'comment'=>'网站说明']) ->addColumn('copyright','string',['limit'=>15,'null'=>false,'comment'=>'版权']) ->addColumn('thinks','string',['limit'=>200,'null'=>false,'comment'=>'网站感谢']) + ->addColumn('danwei','string',['limit'=>80,'null'=>false,'comment'=>'使用单位']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) ->create(); } diff --git a/database/migrations/20181025041505_category.php b/database/migrations/20181025041505_category.php new file mode 100644 index 00000000..545a04b4 --- /dev/null +++ b/database/migrations/20181025041505_category.php @@ -0,0 +1,45 @@ +table('category'); + + // 添加当前表字段 + $table + ->addColumn('title','string',['limit'=>15,'null'=>false,'comment'=>'类型标题']) + ->addColumn('pid','integer',['limit'=>4,'default'=>'0','null'=>false,'comment'=>'父级ID']) + ->addColumn('status','boolean',['limit'=>1,'default'=>'1','null'=>false,'comment'=>'0=禁用,1=正常']) + ->addColumn('paixu','integer',['limit'=>4,'default'=>'99','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/seeds/Category.php b/database/seeds/Category.php new file mode 100644 index 00000000..ba72e054 --- /dev/null +++ b/database/seeds/Category.php @@ -0,0 +1,37 @@ +1,'title'=>'单位性质','pid'=>0,'paixu' =>1], + ['id'=>2,'title'=>'单位级别','pid'=>0,'paixu' =>2], + // 二级类别 + // 单位性质 + ['title'=>'幼儿园','pid'=>1,'paixu'=>1], + ['title'=>'小学','pid'=>1,'paixu'=>2], + ['title'=>'九年一贯','pid'=>1,'paixu'=>3], + ['title'=>'初中','pid'=>1,'paixu'=>4], + ['title'=>'高中','pid'=>1,'paixu'=>5], + ['title'=>'中等职业技术学校','pid'=>1,'paixu'=>6], + ['title'=>'科研机构(教师进修学校)','pid'=>1,'paixu'=>7], + ['title'=>'教育行政部门','pid'=>1,'paixu'=>8], + ['title'=>'其他教育机构','pid'=>1,'paixu'=>9], + ]; + // 保存数据 + $this->table('category')->insert($rows)->save(); + } +} \ No newline at end of file diff --git a/database/seeds/SystemBase.php b/database/seeds/SystemBase.php index 3c827314..4de461b7 100644 --- a/database/seeds/SystemBase.php +++ b/database/seeds/SystemBase.php @@ -23,6 +23,7 @@ class SystemBase extends Seeder 'description' => '这是我们自己开发的系统', 'copyright' => '2018-2018', 'thinks' => 'H-ui前端框架、ThinkPhp框架', + 'danwei' => '大连长兴岛经济区教科培中心', ]; // 保存数据 $this->table('system_base')->insert($rows)->save(); diff --git a/route/system.php b/route/system.php index 6b62d860..5d700ee8 100644 --- a/route/system.php +++ b/route/system.php @@ -10,4 +10,7 @@ // +---------------------------------------------------------------------- //系统设置路由 -Route::resource('sysbase','system/system_base'); +Route::get('sysbase','system/SystemBase/index'); +Route::get('sysbase/:id/edit','system/SystemBase/edit'); +Route::put('sysbase/:id','system/SystemBase/update'); +Route::resource('category','system/Category');