Model_usps_status.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. class Model_Usps_status extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. }
  6. //异常状态
  7. protected $one_arr = [
  8. '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'
  9. ];
  10. //快递点接收
  11. protected $two_arr = ['accepted at usps origin facility'];
  12. //在途
  13. protected $three_arr = ['picked up item','in transit'];
  14. //
  15. protected $four_arr = ['arrived at usps destination facility','distribution center','out for delivery'];
  16. //快递签收
  17. 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'];
  18. //获取快递状态
  19. public function getState($str){
  20. $exstate = 0 ;
  21. if($this->statusOne($str)){
  22. $exstate = 1;
  23. }
  24. if($this->statusTwo($str)){
  25. $exstate = 2;
  26. }
  27. if($this->statusThree($str)){
  28. $exstate = 3;
  29. }
  30. if($this->statusFour($str)){
  31. $exstate = 4;
  32. }
  33. if($this->statusSix($str)){
  34. $exstate = 6;
  35. }
  36. return $exstate;
  37. }
  38. protected function statusOne($str){
  39. $str = strtolower($str);
  40. $one_flag = false;
  41. foreach($this->one_arr as $v){
  42. if(stripos($str,$v) !== false){
  43. $one_flag = true;
  44. }
  45. }
  46. return $one_flag;
  47. }
  48. protected function statusTwo($str){
  49. $str = strtolower($str);
  50. $two_flag = false;
  51. foreach($this->two_arr as $v){
  52. if(stripos($str,$v) !== false){
  53. $two_flag = true;
  54. }
  55. }
  56. return $two_flag;
  57. }
  58. protected function statusThree($str){
  59. $str = strtolower($str);
  60. $three_flag = false;
  61. foreach($this->three_arr as $v){
  62. if(stripos($str,$v) !== false){
  63. $three_flag = true;
  64. }
  65. }
  66. return $three_flag;
  67. }
  68. protected function statusFour($str){
  69. $str = strtolower($str);
  70. $four_flag = false;
  71. foreach($this->four_arr as $v){
  72. if(stripos($str,$v) !== false){
  73. $four_flag = true;
  74. }
  75. }
  76. return $four_flag;
  77. }
  78. protected function statusFive($str){
  79. }
  80. protected function statusSix($str){
  81. $str = strtolower($str);
  82. $six_flag = false;
  83. foreach($this->six_arr as $v){
  84. if(stripos($str,$v) !== false){
  85. $six_flag = true;
  86. }
  87. }
  88. return $six_flag;
  89. }
  90. } //end class