159 lines
4.7 KiB
PHP
159 lines
4.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-4
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models;
|
|
|
|
|
|
|
|
use app\models\BallCart;
|
|
use app\models\Option;
|
|
use app\models\Order;
|
|
use app\models\Store;
|
|
|
|
class IndexForm extends AdminModel
|
|
{
|
|
public $page;
|
|
public $limit;
|
|
public $keywords;
|
|
public $status;
|
|
public $ball_number;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords',], 'trim'],
|
|
[['keywords','ball_number'], 'string'],
|
|
[['page', 'limit', 'status'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @ Author : Lw
|
|
* @ CreateTime : 2022-11-19
|
|
* @ Info : 数据
|
|
*/
|
|
public function actionGetData(){
|
|
$order_success = Order::find()->andWhere([
|
|
'is_pay' => 1,
|
|
'status' => 0,
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$ball_cart_1 = BallCart::find()->andWhere([
|
|
'status' => 1,
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$ball_cart_2 = BallCart::find()->andWhere([
|
|
'status' => 2,
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$ball_cart_0 = BallCart::find()->andWhere([
|
|
'status' => 0,
|
|
'is_delete' => 0,
|
|
])->select('ball_number')->asArray()->all();
|
|
$ball_cart_all = BallCart::find()->andWhere([
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$arr = [
|
|
'order_success' => $order_success,
|
|
'ball_cart_1' => $ball_cart_1,
|
|
'ball_cart_2' => $ball_cart_2,
|
|
'ball_cart_0' => 0,
|
|
'ball_cart_3' => 0,
|
|
'ball_cart_all' => $ball_cart_all,
|
|
];
|
|
|
|
$qc_zl_kwh_min = "qc_zl_kwh_min"; // 球车最低租赁电量
|
|
$find_option = Option::findOne([
|
|
'key'=>$qc_zl_kwh_min,
|
|
]);
|
|
foreach ($ball_cart_0 as $key=>$val){
|
|
$arr['ball_cart_0'] += 1;
|
|
continue;
|
|
if(!empty($find_option)){
|
|
// 查找球车信息
|
|
$redis_name = "api:cxaibc:mqtt:data:{$val['ball_number']}_Detail";
|
|
$get = \Yii::$app->redis->get($redis_name);
|
|
if(empty($get)){
|
|
$arr['ball_cart_3'] += 1;
|
|
continue;
|
|
}
|
|
try{
|
|
$json_data = json_decode($get, true);
|
|
$json_data = json_decode($json_data['data'], true);
|
|
if(intval($json_data['ELEC_PERCENT']) < intval($find_option->value)){
|
|
$arr['ball_cart_3'] += 1;
|
|
}else{
|
|
$arr['ball_cart_0'] += 1;
|
|
}
|
|
}catch (\Exception $e){
|
|
$arr['ball_cart_3'] += 1;
|
|
}
|
|
}else{
|
|
$arr['ball_cart_0'] += 1;
|
|
}
|
|
}
|
|
return $this->apiReturnSuccess('ok',$arr);
|
|
}
|
|
|
|
/**
|
|
* @ Author : Lw
|
|
* @ CreateTime : 2022-11-19
|
|
* @ Info : 地图数据
|
|
*/
|
|
public function actionGetDtData(){
|
|
$select_store = Store::find()->andWhere([
|
|
'is_delete' => 0,
|
|
])->select('id,name,area')->asArray()->all();
|
|
$arr = [
|
|
'store_data' => [],
|
|
'ball_data' => [],
|
|
];
|
|
foreach ($select_store as $key=>$val){
|
|
$json_de = json_decode($val['area'],true);
|
|
$arr['store_data'][] = [
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'store' => $json_de['store']['paths'],
|
|
];
|
|
}
|
|
$select_qc = BallCart::find()->andWhere([
|
|
'is_delete' => 0,
|
|
])->asArray()->all();
|
|
foreach ($select_qc as $key=>$val){
|
|
|
|
$redis_name = "api:cxaibc:mqtt:data:{$val['ball_number']}_GPS";
|
|
$get = \Yii::$app->redis->get($redis_name);
|
|
if(empty($get)){
|
|
$json_data = [
|
|
'LAT' => 0,
|
|
'LON' => 0,
|
|
];
|
|
}else{
|
|
$json_data = json_decode($get, true);
|
|
$json_data = json_decode($json_data['data'], true);
|
|
}
|
|
if($json_data['LAT'] >90 || $json_data['LAT'] < -90){
|
|
$json_data['LAT'] = -1;
|
|
}
|
|
if($json_data['LON'] >180 || $json_data['LON'] < -180){
|
|
$json_data['LON'] = -1;
|
|
}
|
|
$arr['ball_data'][] = [
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'latlng' => [$json_data['LAT'],$json_data['LON']],
|
|
];
|
|
}
|
|
return $this->apiReturnSuccess('ok',$arr);
|
|
}
|
|
} |