Browse Source

Merge remote-tracking branch 'origin/master'

master
wanghongjun 2 years ago
parent
commit
137cf39b62
  1. 4
      source/application/admin/controller/Passport.php
  2. 62
      source/application/admin/controller/setting/Config.php
  3. 52
      source/application/admin/extra/menus.php
  4. 11
      source/application/admin/model/admin/User.php
  5. 2
      source/application/admin/view/layouts/layout.php
  6. 21
      source/application/admin/view/setting/config/index.php
  7. 48
      source/application/api/controller/Controller.php
  8. 45
      source/application/api/controller/config/Setting.php
  9. 183
      source/application/api/controller/library/Pass.php
  10. 65
      source/application/api/controller/pass/Create.php
  11. 34
      source/application/api/controller/pass/Passcc.php
  12. 13
      source/application/api/controller/xtool/Token.php
  13. 35
      source/application/api/controller/xtool/Xtool.php
  14. 49
      source/application/common/dm/Dm.php
  15. 267
      source/application/common/logic/PassFlow.php
  16. 14
      source/application/task/controller/Group.php
  17. 6
      source/application/task/controller/Passreal.php
  18. 7
      web/bt_config.sql
  19. 158
      web/create_bt_library_data.php
  20. 212
      web/create_pass_all.php
  21. 242
      web/handle_data.php
  22. 84
      web/ws_task_real.php
  23. 67
      web/ws_task_real_ty.php
  24. 64
      web/ws_task_real_wh.php

4
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() ?: '登录失败');
}

62
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("<br>",$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()
]);
}
}

52
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'

11
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,18 +24,20 @@ class User extends UserModel
public function login($data)
{
// 验证用户名密码是否正确
if (!$user = self::useGlobalScope(false)->where([
$dm = new Dm();
$user = $dm->dmPDOFind('bt_admin_user',[
'user_name' => $data['user_name'],
'password' => yoshop_hash($data['password'])
])->find()) {
]);
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,
]);

2
source/application/admin/view/layouts/layout.php

@ -31,7 +31,7 @@
<ul>
<!-- 欢迎语 -->
<li class="am-text-sm tpl-header-navbar-welcome">
<a href="<?= url('admin.user/renew') ?>">欢迎你,<span><?= $admin['user']['user_name'] ?></span>
<a href="#">欢迎你,<span><?= $admin['user']['user_name'] ?></span>
</a>
</li>
<!-- 退出 -->

21
source/application/admin/view/setting/config/index.php

@ -1,12 +1,19 @@
<style>
.tpl-form-input {
width: 60px!important;
width: 200px!important;
display: inline-block!important;
text-align: center;
}
.am-checkbox-inline span{
margin-right: 10px;
}
.notice-title{
background-color: #fff7cc;
margin-bottom: 20px;
border: 1px solid #feb;
border-radius: 4px;
font-size: 14px;
}
</style>
<div class="row">
<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
@ -17,16 +24,24 @@
<div class="widget-head am-cf">
<div class="widget-title am-fl">预警阈值</div>
</div>
<div class="notice-title">
&nbsp;&nbsp;计算方式1:阈值<=50% = 舒适、阈值>50% 阈值<=100% = 拥挤、阈值>100% = 爆满
<br>
&nbsp;&nbsp;计算方式2:100-200, 小于100 = 舒适、大于100小于200 = 拥挤、大于200 = 爆满
</div>
<?php foreach ($configList as $item) { ?>
<div class="am-form-group">
<label class="am-u-sm-3 am-form-label form-require"> 阈值 </label>
<label class="am-u-sm-3 am-form-label form-require"><?= $item['groupName'] ?> 阈值 </label>
<div class="am-u-sm-9">
<label class="am-checkbox-inline">
<input type="text" class="tpl-form-input" name="threshold" value="<?= $threshold ?>" required>
<input type="text" class="tpl-form-input" name="threshold[<?= $item['id'] ?>]" value="<?= $item['value'] ?>" required>
</label>
</div>
</div>
<?php } ?>
<div class="am-form-group">
<div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
<input type="hidden" name="token" value="<?= $token ?>">
<button type="submit" class="j-submit am-btn am-btn-secondary">提交
</button>
</div>

