Devicemaster.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Devicemaster extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_devicemaster','devicemaster');
  8. }
  9. //定义方法的调用规则 获取URI第二段值
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg == 'add')
  13. {
  14. $this->_add();
  15. }
  16. else if($arg == 'edit')
  17. {
  18. $this->_edit($arg_array);
  19. }
  20. else if($arg == 'see')
  21. {
  22. $this->_see($arg_array);
  23. }
  24. else if($arg == 'data')
  25. {
  26. $this->_data();
  27. }
  28. else if($arg == 'del')
  29. {
  30. $this->_del();
  31. }
  32. else if($arg == 'indexexcel'){
  33. $this->_indexexcel();
  34. }
  35. else
  36. {
  37. $this->_index();
  38. }
  39. }
  40. public $depart_list =[
  41. 1=>"独立站",
  42. 2=>"Tiktok",
  43. 3=>"亚马逊",
  44. 4=>"速卖通",
  45. 5=>"其他",
  46. ];
  47. public $plat_list = [
  48. 1=>"独立站",
  49. 2=>"Tiktok",
  50. 3=>"亚马逊",
  51. 4=>"速卖通",
  52. 5=>"其他",
  53. ];
  54. public $type_list = [
  55. 1=>"站内",
  56. 2=>"站外",
  57. ];
  58. public $shop_list = [
  59. 1=>"Alipearl",
  60. 2=>"WestKiss",
  61. 3=>"Asteria",
  62. 4=>"Wiggins",
  63. 5=>"Yolissa",
  64. 6=>"SuperNova",
  65. 7=>"无",
  66. ];
  67. public function _index(){
  68. $this->data['depart_list'] = $this->depart_list;
  69. $this->data['plat_list'] = $this->plat_list;
  70. $this->data['type_list'] = $this->type_list;
  71. $this->data['shop_list']=$this->shop_list;
  72. $this->_Template("devicemaster",$this->data);
  73. }
  74. public function _add(){
  75. $post = $this->input->post(NULL, TRUE);
  76. if(!empty($post))
  77. {
  78. $information = [];
  79. $tmp = $this->input->post('information',true);
  80. foreach($tmp as $v){
  81. if(!empty($v)){
  82. $information[] = $v;
  83. }
  84. }
  85. $time = date("Y-m-d H:i:s",time());
  86. $insert_data =[
  87. 'depart_id'=>$this->input->post('depart_id',true),
  88. 'type_id'=>$this->input->post('type_id',true),
  89. 'plat_id'=>$this->input->post('plat_id',true),
  90. 'shop_id'=>$this->input->post('shop_id',true),
  91. 'mobile_type'=>$this->input->post('mobile_type',true),
  92. 'mobile_color'=>$this->input->post('mobile_color',true),
  93. 'mobile'=>$this->input->post('mobile',true),
  94. 'mobile_user'=>$this->input->post('mobile_user',true),
  95. 'id_account'=>$this->input->post('id_account',true),
  96. 'id_password'=>$this->input->post('id_password',true),
  97. 'unlock_password'=>$this->input->post('unlock_password',true),
  98. 'remarks'=>$this->input->post('remarks',true),
  99. 'purpose'=>$this->input->post('purpose',true),
  100. "information"=>json_encode($information,JSON_UNESCAPED_UNICODE),
  101. "is_delete"=>0,
  102. "create_time"=>$time,
  103. "update_time"=>$time
  104. ];
  105. if($this->devicemaster->insert( $insert_data))
  106. {
  107. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  108. }
  109. else
  110. {
  111. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  112. }
  113. }
  114. $this->data['depart_list'] = $this->depart_list;
  115. $this->data['plat_list'] = $this->plat_list;
  116. $this->data['type_list'] = $this->type_list;
  117. $this->data['shop_list']=$this->shop_list;
  118. $this->_Template('devicemaster_add',$this->data);
  119. }
  120. public function _edit($arg_array){
  121. $post = $this->input->post(NULL, TRUE);
  122. if(isset($post['id'])){
  123. $id = $this->input->post('id',true);
  124. $information = [];
  125. $tmp = $this->input->post('information',true);
  126. foreach($tmp as $v){
  127. if(!empty($v)){
  128. $information[] = $v;
  129. }
  130. }
  131. $time = date("Y-m-d H:i:s",time());
  132. $update_data =[
  133. 'depart_id'=>$this->input->post('depart_id',true),
  134. 'type_id'=>$this->input->post('type_id',true),
  135. 'plat_id'=>$this->input->post('plat_id',true),
  136. 'shop_id'=>$this->input->post('shop_id',true),
  137. 'mobile_type'=>$this->input->post('mobile_type',true),
  138. 'mobile_color'=>$this->input->post('mobile_color',true),
  139. 'mobile'=>$this->input->post('mobile',true),
  140. 'mobile_user'=>$this->input->post('mobile_user',true),
  141. 'id_account'=>$this->input->post('id_account',true),
  142. 'id_password'=>$this->input->post('id_password',true),
  143. 'unlock_password'=>$this->input->post('unlock_password',true),
  144. 'remarks'=>$this->input->post('remarks',true),
  145. 'purpose'=>$this->input->post('purpose',true),
  146. "information"=>json_encode($information,JSON_UNESCAPED_UNICODE),
  147. "is_delete"=>0,
  148. "update_time"=>$time
  149. ];
  150. if($this->devicemaster->save($update_data,$id))
  151. {
  152. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  153. }
  154. else
  155. {
  156. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  157. }
  158. }
  159. $id= $arg_array[0];
  160. $info = $this->devicemaster->read($id);
  161. $info['information'] = json_decode($info['information'],true);
  162. $this->data['depart_list'] = $this->depart_list;
  163. $this->data['plat_list'] = $this->plat_list;
  164. $this->data['type_list'] = $this->type_list;
  165. $this->data['shop_list']=$this->shop_list;
  166. $this->data['info'] = $info;
  167. $this->_Template('devicemaster_edit',$this->data);
  168. }
  169. public function _see(){
  170. }
  171. public function _del(){
  172. $post = $this->input->post(NULL, TRUE);
  173. if(isset($post['s']))
  174. {
  175. $id_arr = $this->input->post('s');
  176. $id_arr = explode(',',$id_arr);
  177. if(!$id_arr)
  178. {
  179. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  180. }
  181. $time = date("Y-m-d H:i:s",time());
  182. //循环删除记录
  183. foreach ($id_arr as $v)
  184. {
  185. if(!empty($v)){
  186. $this->devicemaster->save(['is_delete'=>1,'delete_time'=>$time],$v);
  187. }
  188. }
  189. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  190. }
  191. }
  192. public function _data(){
  193. $post = $this->input->post(NULL, TRUE);
  194. if(isset($post['page']))
  195. {
  196. $page = $this->input->post('page',true);
  197. $perpage = $this->input->post('perpage',true);
  198. $depart_id = $this->input->post('depart_id',true);
  199. $type_id = $this->input->post('type_id',true);
  200. $plat_id = $this->input->post('plat_id',true);
  201. $shop_id = $this->input->post('shop_id',true);
  202. $mobile= $this->input->post('mobile',true);
  203. $mobile_user = $this->input->post('mobile_user',true);
  204. $where = " is_delete = 0";
  205. if($depart_id)
  206. {
  207. $where .= " and depart_id = '$depart_id'";
  208. }
  209. if($type_id)
  210. {
  211. $where .= " and type_id = '$type_id'";
  212. }
  213. if($plat_id)
  214. {
  215. $where .= " and plat_id = '$plat_id'";
  216. }
  217. if( $shop_id)
  218. {
  219. $where .= " and shop_id = ' $shop_id'";
  220. }
  221. if($mobile)
  222. {
  223. $where .= " and mobile like '%$mobile%'";
  224. }
  225. if($mobile_user)
  226. {
  227. $where .= " and mobile_user like '%$mobile_user%'";
  228. }
  229. //数据排序
  230. $order_str = "id asc";
  231. if(empty($page))
  232. {
  233. $start = 0;
  234. $perpage = 1;
  235. }
  236. else
  237. {
  238. $start = ($page - 1)*$perpage;
  239. }
  240. //取得信息列表
  241. $info_list = $this->devicemaster->find_all($where,'id,mobile,mobile_user,depart_id,type_id,shop_id,plat_id,mobile_type,mobile_color,id_account,id_password,unlock_password,remarks,purpose,information',$order_str,$start,$perpage);
  242. //格式化数据
  243. foreach ($info_list as $key=>$value)
  244. {
  245. // if($value['status'] == 1)
  246. // {
  247. // $info_list[$key]['status'] = '正常';
  248. // }
  249. // else
  250. // {
  251. // $info_list[$key]['status'] = '禁用';
  252. // }
  253. if(isset($this->depart_list[$info_list[$key]['depart_id']])){
  254. $info_list[$key]['depart_id'] = $this->depart_list[$info_list[$key]['depart_id']];
  255. }
  256. if(isset($this->plat_list[$info_list[$key]['plat_id']])){
  257. $info_list[$key]['plat_id'] =$this->plat_list[$info_list[$key]['plat_id']];
  258. }
  259. if(isset($this->shop_list[$info_list[$key]['shop_id']])){
  260. $info_list[$key]['shop_id'] = $this->shop_list[$info_list[$key]['shop_id']];
  261. }
  262. if(isset($this->type_list[$info_list[$key]['type_id']])){
  263. $info_list[$key]['type_id'] = $this->type_list[$info_list[$key]['type_id']];
  264. }
  265. $information_str = "";
  266. $information = json_decode($info_list[$key]['information'],true);
  267. if(empty($information)){
  268. $info_list[$key]['information'] = "";
  269. }else{
  270. foreach($information as $index=>$item){
  271. $information_str .="<div style='margin-bottom:3px;border:1px dashed #000'>".$item."</div>";
  272. }
  273. $info_list[$key]['information'] = $information_str;
  274. }
  275. }
  276. $total = $this->devicemaster->find_count($where);
  277. $pagenum = ceil($total/$perpage);
  278. $over = $total-($start+$perpage);
  279. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  280. echo json_encode($rows);exit;
  281. }
  282. }
  283. public function _indexexcel(){
  284. $depart_id = $this->input->post('depart_id',true);
  285. $type_id = $this->input->post('type_id',true);
  286. $plat_id = $this->input->post('plat_id',true);
  287. $shop_id = $this->input->post('shop_id',true);
  288. $mobile= $this->input->post('mobile',true);
  289. $mobile_user = $this->input->post('mobile_user',true);
  290. $where = " is_delete = 0";
  291. if($depart_id)
  292. {
  293. $where .= " and depart_id = '$depart_id'";
  294. }
  295. if($type_id)
  296. {
  297. $where .= " and type_id = '$type_id'";
  298. }
  299. if($plat_id)
  300. {
  301. $where .= " and plat_id = '$plat_id'";
  302. }
  303. if( $shop_id)
  304. {
  305. $where .= " and shop_id = ' $shop_id'";
  306. }
  307. if($mobile)
  308. {
  309. $where .= " and mobile like '%$mobile%'";
  310. }
  311. if($mobile_user)
  312. {
  313. $where .= " and mobile_user like '%$mobile_user%'";
  314. }
  315. //数据排序
  316. $order_str = "id asc";
  317. //取得信息列表
  318. $info_list = $this->devicemaster->find_all($where,'id,mobile,mobile_user,depart_id,type_id,shop_id,plat_id,mobile_type,mobile_color,id_account,id_password,unlock_password,remarks,purpose,information',$order_str,0,null);
  319. //格式化数据
  320. $final_list = [];
  321. foreach ($info_list as $key=>$value)
  322. {
  323. $final_list[$key]['ID'] = $value['id'];
  324. $final_list[$key]['手机号'] = $value['mobile'];
  325. $final_list[$key]['手机用户'] = $value['mobile_user'];
  326. $final_list[$key]['部门'] = isset($this->depart_list[$value['depart_id']])?$this->depart_list[$value['depart_id']]:'';
  327. $final_list[$key]['平台'] = isset($this->plat_list[$value['plat_id']])?$this->plat_list[$value['plat_id']]:'';
  328. $final_list[$key]['店铺'] = isset($this->shop_list[$value['shop_id']])?$this->shop_list[$value['shop_id']]:'';
  329. $final_list[$key]['手机类型'] = $value['mobile_type'];
  330. $final_list[$key]['手机颜色'] = $value['mobile_color'];
  331. $final_list[$key]['ID账号'] = $value['id_account'];
  332. $final_list[$key]['ID密码'] = $value['id_password'];
  333. $final_list[$key]['解锁密码'] = $value['unlock_password'];
  334. $final_list[$key]['备注'] = $value['remarks'];
  335. $final_list[$key]['用途'] = $value['purpose'];
  336. $information_str = "";
  337. $information = json_decode($info_list[$key]['information'],true);
  338. if(empty($information)){
  339. $information_str = "";
  340. }else{
  341. // foreach($information as $index=>$item){
  342. // $information_str .= $item.";";
  343. // }
  344. $information_str = json_encode($information,JSON_UNESCAPED_UNICODE);
  345. }
  346. $final_list[$key]['信息'] = $information_str;
  347. }
  348. echo json_encode(['data'=>$final_list,'success'=>true,'msg'=>'导出成功']);exit;
  349. }
  350. }