Power.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Power extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_power','power');
  7. $this->load->_model('Model_user','user');
  8. $this->load->_model('Model_nav','nav');
  9. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  10. $this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid');
  11. }
  12. //定义方法的调用规则 获取URI第二段值
  13. public function _remap($arg,$arg_array)
  14. {
  15. if($arg == 'add')//添加
  16. {
  17. $this->_add();
  18. }
  19. else if($arg == 'edit')//修改
  20. {
  21. $this->_edit($arg_array);
  22. }
  23. else if($arg == 'del')//修改
  24. {
  25. $this->_del();
  26. }
  27. else if($arg == 'rows')//获取数据
  28. {
  29. $this->_rows();
  30. }
  31. else if($arg == 'pxsort')//修改
  32. {
  33. $this->_pxsort();
  34. }
  35. else
  36. {
  37. $this->_index();
  38. }
  39. }
  40. //管理
  41. public function _index()
  42. {
  43. $user = $this->user->get_api($_SESSION['api']);
  44. $post = $this->input->post(NULL, TRUE);
  45. if(isset($post['page']))
  46. {
  47. $page = $this->input->post('page',true);
  48. $perpage = $this->input->post('perpage',true);
  49. $title = $this->input->post('title',true);
  50. $powername = $this->input->post('powername',true);
  51. $where = "own='".$user['own']."'";
  52. //数据排序
  53. $order_str = "sort asc,id asc";
  54. if(empty($page))
  55. {
  56. $start = 0;
  57. $perpage = 1;
  58. }
  59. else
  60. {
  61. $start = ($page - 1)*$perpage;
  62. }
  63. if($powername)
  64. {
  65. $where .= "and powername like '%$powername%'";
  66. }
  67. if($title){
  68. $where .= "and title like '%$title%'";
  69. }
  70. //取得信息列表
  71. $info_list = $this->power->find_all($where,'id,powername,title,powertext,exceltext,sort',$order_str,$start,$perpage);
  72. $final_list = [];
  73. foreach ($info_list as $key => $value) {
  74. $user_list = $this->user->find_all('power = "'.$value['id'].'" ' );
  75. $final_list[$key]['id'] = $value['id'];
  76. $final_list[$key]['powername'] = $value['powername'];
  77. $str = '';
  78. foreach ($user_list as $k => $v) {
  79. $str.= "<p>".$v['userid'].'</p>';
  80. }
  81. $final_list[$key]['user_list'] = $str;
  82. $final_list[$key]['title'] = $value['title'];
  83. $final_list[$key]['powertext'] = mb_strlen($value['powertext']) > 90? '<i class="method fa fa-list-ul" data-t="'.$value['powertext'].'"></i>'.mb_substr($value['powertext'],0,90) : $value['powertext'];
  84. $final_list[$key]['exceltext'] = mb_strlen($value['exceltext']) > 70? '<i class="method fa fa-list-ul" data-t="'.$value['exceltext'].'"></i>'.mb_substr($value['exceltext'],0,70) : $value['exceltext'];
  85. $final_list[$key]['sort'] = "<input value=".$value['sort']." onchange='edit_px(this)' data-id= '".$value['id']."' class='px_do' />";
  86. }
  87. $total = $this->power->find_count($where);
  88. $pagenum = ceil($total/$perpage);
  89. $over = $total-($start+$perpage);
  90. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($final_list));
  91. echo json_encode($rows);exit;
  92. }
  93. $power = $this->power->find_all("1 = 1","*","sort asc,id asc");
  94. $this->data['power'] = $power;
  95. $this->_Template('power',$this->data);
  96. }
  97. //添加
  98. public function _add()
  99. {
  100. $user = $this->user->get_api($_SESSION['api']);
  101. $post = $this->input->post(NULL, TRUE);
  102. if(isset($post['powername']))
  103. {
  104. $post['powername'] = $this->input->post('powername',true);
  105. //$post['excelshop'] = $this->input->post('excelshop',true);
  106. $powertext= $this->input->post('powertext',true);
  107. $powerid = $this->input->post('powerid',true);
  108. $post['powertext'] = "|".$powertext;
  109. $post['powerid'] = "|".$powerid;
  110. $post['own'] = $user['own'];
  111. if($this->power->insert($post))
  112. {
  113. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  114. }
  115. else
  116. {
  117. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  118. }
  119. }
  120. $this->_Template('power_add',$this->data);
  121. }
  122. //修改
  123. public function _edit($arg_array)
  124. {
  125. $post = $this->input->post(NULL, TRUE);
  126. if(isset($post['id']))
  127. {
  128. $id = $this->input->post('id',true);
  129. $post['powername'] = $this->input->post('powername',true);
  130. $post['excelshop'] = $this->input->post('excelshop',true);
  131. $powertext= $this->input->post('powertext',true);
  132. $powerid = $this->input->post('powerid',true);
  133. $post['powertext'] = "|".ltrim($powertext,'|');
  134. $post['powerid'] = "|".ltrim($powerid,'|');
  135. $exceltext= $this->input->post('exceltext',true);
  136. $excelid = $this->input->post('excelid',true);
  137. $post['exceltext'] = "|".ltrim($exceltext,'|');
  138. $post['excelid'] = "|".ltrim($excelid,'|');
  139. if($this->power->save($post,$id))
  140. {
  141. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  142. }
  143. else
  144. {
  145. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  146. }
  147. }
  148. $arg_array = $arg_array[0];
  149. $power = $this->power->read($arg_array);
  150. $this->data['power'] = $power;
  151. $this->_Template('power_edit',$this->data);
  152. }
  153. //删除
  154. public function _del()
  155. {
  156. $post = $this->input->post(NULL, TRUE);
  157. if(isset($post['s']))
  158. {
  159. $id_arr = $this->input->post('s');
  160. $id_arr = explode(',',$id_arr);
  161. if(!$id_arr)
  162. {
  163. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  164. }
  165. //循环删除记录
  166. foreach ($id_arr as $v)
  167. {
  168. $this->power->remove($v);
  169. }
  170. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  171. }
  172. }
  173. //获取数据
  174. public function _rows()
  175. {
  176. $user = $this->user->get_api($_SESSION['api']);
  177. $post = $this->input->post(NULL, TRUE);
  178. if(isset($post['rows']))
  179. {
  180. $rows = $this->input->post('rows',true);
  181. $dataa = $this->nav->find_all('type=1 and '.$user['own'].'=1','*','sort asc');
  182. $datab = $this->nav->find_all('type=2 and '.$user['own'].'=1','*','son asc');
  183. $datac = $this->nav->find_all('type=3 and '.$user['own'].'=1','*','sort asc');
  184. $an = array();
  185. foreach ($dataa as $key=>$value)
  186. {
  187. foreach ($datab as $ke=>$va)
  188. {
  189. if($va['class'] == $value['id'])
  190. {
  191. foreach ($datac as $k=>$v)
  192. {
  193. if($v['class'] == $va['id'])
  194. {
  195. $va['cn'][]=$v;
  196. }
  197. }
  198. $value['bn'][]=$va;
  199. }
  200. }//循环出二级导航航
  201. $an[] = $value;
  202. }
  203. $power = array();
  204. if($rows != "null")
  205. {
  206. $power = $this->power->read($rows);//找出次ID的权限内容
  207. if($power['powerid'])
  208. {
  209. $power = explode('|',trim($power['powerid'],'|'));//数组化权限内容
  210. }
  211. else
  212. {
  213. $power = array();
  214. }
  215. }
  216. echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));
  217. }
  218. else if(isset($post['excel']))
  219. {
  220. $excel = $this->input->post('excel',true);
  221. $rows = $excel;
  222. $dataa = $this->fullorderexcelclassid->find_all('1=1','*','id asc');
  223. $datab = $this->fullorderexcel->find_all('1=1','*','id asc');
  224. $an = array();
  225. foreach ($dataa as $key=>$value)
  226. {
  227. foreach ($datab as $ke=>$va)
  228. {
  229. if($va['type'] == $value['id'])
  230. {
  231. $value['bn'][]=$va;
  232. }
  233. }//循环出二级导航航
  234. $an[] = $value;
  235. }
  236. $power = array();
  237. if($rows != "null")
  238. {
  239. $power = $this->power->read($rows);//找出次ID的权限内容
  240. if($power['excelid'])
  241. {
  242. $power = explode('|',trim($power['excelid'],'|'));//数组化权限内容
  243. }
  244. else
  245. {
  246. $power = array();
  247. }
  248. }
  249. echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));
  250. }
  251. }
  252. public function _pxsort(){
  253. $user = $this->user->get_api($_SESSION['api']);
  254. if(empty($user)){
  255. die;
  256. }
  257. $id = $this->input->post('id', TRUE);
  258. $px = $this->input->post('px', TRUE);
  259. $this->power->save(array('sort'=>$px),$id);
  260. echo json_encode(array('code'=>0,'msg'=>'修改成功'));exit;
  261. }
  262. }