48
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,47 @@ 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");
$data = $encrypt ? html_entity_decode($data) : $data;
$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参数类型错误');
}
}
/**

45
source/application/api/controller/config/Setting.php

@ -0,0 +1,45 @@
<?php
namespace app\api\controller\config;
use \app\api\controller\Controller;
use app\common\dm\Dm;
class Setting extends Controller
{
public function setThreshold()
{
$threshold = $this->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'));
}
}

183
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';
protected 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'));
}
@ -46,26 +56,35 @@ class Pass extends Controller
*/
public function create()
{
$this->validateToken();
$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;
// --------------------- 当天实时数据 --------------------- //
$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());
@ -76,58 +95,117 @@ 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']];
$hoursQuery = $dm->find("bt_library_hours",$hoursQueryWhere);
if (isset($val['hour']) && is_array($val['hour'])) {
foreach ($val['hour'] as $hour => $hourVal) {
# 默认单天数据
$incount = 0;
$outcount = 0;
if ($hoursQuery) {
$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,
'target_today_incount' => 0,
'target_today_outcount' => 0,
'create_time' => date("Y-m-d H:i:s", time())
];
$dm->insert("bt_library_hours", $insert);
}
}
}
// --------------------- 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 = $hoursQuery['incount'] + ($val['today_incount'] - $hoursQuery['target_today_incount']);
$outcount = $hoursQuery['outcount'] + ($val['today_outcount'] - $hoursQuery['target_today_outcount']);
$incount = $query['incount'] + ($incount - $query['last_incount']);
$outcount = $query['outcount'] + ($outcount - $query['last_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())
'incount' => $incount,
'outcount' => $outcount,
'last_incount' => $value['incount'],
'last_outcount' => $value['outcount'],
'update_time' => date("Y-m-d H:i:s",time())
];
$dm->update('bt_library_hours',$update,['id' => $hoursQuery['id']]);
$dm->update('bt_library_data',$update,['id' => $query['id']]);
} else {
# 查看该组是否存在上一条数据
$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'];
$incount = $incount > 0 ? $incount : 0;
$outcount = $val['today_outcount'] - $lastHours['target_today_outcount'];
$outcount = $outcount > 0 ? $outcount : 0;
}
# 创建数据
$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())
'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_hours",$insert);
$dm->insert("bt_library_data",$insert);
}
// --------------------- end --------------------- //
}
return $this->renderSuccess();
}
/**
@ -136,6 +214,7 @@ class Pass extends Controller
*/
public function getLibraryHours24List()
{
$this->requestValiDate();
$data = PassFlow::getLibraryHours24List();
return $this->renderSuccess(compact('data'));
}
@ -149,6 +228,7 @@ class Pass extends Controller
*/
public function getLibraryGroupHoursList()
{
$this->requestValiDate();
$data = PassFlow::getLibraryGroupHoursList();
return $this->renderSuccess(compact('data'));
}
@ -159,6 +239,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);
@ -189,13 +270,15 @@ class Pass extends Controller
return $this->renderSuccess();
}
/**
/**
* 获取今日借阅办证数据
* @return array
*/
public function getLibraryLeaseData()
{
$this->requestValiDate();
$data = PassFlow::getLibraryLeaseData();
return $this->renderSuccess(compact('data'));
}
}

