体育管项目脚本
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.

105 lines
3.4 KiB

<?php
namespace task\tasks;
include 'Base.php';
class Lib extends Base
{
public $libUrl = 'https://balib.cn:8999/CustCount/baoan/stat.json?key=baoan';
public $libCameraId = [
[
'groupId' => 'baz001', # 分馆代码
'name' => '图书馆', # 单位名称
'cameraId' => '1,2,3,4,6,7,9,10,67,98,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,41,42,43,44,45,46,47,48,49,50,51,54,55,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,121,122,124,125,126,132,133,134,135,136,137,138,139,140', # 客流系统内分馆摄像头
], [
'groupId' => 'BAF055',
'name' => '文化馆',
'cameraId' => '141,142',
]
];
public function run()
{
$config = $this->config('api_config');
$requestData = [];
#$allData = $this->getBaoAnLibData();
$tempAllArr = [
'group_id' => 'lib001',
'group_name' => base64_encode('文化')
];
/*foreach ($allData as $allKey => $allValue) {
foreach ($allValue as $aKey => $aValue) {
$tempAllArr[$allKey."_".$aKey] = $aValue;
}
}*/
$libData = $this->getBaoAnLibData(true);
foreach ($libData as $row) {
$tempArr = [
'group_id' => $row['groupId'],
'group_name' => base64_encode($row['name'])
];
foreach ($row['data'] as $key => $value) {
foreach ($value as $k => $v) {
if (is_array($v)) {
foreach ($v as $numKey => $numVal) {
if (!isset($tempAllArr[$key][$k][$numKey])) $tempAllArr[$key][$k][$numKey] = 0;
$tempAllArr[$key][$k][$numKey] += $numVal;
}
$tempArr[$key][$k] = $v;
} else {
$field = $key."_".$k;
$tempArr[$field] = $v ?: 0;
if (!isset($tempAllArr[$field])) $tempAllArr[$field] = 0;
$tempAllArr[$field] += $tempArr[$field];
}
}
}
$requestData[] = $tempArr;
}
$requestData[] = $tempAllArr;
$requestRes = $this->request_create_data($requestData,'/api/library.pass/create',$config['host_path'],true);
if (!$requestRes['status']) {
return $requestRes['msg'];
}
return true;
}
/**
* @param $is_group
* @return array|mixed
*/
public function getBaoAnLibData($is_group = false)
{
if ($is_group) {
$data = [];
foreach ($this->libCameraId as $value) {
$url = $this->libUrl . '&cameraid=' . $value['cameraId'];
$result = $this->curl_post($url);
$result = json_decode($result,true);
$data[] = [
'data' => $result,
'groupId' => $value['groupId'],
'name' => $value['name']
];
}
return $data;
} else {
$result = $this->curl_post($this->libUrl);
return json_decode($result,true);
}
}
}
$lib = new Lib();
echo $lib->run();