You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
242 lines
8.2 KiB
242 lines
8.2 KiB
<?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;
|
|
}
|