123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers\Weikemu\Transforms;
- use App\Maps\BikeMap;
- use App\Models\BoxSettingTraitModel;
- use App\Models\WarningLogTraitModel;
- use App\Servers\BaseServer;
- /**
- * 基站位置报文
- * Class LoginServer
- * @package App\Servers
- */
- class BaseStationLocationTransform extends BaseServer
- {
- use BoxSettingTraitModel, WarningLogTraitModel;
- public function main($body)
- {
- $data = $this->decode($body);
- $bike_no = $_SESSION['bike_no'];
- $box_no = $data['box_no'];
- $battery_power = $data['battery_voltage'];
- $cols = [];
- if (!$this->is_ep_min($box_no, 'update_battery', 5)) {
- $cols['battery_power'] = $battery_power;
- $cols['is_low_battery_power'] = BikeMap::BATTERY_POWER_OK;
- if ($cols['battery_power'] <= self::$max_ride_v) {
- $cols['is_low_battery_power'] = BikeMap::BATTERY_POWER_LOW;
- //30分钟插一次报警信息
- if (!$this->is_ep_min($box_no, 'warning_log_battery', 30)) {
- $this->warningLogBatteryLow($bike_no, $data['box_no'], ['battery_power' => $cols['battery_power']], $body, 'location');
- }
- }
- }
- // 更新车的位置信息(非骑行状态)
- if (count($cols) && !$this->is_ep_min($box_no, 'update_bike_location', 20)) {
- $this->db->update('bikes')->where('box_no = ' . $data['box_no'])->cols($cols)->query();
- } else {
- //换电池及时更新电量
- $openBatteryKey = "cache:open_battery:{$box_no}";
- if ($this->redis->exists($openBatteryKey)) {
- $this->db->update('bikes')->where('box_no = ' . $data['box_no'])->cols($cols)->query();
- }
- }
- $this->mongo->location_logs->insertOne([
- 'bike_no' => $bike_no,
- 'box_no' => $data['box_no'],
- 'order_id' => 0,
- 'bike_id' => 0,
- 'area_id' => 0,
- 'latitude' => 0,
- 'longitude' => 0,
- 'speed' => 0,
- 'battery_power' => $battery_power,
- 'mileage' => 0,
- 'is_riding' => 0,
- 'is_yundong' => 0,
- 'type' => 'no-stationLocation',
- 'is_rent' => 0,
- 'created_at' => date('Y-m-d H:i:s'),
- 'box_time' => $data['box_time'],
- 'status' => 1
- ]);
- return $this->response();
- }
- /**
- * 状态响应
- * @param $login_type
- * @return array
- * User: Mead
- */
- public function response($login_type = '00')
- {
- $body = [
- '5b',
- '0000'
- ];
- return $body;
- }
- /**
- * 解析装载的状态消息
- * @param $body
- * @return array
- * User: Mead
- */
- private function decode($body)
- {
- $top34Data = $this->decodeWeiKeMuTop34($body);
- $i = 34;
- return $top34Data;
- }
- /**
- * 处理设备序列号
- * @param $no
- * @return bool|string
- * User: Mead
- */
- private
- static function box_no($no)
- {
- return substr($no, 0, 9);
- }
- }
|