123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- class Org extends Auth
- {
- public function index(){
- $tree = model('Org')->showAllTree();
- $this->assign('tree',$tree);
- return $this->fetch();
- }
- /**
- * 新增
- */
- public function add($pid=0,$t=0){
- if(request()->isPost()){
- $res = model('Org')->addSave();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('Org')->getError());
- }
- }else{
- $this->assign('pid',$pid);
- $this->assign('t',$t);
- return $this->fetch();
- }
- }
- /**
- * 编辑
- */
- public function edit($id=0){
- if(request()->isPost()){
- $res = model('Org')->editSave();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('Org')->getError());
- }
- }else{
- $info = db('org')->where('id',$id)->find();
- $info['location'] = '';
- if($info && $info['lat'] && $info['lng']){
- $info['location'] = $info['lat'].'-'.$info['lng'];
- }
- $this->assign('info',$info);
- $this->assign('t',$info['type']);
- return $this->fetch();
- }
- }
- public function changeEnable($id=0,$enable=0){
- if($id <= 0){
- $this->error('参数错误');
- }
- $ret = Db::name('org')->where('id',$id)->setField('enable',$enable);
- if(!$ret){
- $this->error('操作失败');
- }
- $this->success('操作成功');
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- // 检查是否有子级
- $ret = Db::name('org')->where('parent_id',$id)->where('del',0)->find();
- if($ret){
- $this->error('有子级不能删除');
- }
- $res = Db::name('org')->where('id',$id)->setField('del',1);
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- /**
- * 授权
- */
- public function auth(){
- if(request()->isPost()){
- $res = model('Org')->authSave();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('Org')->getError());
- }
- }else{
- $orgId = input('id/d',0);
- $meuns = model('Menu')->getAllMenuTree();
- $this->assign('menus',$meuns);
- $sauth = model('Org')->getOrgAuths($orgId,1);
- $this->assign('sauth',$sauth);
- $appauths = model('AppIcon')->getAllIconTree();
- $this->assign('appauths',$appauths);
- $sappauth = model('Org')->getOrgAuths($orgId,2);
- $this->assign('sappauth',$sappauth);
- $this->assign('orgId',$orgId);
- return $this->fetch();
- }
- }
- }
|