Sms_customer_list_adminAction.class.php 7.8 KB

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