diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index d763231..89cc9d9 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -55,6 +55,7 @@ class Pass extends Controller $dm = new Dm(); foreach ($data as $val) { + // --------------------- 当天实时数据 --------------------- // $query = $dm->find('bt_library',['group_id' => $val['group_id']]); $opData = [ @@ -76,7 +77,7 @@ class Pass extends Controller $opData['create_time'] = date("Y-m-d H:i:s",time()); $dm->insert('bt_library',$opData); } - + // --------------------- END --------------------- // // --------------------- 小时数据 --------------------- // $hoursQueryWhere = ['hour_time' => $hour, 'group_id' => $val['group_id'], 'create_time' => ['>=',date('Y-m-d 00:00:00')]]; $hoursQuery = $dm->find("bt_library_hours",$hoursQueryWhere); @@ -107,8 +108,8 @@ class Pass extends Controller if ($lastHours) { $incount = $val['today_incount'] - $lastHours['target_today_incount']; $outcount = $val['today_outcount'] - $lastHours['target_today_outcount']; - $incount = $incount > 0 ? $incount : 0; - $outcount = $outcount > 0 ? $outcount : 0; + $incount = $incount > 0 ? $incount : 0; + $outcount = $outcount > 0 ? $outcount : 0; } # 创建数据 $insert = [ @@ -118,7 +119,7 @@ class Pass extends Controller 'outcount' => $outcount, 'target_today_incount' => $val['today_incount'], 'target_today_outcount' => $val['today_outcount'], - 'hour_time' => $hour, + 'hour_time' => $hour, 'create_time' => date("Y-m-d H:i:s",time()) ]; @@ -126,10 +127,79 @@ class Pass extends Controller } // --------------------- end --------------------- // + $this->saveLibraryData($dm,$val); } return $this->renderSuccess(); } + /** + * 日 月 年数据 收集 + * @param $dm + * @param $data + * @return void + */ + protected function saveLibraryData($dm,$data) + { + $arr = [ + 'day' => [ + 'create_time' => date('Y-m-d 00:00:00'), + 'incount' => $data['today_incount'], + 'outcount' => $data['today_outcount'] + ], + 'month' => [ + 'create_time' => date('Y-m-01 00:00:00'), + 'incount' => $data['month_incount'], + 'outcount' => $data['month_outcount'] + ], + 'year' => [ + 'create_time' => date('Y-01-01 00:00:00'), + 'incount' => $data['year_incount'], + 'outcount' => $data['year_outcount'] + ], + ]; + $group_id = $data['group_id']; + $group_name = base64_decode($data['group_name']); + foreach ($arr as $date => $value) { + + $incount = $value['incount']; + $outcount = $value['outcount']; + $create_time = $value['create_time']; + + $queryWhere = ['date' => $date, 'group_id' => $group_id, 'create_time' => ['>=',$create_time]]; + $query = $dm->find("bt_library_data",$queryWhere); + + if ($query) { + + # 存在的数量 + (这次天数数量 - 上次天数数量) = 当前小时数量 + $incount = $query['incount'] + ($incount - $query['last_incount']); + $outcount = $query['outcount'] + ($outcount - $query['last_outcount']); + + $update = [ + 'incount' => $incount, + 'outcount' => $outcount, + 'last_incount' => $incount, + 'last_outcount' => $outcount, + 'update_time' => date("Y-m-d H:i:s",time()) + ]; + $dm->update('bt_library_data',$update,['id' => $query['id']]); + } else { + + # 创建数据 + $insert = [ + 'group_id' => $group_id, + 'group_name' => $group_name, + 'incount' => $incount, + 'outcount' => $outcount, + 'last_incount' => $incount, + 'last_outcount' => $outcount, + 'date' => $date, + 'create_time' => date("Y-m-d H:i:s",time()) + ]; + $dm->insert("bt_library_data",$insert); + } + } + } + /** * 文化 - 24小时 柱状图 数据 * @return array diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 8df8df9..3419ec7 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -261,19 +261,19 @@ class PassFlow $sumFind = $dm->find('bt_passenger_flow_all', $sumWhere,'SUM("flowInNum") as NUM'); $returnData['sumYear']['noRepeatInNum'] = isset($sumFind['NUM']) ? $sumFind['NUM'] : 0; - if (empty($groupsId)) { - # 文化数据 - $mData = $dm->find('bt_library',['group_id' => 'lib001']); + if (empty($groupsId)) { + # 文化数据 + $mData = $dm->find('bt_library',['group_id' => 'lib001']); $returnData['day']['noRepeatInNum'] += isset($mData['today_incount']) ? $mData['today_incount'] : 0; $returnData['month']['noRepeatInNum'] += isset($mData['month_incount']) ? $mData['month_incount'] : 0; $returnData['year']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; - $returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; - $week_start = date("Y-m-d 00:00:00",strtotime('this week')); - $week_end = date("Y-m-d 23:59:59",strtotime("-".(date("w") - 7) . "day")); - $weekDateWhere = ' "group_id" =' . "'lib001'" . ' and "create_time" >= ' . "'{$week_start}'" . ' and "create_time" <= ' . "'{$week_end}'"; - $weekDate = $dm->find('bt_library_hours',$weekDateWhere,'SUM("incount") as NUM'); - $returnData['week']['noRepeatInNum'] += isset($weekDate['NUM']) ? $weekDate['NUM'] : 0; - } + $returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; + $week_start = date("Y-m-d 00:00:00",strtotime('this week')); + $week_end = date("Y-m-d 23:59:59",strtotime("-".(date("w") - 7) . "day")); + $weekDateWhere = ' "group_id" =' . "'lib001'" . ' and "create_time" >= ' . "'{$week_start}'" . ' and "create_time" <= ' . "'{$week_end}'"; + $weekDate = $dm->find('bt_library_hours',$weekDateWhere,'SUM("incount") as NUM'); + $returnData['week']['noRepeatInNum'] += isset($weekDate['NUM']) ? $weekDate['NUM'] : 0; + } foreach ($returnData as &$val) { $val['noRepeatInNum'] = formatNumber($val['noRepeatInNum']); } @@ -446,37 +446,43 @@ class PassFlow # 累计进馆人数 $sum_all_incount = 0; # 宝安图书馆数据 - $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_all_incount += $sum_year_incount = $year_incount = isset($res['year_incount']) ? $res['year_incount'] : 0; + $ts_res = $dm->find('bt_library',['group_id' => 'baz001']); + $ts_today_incount = isset($ts_res['today_incount']) ? $ts_res['today_incount'] : 0; + $ts_month_incount = isset($ts_res['month_incount']) ? $ts_res['month_incount'] : 0; + $ts_year_incount = isset($ts_res['year_incount']) ? $ts_res['year_incount'] : 0; # 劳务博物馆数据 $dateArr = ['day' => 'daily', 'month' => 'monthly', 'year' => 'yearly']; $dateData = self::getDateData(); - $museumData = []; + $bw_data = []; 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; + $bw_data[$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; + $bw_today_incount = isset($bw_data['day']) ? $bw_data['day'] : 0; + $bw_month_incount = isset($bw_data['month']) ? $bw_data['month'] : 0; + $bw_year_incount = isset($bw_data['year']) ? $bw_data['year'] : 0; - # 文化馆 - $res = $dm->find('bt_library',['group_id' => 'BAF055']); - $culture_today_count = isset($res['today_incount']) ? $res['today_incount'] : 0; + # 文化馆数据 + $wh_res = $dm->find('bt_library',['group_id' => 'BAF055']); + $wh_today_incount = isset($wh_res['today_incount']) ? $wh_res['today_incount'] : 0; + $wh_month_incount = isset($wh_res['month_incount']) ? $wh_res['month_incount'] : 0; + $wh_year_incount = isset($wh_res['year_incount']) ? $wh_res['year_incount'] : 0; - # 累计进馆人数 + # 总年、月、日总数 + $sum_today_incount = $ts_today_incount + $bw_today_incount + $wh_today_incount; + $sum_month_incount = $ts_month_incount + $bw_month_incount + $wh_month_incount; + $sum_year_incount = $ts_year_incount + $bw_year_incount + $wh_year_incount; + + # 累计进馆人数 - 博物馆 $sumAllWhere = ' "granularity" = ' . "'yearly'" . ' and "date" = ' . "'year' " . ' and "groupId"='."'510'"; $sumAllFind = $dm->find('bt_passenger_flow_all', $sumAllWhere,'SUM("flowInNum") as NUM'); $sum_all_incount += isset($sumAllFind['NUM']) ? $sumAllFind['NUM'] : 0; + # 累计进馆人数 - 文化、图书 + $sum_all_incount += $ts_year_incount + $wh_year_incount; $data = [ 'month' => [ @@ -494,15 +500,15 @@ class PassFlow 'hour24' => [ [ 'groupName' => '图书馆', - 'incount' => $today_incount + 'incount' => $ts_today_incount ], [ 'groupName' => '博物馆', - 'incount' => $museum_today_incount + 'incount' => $bw_today_incount ], [ 'groupName' => '文化馆', - 'incount' => $culture_today_count + 'incount' => $wh_today_incount ], ] ]; @@ -646,12 +652,12 @@ class PassFlow if (empty($dm)) $dm = new Dm(); # 获取文化组id -if ($is_group) { - $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 2],'"groupId","groupName"'); - $groupsId = []; - foreach ($groupRes as $groupRow) $groupsId[] = $groupRow['groupId']; - $data = self::toDayGroupsEnterNum($dm,['groupsId' => implode("|",$groupsId)]); -} + if ($is_group) { + $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 2],'"groupId","groupName"'); + $groupsId = []; + foreach ($groupRes as $groupRow) $groupsId[] = $groupRow['groupId']; + $data = self::toDayGroupsEnterNum($dm,['groupsId' => implode("|",$groupsId)]); + } # 图书、文化馆 $start_create_time = date("Y-m-d 00:00:00"); $end_create_time = date("Y-m-d 23:59:59");