From c28770ad2fe1f2d60d68ba22d667302f63e05bb8 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 27 Jul 2023 21:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=97=B6=E9=97=B4=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 111 ++++++++++++++----- 1 file changed, 83 insertions(+), 28 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index c341eaa..fbeafa5 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -13,50 +13,98 @@ class PassFlow * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public static function allGroupTimeNum($param,$dm = null) { + public static function allGroupTimeNum($param, $dm = null) + { $granularity = $param['granularity']; - $groupsId = $param['groupsId']; + $groupsId = $param['groupsId']; - if (empty($granularity)) return ['code' => 0,'msg' => '缺少参数:granularity']; + if (empty($granularity)) return ['code' => 0, 'msg' => '缺少参数:granularity']; $where = ''; - if(!empty($groupsId)){ - $garr = explode("|",$groupsId); - $where .= ' "groupId" in(' . "'" . implode("','",$garr) . "')"; + if (!empty($groupsId)) { + $garr = explode("|", $groupsId); + $where .= ' "groupId" in(' . "'" . implode("','", $garr) . "')"; } $allTimeData = []; - $groupsData = []; - $dkeys=[]; + $groupsData = []; + $dkeys = []; if (empty($dm)) $dm = new Dm(); if ($granularity == 'daily') { - $where .= $where ? ' and "granularity" = ' . "'hourly'" : ' "granularity" = ' . "'hourly'"; - $list = $dm->select('bt_passenger_flow',$where); - $data = self::handleGroupData($list); + $date = self::getDateData('day'); + $start_time = $date['day']['start_time']; + $end_time = $date['day']['end_time']; + $where .= $where ? ' and "granularity" = ' . "'hourly'" : ' "granularity" = ' . "'hourly'"; + $where .= ' and "statTime" >= ' . "'{$start_time}'" . ' and "statTime" <= ' . "'{$end_time}'"; + $list = $dm->select('bt_passenger_flow', $where); + $data = self::handleGroupData($list); $allTimeData = $data['allTimeData']; - $groupsData = $data['groupsData']; - $dkeys = $data['dkeys']; + $groupsData = $data['groupsData']; + $dkeys = $data['dkeys']; } elseif ($granularity == 'monthly') { - $where .= $where ? ' and "granularity" = ' . "'daily'" : ' "granularity" = ' . "'daily'"; - $list = $dm->select('bt_passenger_flow',$where); - $data = self::handleGroupData($list,'d'); + $date = self::getDateData('month'); + $start_time = $date['month']['start_time']; + $end_time = $date['month']['end_time']; + $where .= $where ? ' and "granularity" = ' . "'daily'" : ' "granularity" = ' . "'daily'"; + $where .= ' and "statTime" >= ' . "'{$start_time}'" . ' and "statTime" <= ' . "'{$end_time}'"; + $list = $dm->select('bt_passenger_flow', $where); + $data = self::handleGroupData($list, 'd'); $allTimeData = $data['allTimeData']; - $groupsData = $data['groupsData']; - $dkeys = $data['dkeys']; + $groupsData = $data['groupsData']; + $dkeys = $data['dkeys']; } elseif ($granularity == 'yearly') { - $where .= $where ? ' and "granularity" = ' . "'monthly'" : ' "granularity" = ' . "'monthly'"; - $list = $dm->select('bt_passenger_flow',$where); - $data = self::handleGroupData($list,'m'); + $date = self::getDateData('year'); + $start_time = $date['year']['start_time']; + $end_time = $date['year']['end_time']; + $where .= $where ? ' and "granularity" = ' . "'monthly'" : ' "granularity" = ' . "'monthly'"; + $where .= ' and "statTime" >= ' . "'{$start_time}'" . ' and "statTime" <= ' . "'{$end_time}'"; + $list = $dm->select('bt_passenger_flow', $where); + $data = self::handleGroupData($list, 'm'); $allTimeData = $data['allTimeData']; - $groupsData = $data['groupsData']; - $dkeys = $data['dkeys']; + $groupsData = $data['groupsData']; + $dkeys = $data['dkeys']; } - $data = ['allTimeData' => $allTimeData, 'groupsData' => $groupsData, 'dkeys' => $dkeys]; + $data = ['allTimeData' => $allTimeData, 'groupsData' => $groupsData, 'dkeys' => $dkeys]; return ['code' => 1, 'msg' => 'success', 'data' => $data]; } + /** + * 获取统计开始时间 统计结束时间 + * @param $date + * @return array + */ + protected static function getDateData($date = 'all') + { + $data = []; + if ($date == 'day' || $date == 'all') { + $data['day'] = [ + 'start_time' => date("Y-m-d") . 'T00:00:00.000+08:00', + 'end_time' => date("Y-m-d") . 'T23:59:59.000+08:00' + ]; + } + if ($date == 'week' || $date == 'all') { + $data['week'] = [ + 'start_time' => date("Y-m-d",strtotime("+".(date("w") - 7) . "day")) . 'T00:00:00.000+08:00', + 'end_time' => date("Y-m-d",strtotime("-".(date("w") - 7) . "day")) . 'T23:59:59.000+08:00' + ]; + } + if ($date == 'month' || $date == 'all') { + $data['month'] = [ + 'start_time' => date("Y-m-01") . 'T00:00:00.000+08:00', + 'end_time' => date("Y-m-d", strtotime('-1 day', strtotime(date('Y-m-01', strtotime('+1 month'))))) . 'T23:59:59.000+08:00' + ]; + } + if ($date == 'year' || $date == 'all') { + $data['year'] = [ + 'start_time' => date("Y-01-01") . 'T00:00:00.000+08:00', + 'end_time' => date("Y-m-d", strtotime('-1 day', strtotime(date('Y-01-01', strtotime('+1 year'))))) . 'T23:59:59.000+08:00' + ]; + } + return $data; + } + /** * 特殊处理 * @param $list @@ -141,11 +189,13 @@ class PassFlow # 总进馆人数 $yearSum = 0; if (empty($dm)) $dm = new Dm(); + $dateData = self::getDateData(); foreach ($dateArr as $date => $granularity) { - + $where = ' "granularity" = ' . "'{$granularity}'" . ' and "date" = ' . "'{$date}'"; + $where .= ' and "statTime" >= ' . "'{$dateData[$date]['start_time']}'" . ' and "statTime" <= ' . "'{$dateData[$date]['end_time']}'"; $list = $dm->select( 'bt_passenger_flow_all', - ' "granularity" = ' . "'{$granularity}'" . ' and "date" = ' . "'{$date}'" + $where ); $returnData[$date]['noRepeatInNum'] = 0; @@ -247,8 +297,13 @@ class PassFlow public static function toDayGroupsEnterNum($dm = null) { if (empty($dm)) $dm = new Dm(); - - $list = $dm->select('bt_passenger_flow',' "granularity"='."'hourly'"); + + $where = ' "granularity"='."'hourly' "; + $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 = 9; $i < 23; $i++) { $str = strlen($i) == 1 ? '0'.$i.':00' : $i.':00';