Browse Source

优化接口数据

master
wanghongjun 3 years ago
parent
commit
0eb4153f72
  1. 6
      source/application/api/controller/pass/Passcc.php
  2. 72
      source/application/common/logic/PassFlow.php

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

@ -42,7 +42,8 @@ class Passcc extends Controller
*/
public function allGroupNum()
{
$returnData = PassFlow::allGroupNum();
$groupsId = $this->request->param('groupsId') ?: '';
$returnData = PassFlow::allGroupNum(null,['groupsId' => $groupsId]);
return $this->renderSuccess(compact('returnData'));
}
@ -68,7 +69,8 @@ class Passcc extends Controller
*/
public function toDayGroupsEnterNum()
{
$data = PassFlow::toDayGroupsEnterNum();
$groupsId = $this->request->param('groupsId') ?: '';
$data = PassFlow::toDayGroupsEnterNum(null,['groupsId' => $groupsId]);
return $this->renderSuccess(compact('data'));
}

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

@ -180,7 +180,7 @@ class PassFlow
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function allGroupNum($dm = null) {
public static function allGroupNum($dm = null,$param = []) {
$dateArr = ['day' => 'daily', 'week' => 'daily', 'month' => 'monthly', 'year' => 'yearly'];
@ -189,9 +189,16 @@ class PassFlow
# 总进馆人数
$yearSum = 0;
if (empty($dm)) $dm = new Dm();
$paramWhere = '';
if (!empty($param)) {
if (!empty($param['groupsId'])) {
$groupsId = explode("|",$param['groupsId']);
$paramWhere .= ' and "groupId" in (' . "'" . implode("','",$groupsId) . "'";
}
}
$dateData = self::getDateData();
foreach ($dateArr as $date => $granularity) {
$where = ' "granularity" = ' . "'{$granularity}'" . ' and "date" = ' . "'{$date}'";
$where = ' "granularity" = ' . "'{$granularity}'" . ' and "date" = ' . "'{$date}' {$paramWhere}";
$where .= ' and "statTime" >= ' . "'{$dateData[$date]['start_time']}'" . ' and "statTime" <= ' . "'{$dateData[$date]['end_time']}'";
$list = $dm->select(
'bt_passenger_flow_all',
@ -294,11 +301,17 @@ class PassFlow
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function toDayGroupsEnterNum($dm = null)
public static function toDayGroupsEnterNum($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'];
@ -338,7 +351,7 @@ class PassFlow
}
/**
* 图书管数据接口
* 文化-博物-图书-数据接口 总计服务人数
* @return array
* 返回数据:today.incount=今天进 month.incount=本月进 year.incount=今年进 day30.incount=近30天近 outcount=出
* 不传参数就是所有摄像头,传cameraid就是按传的摄像头ID
@ -347,25 +360,56 @@ class PassFlow
public static function allFlowTrends($dm = null)
{
if (empty($dm)) $dm = new Dm();
# 宝安图书馆数据
$res = $dm->find('bt_library',['group_id' => 'lib001']);
$sum_month_incount = $month_incount = isset($res['month_incount']) ? $res['month_incount'] : 0;
$sum_today_incount = $today_incount = isset($res['today_incount']) ? $res['today_incount'] : 0;
$sum_year_incount = $year_incount = isset($res['year_incount']) ? $res['year_incount'] : 0;
# 劳务博物馆数据
$dateArr = ['day' => 'daily', 'month' => 'monthly', 'year' => 'yearly'];
$dateData = self::getDateData();
$museumData = [];
foreach ($dateArr as $date => $granularity) {
$museumWhere = ' "groupId"='."'510'".' and "granularity" = ' . "'{$granularity}'" . ' and "date" = ' . "'{$date}'";
$museumWhere .= ' and "statTime" >= ' . "'{$dateData[$date]['start_time']}'" . ' and "statTime" <= ' . "'{$dateData[$date]['end_time']}'";
$museumRes = $dm->find('bt_passenger_flow_all',$museumWhere,' SUM("noRepeatInNum") as num');
$museumData[$date] = $museumRes['NUM'] ?: 0;
}
$museum_today_incount = isset($museumData['day']) ? $museumData['day'] : 0;
$sum_today_incount += $museum_today_incount;
$museum_month_incount = isset($museumData['month']) ? $museumData['month'] : 0;
$sum_month_incount += $museum_month_incount;
$museum_year_incount = isset($museumData['year']) ? $museumData['year'] : 0;
$sum_year_incount += $museum_year_incount;
# 文化馆
$data = [
'day30' => [
'incount' => isset($res['day30_incount']) ? $res['day30_incount'] : 0,
'outcount' => isset($res['day30_outcount']) ? $res['day30_outcount'] : 0
],
'month' => [
'incount' => isset($res['month_incount']) ? $res['month_incount'] : 0,
'outcount' => isset($res['month_outcount']) ? $res['month_outcount'] : 0
'incount' => $sum_month_incount
],
'today' => [
'incount' => isset($res['today_incount']) ? $res['today_incount'] : 0,
'outcount' => isset($res['today_outcount']) ? $res['today_outcount'] : 0
'incount' => $sum_today_incount
],
'year' => [
'incount' => isset($res['year_incount']) ? $res['year_incount'] : 0,
'outcount' => isset($res['year_outcount']) ? $res['year_outcount'] : 0
'incount' => $sum_year_incount
],
'hour24' => [
[
'groupName' => '图书馆',
'incount' => $today_incount
],
[
'groupName' => '博物馆',
'incount' => $museum_today_incount
],
[
'groupName' => '文化馆',
'incount' => 0
],
]
];
return $data;

Loading…
Cancel
Save