Sms_customer_list_adminAction.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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 Sms_customer_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. }
  15. //客户列表
  16. public function index(){
  17. require_once (ONU_ROOT . "frame/Page.class.php");
  18. $admin = new AdvertAdminAction();
  19. $uid = $_SESSION['user_infos']['id'];
  20. $info = $_REQUEST['info'];
  21. $page = $_REQUEST['page']?$_REQUEST['page']:1;
  22. $pageSize = isset($_REQUEST['pagesize'])?$_REQUEST['pagesize']:20;
  23. $n = ($page-1)*$pageSize;
  24. $pa = "";//查询参数
  25. $pa='&pagesize='.$pageSize;
  26. $limit = " $n,$pageSize";
  27. $where = " where uid='$uid' ";
  28. $group_list = $admin->select_sms_user_group($where);
  29. $tel = trim($_REQUEST['tel']);
  30. $group_name = $_REQUEST['group_name'];
  31. if(!empty($tel)) {
  32. $where.=" and tel='$tel'";
  33. }
  34. if(!empty($group_name)){
  35. $where.=" and group_name='$group_name'";
  36. $pa .= "&group_name=$group_name";
  37. }
  38. $where.=" and is_block=0";
  39. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  40. $all_total = $admin->selectSmsCustomerCount($where);
  41. $p = new Page($all_total,$pageSize,$pa);
  42. $pp = $p->fpage();
  43. $this->assign('tel',$tel);
  44. $this->assign('list',$customer_list);
  45. $this->assign('group_list',$group_list);
  46. $this->assign('group_name',$group_name);
  47. $this->assign('info',$info);
  48. $this->assign('page',$page);
  49. $this->assign('pagesize',$pageSize);
  50. $this->assign("show",$pp);
  51. $this->display("index.html");
  52. }
  53. public function blackList(){
  54. require_once (ONU_ROOT . "frame/Page.class.php");
  55. $admin = new AdvertAdminAction();
  56. $info = $_REQUEST['info'];
  57. $page = $_REQUEST['page']?$_REQUEST['page']:1;
  58. $pageSize = isset($_REQUEST['pagesize'])?$_REQUEST['pagesize']:20;
  59. $n = ($page-1)*$pageSize;
  60. $pa = "";//查询参数
  61. $pa='&pagesize='.$pageSize;
  62. $limit = " $n,$pageSize";
  63. $where = " where 1=1 ";
  64. $tel = trim($_REQUEST['tel']);
  65. if(!empty($tel)) {
  66. $where.=" and tel='$tel'";
  67. }
  68. $where.=" and is_block=1";
  69. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  70. $all_total = $admin->selectSmsCustomerCount($where);
  71. $p = new Page($all_total,$pageSize,$pa);
  72. $pp = $p->fpage();
  73. $this->assign('tel',$tel);
  74. $this->assign('list',$customer_list);
  75. $this->assign('info',$info);
  76. $this->assign('page',$page);
  77. $this->assign('pagesize',$pageSize);
  78. $this->assign("show",$pp);
  79. $this->display("blacklist.html");
  80. }
  81. public function nosendList(){
  82. require_once (ONU_ROOT . "frame/Page.class.php");
  83. $admin = new AdvertAdminAction();
  84. $info = $_REQUEST['info'];
  85. $page = $_REQUEST['page']?$_REQUEST['page']:1;
  86. $pageSize = isset($_REQUEST['pagesize'])?$_REQUEST['pagesize']:20;
  87. $n = ($page-1)*$pageSize;
  88. $pa = "";//查询参数
  89. $pa='&pagesize='.$pageSize;
  90. $limit = " $n,$pageSize";
  91. $where = " where 1=1 ";
  92. $tel = trim($_REQUEST['tel']);
  93. if(!empty($tel)) {
  94. $where.=" and tel='$tel'";
  95. }
  96. $where.=" and is_send=2";
  97. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  98. $all_total = $admin->selectSmsCustomerCount($where);
  99. $p = new Page($all_total,$pageSize,$pa);
  100. $pp = $p->fpage();
  101. $this->assign('tel',$tel);
  102. $this->assign('list',$customer_list);
  103. $this->assign('info',$info);
  104. $this->assign('page',$page);
  105. $this->assign('pagesize',$pageSize);
  106. $this->assign("show",$pp);
  107. $this->display("nosendList.html");
  108. }
  109. public function remove(){
  110. $admin = new AdvertAdminAction();
  111. $uid = $_SESSION['user_infos']['id'];
  112. $info = $_REQUEST['info'];
  113. $where = " where uid='$uid' ";
  114. $group_list = $admin->select_sms_user_group($where);
  115. $this->assign('group_list',$group_list);
  116. $this->assign('info',$info);
  117. $this->display("remove.html");
  118. }
  119. //添加客户
  120. public function add(){
  121. $admin = new AdvertAdminAction();
  122. $uid = $_SESSION['user_infos']['id'];
  123. $where = "where uid='$uid' ";
  124. $group_list = $admin->select_sms_user_group($where);
  125. if($_POST['tel']){
  126. $data['uname'] = $_POST['username'];
  127. $data['tel'] = trim($_POST['tel']);
  128. $data['group_name'] = trim($_POST['group_name']);
  129. $data['country'] = trim($_POST['country']);
  130. $data['uid'] = $uid;
  131. $is_exist = $admin->selectCustomerByTel($data['tel'], $data['uid']);
  132. if(empty($is_exist)){
  133. $add = $admin->add_sms_customer($data);
  134. if($add){
  135. $info = "添加手机号成功";
  136. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  137. exit();
  138. }else{
  139. $info = "添加手机号失败";
  140. $this->assign('info',$info);
  141. }
  142. }else{
  143. $info = "您之前已经添加过此用户";
  144. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  145. exit();
  146. }
  147. }
  148. $this->assign('group_list',$group_list);
  149. $this->display('add.html');
  150. }
  151. //添加黑名单
  152. public function addBlack(){
  153. $admin = new AdvertAdminAction();
  154. if($_POST['tel']){
  155. $info = '添加失败';
  156. $uname = trim($_POST['username']);
  157. $tel = trim($_POST['tel']);
  158. $country = trim($_POST['country']);
  159. $group_name ='黑名单';
  160. $user = $admin->selectOneCustomerBymobile($tel);//查询手机号是否存在
  161. if($user){
  162. $add =$admin->updateSmsCustomerBlcak($user);
  163. }else{
  164. $uid =99;
  165. $values = "('{$uname}', '{$country}', '{$tel}', {$uid}, '{$group_name}', 1, 2)";
  166. $add =$admin->import_sms_customer($values);
  167. }
  168. if($add){
  169. $info = "添加成功";
  170. header("Location:/?a=sms_customer_list_admin&m=blacklist&info=$info");
  171. exit();
  172. }else{
  173. $this->assign('info',$info);
  174. }
  175. }
  176. $this->display('addBlack.html');
  177. }
  178. //编辑客户
  179. public function edit(){
  180. $admin = new AdvertAdminAction();
  181. $uid = $_SESSION['user_infos']['id'];
  182. $where = "where uid='$uid' ";
  183. $group_list = $admin->select_sms_user_group($where);
  184. $id = $_REQUEST['id'];
  185. $one_info = $admin->selectOneSmsCustomer($id);
  186. if($_POST['tel']){
  187. $id = $_POST['id'];
  188. $data['uname'] = $_POST['username'];
  189. $data['group_name'] = trim($_POST['group_name']);
  190. $data['country'] = trim($_POST['country']);
  191. $data['tel'] = trim($_POST['tel']);
  192. $update = $admin->updateSmsCustomer($data,$id);
  193. if($update){
  194. $info = "编辑客户资料成功";
  195. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  196. exit();
  197. }else{
  198. $info = "编辑客户资料失败";
  199. $this->assign('info',$info);
  200. }
  201. }
  202. $this->assign('id',$id);
  203. $this->assign('one_info',$one_info);
  204. $this->assign('group_list',$group_list);
  205. $this->display('edit.html');
  206. }
  207. //编辑黑名单客户
  208. public function editBlack(){
  209. $admin = new AdvertAdminAction();
  210. $id = $_REQUEST['id'];
  211. $one_info = $admin->selectOneSmsCustomer($id);
  212. if($_POST['tel']){
  213. $id = $_POST['id'];
  214. $data['uname'] = $_POST['username'];
  215. $data['group_name'] = trim($_POST['group_name']);
  216. $data['country'] = trim($_POST['country']);
  217. $data['tel'] = trim($_POST['tel']);
  218. $update = $admin->updateSmsCustomer($data,$id);
  219. if($update){
  220. $info = "编辑客户资料成功";
  221. header("Location:/?a=sms_customer_list_admin&m=blackList&info=$info");
  222. exit();
  223. }else{
  224. $info = "编辑客户资料失败";
  225. $this->assign('info',$info);
  226. }
  227. }
  228. $this->assign('id',$id);
  229. $this->assign('one_info',$one_info);
  230. $this->display('editBlack.html');
  231. }
  232. //删除客户
  233. public function delete(){
  234. $admin = new AdvertAdminAction();
  235. $uid = empty($_REQUEST['isblack']) ? $_SESSION['user_infos']['id'] : 99;
  236. $id = $_REQUEST['id'];
  237. if($_REQUEST['id']){
  238. $delete = $admin->deleteSmsCustomer($id,$uid);
  239. $info = "删除成功";
  240. header("Location:/?a=sms_customer_list_admin&m=blackList&info=$info");
  241. exit();
  242. }
  243. }
  244. //批量删除客户
  245. public function batch_delete(){
  246. $admin = new AdvertAdminAction();
  247. $uid = !empty($_POST['black']) ? 99 : $_SESSION['user_infos']['id'];
  248. $id_array = $_POST['id_array'];
  249. $count = count($id_array);
  250. if($count==1){
  251. $id = $id_array[0];
  252. $delete = $admin->deleteSmsCustomer($id,$uid);
  253. $info = "删除成功";
  254. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  255. exit();
  256. }else if($count>1){
  257. $in_array = implode(',',$id_array);
  258. $delete = $admin->deleteBatchSmsCustomer($in_array,$uid);
  259. $info = "删除成功";
  260. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  261. exit();
  262. }
  263. }
  264. public function import(){
  265. $admin = new AdvertAdminAction();
  266. $city_code =$admin->selectCityCode();
  267. $new=array();
  268. foreach ($city_code as $v){
  269. $new[]=$v['code'];
  270. }
  271. $is_send=1;
  272. $uid = $_SESSION['user_infos']['id'];
  273. if($_POST['to_import_user']=='yes'){
  274. $filename = $_FILES['inputExcel']['name'];
  275. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  276. $excel_array = $this->uploadFile($filename,$tmp_name);
  277. if(!empty($excel_array['error'])){
  278. $info = $excel_array['error'];
  279. }else{
  280. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  281. header("Content-type: text/html; charset=utf-8");
  282. $blackList = $admin->selectSmsBlackList();
  283. $blackListArr = array_column($blackList, 'tel');
  284. $values = '';
  285. foreach($excel_array as $array){
  286. if(!empty($array[2])){
  287. $uname = preg_replace("/[^a-zA-Z\s]+/", "", $array[0]);
  288. $tel = trim($array[1]);
  289. $country = trim($array[2]);
  290. $groupName = trim($array[3]);
  291. if(in_array($tel, $blackListArr)) {
  292. continue;
  293. }
  294. if($country=='United States'||$country=='Canada'){
  295. $tel=$this->checkMobileCode($tel);
  296. $is_send =$this->getSend($tel,$new);
  297. }
  298. $values .= "('{$uname}', '{$country}', '{$tel}', {$uid}, '{$groupName}', 0, '{$is_send}'),";
  299. }
  300. }
  301. if($values) {
  302. $values = trim($values, ",");
  303. $insert = $admin->import_sms_customer($values);
  304. if ($insert == false) {
  305. $info = '导入数据失败';
  306. } else {
  307. $info = '导入数据成功';
  308. }
  309. }
  310. }
  311. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  312. exit();
  313. }
  314. }
  315. public function checkMobileCode($mobile){
  316. $mobile= str_replace('-', '', $mobile);
  317. $mobile= str_replace('_', '', $mobile);
  318. $mobile= str_replace('(', '', $mobile);
  319. $mobile= str_replace(')', '', $mobile);
  320. $mobile= str_replace('+', '', $mobile);
  321. $mobile= str_replace(' ', '', $mobile);
  322. $mobile=trim($mobile);
  323. $frist =(int)substr($mobile, 0, 1 );
  324. $lenth=strlen($mobile);
  325. if($lenth==11&&$frist==1){//例:14696305087
  326. $mobile =substr($mobile , 2 , 10);
  327. }
  328. return $mobile;
  329. }
  330. public function getSend($mobile,$new)
  331. {
  332. $lenth=strlen($mobile);
  333. $code =0;
  334. if($lenth==10){
  335. $code = substr($mobile , 0 , 3);
  336. }
  337. $is_send=2;
  338. if($code){
  339. if (in_array($code, $new)) {
  340. $is_send=1;
  341. }
  342. }
  343. return $is_send;
  344. }
  345. public function importBlackList(){
  346. $admin = new AdvertAdminAction();
  347. $uid = $_SESSION['user_infos']['id'];
  348. if($_POST['to_import_user']=='yes'){
  349. $filename = $_FILES['inputExcel']['name'];
  350. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  351. $excel_array = $this->uploadFile($filename,$tmp_name);
  352. if(!empty($excel_array['error'])){
  353. $info = $excel_array['error'];
  354. }else{
  355. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  356. header("Content-type: text/html; charset=utf-8");
  357. $blackList = $admin->selectSmsBlackList($uid);
  358. $blackListArr = array_column($blackList, 'tel');
  359. $values = '';
  360. foreach($excel_array as $array){
  361. if(!empty($array[1])){
  362. $uname = preg_replace("/[^a-zA-Z\s]+/", "", $array[0]);
  363. $tel = trim($array[1]);
  364. $country = trim($array[2]);
  365. $groupName = trim($array[3]);
  366. if(in_array($tel, $blackListArr)) {
  367. continue;
  368. }
  369. $telsArr[] = $tel;
  370. $values .= "('{$uname}', '{$country}', '{$tel}', 99, '{$groupName}', 1, 2),";
  371. }
  372. }
  373. if($telsArr) {
  374. $telsStr = "'" . implode("','", $telsArr) . "'";
  375. $result = $admin->deleteSmsCustomerByTel($telsStr);
  376. $values = trim($values, ",");
  377. $insert = $admin->import_sms_customer($values);
  378. if ($insert == false) {
  379. $info = '导入数据失败';
  380. } else {
  381. $info = '导入数据成功';
  382. }
  383. }
  384. }
  385. header("Location:/?a=sms_customer_list_admin&m=blacklist&info=$info");
  386. exit();
  387. }
  388. }
  389. public function deleteByExcel(){
  390. $admin = new AdvertAdminAction();
  391. $uid = $_SESSION['user_infos']['id'];
  392. if($_POST['to_import_user']=='yes'){
  393. $filename = $_FILES['inputExcel']['name'];
  394. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  395. $excel_array = $this->uploadFile($filename,$tmp_name);
  396. if(!empty($excel_array['error'])){
  397. $info = $excel_array['error'];
  398. }else{
  399. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  400. header("Content-type: text/html; charset=utf-8");
  401. $telsArr = array();
  402. foreach($excel_array as $array){
  403. if(!empty($array[0])){
  404. $tel = trim($array[0]);
  405. $telsArr[] = $tel;
  406. }
  407. }
  408. if($telsArr) {
  409. $telsStr = "'" . implode("','", $telsArr) . "'";
  410. $result = $admin->deleteSmsCustomerByTel($telsStr);
  411. $info = '删除数据成功';
  412. }
  413. }
  414. header("Location:/?a=sms_customer_list_admin&m=remove&info=$info");
  415. exit();
  416. }
  417. }
  418. public function deleteByGroup() {
  419. $admin = new AdvertAdminAction();
  420. $uid = $_SESSION['user_infos']['id'];
  421. $groupName = $_POST['group_name'];
  422. if($groupName) {
  423. $delete_c = $admin->deleteSmsCustomerByGroup($groupName, $uid);
  424. $info = '删除 ' . $groupName . ' 客户分组成功';
  425. } else {
  426. $error = "删除失败";
  427. }
  428. header("Location:/?a=sms_customer_list_admin&m=remove&info=$info&error=$error");
  429. exit();
  430. }
  431. public function export(){
  432. $admin = new AdvertAdminAction();
  433. $uid = $_SESSION['user_infos']['id'];
  434. $group_name = $_REQUEST['group_name'];
  435. $where = " where uid='$uid' ";
  436. if(!empty($group_name)){
  437. $where.=" and group_name='$group_name'";
  438. }
  439. $where.=" and is_block=0";
  440. $list = $admin->selesctSmsCustomer($where);
  441. $d = date('Y-m-d',time());
  442. $this->generateEXCEL($d."导出客户数据",$list);
  443. }
  444. function generateEXCEL($filename = 'report',$data = ''){
  445. //引入PHPExcel相关文件
  446. require_once( ONU_ROOT . 'phpexcel/PHPExcel.php');
  447. require_once( ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php');
  448. require_once( ONU_ROOT . 'phpexcel/PHPExcel/Writer/Excel5.php');
  449. //新建
  450. $resultPHPExcel = new PHPExcel();
  451. //设置参数
  452. //设值
  453. $resultPHPExcel->getActiveSheet()->setCellValue('A1', 'Name');
  454. $resultPHPExcel->getActiveSheet()->setCellValue('B1', 'Tel');
  455. $resultPHPExcel->getActiveSheet()->setCellValue('C1', 'Country');
  456. $resultPHPExcel->getActiveSheet()->setCellValue('D1', 'Group');
  457. //设置水平居中
  458. $resultPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  459. $resultPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  460. $resultPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  461. $resultPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  462. //设置水平居中
  463. $resultPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  464. $resultPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  465. $resultPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  466. $resultPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  467. $i = 2;
  468. foreach($data as $item){
  469. $resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $item['uname']);
  470. $resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $item['tel']);
  471. $resultPHPExcel->getActiveSheet()->setCellValue('C' . $i, $item['country']);
  472. $resultPHPExcel->getActiveSheet()->setCellValue('D' . $i, $item['group_name']);
  473. //设置单元格宽度
  474. $resultPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(40);
  475. $resultPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  476. $resultPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  477. $resultPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  478. //设置水平居中
  479. $resultPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  480. $resultPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  481. $resultPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  482. $resultPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  483. //设置行高度
  484. $resultPHPExcel->getActiveSheet()->getRowDimension("1")->setRowHeight(20);
  485. $resultPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(20);
  486. $i ++;
  487. }
  488. //设置导出文件名
  489. $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel);
  490. ob_end_clean();//清除缓冲区,避免乱码
  491. //ob_start(); ob_flush();
  492. header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
  493. header("Content-Type: application/force-download");
  494. header("Content-Type: application/octet-stream");
  495. header("Content-Type: application/download");
  496. //header('Content-Disposition:inline;filename="'.$outputFileName.'"');
  497. header('Content-Disposition:attachment;filename='.'"'.$filename.'.xls"'); //可以对文件名进行处理
  498. header("Content-Transfer-Encoding: binary");
  499. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  500. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  501. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  502. header("Pragma: no-cache");
  503. $xlsWriter->save('php://output');
  504. exit;
  505. }
  506. //导入Excel文件
  507. function uploadFile($file,$filetempname)
  508. {
  509. //自己设置的上传文件存放路径
  510. $filePath = 'static/upload/';
  511. $str = "";
  512. //下面的路径按照你PHPExcel的路径来修改
  513. require_once ONU_ROOT . 'phpexcel/PHPExcel.php';
  514. require_once ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php';
  515. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel5.php';
  516. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel2007.php';
  517. //require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/CSV.php';
  518. //注意设置时区
  519. $time=date("y-m-d-H-i-s");//去当前上传的时间
  520. //获取上传文件的扩展名
  521. $extend=strrchr ($file,'.');
  522. //上传后的文件名
  523. $name=$time.$extend;
  524. $uploadfile=$filePath.$name;//上传后的文件名地址
  525. //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
  526. $result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
  527. //echo $result;
  528. if($result) { //如果上传文件成功,就执行导入excel操作
  529. $objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
  530. $objPHPExcel = $objReader->load($uploadfile);
  531. $sheet = $objPHPExcel->getSheet(0);
  532. $highestRow = $sheet->getHighestRow(); //取得总行数
  533. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  534. /* 第二种方法*/
  535. $objWorksheet = $objPHPExcel->getActiveSheet();
  536. $highestRow = $objWorksheet->getHighestRow();
  537. echo 'highestRow='.$highestRow;
  538. echo "<br>";
  539. $highestColumn = $objWorksheet->getHighestColumn();
  540. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
  541. echo 'highestColumnIndex='.$highestColumnIndex;
  542. echo "<br>";
  543. $headtitle=array();
  544. //获取到的excel数据
  545. $excel_array = array();
  546. for ($row = 1;$row <= $highestRow;$row++)
  547. {
  548. $strs=array();
  549. //注意highestColumnIndex的列数索引从0开始
  550. for ($col = 0;$col < $highestColumnIndex;$col++)
  551. {
  552. $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
  553. if($strs[$col] instanceof PHPExcel_RichText){ //富文本转换字符串
  554. $strs[$col] = $strs[$col]->__toString();
  555. }
  556. }
  557. array_push($excel_array, $strs);
  558. }
  559. } else {
  560. $excel_array['error'] = "导入失败!";
  561. }
  562. return $excel_array;
  563. }
  564. public function exportBlackList(){
  565. $admin = new AdvertAdminAction();
  566. $list = $admin->getAllSmsBlacklist();
  567. $d = date('Y-m-d',time());
  568. $this->generateEXCEL($d . "导出短信黑名单客户数据", $list);
  569. }
  570. }