Sms_customer_list_adminAction.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  39. $all_total = $admin->selectSmsCustomerCount($where);
  40. $p = new Page($all_total,$pageSize,$pa);
  41. $pp = $p->fpage();
  42. $this->assign('tel',$tel);
  43. $this->assign('list',$customer_list);
  44. $this->assign('group_list',$group_list);
  45. $this->assign('group_name',$group_name);
  46. $this->assign('info',$info);
  47. $this->assign('page',$page);
  48. $this->assign('pagesize',$pageSize);
  49. $this->assign("show",$pp);
  50. $this->display("index.html");
  51. }
  52. //添加客户
  53. public function add(){
  54. $admin = new AdvertAdminAction();
  55. $uid = $_SESSION['user_infos']['id'];
  56. $where = "where uid='$uid' ";
  57. $group_list = $admin->select_sms_user_group($where);
  58. if($_POST['tel']){
  59. $data['uname'] = $_POST['username'];
  60. $data['tel'] = $_POST['tel'];
  61. $data['group_name'] = $_POST['group_name'];
  62. $data['country'] = $_POST['country'];
  63. $data['uid'] = $uid;
  64. $is_exist = $admin->selectCustomerByTel($data['tel'], $data['uid']);
  65. if(empty($is_exist)){
  66. $add = $admin->add_sms_customer($data);
  67. if($add){
  68. $info = "添加手机号成功";
  69. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  70. exit();
  71. }else{
  72. $info = "添加手机号失败";
  73. $this->assign('info',$info);
  74. }
  75. }else{
  76. $info = "您之前已经添加过此用户";
  77. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  78. exit();
  79. }
  80. }
  81. $this->assign('group_list',$group_list);
  82. $this->display('add.html');
  83. }
  84. //编辑客户
  85. public function edit(){
  86. $admin = new AdvertAdminAction();
  87. $uid = $_SESSION['user_infos']['id'];
  88. $where = "where uid='$uid' ";
  89. $group_list = $admin->select_sms_user_group($where);
  90. $id = $_REQUEST['id'];
  91. $one_info = $admin->selectOneSmsCustomer($id);
  92. if($_POST['tel']){
  93. $id = $_POST['id'];
  94. $data['uname'] = $_POST['username'];
  95. $data['group_name'] = $_POST['group_name'];
  96. $data['country'] = $_POST['country'];
  97. $data['tel'] = $_POST['tel'];
  98. $update = $admin->updateSmsCustomer($data,$id);
  99. if($update){
  100. $info = "编辑客户资料成功";
  101. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  102. exit();
  103. }else{
  104. $info = "编辑客户资料失败";
  105. $this->assign('info',$info);
  106. }
  107. }
  108. $this->assign('id',$id);
  109. $this->assign('one_info',$one_info);
  110. $this->assign('group_list',$group_list);
  111. $this->display('edit.html');
  112. }
  113. //删除客户
  114. public function delete(){
  115. $admin = new AdvertAdminAction();
  116. $uid = $_SESSION['user_infos']['id'];
  117. $id = $_REQUEST['id'];
  118. if($_REQUEST['id']){
  119. $delete = $admin->deleteSmsCustomer($id,$uid);
  120. $info = "删除成功";
  121. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  122. exit();
  123. }
  124. }
  125. //批量删除客户
  126. public function batch_delete(){
  127. $admin = new AdvertAdminAction();
  128. $uid = $_SESSION['user_infos']['id'];
  129. $id_array = $_POST['id_array'];
  130. $count = count($id_array);
  131. if($count==1){
  132. $id = $id_array[0];
  133. $delete = $admin->deleteSmsCustomer($id,$uid);
  134. $info = "删除成功";
  135. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  136. exit();
  137. }else if($count>1){
  138. $in_array = implode(',',$id_array);
  139. $delete = $admin->deleteBatchSmsCustomer($in_array,$uid);
  140. $info = "删除成功";
  141. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  142. exit();
  143. }
  144. }
  145. public function import(){
  146. $admin = new AdvertAdminAction();
  147. $uid = $_SESSION['user_infos']['id'];
  148. if($_POST['to_import_user']=='yes'){
  149. $filename = $_FILES['inputExcel']['name'];
  150. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  151. $excel_array = $this->uploadFile($filename,$tmp_name);
  152. if(!empty($excel_array['error'])){
  153. $info = $excel_array['error'];
  154. }else{
  155. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  156. header("Content-type: text/html; charset=utf-8");
  157. $values = '';
  158. foreach($excel_array as $array){
  159. if(!empty($array[2])){
  160. $uname = str_replace("'", '', $array[0]);;
  161. $country = trim($array[1]);
  162. $tel = trim($array[2]);
  163. $groupName = trim($array[3]);
  164. $values .= "('{$uname}', '{$country}', '{$tel}', {$uid}, '{$groupName}')";
  165. }
  166. }
  167. if($values) {
  168. $insert = $admin->import_sms_customer($values);
  169. $info = '导入数据成功';
  170. }
  171. }
  172. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  173. exit();
  174. }
  175. }
  176. //导入Excel文件
  177. function uploadFile($file,$filetempname)
  178. {
  179. //自己设置的上传文件存放路径
  180. $filePath = 'static/upload/';
  181. $str = "";
  182. //下面的路径按照你PHPExcel的路径来修改
  183. require_once ONU_ROOT . 'phpexcel/PHPExcel.php';
  184. require_once ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php';
  185. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel5.php';
  186. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel2007.php';
  187. //require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/CSV.php';
  188. //注意设置时区
  189. $time=date("y-m-d-H-i-s");//去当前上传的时间
  190. //获取上传文件的扩展名
  191. $extend=strrchr ($file,'.');
  192. //上传后的文件名
  193. $name=$time.$extend;
  194. $uploadfile=$filePath.$name;//上传后的文件名地址
  195. //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
  196. $result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
  197. //echo $result;
  198. if($result) { //如果上传文件成功,就执行导入excel操作
  199. $objReader = new PHPExcel_Reader_Excel2007();//use excel2007 for 2007 format
  200. $objPHPExcel = $objReader->load($uploadfile);
  201. $sheet = $objPHPExcel->getSheet(0);
  202. $highestRow = $sheet->getHighestRow(); //取得总行数
  203. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  204. /* 第二种方法*/
  205. $objWorksheet = $objPHPExcel->getActiveSheet();
  206. $highestRow = $objWorksheet->getHighestRow();
  207. echo 'highestRow='.$highestRow;
  208. echo "<br>";
  209. $highestColumn = $objWorksheet->getHighestColumn();
  210. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
  211. echo 'highestColumnIndex='.$highestColumnIndex;
  212. echo "<br>";
  213. $headtitle=array();
  214. //获取到的excel数据
  215. $excel_array = array();
  216. for ($row = 1;$row <= $highestRow;$row++)
  217. {
  218. $strs=array();
  219. //注意highestColumnIndex的列数索引从0开始
  220. for ($col = 0;$col < $highestColumnIndex;$col++)
  221. {
  222. $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
  223. if($strs[$col] instanceof PHPExcel_RichText){ //富文本转换字符串
  224. $strs[$col] = $strs[$col]->__toString();
  225. }
  226. }
  227. array_push($excel_array, $strs);
  228. }
  229. } else {
  230. $excel_array['error'] = "导入失败!";
  231. }
  232. return $excel_array;
  233. }
  234. }