65
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,9 @@ 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,
@ -81,6 +58,7 @@ class Create extends Controller
];
if ($query) {
$this->mergeYearlyData($insert_arr);
# 判断数据是否发生变化, 发生变化及更新
$queryUpdate = $dm->find('bt_passenger_flow',$insert_arr);
if (!$queryUpdate) {
@ -108,11 +86,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'],
@ -131,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']]);
@ -146,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

34
source/application/api/controller/pass/Passcc.php

@ -5,9 +5,11 @@ 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;
use think\Session;
class Passcc extends Controller
{
@ -16,6 +18,17 @@ class Passcc extends Controller
echo 1111;
}
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字段参数错误']);
}
}
/**
* 分时时间段接口 <首页-客流趋势>
* @return array
@ -26,9 +39,9 @@ class Passcc extends Controller
public function allGroupTimeNum()
{
$granularity = $this->request->param('granularity');
$groupsId = $this->request->param('groupsId');
$res = PassFlow::allGroupTimeNum(['granularity' => $granularity, 'groupsId' => $groupsId]);
if (empty($res['code'])) $this->renderError($res['msg']);
$type = $this->request->param('type');
$res = PassFlow::allGroupTimeNum(['granularity' => $granularity, 'type' => $type]);
if (empty($res['code'])) return $this->renderError($res['msg']);
$data = $res['data'];
return $this->renderSuccess(compact('data'));
}
@ -42,8 +55,9 @@ 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]);
if (isset($returnData['code'])) return $this->renderError($returnData['msg']);
return $this->renderSuccess(compact('returnData'));
}
@ -69,8 +83,9 @@ 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]);
if (isset($data['code'])) return $this->renderError($data['msg']);
return $this->renderSuccess(compact('data'));
}
@ -93,8 +108,9 @@ 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]);
if (isset($data['code'])) return $this->renderError($data['msg']);
return $this->renderSuccess(compact('data'));
}
}

13
source/application/api/controller/xtool/Token.php

@ -0,0 +1,13 @@
<?php
namespace app\api\controller\xtool;
use app\api\controller\Controller;
class Token extends Controller
{
public function getToken()
{
return $this->renderSuccess(['token' => $this->request->token()]);
}
}

35
source/application/api/controller/xtool/Xtool.php

@ -0,0 +1,35 @@
<?php
namespace app\api\controller\xtool;
use app\api\controller\Controller;
use app\common\dm\Dm;
class Xtool extends Controller
{
//
public function index(){
if($_GET['run']==1){
$dbname = $this->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();
}
}

49
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,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()];
}
}
}

267
source/application/common/logic/PassFlow.php

@ -6,6 +6,35 @@ use app\common\dm\Dm;
class PassFlow
{
protected static $groupType = [1,2];# 1 = 体育 2 = 文化
protected static $granularity = ['daily','monthly','yearly'];# 1 = 体育 2 = 文化
protected static $groupThreshold = [
'baz001' => 40000,# 图书馆
'BAF055' => 1000,# 文化馆
'110' => [
'min' => 8000,
'max' => 12000
],# 体育场
'210' => [
'min' => 8000,
'max' => 12000
],# 体育馆
'310' => [
'min' => 6000,
'max' => 10000
],# 游泳馆
'510' => 1000 # 博物馆
];
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,20 +46,23 @@ class PassFlow
{
$granularity = $param['granularity'];
$groupsId = $param['groupsId'];
$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'];
$where = '';
if (!empty($groupsId)) {
$garr = explode("|", $groupsId);
$where .= ' "groupId" in(' . "'" . implode("','", $garr) . "')";
$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);
$groupsId = implode("|",$groupsIdArr);
$where .= ' "groupId" in(' . "'" . implode("','", $groupsIdArr) . "')";
}
$allTimeData = [];
$groupsData = [];
$dkeys = [];
if (empty($dm)) $dm = new Dm();
if ($granularity == 'daily') {
$date = self::getDateData('day');
$start_time = $date['day']['start_time'];
@ -86,7 +118,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 +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;
@ -142,6 +174,7 @@ class PassFlow
$dkey[]=$str;
}
}
# 体育 + 博物馆客流柱状图数据
$sumNoRepeatInNum = 0;
$groupsIdArr = [];
foreach ($list as $value) {
@ -156,20 +189,40 @@ class PassFlow
ksort($allTimeData);
$groupsIdParamArr = [];
# 总览-合并文化数据
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 = [];
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) {
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'];
}
} else {
$groupsIdParamArr = explode("|",$groupsId);
}
@ -230,8 +283,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) . "')";
}
}
@ -261,20 +315,28 @@ 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'])) {
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;
$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');
$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}'";
$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']);
}
@ -296,19 +358,30 @@ 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'];
if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0;
$data[$value['groupId']]['holdValue'] += $value['holdValue'];
}
$groupThreshold = self::getConfig($dm);
$returnData = [];
foreach ($data as $groupId => $val) {
$proportion = $val['allEnter'] > 0 ? round($val['allEnter']/$threshold,2) : 0;
$val['proportion'] = ($proportion * 100) . "%";
$val['congestion'] = self::getPassType($proportion);
if (!isset($groupThreshold[$groupId])) continue;
$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}'");
@ -318,7 +391,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,2) : 0;
$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;
$returnData[] = [
@ -343,24 +417,40 @@ 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 '';
}
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
@ -374,9 +464,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) . "')";
}
@ -397,15 +489,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,16 +511,31 @@ 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($groupsId)){
$data = self::getLibraryGroupHoursList($dm,false,$data);
}
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
@ -442,37 +549,44 @@ 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 = self::getWhYearData($dm,'baz001');
# 劳务博物馆数据
$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 = ' "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;
$museumRes = $dm->find('bt_passenger_flow_all',$museumWhere,' SUM("flowInNum") as NUM');
$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 = self::getWhYearData($dm,'BAF055');
# 累计进馆人数
# 总年、月、日总数
$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;
# 累计进馆人数 - 文化、图书
$libData = $dm->find('bt_library_data',['group_id' => 'lib001','date' => 'year'],' SUM("incount") as SUM');
$sum_all_incount += $libData ? $libData['SUM'] : 0;
$data = [
'month' => [
@ -490,15 +604,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
],
]
];
@ -515,8 +629,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) . "')";
}
}
@ -604,14 +719,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 (' . "'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) {
@ -646,9 +761,8 @@ 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");
$end_create_time = date("Y-m-d 23:59:59");
@ -673,7 +787,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'];
}
@ -709,10 +823,31 @@ 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;
}
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;
}
}

14
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');

6
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']);

7
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');

158
web/create_bt_library_data.php

@ -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;

212
web/create_pass_all.php

@ -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;

242
web/handle_data.php

@ -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;
}

84
web/ws_task_real.php

@ -1,10 +1,17 @@
<?php
/**
* 总览
*/
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 Workerman\Worker;
use Workerman\Timer;
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';
@ -12,24 +19,53 @@ require_once __DIR__ . '../../source/thinkphp/library/think/Config.php';
require_once __DIR__ . '../../source/application/common.php';
$config = require_once __DIR__ . '../../source/application/database.php';
$worker = new Worker('websocket://0.0.0.0:2000');
$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 = [];
$passData = PassFlow::realTimeData($dm);
$returnData = ['data' => $passData];
$data['realTimeData'] = $returnData;
$toDayGroupsEnterNum = PassFlow::toDayGroupsEnterNum($dm);
$data['toDayGroupsEnterNum'] = $toDayGroupsEnterNum;
$connection->send(json_encode($data));
}
});
};
Worker::runAll();
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);
}
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;
}

67
web/ws_task_real_ty.php

@ -0,0 +1,67 @@
<?php
/**
* 体育
*/
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__ . '../../source/application/common/dm/Dm.php';
require_once __DIR__ . '../../source/application/common/logic/PassFlow.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';
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);
}
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;
}

64
web/ws_task_real_wh.php

@ -0,0 +1,64 @@
<?php
/**
* 文化
*/
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__ . '../../source/application/common/dm/Dm.php';
require_once __DIR__ . '../../source/application/common/logic/PassFlow.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';
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);
}
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;
}
Loading…
Cancel
Save