宝体数据调用接口
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.
 
 
 
 
 
 

67 lines
1.9 KiB

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