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