Browse Source

文化管数据合并

master
wanghongjun 1 year ago
parent
commit
333bbd70dd
  1. 53
      source/application/api/controller/pass/Statistics.php

53
source/application/api/controller/pass/Statistics.php

@ -10,7 +10,7 @@ class Statistics extends Controller
private $password = 'batyg@2023'; private $password = 'batyg@2023';
protected function validateUserToken($token) { private function validateUserToken($token) {
$xtToken = md5(base64_encode($this->password)); $xtToken = md5(base64_encode($this->password));
return $xtToken === $token; return $xtToken === $token;
} }
@ -57,6 +57,9 @@ class Statistics extends Controller
'dataResult' => [] 'dataResult' => []
]; ];
$whgData = isset($tyData['610']) ? $tyData['610'] : ['sum_year' => 0, 'month' => []];
unset($tyData['610']);
foreach ($tyData as $groupId => $monthData) { foreach ($tyData as $groupId => $monthData) {
@ -64,10 +67,12 @@ class Statistics extends Controller
$groupName = $getGroup['groupName'] ?: ''; $groupName = $getGroup['groupName'] ?: '';
$tempData = [ $tempData = [
'name' => $groupName, 'name' => $groupName,
'year' => $monthData['sum_year'], 'yearAmount' => $monthData['sum_year'],
'monthDate' => [] 'monthDate' => []
]; ];
ksort($monthData['month']); ksort($monthData['month']);
foreach ($monthData['month'] as $month => $value) { foreach ($monthData['month'] as $month => $value) {
$tempData['monthDate'][] = [ $tempData['monthDate'][] = [
'month' => $month, 'month' => $month,
@ -97,19 +102,24 @@ class Statistics extends Controller
$whData[$groupId]['sum_year'] += $item['incount']; $whData[$groupId]['sum_year'] += $item['incount'];
if (!isset($whData[$groupId]['month'][$month])) $whData[$groupId]['month'][$month] = 0; if (!isset($whData[$groupId]['month'][$month])) $whData[$groupId]['month'][$month] = 0;
$whData[$groupId]['month'][$month] += $item['incount']; $whData[$groupId]['month'][010] += $item['incount'];
} }
$whg2Data = isset($whData['BAF055']) ? $whData['BAF055'] : ['sum_year' => 0, 'month' => []];
unset($whData['BAF055']);
foreach ($whData as $groupId => $monthData) { foreach ($whData as $groupId => $monthData) {
$groupName = isset($whGroupName[$groupId]) ? $whGroupName[$groupId] : ''; $groupName = isset($whGroupName[$groupId]) ? $whGroupName[$groupId] : '';
$tempData = [ $tempData = [
'name' => $groupName, 'name' => $groupName,
'year' => $monthData['sum_year'], 'yearAmount' => $monthData['sum_year'],
'monthDate' => [] 'monthDate' => []
]; ];
ksort($monthData['month']); ksort($monthData['month']);
foreach ($monthData['month'] as $month => $value) { foreach ($monthData['month'] as $month => $value) {
$tempData['monthDate'][] = [ $tempData['monthDate'][] = [
'month' => $month, 'month' => $month,
@ -119,6 +129,39 @@ class Statistics extends Controller
$data['dataResult'][] = $tempData; $data['dataResult'][] = $tempData;
} }
// 文化馆两数据合并
$getGroup = $dm->find('bt_passenger_monitor_group',' "groupId" = ' . "'610'");
$groupName = $getGroup['groupName'] ?: '';
$tempData = [
'name' => $groupName,
'yearAmount' => $whgData['sum_year'] + $whg2Data['sum_year'],
'monthDate' => []
];
$whgMonthKeyArr = array_keys($whgData['month']);
foreach ($whg2Data['month'] as $key => $value) {
if (in_array($key, $whgMonthKeyArr)) {
$whgData['month'][$key] += $value;
unset($whg2Data['month'][$key]);
}
}
if (!empty($whg2Data['month'])) {
$whgData['month'] = array_merge($whgData['month'], $whg2Data['month']);
}
ksort($whgData['month']);
foreach ($whgData['month'] as $month => $value) {
$tempData['monthDate'][] = [
'month' => $month,
'value' => $value
];
}
$data['dataResult'][] = $tempData;
return $this->renderSuccess($data); return $this->renderSuccess($data);
} }
} }

Loading…
Cancel
Save