Sms_customer_list_adminAction.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. $uid = $_SESSION['user_infos']['id'];
  57. $info = $_REQUEST['info'];
  58. $page = $_REQUEST['page']?$_REQUEST['page']:1;
  59. $pageSize = isset($_REQUEST['pagesize'])?$_REQUEST['pagesize']:20;
  60. $n = ($page-1)*$pageSize;
  61. $pa = "";//查询参数
  62. $pa='&pagesize='.$pageSize;
  63. $limit = " $n,$pageSize";
  64. $where = " where uid='$uid' ";
  65. $tel = trim($_REQUEST['tel']);
  66. if(!empty($tel)) {
  67. $where.=" and tel='$tel'";
  68. }
  69. $where.=" and is_block=1";
  70. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  71. $all_total = $admin->selectSmsCustomerCount($where);
  72. $p = new Page($all_total,$pageSize,$pa);
  73. $pp = $p->fpage();
  74. $this->assign('tel',$tel);
  75. $this->assign('list',$customer_list);
  76. $this->assign('info',$info);
  77. $this->assign('page',$page);
  78. $this->assign('pagesize',$pageSize);
  79. $this->assign("show",$pp);
  80. $this->display("blacklist.html");
  81. }
  82. //添加客户
  83. public function add(){
  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. if($_POST['tel']){
  89. $data['uname'] = $_POST['username'];
  90. $data['tel'] = $_POST['tel'];
  91. $data['group_name'] = $_POST['group_name'];
  92. $data['country'] = $_POST['country'];
  93. $data['uid'] = $uid;
  94. $is_exist = $admin->selectCustomerByTel($data['tel'], $data['uid']);
  95. if(empty($is_exist)){
  96. $add = $admin->add_sms_customer($data);
  97. if($add){
  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. }else{
  106. $info = "您之前已经添加过此用户";
  107. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  108. exit();
  109. }
  110. }
  111. $this->assign('group_list',$group_list);
  112. $this->display('add.html');
  113. }
  114. //编辑客户
  115. public function edit(){
  116. $admin = new AdvertAdminAction();
  117. $uid = $_SESSION['user_infos']['id'];
  118. $where = "where uid='$uid' ";
  119. $group_list = $admin->select_sms_user_group($where);
  120. $id = $_REQUEST['id'];
  121. $one_info = $admin->selectOneSmsCustomer($id);
  122. if($_POST['tel']){
  123. $id = $_POST['id'];
  124. $data['uname'] = $_POST['username'];
  125. $data['group_name'] = $_POST['group_name'];
  126. $data['country'] = $_POST['country'];
  127. $data['tel'] = $_POST['tel'];
  128. $update = $admin->updateSmsCustomer($data,$id);
  129. if($update){
  130. $info = "编辑客户资料成功";
  131. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  132. exit();
  133. }else{
  134. $info = "编辑客户资料失败";
  135. $this->assign('info',$info);
  136. }
  137. }
  138. $this->assign('id',$id);
  139. $this->assign('one_info',$one_info);
  140. $this->assign('group_list',$group_list);
  141. $this->display('edit.html');
  142. }
  143. //删除客户
  144. public function delete(){
  145. $admin = new AdvertAdminAction();
  146. $uid = $_SESSION['user_infos']['id'];
  147. $id = $_REQUEST['id'];
  148. if($_REQUEST['id']){
  149. $delete = $admin->deleteSmsCustomer($id,$uid);
  150. $info = "删除成功";
  151. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  152. exit();
  153. }
  154. }
  155. //批量删除客户
  156. public function batch_delete(){
  157. $admin = new AdvertAdminAction();
  158. $uid = $_SESSION['user_infos']['id'];
  159. $id_array = $_POST['id_array'];
  160. $count = count($id_array);
  161. if($count==1){
  162. $id = $id_array[0];
  163. $delete = $admin->deleteSmsCustomer($id,$uid);
  164. $info = "删除成功";
  165. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  166. exit();
  167. }else if($count>1){
  168. $in_array = implode(',',$id_array);
  169. $delete = $admin->deleteBatchSmsCustomer($in_array,$uid);
  170. $info = "删除成功";
  171. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  172. exit();
  173. }
  174. }
  175. public function import(){
  176. $admin = new AdvertAdminAction();
  177. $uid = $_SESSION['user_infos']['id'];
  178. if($_POST['to_import_user']=='yes'){
  179. $filename = $_FILES['inputExcel']['name'];
  180. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  181. $excel_array = $this->uploadFile($filename,$tmp_name);
  182. if(!empty($excel_array['error'])){
  183. $info = $excel_array['error'];
  184. }else{
  185. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  186. header("Content-type: text/html; charset=utf-8");
  187. $values = '';
  188. foreach($excel_array as $array){
  189. if(!empty($array[2])){
  190. $uname = str_replace("'", '', $array[0]);;
  191. $country = trim($array[1]);
  192. $tel = trim($array[2]);
  193. $groupName = trim($array[3]);
  194. $values .= "('{$uname}', '{$country}', '{$tel}', {$uid}, '{$groupName}', 0),";
  195. }
  196. }
  197. if($values) {
  198. $values = trim($values, ",");
  199. $insert = $admin->import_sms_customer($values);
  200. $info = '导入数据成功';
  201. }
  202. }
  203. header("Location:/?a=sms_customer_list_admin&m=index&info=$info");
  204. exit();
  205. }
  206. }
  207. public function importBlackList(){
  208. $admin = new AdvertAdminAction();
  209. $uid = $_SESSION['user_infos']['id'];
  210. if($_POST['to_import_user']=='yes'){
  211. $filename = $_FILES['inputExcel']['name'];
  212. $tmp_name = $_FILES['inputExcel']['tmp_name'];
  213. $excel_array = $this->uploadFile($filename,$tmp_name);
  214. if(!empty($excel_array['error'])){
  215. $info = $excel_array['error'];
  216. }else{
  217. unset($excel_array[0]);//若第一排的数据是字段名的话,删除
  218. header("Content-type: text/html; charset=utf-8");
  219. $blackList = $admin->selectSmsBlackList($uid);
  220. $blackListArr = array_column($blackList, 'tel');
  221. $values = '';
  222. foreach($excel_array as $array){
  223. if(!empty($array[2])){
  224. $uname = str_replace("'", '', $array[0]);;
  225. $country = trim($array[1]);
  226. $tel = trim($array[2]);
  227. $groupName = trim($array[3]);
  228. if(in_array($tel, $blackList)) {
  229. continue;
  230. }
  231. $values .= "('{$uname}', '{$country}', '{$tel}', {$uid}, '{$groupName}', 1),";
  232. }
  233. }
  234. if($values) {
  235. $values = trim($values, ",");
  236. $insert = $admin->import_sms_customer($values);
  237. $info = '导入数据成功';
  238. }
  239. }
  240. header("Location:/?a=sms_customer_list_admin&m=blacklist&info=$info");
  241. exit();
  242. }
  243. }
  244. //导入Excel文件
  245. function uploadFile($file,$filetempname)
  246. {
  247. //自己设置的上传文件存放路径
  248. $filePath = 'static/upload/';
  249. $str = "";
  250. //下面的路径按照你PHPExcel的路径来修改
  251. require_once ONU_ROOT . 'phpexcel/PHPExcel.php';
  252. require_once ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php';
  253. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel5.php';
  254. require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/Excel2007.php';
  255. //require_once ONU_ROOT . 'phpexcel/PHPExcel/Reader/CSV.php';
  256. //注意设置时区
  257. $time=date("y-m-d-H-i-s");//去当前上传的时间
  258. //获取上传文件的扩展名
  259. $extend=strrchr ($file,'.');
  260. //上传后的文件名
  261. $name=$time.$extend;
  262. $uploadfile=$filePath.$name;//上传后的文件名地址
  263. //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
  264. $result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
  265. //echo $result;
  266. if($result) { //如果上传文件成功,就执行导入excel操作
  267. $objReader = new PHPExcel_Reader_Excel2007();//use excel2007 for 2007 format
  268. $objPHPExcel = $objReader->load($uploadfile);
  269. $sheet = $objPHPExcel->getSheet(0);
  270. $highestRow = $sheet->getHighestRow(); //取得总行数
  271. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  272. /* 第二种方法*/
  273. $objWorksheet = $objPHPExcel->getActiveSheet();
  274. $highestRow = $objWorksheet->getHighestRow();
  275. echo 'highestRow='.$highestRow;
  276. echo "<br>";
  277. $highestColumn = $objWorksheet->getHighestColumn();
  278. $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
  279. echo 'highestColumnIndex='.$highestColumnIndex;
  280. echo "<br>";
  281. $headtitle=array();
  282. //获取到的excel数据
  283. $excel_array = array();
  284. for ($row = 1;$row <= $highestRow;$row++)
  285. {
  286. $strs=array();
  287. //注意highestColumnIndex的列数索引从0开始
  288. for ($col = 0;$col < $highestColumnIndex;$col++)
  289. {
  290. $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
  291. if($strs[$col] instanceof PHPExcel_RichText){ //富文本转换字符串
  292. $strs[$col] = $strs[$col]->__toString();
  293. }
  294. }
  295. array_push($excel_array, $strs);
  296. }
  297. } else {
  298. $excel_array['error'] = "导入失败!";
  299. }
  300. return $excel_array;
  301. }
  302. }