Browse Source

24小时各场馆数据

master
wanghongjun 3 years ago
parent
commit
e8523e3b93
  1. 10
      source/application/api/controller/pass/Passcc.php
  2. 41
      source/application/common/logic/PassFlow.php

10
source/application/api/controller/pass/Passcc.php

@ -87,4 +87,14 @@ class Passcc extends Controller
return $this->renderSuccess(compact('data'));
}
/**
* 24小时各场馆数据
* @return array
*/
public function getPassHoursData()
{
$groupsId = $this->request->param('groupsId') ?: '';
$data = PassFlow::getPassHoursData(null,['groupsId' => $groupsId]);
return $this->renderSuccess(compact('data'));
}
}

41
source/application/common/logic/PassFlow.php

@ -414,4 +414,45 @@ class PassFlow
return $data;
}
/**
* 24小时各场馆数据
* @return array
*/
public static function getPassHoursData($dm = null,$param = [])
{
if (empty($dm)) $dm = new Dm();
$where = ' "granularity"='."'hourly' ";
if (!empty($param)) {
if (!empty($param['groupsId'])) {
$groupsId = explode("|",$param['groupsId']);
$where .= ' and "groupId" in (' . "'" . implode("','",$groupsId) . "')";
}
}
$date = self::getDateData('day');
$start_time = $date['day']['start_time'];
$end_time = $date['day']['end_time'];
$where .= ' and "statTime" >= ' . "'{$start_time}'" . ' and "statTime" <= ' . "'{$end_time}'";
$list = $dm->select('bt_passenger_flow',$where);
$allTimeData = [];
for ($i = 0; $i < 23; $i++) {
$str = strlen($i) == 1 ? '0'.$i.':00' : $i.':00';
$allTimeData[$str] = 0;
}
$returnData = [];
foreach ($list as $value) {
$date = date('H:00',strtotime($value['statTime']) + (8*3600)); // 各时间端进馆人数
if (!isset($allTimeData[$date])) continue;
if (!isset($returnData[$allTimeData[$date]])) $returnData[$allTimeData[$date]] = 0;
$returnData[$allTimeData[$date]] += $value['noRepeatInNum'];
}
$data = [];
foreach ($returnData as $date => $item) {
$data['dkeys'][] = $date;
$data['dvalue'][] = $item;
}
return $data;
}
}
Loading…
Cancel
Save