Power.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 style="padding:3px;color:#66CC33" 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 style="padding:3px;color:#66CC33" 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. $lyapiid = $this->input->post('lyapiid',true);
  140. $lyapitext = $this->input->post('lyapitext',true);
  141. $post['lyapitext'] = "|".ltrim($lyapitext,'|');
  142. $post['lyapiid'] = "|".ltrim($lyapiid,'|');
  143. if($this->power->save($post,$id))
  144. {
  145. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  146. }
  147. else
  148. {
  149. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  150. }
  151. }
  152. $arg_array = $arg_array[0];
  153. $power = $this->power->read($arg_array);
  154. $this->data['power'] = $power;
  155. $this->_Template('power_edit',$this->data);
  156. }
  157. //删除
  158. public function _del()
  159. {
  160. $post = $this->input->post(NULL, TRUE);
  161. if(isset($post['s']))
  162. {
  163. $id_arr = $this->input->post('s');
  164. $id_arr = explode(',',$id_arr);
  165. if(!$id_arr)
  166. {
  167. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  168. }
  169. //循环删除记录
  170. foreach ($id_arr as $v)
  171. {
  172. $this->power->remove($v);
  173. }
  174. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  175. }
  176. }
  177. //获取数据
  178. public function _rows()
  179. {
  180. $user = $this->user->get_api($_SESSION['api']);
  181. $post = $this->input->post(NULL, TRUE);
  182. if(isset($post['rows']))
  183. {
  184. $rows = $this->input->post('rows',true);
  185. $dataa = $this->nav->find_all('type=1 and '.$user['own'].'=1','*','sort asc');
  186. $datab = $this->nav->find_all('type=2 and '.$user['own'].'=1','*','son asc');
  187. $datac = $this->nav->find_all('type=3 and '.$user['own'].'=1','*','sort asc');
  188. $an = array();
  189. foreach ($dataa as $key=>$value)
  190. {
  191. foreach ($datab as $ke=>$va)
  192. {
  193. if($va['class'] == $value['id'])
  194. {
  195. foreach ($datac as $k=>$v)
  196. {
  197. if($v['class'] == $va['id'])
  198. {
  199. $va['cn'][]=$v;
  200. }
  201. }
  202. $value['bn'][]=$va;
  203. }
  204. }//循环出二级导航航
  205. $an[] = $value;
  206. }
  207. $power = array();
  208. if($rows != "null")
  209. {
  210. $power = $this->power->read($rows);//找出次ID的权限内容
  211. if($power['powerid'])
  212. {
  213. $power = explode('|',trim($power['powerid'],'|'));//数组化权限内容
  214. }
  215. else
  216. {
  217. $power = array();
  218. }
  219. }
  220. echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));
  221. }
  222. else if(isset($post['excel']))
  223. {
  224. $excel = $this->input->post('excel',true);
  225. $rows = $excel;
  226. $dataa = $this->fullorderexcelclassid->find_all('1=1','*','id asc');
  227. $datab = $this->fullorderexcel->find_all('1=1','*','id asc');
  228. $an = array();
  229. foreach ($dataa as $key=>$value)
  230. {
  231. foreach ($datab as $ke=>$va)
  232. {
  233. if($va['type'] == $value['id'])
  234. {
  235. $value['bn'][]=$va;
  236. }
  237. }//循环出二级导航航
  238. $an[] = $value;
  239. }
  240. $power = array();
  241. if($rows != "null")
  242. {
  243. $power = $this->power->read($rows);//找出次ID的权限内容
  244. if($power['excelid'])
  245. {
  246. $power = explode('|',trim($power['excelid'],'|'));//数组化权限内容
  247. }
  248. else
  249. {
  250. $power = array();
  251. }
  252. }
  253. echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));
  254. }elseif(isset($post['lyapi'])){
  255. $lyapi = $this->input->post('lyapi',true);
  256. $rows = $lyapi;
  257. $res = $this->power->_lyapi();
  258. $dataa = $res['type_list'];
  259. $datab = $res['lyapi_list'];
  260. $an = array();
  261. foreach ($dataa as $key=>$value)
  262. {
  263. foreach ($datab as $ke=>$va)
  264. {
  265. if($va['classid'] == $value['id'])
  266. {
  267. $value['bn'][]=$va;
  268. }
  269. }//循环出二级导航航
  270. $an[] = $value;
  271. }
  272. $power = array();
  273. if($rows != "null")
  274. {
  275. $power = $this->power->read($rows);//找出次ID的权限内容
  276. if($power['lyapiid'])
  277. {
  278. $power = explode('|',trim($power['lyapiid'],'|'));//数组化权限内容
  279. }
  280. else
  281. {
  282. $power = array();
  283. }
  284. }
  285. echo json_encode(array('msg'=>($an),'power'=>($power),'success'=>true));
  286. }
  287. }
  288. public function _pxsort(){
  289. $user = $this->user->get_api($_SESSION['api']);
  290. if(empty($user)){
  291. die;
  292. }
  293. $id = $this->input->post('id', TRUE);
  294. $px = $this->input->post('px', TRUE);
  295. $this->power->save(array('sort'=>$px),$id);
  296. echo json_encode(array('code'=>0,'msg'=>'修改成功'));exit;
  297. }
  298. }