Sms_customer_list_adminAction.class.php 12 KB

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