You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.7 KiB
125 lines
3.7 KiB
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use app\common\dm\Dm;
|
|
|
|
class Pass extends BaseModel
|
|
{
|
|
public static $unit = [1 => '>', 2 => '<', 3 => '=', 4 => '≥', 5 => '<=', 6 => '!='];
|
|
|
|
public static $libUrl = 'http://balib.cn:8999/CustCount/baoan/stat.json?key=baoan';
|
|
|
|
public static $libCameraId = [
|
|
[
|
|
'groupId' => 'baz001', # 分馆代码
|
|
'name' => '宝安图书馆', # 单位名称
|
|
'cameraId' => '9,7,6,4,2,1,67,3', # 客流系统内分馆摄像头
|
|
], [
|
|
'groupId' => 'BAF055',
|
|
'name' => '1990分馆',
|
|
'cameraId' => '134,135',
|
|
]
|
|
];
|
|
|
|
/**
|
|
* 馆舍客流情况-拥挤程度
|
|
* @param $proportion // 比例
|
|
* @return string
|
|
*/
|
|
public static function getPassType($proportion)
|
|
{
|
|
# 舒适:阈值<80%
|
|
if ($proportion < 0.8) {
|
|
return '舒适';
|
|
}
|
|
# 饱和:80%<阈值<100%
|
|
if (0.8 < $proportion || $proportion < 1) {
|
|
return '饱和';
|
|
}
|
|
# 拥挤:阈值=100%
|
|
if ($proportion == 1) {
|
|
return '拥挤';
|
|
}
|
|
# 拥挤:阈值=100%
|
|
if ($proportion >= 1.2) {
|
|
return '爆满';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* 请求创建数据
|
|
* @param $requestData
|
|
* @param $url
|
|
* @param $host_path
|
|
* @return array|int[]
|
|
*/
|
|
public static function requestCreateData($requestData,$url,$host_path = '')
|
|
{
|
|
# 验证传输数据
|
|
if (empty($requestData) && is_array($requestData)) return ['status' => 0, 'msg' => 'requestData不能为空,且必须是数组'];
|
|
if (empty($url)) return ['status' => 0, 'msg' => 'url不能为空'];
|
|
# 获取请求路径
|
|
if (empty($host_path)) {
|
|
$config = config('api_config');
|
|
$host_path = $config['host_path'];
|
|
}
|
|
# 验证令牌
|
|
$token = '9c4cb25665cf08667c815420ab383cb5';
|
|
# 请求接口数据
|
|
$data = [
|
|
'data' => base64_encode(json_encode($requestData)),
|
|
'token' => md5($token . date('Ymd'))
|
|
];
|
|
$json_data = json_encode($data);
|
|
$createUrl = $host_path . $url;
|
|
# 发起请求
|
|
$result = postToken($createUrl,$json_data,false,[],$token);
|
|
$result = json_decode($result,true);
|
|
# 判断返回信息
|
|
if ($result['code'] != 1) return ['status' => 0, 'msg' => $result['msg']];
|
|
return ['status' => 1];
|
|
}
|
|
|
|
/**
|
|
* 获取统计组ID
|
|
* @param $dataType // 1 返回字符串 2 返回数组
|
|
* @return array|string
|
|
*/
|
|
public static function getGroupIds($dataType)
|
|
{
|
|
$dm = new Dm();
|
|
$groupRes = $dm->select('bt_passenger_monitor_group',null,'"groupId"');
|
|
$groupIdArr = array_column($groupRes,'groupId') ?: [];
|
|
return $dataType == 2 ? $groupIdArr : implode(",",$groupIdArr);
|
|
}
|
|
|
|
/**
|
|
* @param $is_group
|
|
* @return array|mixed
|
|
*/
|
|
public static function getBaoAnLibData($is_group = false)
|
|
{
|
|
if ($is_group) {
|
|
|
|
$data = [];
|
|
foreach (self::$libCameraId as $value) {
|
|
|
|
$url = self::$libUrl . '&cameraid=' . $value['cameraId'];
|
|
$result = curlPost($url);
|
|
$result = json_decode($result,true);
|
|
$data[] = [
|
|
'data' => $result,
|
|
'groupId' => $value['groupId'],
|
|
'name' => $value['name']
|
|
];
|
|
}
|
|
return $data;
|
|
} else {
|
|
|
|
$result = curlPost(self::$libUrl);
|
|
return json_decode($result,true);
|
|
}
|
|
}
|
|
}
|