diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index 9a88448..13af68c 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'] = round($val['flowInNum']+$mergeData[$val['groupId']]['flowInNum']); + $val['noRepeatInNum'] = round($val['noRepeatInNum']+$mergeData[$val['groupId']]['noRepeatInNum']); + } + } + /** * 创建总客流统计数据 * @return array diff --git a/source/application/api/controller/pass/Statistics.php b/source/application/api/controller/pass/Statistics.php new file mode 100644 index 0000000..f6f762c --- /dev/null +++ b/source/application/api/controller/pass/Statistics.php @@ -0,0 +1,124 @@ +password)); + return $xtToken === $token; + } + + /** + * 获取年各场馆统计数据 + * @return array + */ + public function getYearVenueData() + { + $year = $this->request->param('year') ?: date('Y'); + $token = $this->request->param('token'); + if (!is_numeric($year)) return $this->renderError('请求失败'); + if (empty($token)) return $this->renderError('请求失败'); + if (!$this->validateUserToken($token)) return $this->renderError('请求验证不通过'); + + $dm = new Dm(); + + $start_time = "{$year}-01-01" . 'T00:00:00.000+08:00'; + $end_time = "{$year}-12-31" . 'T23:59:59.000+08:00'; + $yearWhere = '"date" =' . "'month'" + . ' and "granularity"=' . "'monthly'" + . ' and "statTime">=' . "'{$start_time}'" + . ' and "statTime"<=' . "'{$end_time}'"; + + # 体育馆 体育场 劳务博物馆 游泳场馆 + $tyData = []; + + $tyResult = $dm->select('bt_passenger_flow_all',$yearWhere,'"groupId","flowInNum","statTime"'); + foreach ($tyResult as $item) { + + $groupId = $item['groupId']; + $month = date("m", strtotime($item['statTime'])); + + if (!isset($tyData[$groupId]['sum_year'])) $tyData[$groupId]['sum_year'] = 0; + $tyData[$groupId]['sum_year'] += $item['flowInNum']; + + if (!isset($tyData[$groupId]['month'][$month])) $tyData[$groupId]['month'][$month] = 0; + $tyData[$groupId]['month'][$month] += $item['flowInNum']; + } + + $data = [ + 'yearDate' => $year, + 'dataResult' => [] + ]; + + foreach ($tyData as $groupId => $monthData) { + + + $getGroup = $dm->find('bt_passenger_monitor_group',' "groupId" = ' . "'{$groupId}'"); + $groupName = $getGroup['groupName'] ?: ''; + $tempData = [ + 'name' => $groupName, + 'year' => $monthData['sum_year'], + 'monthDate' => [] + ]; + ksort($monthData['month']); + foreach ($monthData['month'] as $month => $value) { + $tempData['monthDate'][] = [ + 'month' => $month, + 'value' => $value + ]; + } + $data['dataResult'][] = $tempData; + } + + # 文化馆 图书馆 + $start_time = "{$year}-01-01 00:00:00"; + $end_time = "{$year}-12-31 23:59:59"; + $whWhere = '"date"=' . "'month'" + .' and "group_id"<>' . "'lib001'" + .' and "create_time">=' . "'{$start_time}'" + .' and "create_time"<=' . "'{$end_time}'"; + $whResult = $dm->select('bt_library_data',$whWhere,'"group_id","group_name","incount","create_time"'); + $whData = []; + $whGroupName = []; + + foreach ($whResult as $item) { + $groupId = $item['group_id']; + $month = date("m", strtotime($item['create_time'])); + $whGroupName[$groupId] = $item['group_name']; + + if (!isset($whData[$groupId]['sum_year'])) $whData[$groupId]['sum_year'] = 0; + $whData[$groupId]['sum_year'] += $item['incount']; + + if (!isset($whData[$groupId]['month'][$month])) $whData[$groupId]['month'][$month] = 0; + $whData[$groupId]['month'][$month] += $item['incount']; + } + + foreach ($whData as $groupId => $monthData) { + + $groupName = isset($whGroupName[$groupId]) ? $whGroupName[$groupId] : ''; + + $tempData = [ + 'name' => $groupName, + 'year' => $monthData['sum_year'], + 'monthDate' => [] + ]; + ksort($monthData['month']); + foreach ($monthData['month'] as $month => $value) { + $tempData['monthDate'][] = [ + 'month' => $month, + 'value' => $value + ]; + } + $data['dataResult'][] = $tempData; + } + + return $this->renderSuccess($data); + } +} \ No newline at end of file diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index 9dddc10..14181d2 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 = isset($param['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']; @@ -148,7 +148,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; @@ -321,7 +321,6 @@ 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()); @@ -331,7 +330,7 @@ class PassFlow // $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'); + #$libraryData = $dm->find('bt_library_data',['group_id' => 'lib001','date' => 'year'],'SUM("incount") as NUM'); $returnData['sumYear']['noRepeatInNum'] += isset($libraryDataYear['incount']) ? $libraryDataYear['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")); @@ -356,7 +355,7 @@ class PassFlow public static function realTimeData($dm = null) { if (empty($dm)) $dm = new Dm(); - + $list = $dm->select('bt_passenger_flow_real'); $data = []; @@ -391,7 +390,6 @@ class PassFlow $val['sort']=intval($getGroup['sort']); $returnData[] = $val; } - $libData = $dm->select('bt_library',['group_id' => ['baz001','BAF055']]); foreach ($libData as $libRow) { $holdValue = abs($libRow['today_incount'] - $libRow['today_outcount']); @@ -523,9 +521,9 @@ class PassFlow 'list' => $listData ]; } - if(empty($groupsId)){ - $data = self::getLibraryGroupHoursList($dm,false,$data); - } + if(empty($groupsId)){ + $data = self::getLibraryGroupHoursList($dm,false,$data); + } return $data; } diff --git a/web/create_bt_library_data.php b/web/create_bt_library_data.php new file mode 100644 index 0000000..970afbf --- /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 = 7; +$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 = round($temp_count-$temp_day); + } + + if ($i == 2) { + # 减去未满30 + $temp_day = $day * 2; + $temp_count = round($temp_count-$temp_day); + } + + # 每月数量 + $flowInNum = round($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' => round($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' => round($queryBaz['incount']+$countBaz['baz001']['incount']), + 'outcount' => round($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' => round($queryBaf['incount']+$countBaz['BAF055']['incount']), + 'outcount' => round($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 diff --git a/web/create_pass_all.php b/web/create_pass_all.php new file mode 100644 index 0000000..747099a --- /dev/null +++ b/web/create_pass_all.php @@ -0,0 +1,212 @@ + [ + '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 = 7; + + +$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 = round($temp_count-$temp_day); + } + + if ($i == 2) { + # 减去未满30 + $temp_day = $day * 2; + $temp_count = round($temp_count-$temp_day); + } + + # 每月数量 + $flowInNum = round($count+$temp_count); + + $sumFlowInNum = round($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' => round($querySumAll['flowInNum']+$sumFlowInNum), + 'noRepeatInNum' => round($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' => round($querySum['flowInNum']+$sumFlowInNum), + 'noRepeatInNum' => round($querySum['noRepeatInNum']+$sumFlowInNum), + ]; + + $dm->update('bt_passenger_flow',$update,'"id" = ' . "'{$querySum['id']}'"); + } + + echo "
";
+    var_dump($groupId);
+    var_dump($sumFlowInNum);
+}
+
+//var_dump($returnData);
+//var_dump($returnDataAll);
+echo true;
\ No newline at end of file
diff --git a/web/handle_data.php b/web/handle_data.php
new file mode 100644
index 0000000..bc360c3
--- /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