1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if (!$this->validate()) { return $this->getModelError(); } $query = BallCart::find()->alias('ball') ->leftJoin(['store' => Store::tableName()], 'ball.store_id=store.id') ->leftJoin(['mark' => BallMark::tableName()], 'ball.mark_id=mark.id') ->select('ball.id,mark.name as mard_name,mark.id as mard_id,ball.ball_number,ball.status,store.name,ball.money') ->where([ 'ball.is_delete' => 0 ]) ->andFilterWhere([ 'OR', // ['like', 'ball.ball_model', $this->keywords], ['like', 'ball.ball_number', $this->keywords], ['like', 'store.name', $this->keywords], ])->andFilterWhere([ 'ball.status' => $this->status, 'ball.store_id' => $this->store_id, ]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['ball.id' => SORT_DESC])->asArray()->all(); $qc_wgh_value = "qc_wgh"; // 球车超出时长报警 $find_option = Option::findOne([ 'key' => $qc_wgh_value, ]); foreach ($list as $key => $value) { $ball_status = $this->getBallCart($value['ball_number']); $list[$key]['ball_status'] = $ball_status == true ? 1 : 0; $list[$key]['warn_info'] = []; if(!empty($ball_status)){ $redis_name = "api:cxaibc:mqtt:warn_status:{$value['ball_number']}"; $get = \Yii::$app->redis->get($redis_name); if(!empty($get)){ $json_data = json_decode($get, true); $title_arr = [ 'WARN_HARDWARE' => '链路异常', 'WARN_LOW_POWER' => '低电量', 'WARN_FALLDOWN' => '倾倒', 'GPS_CALL' => '超出安全范围', 'GPS_STORE' => '超出门店范围', ]; foreach ($json_data as $k=>$v){ if(!empty($v)){ $list[$key]['warn_info'][] = $title_arr[$k]; } } } } if(!empty($find_option->value) && intval($value['status']) === 1 && $value['updated_at']+(60*intval($find_option->value)) <= time()){ $list[$key]['warn_info'][] = "租赁超出指定时间"; } $list[$key]['warn_info'] = implode(',',$list[$key]['warn_info']); } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } public function getBallCart($ball_number) { $redis_name = self::BALL_CART_INFO . $ball_number . '_Detail'; if (\Yii::$app->redis->setnx($redis_name, 1)) { \Yii::$app->redis->del($redis_name); return false; } $json_data = \Yii::$app->redis->get($redis_name); $json_data_base = json_decode($json_data, true); $json_data = json_decode($json_data_base['data'], true); if (!is_array($json_data) && empty($json_data)) { return false; } if(intval($json_data_base['time']) >= time()-60*2){ return true; } return true; } /** * @ Author : Lw * @ CreateTime : 2022-11-18 * @ Info : 球车详情 */ public function actionQcData(){ if(empty($this->ball_number)){ return $this->apiReturnError('请求错误'); } $redis_name = "api:cxaibc:mqtt:data:{$this->ball_number}_Detail"; $get = \Yii::$app->redis->get($redis_name); if(empty($get)){ return $this->apiReturnError('车辆暂无信息'); } $json_data = json_decode($get, true); $json_data = json_decode($json_data['data'], true); $arr = $json_data; $redis_name = "api:cxaibc:mqtt:data:{$this->ball_number}_GPS"; $get = \Yii::$app->redis->get($redis_name); if(empty($get)){ $json_data = [ 'LAT' => 0, 'LON' => 0, ]; $json_data_base['time'] = 0; }else{ $json_data_base = json_decode($get, true); $json_data = json_decode($json_data_base['data'], true); } $arr['LAT'] = $json_data['LAT']; $arr['LON'] = $json_data['LON']; if(!empty($json_data_base['time'])){ $arr['time'] = date('Y-m-d H:i:s',intval($json_data_base['time'])); }else{ $arr['time'] = " -- "; } $arr['time_page'] = date('Y-m-d H:i:s',time()); $arr['error_info'] = []; $redis_name = "api:cxaibc:mqtt:warn_status:{$this->ball_number}"; $get = \Yii::$app->redis->get($redis_name); if(!empty($get)){ $json_data = json_decode($get, true); $title_arr = [ 'WARN_HARDWARE' => '链路异常警告', 'WARN_LOW_POWER' => '低电量警告', 'WARN_FALLDOWN' => '倾倒告警', 'GPS_CALL' => '超出安全范围', 'GPS_STORE' => '超出门店范围', ]; foreach ($json_data as $key=>$val){ if(!empty($val)){ $arr['error_info'][] = [ 'msg' => $title_arr[$key], 'time' => date('Y-m-d H:i:s',intval($val)), ]; } } } return $this->apiReturnSuccess('',$arr); } }