1 changed files with 124 additions and 0 deletions
@ -0,0 +1,124 @@ |
|||
<?php |
|||
|
|||
namespace app\api\controller\pass; |
|||
|
|||
use app\api\controller\Controller; |
|||
use app\common\dm\Dm; |
|||
|
|||
class Statistics extends Controller |
|||
{ |
|||
|
|||
private $password = 'batyg@2023'; |
|||
|
|||
private function validateToken($token) { |
|||
$xtToken = md5(base64_encode($this->password)); |
|||
return $xtToken === $token; |
|||
} |
|||
|
|||
/** |
|||
* 获取年各场馆统计数据 |
|||
* @return array |
|||
*/ |
|||
public function getYearVenueData() |
|||
{ |
|||
$year = $this->request->param('year') ?: date('Y'); |
|||
$token = $this->request->param('token'); |
|||
if (!is_numeric($year)) return $this->renderError('请求失败'); |
|||
if (empty($token)) return $this->renderError('请求失败'); |
|||
if (!$this->validateToken($token)) return $this->renderError('请求验证不通过'); |
|||
|
|||
$dm = new Dm(); |
|||
|
|||
$start_time = "{$year}-01-01" . 'T00:00:00.000+08:00'; |
|||
$end_time = "{$year}-12-31" . 'T23:59:59.000+08:00'; |
|||
$yearWhere = '"date" =' . "'month'" |
|||
. ' and "granularity"=' . "'monthly'" |
|||
. ' and "statTime">=' . "'{$start_time}'" |
|||
. ' and "statTime"<=' . "'{$end_time}'"; |
|||
|
|||
# 体育馆 体育场 劳务博物馆 游泳场馆 |
|||
$tyData = []; |
|||
|
|||
$tyResult = $dm->select('bt_passenger_flow_all',$yearWhere,'"groupId","flowInNum","statTime"'); |
|||
foreach ($tyResult as $item) { |
|||
|
|||
$groupId = $item['groupId']; |
|||
$month = date("m", strtotime($item['statTime'])); |
|||
|
|||
if (!isset($tyData[$groupId]['sum_year'])) $tyData[$groupId]['sum_year'] = 0; |
|||
$tyData[$groupId]['sum_year'] += $item['flowInNum']; |
|||
|
|||
if (!isset($tyData[$groupId]['month'][$month])) $tyData[$groupId]['month'][$month] = 0; |
|||
$tyData[$groupId]['month'][$month] += $item['flowInNum']; |
|||
} |
|||
|
|||
$data = [ |
|||
'yearDate' => $year, |
|||
'dataResult' => [] |
|||
]; |
|||
|
|||
foreach ($tyData as $groupId => $monthData) { |
|||
|
|||
|
|||
$getGroup = $dm->find('bt_passenger_monitor_group',' "groupId" = ' . "'{$groupId}'"); |
|||
$groupName = $getGroup['groupName'] ?: ''; |
|||
$tempData = [ |
|||
'name' => $groupName, |
|||
'year' => $monthData['sum_year'], |
|||
'monthDate' => [] |
|||
]; |
|||
|
|||
foreach ($monthData['month'] as $month => $value) { |
|||
$tempData['monthDate'][] = [ |
|||
'month' => $month, |
|||
'value' => $value |
|||
]; |
|||
} |
|||
$data['dataResult'][] = $tempData; |
|||
} |
|||
|
|||
# 文化馆 图书馆 |
|||
$start_time = "{$year}-01-01 00:00:00"; |
|||
$end_time = "{$year}-12-31 23:59:59"; |
|||
$whWhere = '"date"=' . "'month'" |
|||
.' and "group_id"<>' . "'lib001'" |
|||
.' and "create_time">=' . "'{$start_time}'" |
|||
.' and "create_time"<=' . "'{$end_time}'"; |
|||
$whResult = $dm->select('bt_library_data',$whWhere,'"group_id","group_name","incount","create_time"'); |
|||
$whData = []; |
|||
$whGroupName = []; |
|||
|
|||
foreach ($whResult as $item) { |
|||
$groupId = $item['group_id']; |
|||
$month = date("m", strtotime($item['create_time'])); |
|||
$whGroupName[$groupId] = $item['group_name']; |
|||
|
|||
if (!isset($whData[$groupId]['sum_year'])) $whData[$groupId]['sum_year'] = 0; |
|||
$whData[$groupId]['sum_year'] += $item['incount']; |
|||
|
|||
if (!isset($whData[$groupId]['month'][$month])) $whData[$groupId]['month'][$month] = 0; |
|||
$whData[$groupId]['month'][$month] += $item['incount']; |
|||
} |
|||
|
|||
foreach ($whData as $groupId => $monthData) { |
|||
|
|||
$groupName = isset($whGroupName[$groupId]) ? $whGroupName[$groupId] : ''; |
|||
|
|||
$tempData = [ |
|||
'name' => $groupName, |
|||
'year' => $monthData['sum_year'], |
|||
'monthDate' => [] |
|||
]; |
|||
|
|||
foreach ($monthData['month'] as $month => $value) { |
|||
$tempData['monthDate'][] = [ |
|||
'month' => $month, |
|||
'value' => $value |
|||
]; |
|||
} |
|||
$data['dataResult'][] = $tempData; |
|||
} |
|||
|
|||
return $this->renderSuccess($data); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue