| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Notice extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_user','user');		$this->load->_model('Model_notice','notice');		$this->load->_model('Model_noticeemail','noticeemail');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_express','express');		$this->load->_model('Model_emaildata','emaildata');		$this->load->_model('Model_als','als');		$this->load->_model('Model_apitt','apitt');		$this->load->_model('Model_producttitle','producttitle');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'add')//添加        {             $this->_add($arg_array);        }		else if($arg == 'edit')//修改        {             $this->_edit($arg_array);        }		else if($arg == 'del')//修改        {             $this->_del();        }		else if($arg == 'rows')//数据        {             $this->_rows();        }		else if($arg == 'email')        {             $this->_email();        }		else if($arg == 'addemail')        {             $this->_addemail();        }		else if($arg == 'emailfs')        {             $this->_emailfs();        }		else if($arg == 'testfs')        {             $this->_testfs();        }		else		{			 $this->_index($arg_array);		}    }	//管理	public function _index($arg_array)	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);		    $fgshop = "";$sid = "";		    $user = explode('|',trim($user['shop'],'|'));			foreach ($user as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$shop = $this->input->post('shop',true);			$type = $this->input->post('type',true);			$ordertatus = $this->input->post('ordertatus',true);			$arg = $this->input->post('arg',true);			$logisticstatus = $this->input->post('logisticstatus',true);			$where = "1=1 and (".rtrim($fgshop,'or').")";			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($ordertatus)            {                $where  .= " and ordertatus = '$ordertatus'";            }			if($logisticstatus)            {                $where  .= " and logisticstatus = '$logisticstatus'";            }            //数据排序            $order_str = "id asc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->notice->find_all($where,'id,shop,title,type,message,email,ordertatus,logisticstatus,ktime,jtime,state',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				$email = $this->emaildata->read($value['email']);				$info_list[$key]['email'] = $email['smtp_user'];				$info_list[$key]['ktime'] = date('Y-m-d',$value['ktime']);				$info_list[$key]['jtime'] = date('Y-m-d',$value['jtime']);		    	if($value['type'] == 1)				{					$info_list[$key]['type'] = '自动发送';				}				else if($value['type'] == 2)				{					$info_list[$key]['type'] = '物流追踪';				}				else if($value['type'] == 3)				{					$info_list[$key]['type'] = '营销';				}				else if($value['type'] == 4)				{					$info_list[$key]['type'] = '运单号通知';				}				if($value['message'] == 1)				{					$info_list[$key]['message'] = '发送邮件';				}				//订单状态开始				$typeclass = $this->typeclass->read($value['ordertatus']);				$info_list[$key]['ordertatus'] = $typeclass?(($arg==1)?$typeclass['title']:$typeclass['spare']):'';				//订单状态结束				if($value['logisticstatus'] == 0)				{					$info_list[$key]['logisticstatus'] = "无信息";				}				else if($value['logisticstatus'] == 2)				{					$info_list[$key]['logisticstatus'] = "已取件";				}				else if($value['logisticstatus'] == 3)				{					$info_list[$key]['logisticstatus'] = "在途中";				}				/**				else if($value['logisticstatus'] == 4)				{					$info_list[$key]['logisticstatus'] = "到达目的地国";				}				**/				else if($value['logisticstatus'] == 4 || $value['logisticstatus'] == 5)				{					$info_list[$key]['logisticstatus'] = "即将派送";				}				else if($value['logisticstatus'] == 6)				{					$info_list[$key]['logisticstatus'] = "已签收";				}				else if($value['logisticstatus'] == 1)				{					$info_list[$key]['logisticstatus'] = "派送异常";				}				if($value['message'] == 1)				{					$info_list[$key]['message'] = '发送邮件';				}				else if($value['message'] == 2)				{					$info_list[$key]['message'] = 'AE站内信';				}				else if($value['message'] == 3)				{					$info_list[$key]['message'] = 'TT会话';				}				if($value['state'] == 1)				{					$info_list[$key]['state'] = '启用中';				}				else if($value['state'] == 2)				{					$info_list[$key]['state'] = '未启用';				}            }		    $total = $this->notice->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));		    echo json_encode($rows);exit;		}		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));		$this->data['wlshop'] = $wlshop;		$mb = 2;		if(isset($arg_array[0]))		{			if($arg_array[0]=='smt')			{				$mb = 1;			}			else if($arg_array[0]=='dlz')			{				$mb = 2;			}			else if($arg_array[0]=='tt')			{				$mb = 3;			}		}		$this->data['arg'] = $mb;		$this->_Template('notice',$this->data);	}	//添加	public function _add($arg_array)	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);		    $fgshop = "";$sid = "";		    $user = explode('|',trim($user['shop'],'|'));			foreach ($user as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['title']))		{			$post['title'] = $this->input->post('title',true);			$post['shop'] = $this->input->post('shop',true);			$post['message'] = $this->input->post('message',true);			$post['type'] = $this->input->post('type',true);			$post['repeat'] = $this->input->post('repeat',true);			$ktime = $this->input->post('ktime',true);			$post['ktime'] = strtotime($ktime);			$jtime = $this->input->post('jtime',true);			$post['jtime'] = strtotime($jtime);			$post['content'] = $this->input->post('content');			$emailtitle = $this->input->post('emailtitle');			$post['js'] = '';			if($emailtitle)			{				$post['emailtitle'] = $emailtitle;			}			if($post['type'] == 1)			{				$post['ordertatus'] = $this->input->post('ordertatus',true);				if($post['ordertatus'] == 2 || $post['ordertatus'] == 3)				{					$post['sending'] = $this->input->post('sending',true);					$post['timeinterval'] = $this->input->post('timeinterval',true);				}			}			else if($post['type'] == 2)			{				$post['logisticstatus'] = $this->input->post('logisticstatus',true);			}			else if($post['type'] == 3)			{				$marketing = $this->input->post('marketing',true);			    $post['marketing'] = strtotime($marketing);			}			else if($post['type'] == 4)			{				$post['js'] = $this->input->post('js',true);				if($post['js'] != '')				{					$post['js'] = ','.$post['js'];				}				$post['express'] = $this->input->post('express',true);				if($post['express'] != '')				{					$post['express'] = ','.$post['express'];				}			}			$post['state'] = $this->input->post('state',true);			if($post['state'] == 1)			{				$post['statetime'] = time();			}						if($this->notice->insert($post))        	{         		echo json_encode(array('msg'=>'添加成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;        	}		}		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));		$this->data['wlshop'] = $wlshop;		$email = $this->emaildata->find_all('1=1 and '.rtrim($fgshop,'or'));		$this->data['email'] = $email;		$mb = 2;		if(isset($arg_array[0]))		{			if($arg_array[0]=='smt')			{				$mb = 1;			}			else if($arg_array[0]=='dlz')			{				$mb = 2;			}			else if($arg_array[0]=='tt')			{				$mb = 3;			}		}		$this->data['arg'] = $mb;		$this->_Template('notice_add',$this->data);	}	//修改	public function _edit($arg_array)	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);		    $fgshop = "";$sid = "";		    $user = explode('|',trim($user['shop'],'|'));			foreach ($user as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$post['title'] = $this->input->post('title',true);			$post['shop'] = $this->input->post('shop',true);			$post['message'] = $this->input->post('message',true);			$post['type'] = $this->input->post('type',true);			$post['repeat'] = $this->input->post('repeat',true);			$ktime = $this->input->post('ktime',true);			$post['ktime'] = strtotime($ktime);			$jtime = $this->input->post('jtime',true);			$post['jtime'] = strtotime($jtime);			$post['content'] = $this->input->post('content');			$post['emailtitle'] = $this->input->post('emailtitle');			$post['js'] = '';			if($post['type'] == 1)			{				$post['ordertatus'] = $this->input->post('ordertatus',true);				if($post['ordertatus'] == 2 || $post['ordertatus'] == 3)				{					$post['sending'] = $this->input->post('sending',true);					$post['timeinterval'] = $this->input->post('timeinterval',true);				}				$post['logisticstatus'] = 0;			}			else if($post['type'] == 2)			{				$post['ordertatus'] = 0;//非订单状态写入:未获取				$post['logisticstatus'] = $this->input->post('logisticstatus',true);			}			else if($post['type'] == 3)			{				$post['ordertatus'] = 0;//非订单状态写入:未获取				$marketing = $this->input->post('marketing',true);			    $post['marketing'] = strtotime($marketing);			}			else if($post['type'] == 4)			{				$post['js'] = $this->input->post('js',true);				if($post['js'] != '')				{					$post['js'] = ','.$post['js'];				}				$post['express'] = $this->input->post('express',true);				if($post['express'] != '')				{					$post['express'] = ','.$post['express'];				}			}			$post['state'] = $this->input->post('state',true);			if($post['state'] == 1)			{				$post['statetime'] = time();			}			if($this->notice->save($post,$id))        	{         		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		$notice = $this->notice->read($arg_array[0]);		$this->data['notice'] = $notice;		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));		$this->data['wlshop'] = $wlshop;		$email = $this->emaildata->find_all('1=1 and '.rtrim($fgshop,'or'));		$this->data['email'] = $email;		$mb = 2;		if(isset($arg_array[0]))		{			if($arg_array[0]=='smt')			{				$mb = 1;			}			else if($arg_array[0]=='dlz')			{				$mb = 2;			}			else if($arg_array[0]=='tt')			{				$mb = 3;			}		}		$this->data['arg'] = $mb;		$this->_Template('notice_edit',$this->data);	}	//删除	public function _del()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{            $id_arr = $this->input->post('s');            $id_arr =  explode(',',$id_arr);            if(!$id_arr)            {                echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;            }            //循环删除记录            foreach ($id_arr as $v) 		    {                $this->notice->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }		public function _email()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);		    $fgshop = "";$sid = "";		    $user = explode('|',trim($user['shop'],'|'));			foreach ($user as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$shop = $this->input->post('shop',true);			$email = $this->input->post('email',true);			$notice = $this->input->post('notice',true);			$xztime = $this->input->post('xztime',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1 and (".rtrim($fgshop,'or').")";			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($email)            {                $where  .= " and email like '%$email%'";            }			if($notice)            {                $where  .= " and notice = '$notice'";            }			if($timetk && $timetj)            {                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->noticeemail->find_all($where,'id,shop,email,notice,addtime,time',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$data = $this->noticeemail->read($value['id']);				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				$info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);				if(is_numeric($value['time']) &&  $value['time'] > 0)				{				    $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);				}				else				{					$info_list[$key]['time'] = '';					if($data['error'] != '')					{						$info_list[$key]['time'] = $data['error'];					}				}				$notice = $this->notice->read($value['notice']);				$info_list[$key]['notice'] = $notice['title'];            }		    $total = $this->noticeemail->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));		    echo json_encode($rows);exit;		}		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));		$this->data['wlshop'] = $wlshop;		$notice = $this->notice->find_all("message = 1 and type = '3' and (".rtrim($fgshop,'or').")");		$this->data['notice'] = $notice;		$this->_Template('notice_email',$this->data);	}		public function _addemail()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);		    $fgshop = "";$sid = "";		    $user = explode('|',trim($user['shop'],'|'));			foreach ($user as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['email']))  		{			$time = time();$cw = '';$i = 0;$fs = '';		    $notice = $this->input->post('notice',true);			$n = $this->notice->read($notice);			$email = $this->input->post('email',true);			$email = str_replace(PHP_EOL, ',', $email);            $email =  explode(',',trim($email,','));			$this->db->trans_begin();			foreach ($email as $v) 		    {				$f = $this->fullorder->find_all("email = '$v' and shop = '".$n['shop']."'",'*','id desc');				if(isset($f[0]['email']))				{					$tid = $this->noticeemail->insert(array('shop'=>$f[0]['shop'],'email'=>$v,'notice'=>$notice,'addtime'=>$time));					$fs .= $f[0]['id'].'-'.$tid.',';				}				else				{					$i++;					$cw .= $v.',';				}			}			if(count($email) == $i)			{				echo json_encode(array('msg'=>'Email地址全部错误,请排查!','success'=>false));exit;			}			if($this->db->trans_status() === TRUE)			{				$this->db->trans_commit();				$ch = curl_init();				$url = 'http://a'.rand(10,50).'.wepolicy.cn/notice/emailfs';				curl_setopt($ch,CURLOPT_URL,$url);				curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);				curl_setopt($ch,CURLOPT_HEADER,0);				curl_setopt($ch,CURLOPT_POST, 1);				curl_setopt($ch,CURLOPT_TIMEOUT,1);        		//设置post数据				$post = array();				$post['notice'] = $notice;				$post['fs'] = trim($fs,',');        		curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));				$res = curl_exec($ch);				curl_close($ch);				if($i > 0)				{					echo json_encode(array('msg'=>'有错误Email地址,请排查!其它正常发送中。<br>错误Email:<br>'.trim($cw,',').'<br>','success'=>true));exit;				}				else				{					echo json_encode(array('n'=>0,'msg'=>'添加成功,邮件逐条发送中','success'=>true));exit;			    }							}			else			{			    $this->db->trans_rollback();				echo json_encode(array('msg'=>'系统错误,请重试!!','success'=>false));exit;		    }		}		$notice = $this->notice->find_all("message = 1 and type = '3' and (".rtrim($fgshop,'or').")");		$this->data['notice'] = $notice;		$this->_Template('notice_addemail',$this->data);	}		public function _emailfs()	{		$time = time();		$post = $this->input->post(NULL, TRUE);		if(isset($post['notice']))  		{			$notice = $this->input->post('notice');			$notice = $this->notice->read($notice);			$notice['email'] = $this->emaildata->read($notice['email']);			$fs = $this->input->post('fs');			$fs =  explode(',',$fs);			foreach ($fs as $v) 		    {				$v = explode('-',$v);				$data = $this->fullorder->read($v[0]);				$shop = $this->shop->read($data['shop']);				$express = $this->express->read($data['express']);				$this->als->save(array('cs'=>json_encode(array($data,$shop,$express,$notice))),1);				$go = $this->notice->get_god($data,$shop,$express,$notice);				if($go == 1)		        {					$this->noticeemail->save(array('time'=>time()),$v[1]);				}				else				{					$this->noticeemail->save(array('error'=>$go),$v[1]);				}				sleep(50);			}		}	}		public function _testfs()	{		$time = time();		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))  		{			$id = $this->input->post('id');			$email = $this->input->post('email');			$number = $this->input->post('number');			$data = $this->fullorder->get_number($number);			if(!$data)			{				$data = $this->fullordersmt->get_number($number);				if(!$data)				{					$data = $this->fullordertt->get_number($number);					if(!$data)					{						echo json_encode(array('msg'=>'编号无效!','success'=>false));exit;					}				}			}			else			{				if(!$email)				{					echo json_encode(array('msg'=>'请输入邮箱!','success'=>false));exit;				}			}			$data['email'] = $email;			$shop = $this->shop->read($data['shop']);			$express = $this->express->read($data['express']);			$id_arr =  explode(',',trim($id,','));$i = 0;			foreach ($id_arr as $v) 		    {				$notice = $this->notice->read($v);				if($notice)				{					$notice['email'] = $this->emaildata->read($notice['email']);					$go = $this->notice->get_god($data,$shop,$express,$notice);					if($go == 1)		        	{						$i++;					}				}			}			if($i == count($id_arr))			{				echo json_encode(array('msg'=>'发送成功','success'=>false));exit;			}			else			{				echo json_encode(array('msg'=>'有部分发送失败'.$go,'success'=>false));exit;			}		}	}}
 |