Browse Source

图书馆脚本优化

master
wanghongjun 2 years ago
parent
commit
46b3c9956a
  1. 86
      tasks/Passreal.php

86
tasks/Passreal.php

@ -13,19 +13,18 @@ class Passreal extends Base
$requestData = [];
try{
date_default_timezone_set('Asia/Shanghai');
date_default_timezone_set('Asia/Shanghai');
# $url = $config['host_url'] . "/api/cfas/v3/passenger/realTime";
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$token = $this->get_access_token();
# $dataArr = $this->get_real_group_ids($config,$token,2);
$dataArr = [
'ids' => $this->get_real_group_ids($config,$token,1),
'granularity' => 'daily',
'startTime' => date("c",strtotime('today')),
'endTime' => date('c',time())
];
$dataArr = [
'ids' => $this->get_real_group_ids($config,$token,1),
'granularity' => 'hourly',
'startTime' => date("c",strtotime('today')),
'endTime' => date('c',time())
];
$json_data = json_encode($dataArr);
$result = $this->post_token($url,$json_data,false,[],$token);
@ -34,24 +33,63 @@ class Passreal extends Base
$list = (array) $res_data['data'];
$existsArr = [];
$resultList = [];
foreach ($list['list'] as $value) {
$existsArr[] = $value['groupId'];
$insert_arr = [
'groupId' => $value['groupId'],
'regionId' => '0',
'statisticsTime' => $value['statTime'],
'enter' => $value['noRepeatOutNum'],
'exit' => $value['flowOutNum'],
'pass' => $value['holdValue'] ?: '',
'holdValue' => $value['netValue'],
'allEnter' => $value['flowInNum'],
'allExit' => $value['noRepeatInNum']
];
#Db::table('bt_passenger_flow_real')->insert($insert_arr);
$value['netValue'] = $value['netValue'] > 0 ? $value['netValue'] : 0;
$groupId = $value['groupId'];
# 统计时间
if (!isset($resultList[$groupId]['statisticsTime'])) {
$resultList[$groupId]['statisticsTime'] = $value['statTime'];
}
# 去重后进客流
if (!isset($resultList[$groupId]['enter'])) {
$resultList[$groupId]['enter'] = $value['noRepeatOutNum'];
} else {
$resultList[$groupId]['enter'] += $value['noRepeatOutNum'];
}
# 去重后出客流
if (!isset($resultList[$groupId]['exit'])) {
$resultList[$groupId]['exit'] = $value['flowOutNum'];
} else {
$resultList[$groupId]['exit'] += $value['flowOutNum'];
}
# 总经过人数
if (!isset($resultList[$groupId]['pass'])) {
$resultList[$groupId]['pass'] = $value['holdValue'] ?: 0;
} else {
$resultList[$groupId]['pass'] += $value['holdValue'] ?: 0;
}
# 保有量
if (!isset($resultList[$groupId]['holdValue'])) {
$resultList[$groupId]['holdValue'] = $value['netValue'];
} else {
$resultList[$groupId]['holdValue'] += $value['netValue'];
}
# 去重前进入人数
if (!isset($resultList[$groupId]['allEnter'])) {
$resultList[$groupId]['allEnter'] = $value['flowInNum'];
} else {
$resultList[$groupId]['allEnter'] += $value['flowInNum'];
}
# 去重前离开人数
if (!isset($resultList[$groupId]['allExit'])) {
$resultList[$groupId]['allExit'] = $value['noRepeatInNum'];
} else {
$resultList[$groupId]['allExit'] += $value['noRepeatInNum'];
}
}
# 总和数据发送,存储
foreach ($resultList as $groupId => $insert_arr) {
$existsArr[] = $groupId;
$insert_arr['groupId'] = $groupId;
$insert_arr['regionId'] = '0';
$requestData[] = $insert_arr;
}
$idsArr = explode(",",$dataArr['ids']);
# 如果数据不存在,传输数据全部为0
$idsArr = explode(",",$dataArr['ids']);
foreach ($idsArr as $id) {
$is_continue = true;
if (empty($id)) {

Loading…
Cancel
Save