|  | @@ -4,95 +4,168 @@ class Model_Usps_status extends Lin_Model {
 | 
												
													
														
															|  |  			parent::__construct();
 |  |  			parent::__construct();
 | 
												
													
														
															|  |  			
 |  |  			
 | 
												
													
														
															|  |  	}
 |  |  	}
 | 
												
													
														
															|  | -	//异常状态
 |  | 
 | 
												
													
														
															|  | -	protected $one_arr = [
 |  | 
 | 
												
													
														
															|  | -		'processing exception','was returned','delivery exception','addressee unknown','delivered to agent for final delivery','reminder to pick up your item','available for pickup','return to sender processed','redelivery scheduled','notice left','delivery attempted but no response at consignee address','delivery attempt could not be completed','forwarded to a third party agent','awaiting collection by the consignee','consignee has moved from the address provided','awaiting customer pickup'
 |  | 
 | 
												
													
														
															|  | -	];
 |  | 
 | 
												
													
														
															|  | -	//快递点接收
 |  | 
 | 
												
													
														
															|  | -	protected $two_arr = ['accepted at usps origin facility'];
 |  | 
 | 
												
													
														
															|  | -	//在途
 |  | 
 | 
												
													
														
															|  | -	protected $three_arr = ['picked up item','in transit'];
 |  | 
 | 
												
													
														
															|  | -	//
 |  | 
 | 
												
													
														
															|  | -	protected $four_arr = ['arrived at usps destination facility','distribution center','out for delivery'];
 |  | 
 | 
												
													
														
															|  | -	//快递签收
 |  | 
 | 
												
													
														
															|  | -	protected $six_arr = ['delivered','delivered by the expected delivery date','delivered by the expected delivery date','to be delivered','your item was picked up at the post office','your item was picked up at'];
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | 
 |  | +	
 | 
												
													
														
															|  |  	//获取快递状态
 |  |  	//获取快递状态
 | 
												
													
														
															|  | -	public function getState($str){
 |  | 
 | 
												
													
														
															|  | 
 |  | +	public function getState($str,$zt,$dataprovince){
 | 
												
													
														
															|  |  		$exstate =  0 ;
 |  |  		$exstate =  0 ;
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -		if($this->statusOne($str)){
 |  | 
 | 
												
													
														
															|  | -			$exstate = 1;
 |  | 
 | 
												
													
														
															|  | -		}
 |  | 
 | 
												
													
														
															|  | -		if($this->statusTwo($str)){
 |  | 
 | 
												
													
														
															|  | -			$exstate = 2;
 |  | 
 | 
												
													
														
															|  | 
 |  | +		if(
 | 
												
													
														
															|  | 
 |  | +			(stripos($str,'delivered') !== false && stripos($str,'delivered by the expected delivery date') === false && stripos($str,'to be delivered') === false) 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Your item was picked up at the post office') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| stripos($str,'Your item was picked up at') !== false
 | 
												
													
														
															|  | 
 |  | +		)
 | 
												
													
														
															|  | 
 |  | +		{
 | 
												
													
														
															|  | 
 |  | +			$exstate = 6;
 | 
												
													
														
															|  | 
 |  | +			$zx = 1;
 | 
												
													
														
															|  |  		}
 |  |  		}
 | 
												
													
														
															|  | -		if($this->statusThree($str)){
 |  | 
 | 
												
													
														
															|  | -			$exstate = 3;
 |  | 
 | 
												
													
														
															|  | 
 |  | +		else if(
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'out for delivery') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Processing Exception') 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'was returned') 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Delivery exception') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Addressee Unknown') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Delivered to Agent for Final Delivery') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Reminder to pick up your item') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Available for Pickup') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Processing Exception') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Return to Sender Processed') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Redelivery Scheduled') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Notice Left') !== false
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Delivery attempted but no response at Consignee address') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Delivery attempt could not be completed') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Forwarded to a third party agent') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Awaiting collection by the consignee') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'Consignee has moved from the address provided') !== false 
 | 
												
													
														
															|  | 
 |  | +			|| 
 | 
												
													
														
															|  | 
 |  | +			stripos($str,'awaiting customer pickup') !== false)
 | 
												
													
														
															|  | 
 |  | +		{
 | 
												
													
														
															|  | 
 |  | +			$exstate = 1;
 | 
												
													
														
															|  | 
 |  | +			$zx = 1;
 | 
												
													
														
															|  |  		}
 |  |  		}
 | 
												
													
														
															|  | -		if($this->statusFour($str)){
 |  | 
 | 
												
													
														
															|  | 
 |  | +		else if(
 | 
												
													
														
															|  | 
 |  | +			stripos(strtolower($str),strtolower('Arrived at USPS Destination Facility')) !== false && stripos(strtolower($str),strtolower($dataprovince.' DISTRIBUTION CENTER')) !== false
 | 
												
													
														
															|  | 
 |  | +		)
 | 
												
													
														
															|  | 
 |  | +		{
 | 
												
													
														
															|  |  			$exstate = 4;
 |  |  			$exstate = 4;
 | 
												
													
														
															|  | 
 |  | +			$zx = 1;
 | 
												
													
														
															|  |  		}
 |  |  		}
 | 
												
													
														
															|  | -		if($this->statusSix($str)){
 |  | 
 | 
												
													
														
															|  | -			$exstate = 6;
 |  | 
 | 
												
													
														
															|  | -		}
 |  | 
 | 
												
													
														
															|  | -		return $exstate;
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -	}
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -	protected function statusOne($str){
 |  | 
 | 
												
													
														
															|  | -		$str = strtolower($str);
 |  | 
 | 
												
													
														
															|  | -		$one_flag = false;
 |  | 
 | 
												
													
														
															|  | -		foreach($this->one_arr as $v){
 |  | 
 | 
												
													
														
															|  | -			if(stripos($str,$v) !== false){
 |  | 
 | 
												
													
														
															|  | -				$one_flag = true;
 |  | 
 | 
												
													
														
															|  | -			}
 |  | 
 | 
												
													
														
															|  | 
 |  | +		else if(stripos(strtolower($str),'In transit') !== false || stripos(strtolower($str),'picked up item') !== false)
 | 
												
													
														
															|  | 
 |  | +		{
 | 
												
													
														
															|  | 
 |  | +			$exstate = 3;
 | 
												
													
														
															|  | 
 |  | +			$zx = 1;
 | 
												
													
														
															|  |  		}
 |  |  		}
 | 
												
													
														
															|  | -		return $one_flag;
 |  | 
 | 
												
													
														
															|  | -	}
 |  | 
 | 
												
													
														
															|  | -	protected function statusTwo($str){
 |  | 
 | 
												
													
														
															|  | -		$str = strtolower($str);
 |  | 
 | 
												
													
														
															|  | -		$two_flag = false;
 |  | 
 | 
												
													
														
															|  | -		foreach($this->two_arr as $v){
 |  | 
 | 
												
													
														
															|  | -			if(stripos($str,$v) !== false){
 |  | 
 | 
												
													
														
															|  | -				$two_flag = true;
 |  | 
 | 
												
													
														
															|  | -			}
 |  | 
 | 
												
													
														
															|  | 
 |  | +		else if(stripos(strtolower($str),'accepted at usps origin facility') !== false)
 | 
												
													
														
															|  | 
 |  | +		{
 | 
												
													
														
															|  | 
 |  | +			$exstate = 2;
 | 
												
													
														
															|  | 
 |  | +				$zx = 1;
 | 
												
													
														
															|  |  		}
 |  |  		}
 | 
												
													
														
															|  | -		return $two_flag;
 |  | 
 | 
												
													
														
															|  | -	}
 |  | 
 | 
												
													
														
															|  | -	protected function statusThree($str){
 |  | 
 | 
												
													
														
															|  | -		$str = strtolower($str);
 |  | 
 | 
												
													
														
															|  | -		$three_flag = false;
 |  | 
 | 
												
													
														
															|  | -		foreach($this->three_arr as $v){
 |  | 
 | 
												
													
														
															|  | -			if(stripos($str,$v) !== false){
 |  | 
 | 
												
													
														
															|  | -				$three_flag = true;
 |  | 
 | 
												
													
														
															|  | 
 |  | +		else
 | 
												
													
														
															|  | 
 |  | +		{
 | 
												
													
														
															|  | 
 |  | +			if(is_array($zt))
 | 
												
													
														
															|  | 
 |  | +			{
 | 
												
													
														
															|  | 
 |  | +				foreach($zt as $item)
 | 
												
													
														
															|  | 
 |  | +				{ 
 | 
												
													
														
															|  | 
 |  | +					$v =isset($item['eventType'])?$item['eventType']:"";
 | 
												
													
														
															|  | 
 |  | +					if(
 | 
												
													
														
															|  | 
 |  | +						stripos(strtolower($v),'out for delivery') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos(strtolower($v),'processing exception') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Delivery exception') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Addressee Unknown') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Delivered to Agent for Final Delivery') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Reminder to pick up your item') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Available for Pickup') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Processing Exception') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Return to Sender Processed') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Redelivery Scheduled') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Notice Left') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Delivery attempted but no response at Consignee address') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Delivery attempt could not be completed') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Forwarded to a third party agent') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Awaiting collection by the consignee') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'Consignee has moved from the address provided') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos($v,'awaiting customer pickup') !== false
 | 
												
													
														
															|  | 
 |  | +					)
 | 
												
													
														
															|  | 
 |  | +					{
 | 
												
													
														
															|  | 
 |  | +						$exstate = 1;
 | 
												
													
														
															|  | 
 |  | +						break;
 | 
												
													
														
															|  | 
 |  | +					}
 | 
												
													
														
															|  | 
 |  | +					/**
 | 
												
													
														
															|  | 
 |  | +					if(stripos(strtolower($v),strtolower($number['city'])) !== false && stripos(strtolower($v),'arrived at post office') !== false)
 | 
												
													
														
															|  | 
 |  | +					{
 | 
												
													
														
															|  | 
 |  | +						$exstate = 5;
 | 
												
													
														
															|  | 
 |  | +						break;
 | 
												
													
														
															|  | 
 |  | +					}
 | 
												
													
														
															|  | 
 |  | +					**/
 | 
												
													
														
															|  | 
 |  | +					else if(
 | 
												
													
														
															|  | 
 |  | +						stripos(strtolower($v),strtolower('Arrived at USPS Destination Facility')) !== false 
 | 
												
													
														
															|  | 
 |  | +						&& 
 | 
												
													
														
															|  | 
 |  | +						stripos(strtolower($v),strtolower($dataprovince.' DISTRIBUTION CENTER')) !== false
 | 
												
													
														
															|  | 
 |  | +					)
 | 
												
													
														
															|  | 
 |  | +					{
 | 
												
													
														
															|  | 
 |  | +						$exstate = 4;
 | 
												
													
														
															|  | 
 |  | +						break;
 | 
												
													
														
															|  | 
 |  | +					}
 | 
												
													
														
															|  | 
 |  | +					if(
 | 
												
													
														
															|  | 
 |  | +						stripos(strtolower($v),'In transit') !== false 
 | 
												
													
														
															|  | 
 |  | +						|| 
 | 
												
													
														
															|  | 
 |  | +						stripos(strtolower($v),'picked up item') !== false
 | 
												
													
														
															|  | 
 |  | +					)
 | 
												
													
														
															|  | 
 |  | +					{
 | 
												
													
														
															|  | 
 |  | +						$exstate = 3;
 | 
												
													
														
															|  | 
 |  | +						break;
 | 
												
													
														
															|  | 
 |  | +					}
 | 
												
													
														
															|  | 
 |  | +					if(stripos(strtolower($v),'accepted at usps origin facility') !== false)
 | 
												
													
														
															|  | 
 |  | +					{
 | 
												
													
														
															|  | 
 |  | +						$exstate = 2;
 | 
												
													
														
															|  | 
 |  | +						break;
 | 
												
													
														
															|  | 
 |  | +					}
 | 
												
													
														
															|  | 
 |  | +				}
 | 
												
													
														
															|  |  			}
 |  |  			}
 | 
												
													
														
															|  | -		}
 |  | 
 | 
												
													
														
															|  | -		return $three_flag;
 |  | 
 | 
												
													
														
															|  | -	}
 |  | 
 | 
												
													
														
															|  | -	protected function statusFour($str){
 |  | 
 | 
												
													
														
															|  | -		$str = strtolower($str);
 |  | 
 | 
												
													
														
															|  | -		$four_flag = false;
 |  | 
 | 
												
													
														
															|  | -		foreach($this->four_arr as $v){
 |  | 
 | 
												
													
														
															|  | -			if(stripos($str,$v) !== false){
 |  | 
 | 
												
													
														
															|  | -				$four_flag = true;
 |  | 
 | 
												
													
														
															|  | 
 |  | +			else
 | 
												
													
														
															|  | 
 |  | +			{
 | 
												
													
														
															|  | 
 |  | +				//这种情况基本没有 因为文档上返回的参数必须是数组,哪怕就一个状态也是数组
 | 
												
													
														
															|  | 
 |  | +				$exstate = 1;
 | 
												
													
														
															|  | 
 |  | +				
 | 
												
													
														
															|  |  			}
 |  |  			}
 | 
												
													
														
															|  | 
 |  | +			
 | 
												
													
														
															|  |  		}
 |  |  		}
 | 
												
													
														
															|  | -		return $four_flag;
 |  | 
 | 
												
													
														
															|  | 
 |  | +		return  $exstate;
 | 
												
													
														
															|  |  	}
 |  |  	}
 | 
												
													
														
															|  | -	protected function statusFive($str){
 |  | 
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -	}
 |  | 
 | 
												
													
														
															|  | -	protected function statusSix($str){
 |  | 
 | 
												
													
														
															|  | -		$str = strtolower($str);
 |  | 
 | 
												
													
														
															|  | -		$six_flag = false;
 |  | 
 | 
												
													
														
															|  | -		foreach($this->six_arr as $v){
 |  | 
 | 
												
													
														
															|  | -			if(stripos($str,$v) !== false){
 |  | 
 | 
												
													
														
															|  | -				$six_flag  = true;
 |  | 
 | 
												
													
														
															|  | -			}
 |  | 
 | 
												
													
														
															|  | -		}
 |  | 
 | 
												
													
														
															|  | -		return $six_flag;
 |  | 
 | 
												
													
														
															|  | -	}
 |  | 
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +	
 | 
												
													
														
															|  |  	
 |  |  	
 | 
												
													
														
															|  |  }  //end class
 |  |  }  //end class
 |