6 changed files with 772 additions and 10 deletions
@ -0,0 +1,124 @@ |
|||
<?php |
|||
|
|||
namespace app\api\controller\pass; |
|||
|
|||
use app\api\controller\Controller; |
|||
use app\common\dm\Dm; |
|||
|
|||
class Statistics extends Controller |
|||
{ |
|||
|
|||
private $password = 'batyg@2023'; |
|||
|
|||
protected function validateUserToken($token) { |
|||
$xtToken = md5(base64_encode($this->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); |
|||
} |
|||
} |
|||
@ -0,0 +1,158 @@ |
|||
<?php |
|||
use app\common\dm\Dm; |
|||
require_once __DIR__ . '../../source/application/common/dm/Dm.php'; |
|||
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'; |
|||
|
|||
|
|||
$dm = new Dm($config['connections']['dm']); |
|||
|
|||
|
|||
$countBaz = '376378'; |
|||
$countBaf = '28100'; |
|||
|
|||
$data = [ |
|||
'baz001' => [ |
|||
'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; |
|||
@ -0,0 +1,212 @@ |
|||
<?php |
|||
|
|||
use app\common\dm\Dm; |
|||
require_once __DIR__ . '../../source/application/common/dm/Dm.php'; |
|||
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'; |
|||
|
|||
$dm = new Dm($config['connections']['dm']); |
|||
|
|||
$y = 2023; |
|||
|
|||
$groupArr = [ |
|||
'110' => [ |
|||
'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 "<pre>"; |
|||
var_dump($groupId); |
|||
var_dump($sumFlowInNum); |
|||
} |
|||
|
|||
//var_dump($returnData); |
|||
//var_dump($returnDataAll); |
|||
echo true; |
|||
@ -0,0 +1,242 @@ |
|||
<?php |
|||
use app\common\dm\Dm; |
|||
require_once __DIR__ . '../../source/application/common/dm/Dm.php'; |
|||
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; |
|||
$monthNum = 7; |
|||
$y = 2023; |
|||
|
|||
|
|||
$tyg = get_pass($dm,'110',$y,$monthNum); // 体育场 <-- replace --> |
|||
$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 "<br>"; |
|||
echo $tyYearSum; |
|||
echo "<br>"; |
|||
echo "----------------------------------"; |
|||
echo "<br>"; |
|||
} |
|||
echo "<h1>体育结束....</h1>"; |
|||
# ---------------------------- 体育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 "<br>"; |
|||
echo $yearSumInCount; |
|||
echo "<br>"; |
|||
echo "----------------------------------"; |
|||
echo "<br>"; |
|||
} |
|||
echo "<h1>文化结束....</h1>"; |
|||
|
|||
# ---------------------------- 文化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; |
|||
} |
|||
Loading…
Reference in new issue