TaxiCar.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\model;
  3. use Curl\Curl;
  4. use GuzzleHttp\Client;
  5. use think\facade\Db;
  6. class TaxiCar
  7. {
  8. protected $path = "http://dlyz.chefudang.cn:8102/transportapp/queryVehicleList?";
  9. protected $curl = null;
  10. public function __construct()
  11. {
  12. $this->db = Db::connect('mysql0');
  13. $this->client = new Client();
  14. $this->curl = new Curl();
  15. }
  16. /**
  17. * 处理数据
  18. * @throws \think\db\exception\DbException
  19. */
  20. public function editData()
  21. {
  22. $this->db->table('total_cars')
  23. ->field('id,num,cert')
  24. ->chunk(1000,function ($list){
  25. foreach ($list as $item){
  26. //$certiticate = $this->findNum($item['Certiticate']);
  27. $this->getCarRes($item['num'],$item['cert'],$item['id']);
  28. }
  29. });
  30. }
  31. /**
  32. * 更新车证状态
  33. * @param $plate_number
  34. * @param $vin_no
  35. * @param $car_id
  36. * @throws \think\db\exception\DbException
  37. */
  38. public function getCarRes($plate_number,$Certiticate,$car_id)
  39. {
  40. $plate_number = urlencode($plate_number);
  41. $params = 'VehicleNo='.$plate_number.'&TransCertificateCode='.$Certiticate.'&Page=1&PageSize=10';
  42. $url = $this->path.$params;
  43. $re = curlGet($url);
  44. if(strpos($re,'营运') !== false ){
  45. $this->db->table('total_cars')
  46. ->where('id','=',$car_id)
  47. ->update(['is_leg'=>'有']);
  48. }
  49. // if(strpos($re,'注销') !== false || strpos($re,'服务器内部错误') !== false){
  50. // $this->db->table('taxi_cars')
  51. // ->where('carid','=',$car_id)
  52. // ->update(['is_test'=>1]);
  53. // }
  54. }
  55. /**
  56. * 字符串中提取数字
  57. * @param string $str
  58. * @return string
  59. */
  60. public function findNum($str='')
  61. {
  62. $str=trim($str);
  63. if(empty($str)){return '';}
  64. $result='';
  65. for($i=0;$i<strlen($str);$i++){
  66. if(is_numeric($str[$i])){
  67. $result.=$str[$i];
  68. }
  69. }
  70. return $result;
  71. }
  72. }