select_smstm_list($where); //查询所有的用户分组 $where2 = "where uid='$uid' "; $group_list = $admin->select_sms_user_group($where2); /*if(!empty($_POST['group_name']) && $_POST['group_name']!='all'){ $where3.=" and group_name='{$_POST['group_name']}'"; } $customer_list = $admin->selesctCustomer($where3);*/ /*if(!empty($_POST['group_name']) && $_POST['group_name']!='all'){ $where3.=" and group_name='{$_POST['group_name']}'"; $customer_list = $admin->selesctCustomer($where3); }elseif(!empty($_POST['group_name']) && $_POST['group_name']=='all'){ $customer_list = $admin->selesctCustomer($where2); } $count = count($customer_list); //假设一次只能给100个人发,看需要发几次 $c = 100; $p = ceil($count/100);//需要发总次数*/ $where3 = "where uid='$uid' and is_block=0 and is_send=1 "; if (!empty($_POST['group_name'])) { if ($_POST['group_name'] != 'all') { $where3 .= " and group_name='{$_POST['group_name']}'"; $customer_list = $admin->selesctSmsCustomer($where3); } elseif ($_POST['group_name'] == 'all') { $customer_list = $admin->selesctSmsCustomer($where2); } $count = count($customer_list); $c = 100; $p = ceil($count/100); } $send_type=1; if ($_POST['template_id']) { $id = $_POST['template_id']; $one_info = $admin->select_onesms_template($id); $content = str_replace("'", '', $one_info['msg_content']); for($i=1;$i<=$p;$i++){ $min = $c*($i-1); $data = array(); $x_smtpapi=array(); $customer_list_now = array_slice($customer_list, $min, $c); foreach($customer_list_now as $key=>$list){ $countryMobile = $this->getCountryMobile($list['country']); if($countryMobile==1){ $data[$key]['from_name'] =$fromDm; }else{ $data[$key]['from_name'] =$from; } $data[$key]['mobile'] =$countryMobile.$list['tel']; $appkey='FH1W2L97'; $secretkey='OCio2JBh'; if($uid==7){//--牛信云 yolissahair $x_smtpapi[] = $countryMobile.$list['tel']; $from=18332604755; $appkey='fm6S6TTz'; $secretkey='PNQzoBIk'; } if($uid==5){//--牛信云 asteriahair $x_smtpapi[] = $countryMobile.$list['tel']; $from=18332359525; $appkey='ss9jHs2r'; $secretkey='XW7iy4uC'; } if($uid==1){//--牛信云 alipearlhair $x_smtpapi[] = $countryMobile.$list['tel']; $from=18444795753; $appkey='qQcsCT7e'; $secretkey='2Z9dyFyn'; } if($uid==6){//--牛信云 supernovahair $x_smtpapi[] = $countryMobile.$list['tel']; $from=18444796463; $appkey='4CdNKjBj'; $secretkey='lVd866Tx'; } if($uid==3){//--牛信云 westkisshair $x_smtpapi[] = $countryMobile.$list['tel']; $from=18444797525; $appkey='MMoVdvdC'; $secretkey='jlkPGrdi'; } if($uid==4){//--牛信云 wigginshair $x_smtpapi[] = $countryMobile.$list['tel']; $from=18337593782; $appkey='t9Qse0Rs'; $secretkey='xHw8EAIM'; } } $params = array( 'to' => $data, 'template_id' => $id, 'uid' => $uid, 'accessKeyId' => $accessKeyId, 'accessKeySecret' => $accessKeySecret, 'template_body' => $content ); if($uid==7||$uid==1||$uid==6||$uid==3||$uid==4||$uid==5){//--牛信云 $send_type=2; if($uid==5){ $params = array( 'appkey' => $appkey, 'secretkey' =>$secretkey, 'phone' => $x_smtpapi, 'content' => $content, // 'source_address' => $from, 'uid' => $uid ); }else{ $params = array( 'appkey' => $appkey, 'secretkey' =>$secretkey, 'phone' => $x_smtpapi, 'content' => $content, 'source_address' => $from, 'uid' => $uid ); } } $params_arr[] = $params; } if($send_type==1){ $apid=$accessKeyId; $apsecret=$accessKeySecret; }else{ $apid=$appkey; $apsecret=$secretkey; } $fid=0; if($count>0){ //$one_info['msg_content'],$_POST['group_name'] $fid=$admin->add_sms_data_logs($uid,$uname,$_POST['group_name'],$one_info['msg_title'],$count,$send_type,$showtime,$datetime,$apid,$apsecret); } if($uid==7||$uid==1||$uid==6||$uid==3||$uid==4||$uid==5){ $result = $admin->add_sms_data_queue_new($params_arr,$showtime,$datetime,$fid,$uid); }else{ $result = $admin->add_sms_data_queue($params_arr,$showtime,$datetime,$fid); } if ($result) { $info = '短信已进入待发送队列'; } else { $info = '短信发送失败'; } header("Location:/?a=send_sms_admin&m=index&info=$info"); exit(); } $email = $admin->selectSmsTmpData(); $this->assign('email_counts', $email[0]['ct']); $this->assign('group_list', $group_list); $this->assign('info', $info); $this->assign('template_list', $template_list); $this->display("index.html"); } function query(){ require_once (ONU_ROOT . "frame/Page.class.php"); $admin = new AdvertAdminAction(); $where = "where 1=1 "; $page = $_REQUEST['page']?$_REQUEST['page']:1; $pageSize = 10; $n = ($page-1)*$pageSize; $pa = "";//查询参数 $limit = " $n,$pageSize"; $info = $_REQUEST['info']; $error = $_REQUEST['error']; $uname = $_SESSION['user_infos']['uname']; $list = $admin->select_smslog_list($where,$limit); $all_total = $admin->select_smslog_count($where); $p = new Page($all_total,$pageSize,$pa); $pp = $p->fpage(); $send_array = array( '1' => '阿里', '2' => '牛信云', ); $status_array = array( '1' => '已发送', '2' => '未发送', '3' => '已取消', ); $new=array(); $times=time(); $where.=" and sendtime> $times and status is null "; $lists = $admin->select_smslog_list($where); $wnums=0; foreach ($lists as $ks=>$vs){ $wnums=$wnums+$vs['count']; } foreach ($list as $k=>$v){ $new[$k]=$v; $new[$k]['status']=1; $new[$k]['sendtime']=date('Y-m-d H:i:s',$v['sendtime']); if($v['sendtime']>time()){ $new[$k]['status']=2; } if($v['status']==1){ $new[$k]['status']=3; } } if ($_GET['id']) { $id=$_GET['id']; $wheres =" where b.fid={$id} " ; $totals = $admin->select_smslog_count_query($wheres); if($totals){ $result =$admin->delete_smslog($id,$totals); if ($result) { $info = '取消成功'; header("Location:/?a=send_sms_admin&m=query&info=$info"); } else { $error = '取消失败'; header("Location:/?a=send_sms_admin&m=query&error=$error"); } }else{ $error = '取消失败,没有待发送的短信'; header("Location:/?a=send_sms_admin&m=query&error=$error"); } exit(); } $this->assign('status_array',$status_array); $this->assign('send_array',$send_array); $this->assign('wnums',$wnums); $this->assign('info',$info); $this->assign('error',$error); $this->assign('page',$page); $this->assign("show",$pp); $this->assign('list',$new); $this->assign('uname',$uname); $this->display('query.html'); } function didquery(){ require_once (ONU_ROOT . "frame/Page.class.php"); $admin = new AdvertAdminAction(); $where = "where 1=1 "; $page = $_REQUEST['page']?$_REQUEST['page']:1; $pageSize = 10; $n = ($page-1)*$pageSize; $pa = "";//查询参数 $limit = " $n,$pageSize"; $info = $_REQUEST['info']; $error = $_REQUEST['error']; $uname = $_SESSION['user_infos']['uname']; $tel = trim($_REQUEST['tel']); if(!empty($tel)) { $where.=" and (mobile='$tel' or from_phone ='$tel' )"; } $starttime = trim($_REQUEST['starttime']); if(!empty($starttime)) { $starttimes=strtotime($starttime); $where.=" and UNIX_TIMESTAMP(receive_time) >'{$starttimes}'"; } $endtime = trim($_REQUEST['endtime']); if(!empty($endtime)) { $endtimes=strtotime($endtime); $where.=" and UNIX_TIMESTAMP(receive_time) <'{$endtimes}'"; } $list = $admin->select_smsdidlog_list($where,$limit); $all_total = $admin->select_smsdidlog_count($where); $p = new Page($all_total,$pageSize,$pa); $pp = $p->fpage(); $status_array = array( '1' => '正常', '2' => '禁用', ); foreach ($list as $k=>$v){ $new[$k]=$v; $new[$k]['uname']=$this->getName($admin,$v['uid']); } $this->assign('tel',$tel); $this->assign('starttime',$starttime); $this->assign('endtime',$endtime); $this->assign('status_array',$status_array); $this->assign('info',$info); $this->assign('error',$error); $this->assign('page',$page); $this->assign("show",$pp); $this->assign('list',$new); $this->assign('uname',$uname); $this->display('didquery.html'); } public function export(){ $admin = new AdvertAdminAction(); $where = "where 1=1 "; $starttime = trim($_REQUEST['starttime']); if(!empty($starttime)) { $starttimes=strtotime($starttime); $where.=" and UNIX_TIMESTAMP(receive_time) >'{$starttimes}'"; } $endtime = trim($_REQUEST['endtime']); if(!empty($endtime)) { $endtimes=strtotime($endtime); $where.=" and UNIX_TIMESTAMP(receive_time) <'{$endtimes}'"; } $list = $admin->select_smsdidlog_list($where); $new=array(); foreach ($list as $k=>$v){ $new[$k]=$v; $new[$k]['uname']=$this->getName($admin,$v['uid']); } $d = date('Y-m-d',time()); $this->generateEXCEL($d."导出取消订阅客户数据",$new); } function generateEXCEL($filename = 'report',$data = ''){ //引入PHPExcel相关文件 require_once( ONU_ROOT . 'phpexcel/PHPExcel.php'); require_once( ONU_ROOT . 'phpexcel/PHPExcel/IOFactory.php'); require_once( ONU_ROOT . 'phpexcel/PHPExcel/Writer/Excel5.php'); //新建 $resultPHPExcel = new PHPExcel(); //设置参数 //设值 $resultPHPExcel->getActiveSheet()->setCellValue('A1', '站点'); $resultPHPExcel->getActiveSheet()->setCellValue('B1', 'mobile'); //设置水平居中 $resultPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $resultPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置水平居中 $resultPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $resultPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $i = 2; foreach($data as $item){ $resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $item['uname']); $resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $item['mobile']); //设置单元格宽度 $resultPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(40); $resultPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30); $resultPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30); $resultPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30); //设置水平居中 $resultPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $resultPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置行高度 $resultPHPExcel->getActiveSheet()->getRowDimension("1")->setRowHeight(20); $resultPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(20); $i ++; } //设置导出文件名 $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel); ob_end_clean();//清除缓冲区,避免乱码 //ob_start(); ob_flush(); header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); //header('Content-Disposition:inline;filename="'.$outputFileName.'"'); header('Content-Disposition:attachment;filename='.'"'.$filename.'.xls"'); //可以对文件名进行处理 header("Content-Transfer-Encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); $xlsWriter->save('php://output'); exit; } public function getName($admin,$uid){ $result = $admin->selectUserName($uid); return $result['uname']; } function querylists(){ require_once (ONU_ROOT . "frame/Page.class.php"); $admin = new AdvertAdminAction(); $where = "where 1=1 "; if ($_GET['id']) { $where.=" and b.fid={$_GET['id']} " ; } $page = $_REQUEST['page']?$_REQUEST['page']:1; $pageSize = 10; $n = ($page-1)*$pageSize; $pa = "";//查询参数 $limit = " $n,$pageSize"; $info = $_REQUEST['info']; $error = $_REQUEST['error']; $uname = $_SESSION['user_infos']['uname']; $list = $admin->select_smslog_list_query($where,$limit); $all_total = $admin->select_smslog_count_query($where); $p = new Page($all_total,$pageSize,$pa); $pp = $p->fpage(); $send_array = array( '1' => '阿里', '2' => '牛信云', ); $status_array = array( '1' => '发送中', '2' => '未发送', ); $new=array(); foreach ($list as $k=>$v){ $params = unserialize($v['params_json']); $new[$k]=$v; $new[$k]['status']=1; $new[$k]['sendtime']=date('Y-m-d H:i:s',$v['sendtime']); if($v['sendtime']>time()){ $new[$k]['status']=2; } $new[$k]['count']=count($params['phone']); } $this->assign('status_array',$status_array); $this->assign('send_array',$send_array); $this->assign('info',$info); $this->assign('error',$error); $this->assign('page',$page); $this->assign("show",$pp); $this->assign('list',$new); $this->assign('uname',$uname); $this->display('querylists.html'); } //过滤已加入分组美加用户州区号 public function jinList(){ $admin = new AdvertAdminAction(); $where =" where is_send=1"; $page=1; $pageSize=50; $city_code =$admin->selectCityCode() ; $new=array(); foreach ($city_code as $v){ $new[]=$v['code']; } do { try { $n = ($page-1)*$pageSize; $limit = " $n,$pageSize"; $customer_list = $admin->selesctSmsCustomer($where,$limit); foreach ($customer_list as $vs){ $countryMobile = $this->getCountryMobile($vs['country']); if($countryMobile==1){ $tel=$this->checkMobileCode($vs['tel']); $is_send =$this->getSend($tel,$new); if($is_send==2){ $admin->upCodeSmsCustomer($is_send,$vs['id'],$tel); } } } $page=$page+1; } catch (\Exception $e) { exit(1); } } while (is_array($customer_list) && !empty($customer_list)); echo ' over~~'; } public function checkMobileCode($mobile){ $mobile= str_replace('-', '', $mobile); $mobile= str_replace('_', '', $mobile); $mobile= str_replace('(', '', $mobile); $mobile= str_replace(')', '', $mobile); $mobile= str_replace('+', '', $mobile); $mobile= str_replace(' ', '', $mobile); $mobile=trim($mobile); $frist =(int)substr($mobile, 0, 1 ); $lenth=strlen($mobile); if($lenth==11&&$frist==1){//例:14696305087 $mobile =substr($mobile , 2 , 10); } return $mobile; } public function getSend($mobile,$new) { $lenth=strlen($mobile); $code =0; if($lenth==10){ $code = substr($mobile , 0 , 3); } $is_send=2; if($code){ if (in_array($code, $new)) { $is_send=1; } } return $is_send; } public function getCountryMobile($countryCode){ $country = $countryCode; $countrys_en = [ "China", "Afghanistan", "Albania", "Algera", "Andorra", "Angola", "Anguilla", "Ascension", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botwana", "Brazill", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "Colombia", "Comoros", "Republic of the Congo", "Democratic Republic of the Congo", "Cook Islands", "Costa Rica", "Cote divoire", "Croatia", "Cuba", "Cyprus", "+Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "EISalvador", "Estonia", "Ethiopia", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guernsey", "Guinea", "Guyana", "Haiti", "Honduras", "Hong Kong", "Myanmar", "Hungary", "Iceland", "Indea", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazeakhstan", "Kenya", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Namibia", "Nepal", "Netherlands", "Netherlands Antillse", "New Caledonia", "NewZealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palestinian", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "PuertoRico", "Qotar", "Reunion", "Romania", "Russia", "Rwanda", "Samoa Eastern", "Samoa Western", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "South Africa", "Korea", "Spain", "SriLanka", "St Kitts and Nevis", "St.Lucia", "St.Vincent", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "USA", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "Yemen", "Zambia", "Zimbabwe" ]; $countrys = array_keys($countrys_en,$country,true); if($countrys[0]){ $countryMobile =$this->getCountryCode($countrys[0]); }else{ $countryMobile ='+1'; } $countryMobile = str_replace('+','',$countryMobile); return (int)$countryMobile; } //获取国家手机编号 public function getCountryCode($countryCode){ $codes = [ "+86", "+93", "+355", "+213", "+376", "+244", "+1264", "+247", "+1268", "+54", "+374", "+297", "+61", "+43", "+994", "+1242", "+973", "+880", "+1246", "+375", "+32", "+501", "+229", "+1441", "+975", "+591", "+387", "+267", "+55", "+673", "+359", "+226", "+257", "+855", "+237", "+1", "+238", "+1345", "+236", "+235", "+56", "+57", "+269", "+242", "+243", "+682", "+506", "+225", "+385", "+53", "+357", "+420", "+45", "+253", "+1767", "+1809", "+593", "+20", "+503", "+372", "+251", "+298", "+679", "+358", "+33", "+594", "+689", "+241", "+220", "+995", "+94", "+233", "+350", "+30", "+299", "+1473", "+590", "+1671", "+502", "+240", "+44", "+224", "+592", "+509", "+504", "+852", "+95", "+36", "+354", "+91", "+62", "+98", "+964", "+353", "+44", "+972", "+93", "+1876", "+81", "+44", "+962", "+7", "+254", "+383", "+965", "+996", "+856", "+371", "+961", "+266", "+231", "+218", "+423", "+370", "+352", "+853", "+389", "+261", "+265", "+60", "+960", "+223", "+356", "+596", "+222", "+230", "+262", "+52", "+373", "+377", "+976", "+382", "+1664", "+212", "+258", "+264", "+977", "+31", "+599", "+687", "+64", "+505", "+227", "+234", "+47", "+968", "+92", "+970", "+507", "+675", "+595", "+51", "+63", "+48", "+351", "+1", "+974", "+262", "+40", "+7", "+250", "+684", "+685", "+378", "+239", "+966", "+221", "+381", "+248", "+232", "+65", "+421", "+386", "+27", "+82", "+34", "+94", "+1869", "+1758", "+1784", "+249", "+597", "+268", "+46", "+41", "+963", "+886", "+992", "+255", "+66", "+670", "+228", "+676", "+1868", "+216", "+90", "+993", "+1649", "+256", "+380", "+971", "+44", "+1", "+598", "+998", "+678", "+58", "+84", "+1340", "+967", "+260", "+263" ]; return $codes[$countryCode]; } }