Sms_customer_list_adminAction.class.php 12 KB

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