| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Power extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_power','power');		$this->load->_model('Model_user','user');		$this->load->_model('Model_nav','nav');		$this->load->_model('Model_fullorderexcel','fullorderexcel');		$this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'add')//添加        {             $this->_add();        }		else if($arg == 'edit')//修改        {             $this->_edit($arg_array);        }		else if($arg == 'del')//修改        {             $this->_del();        }		else if($arg == 'rows')//获取数据        {             $this->_rows();        }		else if($arg == 'pxsort')//修改        {             $this->_pxsort();        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$user = $this->user->get_api($_SESSION['api']);		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$title = $this->input->post('title',true);			$powername = $this->input->post('powername',true);			$where = "own='".$user['own']."'";            //数据排序            $order_str = "sort asc,id asc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			if($powername)			{				$where .= "and powername like '%$powername%'";			}			if($title){				$where .= "and title like '%$title%'";			}            //取得信息列表            $info_list = $this->power->find_all($where,'id,powername,title,powertext,exceltext,sort',$order_str,$start,$perpage);            $final_list = [];            foreach ($info_list as $key => $value) {                $user_list = $this->user->find_all('power = "'.$value['id'].'" ' );                $final_list[$key]['id'] = $value['id'];                $final_list[$key]['powername'] = $value['powername'];                $str = '';                foreach ($user_list as $k => $v) {                    $str.= "<p>".$v['userid'].'</p>';                }                $final_list[$key]['user_list'] = $str;                $final_list[$key]['title'] = $value['title'];				                $final_list[$key]['powertext'] = mb_strlen($value['powertext']) > 90? '<i style="padding:3px;color:#66CC33" class="method fa fa-list-ul" data-t="'.$value['powertext'].'"></i>'.mb_substr($value['powertext'],0,90) : $value['powertext'];                $final_list[$key]['exceltext'] = mb_strlen($value['exceltext']) > 70? '<i style="padding:3px;color:#66CC33"  class="method fa fa-list-ul" data-t="'.$value['exceltext'].'"></i>'.mb_substr($value['exceltext'],0,70) : $value['exceltext'];				$final_list[$key]['sort'] = "<input value=".$value['sort']." onchange='edit_px(this)' data-id= '".$value['id']."' class='px_do' />";             }		    $total = $this->power->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($final_list));		    echo json_encode($rows);exit;		}		$power = $this->power->find_all("1 = 1","*","sort asc,id asc");		$this->data['power'] = $power;		$this->_Template('power',$this->data);	}	//添加	public function _add()	{		$user = $this->user->get_api($_SESSION['api']);		$post = $this->input->post(NULL, TRUE);		if(isset($post['powername']))		{			$post['powername'] = $this->input->post('powername',true);			//$post['excelshop'] = $this->input->post('excelshop',true);			$powertext= $this->input->post('powertext',true);			$powerid = $this->input->post('powerid',true);			$post['powertext'] = "|".$powertext;			$post['powerid'] = "|".$powerid;			$post['own'] = $user['own'];			if($this->power->insert($post))        	{         		echo json_encode(array('msg'=>'添加成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;        	}		}		$this->_Template('power_add',$this->data);	}	//修改	public function _edit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$post['powername'] = $this->input->post('powername',true);			$post['excelshop'] = $this->input->post('excelshop',true);			$powertext= $this->input->post('powertext',true);			$powerid = $this->input->post('powerid',true);			$post['powertext'] = "|".ltrim($powertext,'|');			$post['powerid'] = "|".ltrim($powerid,'|');			$exceltext= $this->input->post('exceltext',true);			$excelid = $this->input->post('excelid',true);			$post['exceltext'] = "|".ltrim($exceltext,'|');			$post['excelid'] = "|".ltrim($excelid,'|');			if($this->power->save($post,$id))        	{         		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		$arg_array = $arg_array[0];		$power = $this->power->read($arg_array);		$this->data['power'] = $power;		$this->_Template('power_edit',$this->data);	}	//删除	public function _del()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{            $id_arr = $this->input->post('s');            $id_arr =  explode(',',$id_arr);            if(!$id_arr)            {                echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;            }            //循环删除记录            foreach ($id_arr as $v) 		    {                $this->power->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }	//获取数据	public function _rows()	{		$user = $this->user->get_api($_SESSION['api']);		$post = $this->input->post(NULL, TRUE);		if(isset($post['rows']))  		{			$rows = $this->input->post('rows',true);            $dataa = $this->nav->find_all('type=1 and '.$user['own'].'=1','*','sort asc');		    $datab = $this->nav->find_all('type=2 and '.$user['own'].'=1','*','son asc');		    $datac = $this->nav->find_all('type=3 and '.$user['own'].'=1','*','sort asc');		    $an = array();		    foreach ($dataa as $key=>$value) 		    {			    foreach ($datab as $ke=>$va) 		        {			    	if($va['class'] == $value['id'])			        {				    	foreach ($datac as $k=>$v) 		                {					    	if($v['class'] == $va['id'])			                {					    		$va['cn'][]=$v;			                }			            }						$value['bn'][]=$va;			        }			     }//循环出二级导航航				 $an[] = $value;            }			$power = array();			if($rows != "null")			{			    $power = $this->power->read($rows);//找出次ID的权限内容				if($power['powerid'])				{			        $power = explode('|',trim($power['powerid'],'|'));//数组化权限内容				}				else				{					$power = array();				}			}		    echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));		}		else if(isset($post['excel']))  		{			$excel = $this->input->post('excel',true);			$rows = $excel;            $dataa = $this->fullorderexcelclassid->find_all('1=1','*','id asc');		    $datab = $this->fullorderexcel->find_all('1=1','*','id asc');		    $an = array();		    foreach ($dataa as $key=>$value) 		    {			    foreach ($datab as $ke=>$va) 		        {			    	if($va['type'] == $value['id'])			        {						$value['bn'][]=$va;			        }			     }//循环出二级导航航				 $an[] = $value;            }			$power = array();			if($rows != "null")			{			    $power = $this->power->read($rows);//找出次ID的权限内容				if($power['excelid'])				{			        $power = explode('|',trim($power['excelid'],'|'));//数组化权限内容				}				else				{					$power = array();				}			}		    echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));		}    }		public function _pxsort(){		$user = $this->user->get_api($_SESSION['api']);		if(empty($user)){			die;		}		$id = $this->input->post('id', TRUE);		$px = $this->input->post('px', TRUE);		$this->power->save(array('sort'=>$px),$id);		echo json_encode(array('code'=>0,'msg'=>'修改成功'));exit;	}}
 |