Car.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 汽车
  7. *
  8. * @icon fa fa-car
  9. */
  10. class Car extends Backend
  11. {
  12. /**
  13. * Car模型对象
  14. * @var \app\admin\model\Car
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Car;
  21. $this->view->assign("chepaicolorList", $this->model->getChepaicolorList());
  22. $this->view->assign("isEtcList", $this->model->getIsEtcList());
  23. $this->view->assign("powerList", $this->model->getPowerList());
  24. $this->view->assign("leasetypeList", $this->model->getLeasetypeList());
  25. }
  26. /**
  27. * 即时信息
  28. */
  29. public function gpsinfo(){
  30. $id = input('id',0);
  31. $row = Db::name('car')->where('id',$id)->find();
  32. $data = $this->getgpsinfo($row['chepaihao'],$row['chepaicolor'],$this->model->getChepaicolorList());
  33. $this->view->assign("gpsinfo", $data);
  34. return $this->view->fetch();
  35. }
  36. private function getgpsinfo($chepaihao = '',$chepaicolor = '',$color_code)
  37. {
  38. $url = 'http://140.210.193.143:8088/topgps/services/TopDataService.ashx';
  39. $url = 'http://ads.cetgps.com/topgps/services/TopDataService.ashx';
  40. $request = [
  41. 'Action' => 'GetVehicleGpsInfo',
  42. 'UserId' => 'dxqc',
  43. 'Pwd' => strtoupper(md5('134679aA#')),
  44. 'Vehicles' => [
  45. [
  46. 'PlateNum' => $chepaihao,
  47. 'ColorCode' => $chepaicolor,
  48. ],
  49. ],
  50. 'NeedAddress' => '1',
  51. ];
  52. $curl_data = ['request'=>json_encode($request)];
  53. $result = curl_post($url,$curl_data);
  54. //$result = '{"Ret":0,"Msg":"","Data":[{"PlateNum":"川AA80498","ColorCode":"5","GpsTime":"2024/1/17 15:04:13","Mileage":"50805.90","Speed":"5.5","Longitude":"104.045393","Latitude":"30.646638","Address":"四川省成都市武侯区武侯祠大街231-2号 成都武侯祠博物馆南272米","Direction":"94","Altitude":"463","IsGpsValid":"1","AlarmInfo":"","StateInfo":"ACC开;定位;运营;","DriverLicense":"","DriverName":"","OrgName":"成都登欣汽车服务有限公司"}],"Datal":[]}';
  55. $data = [];
  56. //字段
  57. $field_arr = [
  58. 'PlateNum' => '车牌号码',
  59. 'ColorCode' => '车牌颜色编码',
  60. 'Mileage' => '里程',
  61. 'Speed' => '速度',
  62. 'GpsTime' => '时间',
  63. 'Longitude' => '经度',
  64. 'Latitude' => '纬度',
  65. 'Address' => '地理位置',
  66. 'Direction' => '海拔',
  67. 'Altitude' => '方向',
  68. 'IsGpsValid' => '是否定位',
  69. 'AlarmInfo' => '报警信息',
  70. 'StateInfo' => '状态信息',
  71. // 'DriverLicense' => '司机',
  72. // 'DriverName' => '司机',
  73. // 'OrgName' => '公司名',
  74. ];
  75. /*//颜色码
  76. $color_code = [
  77. 5=>'绿色',
  78. 1=>'蓝色',
  79. 2=>'黄色',
  80. 3=>'黑色',
  81. 4=>'白色',
  82. 9=>'其他',
  83. 91=>'农黄色',
  84. 92=>'农绿色',
  85. 94=>'渐变绿',
  86. 224=>'黄绿',
  87. 225=>'白绿'
  88. ];*/
  89. $result = json_decode($result,true);
  90. if(is_array($result) && isset($result['Ret']) && $result['Ret'] == 0){
  91. if(isset($result['Data'][0])){
  92. $data0 = $result['Data'][0];
  93. unset($data0['DriverLicense']);
  94. unset($data0['DriverName']);
  95. unset($data0['OrgName']);
  96. foreach($data0 as $key => $val){
  97. if($key == 'IsGpsValid'){
  98. $val = ($val == 1) ? '定位' : '未定位';
  99. }
  100. if($key == 'ColorCode'){
  101. $val = isset($color_code[$val]) ? $color_code[$val] : '未知';
  102. }
  103. //字段转换中文
  104. $newkey = isset($field_arr[$key]) ? $field_arr[$key] : $key;
  105. $data[$newkey] = $val;
  106. }
  107. }
  108. }
  109. //dump($data);
  110. return $data;
  111. }
  112. }