| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | 
							- <?php 
 
- /**
 
-  * 导入客户信息,导出客户信息
 
-  */
 
- require_once( ONU_ROOT . 'application/module/ctrl/Action.class.php');
 
- require_once ( ONU_ROOT . 'application/lib/data/adminAction.php');
 
- class Delete_list_adminAction extends Action{
 
- 	
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		if(empty($_SESSION['mds_user'])){
 
- 			header("Location:/?a=index&m=admin_login");
 
- 			exit();
 
- 		}
 
- //		$this->checkAdministratorRight('1');
 
- 	}
 
- 	//客户列表
 
- 	public function index(){
 
- 		require_once (ONU_ROOT . "frame/Page.class.php");
 
- 		$admin = new AdvertAdminAction();
 
- 		$uid   = $_SESSION['user_infos']['id'];
 
- 		$where = " where uid='$uid' ";
 
- 		$group_list = $admin->select_user_group($where);
 
- 		$this->assign('group_list',$group_list);
 
- 		$this->display("index.html");
 
- 	}
 
- 	//批量删除客户
 
- 	public function batch_delete(){
 
- 		$admin = new AdvertAdminAction();
 
- 		$uid   = $_SESSION['user_infos']['id'];
 
- 		$id_array = $_POST['id_array'];
 
- 		$count    = count($id_array);
 
- 		if($count==1){
 
- 			$id = $id_array[0];
 
- 			$delete = $admin->deleteCustomer($id,$uid);
 
- 			$info = "删除成功";
 
- 			header("Location:/?a=customer_list_admin&m=index&info=$info");
 
- 			exit();
 
- 		}else if($count>1){
 
- 			$in_array = implode(',',$id_array);
 
- 			$delete = $admin->deleteBatchCustomer($in_array,$uid);
 
- 			$info = "删除成功";
 
- 			header("Location:/?a=customer_list_admin&m=index&info=$info");
 
- 			exit();
 
- 		}
 
- 	}
 
- 	public function deleteByGroup() {
 
- 		$admin = new AdvertAdminAction();
 
- 		$uid   = $_SESSION['user_infos']['id'];
 
- 		$groupName = $_POST['group_name'];
 
- 		
 
- 		if($groupName) {
 
- 			$delete_c = $admin->deleteCustomerByGroup($groupName, $uid);
 
- 			$info = '删除 ' . $groupName . ' 客户分组成功';
 
- 		} else {
 
- 			$error = "删除失败";
 
- 		}
 
- 		header("Location:/?a=customer_list_admin&m=index&info=$info&error=$error");
 
- 		exit();
 
- 	}
 
- 	//导入excel
 
- 	public function importDelete(){
 
- 		$admin = new AdvertAdminAction();
 
- 		$uid   = $_SESSION['user_infos']['id'];
 
- 		if($_POST['to_import_user']=='yes'){
 
- 			$filename = $_FILES['inputExcel']['name'];
 
- 			$tmp_name = $_FILES['inputExcel']['tmp_name'];
 
- 			$excel_array = $this->uploadFile($filename,$tmp_name);
 
- 			if(!empty($excel_array['error'])){
 
- 				//导入失败
 
- 				$info = $excel_array['error'];
 
- 			}else{
 
- 				unset($excel_array[0]);//若第一排的数据是字段名的话,删除
 
- 				header("Content-type: text/html; charset=utf-8");
 
- 				$list=array_column($excel_array,0);
 
- 				$data="";
 
- 				for ($i=0; $i <= count($list); $i++) { 
 
- 					if(filter_var($list[$i],FILTER_VALIDATE_EMAIL)){
 
- 						$data.='"'.$list[$i].'",';
 
- 					}
 
- 					if($i&&($i%30==0||$i==count($list))){
 
- 						$delete = $admin->deleteBatchCustomerByEmail(trim($data,','),$uid);
 
- 						$data="";
 
- 					}
 
- 					$info="成功";
 
- 				}
 
- 			
 
- 			header("Location:/?a=customer_list_admin&m=index&info=$info");
 
- 			exit();
 
- 		}
 
- 	}
 
- 	}
 
- 	//导入Excel文件
 
- 	function uploadFile($file,$filetempname)
 
- 	{
 
- 		//自己设置的上传文件存放路径
 
- 		$filePath = 'static/upload/';
 
- 		$str = "";
 
- 		//下面的路径按照你PHPExcel的路径来修改
 
- 		require_once ONU_ROOT . 'phpexcel/PHPExcel.php';
 
- 		require_once ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php';
 
- 		require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel5.php';
 
- 		//require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/CSV.php';
 
- 		//注意设置时区
 
- 		$time=date("y-m-d-H-i-s");//去当前上传的时间
 
- 		//获取上传文件的扩展名
 
- 		$extend=strrchr ($file,'.');
 
- 		//上传后的文件名
 
- 		$name=$time.$extend;
 
- 		$uploadfile=$filePath.$name;//上传后的文件名地址
 
- 		//move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
 
- 		$result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
 
- 		//echo $result;
 
- 		if($result) //如果上传文件成功,就执行导入excel操作
 
- 		{
 
- 			$objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
 
- 			$objPHPExcel = $objReader->load($uploadfile);
 
- 			$sheet = $objPHPExcel->getSheet(0);
 
- 			$highestRow = $sheet->getHighestRow();           //取得总行数
 
- 			$highestColumn = $sheet->getHighestColumn(); //取得总列数
 
- 			/* 第二种方法*/
 
- 			$objWorksheet = $objPHPExcel->getActiveSheet();
 
- 			$highestRow = $objWorksheet->getHighestRow();
 
- 			echo 'highestRow='.$highestRow;
 
- 			echo "<br>";
 
- 			$highestColumn = $objWorksheet->getHighestColumn();
 
- 			$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
 
- 			echo 'highestColumnIndex='.$highestColumnIndex;
 
- 			echo "<br>";
 
- 			$headtitle=array();
 
- 			//获取到的excel数据
 
- 			$excel_array = array();
 
- 			for ($row = 1;$row <= $highestRow;$row++)
 
- 			{
 
- 				$strs=array();
 
- 				//注意highestColumnIndex的列数索引从0开始
 
- 				for ($col = 0;$col < $highestColumnIndex;$col++)
 
- 				{
 
- 					$strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
 
- 					if($strs[$col] instanceof PHPExcel_RichText){     //富文本转换字符串
 
- 						$strs[$col] = $strs[$col]->__toString();
 
- 					}
 
- 					//第七个数字是日期型的
 
- //					if($col==7){
 
- //						$strs[$col]=gmdate("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($strs[$col]));
 
- //					}
 
- 				}
 
- 				array_push($excel_array, $strs);
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			$excel_array['error'] = "导入失败!";
 
- 		}
 
- 		return $excel_array;
 
- 	}
 
- 	// class   end
 
- }
 
- ?>
 
 
  |