BaseStationLocationTransform.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/9/3
  6. * Time: 8:05 PM
  7. */
  8. namespace App\Servers\Weikemu\Transforms;
  9. use App\Maps\BikeMap;
  10. use App\Models\BoxSettingTraitModel;
  11. use App\Models\WarningLogTraitModel;
  12. use App\Servers\BaseServer;
  13. /**
  14. * 基站位置报文
  15. * Class LoginServer
  16. * @package App\Servers
  17. */
  18. class BaseStationLocationTransform extends BaseServer
  19. {
  20. use BoxSettingTraitModel, WarningLogTraitModel;
  21. public function main($body)
  22. {
  23. $data = $this->decode($body);
  24. $bike_no = $_SESSION['bike_no'];
  25. $box_no = $data['box_no'];
  26. $battery_power = $data['battery_voltage'];
  27. $cols = [];
  28. if (!$this->is_ep_min($box_no, 'update_battery', 5)) {
  29. $cols['battery_power'] = $battery_power;
  30. $cols['is_low_battery_power'] = BikeMap::BATTERY_POWER_OK;
  31. if ($cols['battery_power'] <= self::$max_ride_v) {
  32. $cols['is_low_battery_power'] = BikeMap::BATTERY_POWER_LOW;
  33. //30分钟插一次报警信息
  34. if (!$this->is_ep_min($box_no, 'warning_log_battery', 30)) {
  35. $this->warningLogBatteryLow($bike_no, $data['box_no'], ['battery_power' => $cols['battery_power']], $body, 'location');
  36. }
  37. }
  38. }
  39. // 更新车的位置信息(非骑行状态)
  40. if (count($cols) && !$this->is_ep_min($box_no, 'update_bike_location', 20)) {
  41. $this->db->update('bikes')->where('box_no = ' . $data['box_no'])->cols($cols)->query();
  42. } else {
  43. //换电池及时更新电量
  44. $openBatteryKey = "cache:open_battery:{$box_no}";
  45. if ($this->redis->exists($openBatteryKey)) {
  46. $this->db->update('bikes')->where('box_no = ' . $data['box_no'])->cols($cols)->query();
  47. }
  48. }
  49. $this->mongo->location_logs->insertOne([
  50. 'bike_no' => $bike_no,
  51. 'box_no' => $data['box_no'],
  52. 'order_id' => 0,
  53. 'bike_id' => 0,
  54. 'area_id' => 0,
  55. 'latitude' => 0,
  56. 'longitude' => 0,
  57. 'speed' => 0,
  58. 'battery_power' => $battery_power,
  59. 'mileage' => 0,
  60. 'is_riding' => 0,
  61. 'is_yundong' => 0,
  62. 'type' => 'no-stationLocation',
  63. 'is_rent' => 0,
  64. 'created_at' => date('Y-m-d H:i:s'),
  65. 'box_time' => $data['box_time'],
  66. 'status' => 1
  67. ]);
  68. return $this->response();
  69. }
  70. /**
  71. * 状态响应
  72. * @param $login_type
  73. * @return array
  74. * User: Mead
  75. */
  76. public function response($login_type = '00')
  77. {
  78. $body = [
  79. '5b',
  80. '0000'
  81. ];
  82. return $body;
  83. }
  84. /**
  85. * 解析装载的状态消息
  86. * @param $body
  87. * @return array
  88. * User: Mead
  89. */
  90. private function decode($body)
  91. {
  92. $top34Data = $this->decodeWeiKeMuTop34($body);
  93. $i = 34;
  94. return $top34Data;
  95. }
  96. /**
  97. * 处理设备序列号
  98. * @param $no
  99. * @return bool|string
  100. * User: Mead
  101. */
  102. private
  103. static function box_no($no)
  104. {
  105. return substr($no, 0, 9);
  106. }
  107. }