Delete_list_adminAction.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 导入客户信息,导出客户信息
  4. */
  5. require_once( ONU_ROOT . 'application/module/ctrl/Action.class.php');
  6. require_once ( ONU_ROOT . 'application/lib/data/adminAction.php');
  7. class Delete_list_adminAction extends Action{
  8. public function __construct(){
  9. parent::__construct();
  10. if(empty($_SESSION['mds_user'])){
  11. header("Location:/?a=index&m=admin_login");
  12. exit();
  13. }
  14. // $this->checkAdministratorRight('1');
  15. }
  16. //客户列表
  17. public function index(){
  18. require_once (ONU_ROOT . "frame/Page.class.php");
  19. $admin = new AdvertAdminAction();
  20. $uid = $_SESSION['user_infos']['id'];
  21. $where = " where uid='$uid' ";
  22. $group_list = $admin->select_user_group($where);
  23. $this->assign('group_list',$group_list);
  24. $this->display("index.html");
  25. }
  26. //批量删除客户
  27. public function batch_delete(){
  28. $admin = new AdvertAdminAction();
  29. $uid = $_SESSION['user_infos']['id'];
  30. $id_array = $_POST['id_array'];
  31. $count = count($id_array);
  32. if($count==1){
  33. $id = $id_array[0];
  34. $delete = $admin->deleteCustomer($id,$uid);
  35. $info = "删除成功";
  36. header("Location:/?a=customer_list_admin&m=index&info=$info");
  37. exit();
  38. }else if($count>1){
  39. $in_array = implode(',',$id_array);
  40. $delete = $admin->deleteBatchCustomer($in_array,$uid);
  41. $info = "删除成功";
  42. header("Location:/?a=customer_list_admin&m=index&info=$info");
  43. exit();
  44. }
  45. }
  46. public function deleteByGroup() {
  47. $admin = new AdvertAdminAction();
  48. $uid = $_SESSION['user_infos']['id'];
  49. echo $uid;
  50. print_r($_POST);
  51. }
  52. //导入excel
  53. public function importDelete(){
  54. $admin = new AdvertAdminAction();
  55. $uid = $_SESSION['user_infos']['id'];
  56. if($_POST['to_import_user']=='yes'){
  57. $filename = $_FILES['inputExcel']['name'];
  58. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  59. $excel_array = $this->uploadFile($filename,$tmp_name);
  60. if(!empty($excel_array['error'])){
  61. //导入失败
  62. $info = $excel_array['error'];
  63. }else{
  64. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  65. header("Content-type: text/html; charset=utf-8");
  66. $list=array_column($excel_array,0);
  67. $data="";
  68. for ($i=0; $i <= count($list); $i++) {
  69. if(filter_var($list[$i],FILTER_VALIDATE_EMAIL)){
  70. $data.='"'.$list[$i].'",';
  71. }
  72. if($i&&($i%30==0||$i==count($list))){
  73. $delete = $admin->deleteBatchCustomerByEmail(trim($data,','),$uid);
  74. $data="";
  75. }
  76. $info="成功";
  77. }
  78. header("Location:/?a=customer_list_admin&m=index&info=$info");
  79. exit();
  80. }
  81. }
  82. }
  83. //导入Excel文件
  84. function uploadFile($file,$filetempname)
  85. {
  86. //自己设置的上传文件存放路径
  87. $filePath = 'static/upload/';
  88. $str = "";
  89. //下面的路径按照你PHPExcel的路径来修改
  90. require_once ONU_ROOT . 'phpexcel/PHPExcel.php';
  91. require_once ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php';
  92. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel5.php';
  93. //require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/CSV.php';
  94. //注意设置时区
  95. $time=date("y-m-d-H-i-s");//去当前上传的时间
  96. //获取上传文件的扩展名
  97. $extend=strrchr ($file,'.');
  98. //上传后的文件名
  99. $name=$time.$extend;
  100. $uploadfile=$filePath.$name;//上传后的文件名地址
  101. //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
  102. $result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
  103. //echo $result;
  104. if($result) //如果上传文件成功,就执行导入excel操作
  105. {
  106. $objReader = PHPExcel_IOFactory::createReader('CSV');//use excel2007 for 2007 format
  107. $objPHPExcel = $objReader->load($uploadfile);
  108. $sheet = $objPHPExcel->getSheet(0);
  109. $highestRow = $sheet->getHighestRow(); //取得总行数
  110. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  111. /* 第二种方法*/
  112. $objWorksheet = $objPHPExcel->getActiveSheet();
  113. $highestRow = $objWorksheet->getHighestRow();
  114. echo 'highestRow='.$highestRow;
  115. echo "<br>";
  116. $highestColumn = $objWorksheet->getHighestColumn();
  117. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
  118. echo 'highestColumnIndex='.$highestColumnIndex;
  119. echo "<br>";
  120. $headtitle=array();
  121. //获取到的excel数据
  122. $excel_array = array();
  123. for ($row = 1;$row <= $highestRow;$row++)
  124. {
  125. $strs=array();
  126. //注意highestColumnIndex的列数索引从0开始
  127. for ($col = 0;$col < $highestColumnIndex;$col++)
  128. {
  129. $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
  130. if($strs[$col] instanceof PHPExcel_RichText){ //富文本转换字符串
  131. $strs[$col] = $strs[$col]->__toString();
  132. }
  133. //第七个数字是日期型的
  134. // if($col==7){
  135. // $strs[$col]=gmdate("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($strs[$col]));
  136. // }
  137. }
  138. array_push($excel_array, $strs);
  139. }
  140. }
  141. else
  142. {
  143. $excel_array['error'] = "导入失败!";
  144. }
  145. return $excel_array;
  146. }
  147. // class end
  148. }
  149. ?>