Sms_customer_list_adminAction.class.php 10 KB

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