From 66dbcab2db38321a11b30e235abf6a6d505f650c Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 1 Aug 2023 11:26:34 +0800 Subject: [PATCH 01/51] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=BA=BF=E4=B8=8A?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/library/Pass.php | 13 ++-- .../api/controller/pass/Create.php | 11 ++-- source/application/common/dm/Dm.php | 8 +-- source/application/common/logic/PassFlow.php | 65 ++++++++++--------- source/application/task/controller/Group.php | 16 ++++- .../application/task/controller/Passreal.php | 6 +- 6 files changed, 66 insertions(+), 53 deletions(-) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index b62cb70..d763231 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -78,7 +78,7 @@ class Pass extends Controller } // --------------------- 小时数据 --------------------- // - $hoursQueryWhere = ['hour_time' => $hour, 'group_id' => $val['group_id']]; + $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); # 默认单天数据 @@ -106,9 +106,9 @@ class Pass extends Controller $lastHours = $dm->find('bt_library_hours',$lastHoursWhere,'*','id DESC'); if ($lastHours) { $incount = $val['today_incount'] - $lastHours['target_today_incount']; - $incount = $incount > 0 ? $incount : 0; $outcount = $val['today_outcount'] - $lastHours['target_today_outcount']; - $outcount = $outcount > 0 ? $outcount : 0; + $incount = $incount > 0 ? $incount : 0; + $outcount = $outcount > 0 ? $outcount : 0; } # 创建数据 $insert = [ @@ -118,7 +118,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()) ]; @@ -189,7 +189,7 @@ class Pass extends Controller return $this->renderSuccess(); } - /** + /** * 获取今日借阅办证数据 * @return array */ @@ -198,4 +198,5 @@ class Pass extends Controller $data = PassFlow::getLibraryLeaseData(); return $this->renderSuccess(compact('data')); } -} \ No newline at end of file + +} diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index f9bb449..d84efce 100644 --- a/source/application/api/controller/pass/Create.php +++ b/source/application/api/controller/pass/Create.php @@ -62,9 +62,10 @@ class Create extends Controller $queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime']]; $query = $dm->find('bt_passenger_flow',$queryWhere); + + $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); + $groupName = isset($groupRes['groupName']) ? $groupRes['groupName']:$val['groupName']; - $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); - $groupName = isset($groupRes['groupName']) ? $groupRes['groupName'] : $val['groupName']; $insert_arr = [ 'groupId' => $val['groupId'], 'groupName' => $groupName, @@ -108,11 +109,11 @@ class Create extends Controller $dm = new Dm(); foreach ($data as $val) { - $queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime']]; + $queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime'],'date'=>$val['date']]; $query = $dm->find('bt_passenger_flow_all',$queryWhere); $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); - $groupName = isset($groupRes['groupName']) ? $groupRes['groupName'] : $val['groupName']; + $groupName = isset($groupRes['groupName']) ? $groupRes['groupName']:$val['groupName']; $insert_arr = [ 'groupId' => $val['groupId'], @@ -246,4 +247,4 @@ class Create extends Controller } -} \ No newline at end of file +} diff --git a/source/application/common/dm/Dm.php b/source/application/common/dm/Dm.php index aac5889..7a48274 100644 --- a/source/application/common/dm/Dm.php +++ b/source/application/common/dm/Dm.php @@ -4,12 +4,6 @@ namespace app\common\dm; class Dm { - private $host = 'localhost:5236'; // IP 地址 - private $port = '5236'; // 端口号 - private $dbname = 'CXK'; // 数据库名 - private $username = 'SYSDBA'; // 用户名 - private $password = 'SYSDBA'; // 密码 - private $charset = 'GBK'; // 字符集 public $conn; public $database = 'STADIUM'; @@ -319,4 +313,4 @@ class Dm 'pageData' => $pageData, ]; } -} \ No newline at end of file +} diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index d9499aa..8df8df9 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -86,7 +86,7 @@ class PassFlow } if ($date == 'week' || $date == 'all') { $data['week'] = [ - 'start_time' => date("Y-m-d",strtotime('this week')) . 'T00:00:00.000+08:00', + 'start_time' => date("Y-m-d",strtotime("this week")) . 'T00:00:00.000+08:00', 'end_time' => date("Y-m-d",strtotime("-".(date("w") - 7) . "day")) . 'T23:59:59.000+08:00' ]; } @@ -116,7 +116,7 @@ class PassFlow $groupsData = []; $dkey=[]; if ($date_str == 'H:00') { - $hour = (int)date("H"); + $hour = (int) date('H'); for ($i = 0; $i <= $hour; $i++) { $str = strlen($i) == 1 ? '0'.$i.':00' : $i.':00'; $allTimeData[$str]['num'] = 0; @@ -261,20 +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($param['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']); } @@ -306,7 +305,7 @@ class PassFlow $returnData = []; foreach ($data as $groupId => $val) { - $proportion = $val['allEnter'] > 0 ? round($val['allEnter']/$threshold,2) : 0; + $proportion = $val['allEnter'] > 0 ? round($val['allEnter']/$threshold,4) : 0; $val['proportion'] = ($proportion * 100) . "%"; $val['congestion'] = self::getPassType($proportion); $val['groupId'] = $groupId; @@ -318,7 +317,7 @@ class PassFlow } $libData = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); foreach ($libData as $libRow) { - $libProportion = $libRow['today_incount'] > 0 ? round($libRow['today_incount']/$threshold,2) : 0; + $libProportion = $libRow['today_incount'] > 0 ? round($libRow['today_incount']/$threshold,4) : 0; // 文化馆排 4# 图书馆 2# $isort = $libRow['group_id']=='baz001'?2:4; $returnData[] = [ @@ -397,15 +396,15 @@ class PassFlow $groupData = $dm->select('bt_passenger_monitor_group',$groupsWhere); foreach ($groupData as $groupDataRow) { foreach ($allTimeData as $date => $dateValue) { - $returnData[$groupDataRow['groupName']][$date] = $dateValue; + $returnData[$groupDataRow['groupId']][$date] = $dateValue; } } foreach ($list as $value) { $date = date('H:00',ceil($value['createTime'] / 1000)); // 各时间端进馆人数 if (!isset($allTimeData[$date])) continue; - if (!isset($returnData[$value['groupName']][$allTimeData[$date]])) $returnData[$value['groupName']][$date] = 0; - $returnData[$value['groupName']][$date] += $value['flowInNum']; + if (!isset($returnData[$value['groupId']][$allTimeData[$date]])) $returnData[$value['groupId']][$date] = 0; + $returnData[$value['groupId']][$date] += $value['flowInNum']; } $data = []; @@ -419,13 +418,18 @@ class PassFlow $listData['dkeys'][] = $itemKey; $listData['dvalue'][] = $itemRow; } + if (is_numeric($groupName)) { + $groupData = $dm->find('bt_passenger_monitor_group',['groupId' => $groupName]); + $groupName = isset($groupData['groupName']) ? $groupData['groupName'] : $groupName; + } $data[] = [ 'groupName' => $groupName, 'list' => $listData ]; } - $data = self::getLibraryGroupHoursList($dm,false,$data); - + if(empty($param['groupsId'])){ + $data = self::getLibraryGroupHoursList($dm,false,$data); + } return $data; } @@ -642,13 +646,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"); @@ -709,10 +712,12 @@ class PassFlow 'returncount' => 0 ]; if ($LibLeaseRes) { - $data['newreader'] = $LibLeaseRes['newreader']; # 今日办证人数 - $data['servcount'] = $LibLeaseRes['servcount']; # 今日借书册数 + $data['newreader'] = $LibLeaseRes['newreader']; # 今日办证册数 + $data['servcount'] = $LibLeaseRes['servcount']; # 今日借书人数 $data['returncount'] = $LibLeaseRes['returncount']; # 今日还书册数 } return $data; } -} \ No newline at end of file + + +} diff --git a/source/application/task/controller/Group.php b/source/application/task/controller/Group.php index d607f81..d51c6ab 100644 --- a/source/application/task/controller/Group.php +++ b/source/application/task/controller/Group.php @@ -7,7 +7,19 @@ use app\common\model\Pass; class Group { - function run() + public function run(){ + $link = dm_connect('10.97.121.4:5236','SYSDBA','Hn@dameng123') or die('err'.dm_error()); +$sql='select * from "STADIUM"."bt_config"'; +$res = dm_exec($link,$sql); +$data = []; +while ($row = dm_fetch_array($res)) { + $data=$row; +} +var_dump($data); +dm_close($link); + } + + function runbak() { $config = config('api_config'); @@ -80,4 +92,4 @@ class Group return true; } -} \ No newline at end of file +} diff --git a/source/application/task/controller/Passreal.php b/source/application/task/controller/Passreal.php index 796987a..a300ad5 100644 --- a/source/application/task/controller/Passreal.php +++ b/source/application/task/controller/Passreal.php @@ -40,18 +40,18 @@ class Passreal 'statisticsTime' => $value['statisticsTime'], 'enter' => $value['enter'], 'exit' => $value['exit'], - 'pass' => $value['pass'] ?: '', + 'pass' => $value['pass'], 'holdValue' => $value['holdValue'], 'allEnter' => $value['allEnter'], 'allExit' => $value['allExit'] ]; - #Db::table('bt_passenger_flow_real')->insert($insert_arr); + Db::table('bt_passenger_flow_real')->insert($insert_arr); $requestData[] = $insert_arr; } } catch (\Exception $e) { - return $e->getMessage(); + exit( $e->getMessage() ); } $requestRes = \app\common\model\Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowReal', $config['host_path']); From 387cf2869e3c9724fccd8aa92bd3cfd1004aba36 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 1 Aug 2023 14:54:01 +0800 Subject: [PATCH 02/51] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E6=A8=A1?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9B=BE=E4=B9=A6=EF=BC=8C=E6=96=87=E5=8C=96=E9=A6=86=E6=97=A5?= =?UTF-8?q?=E6=9C=88=E5=B9=B4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/library/Pass.php | 78 ++++++++++++++++++- source/application/common/logic/PassFlow.php | 76 +++++++++--------- 2 files changed, 115 insertions(+), 39 deletions(-) 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"); From 16a282a3adb076ff4287a1fe3cba9cef472cc86e Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 1 Aug 2023 15:20:44 +0800 Subject: [PATCH 03/51] =?UTF-8?q?=E6=B8=85=E7=A9=BA=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/xtool/Xtool.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 source/application/api/controller/xtool/Xtool.php diff --git a/source/application/api/controller/xtool/Xtool.php b/source/application/api/controller/xtool/Xtool.php new file mode 100644 index 0000000..72edb4c --- /dev/null +++ b/source/application/api/controller/xtool/Xtool.php @@ -0,0 +1,35 @@ +request->param('dname'); + //return $dbname; + $dm = new Dm; + $dm->truncate($dbname); + return $this->success(); + + //$dm->truncate('bt_passenger_flow'); + // + //$dm->truncate('bt_passenger_flow_all'); + // + //$dm->truncate('bt_passenger_monitor_group'); + // + //$dm->truncate('bt_video'); + } + } + + // + public function sc(){ + $dm = new Dm; + $dm->insert('bt_config',['key'=>'threshold','value'=>'10000']); + $this->renderSuccess(); + } +} From 5955d7938dba9ad220da6939acdee826701ec102 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 1 Aug 2023 18:58:37 +0800 Subject: [PATCH 04/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 25 ++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 3419ec7..cb5514b 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -116,7 +116,7 @@ class PassFlow $groupsData = []; $dkey=[]; if ($date_str == 'H:00') { - $hour = (int) date('H'); + $hour = (int) date('H'); for ($i = 0; $i <= $hour; $i++) { $str = strlen($i) == 1 ? '0'.$i.':00' : $i.':00'; $allTimeData[$str]['num'] = 0; @@ -142,6 +142,7 @@ class PassFlow $dkey[]=$str; } } + # 体育 + 博物馆客流柱状图数据 $sumNoRepeatInNum = 0; $groupsIdArr = []; foreach ($list as $value) { @@ -156,6 +157,7 @@ class PassFlow ksort($allTimeData); $groupsIdParamArr = []; + # 总览-合并文化数据 if (empty($groupsId)) { $res = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); foreach ($res as $row) { @@ -170,6 +172,20 @@ class PassFlow $groupsData[$row['group_name']]['noRepeatInNum'] = $row['year_incount']; } } + $whgData = []; + if ($date_str == 'H:00') { + $whgData = $dm->select('bt_library_hours',['create_time' => ['>=',date("Y-m-d 00:00:00")],'group_id' => 'lib001']); + } elseif ($date_str == 'd') { + $whgData = $dm->select('bt_library_data',['create_time' => ['>=',date("Y-m-01 00:00:00")],'group_id' => 'lib001','date' => 'day']); + } elseif ($date_str == 'm') { + $whgData = $dm->select('bt_library_data',['create_time' => ['>=',date("Y-01-01 00:00:00")],'group_id' => 'lib001','date' => 'month']); + } + # 文化馆客流柱状图数据 + foreach ($whgData as $whgRow) { + $date = date($date_str,strtotime($whgRow['create_time'])); // 各时间端进馆人数 + if (!isset($allTimeData[$date])) continue; + $allTimeData[$date]['num'] += $whgRow['incount']; + } } else { $groupsIdParamArr = explode("|",$groupsId); } @@ -482,7 +498,8 @@ class PassFlow $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; + $libData = $dm->find('bt_library_data',['group_id' => 'lib001','date' => 'year'],' SUM("incount") as SUM'); + $sum_all_incount += $libData ? $libData['SUM'] : 0; $data = [ 'month' => [ @@ -614,14 +631,14 @@ class PassFlow if (!isset($returnData[$str])) $returnData[$str] = 0; } foreach ($list as $value) { - $date = date('H:00',strtotime($value['statTime'])); // 各时间端进馆人数 + $date = date('H:00',ceil($value['createTime'] / 1000)); // 各时间端进馆人数 if (!isset($allTimeData[$date])) continue; $returnData[$date] += $value['flowInNum']; } # 图书、文化馆 $start_create_time = date("Y-m-d H:00:00",strtotime('-23 hours')); $end_create_time = date("Y-m-d H:59:59"); - $hoursWhere = ' "group_id" = ' . "'lib001'" . ' and "create_time" >= ' . "'{$start_create_time}'" + $hoursWhere = ' "group_id" in (' . "'lib001','BAF055')" . ' and "create_time" >= ' . "'{$start_create_time}'" . ' and "create_time" <= ' . "'{$end_create_time}'" ; $hoursRes = $dm->select('bt_library_hours',$hoursWhere); foreach ($hoursRes as $hoursRow) { From 870022fa501390296779ca99b2f22d4abc2f6740 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 1 Aug 2023 19:48:30 +0800 Subject: [PATCH 05/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index cb5514b..3ea6c94 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -475,7 +475,7 @@ class PassFlow $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'); + $museumRes = $dm->find('bt_passenger_flow_all',$museumWhere,' SUM("flowInNum") as NUM'); $bw_data[$date] = $museumRes['NUM'] ?: 0; } $bw_today_incount = isset($bw_data['day']) ? $bw_data['day'] : 0; @@ -638,7 +638,7 @@ class PassFlow # 图书、文化馆 $start_create_time = date("Y-m-d H:00:00",strtotime('-23 hours')); $end_create_time = date("Y-m-d H:59:59"); - $hoursWhere = ' "group_id" in (' . "'lib001','BAF055')" . ' and "create_time" >= ' . "'{$start_create_time}'" + $hoursWhere = ' "group_id" in (' . "'baz001','BAF055')" . ' and "create_time" >= ' . "'{$start_create_time}'" . ' and "create_time" <= ' . "'{$end_create_time}'" ; $hoursRes = $dm->select('bt_library_hours',$hoursWhere); foreach ($hoursRes as $hoursRow) { @@ -699,7 +699,7 @@ class PassFlow foreach ($hoursRes as $hoursRow) { $date = $hoursRow['hour_time']; // 各时间端进馆人数 if (!isset($allTimeData[$date])) continue; - if (!isset($returnData[$hoursRow['group_name']][$allTimeData[$date]])) $returnData[$hoursRow['group_name']][$date] = 0; + if (!isset($returnData[$hoursRow['group_name']][$date])) $returnData[$hoursRow['group_name']][$date] = 0; $returnData[$hoursRow['group_name']][$date] += $hoursRow['incount']; } From 6621900d6150a9f9da01fff03c8ad38d0cbdf3c0 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 2 Aug 2023 09:09:14 +0800 Subject: [PATCH 06/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 3ea6c94..5c76846 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -473,9 +473,9 @@ class PassFlow $bw_data = []; foreach ($dateArr as $date => $granularity) { - $museumWhere = ' "groupId"='."'510'".' and "granularity" = ' . "'{$granularity}'" . ' and "date" = ' . "'{$date}'"; + $museumWhere = ' "groupId"='."'510'".' and "granularity" = ' . "'{$granularity}'" ; $museumWhere .= ' and "statTime" >= ' . "'{$dateData[$date]['start_time']}'" . ' and "statTime" <= ' . "'{$dateData[$date]['end_time']}'"; - $museumRes = $dm->find('bt_passenger_flow_all',$museumWhere,' SUM("flowInNum") as NUM'); + $museumRes = $dm->find('bt_passenger_flow',$museumWhere,' SUM("flowInNum") as NUM'); $bw_data[$date] = $museumRes['NUM'] ?: 0; } $bw_today_incount = isset($bw_data['day']) ? $bw_data['day'] : 0; From 2e19fc84e053d10fe8739607794a2074a189514f Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 2 Aug 2023 10:42:37 +0800 Subject: [PATCH 07/51] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E3=80=82=E8=AF=B7=E6=B1=82=E9=99=90=E5=88=B6=EF=BC=8C=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/api/controller/Controller.php | 47 +++++++++++++++---- .../api/controller/library/Pass.php | 2 + .../api/controller/pass/Create.php | 30 ++---------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/source/application/api/controller/Controller.php b/source/application/api/controller/Controller.php index 79dd99e..339ab51 100644 --- a/source/application/api/controller/Controller.php +++ b/source/application/api/controller/Controller.php @@ -15,6 +15,7 @@ class Controller extends \think\Controller { const JSON_SUCCESS_STATUS = 1; const JSON_ERROR_STATUS = 0; + protected $token = '9c4cb25665cf08667c815420ab383cb5'; /* @ver $wxapp_id 小程序id */ // protected $wxapp_id; @@ -26,20 +27,46 @@ class Controller extends \think\Controller */ public function _initialize() { + /* $config = config('api_config'); -// foreach ($config['access_control_allow_origin'] as $value) { -// header("Access-Control-Allow-Origin: ".$value); -// } - header("Access-Control-Allow-Origin: http://192.168.66.254:8080"); - header("Access-Control-Allow-Origin: http://192.168.66.254:8081"); - #header("Access-Control-Allow-Origin: *"); + foreach ($config['access_control_allow_origin'] as $value) { + header("Access-Control-Allow-Origin: ".$value); + } + + header("Access-Control-Allow-Origin:*"); header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE"); header("Access-Control-Allow-Headers: Content-Type"); header("Access-Control-Allow-Credentials: true"); - // 当前小程序id -// $this->wxapp_id = $this->getWxappId(); -// // 验证当前小程序状态 -// $this->checkWxapp(); + */ + } + + /** + * 获取请求token + * @return mixed + * @throws BaseException + */ + protected function validateToken() + { + $signature = $this->request->param('signature'); + + if (empty($signature)) { + throw new BaseException(['msg' => '缺少必要的参数:signature']); + } else { + $data = $this->request->param('data'); + $encrypt = $this->request->param('encrypt'); + $date = (int)date("d"); + $new_signature = md5($this->token . ($date % 2) . md5($data)); + if ($new_signature !== $signature) { + throw new BaseException(['msg' => '数据校验失败']); + } + if (empty($data)) { + throw new BaseException('缺少必要参数:data'); + } + $data_json = $encrypt ? $data : base64_decode($data); + $dataArr = json_decode(html_entity_decode($data_json),true); + if (empty($dataArr)) throw new BaseException('data参数不能为空'); + if (!is_array($dataArr)) throw new BaseException('data参数类型错误'); + } } /** diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 89cc9d9..6e20e3f 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -46,6 +46,7 @@ class Pass extends Controller */ public function create() { + $this->validateToken(); $data_json = $this->request->param('data'); $data = json_decode(html_entity_decode($data_json),true); @@ -229,6 +230,7 @@ class Pass extends Controller */ public function createLibraryLease() { + $this->validateToken(); $data_json = $this->request->param('data'); $data = json_decode(html_entity_decode($data_json),true); diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index d84efce..9a88448 100644 --- a/source/application/api/controller/pass/Create.php +++ b/source/application/api/controller/pass/Create.php @@ -19,32 +19,8 @@ class Create extends Controller */ public function _initialize() { - // $this->getToken(); + $this->validateToken(); } - - /** - * 获取请求token - * @return mixed - * @throws BaseException - */ - private function getToken() - { - if (!$token = $this->request->param('token')) { - throw new BaseException(['msg' => '缺少必要的参数:token']); - } - $validateToken = md5($this->token . date('Ymd')); - if ($validateToken != $token) { - throw new BaseException(['msg' => '错误参数:token']); - } - if (!$data = $this->request->param('data')) { - throw new BaseException(['msg' => '缺少必要的参数:data']); - } else { - $data = json_decode(html_entity_decode(base64_decode($data)),true); - if (empty($data)) throw new BaseException(['msg' => '参数为空:data']); - if (!is_array($data)) throw new BaseException(['msg' => '数据有误:data']); - } - } - /** * 创建客流统计数据 * @return array @@ -63,8 +39,8 @@ class Create extends Controller $queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime']]; $query = $dm->find('bt_passenger_flow',$queryWhere); - $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); - $groupName = isset($groupRes['groupName']) ? $groupRes['groupName']:$val['groupName']; + $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); + $groupName = isset($groupRes['groupName']) ? $groupRes['groupName']:$val['groupName']; $insert_arr = [ 'groupId' => $val['groupId'], From bda0ecadc5d52eac888ec65d6a4b32ac179b6f7f Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 2 Aug 2023 14:17:41 +0800 Subject: [PATCH 08/51] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E5=B1=95=E7=A4=BA=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 5c76846..74c9d47 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -161,15 +161,16 @@ class PassFlow if (empty($groupsId)) { $res = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); foreach ($res as $row) { + if (!isset($groupsData[$row['group_name']]['noRepeatInNum'])) $groupsData[$row['group_name']]['noRepeatInNum'] = 0; if ($date_str == 'H:00') { $sumNoRepeatInNum += $row['today_incount']; - $groupsData[$row['group_name']]['noRepeatInNum'] = $row['today_incount']; + $groupsData[$row['group_name']]['noRepeatInNum'] = $row['today_incount']?:0; } elseif ($date_str == 'd') { $sumNoRepeatInNum += $row['month_incount']; - $groupsData[$row['group_name']]['noRepeatInNum'] = $row['month_incount']; + $groupsData[$row['group_name']]['noRepeatInNum'] = $row['month_incount']?:0; } elseif ($date_str == 'm') { $sumNoRepeatInNum += $row['year_incount']; - $groupsData[$row['group_name']]['noRepeatInNum'] = $row['year_incount']; + $groupsData[$row['group_name']]['noRepeatInNum'] = $row['year_incount']?:0; } } $whgData = []; From 68ee60ef3a652c839348dce9a373dca2174ff3c1 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 2 Aug 2023 15:28:50 +0800 Subject: [PATCH 09/51] =?UTF-8?q?ws=E8=87=AA=E5=8A=A8=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ws_task_real.php | 35 ++++++++++++++++++++------ web/ws_task_real_ty.php | 54 +++++++++++++++++++++++++++++++++++++++++ web/ws_task_real_wh.php | 46 +++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 web/ws_task_real_ty.php create mode 100644 web/ws_task_real_wh.php diff --git a/web/ws_task_real.php b/web/ws_task_real.php index b9271db..ac75391 100644 --- a/web/ws_task_real.php +++ b/web/ws_task_real.php @@ -1,5 +1,7 @@ count = 4; // 进程启动后定时推送数据给客户端 $worker->onWorkerStart = function($worker) use($config) { @@ -22,12 +24,29 @@ $worker->onWorkerStart = function($worker) use($config) { $time_interval = 3; Timer::add($time_interval, function()use($worker,$dm){ foreach($worker->connections as $connection) { - $data = []; - $passData = PassFlow::realTimeData($dm); - $returnData = ['data' => $passData]; - $data['realTimeData'] = $returnData; - $toDayGroupsEnterNum = PassFlow::toDayGroupsEnterNum($dm); - $data['toDayGroupsEnterNum'] = $toDayGroupsEnterNum; + + $data = [ + 'code' => 1, + 'msg' => 'success' + ]; + + # 客流趋势 与 占比 + $allGroupTimeNumDay = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'daily'],$dm); + $allGroupTimeNumMonth = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'monthly'],$dm); + $allGroupTimeNumYear = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'yearly'],$dm); + $data['allGroupTimeNumDay'] = ['data' => $allGroupTimeNumDay]; + $data['allGroupTimeNumMonth'] = ['data' => $allGroupTimeNumMonth]; + $data['allGroupTimeNumYear'] = ['data' => $allGroupTimeNumYear]; + + # 今日各场馆 + $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm)]; + + # 中间总数据 + $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm)]; + + # 各场馆实时 + $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; + $connection->send(json_encode($data)); } }); diff --git a/web/ws_task_real_ty.php b/web/ws_task_real_ty.php new file mode 100644 index 0000000..a2d8fa0 --- /dev/null +++ b/web/ws_task_real_ty.php @@ -0,0 +1,54 @@ +count = 4; +// 进程启动后定时推送数据给客户端 +$worker->onWorkerStart = function($worker) use($config) { + # 数据库链接不能在主进程,方法外是主进程 + $dm = new Dm($config['connections']['dm']); + // 每2.5秒执行一次 + $time_interval = 3; + Timer::add($time_interval, function()use($worker,$dm){ + foreach($worker->connections as $connection) { + $data = []; + # 主动推送对应页面数据 + + $groupIdArr = []; + $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 1]); + foreach ($groupRes as $groupRow) $groupIdArr[] = $groupRow['groupId']; + $groupIdStr = !empty($groupIdArr) ? implode("|",$groupIdArr) : ''; + + # 累计服务人数 + $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm,['groupsId' => $groupIdStr])]; + + # 24小时 + $data['getPassHoursData'] = ['data' => PassFlow::getPassHoursData($dm,['groupsId' => $groupIdStr])]; + + # 24小时进馆人数 + $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; + + # 各场馆服务人次占比 + $data['allGroupTimeNum'] = ['data' => PassFlow::allGroupTimeNum(['groupsId' => $groupIdStr,'granularity' => 'daily'],$dm)]; + + # 各场馆服务人次趋势 + $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm,['groupsId' => $groupIdStr])]; + + $connection->send(json_encode($data)); + } + }); +}; +Worker::runAll(); \ No newline at end of file diff --git a/web/ws_task_real_wh.php b/web/ws_task_real_wh.php new file mode 100644 index 0000000..7269de5 --- /dev/null +++ b/web/ws_task_real_wh.php @@ -0,0 +1,46 @@ +count = 4; +// 进程启动后定时推送数据给客户端 +$worker->onWorkerStart = function($worker) use($config) { + # 数据库链接不能在主进程,方法外是主进程 + $dm = new Dm($config['connections']['dm']); + // 每2.5秒执行一次 + $time_interval = 3; + Timer::add($time_interval, function()use($worker,$dm){ + foreach($worker->connections as $connection) { + $data = []; + # 主动推送对应页面数据 + + # 累计服务人数 - 24小时服务人次 + $data['allFlowTrends'] = ['data' => PassFlow::allFlowTrends($dm)]; + + # 24小时总服务人次趋势 + $data['getLibraryHours24List'] = ['data' => PassFlow::getLibraryHours24List($dm)]; + + # 各场馆服务人次趋势 + $data['getLibraryGroupHoursList'] = ['data' => PassFlow::getLibraryGroupHoursList($dm)]; + + # 图书馆数据统计 + $data['getLibraryLeaseData'] = ['data' => PassFlow::getLibraryLeaseData($dm)]; + + $connection->send(json_encode($data)); + } + }); +}; +Worker::runAll(); \ No newline at end of file From 39159c1cd7f98ae03e3d1c30441136152f3e69fa Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 3 Aug 2023 15:00:41 +0800 Subject: [PATCH 10/51] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/library/Pass.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 6e20e3f..6e5cb30 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -106,9 +106,9 @@ class Pass extends Controller # 查看该组是否存在上一条数据 $lastHoursWhere = ['hour_time' => $last_hour, 'group_id' => $val['group_id']]; $lastHours = $dm->find('bt_library_hours',$lastHoursWhere,'*','id DESC'); - if ($lastHours) { - $incount = $val['today_incount'] - $lastHours['target_today_incount']; - $outcount = $val['today_outcount'] - $lastHours['target_today_outcount']; + if ($lastHours && $hour != '00:00') { + $incount = (int)($val['today_incount'] - $lastHours['target_today_incount']); + $outcount = (int)($val['today_outcount'] - $lastHours['target_today_outcount']); $incount = $incount > 0 ? $incount : 0; $outcount = $outcount > 0 ? $outcount : 0; } @@ -178,8 +178,8 @@ class Pass extends Controller $update = [ 'incount' => $incount, 'outcount' => $outcount, - 'last_incount' => $incount, - 'last_outcount' => $outcount, + 'last_incount' => $value['incount'], + 'last_outcount' => $value['outcount'], 'update_time' => date("Y-m-d H:i:s",time()) ]; $dm->update('bt_library_data',$update,['id' => $query['id']]); From d5b670d2cd89b3d0e03d6488416fc03c9af25846 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 3 Aug 2023 15:05:50 +0800 Subject: [PATCH 11/51] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/library/Pass.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 6e5cb30..c5f4eff 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -55,6 +55,14 @@ class Pass extends Controller $last_hour = date("H:00",strtotime('-1 hour')); $dm = new Dm(); foreach ($data as $val) { + $val['day30_incount'] = $val['day30_incount'] ?: 0; + $val['day30_outcount'] = $val['day30_outcount'] ?: 0; + $val['today_incount'] = $val['today_incount'] ?: 0; + $val['today_outcount'] = $val['today_outcount'] ?: 0; + $val['month_incount'] = $val['month_incount'] ?: 0; + $val['month_outcount'] = $val['month_outcount'] ?: 0; + $val['year_incount'] = $val['year_incount'] ?: 0; + $val['year_outcount'] = $val['year_outcount'] ?: 0; // --------------------- 当天实时数据 --------------------- // $query = $dm->find('bt_library',['group_id' => $val['group_id']]); From 17bfb171770202a6ee52c3ba2d494eee02523f9c Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 3 Aug 2023 17:08:35 +0800 Subject: [PATCH 12/51] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/Controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/source/application/api/controller/Controller.php b/source/application/api/controller/Controller.php index 339ab51..50cb1a6 100644 --- a/source/application/api/controller/Controller.php +++ b/source/application/api/controller/Controller.php @@ -55,6 +55,7 @@ class Controller extends \think\Controller $data = $this->request->param('data'); $encrypt = $this->request->param('encrypt'); $date = (int)date("d"); + $data = $encrypt ? html_entity_decode($data) : $data; $new_signature = md5($this->token . ($date % 2) . md5($data)); if ($new_signature !== $signature) { throw new BaseException(['msg' => '数据校验失败']); From e4971bd88825e16aa59047dd7f9ea5cd9874c487 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 7 Aug 2023 16:30:34 +0800 Subject: [PATCH 13/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E9=A6=86=EF=BC=8C=E6=96=87=E5=8C=96=E9=A6=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/library/Pass.php | 113 ++++++++---------- 1 file changed, 50 insertions(+), 63 deletions(-) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index c5f4eff..5b8babf 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -51,31 +51,30 @@ class Pass extends Controller $data_json = $this->request->param('data'); $data = json_decode(html_entity_decode($data_json),true); - $hour = date("H:00"); - $last_hour = date("H:00",strtotime('-1 hour')); $dm = new Dm(); foreach ($data as $val) { - $val['day30_incount'] = $val['day30_incount'] ?: 0; - $val['day30_outcount'] = $val['day30_outcount'] ?: 0; - $val['today_incount'] = $val['today_incount'] ?: 0; - $val['today_outcount'] = $val['today_outcount'] ?: 0; - $val['month_incount'] = $val['month_incount'] ?: 0; - $val['month_outcount'] = $val['month_outcount'] ?: 0; - $val['year_incount'] = $val['year_incount'] ?: 0; - $val['year_outcount'] = $val['year_outcount'] ?: 0; + + $val['day30_incount'] = $val['day30_incount'] ?: 0; + $val['day30_outcount'] = $val['day30_outcount'] ?: 0; + $val['today_incount'] = $val['today_incount'] ?: 0; + $val['today_outcount'] = $val['today_outcount'] ?: 0; + $val['month_incount'] = $val['month_incount'] ?: 0; + $val['month_outcount'] = $val['month_outcount'] ?: 0; + $val['year_incount'] = $val['year_incount'] ?: 0; + $val['year_outcount'] = $val['year_outcount'] ?: 0; // --------------------- 当天实时数据 --------------------- // $query = $dm->find('bt_library',['group_id' => $val['group_id']]); $opData = [ - 'day30_incount' => $val['day30_incount'], - 'day30_outcount' => $val['day30_outcount'], - 'today_incount' => $val['today_incount'], - 'today_outcount' => $val['today_outcount'], - 'month_incount' => $val['month_incount'], - 'month_outcount' => $val['month_outcount'], - 'year_incount' => $val['year_incount'], - 'year_outcount' => $val['year_outcount'], + 'day30_incount' => $val['day30_incount'], + 'day30_outcount' => $val['day30_outcount'], + 'today_incount' => $val['today_incount'], + 'today_outcount' => $val['today_outcount'], + 'month_incount' => $val['month_incount'], + 'month_outcount' => $val['month_outcount'], + 'year_incount' => $val['year_incount'], + 'year_outcount' => $val['year_outcount'], ]; if ($query) { $opData['update_time'] = date("Y-m-d H:i:s",time()); @@ -88,53 +87,41 @@ class Pass extends Controller } // --------------------- 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); - - # 默认单天数据 - $incount = 0; - $outcount = 0; - if ($hoursQuery) { - - # 存在的数量 + (这次天数数量 - 上次天数数量) = 当前小时数量 - $incount = $hoursQuery['incount'] + ($val['today_incount'] - $hoursQuery['target_today_incount']); - $outcount = $hoursQuery['outcount'] + ($val['today_outcount'] - $hoursQuery['target_today_outcount']); - - $update = [ - 'incount' => $incount, - 'outcount' => $outcount, - 'target_today_incount' => $val['today_incount'], - 'target_today_outcount' => $val['today_outcount'], - 'update_time' => date("Y-m-d H:i:s",time()) - ]; - - $dm->update('bt_library_hours',$update,['id' => $hoursQuery['id']]); - - } else { - # 查看该组是否存在上一条数据 - $lastHoursWhere = ['hour_time' => $last_hour, 'group_id' => $val['group_id']]; - $lastHours = $dm->find('bt_library_hours',$lastHoursWhere,'*','id DESC'); - if ($lastHours && $hour != '00:00') { - $incount = (int)($val['today_incount'] - $lastHours['target_today_incount']); - $outcount = (int)($val['today_outcount'] - $lastHours['target_today_outcount']); - $incount = $incount > 0 ? $incount : 0; - $outcount = $outcount > 0 ? $outcount : 0; + if (isset($val['hour']) && is_array($val['hour'])) { + + foreach ($val['hour'] as $hour => $hourVal) { + + $hour = strlen($hour) > 1 ? $hour : '0' . $hour; + $hour .= ':00'; + # 查看数据是否已经生成 + $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); + + if ($hoursQuery) { + # 数据发生变化再修改 + if ($hourVal['incount'] == $hoursQuery['incount'] && $hourVal['outcount'] == $hoursQuery['outcount']) { + continue; + } + $update = [ + 'incount' => $hourVal['incount'], + 'outcount' => $hourVal['outcount'], + 'update_time' => date("Y-m-d H:i:s", time()) + ]; + $dm->update('bt_library_hours', $update, ['id' => $hoursQuery['id']]); + } else { + # 创建数据 + $insert = [ + 'group_id' => $val['group_id'], + 'group_name' => base64_decode($val['group_name']), + 'incount' => $hourVal['incount'], + 'outcount' => $hourVal['outcount'], + 'hour_time' => $hour, + 'create_time' => date("Y-m-d H:i:s", time()) + ]; + $dm->insert("bt_library_hours", $insert); + } } - # 创建数据 - $insert = [ - 'group_id' => $val['group_id'], - 'group_name' => base64_decode($val['group_name']), - 'incount' => $incount, - 'outcount' => $outcount, - 'target_today_incount' => $val['today_incount'], - 'target_today_outcount' => $val['today_outcount'], - 'hour_time' => $hour, - 'create_time' => date("Y-m-d H:i:s",time()) - ]; - - $dm->insert("bt_library_hours",$insert); } - // --------------------- end --------------------- // $this->saveLibraryData($dm,$val); } From cd900192b75fea81e7617a28881fa59b34bc57f5 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 7 Aug 2023 16:52:39 +0800 Subject: [PATCH 14/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E9=A6=86=EF=BC=8C=E6=96=87=E5=8C=96=E9=A6=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/library/Pass.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 5b8babf..6c34190 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -116,6 +116,8 @@ class Pass extends Controller 'incount' => $hourVal['incount'], 'outcount' => $hourVal['outcount'], 'hour_time' => $hour, + 'target_today_incount' => 0, + 'target_today_outcount' => 0, 'create_time' => date("Y-m-d H:i:s", time()) ]; $dm->insert("bt_library_hours", $insert); From 2204501abd0f488134031dfb51d24011785384a8 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 7 Aug 2023 18:17:26 +0800 Subject: [PATCH 15/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 74c9d47..93fe402 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -474,9 +474,9 @@ class PassFlow $bw_data = []; foreach ($dateArr as $date => $granularity) { - $museumWhere = ' "groupId"='."'510'".' and "granularity" = ' . "'{$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',$museumWhere,' SUM("flowInNum") as NUM'); + $museumRes = $dm->find('bt_passenger_flow_all',$museumWhere,' SUM("flowInNum") as NUM'); $bw_data[$date] = $museumRes['NUM'] ?: 0; } $bw_today_incount = isset($bw_data['day']) ? $bw_data['day'] : 0; From 9100f8764f157c8aa22e836780612549f4db4a65 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 7 Aug 2023 18:36:14 +0800 Subject: [PATCH 16/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 93fe402..0db6ada 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -183,7 +183,11 @@ class PassFlow } # 文化馆客流柱状图数据 foreach ($whgData as $whgRow) { - $date = date($date_str,strtotime($whgRow['create_time'])); // 各时间端进馆人数 + if ($date_str == 'H:00') { + $date = $whgRow['hour_time']; + } else { + $date = date($date_str,strtotime($whgRow['create_time'])); // 各时间端进馆人数 + } if (!isset($allTimeData[$date])) continue; $allTimeData[$date]['num'] += $whgRow['incount']; } From 08fd7daf8cc39bb44c21b75f94282c72e6129dc4 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 8 Aug 2023 16:05:57 +0800 Subject: [PATCH 17/51] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E3=80=81=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/config/Setting.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 source/application/api/controller/config/Setting.php diff --git a/source/application/api/controller/config/Setting.php b/source/application/api/controller/config/Setting.php new file mode 100644 index 0000000..8118cfc --- /dev/null +++ b/source/application/api/controller/config/Setting.php @@ -0,0 +1,45 @@ +request->param('value'); + + if (empty($threshold) || $threshold == 'NULL') return $this->renderError('请填写阈值'); + if (!is_numeric($threshold)) return $this->renderError('阈值必须是整形'); + if ($threshold < 0) return $this->renderError('阈值不能为负数'); + + $dm = new Dm(); + + $queryConfig = $dm->find('bt_config',['key' => 'threshold']); + + if ($queryConfig['value'] == $threshold) { + return $this->renderError('阈值与当前设置阈值一致:'.$threshold); + } + + # 修改阈值 + $dm->update('bt_config',['value' => $threshold],['key' => 'threshold']); + + $commit_explain = '修改阈值:'.$queryConfig['value'].' => '.$threshold; + + return $this->renderSuccess(compact('commit_explain')); + } + + public function getThreshold() + { + $dm = new Dm(); + + $config = $dm->find('bt_config',['key' => 'threshold']); + + $commit_explain = '当前阈值:'.$config['value']; + + return $this->renderSuccess(compact('commit_explain')); + } +} \ No newline at end of file From 9e6042d17c4acc2a84ccc09341511e15f7337c88 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 8 Aug 2023 18:01:39 +0800 Subject: [PATCH 18/51] =?UTF-8?q?=E9=98=B2=E6=AD=A2sql=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/pass/Passcc.php | 4 +- source/application/common/logic/PassFlow.php | 41 +++++++++++++------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index 17d8cc2..a6d842d 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -93,8 +93,8 @@ class Passcc extends Controller */ public function getPassHoursData() { - $groupsId = $this->request->param('groupsId') ?: ''; - $data = PassFlow::getPassHoursData(null,['groupsId' => $groupsId]); + $type = $this->request->param('type') ?: ''; + $data = PassFlow::getPassHoursData(null,['type' => $type]); return $this->renderSuccess(compact('data')); } } \ No newline at end of file diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 0db6ada..2fb6391 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -6,6 +6,17 @@ use app\common\dm\Dm; class PassFlow { + protected static $groupType = [1,2];# 1 = 体育 2 = 文化 + + protected static function getGroupIds($dm,$type = 1) + { + $groupIdArr = []; + $result = $dm->select('bt_passenger_monitor_group',['type' => $type]); + foreach ($result as $row) { + $groupIdArr[] = $row['groupId']; + } + return $groupIdArr; + } /** * 分时时间段接口 <首页-客流趋势> * @return array @@ -17,14 +28,16 @@ class PassFlow { $granularity = $param['granularity']; - $groupsId = $param['groupsId']; + $type = $param['type']; if (empty($granularity)) return ['code' => 0, 'msg' => '缺少参数:granularity']; $where = ''; - if (!empty($groupsId)) { - $garr = explode("|", $groupsId); - $where .= ' "groupId" in(' . "'" . implode("','", $garr) . "')"; - + $groupsId = ''; + if (!empty($type)) { + if (!in_array($type,self::$groupType)) return ['code' => 0, 'msg' => 'type字段参数错误']; + $groupsIdArr = self::getGroupIds($dm,$type); + $groupsId = implode("|",$groupsIdArr); + $where .= ' "groupId" in(' . "'" . implode("','", $groupsIdArr) . "')"; } $allTimeData = []; @@ -251,8 +264,9 @@ class PassFlow if (empty($dm)) $dm = new Dm(); $paramWhere = ''; if (!empty($param)) { - if (!empty($param['groupsId'])) { - $groupsId = explode("|",$param['groupsId']); + if (!empty($param['type'])) { + if (!in_array($param['type'],self::$groupType)) return ['code' => 0, 'msg' => 'type字段参数错误']; + $groupsId = self::getGroupIds($dm,$param['type']); $paramWhere .= ' and "groupId" in (' . "'" . implode("','",$groupsId) . "')"; } } @@ -394,9 +408,11 @@ class PassFlow $where = ' "granularity"='."'hourly' "; $groupsWhere = null; + $groupsId = []; if (!empty($param)) { - if (!empty($param['groupsId'])) { - $groupsId = explode("|",$param['groupsId']); + if (!empty($param['type'])) { + if (!in_array($param['type'],self::$groupType)) return ['code' => 0, 'msg' => 'type字段参数错误']; + $groupsId = self::getGroupIds($dm,$param['type']); $groupsWhere = ['groupId' => $groupsId]; $where .= ' and "groupId" in (' . "'" . implode("','",$groupsId) . "')"; } @@ -448,7 +464,7 @@ class PassFlow 'list' => $listData ]; } - if(empty($param['groupsId'])){ + if(empty($groupsId)){ $data = self::getLibraryGroupHoursList($dm,false,$data); } return $data; @@ -547,8 +563,9 @@ class PassFlow $where = ' "granularity"='."'hourly' "; if (!empty($param)) { - if (!empty($param['groupsId'])) { - $groupsId = explode("|",$param['groupsId']); + if (!empty($param['type'])) { + if (!in_array($param['type'], self::$groupType)) return ['code' => 0, 'msg' => 'type字段参数错误']; + $groupsId = self::getGroupIds($dm, $param['type']); $where .= ' and "groupId" in (' . "'" . implode("','",$groupsId) . "')"; } } From a6f0f141de447e24439c0d4aade7b8a9923c72fe Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 8 Aug 2023 18:02:06 +0800 Subject: [PATCH 19/51] =?UTF-8?q?=E9=98=B2=E6=AD=A2sql=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ws_task_real_ty.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web/ws_task_real_ty.php b/web/ws_task_real_ty.php index a2d8fa0..5cf6861 100644 --- a/web/ws_task_real_ty.php +++ b/web/ws_task_real_ty.php @@ -27,25 +27,25 @@ $worker->onWorkerStart = function($worker) use($config) { $data = []; # 主动推送对应页面数据 - $groupIdArr = []; - $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 1]); - foreach ($groupRes as $groupRow) $groupIdArr[] = $groupRow['groupId']; - $groupIdStr = !empty($groupIdArr) ? implode("|",$groupIdArr) : ''; +// $groupIdArr = []; +// $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 1]); +// foreach ($groupRes as $groupRow) $groupIdArr[] = $groupRow['groupId']; +// $groupIdStr = !empty($groupIdArr) ? implode("|",$groupIdArr) : ''; # 累计服务人数 - $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm,['groupsId' => $groupIdStr])]; + $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm,['type' => 1])]; # 24小时 - $data['getPassHoursData'] = ['data' => PassFlow::getPassHoursData($dm,['groupsId' => $groupIdStr])]; + $data['getPassHoursData'] = ['data' => PassFlow::getPassHoursData($dm,['type' => 1])]; # 24小时进馆人数 $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; # 各场馆服务人次占比 - $data['allGroupTimeNum'] = ['data' => PassFlow::allGroupTimeNum(['groupsId' => $groupIdStr,'granularity' => 'daily'],$dm)]; + $data['allGroupTimeNum'] = ['data' => PassFlow::allGroupTimeNum(['type' => 1,'granularity' => 'daily'],$dm)]; # 各场馆服务人次趋势 - $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm,['groupsId' => $groupIdStr])]; + $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm,['type' => 1])]; $connection->send(json_encode($data)); } From bd94f83bfda4e0c65b02a4c7a81ccb89097f7551 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 8 Aug 2023 18:06:48 +0800 Subject: [PATCH 20/51] =?UTF-8?q?=E9=98=B2=E6=AD=A2sql=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/pass/Passcc.php | 12 ++++++------ source/application/common/logic/PassFlow.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index a6d842d..c8f5811 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -26,8 +26,8 @@ class Passcc extends Controller public function allGroupTimeNum() { $granularity = $this->request->param('granularity'); - $groupsId = $this->request->param('groupsId'); - $res = PassFlow::allGroupTimeNum(['granularity' => $granularity, 'groupsId' => $groupsId]); + $type = $this->request->param('type'); + $res = PassFlow::allGroupTimeNum(['granularity' => $granularity, 'type' => $type]); if (empty($res['code'])) $this->renderError($res['msg']); $data = $res['data']; return $this->renderSuccess(compact('data')); @@ -42,8 +42,8 @@ class Passcc extends Controller */ public function allGroupNum() { - $groupsId = $this->request->param('groupsId') ?: ''; - $returnData = PassFlow::allGroupNum(null,['groupsId' => $groupsId]); + $type = $this->request->param('type') ?: ''; + $returnData = PassFlow::allGroupNum(null,['type' => $type]); return $this->renderSuccess(compact('returnData')); } @@ -69,8 +69,8 @@ class Passcc extends Controller */ public function toDayGroupsEnterNum() { - $groupsId = $this->request->param('groupsId') ?: ''; - $data = PassFlow::toDayGroupsEnterNum(null,['groupsId' => $groupsId]); + $type = $this->request->param('type') ?: ''; + $data = PassFlow::toDayGroupsEnterNum(null,['type' => $type]); return $this->renderSuccess(compact('data')); } diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 2fb6391..a7fd2d5 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -7,6 +7,7 @@ use app\common\dm\Dm; class PassFlow { protected static $groupType = [1,2];# 1 = 体育 2 = 文化 + protected static $granularity = ['daily','monthly','yearly'];# 1 = 体育 2 = 文化 protected static function getGroupIds($dm,$type = 1) { @@ -31,6 +32,7 @@ class PassFlow $type = $param['type']; if (empty($granularity)) return ['code' => 0, 'msg' => '缺少参数:granularity']; + if (!in_array($granularity,self::$granularity)) return ['code' => 0, 'msg' => '参数错误:granularity']; $where = ''; $groupsId = ''; if (!empty($type)) { From 31891865277014a6594a5fb094324072475d4b61 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 8 Aug 2023 18:22:57 +0800 Subject: [PATCH 21/51] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/pass/Passcc.php | 5 ++++- source/application/common/logic/PassFlow.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index c8f5811..e6ed82f 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -28,7 +28,7 @@ class Passcc extends Controller $granularity = $this->request->param('granularity'); $type = $this->request->param('type'); $res = PassFlow::allGroupTimeNum(['granularity' => $granularity, 'type' => $type]); - if (empty($res['code'])) $this->renderError($res['msg']); + if (empty($res['code'])) return $this->renderError($res['msg']); $data = $res['data']; return $this->renderSuccess(compact('data')); } @@ -44,6 +44,7 @@ class Passcc extends Controller { $type = $this->request->param('type') ?: ''; $returnData = PassFlow::allGroupNum(null,['type' => $type]); + if (isset($returnData['code'])) return $this->renderError($returnData['msg']); return $this->renderSuccess(compact('returnData')); } @@ -71,6 +72,7 @@ class Passcc extends Controller { $type = $this->request->param('type') ?: ''; $data = PassFlow::toDayGroupsEnterNum(null,['type' => $type]); + if (isset($data['code'])) return $this->renderError($data['msg']); return $this->renderSuccess(compact('data')); } @@ -95,6 +97,7 @@ class Passcc extends Controller { $type = $this->request->param('type') ?: ''; $data = PassFlow::getPassHoursData(null,['type' => $type]); + if (isset($data['code'])) return $this->renderError($data['msg']); return $this->renderSuccess(compact('data')); } } \ No newline at end of file diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index a7fd2d5..d2ab9ea 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -35,6 +35,7 @@ class PassFlow if (!in_array($granularity,self::$granularity)) return ['code' => 0, 'msg' => '参数错误:granularity']; $where = ''; $groupsId = ''; + if (empty($dm)) $dm = new Dm(); if (!empty($type)) { if (!in_array($type,self::$groupType)) return ['code' => 0, 'msg' => 'type字段参数错误']; $groupsIdArr = self::getGroupIds($dm,$type); @@ -45,7 +46,6 @@ class PassFlow $allTimeData = []; $groupsData = []; $dkeys = []; - if (empty($dm)) $dm = new Dm(); if ($granularity == 'daily') { $date = self::getDateData('day'); $start_time = $date['day']['start_time']; From c825ecf175cf33a15ef8fd6c3dfde37a0e9e1907 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 9 Aug 2023 09:07:48 +0800 Subject: [PATCH 22/51] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index d2ab9ea..fc10af1 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -697,7 +697,7 @@ class PassFlow $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)]); + $data = self::toDayGroupsEnterNum($dm,['type' => 2]); } # 图书、文化馆 $start_create_time = date("Y-m-d 00:00:00"); From 8d37d446fbe97a8b341324c5202f458b7b82856b Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 9 Aug 2023 09:09:10 +0800 Subject: [PATCH 23/51] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ws_task_real.php | 2 ++ web/ws_task_real_ty.php | 2 ++ web/ws_task_real_wh.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/web/ws_task_real.php b/web/ws_task_real.php index ac75391..6666cbb 100644 --- a/web/ws_task_real.php +++ b/web/ws_task_real.php @@ -14,6 +14,8 @@ require_once __DIR__ . '../../source/thinkphp/library/think/Config.php'; require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; +date_default_timezone_set('Asia/Shanghai'); + $worker = new Worker('websocket://0.0.0.0:1234'); $worker->count = 4; // 进程启动后定时推送数据给客户端 diff --git a/web/ws_task_real_ty.php b/web/ws_task_real_ty.php index 5cf6861..a19d2b5 100644 --- a/web/ws_task_real_ty.php +++ b/web/ws_task_real_ty.php @@ -14,6 +14,8 @@ require_once __DIR__ . '../../source/thinkphp/library/think/Config.php'; require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; +date_default_timezone_set('Asia/Shanghai'); + $worker = new Worker('websocket://0.0.0.0:1235'); $worker->count = 4; // 进程启动后定时推送数据给客户端 diff --git a/web/ws_task_real_wh.php b/web/ws_task_real_wh.php index 7269de5..2c7ce8b 100644 --- a/web/ws_task_real_wh.php +++ b/web/ws_task_real_wh.php @@ -14,6 +14,8 @@ require_once __DIR__ . '../../source/thinkphp/library/think/Config.php'; require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; +date_default_timezone_set('Asia/Shanghai'); + $worker = new Worker('websocket://0.0.0.0:1236'); $worker->count = 4; // 进程启动后定时推送数据给客户端 From f7cbd5c33127c9062f557a6c05fd48fcfbaef432 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 9 Aug 2023 14:04:50 +0800 Subject: [PATCH 24/51] =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/pass/Passcc.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index e6ed82f..b4a36b5 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -5,6 +5,7 @@ namespace app\api\controller\pass; use app\api\controller\Controller; use app\common\dm\Dm; +use app\common\exception\BaseException; use app\common\logic\PassFlow; use app\common\model\Pass; use think\Db; @@ -16,6 +17,14 @@ class Passcc extends Controller echo 1111; } + public function _initialize() + { + $type = $this->request->param('type'); + if (!empty($type)) { + if (!preg_match('/^[1-2]$/',$type)) throw new BaseException(['msg' => 'type字段参数错误']); + } + } + /** * 分时时间段接口 <首页-客流趋势> * @return array From 47ae7b1aaca6a6d1f483d889bc79f68a637ef6ea Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 9 Aug 2023 14:16:48 +0800 Subject: [PATCH 25/51] =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/pass/Passcc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index b4a36b5..b68eb14 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -20,7 +20,7 @@ class Passcc extends Controller public function _initialize() { $type = $this->request->param('type'); - if (!empty($type)) { + if (!empty($type) || is_numeric($type)) { if (!preg_match('/^[1-2]$/',$type)) throw new BaseException(['msg' => 'type字段参数错误']); } } From 27c819a4407bcb6c108f32dfbfa36c70899737b2 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 9 Aug 2023 18:52:10 +0800 Subject: [PATCH 26/51] =?UTF-8?q?=E9=98=88=E5=80=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 35 ++++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index fc10af1..351f6fc 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -8,6 +8,14 @@ class PassFlow { protected static $groupType = [1,2];# 1 = 体育 2 = 文化 protected static $granularity = ['daily','monthly','yearly'];# 1 = 体育 2 = 文化 + protected static $groupThreshold = [ + 'baz001' => 10000,# 图书馆 + 'BAF055' => 1000,# 文化馆 + '110' => 10000,# 体育场 + '210' => 10000,# 体育馆 + '310' => 1000,# 游泳馆 + '510' => 1000 # 博物馆 + ]; protected static function getGroupIds($dm,$type = 1) { @@ -304,7 +312,10 @@ class PassFlow $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; +// $returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; + # 文化总年度 + $libraryData = $dm->find('bt_library_data',['group_id' => 'lib001','date' => 'year'],'SUM("incount") as NUM'); + $returnData['sumYear']['noRepeatInNum'] += isset($libraryData['NUM']) ? $libraryData['NUM'] : 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}'"; @@ -332,17 +343,18 @@ class PassFlow $list = $dm->select('bt_passenger_flow_real'); $data = []; - $configRes = $dm->find("bt_config",' "key" = ' . "'threshold'"); - $threshold = $configRes['value'] ?: 0; +// $configRes = $dm->find("bt_config",' "key" = ' . "'threshold'"); +// $threshold = $configRes['value'] ?: 0; foreach ($list as $value) { if (!isset($data[$value['groupId']]['allEnter'])) $data[$value['groupId']]['allEnter'] = 0; $data[$value['groupId']]['allEnter'] += $value['allEnter']; } + $groupThreshold = self::$groupThreshold; $returnData = []; foreach ($data as $groupId => $val) { - $proportion = $val['allEnter'] > 0 ? round($val['allEnter']/$threshold,4) : 0; + $proportion = $val['holdValue'] > 0 ? round($val['holdValue']/$groupThreshold[$val['groupId']],4) : 0; $val['proportion'] = ($proportion * 100) . "%"; $val['congestion'] = self::getPassType($proportion); $val['groupId'] = $groupId; @@ -354,7 +366,8 @@ class PassFlow } $libData = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); foreach ($libData as $libRow) { - $libProportion = $libRow['today_incount'] > 0 ? round($libRow['today_incount']/$threshold,4) : 0; + $holdValue = $libRow['today_incount'] - $libRow['today_outcount']; + $libProportion = $holdValue > 0 ? round($holdValue/$groupThreshold[$libRow['group_id']],4) : 0; // 文化馆排 4# 图书馆 2# $isort = $libRow['group_id']=='baz001'?2:4; $returnData[] = [ @@ -379,19 +392,19 @@ class PassFlow protected static function getPassType($proportion) { # 舒适:阈值<80% - if ($proportion < 0.8) { + if ($proportion <= 0.5) { return '舒适'; } # 饱和:80%<阈值<100% - if (0.8 < $proportion || $proportion < 1) { - return '饱和'; - } +// if (0.8 < $proportion || $proportion < 1) { +// return '饱和'; +// } # 拥挤:阈值=100% - if ($proportion == 1) { + if ($proportion > 0.5 && $proportion <= 1) { return '拥挤'; } # 拥挤:阈值=100% - if ($proportion >= 1.2) { + if ($proportion > 1) { return '爆满'; } return ''; From 664f07a75a7faa3a60a3fd89adc59bb35f82d15f Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 9 Aug 2023 19:06:48 +0800 Subject: [PATCH 27/51] =?UTF-8?q?=E9=98=88=E5=80=BC=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 351f6fc..e29a417 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -349,12 +349,14 @@ class PassFlow foreach ($list as $value) { if (!isset($data[$value['groupId']]['allEnter'])) $data[$value['groupId']]['allEnter'] = 0; $data[$value['groupId']]['allEnter'] += $value['allEnter']; + if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0; + $data[$value['groupId']]['holdValue'] += $value['holdValue']; } $groupThreshold = self::$groupThreshold; $returnData = []; foreach ($data as $groupId => $val) { - $proportion = $val['holdValue'] > 0 ? round($val['holdValue']/$groupThreshold[$val['groupId']],4) : 0; + $proportion = $val['holdValue'] > 0 ? round($val['holdValue']/$groupThreshold[$groupId],4) : 0; $val['proportion'] = ($proportion * 100) . "%"; $val['congestion'] = self::getPassType($proportion); $val['groupId'] = $groupId; From f8bd3ba20ac91b524cdf2e3af7797266b9e6aee8 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 10 Aug 2023 16:55:29 +0800 Subject: [PATCH 28/51] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A2=9E=E5=8A=A0token=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/library/Pass.php | 13 +++++++++++++ source/application/api/controller/pass/Passcc.php | 4 ++++ source/application/api/controller/xtool/Token.php | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 source/application/api/controller/xtool/Token.php diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 6c34190..72d4483 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -3,13 +3,22 @@ namespace app\api\controller\library; use app\api\controller\Controller; use app\common\dm\Dm; +use app\common\exception\BaseException; use app\common\logic\PassFlow; +use think\Session; class Pass extends Controller { protected $url = 'http://balib.cn:8999'; + public function requestValiDate() + { + $token = $this->request->param('token'); + if (empty($token)) throw new BaseException(['msg' => '缺少token参数']); + if ($token != Session::pull('__token__')) throw new BaseException(['msg' => 'token验证失败']); + } + /** * 图书管数据接口 * @return array @@ -19,6 +28,7 @@ class Pass extends Controller */ public function allFlowTrends() { + $this->requestValiDate(); $data = PassFlow::allFlowTrends(); return $this->renderSuccess(compact('data')); } @@ -204,6 +214,7 @@ class Pass extends Controller */ public function getLibraryHours24List() { + $this->requestValiDate(); $data = PassFlow::getLibraryHours24List(); return $this->renderSuccess(compact('data')); } @@ -217,6 +228,7 @@ class Pass extends Controller */ public function getLibraryGroupHoursList() { + $this->requestValiDate(); $data = PassFlow::getLibraryGroupHoursList(); return $this->renderSuccess(compact('data')); } @@ -264,6 +276,7 @@ class Pass extends Controller */ public function getLibraryLeaseData() { + $this->requestValiDate(); $data = PassFlow::getLibraryLeaseData(); return $this->renderSuccess(compact('data')); } diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index b68eb14..f243347 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -9,6 +9,7 @@ use app\common\exception\BaseException; use app\common\logic\PassFlow; use app\common\model\Pass; use think\Db; +use think\Session; class Passcc extends Controller { @@ -19,6 +20,9 @@ class Passcc extends Controller public function _initialize() { + $token = $this->request->param('token'); + if (empty($token)) throw new BaseException(['msg' => '缺少token参数']); + if ($token != Session::pull('__token__')) throw new BaseException(['msg' => 'token验证失败']); $type = $this->request->param('type'); if (!empty($type) || is_numeric($type)) { if (!preg_match('/^[1-2]$/',$type)) throw new BaseException(['msg' => 'type字段参数错误']); diff --git a/source/application/api/controller/xtool/Token.php b/source/application/api/controller/xtool/Token.php new file mode 100644 index 0000000..02357af --- /dev/null +++ b/source/application/api/controller/xtool/Token.php @@ -0,0 +1,13 @@ +renderSuccess(['token' => $this->request->token()]); + } +} \ No newline at end of file From 8c305a52aaaf49e88c1758d271d14b1f596eab90 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 10 Aug 2023 16:56:12 +0800 Subject: [PATCH 29/51] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A2=9E=E5=8A=A0token=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/library/Pass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 72d4483..2bdc03f 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -12,7 +12,7 @@ class Pass extends Controller protected $url = 'http://balib.cn:8999'; - public function requestValiDate() + protected function requestValiDate() { $token = $this->request->param('token'); if (empty($token)) throw new BaseException(['msg' => '缺少token参数']); From c57b298638f5b9537c9b92deebbb8a9c1aa34a49 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 16 Aug 2023 18:15:51 +0800 Subject: [PATCH 30/51] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E4=B9=A6?= =?UTF-8?q?=E9=A6=86=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index e29a417..7d34a47 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -9,7 +9,7 @@ class PassFlow protected static $groupType = [1,2];# 1 = 体育 2 = 文化 protected static $granularity = ['daily','monthly','yearly'];# 1 = 体育 2 = 文化 protected static $groupThreshold = [ - 'baz001' => 10000,# 图书馆 + 'baz001' => 40000,# 图书馆 'BAF055' => 1000,# 文化馆 '110' => 10000,# 体育场 '210' => 10000,# 体育馆 From 52b192635dbb2056c435c4a8f61361e005a751f9 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 21 Aug 2023 11:01:02 +0800 Subject: [PATCH 31/51] =?UTF-8?q?=E5=8F=96=E7=BB=9D=E5=AF=B9=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 7d34a47..3a1225c 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -368,7 +368,7 @@ class PassFlow } $libData = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); foreach ($libData as $libRow) { - $holdValue = $libRow['today_incount'] - $libRow['today_outcount']; + $holdValue = abs($libRow['today_incount'] - $libRow['today_outcount']); $libProportion = $holdValue > 0 ? round($holdValue/$groupThreshold[$libRow['group_id']],4) : 0; // 文化馆排 4# 图书馆 2# $isort = $libRow['group_id']=='baz001'?2:4; From 60766bb6e7f1894dd457c1a697cbf9f087a605d1 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 21 Aug 2023 15:25:06 +0800 Subject: [PATCH 32/51] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E5=8D=A0=E6=AF=94=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 44 +++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 3a1225c..e41f497 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -11,9 +11,18 @@ class PassFlow protected static $groupThreshold = [ 'baz001' => 40000,# 图书馆 'BAF055' => 1000,# 文化馆 - '110' => 10000,# 体育场 - '210' => 10000,# 体育馆 - '310' => 1000,# 游泳馆 + '110' => [ + 'min' => 8000, + 'max' => 12000 + ],# 体育场 + '210' => [ + 'min' => 8000, + 'max' => 12000 + ],# 体育馆 + '310' => [ + 'min' => 6000, + 'max' => 10000 + ],# 游泳馆 '510' => 1000 # 博物馆 ]; @@ -356,9 +365,16 @@ class PassFlow $returnData = []; foreach ($data as $groupId => $val) { - $proportion = $val['holdValue'] > 0 ? round($val['holdValue']/$groupThreshold[$groupId],4) : 0; - $val['proportion'] = ($proportion * 100) . "%"; - $val['congestion'] = self::getPassType($proportion); + $threshold = $groupThreshold[$groupId]; + if (is_array($threshold)) { + $interval = self::getIntervalType($val['holdValue'],$threshold['min'],$threshold['max']); + $val['proportion'] = $interval['rate']; + $val['congestion'] = $interval['str']; + } else { + $proportion = $val['holdValue'] > 0 ? round($val['holdValue']/$threshold,4) : 0; + $val['proportion'] = ($proportion * 100) . "%"; + $val['congestion'] = self::getPassType($proportion); + } $val['groupId'] = $groupId; $getGroup = $dm->find('bt_passenger_monitor_group',' "groupId" = ' . "'{$groupId}'"); @@ -412,6 +428,22 @@ class PassFlow return ''; } + protected static function getIntervalType($proportion,$min,$max) + { + + if ($proportion < $min) { + return ['str' => '舒适', 'rate' => '49%']; + } + if ($proportion > $min && $proportion < $max) { + return ['str' => '拥挤', 'rate' => '99%']; + } + if ($proportion > $max) { + return ['str' => '爆满', 'rate' => '149%']; + } + + return ['str' => '', 'rate' => '0%']; + } + /** * 今日各场馆人数趋势 * @return array From 123c10024c56146663e227a87e99891763ddd6bd Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 21 Aug 2023 17:09:59 +0800 Subject: [PATCH 33/51] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=98=88=E5=80=BC?= =?UTF-8?q?=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/setting/Config.php | 62 +++++++++++++++---- .../admin/view/setting/config/index.php | 21 ++++++- source/application/common/logic/PassFlow.php | 21 ++++++- 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/source/application/admin/controller/setting/Config.php b/source/application/admin/controller/setting/Config.php index f620414..044ceab 100644 --- a/source/application/admin/controller/setting/Config.php +++ b/source/application/admin/controller/setting/Config.php @@ -5,6 +5,7 @@ namespace app\admin\controller\setting; use app\admin\controller\Controller; use app\common\dm\Dm; use app\common\model\Pass; +use think\Session; /** * 配置 @@ -24,26 +25,65 @@ class Config extends Controller if ($this->request->isAjax()) { - $request = $this->request->request(); + $request = $_POST; + if ( Session::get('__token__') != $request['token']) $this->renderError('token验证失败'); $threshold = $request['threshold']; - if (empty($threshold)) $this->renderError('请填写阈值'); - if (is_numeric($threshold) && $threshold > 0) $this->renderError('阈值必须是数字'); + if (!is_array($threshold)) $this->renderError('参数类型错误'); - # 修改阈值 - $dm->update('bt_config',['value' => $threshold],'"key"='."'threshold'"); + $errorArr = []; + $i = 0; + foreach ($threshold as $id => $value) { + $error = []; + $i++; + $strpos = strpos($value,'-'); + if ($strpos !== false) { + $arr = explode("-",$value); + if (!preg_match("/^\d+$/",$arr[0])) $error[] = "第{$i}行,第1个数据必须是数字"; + if (!preg_match("/^\d+$/",$arr[1])) $error[] = "第{$i}行,第2个必须是数字"; + if ($arr[1] < $arr[0]) $error[] = "第{$i}行,第2个不能小于第1个数据"; + } else { + if (!preg_match("/^\d+$/",$value)) $error[] = "第{$i}行,数据必须是数字"; + } + + # 验证数据是否发生修改 + $queryRes = $dm->find('bt_config',['id' => $id]); + if (empty($queryRes)) $error[] = "第{$i}行,数据不存在"; + if ($queryRes['value'] == $value) continue; + + if (!empty($error)) { + $errorArr = array_merge($errorArr,$error); + continue; + } + + $dm->update('bt_config',['value' => $value],['id' => $id]); + } + + if (!empty($errorArr)) { + return $this->renderError(implode("
",$errorArr)); + } return $this->renderSuccess('操作成功'); } - $configList = []; - - $configRes = $dm->find("bt_config",' "key" = ' . "'threshold'"); - $threshold = $configRes['value']; + $configRes = $dm->select("bt_config"); + foreach ($configRes as &$configRow) { + $configRow['groupName'] = ''; + $tyGroupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $configRow['key']],'"groupName"'); + if ($tyGroupRes) { + $configRow['groupName'] = $tyGroupRes['groupName']; + } + if (empty($configRow['groupName'])) { + $whGroupRes = $dm->find('bt_library',['group_id' => $configRow['key']],'"group_name"'); + if ($whGroupRes) { + $configRow['groupName'] = $whGroupRes['group_name']; + } + } + } return $this->fetch('index', [ - 'configList' => $configList, - 'threshold' => $threshold, + 'configList' => $configRes, + 'token' => $this->request->token() ]); } } \ No newline at end of file diff --git a/source/application/admin/view/setting/config/index.php b/source/application/admin/view/setting/config/index.php index 3baa3ea..6a8e3d4 100644 --- a/source/application/admin/view/setting/config/index.php +++ b/source/application/admin/view/setting/config/index.php @@ -1,12 +1,19 @@
@@ -17,16 +24,24 @@
预警阈值
+
+   计算方式1:阈值<=50% = 舒适、阈值>50% 阈值<=100% = 拥挤、阈值>100% = 爆满 +
+   计算方式2:100-200, 小于100 = 舒适、大于100小于200 = 拥挤、大于200 = 爆满 +
+
- +
+
+
diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index e41f497..cbe6e87 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -361,7 +361,7 @@ class PassFlow if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0; $data[$value['groupId']]['holdValue'] += $value['holdValue']; } - $groupThreshold = self::$groupThreshold; + $groupThreshold = self::getConfig($dm); $returnData = []; foreach ($data as $groupId => $val) { @@ -814,4 +814,23 @@ class PassFlow } + public static function getConfig($dm) + { + $res = $dm->select('bt_config'); + $data = []; + foreach ($res as $row) { + + $dataValue = $row['value']; + if (strpos($row['value'],"-") !== false) { + $arr = explode("-",$dataValue); + $dataValue = [ + 'min' => $arr[0], + 'max' => $arr[1] + ]; + } + $data[$row['key']] = $dataValue; + + } + return $data; + } } From d4103fd5243cc08c2677a599f7721e635fe0d311 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 21 Aug 2023 17:33:23 +0800 Subject: [PATCH 34/51] =?UTF-8?q?=E5=85=88=E5=8E=BB=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index cbe6e87..bc5a643 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -361,7 +361,7 @@ class PassFlow if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0; $data[$value['groupId']]['holdValue'] += $value['holdValue']; } - $groupThreshold = self::getConfig($dm); + $groupThreshold = self::$groupThreshold;#self::getConfig($dm); $returnData = []; foreach ($data as $groupId => $val) { From dd21fc5d24b5425521ec801e6f3bb452295ee9d9 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 22 Aug 2023 11:14:09 +0800 Subject: [PATCH 35/51] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/admin/controller/Passport.php | 4 +- source/application/admin/extra/menus.php | 52 +++++++++---------- source/application/admin/model/admin/User.php | 6 ++- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/source/application/admin/controller/Passport.php b/source/application/admin/controller/Passport.php index 411dd8d..a2ba53b 100644 --- a/source/application/admin/controller/Passport.php +++ b/source/application/admin/controller/Passport.php @@ -23,8 +23,8 @@ class Passport extends Controller { if ($this->request->isAjax()) { $model = new UserModel; - if ($model->login($this->postData('User'))) { - return $this->renderSuccess('登录成功', url('index/index')); + if ($model->login($_POST['User'])) { + return $this->renderSuccess('登录成功', url('admin/setting.config/index')); } return $this->renderError($model->getError() ?: '登录失败'); } diff --git a/source/application/admin/extra/menus.php b/source/application/admin/extra/menus.php index 85aaeff..095642a 100644 --- a/source/application/admin/extra/menus.php +++ b/source/application/admin/extra/menus.php @@ -30,36 +30,36 @@ return [ // ] // ], // ], - 'statistics' => [ - 'name' => '数据统计', - 'icon' => 'icon-shezhi', - 'submenu' => [ - [ - 'name' => '客流统计数据', - 'index' => 'pass.pass/index' - ], - [ - 'name' => '总客流统计数据', - 'index' => 'pass.pass/allIndex' - ], - [ - 'name' => '客流实时统计数据', - 'index' => 'pass.pass/realIndex' - ], - ], - ], +// 'statistics' => [ +// 'name' => '数据统计', +// 'icon' => 'icon-shezhi', +// 'submenu' => [ +// [ +// 'name' => '客流统计数据', +// 'index' => 'pass.pass/index' +// ], +// [ +// 'name' => '总客流统计数据', +// 'index' => 'pass.pass/allIndex' +// ], +// [ +// 'name' => '客流实时统计数据', +// 'index' => 'pass.pass/realIndex' +// ], +// ], +// ], 'setting' => [ 'name' => '系统设置', 'icon' => 'icon-shezhi', 'submenu' => [ - [ - 'name' => '清理缓存', - 'index' => 'setting.cache/clear' - ], - [ - 'name' => '环境检测', - 'index' => 'setting.science/index' - ], +// [ +// 'name' => '清理缓存', +// 'index' => 'setting.cache/clear' +// ], +// [ +// 'name' => '环境检测', +// 'index' => 'setting.science/index' +// ], [ 'name' => '配置', 'index' => 'setting.config/index' diff --git a/source/application/admin/model/admin/User.php b/source/application/admin/model/admin/User.php index bc2b3dc..e04beb4 100644 --- a/source/application/admin/model/admin/User.php +++ b/source/application/admin/model/admin/User.php @@ -2,6 +2,7 @@ namespace app\admin\model\admin; +use app\common\dm\Dm; use think\Session; use app\common\model\admin\User as UserModel; @@ -23,10 +24,11 @@ class User extends UserModel public function login($data) { // 验证用户名密码是否正确 - if (!$user = self::useGlobalScope(false)->where([ + $dm = new Dm(); + if (!$user = $dm->find('bt_admin_user',[ 'user_name' => $data['user_name'], 'password' => yoshop_hash($data['password']) - ])->find()) { + ])) { $this->error = '登录失败, 用户名或密码错误'; return false; } From 7570ca254330e3d9dd45f335b56b3cfae9b9060f Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 22 Aug 2023 11:18:23 +0800 Subject: [PATCH 36/51] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index bc5a643..cbe6e87 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -361,7 +361,7 @@ class PassFlow if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0; $data[$value['groupId']]['holdValue'] += $value['holdValue']; } - $groupThreshold = self::$groupThreshold;#self::getConfig($dm); + $groupThreshold = self::getConfig($dm); $returnData = []; foreach ($data as $groupId => $val) { From 238dc48e888b138fa40ca75674afdb7007b24b3a Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 22 Aug 2023 11:28:58 +0800 Subject: [PATCH 37/51] =?UTF-8?q?=E5=B9=B2=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/admin/view/layouts/layout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/admin/view/layouts/layout.php b/source/application/admin/view/layouts/layout.php index 03dc60c..abf3c5c 100644 --- a/source/application/admin/view/layouts/layout.php +++ b/source/application/admin/view/layouts/layout.php @@ -31,7 +31,7 @@
  • - 欢迎你, + 欢迎你,
  • From cfa01802fbe074a45d0e315903273d0d9bbbe8d1 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 22 Aug 2023 14:03:49 +0800 Subject: [PATCH 38/51] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=94=B9=E7=94=A8PDO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/admin/model/admin/User.php | 9 ++-- source/application/common/dm/Dm.php | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/source/application/admin/model/admin/User.php b/source/application/admin/model/admin/User.php index e04beb4..14220b8 100644 --- a/source/application/admin/model/admin/User.php +++ b/source/application/admin/model/admin/User.php @@ -25,18 +25,19 @@ class User extends UserModel { // 验证用户名密码是否正确 $dm = new Dm(); - if (!$user = $dm->find('bt_admin_user',[ + $user = $dm->dmPDOFind('bt_admin_user',[ 'user_name' => $data['user_name'], 'password' => yoshop_hash($data['password']) - ])) { + ]); + if (!$user['status']) { $this->error = '登录失败, 用户名或密码错误'; return false; } // 保存登录状态 Session::set('yoshop_admin', [ 'user' => [ - 'admin_user_id' => $user['admin_user_id'], - 'user_name' => $user['user_name'], + 'admin_user_id' => $user['data']['admin_user_id'], + 'user_name' => $user['data']['user_name'], ], 'is_login' => true, ]); diff --git a/source/application/common/dm/Dm.php b/source/application/common/dm/Dm.php index 7a48274..f93fca5 100644 --- a/source/application/common/dm/Dm.php +++ b/source/application/common/dm/Dm.php @@ -313,4 +313,47 @@ class Dm 'pageData' => $pageData, ]; } + + public function dmPDOFind($table,array $where) + { + + try { + $database = config('database'); + $dm_config = $database['connections']['dm']; + + $dsn = "dm:host={$dm_config['hostname']};port={$dm_config['hostport']};dbname={$dm_config['database']}"; + + $connection = new \PDO($dsn, $dm_config['username'], $dm_config['password']); + $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + + $tableName = $this->splitTableName($table); + $fields = array_keys($where); + + $whereSqlArr = []; + foreach ($fields as $field) $whereSqlArr[] = '"'.$field.'"' . ' = ' . '?'; + + $whereSql = implode(" and ",$whereSqlArr); + + $sql = "SELECT * FROM {$tableName} WHERE " . $whereSql; + + // 准备预编译语句 + $statement = $connection->prepare($sql); + + $statement->bindParam(1, $where['user_name']); + $statement->bindParam(2, $where['password']); + + // 执行查询 + $statement->execute(); + + $data = []; + while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { + $data = $row; + } + if (empty($data)) return ['status' => false, 'msg' => '失败']; + + return ['status' => true, 'msg' => '成功','data' => $data]; + } catch (\PDOException $e) { + return ['status' => false, 'msg' => $e->getMessage()]; + } + } } From 48b7a989d7a0298ffc865a6bdbf3d11d2da298ef Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 24 Aug 2023 09:18:36 +0800 Subject: [PATCH 39/51] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/bt_config.sql | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 web/bt_config.sql diff --git a/web/bt_config.sql b/web/bt_config.sql new file mode 100644 index 0000000..3e1dccb --- /dev/null +++ b/web/bt_config.sql @@ -0,0 +1,7 @@ +delete from "STADIUM"."bt_config" where "id" >= 1; +insert into "STADIUM"."bt_config" ("id", "key", "value") values (1, 'baz001', '40000'); +insert into "STADIUM"."bt_config" ("id", "key", "value") values (2, 'BAF055', '1000'); +insert into "STADIUM"."bt_config" ("id", "key", "value") values (3, '110', '8000-12000'); +insert into "STADIUM"."bt_config" ("id", "key", "value") values (4, '210', '8000-12000'); +insert into "STADIUM"."bt_config" ("id", "key", "value") values (5, '310', '6000-10000'); +insert into "STADIUM"."bt_config" ("id", "key", "value") values (6, '510', '1000'); From 7db3147eed66a199888873c7d7dcc5c43e0faf43 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 24 Aug 2023 15:50:52 +0800 Subject: [PATCH 40/51] =?UTF-8?q?type=E6=9C=AA=E8=AE=BE=E7=BD=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index cbe6e87..31c844c 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -46,7 +46,7 @@ class PassFlow { $granularity = $param['granularity']; - $type = $param['type']; + $type = isset($param['type']) ?$param['type']:''; if (empty($granularity)) return ['code' => 0, 'msg' => '缺少参数:granularity']; if (!in_array($granularity,self::$granularity)) return ['code' => 0, 'msg' => '参数错误:granularity']; From 888e9ccec1a0d0759200f4b35c7b2e22b5f1486b Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 25 Aug 2023 16:14:54 +0800 Subject: [PATCH 41/51] =?UTF-8?q?=E5=88=87=E6=8D=A2=20EventSource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ws_task_real.php | 96 ++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/web/ws_task_real.php b/web/ws_task_real.php index 6666cbb..25d1ba7 100644 --- a/web/ws_task_real.php +++ b/web/ws_task_real.php @@ -2,8 +2,14 @@ /** * 总览 */ -use Workerman\Worker; -use Workerman\Timer; + +header("Access-Control-Allow-Origin:*"); +header('X-Accel-Buffering: no'); +header('Content-Type: text/event-stream'); +header('Cache-Control: no-cache'); +ob_end_clean(); +ob_implicit_flush(1); + use app\common\dm\Dm; use app\common\logic\PassFlow; require_once __DIR__ . '/workman/vendor/autoload.php'; @@ -15,42 +21,52 @@ require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; date_default_timezone_set('Asia/Shanghai'); +$dm = new Dm($config['connections']['dm']); + +$xh = 0; +while($xh < 1) { + $data = [ + 'code' => 1, + 'msg' => 'success' + ]; + + # 客流趋势 与 占比 + $allGroupTimeNumDay = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'daily'],$dm); + $allGroupTimeNumMonth = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'monthly'],$dm); + $allGroupTimeNumYear = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'yearly'],$dm); + $data['allGroupTimeNumDay'] = ['data' => $allGroupTimeNumDay]; + $data['allGroupTimeNumMonth'] = ['data' => $allGroupTimeNumMonth]; + $data['allGroupTimeNumYear'] = ['data' => $allGroupTimeNumYear]; + + # 今日各场馆 + $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm)]; + + # 中间总数据 + $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm)]; + + # 各场馆实时 + $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; + + $xh = $xh + 1; + returnEventData($data,"message",$xh); + sleep(3); +} -$worker = new Worker('websocket://0.0.0.0:1234'); -$worker->count = 4; -// 进程启动后定时推送数据给客户端 -$worker->onWorkerStart = function($worker) use($config) { - # 数据库链接不能在主进程,方法外是主进程 - $dm = new Dm($config['connections']['dm']); - // 每2.5秒执行一次 - $time_interval = 3; - Timer::add($time_interval, function()use($worker,$dm){ - foreach($worker->connections as $connection) { - - $data = [ - 'code' => 1, - 'msg' => 'success' - ]; - - # 客流趋势 与 占比 - $allGroupTimeNumDay = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'daily'],$dm); - $allGroupTimeNumMonth = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'monthly'],$dm); - $allGroupTimeNumYear = PassFlow::allGroupTimeNum(['groupsId' => '','granularity' => 'yearly'],$dm); - $data['allGroupTimeNumDay'] = ['data' => $allGroupTimeNumDay]; - $data['allGroupTimeNumMonth'] = ['data' => $allGroupTimeNumMonth]; - $data['allGroupTimeNumYear'] = ['data' => $allGroupTimeNumYear]; - - # 今日各场馆 - $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm)]; - - # 中间总数据 - $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm)]; - - # 各场馆实时 - $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; - - $connection->send(json_encode($data)); - } - }); -}; -Worker::runAll(); \ No newline at end of file +function returnEventData($returnData, $event='message', $id=0, $retry=0) { + $str = ''; + if($id>0) { + $str .= "id: {$id}".PHP_EOL; + } + if($event) { + $str.= "event: {$event}".PHP_EOL; + } + if($retry>0) { + $str .= "retry: {$retry}".PHP_EOL; + } + if(is_array($returnData)) { + $returnData = json_encode($returnData); + } + $str .= "data: {$returnData}".PHP_EOL; + $str .= PHP_EOL; + echo $str; +} \ No newline at end of file From 5b0f51dde66cee3db7b695aca5f379653d5faab7 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 25 Aug 2023 18:38:23 +0800 Subject: [PATCH 42/51] =?UTF-8?q?ws=E6=9B=BF=E6=8D=A2EventSource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ws_task_real.php | 1 - web/ws_task_real_ty.php | 93 +++++++++++++++++++++++------------------ web/ws_task_real_wh.php | 82 +++++++++++++++++++++--------------- 3 files changed, 101 insertions(+), 75 deletions(-) diff --git a/web/ws_task_real.php b/web/ws_task_real.php index 25d1ba7..aed848d 100644 --- a/web/ws_task_real.php +++ b/web/ws_task_real.php @@ -12,7 +12,6 @@ ob_implicit_flush(1); use app\common\dm\Dm; use app\common\logic\PassFlow; -require_once __DIR__ . '/workman/vendor/autoload.php'; require_once __DIR__ . '../../source/application/common/dm/Dm.php'; require_once __DIR__ . '../../source/application/common/logic/PassFlow.php'; require_once __DIR__ . '../../source/thinkphp/helper.php'; diff --git a/web/ws_task_real_ty.php b/web/ws_task_real_ty.php index a19d2b5..907bac2 100644 --- a/web/ws_task_real_ty.php +++ b/web/ws_task_real_ty.php @@ -2,11 +2,17 @@ /** * 体育 */ -use Workerman\Worker; -use Workerman\Timer; + + +header("Access-Control-Allow-Origin:*"); +header('X-Accel-Buffering: no'); +header('Content-Type: text/event-stream'); +header('Cache-Control: no-cache'); +ob_end_clean(); +ob_implicit_flush(1); + use app\common\dm\Dm; use app\common\logic\PassFlow; -require_once __DIR__ . '/workman/vendor/autoload.php'; require_once __DIR__ . '../../source/application/common/dm/Dm.php'; require_once __DIR__ . '../../source/application/common/logic/PassFlow.php'; require_once __DIR__ . '../../source/thinkphp/helper.php'; @@ -15,42 +21,47 @@ require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; date_default_timezone_set('Asia/Shanghai'); +$dm = new Dm($config['connections']['dm']); + +$xh = 0; +while($xh < 1) { + $data = []; + + # 累计服务人数 + $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm,['type' => 1])]; + + # 24小时 + $data['getPassHoursData'] = ['data' => PassFlow::getPassHoursData($dm,['type' => 1])]; + + # 24小时进馆人数 + $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; + + # 各场馆服务人次占比 + $data['allGroupTimeNum'] = ['data' => PassFlow::allGroupTimeNum(['type' => 1,'granularity' => 'daily'],$dm)]; + + # 各场馆服务人次趋势 + $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm,['type' => 1])]; + + $xh = $xh + 1; + returnEventData($data,"message",$xh); + sleep(3); +} -$worker = new Worker('websocket://0.0.0.0:1235'); -$worker->count = 4; -// 进程启动后定时推送数据给客户端 -$worker->onWorkerStart = function($worker) use($config) { - # 数据库链接不能在主进程,方法外是主进程 - $dm = new Dm($config['connections']['dm']); - // 每2.5秒执行一次 - $time_interval = 3; - Timer::add($time_interval, function()use($worker,$dm){ - foreach($worker->connections as $connection) { - $data = []; - # 主动推送对应页面数据 - -// $groupIdArr = []; -// $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 1]); -// foreach ($groupRes as $groupRow) $groupIdArr[] = $groupRow['groupId']; -// $groupIdStr = !empty($groupIdArr) ? implode("|",$groupIdArr) : ''; - - # 累计服务人数 - $data['allGroupNum'] = ['data' => PassFlow::allGroupNum($dm,['type' => 1])]; - - # 24小时 - $data['getPassHoursData'] = ['data' => PassFlow::getPassHoursData($dm,['type' => 1])]; - - # 24小时进馆人数 - $data['realTimeData'] = ['data' => PassFlow::realTimeData($dm)]; - - # 各场馆服务人次占比 - $data['allGroupTimeNum'] = ['data' => PassFlow::allGroupTimeNum(['type' => 1,'granularity' => 'daily'],$dm)]; - - # 各场馆服务人次趋势 - $data['toDayGroupsEnterNum'] = ['data' => PassFlow::toDayGroupsEnterNum($dm,['type' => 1])]; - - $connection->send(json_encode($data)); - } - }); -}; -Worker::runAll(); \ No newline at end of file +function returnEventData($returnData, $event='message', $id=0, $retry=0) { + $str = ''; + if($id>0) { + $str .= "id: {$id}".PHP_EOL; + } + if($event) { + $str.= "event: {$event}".PHP_EOL; + } + if($retry>0) { + $str .= "retry: {$retry}".PHP_EOL; + } + if(is_array($returnData)) { + $returnData = json_encode($returnData); + } + $str .= "data: {$returnData}".PHP_EOL; + $str .= PHP_EOL; + echo $str; +} \ No newline at end of file diff --git a/web/ws_task_real_wh.php b/web/ws_task_real_wh.php index 2c7ce8b..31185a4 100644 --- a/web/ws_task_real_wh.php +++ b/web/ws_task_real_wh.php @@ -2,11 +2,15 @@ /** * 文化 */ -use Workerman\Worker; -use Workerman\Timer; +header("Access-Control-Allow-Origin:*"); +header('X-Accel-Buffering: no'); +header('Content-Type: text/event-stream'); +header('Cache-Control: no-cache'); +ob_end_clean(); +ob_implicit_flush(1); + use app\common\dm\Dm; use app\common\logic\PassFlow; -require_once __DIR__ . '/workman/vendor/autoload.php'; require_once __DIR__ . '../../source/application/common/dm/Dm.php'; require_once __DIR__ . '../../source/application/common/logic/PassFlow.php'; require_once __DIR__ . '../../source/thinkphp/helper.php'; @@ -15,34 +19,46 @@ require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; date_default_timezone_set('Asia/Shanghai'); +$dm = new Dm($config['connections']['dm']); + +$xh = 0; +while($xh < 1) { + $data = []; + + # 主动推送对应页面数据 + + # 累计服务人数 - 24小时服务人次 + $data['allFlowTrends'] = ['data' => PassFlow::allFlowTrends($dm)]; + + # 24小时总服务人次趋势 + $data['getLibraryHours24List'] = ['data' => PassFlow::getLibraryHours24List($dm)]; + + # 各场馆服务人次趋势 + $data['getLibraryGroupHoursList'] = ['data' => PassFlow::getLibraryGroupHoursList($dm)]; + + # 图书馆数据统计 + $data['getLibraryLeaseData'] = ['data' => PassFlow::getLibraryLeaseData($dm)]; + + $xh = $xh + 1; + returnEventData($data,"message",$xh); + sleep(3); +} -$worker = new Worker('websocket://0.0.0.0:1236'); -$worker->count = 4; -// 进程启动后定时推送数据给客户端 -$worker->onWorkerStart = function($worker) use($config) { - # 数据库链接不能在主进程,方法外是主进程 - $dm = new Dm($config['connections']['dm']); - // 每2.5秒执行一次 - $time_interval = 3; - Timer::add($time_interval, function()use($worker,$dm){ - foreach($worker->connections as $connection) { - $data = []; - # 主动推送对应页面数据 - - # 累计服务人数 - 24小时服务人次 - $data['allFlowTrends'] = ['data' => PassFlow::allFlowTrends($dm)]; - - # 24小时总服务人次趋势 - $data['getLibraryHours24List'] = ['data' => PassFlow::getLibraryHours24List($dm)]; - - # 各场馆服务人次趋势 - $data['getLibraryGroupHoursList'] = ['data' => PassFlow::getLibraryGroupHoursList($dm)]; - - # 图书馆数据统计 - $data['getLibraryLeaseData'] = ['data' => PassFlow::getLibraryLeaseData($dm)]; - - $connection->send(json_encode($data)); - } - }); -}; -Worker::runAll(); \ No newline at end of file +function returnEventData($returnData, $event='message', $id=0, $retry=0) { + $str = ''; + if($id>0) { + $str .= "id: {$id}".PHP_EOL; + } + if($event) { + $str.= "event: {$event}".PHP_EOL; + } + if($retry>0) { + $str .= "retry: {$retry}".PHP_EOL; + } + if(is_array($returnData)) { + $returnData = json_encode($returnData); + } + $str .= "data: {$returnData}".PHP_EOL; + $str .= PHP_EOL; + echo $str; +} \ No newline at end of file From 14aa88bfc6cb211083c0bfea43207645322bede6 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 13 Oct 2023 10:09:21 +0800 Subject: [PATCH 43/51] =?UTF-8?q?=E4=BD=93=E8=82=B2=E5=9C=BA=E9=A6=86?= =?UTF-8?q?=E5=90=84=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/create_pass_all.php | 208 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 web/create_pass_all.php diff --git a/web/create_pass_all.php b/web/create_pass_all.php new file mode 100644 index 0000000..1c5fc2c --- /dev/null +++ b/web/create_pass_all.php @@ -0,0 +1,208 @@ + [ + 'name' => '体育场', + 'count' => '354670', + 'day' => '11822', + 'amplitude' => [ + 'min' => '-10640', + 'max' => '17733', + ] + ], + '210' => [ + 'name' => '体育馆', + 'count' => '380343', + 'day' => '12678', + 'amplitude' => [ + 'min' => '-11410', + 'max' => '19017', + ] + ], + '310' => [ + 'name' => '游泳馆', + 'count' => '114346', + 'day' => '3811', + 'amplitude' => [ + 'min' => '-3430', + 'max' => '5717', + ] + ], + '510' => [ + 'name' => '博物馆', + 'count' => '4018', + 'day' => '133', + 'amplitude' => [ + 'min' => '-120', + 'max' => '200', + ] + ] +]; +$monthNum = 6; + + +$returnData = []; +$returnDataAll = []; +foreach ($groupArr as $groupId => $val) { + + $groupName = $val['name']; + $count = $val['count']; + $day = $val['day']; + + # 月总数 + $sumFlowInNum = 0; + + for ($i = 1; $i <= $monthNum; $i++) { + + # 幅度 + $temp_count = rand($val['amplitude']['min'],$val['amplitude']['max']); + + if ($i == 1) { + # 减去假期 + $temp_day = $day * 7; + $temp_count = bcsub($temp_count,$temp_day); + } + + if ($i == 2) { + # 减去未满30 + $temp_day = $day * 2; + $temp_count = bcsub($temp_count,$temp_day); + } + + # 每月数量 + $flowInNum = bcadd($count,$temp_count); + + $sumFlowInNum = bcadd($sumFlowInNum,$flowInNum); + + $iStr = strlen($i) == 1 ? '0'.$i : $i; + + $statTime = "{$y}-{$iStr}-01T00:00:00.000+08:00"; + + $queryWhereAll = ['groupId' => $groupId,'granularity' => 'monthly','statTime' => $statTime,'date'=>'month']; + $queryAll = $dm->find('bt_passenger_flow_all',$queryWhereAll); + + if (!$queryAll) { + + $iArrAll = [ + 'groupId' => $groupId, + 'groupName' => $groupName, + 'flowInNum' => $flowInNum, + 'flowOutNum' => 0, + 'noRepeatInNum' => $flowInNum, + 'noRepeatOutNum' => 0, + 'holdValue' => 0, + 'netValue' => 0, + 'createTime' => strtotime("{$y}-{$iStr}-01 00:00:00") . "000", + 'updateTime' => strtotime("{$y}-{$iStr}-01 00:00:00") . "000", + 'statTime' => $statTime, + 'granularity' => 'monthly', + 'date' => 'month' + ]; + $dm->insert('bt_passenger_flow_all',$iArrAll); + $returnDataAll[] = $iArrAll; + } + + + + + $queryWhere = ['groupId' => $groupId,'granularity' => 'monthly','statTime' => $statTime]; + $query = $dm->find('bt_passenger_flow',$queryWhere); + if (!$query) { + + $iArr = [ + 'groupId' => $groupId, + 'groupName' => $groupName, + 'flowInNum' => $flowInNum, + 'flowOutNum' => 0, + 'noRepeatInNum' => $flowInNum, + 'noRepeatOutNum' => 0, + 'holdValue' => 0, + 'netValue' => 0, + 'createTime' => strtotime("{$y}-{$iStr}-01 00:00:00") . "000", + 'updateTime' => strtotime("{$y}-{$iStr}-01 00:00:00") . "000", + 'statTime' => $statTime, + 'granularity' => 'monthly' + ]; + + $dm->insert('bt_passenger_flow',$iArr); + $returnData[] = $iArr; + } + } + + + # 总的 + + $queryWhereSumAll = ['groupId' => $groupId,'granularity' => 'yearly','statTime' => ['>=',"{$y}-01-01T00:00:00.000+08:00"],'date' => 'year']; + $querySumAll = $dm->find('bt_passenger_flow_all',$queryWhereSumAll); + + if ($querySumAll) { + +// $iArrSumAll = [ +// 'groupId' => $groupId, +// 'groupName' => $groupName, +// 'flowOutNum' => 0, +// 'noRepeatOutNum' => 0, +// 'holdValue' => 0, +// 'netValue' => 0, +// 'flowInNum' => bcadd(0,$sumFlowInNum), +// 'noRepeatInNum' => bcadd(0,$sumFlowInNum), +// 'createTime' => strtotime("{$y}--01-01 00:00:00") . "000", +// 'updateTime' => strtotime("{$y}--01-01 00:00:00") . "000", +// 'statTime' => "{$y}-01-01T00:00:00.000+08:00", +// 'granularity' => 'yearly', +// 'date' => 'year' +// ]; +// $returnDataAll[] = $iArrSumAll; + + $updateAll = [ + 'flowInNum' => bcadd($querySumAll['flowInNum'],$sumFlowInNum), + 'noRepeatInNum' => bcadd($querySumAll['noRepeatInNum'],$sumFlowInNum), + ]; + + $dm->update('bt_passenger_flow_all',$updateAll,'"id" = ' . "'{$querySumAll['id']}'"); + } + + $queryWhereSum = ['groupId' => $groupId,'granularity' => 'yearly','statTime' => ['>=',"{$y}-01-01T00:00:00.000+08:00"]]; + $querySum = $dm->find('bt_passenger_flow',$queryWhereSum); + + if ($querySum) { + +// $iArrSum = [ +// 'groupId' => $groupId, +// 'groupName' => $groupName, +// 'flowOutNum' => 0, +// 'noRepeatOutNum' => 0, +// 'holdValue' => 0, +// 'netValue' => 0, +// 'flowInNum' => bcadd(0,$sumFlowInNum), +// 'noRepeatInNum' => bcadd(0,$sumFlowInNum), +// 'createTime' => strtotime("{$y}--01-01 00:00:00") . "000", +// 'updateTime' => strtotime("{$y}--01-01 00:00:00") . "000", +// 'statTime' => "{$y}-01-01T00:00:00.000+08:00", +// 'granularity' => 'yearly' +// ]; +// +// $returnData[] = $iArrSum; + $update = [ + 'flowInNum' => bcadd($querySum['flowInNum'],$sumFlowInNum), + 'noRepeatInNum' => bcadd($querySum['noRepeatInNum'],$sumFlowInNum), + ]; + + $dm->update('bt_passenger_flow',$update,'"id" = ' . "'{$querySum['id']}'"); + } +} + +//var_dump($returnData); +//var_dump($returnDataAll); +echo true; \ No newline at end of file From 3140a0a0729bc7b4111660f0b0702726c4c78308 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 13 Oct 2023 15:15:08 +0800 Subject: [PATCH 44/51] =?UTF-8?q?=E6=96=87=E5=8C=96=E7=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/create_bt_library_data.php | 158 +++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 web/create_bt_library_data.php diff --git a/web/create_bt_library_data.php b/web/create_bt_library_data.php new file mode 100644 index 0000000..24fd94c --- /dev/null +++ b/web/create_bt_library_data.php @@ -0,0 +1,158 @@ + [ + 'name' => '图书馆', + 'count' => $countBaz, + 'day' => round($countBaz / 30), + 'amplitude' => [ + 'min' => 0 - ($countBaz * 0.03), + 'max' => $countBaz * 0.05, + ] + ], + 'BAF055' => [ + 'name' => '文化馆', + 'count' => $countBaf, + 'day' => round($countBaf / 30), + 'amplitude' => [ + 'min' => 0 - ($countBaf * 0.03), + 'max' => $countBaf * 0.05, + ] + ], +]; + +$monthNum = 6; +$countBaz = [ + 'baz001' => ['incount' => 0, 'outcount' => 0], + 'BAF055' => ['incount' => 0, 'outcount' => 0] +]; + +for ($i = 1; $i <= $monthNum; $i++) { + + $str = strlen($i) == 1 ? '0' . $i : $i; + $incount = 0; + $outcount = 0; + + foreach ($data as $group_id => $item) { + + $name = $item['name']; + $count = $item['count']; + $day = $item['day']; + + # 幅度 + $temp_count = rand($item['amplitude']['min'],$item['amplitude']['max']); + + if ($i == 1) { + # 减去假期 + $temp_day = $day * 7; + $temp_count = bcsub($temp_count,$temp_day); + } + + if ($i == 2) { + # 减去未满30 + $temp_day = $day * 2; + $temp_count = bcsub($temp_count,$temp_day); + } + + # 每月数量 + $flowInNum = bcadd($count,$temp_count); + + $days = date('t', strtotime(2023 . '-' . $str . '-01')); + $start = date("Y-{$str}-01 ") ."00:00:00"; + $end = date("Y-{$str}-{$days} ") ."23:59:59"; + $queryWhere = ' "date" = ' . "'month'" . ' and "group_id" = ' . "'{$group_id}'" . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'" ; + $query = $dm->find('bt_library_data',$queryWhere); + + if (!$query) { + $insert_data = [ + 'group_id' => $group_id, + 'group_name' => $name, + 'incount' => $flowInNum, + 'outcount' => bcadd($flowInNum,rand(0, 10)), + 'date' => 'month', + 'create_time' => date("Y-{$str}-01 ") . "00:00:00", + 'last_incount' => 0, + 'last_outcount' => 0, + ]; + $dm->insert('bt_library_data', $insert_data); + + + # 当月总数 + $incount += $insert_data['incount']; + $outcount += $insert_data['outcount']; + + # 总年 + $countBaz[$group_id]['incount'] += $insert_data['incount']; + $countBaz[$group_id]['outcount'] += $insert_data['outcount']; + } + } + $queryWhere2 = ' "date" = ' . "'month'" . ' and "group_id" = ' . "'lib001'" . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'" ; + $query2 = $dm->find('bt_library_data',$queryWhere2); + if (!$query2) { + $lib001 = [ + 'group_id' => 'lib001', + 'group_name' => '文化', + 'incount' => $incount, + 'outcount' => $outcount, + 'date' => 'month', + 'create_time' => date("Y-{$str}-01 ") . "00:00:00", + 'last_incount' => 0, + 'last_outcount' => 0, + ]; + $dm->insert('bt_library_data', $lib001); + } +} + + + +// --------------- baz001 --------------- // +$queryWhereBaz = ['date' => 'year', 'group_id' => 'baz001', 'create_time' => ['>=',date("Y-01-01 ") ."00:00:00"]]; +$queryBaz = $dm->find("bt_library_data",$queryWhereBaz); + +if ($queryBaz) { + $baz001 = [ + 'incount' => bcadd($queryBaz['incount'],$countBaz['baz001']['incount']), + 'outcount' => bcadd($queryBaz['outcount'],$countBaz['baz001']['outcount']) + ]; + $dm->update('bt_library_data',$baz001,'"id" = ' . "'{$queryBaz['id']}'"); +} + +// --------------- BAF055 --------------- // +$queryWhereBaf = ['date' => 'year', 'group_id' => 'BAF055', 'create_time' => ['>=',date("Y-01-01 ") ."00:00:00"]]; +$queryBaf = $dm->find("bt_library_data",$queryWhereBaf); + +if ($queryBaf) { + + $BAF055 = [ + 'incount' => bcadd($queryBaf['incount'],$countBaz['BAF055']['incount']), + 'outcount' => bcadd($queryBaf['outcount'],$countBaz['BAF055']['outcount']) + ]; + $dm->update('bt_library_data',$BAF055,'"id" = ' . "'{$queryBaf['id']}'"); +} + +// --------------- lib001 --------------- // +$queryWhereLib = ['date' => 'year', 'group_id' => 'lib001', 'create_time' => ['>=',date("Y-01-01 ") ."00:00:00"]]; +$queryLib = $dm->find("bt_library_data",$queryWhereLib); +if ($queryLib) { + + $lib001 = [ + 'incount' => $baz001['incount'] + $BAF055['incount'], + 'outcount' => $baz001['outcount'] + $BAF055['outcount'] + ]; + $dm->update('bt_library_data',$lib001,'"id" = ' . "'{$queryLib['id']}'"); +} + +echo true; \ No newline at end of file From a4a6c2b2e4d03cd75dbb6f362a7f892b929e5abc Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 13 Oct 2023 16:13:27 +0800 Subject: [PATCH 45/51] 7 --- web/create_bt_library_data.php | 2 +- web/create_pass_all.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/create_bt_library_data.php b/web/create_bt_library_data.php index 24fd94c..658b89c 100644 --- a/web/create_bt_library_data.php +++ b/web/create_bt_library_data.php @@ -34,7 +34,7 @@ $data = [ ], ]; -$monthNum = 6; +$monthNum = 7; $countBaz = [ 'baz001' => ['incount' => 0, 'outcount' => 0], 'BAF055' => ['incount' => 0, 'outcount' => 0] diff --git a/web/create_pass_all.php b/web/create_pass_all.php index 1c5fc2c..2caeb8b 100644 --- a/web/create_pass_all.php +++ b/web/create_pass_all.php @@ -49,7 +49,7 @@ $groupArr = [ ] ] ]; -$monthNum = 6; +$monthNum = 7; $returnData = []; From ee8e2abca88fd4bb463d9bbfccec522abc13780b Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 13 Oct 2023 16:56:00 +0800 Subject: [PATCH 46/51] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/pass/Create.php | 30 ++++++++++++++++++- web/create_bt_library_data.php | 4 +-- web/create_pass_all.php | 4 +++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index 9a88448..7ebcd57 100644 --- a/source/application/api/controller/pass/Create.php +++ b/source/application/api/controller/pass/Create.php @@ -58,6 +58,7 @@ class Create extends Controller ]; if ($query) { + $this->mergeYearlyData($insert_arr); # 判断数据是否发生变化, 发生变化及更新 $queryUpdate = $dm->find('bt_passenger_flow',$insert_arr); if (!$queryUpdate) { @@ -108,7 +109,7 @@ class Create extends Controller ]; if ($query) { - + $this->mergeYearlyData($insert_arr); $updateQuery = $dm->find('bt_passenger_flow_all',$insert_arr); if (!$updateQuery) { $dm->update('bt_passenger_flow_all',$insert_arr,['id' => $query['id']]); @@ -123,6 +124,33 @@ class Create extends Controller return $this->renderSuccess(); } + protected function mergeYearlyData(&$val) + { + if ($val['granularity'] == 'yearly' && date("Y") == '2023') { + $mergeData = [ + '110' => [ + 'flowInNum' => 0, + 'noRepeatInNum' => 0, + ], + '210' => [ + 'flowInNum' => 0, + 'noRepeatInNum' => 0, + ], + '310' => [ + 'flowInNum' => 0, + 'noRepeatInNum' => 0, + ], + '510' => [ + 'flowInNum' => 0, + 'noRepeatInNum' => 0, + ], + ]; + + $val['flowInNum'] = bcadd($val['flowInNum'],$mergeData[$val['groupId']]['flowInNum']); + $val['noRepeatInNum'] = bcadd($val['noRepeatInNum'],$mergeData[$val['groupId']]['noRepeatInNum']); + } + } + /** * 创建总客流统计数据 * @return array diff --git a/web/create_bt_library_data.php b/web/create_bt_library_data.php index 658b89c..221bbc1 100644 --- a/web/create_bt_library_data.php +++ b/web/create_bt_library_data.php @@ -10,8 +10,8 @@ $config = require_once __DIR__ . '../../source/application/database.php'; $dm = new Dm($config['connections']['dm']); -$countBaz = '200000'; -$countBaf = '50000'; +$countBaz = '376378'; +$countBaf = '28100'; $data = [ 'baz001' => [ diff --git a/web/create_pass_all.php b/web/create_pass_all.php index 2caeb8b..a5bd892 100644 --- a/web/create_pass_all.php +++ b/web/create_pass_all.php @@ -201,6 +201,10 @@ foreach ($groupArr as $groupId => $val) { $dm->update('bt_passenger_flow',$update,'"id" = ' . "'{$querySum['id']}'"); } + + echo "
    ";
    +    var_dump($groupId);
    +    var_dump($sumFlowInNum);
     }
     
     //var_dump($returnData);
    
    From 84ab3fcc94766b7ea3077d1c2db5b55b407e939f Mon Sep 17 00:00:00 2001
    From: wanghongjun <1445693971@qq,com>
    Date: Fri, 13 Oct 2023 18:18:43 +0800
    Subject: [PATCH 47/51] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=95=B0=E6=8D=AE?=
     =?UTF-8?q?=E4=BC=98=E5=8C=96?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     .../application/api/controller/pass/Create.php   |  4 ++--
     source/application/common/logic/PassFlow.php     |  8 +++++++-
     web/create_bt_library_data.php                   | 16 ++++++++--------
     web/create_pass_all.php                          | 16 ++++++++--------
     4 files changed, 25 insertions(+), 19 deletions(-)
    
    diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php
    index 7ebcd57..13af68c 100644
    --- a/source/application/api/controller/pass/Create.php
    +++ b/source/application/api/controller/pass/Create.php
    @@ -146,8 +146,8 @@ class Create extends Controller
                     ],
                 ];
     
    -            $val['flowInNum'] = bcadd($val['flowInNum'],$mergeData[$val['groupId']]['flowInNum']);
    -            $val['noRepeatInNum'] = bcadd($val['noRepeatInNum'],$mergeData[$val['groupId']]['noRepeatInNum']);
    +            $val['flowInNum'] = round($val['flowInNum']+$mergeData[$val['groupId']]['flowInNum']);
    +            $val['noRepeatInNum'] = round($val['noRepeatInNum']+$mergeData[$val['groupId']]['noRepeatInNum']);
             }
         }
     
    diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php
    index 31c844c..e3c50b4 100644
    --- a/source/application/common/logic/PassFlow.php
    +++ b/source/application/common/logic/PassFlow.php
    @@ -320,7 +320,13 @@ class PassFlow
                 $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;
    +
    +            $start = date("Y-01-01 00:00:00",time());
    +            $end = date("Y-12-31 23:59:59",time());
    +            $libraryDataYearWhere = ' "date" = ' . "'year'" . ' and "group_id" = ' . "'lib001'" . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'";
    +            $libraryDataYear = $dm->find('bt_library_data',$libraryDataYearWhere);
    +            $returnData['year']['noRepeatInNum'] += isset($libraryDataYear['incount']) ? $libraryDataYear['incount'] : 0;
    +
     //            $returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0;
                 # 文化总年度
                 $libraryData = $dm->find('bt_library_data',['group_id' => 'lib001','date' => 'year'],'SUM("incount") as NUM');
    diff --git a/web/create_bt_library_data.php b/web/create_bt_library_data.php
    index 221bbc1..970afbf 100644
    --- a/web/create_bt_library_data.php
    +++ b/web/create_bt_library_data.php
    @@ -58,17 +58,17 @@ for ($i = 1; $i <= $monthNum; $i++) {
             if ($i == 1) {
                 # 减去假期
                 $temp_day = $day * 7;
    -            $temp_count = bcsub($temp_count,$temp_day);
    +            $temp_count = round($temp_count-$temp_day);
             }
     
             if ($i == 2) {
                 # 减去未满30
                 $temp_day = $day * 2;
    -            $temp_count = bcsub($temp_count,$temp_day);
    +            $temp_count = round($temp_count-$temp_day);
             }
     
             # 每月数量
    -        $flowInNum = bcadd($count,$temp_count);
    +        $flowInNum = round($count+$temp_count);
     
             $days = date('t', strtotime(2023 . '-' . $str . '-01'));
             $start = date("Y-{$str}-01 ") ."00:00:00";
    @@ -81,7 +81,7 @@ for ($i = 1; $i <= $monthNum; $i++) {
                     'group_id'      => $group_id,
                     'group_name'    => $name,
                     'incount'       => $flowInNum,
    -                'outcount'      => bcadd($flowInNum,rand(0, 10)),
    +                'outcount'      => round($flowInNum+rand(0, 10)),
                     'date'          => 'month',
                     'create_time'   => date("Y-{$str}-01 ") . "00:00:00",
                     'last_incount'  => 0,
    @@ -124,8 +124,8 @@ $queryBaz = $dm->find("bt_library_data",$queryWhereBaz);
     
     if ($queryBaz) {
         $baz001 = [
    -        'incount' => bcadd($queryBaz['incount'],$countBaz['baz001']['incount']),
    -        'outcount' => bcadd($queryBaz['outcount'],$countBaz['baz001']['outcount'])
    +        'incount' => round($queryBaz['incount']+$countBaz['baz001']['incount']),
    +        'outcount' => round($queryBaz['outcount']+$countBaz['baz001']['outcount'])
         ];
         $dm->update('bt_library_data',$baz001,'"id" = ' . "'{$queryBaz['id']}'");
     }
    @@ -137,8 +137,8 @@ $queryBaf = $dm->find("bt_library_data",$queryWhereBaf);
     if ($queryBaf) {
     
         $BAF055 = [
    -        'incount' => bcadd($queryBaf['incount'],$countBaz['BAF055']['incount']),
    -        'outcount' => bcadd($queryBaf['outcount'],$countBaz['BAF055']['outcount'])
    +        'incount' => round($queryBaf['incount']+$countBaz['BAF055']['incount']),
    +        'outcount' => round($queryBaf['outcount']+$countBaz['BAF055']['outcount'])
         ];
         $dm->update('bt_library_data',$BAF055,'"id" = ' . "'{$queryBaf['id']}'");
     }
    diff --git a/web/create_pass_all.php b/web/create_pass_all.php
    index a5bd892..747099a 100644
    --- a/web/create_pass_all.php
    +++ b/web/create_pass_all.php
    @@ -71,19 +71,19 @@ foreach ($groupArr as $groupId => $val) {
             if ($i == 1) {
                 # 减去假期
                 $temp_day = $day * 7;
    -            $temp_count = bcsub($temp_count,$temp_day);
    +            $temp_count = round($temp_count-$temp_day);
             }
     
             if ($i == 2) {
                 # 减去未满30
                 $temp_day = $day * 2;
    -            $temp_count = bcsub($temp_count,$temp_day);
    +            $temp_count = round($temp_count-$temp_day);
             }
     
             # 每月数量
    -        $flowInNum = bcadd($count,$temp_count);
    +        $flowInNum = round($count+$temp_count);
     
    -        $sumFlowInNum = bcadd($sumFlowInNum,$flowInNum);
    +        $sumFlowInNum = round($sumFlowInNum+$flowInNum);
     
             $iStr = strlen($i) == 1 ? '0'.$i : $i;
     
    @@ -166,8 +166,8 @@ foreach ($groupArr as $groupId => $val) {
     //        $returnDataAll[] = $iArrSumAll;
     
             $updateAll = [
    -            'flowInNum' => bcadd($querySumAll['flowInNum'],$sumFlowInNum),
    -            'noRepeatInNum' => bcadd($querySumAll['noRepeatInNum'],$sumFlowInNum),
    +            'flowInNum' => round($querySumAll['flowInNum']+$sumFlowInNum),
    +            'noRepeatInNum' => round($querySumAll['noRepeatInNum']+$sumFlowInNum),
             ];
     
             $dm->update('bt_passenger_flow_all',$updateAll,'"id" = ' . "'{$querySumAll['id']}'");
    @@ -195,8 +195,8 @@ foreach ($groupArr as $groupId => $val) {
     //
     //        $returnData[] = $iArrSum;
             $update = [
    -            'flowInNum' => bcadd($querySum['flowInNum'],$sumFlowInNum),
    -            'noRepeatInNum' => bcadd($querySum['noRepeatInNum'],$sumFlowInNum),
    +            'flowInNum' => round($querySum['flowInNum']+$sumFlowInNum),
    +            'noRepeatInNum' => round($querySum['noRepeatInNum']+$sumFlowInNum),
             ];
     
             $dm->update('bt_passenger_flow',$update,'"id" = ' . "'{$querySum['id']}'");
    
    From db8816c1a2cac6b4848ce575ece11876b4bd3929 Mon Sep 17 00:00:00 2001
    From: wanghongjun <1445693971@qq,com>
    Date: Mon, 23 Oct 2023 15:22:30 +0800
    Subject: [PATCH 48/51] =?UTF-8?q?=E5=87=8F=E5=8E=BB250=E4=B8=87=E8=99=9A?=
     =?UTF-8?q?=E6=8B=9F=E6=95=B0=E6=8D=AE?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     web/handle_data.php | 242 ++++++++++++++++++++++++++++++++++++++++++++
     1 file changed, 242 insertions(+)
     create mode 100644 web/handle_data.php
    
    diff --git a/web/handle_data.php b/web/handle_data.php
    new file mode 100644
    index 0000000..c5043d5
    --- /dev/null
    +++ b/web/handle_data.php
    @@ -0,0 +1,242 @@
    +
    +$tyc = get_pass($dm,'210',$y,$monthNum); // 体育馆 <-- replace -->
    +$yyg = get_pass($dm,'310',$y,$monthNum); // 游泳馆 <-- replace -->
    +$bwg = get_pass($dm,'510',$y,$monthNum); // 劳务博物馆 <-- replace -->
    +$tsg = get_lib($dm,'baz001',$y,$monthNum); // 图书馆 <-- replace -->
    +$whg = get_lib($dm,'BAF055',$y,$monthNum); // 文化馆 <-- replace -->
    +
    +$allSum = $tyg + $tyc + $yyg + $bwg + $tsg + $whg;
    +
    +
    +$tyHandleData = [
    +    '110' => round($tyg/$allSum,4),
    +    '210' => round($tyc/$allSum,4),
    +    '310' => round($yyg/$allSum,4),
    +    '510' => round($bwg/$allSum,4)
    +];
    +
    +$whHandleData = [
    +    'baz001' => round($tsg/$allSum,4),
    +    'BAF055' => round($whg/$allSum,4)
    +];
    +
    +# ---------------------------- 体育 ----------------------------- #
    +
    +foreach ($tyHandleData as $groupId => $rate) {
    +
    +    $tyYearSum = 0;
    +
    +    # 月度
    +    for ($i = 1; $i <= $monthNum; $i++) {
    +
    +        $flowInNum = round($sumNum * $rate / $monthNum);
    +
    +        $tyYearSum += $flowInNum;
    +
    +        $iStr = strlen($i) == 1 ? '0'.$i : $i;
    +
    +        $statTime = "{$y}-{$iStr}-01T00:00:00.000+08:00";
    +
    +        $queryWhereAll = ['groupId' => $groupId,'granularity' => 'monthly','statTime' => $statTime,'date'=>'month'];
    +        $queryAll = $dm->find('bt_passenger_flow_all',$queryWhereAll);
    +        if ($queryAll) {
    +
    +            $upData = [
    +                'flowInNum' => $queryAll['flowInNum'] - $flowInNum,
    +                'noRepeatInNum' => $queryAll['noRepeatInNum'] - $flowInNum
    +            ];
    +            $dm->update('bt_passenger_flow_all',$upData,'"id" = ' . "'{$queryAll['id']}'");
    +        }
    +
    +        $queryWhere = ['groupId' => $groupId,'granularity' => 'monthly','statTime' => $statTime];
    +        $query = $dm->find('bt_passenger_flow',$queryWhere);
    +
    +        if ($query) {
    +
    +            $upData = [
    +                'flowInNum' => $query['flowInNum'] - $flowInNum,
    +                'noRepeatInNum' => $query['noRepeatInNum'] - $flowInNum
    +            ];
    +            $dm->update('bt_passenger_flow',$upData,'"id" = ' . "'{$query['id']}'");
    +        }
    +    }
    +
    +    # 年度
    +    $queryWhereSumAll = ['groupId' => $groupId,'granularity' => 'yearly','statTime' => ['>=',"{$y}-01-01T00:00:00.000+08:00"],'date' => 'year'];
    +    $querySumAll = $dm->find('bt_passenger_flow_all',$queryWhereSumAll);
    +
    +    if ($querySumAll) {
    +        $updateAll = [
    +            'flowInNum' => $querySumAll['flowInNum'] - $tyYearSum,
    +            'noRepeatInNum' => $querySumAll['noRepeatInNum'] - $tyYearSum,
    +        ];
    +
    +        $dm->update('bt_passenger_flow_all',$updateAll,'"id" = ' . "'{$querySumAll['id']}'");
    +    }
    +
    +    $queryWhereSum = ['groupId' => $groupId,'granularity' => 'yearly','statTime' => ['>=',"{$y}-01-01T00:00:00.000+08:00"]];
    +    $querySum = $dm->find('bt_passenger_flow',$queryWhereSum);
    +
    +    if ($querySum) {
    +
    +        $update = [
    +            'flowInNum' => $querySum['flowInNum'] - $tyYearSum,
    +            'noRepeatInNum' => $querySum['noRepeatInNum']- $tyYearSum,
    +        ];
    +
    +        $dm->update('bt_passenger_flow',$update,'"id" = ' . "'{$querySum['id']}'");
    +    }
    +    echo $groupId;
    +    echo "
    "; + echo $tyYearSum; + echo "
    "; + echo "----------------------------------"; + echo "
    "; +} +echo "

    体育结束....

    "; +# ---------------------------- 体育end ----------------------------- # + +# ---------------------------- 文化 ----------------------------- # + +$whYearSum = [ + 'baz001' => 0, + 'BAF055' => 0, + 'lib001' => 0 +]; + +$whMonthRate = []; + +foreach ($whHandleData as $group_id => $whRate) { + + + $groupData = []; + $groupDataSumNum = 0; + for ($i = 1; $i <= $monthNum; $i++) { + + $str = strlen($i) == 1 ? '0' . $i : $i; + + $days = date('t', strtotime($y . '-' . $str . '-01')); + $start = date("{$y}-{$str}-01 ") ."00:00:00"; + $end = date("{$y}-{$str}-{$days} ") ."23:59:59"; + $queryWhere = ' "date" = ' . "'month'" . ' and "group_id" = ' . "'{$group_id}'" . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'"; + $query = $dm->find('bt_library_data', $queryWhere); + if ($query) { + $groupData[$i]['id'] = $query['id']; + $groupData[$i]['incount'] = $query['incount']; + $groupData[$i]['outcount'] = $query['outcount']; + $groupDataSumNum += $query['incount']; + } + } + + foreach ($groupData as &$item) { + $item['rate'] = round($item['incount']/$groupDataSumNum,4); + } + + $whMonthRate[$group_id] = $groupData; +} + +# 文化月度 +for ($i = 1; $i <= $monthNum; $i++) { + + $str = strlen($i) == 1 ? '0' . $i : $i; + + $libInCount = 0; + + $days = date('t', strtotime($y . '-' . $str . '-01')); + $start = date("{$y}-{$str}-01 ") ."00:00:00"; + $end = date("{$y}-{$str}-{$days} ") ."23:59:59"; + + foreach ($whHandleData as $group_id => $whRate) { + + $query = $whMonthRate[$group_id][$i]; + + if ($query) { + + $incount = round($sumNum * $whRate * $query['rate']); + + $libInCount += $incount; + $whYearSum[$group_id] += $incount; + + $upData = [ + 'incount' => $query['incount'] - $incount, + 'outcount' => $query['outcount'] - $incount, + ]; + + $dm->update('bt_library_data',$upData,'"id" = ' . "'{$query['id']}'"); + } + } + + $queryWhere2 = ' "date" = ' . "'month'" . ' and "group_id" = ' . "'lib001'" . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'" ; + $query2 = $dm->find('bt_library_data',$queryWhere2); + if ($query2) { + + $whYearSum['lib001'] += $libInCount; + + $lib001 = [ + 'incount' => $query2['incount'] - $libInCount, + 'outcount' => $query2['outcount'] - $libInCount + ]; + $dm->update('bt_library_data', $lib001,'"id" = ' . "'{$query2['id']}'"); + } +} + +# 文化年度 +foreach ($whYearSum as $group_id => $yearSumInCount) { + + $whQueryWhere = ['date' => 'year', 'group_id' => $group_id, 'create_time' => ['>=',date("Y-01-01 ") ."00:00:00"]]; + $whQuery = $dm->find("bt_library_data",$whQueryWhere); + + if ($whQuery) { + $baz001 = [ + 'incount' => $whQuery['incount'] - $yearSumInCount, + 'outcount' => $whQuery['outcount'] - $yearSumInCount + ]; + $dm->update('bt_library_data',$baz001,'"id" = ' . "'{$whQuery['id']}'"); + } + echo $group_id; + echo "
    "; + echo $yearSumInCount; + echo "
    "; + echo "----------------------------------"; + echo "
    "; +} +echo "

    文化结束....

    "; + +# ---------------------------- 文化end ----------------------------- # + +function get_lib($dm,$group_id,$y,$month) { + $str = strlen($month) == 1 ? '0' . $month : $month; + $days = date('t', strtotime($y . '-' . $str . '-01')); + $start = date("{$y}-01-01 ") ."00:00:00"; + $end = date("{$y}-{$str}-{$days} ") ."23:59:59"; + + $whQueryWhere = ' "date" = ' . "'month'" . ' and "group_id" = ' . "'{$group_id}'" . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'" ; + $whQuery = $dm->find("bt_library_data",$whQueryWhere,'SUM("incount") as sum_incount'); + return $whQuery ? $whQuery['SUM_INCOUNT'] : 0; +} + +function get_pass($dm,$groupId,$y,$month) { + $str = strlen($month) == 1 ? '0' . $month : $month; + $days = date('t', strtotime($y . '-' . $str . '-01')); + $start = date("{$y}-01-01") ."T00:00:00.000+08:00"; + $end = date("{$y}-{$str}-{$days}") ."T23:59:59.000+08:00"; + $tyQueryWhere = ' "date" = ' . "'month'" . ' and "granularity" = ' . "'monthly'" . ' and "groupId" = ' . "'{$groupId}'" . ' and "statTime" >= ' . "'{$start}'" . ' and "statTime" <= ' . "'{$end}'" ; + $tyQuery = $dm->find("bt_passenger_flow_all",$tyQueryWhere,'SUM("flowInNum") as sum_incount'); + return $tyQuery ? $tyQuery['SUM_INCOUNT'] : 0; +} \ No newline at end of file From 809071423bb920b092d4711d1be44b33e4c21919 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 23 Oct 2023 15:24:31 +0800 Subject: [PATCH 49/51] =?UTF-8?q?=E5=87=8F=E5=8E=BB250=E4=B8=87=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/handle_data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/handle_data.php b/web/handle_data.php index c5043d5..bc360c3 100644 --- a/web/handle_data.php +++ b/web/handle_data.php @@ -5,8 +5,8 @@ require_once __DIR__ . '../../source/thinkphp/helper.php'; require_once __DIR__ . '../../source/thinkphp/library/think/Config.php'; require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; - - +# 不使用是关闭 第9行 +exit(); $dm = new Dm($config['connections']['dm']); $sumNum = 2500000; From 742de7d5ce5f3e0b9dd0b7f3578982bba87c3401 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 24 Oct 2023 09:54:23 +0800 Subject: [PATCH 50/51] =?UTF-8?q?=E6=96=B0=E7=BB=9F=E8=AE=A1=E7=BB=84?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 1 + 1 file changed, 1 insertion(+) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index e3c50b4..b416cb5 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -371,6 +371,7 @@ class PassFlow $returnData = []; foreach ($data as $groupId => $val) { + if (!isset($groupThreshold[$groupId])) continue; $threshold = $groupThreshold[$groupId]; if (is_array($threshold)) { $interval = self::getIntervalType($val['holdValue'],$threshold['min'],$threshold['max']); From 351f18b9839a70df41bc50b5ca408521f01dafa3 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 7 Nov 2023 16:14:54 +0800 Subject: [PATCH 51/51] =?UTF-8?q?=E6=96=87=E5=8C=96=E9=A6=86=E5=B9=B4?= =?UTF-8?q?=E5=BA=A6=E6=80=BB=E6=95=B0=E6=8D=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/common/logic/PassFlow.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index b416cb5..ac3d61c 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -526,6 +526,16 @@ class PassFlow return $data; } + protected static function getWhYearData($dm,$group_id) + { + $start = date("Y-01-01 ") ."00:00:00"; + $end = date("Y-12-31 ") ."23:59:59"; + $where = ' "date" = ' . "'year'" . ' and "group_id" = ' . "'{$group_id}'" + . ' and "create_time" >= ' . "'{$start}'" . ' and "create_time" <= ' . "'{$end}'"; + $libData = $dm->find('bt_library_data',$where,'incount'); + return $libData['incount'] ?: 0; + } + /** * 文化-博物-图书-数据接口 总计服务人数 * @return array @@ -542,7 +552,7 @@ class PassFlow $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; + $ts_year_incount = self::getWhYearData($dm,'baz001'); # 劳务博物馆数据 $dateArr = ['day' => 'daily', 'month' => 'monthly', 'year' => 'yearly']; @@ -563,7 +573,7 @@ class PassFlow $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; + $wh_year_incount = self::getWhYearData($dm,'BAF055'); # 总年、月、日总数 $sum_today_incount = $ts_today_incount + $bw_today_incount + $wh_today_incount;