Sms_customer_list_adminAction.class.php 12 KB

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