<?php
namespace app\admin\model;
use think\Model;

// 引入框架内置类
use think\facade\Db;
use think\facade\Event;
use think\facade\Session;
use think\facade\Request;

class AuthRule extends Model{
	
    // 定义时间戳字段名
    protected $createTime = 'createTime';
    protected $updateTime = 'updateTime';



    public static function rule(){
		$list=AuthRule::order('sort asc')->select();
        return $list;
    }

    public static function save_rule(){
		$tdata=Request::param();
		$map['pid']=$tdata['pid'];
		$info=AuthRule::where($map)->field('sort')->order('sort desc')->find();
		if(isset($tdata['id'])==false){
		$tdata['sort']=$info['sort']+1;
		}
		Db::name('auth_rule')->save($tdata);
		return 1;
    }

	//首页左侧菜单
    public static function admin_index_left($pid=0,$is_effect=0){
		$map['pid']=$pid;
		if($is_effect==1){
			$map['is_effect']=1;
		}
		$list=AuthRule::where($map)->order('sort asc')->select()->toArray();
        return $list;
    }

    public static function group(){
		$list=Db::name('auth_group')->order('id asc')->select();
        return $list;
    }

    public static function save_group(){
		$tdata=Request::param();
		if($tdata['id']==''){
			unset($tdata['id']);
		}
		Db::name('auth_group')->json(['rid'])->save($tdata);
        return 1;
    }

    public static function auth_group_list(){
		$list=Db::name('auth_group')->select();
        return $list;
    }
	
	
	//content_group 以下是内容权限设置
	public static function content_group(){
		$list=Db::name('content_group')->order('id asc')->select();
		return $list;
    }

    public static function save_content_group(){
		$tdata=Request::param();
		if($tdata['id']==''){
			unset($tdata['id']);
		}
		Db::name('content_group')->json(['rid'])->save($tdata);
        return 1;
    }
	
    public static function auth_content_group_list(){
		$list=Db::name('content_group')->select();
        return $list;
    }

	public static function content_group_info($id){
		$list=Db::name('content_group')->find($id);
		return $list;
    }
	
}