Blacklist_adminAction.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 Blacklist_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('5');
  15. }
  16. function index(){
  17. $admin = new AdvertAdminAction();
  18. $where = "where uid='{$_SESSION['user_infos']['id']}'";
  19. $uname = $_SESSION['user_infos']['uname'];
  20. $info = $_REQUEST['info'];
  21. $error = $_REQUEST['error'];
  22. // $isexcel = $_POST['isexcel'];
  23. //
  24. // //导入数据
  25. //
  26. // if($_POST['leadExcel'] == "true")
  27. // {
  28. // $filename = $_FILES['inputExcel']['name'];
  29. // $tmp_name = $_FILES['inputExcel']['tmp_name'];
  30. //
  31. // $excel_array = $this->uploadFile($filename,$tmp_name);
  32. //
  33. // if(!empty($excel_array['error'])){
  34. // //导入失败
  35. // $error = $excel_array['error'];
  36. //
  37. // }else{
  38. //
  39. // unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  40. // header("Content-type: text/html; charset=utf-8");
  41. //
  42. // foreach($excel_array as $array){
  43. //
  44. // $insert = $admin->add_black_content($array[0], $array[1], $array[2], $array[3], $array[4], $array[5], $array[6], strtotime($array[7]), time());
  45. //
  46. // }
  47. //
  48. // $info = '导入数据成功';
  49. //
  50. // header("Location:/?a=blacklist_admin&m=index&info=$info");
  51. // exit();
  52. //
  53. // }
  54. //
  55. //
  56. // }
  57. // //end
  58. $list = $admin->select_black_list($where);
  59. foreach($list as &$ls){
  60. $ls['add_time'] = date('Y-m-d H:i:s',$ls['add_time']);
  61. $ls['update_time'] = date('Y-m-d H:i:s',$ls['update_time']);
  62. }
  63. // //导出数据
  64. // if($isexcel=='yes'){
  65. //
  66. // $this->generateEXCEL('blacklist',$list);
  67. //
  68. // exit;
  69. // }
  70. $this->assign('info',$info);
  71. $this->assign('error',$error);
  72. $this->assign('list',$list);
  73. $this->assign('uname',$uname);
  74. $this->display('index.html');
  75. }
  76. //导出excel
  77. function generateEXCEL($filename = 'report',$data = ''){
  78. //引入PHPExcel相关文件
  79. require_once( ONU_ROOT . 'phpexcel/PHPExcel.php');
  80. require_once( ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php');
  81. require_once( ONU_ROOT . 'phpexcel/PHPExcel/Writer/Excel5.php');
  82. //新建
  83. $resultPHPExcel = new PHPExcel();
  84. //设置参数
  85. //设值
  86. $resultPHPExcel->getActiveSheet()->setCellValue('A1', '订单来源');
  87. $resultPHPExcel->getActiveSheet()->setCellValue('B1', '负责人姓名 ');
  88. $resultPHPExcel->getActiveSheet()->setCellValue('C1', '用户名');
  89. $resultPHPExcel->getActiveSheet()->setCellValue('D1', '用户uid');
  90. $resultPHPExcel->getActiveSheet()->setCellValue('E1', '国家 ');
  91. $resultPHPExcel->getActiveSheet()->setCellValue('F1', '订单金额');
  92. $resultPHPExcel->getActiveSheet()->setCellValue('G1', '备注说明 ');
  93. $resultPHPExcel->getActiveSheet()->setCellValue('H1', '上次购买日期');
  94. $i = 2;
  95. foreach($data as $item){
  96. $resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $item['order_from']);
  97. $resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $item['fz_name']);
  98. $resultPHPExcel->getActiveSheet()->setCellValue('C' . $i, $item['uname']);
  99. $resultPHPExcel->getActiveSheet()->setCellValue('D' . $i, $item['uid']);
  100. $resultPHPExcel->getActiveSheet()->setCellValue('E' . $i, $item['country']);
  101. $resultPHPExcel->getActiveSheet()->setCellValue('F' . $i, $item['money']);
  102. $resultPHPExcel->getActiveSheet()->setCellValue('G' . $i, $item['remark']);
  103. $resultPHPExcel->getActiveSheet()->setCellValue('H' . $i, date('Y-m-d',$item['pre_time']));
  104. $i ++;
  105. }
  106. //设置导出文件名
  107. $outputFileName = "$filename.xls";
  108. $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel);
  109. ob_end_clean();//清除缓冲区,避免乱码
  110. //ob_start(); ob_flush();
  111. header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
  112. header("Content-Type: application/force-download");
  113. header("Content-Type: application/octet-stream");
  114. header("Content-Type: application/download");
  115. header('Content-Disposition:inline;filename="'.$outputFileName.'"');
  116. header("Content-Transfer-Encoding: binary");
  117. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  118. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  119. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  120. header("Pragma: no-cache");
  121. $finalFileName = $outputFileName;
  122. $xlsWriter->save($finalFileName);
  123. echo file_get_contents($finalFileName);
  124. exit;
  125. }
  126. //导入Excel文件
  127. function uploadFile($file,$filetempname)
  128. {
  129. //自己设置的上传文件存放路径
  130. $filePath = 'static/upload/';
  131. $str = "";
  132. //下面的路径按照你PHPExcel的路径来修改
  133. require_once ONU_ROOT . 'phpexcel/PHPExcel.php';
  134. require_once ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php';
  135. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel5.php';
  136. //注意设置时区
  137. $time=date("y-m-d-H-i-s");//去当前上传的时间
  138. //获取上传文件的扩展名
  139. $extend=strrchr ($file,'.');
  140. //上传后的文件名
  141. $name=$time.$extend;
  142. $uploadfile=$filePath.$name;//上传后的文件名地址
  143. //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
  144. $result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
  145. //echo $result;
  146. if($result) //如果上传文件成功,就执行导入excel操作
  147. {
  148. $objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
  149. $objPHPExcel = $objReader->load($uploadfile);
  150. $sheet = $objPHPExcel->getSheet(0);
  151. $highestRow = $sheet->getHighestRow(); //取得总行数
  152. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  153. /* 第二种方法*/
  154. $objWorksheet = $objPHPExcel->getActiveSheet();
  155. $highestRow = $objWorksheet->getHighestRow();
  156. echo 'highestRow='.$highestRow;
  157. echo "<br>";
  158. $highestColumn = $objWorksheet->getHighestColumn();
  159. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
  160. echo 'highestColumnIndex='.$highestColumnIndex;
  161. echo "<br>";
  162. $headtitle=array();
  163. //获取到的excel数据
  164. $excel_array = array();
  165. for ($row = 1;$row <= $highestRow;$row++)
  166. {
  167. $strs=array();
  168. //注意highestColumnIndex的列数索引从0开始
  169. for ($col = 0;$col < $highestColumnIndex;$col++)
  170. {
  171. $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
  172. if($strs[$col] instanceof PHPExcel_RichText){ //富文本转换字符串
  173. $strs[$col] = $strs[$col]->__toString();
  174. }
  175. //第七个数字是日期型的
  176. // if($col==7){
  177. // $strs[$col]=gmdate("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($strs[$col]));
  178. // }
  179. }
  180. array_push($excel_array, $strs);
  181. }
  182. }
  183. else
  184. {
  185. $excel_array['error'] = "导入失败!";
  186. }
  187. return $excel_array;
  188. }
  189. //end
  190. }
  191. ?>