<?php

namespace App\Models;

class Priv_roleModel extends BaseModel {
	protected $table = 'dc_priv_role';
	function getlist($list=10){
	    $data=$this->orderBy('create_at','desc')->paginate($list);
	    if(!$data){
	        return -7050000204;
        }
        return $data->toArray();
    }
    //角色信息
    function getRole($id){
        $data=$this->where('rolo_id',$id)->first();
        if(!$data){
            return -7050001204;
        }
        return $data->toArray();
    }
    //获取所有角色代码id
    function getAllCode($role_ids){
        $data=$this->select('priv_id')->whereIn('role_id',$role_ids)->get();
        if(!$data){
            return -7051121522;//没有权限代码
        }
        $data=$data->toArray();
        $arr=[];
        foreach ($data as $k=>$v){
            $arr[]=$v['priv_id'];
        }
        return $arr;
    }
    //获取代码id
    protected function getPrivID($admin_id){
//        $data=$this->select('priv_id')->whereIn('role_id', function ($query) {
//                $query->select('role_id')->from('dc_role')->where('admin_id', $admin_id);
//            })->get();
        $data=$this->select('priv_id')
            ->join('dc_role',$this->table.'.role_id','dc_role.role_id')
            ->where('admin_id',$admin_id)
            ->get();
        if(!$data){
            return -2344;
        }
        return $data->toArray();

    }
}