Delete_list_adminAction.class.php 4.7 KB

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