14 changed files with 1042 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||
|
# 默认忽略的文件 |
||||
|
/shelf/ |
||||
|
/workspace.xml |
||||
|
# 基于编辑器的 HTTP 客户端请求 |
||||
|
/httpRequests/ |
||||
|
# Datasource local storage ignored files |
||||
|
/dataSources/ |
||||
|
/dataSources.local.xml |
||||
@ -0,0 +1,21 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false"> |
||||
|
<serverData> |
||||
|
<paths name="aslftp_temp"> |
||||
|
<serverdata> |
||||
|
<mappings> |
||||
|
<mapping local="$PROJECT_DIR$" web="/" /> |
||||
|
</mappings> |
||||
|
</serverdata> |
||||
|
</paths> |
||||
|
<paths name="why"> |
||||
|
<serverdata> |
||||
|
<mappings> |
||||
|
<mapping local="$PROJECT_DIR$" web="/" /> |
||||
|
</mappings> |
||||
|
</serverdata> |
||||
|
</paths> |
||||
|
</serverData> |
||||
|
</component> |
||||
|
</project> |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="ProjectModuleManager"> |
||||
|
<modules> |
||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/task.iml" filepath="$PROJECT_DIR$/.idea/task.iml" /> |
||||
|
</modules> |
||||
|
</component> |
||||
|
</project> |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<module type="WEB_MODULE" version="4"> |
||||
|
<component name="NewModuleRootManager"> |
||||
|
<content url="file://$MODULE_DIR$" /> |
||||
|
<orderEntry type="inheritedJdk" /> |
||||
|
<orderEntry type="sourceFolder" forTests="false" /> |
||||
|
</component> |
||||
|
</module> |
||||
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="VcsDirectoryMappings"> |
||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" /> |
||||
|
</component> |
||||
|
</project> |
||||
@ -0,0 +1,188 @@ |
|||||
|
<?php |
||||
|
|
||||
|
if (!function_exists('get_access_token')) { |
||||
|
|
||||
|
/** |
||||
|
* 获取 接口 accessToken |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
function get_access_token(){ |
||||
|
|
||||
|
// 记录缓存, 时效2小时分钟 |
||||
|
$token = get_cache('api_access_token'); |
||||
|
|
||||
|
if (empty($token)) { |
||||
|
$config = config('api_config'); |
||||
|
// |
||||
|
$url = $config['host_url']."/oauth/token?client_id=".$config['cid']."&client_secret=".$config['cskey']; |
||||
|
// do post |
||||
|
$ret = curl_post($url); |
||||
|
$res = json_decode($ret,true); |
||||
|
if ($res['access_token']) { |
||||
|
set_cache('api_access_token', $res['access_token'], 7200); |
||||
|
$token = $res['access_token']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $token; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('get_target_date')) { |
||||
|
/** |
||||
|
* 获取当前时间日期 |
||||
|
* @param $granularity // 返回当前日期 all = 所有 |
||||
|
* @return array |
||||
|
*/ |
||||
|
function get_target_date($granularity = 'all') { |
||||
|
|
||||
|
$data = []; |
||||
|
|
||||
|
if ($granularity === 'day' || $granularity === 'all') { |
||||
|
$date = $granularity !== 'all' ? $granularity : 'day'; |
||||
|
$data[$date] = [ |
||||
|
'start_time' => strtotime('today'), |
||||
|
'end_time' => strtotime('tomorrow - 1 second'), |
||||
|
]; |
||||
|
} |
||||
|
if ($granularity === 'week' || $granularity === 'all') { |
||||
|
$date = $granularity !== 'all' ? $granularity : 'week'; |
||||
|
$data[$date] = [ |
||||
|
'start_time' => strtotime('this week midnight'), |
||||
|
'end_time' => strtotime('next week midnight - 1 second'), |
||||
|
]; |
||||
|
} |
||||
|
if ($granularity === 'month' || $granularity === 'all') { |
||||
|
$date = $granularity !== 'all' ? $granularity : 'month'; |
||||
|
$data[$date] = [ |
||||
|
'start_time' => strtotime(date('Y-m-01 00:00:00')), |
||||
|
'end_time' => strtotime(date('Y-m-t 23:59:59')), |
||||
|
]; |
||||
|
} |
||||
|
if ($granularity === 'year' || $granularity === 'all') { |
||||
|
$date = $granularity !== 'all' ? $granularity : 'year'; |
||||
|
$data[$date] = [ |
||||
|
'start_time' => strtotime('first day of January this year'), |
||||
|
'end_time' => strtotime('first day of January next year - 1 second'), |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
foreach ($data as &$val) { |
||||
|
$val['c_start_time'] = date("c",$val['start_time']); |
||||
|
$val['c_end_time'] = date("c",$val['end_time']); |
||||
|
$val['start_time'] = date("Y-m-d H:i:s",$val['start_time']); |
||||
|
$val['end_time'] = date("Y-m-d H:i:s",$val['end_time']); |
||||
|
} |
||||
|
return $data; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('get_cache')) { |
||||
|
|
||||
|
function get_cache($key){ |
||||
|
|
||||
|
|
||||
|
return ''; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
if (!function_exists('set_cache')) { |
||||
|
|
||||
|
function set_cache($key, $value,$expire_time = 0) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('config')) { |
||||
|
/** |
||||
|
* 获取配置数据 |
||||
|
* @param $key |
||||
|
* @return array|mixed |
||||
|
*/ |
||||
|
function config($key = 'all') { |
||||
|
$config = include 'config.php'; |
||||
|
if ($key == 'all') { |
||||
|
return $config; |
||||
|
} else { |
||||
|
return isset($config[$key]) ? $config[$key] : []; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('curl_post')) { |
||||
|
/** |
||||
|
* curl请求指定url (post) |
||||
|
* @param $url |
||||
|
* @param array $data |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
function curl_post($url, $data = []) |
||||
|
{ |
||||
|
$ch = curl_init(); |
||||
|
curl_setopt($ch, CURLOPT_POST, 1); |
||||
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||||
|
curl_setopt($ch, CURLOPT_URL, $url); |
||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||||
|
$result = curl_exec($ch); |
||||
|
curl_close($ch); |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('post_token')) { |
||||
|
/** |
||||
|
* 模拟POST请求 |
||||
|
* @param string $url 请求地址 |
||||
|
* @param mixed $data 请求数据 |
||||
|
* @param false $useCert 是否引入微信支付证书 |
||||
|
* @param array $sslCert 证书路径 |
||||
|
* @param string $token 请求token |
||||
|
* @return bool|mixed|string |
||||
|
*/ |
||||
|
function post_token($url, $data = [], $useCert = false, $sslCert = [], $token = '') |
||||
|
{ |
||||
|
$header = [ |
||||
|
'Content-type: application/json;', |
||||
|
"access_token: {$token}" |
||||
|
]; |
||||
|
$curl = curl_init(); |
||||
|
curl_setopt($curl, CURLOPT_URL, $url); |
||||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); |
||||
|
curl_setopt($curl, CURLOPT_HEADER, false); |
||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
||||
|
curl_setopt($curl, CURLOPT_POST, TRUE); |
||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
||||
|
if ($useCert == true) { |
||||
|
// 设置证书:cert 与 key 分别属于两个.pem文件 |
||||
|
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM'); |
||||
|
curl_setopt($curl, CURLOPT_SSLCERT, $sslCert['certPem']); |
||||
|
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM'); |
||||
|
curl_setopt($curl, CURLOPT_SSLKEY, $sslCert['keyPem']); |
||||
|
} |
||||
|
$result = curl_exec($curl); |
||||
|
if ($result === false) { |
||||
|
curl_error($curl); |
||||
|
} |
||||
|
curl_close($curl); |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('dump')) { |
||||
|
/** |
||||
|
* 输出数据 |
||||
|
* @param $data // 待数据 |
||||
|
* @param $is_die // 是否停止运行 |
||||
|
* @return void |
||||
|
*/ |
||||
|
function dump($data, $is_die = true) { |
||||
|
var_dump($data); |
||||
|
if ($is_die) die; |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,68 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved. |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: liu21st <liu21st@gmail.com> |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
$dm_db = [ |
||||
|
'host' => 'localhost', |
||||
|
'database' => 'CXK', |
||||
|
'username' => 'SYSDBA', |
||||
|
'password' => 'SYSDBA', |
||||
|
'port' => '5236', |
||||
|
'charset' => 'utf8', |
||||
|
]; |
||||
|
|
||||
|
return [ |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 数据库配置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
'database' => [ |
||||
|
# 达梦数据库 |
||||
|
'dm' => [ |
||||
|
// 服务器地址 |
||||
|
'hostname' => $dm_db['host'], |
||||
|
// 数据库名 |
||||
|
'database' => $dm_db['database'], |
||||
|
// 用户名 |
||||
|
'username' => $dm_db['username'], |
||||
|
// 密码 |
||||
|
'password' => $dm_db['password'], |
||||
|
// 端口 |
||||
|
'hostport' => $dm_db['port'], |
||||
|
// 数据库编码默认采用utf8 |
||||
|
'charset' => $dm_db['charset'], |
||||
|
] |
||||
|
], |
||||
|
|
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 自定义配置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
'api_config' => [ |
||||
|
# 调用网址地址 |
||||
|
'host' => '192.168.66.13', |
||||
|
# 端口号 |
||||
|
'port' => '443', |
||||
|
# 请求key |
||||
|
'cid' => '29940726', |
||||
|
# 请求密钥 |
||||
|
'cskey' => 'SkTCnQdFbNW4Z2suNj8P', |
||||
|
# 请求智慧景区接口地址 |
||||
|
'host_url' => 'https://192.168.66.13:443/artemis', |
||||
|
# 脚本数据推送创建数据地址 |
||||
|
//'host_path' => 'http://btgym.xingtongworld.com/index.php?s=', |
||||
|
// 'host_path' => 'http://192.168.66.16/index.php?s=', |
||||
|
'host_path' => 'http://www.stadium.com/index.php?s=', |
||||
|
# 允许跨域 请求的IP地址 |
||||
|
'access_control_allow_origin' => [ |
||||
|
'http://192.168.66.220:8080', |
||||
|
'http://192.168.66.220:8081' |
||||
|
] |
||||
|
] |
||||
|
]; |
||||
@ -0,0 +1,56 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\module\Pass; |
||||
|
|
||||
|
use task\module\dm\Dm; |
||||
|
|
||||
|
class Pass |
||||
|
{ |
||||
|
/** |
||||
|
* 请求创建数据 |
||||
|
* @param $requestData |
||||
|
* @param $url |
||||
|
* @param $host_path |
||||
|
* @return array|int[] |
||||
|
*/ |
||||
|
public static function requestCreateData($requestData,$url,$host_path = '') |
||||
|
{ |
||||
|
# 验证传输数据 |
||||
|
if (empty($requestData) && is_array($requestData)) return ['status' => 0, 'msg' => 'requestData不能为空,且必须是数组']; |
||||
|
if (empty($url)) return ['status' => 0, 'msg' => 'url不能为空']; |
||||
|
# 获取请求路径 |
||||
|
if (empty($host_path)) { |
||||
|
$config = config('api_config'); |
||||
|
$host_path = $config['host_path']; |
||||
|
} |
||||
|
# 验证令牌 |
||||
|
$token = '9c4cb25665cf08667c815420ab383cb5'; |
||||
|
# 请求接口数据 |
||||
|
$data = [ |
||||
|
'data' => base64_encode(json_encode($requestData)), |
||||
|
'token' => md5($token . date('Ymd')) |
||||
|
]; |
||||
|
$json_data = json_encode($data); |
||||
|
$createUrl = $host_path . $url; |
||||
|
# 发起请求 |
||||
|
$result = post_token($createUrl,$json_data,false,[],$token); |
||||
|
$result = json_decode($result,true); |
||||
|
# 判断返回信息 |
||||
|
if ($result['code'] != 1) return ['status' => 0, 'msg' => $result['msg']]; |
||||
|
return ['status' => 1]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取统计组ID |
||||
|
* @param $dataType // 1 返回字符串 2 返回数组 |
||||
|
* @return array|string |
||||
|
*/ |
||||
|
public static function getGroupIds($dataType) |
||||
|
{ |
||||
|
include '../module/dm/Dm.php'; |
||||
|
$dm = new Dm(); |
||||
|
$groupRes = $dm->select('bt_passenger_monitor_group',null,'"groupId"'); |
||||
|
$groupIdArr = array_column($groupRes,'groupId') ?: []; |
||||
|
return $dataType == 2 ? $groupIdArr : implode(",",$groupIdArr); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,275 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\module\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'; |
||||
|
public $sql; |
||||
|
|
||||
|
public function __construct() |
||||
|
{ |
||||
|
# 获取配置数据 |
||||
|
$database = config('database'); |
||||
|
$dm = $database['dm']; |
||||
|
# 模式名称 |
||||
|
$this->database = $dm['database']; |
||||
|
# 连接达梦数据库 |
||||
|
$this->conn = dm_connect($dm['hostname'].':'.$dm['hostport'], $dm['username'], $dm['password']); |
||||
|
if (!$this->conn) { |
||||
|
die('连接数据库失败!'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 拼接达梦查询数据表名 |
||||
|
* @param string $tableName // 表名 |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected function splitTableName($tableName) { |
||||
|
if (strpos($tableName,$this->database) !== false) return $tableName; |
||||
|
return '"' . $this->database . '"."' . $tableName .'"'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建数据 |
||||
|
* @param string $table // 创建数据表名 |
||||
|
* @param array $data // 创建数据 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function insert($table, $data) |
||||
|
{ |
||||
|
$fields = '"' . implode('","', array_keys($data)) . '"'; |
||||
|
$values = "'" . implode("','", array_values($data)) . "'"; |
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'INSERT INTO '.$tableName.'('.$fields.') VALUES ('.$values.')'; |
||||
|
|
||||
|
$res = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
dm_free_result($res); |
||||
|
|
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新数据 |
||||
|
* @param string $table // 更新数据表名 |
||||
|
* @param array $data // 更新数据 |
||||
|
* @param string $where // 更新数据条件 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function update($table, $data, $where) |
||||
|
{ |
||||
|
$set = array(); |
||||
|
foreach ($data as $key => $value) { |
||||
|
$set[] = '"'.$key.'"' . '=' . "'{$value}'"; |
||||
|
} |
||||
|
|
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'UPDATE '.$tableName." SET " . implode(",", $set) . ' WHERE '.$where; |
||||
|
|
||||
|
$res = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
dm_free_result($res); |
||||
|
|
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除数据 |
||||
|
* @param string $table // 删除数据表名 |
||||
|
* @param string $where // 删除数据条件 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function delete($table, $where) |
||||
|
{ |
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'DELETE FROM '.$tableName.' WHERE '.$where; |
||||
|
|
||||
|
$result = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
dm_free_result($result); |
||||
|
|
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 清空表 |
||||
|
* @param string $table // 清空表名 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function truncate($table) |
||||
|
{ |
||||
|
|
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'truncate table '.$tableName; |
||||
|
|
||||
|
$result = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
dm_free_result($result); |
||||
|
|
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询多条数据 |
||||
|
* @param string $table // 查询表名 |
||||
|
* @param string $where // 查询条件 |
||||
|
* @param string $fields // 查询字段 |
||||
|
* @param string $order // 查询排序 |
||||
|
* @param string $limit // 查询条数 |
||||
|
* @param string $group // 查询分组 |
||||
|
* @return array // 返回数组 |
||||
|
*/ |
||||
|
public function select($table, $where = null, $fields = '*', $order = null, $limit = null, $group = null) |
||||
|
{ |
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'SELECT '.$fields.' FROM '.$tableName; |
||||
|
if ($where != null) { |
||||
|
$sql .= ' WHERE '.$where; |
||||
|
} |
||||
|
if ($group != null) { |
||||
|
$sql .= ' GROUP BY '.$group; |
||||
|
} |
||||
|
if ($order != null) { |
||||
|
$sql .= ' ORDER BY '.$order; |
||||
|
} |
||||
|
if ($limit != null) { |
||||
|
$sql .= ' LIMIT '.$limit; |
||||
|
} |
||||
|
|
||||
|
$result = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
$data = array(); |
||||
|
|
||||
|
while ($row = dm_fetch_array($result)) { |
||||
|
$data[] = $row; |
||||
|
} |
||||
|
|
||||
|
dm_free_result($result); |
||||
|
|
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查询单条数据 |
||||
|
* @param string $table // 查询表名 |
||||
|
* @param string $where // 查询条件 |
||||
|
* @param string $fields // 查询字段 |
||||
|
* @param string $order // 查询排序 |
||||
|
* @return array // 返回数组 |
||||
|
*/ |
||||
|
public function find($table, $where = null, $fields = '*', $order = null) |
||||
|
{ |
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'SELECT '.$fields.' FROM '.$tableName; |
||||
|
if ($where != null) { |
||||
|
$sql .= ' WHERE '.$where; |
||||
|
} |
||||
|
if ($order != null) { |
||||
|
$sql .= ' ORDER BY '.$order; |
||||
|
} |
||||
|
$sql .= ' LIMIT 1'; |
||||
|
|
||||
|
|
||||
|
$result = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
$data = array(); |
||||
|
|
||||
|
while ($row = dm_fetch_array($result)) { |
||||
|
$data = $row; |
||||
|
} |
||||
|
|
||||
|
dm_free_result($result); |
||||
|
|
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询数据总数 |
||||
|
* @param string $table // 查询表名 |
||||
|
* @param string $where // 查询条件 |
||||
|
* @return array // 返回数组 |
||||
|
*/ |
||||
|
public function count($table, $where = null) |
||||
|
{ |
||||
|
$tableName = $this->splitTableName($table); |
||||
|
$sql = 'SELECT COUNT(*) as count FROM '.$tableName; |
||||
|
|
||||
|
if ($where != null) { |
||||
|
$sql .= ' WHERE '.$where; |
||||
|
} |
||||
|
|
||||
|
$result = dm_exec($this->conn, $sql); |
||||
|
|
||||
|
$this->sql = $sql; |
||||
|
|
||||
|
$count = 0; |
||||
|
|
||||
|
while ($row = dm_fetch_array($result)) { |
||||
|
$count = $row['COUNT']; |
||||
|
} |
||||
|
|
||||
|
dm_free_result($result); |
||||
|
|
||||
|
return $count; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取上次执行数据Sql |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function getLastSql() |
||||
|
{ |
||||
|
return $this->sql; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $table |
||||
|
* @param $where |
||||
|
* @param $fields |
||||
|
* @param $order |
||||
|
* @param $limit |
||||
|
* @param $page |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getPaginate($table, $where = null, $fields = '*', $order = null, $limit = 10, $page = 1) |
||||
|
{ |
||||
|
# 查询条数 |
||||
|
$pageLimit = ($page - 1) * $limit; |
||||
|
# 总数 |
||||
|
$total = $this->count($table); |
||||
|
# 数据 |
||||
|
$list = $this->select($table,$where,$fields,$order,$pageLimit.','.$limit); |
||||
|
# 计算总页数 |
||||
|
$totalPages = ceil($total / $limit); |
||||
|
# 组合分页按钮 |
||||
|
$pageData = $totalPages >= 2 ? get_paginate($totalPages,$page,'/?s=/admin/pass.pass/index') : ''; |
||||
|
|
||||
|
return [ |
||||
|
'list' => $list ?: [], |
||||
|
'pageData' => $pageData, |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\tasks; |
||||
|
use task\module\Pass\Pass; |
||||
|
|
||||
|
$aa = new Group(); |
||||
|
echo $aa->run(); |
||||
|
class Group |
||||
|
{ |
||||
|
function run() |
||||
|
{ |
||||
|
include_once '../common.php'; |
||||
|
include_once '../module/Pass/Pass.php'; |
||||
|
$config = config('api_config'); |
||||
|
$token = get_access_token(); |
||||
|
|
||||
|
$url = $config['host_url'] . "/api/cfas/v2/countGroup/groups/page"; |
||||
|
|
||||
|
$pageNo = 1; |
||||
|
$pageSize = 1; |
||||
|
|
||||
|
$requestData = []; |
||||
|
while (1) { |
||||
|
|
||||
|
$dataArr = [ |
||||
|
"regionId"=> "root000000", |
||||
|
"isCascade"=> 1, |
||||
|
"groupType"=> 0, |
||||
|
"statType"=> 0, |
||||
|
"pageNo"=> $pageNo, |
||||
|
"pageSize"=> $pageSize |
||||
|
]; |
||||
|
|
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = post_token($url,$json_data,false,[],$token); |
||||
|
|
||||
|
$res_data = json_decode($result,true); |
||||
|
|
||||
|
# 存在错误结束循环 |
||||
|
if ($res_data['code'] != 0) break; |
||||
|
# 数据不存在结束循环 |
||||
|
$list = (array)$res_data['data']['list']; |
||||
|
if (empty($list)) break; |
||||
|
|
||||
|
foreach ($list as $value) { |
||||
|
|
||||
|
$insert = [ |
||||
|
'groupId' => $value['groupId'], |
||||
|
'groupName' => $value['groupName'], |
||||
|
'groupType' => $value['groupType'], |
||||
|
'statType' => $value['statType'], |
||||
|
'regionId' => $value['regionId'], |
||||
|
'thirdPartCode' => $value['thirdPartCode'], |
||||
|
'workStartTime' => $value['workStartTime'], |
||||
|
'workEndTime' => $value['workEndTime'], |
||||
|
'holdBase' => $value['holdBase'], |
||||
|
'earlyWarningValue' => $value['earlyWarningValue'], |
||||
|
'warningValue' => $value['warningValue'], |
||||
|
'warningSwitch' => $value['warningSwitch'] |
||||
|
]; |
||||
|
|
||||
|
$requestData[] = $insert; |
||||
|
} |
||||
|
|
||||
|
# 总条数不够结束循环 |
||||
|
if (count($list) < $pageSize) break; |
||||
|
++$pageNo; |
||||
|
} |
||||
|
|
||||
|
$requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createGroup',$config['host_path']); |
||||
|
|
||||
|
if (!$requestRes['status']) { |
||||
|
return $requestRes['msg']; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\tasks; |
||||
|
|
||||
|
$pass = new Pass(); |
||||
|
echo $pass->run(); |
||||
|
class Pass |
||||
|
{ |
||||
|
public function run() |
||||
|
{ |
||||
|
include_once '../common.php'; |
||||
|
include_once '../module/Pass/Pass.php'; |
||||
|
$config = config('api_config'); |
||||
|
$dateData = get_target_date(); |
||||
|
$token = get_access_token(); |
||||
|
|
||||
|
$arr = [ |
||||
|
'hourly' => [ |
||||
|
'startTime' => $dateData['day']['c_start_time'], |
||||
|
'endTime' => date('c',time()), |
||||
|
], |
||||
|
'daily' => [ |
||||
|
'startTime' => $dateData['month']['c_start_time'], |
||||
|
'endTime' => date('c',time()), |
||||
|
], |
||||
|
'monthly' => [ |
||||
|
'startTime' => $dateData['year']['c_start_time'], |
||||
|
'endTime' => date('c'), |
||||
|
] |
||||
|
]; |
||||
|
|
||||
|
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups"; |
||||
|
|
||||
|
$requestData = []; |
||||
|
try { |
||||
|
$ids = \task\module\Pass\Pass::getGroupIds(1); |
||||
|
foreach ($arr as $granularity => $value) { |
||||
|
|
||||
|
$dataArr = [ |
||||
|
'granularity' => $granularity, |
||||
|
'startTime' => $value['startTime'], |
||||
|
'endTime' => $value['endTime'], |
||||
|
'ids' => $ids |
||||
|
]; |
||||
|
|
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = post_token($url,$json_data,false,[],$token); |
||||
|
|
||||
|
$res_data = json_decode($result,true); |
||||
|
if ($res_data['code'] != 0) throw new \Exception('请求失败'); |
||||
|
$list = (array)$res_data['data']['list']; |
||||
|
|
||||
|
foreach ($list as $val) { |
||||
|
$insert_arr = [ |
||||
|
'groupId' => $val['groupId'], |
||||
|
'groupName' => $val['groupName'], |
||||
|
'flowInNum' => $val['flowInNum'], |
||||
|
'flowOutNum' => $val['flowOutNum'], |
||||
|
'noRepeatInNum' => $val['noRepeatInNum'], |
||||
|
'noRepeatOutNum' => $val['noRepeatOutNum'], |
||||
|
'holdValue' => $val['holdValue'], |
||||
|
'createTime' => $val['createTime'], |
||||
|
'updateTime' => $val['updateTime'], |
||||
|
'netValue' => $val['netValue'], |
||||
|
'statTime' => $val['statTime'], |
||||
|
'granularity' => $granularity, |
||||
|
]; |
||||
|
|
||||
|
$requestData[] = $insert_arr; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} catch (\Exception $e) { |
||||
|
return $e->getMessage(); |
||||
|
} |
||||
|
|
||||
|
$requestRes = \task\module\Pass\Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlow', $config['host_path']); |
||||
|
|
||||
|
if (!$requestRes['status']) { |
||||
|
return $requestRes['msg']; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,99 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\tasks; |
||||
|
|
||||
|
use task\module\Pass\Pass; |
||||
|
|
||||
|
$Passall = new Passall(); |
||||
|
echo $Passall->run(); |
||||
|
class Passall |
||||
|
{ |
||||
|
public function run() |
||||
|
{ |
||||
|
include_once '../common.php'; |
||||
|
include_once '../module/Pass/Pass.php'; |
||||
|
$config = config('api_config'); |
||||
|
$dateData = get_target_date(); |
||||
|
$token = get_access_token(); |
||||
|
|
||||
|
$dateArr = [ |
||||
|
'day' => [ |
||||
|
'startTime' => $dateData['day']['c_start_time'],// 当天开始时间 |
||||
|
'endTime' => date("c"),// 当天结束时间 |
||||
|
'granularity' => 'daily' |
||||
|
], |
||||
|
'week' => [ |
||||
|
'startTime' => $dateData['week']['c_start_time'], |
||||
|
'endTime' => date("c"), |
||||
|
'granularity' => 'daily' |
||||
|
], |
||||
|
'month' =>[ |
||||
|
'startTime' => $dateData['month']['c_start_time'], |
||||
|
'endTime' => date("c"), |
||||
|
'granularity' => 'monthly' |
||||
|
], |
||||
|
'year' =>[ |
||||
|
'startTime' => date("c",strtotime("-10 year")), |
||||
|
'endTime' => date("c",time()), |
||||
|
'granularity' => 'yearly' |
||||
|
] |
||||
|
|
||||
|
]; |
||||
|
|
||||
|
$requestData = []; |
||||
|
|
||||
|
try { |
||||
|
$ids = Pass::getGroupIds(1); |
||||
|
|
||||
|
foreach ($dateArr as $date => $value) { |
||||
|
|
||||
|
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups"; |
||||
|
$granularity = $value['granularity']; |
||||
|
|
||||
|
$dataArr = [ |
||||
|
'granularity' => $granularity, |
||||
|
'startTime' => $value['startTime'], |
||||
|
'endTime' => $value['endTime'], |
||||
|
'ids' => $ids |
||||
|
]; |
||||
|
|
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = post_token($url,$json_data,false,[],$token); |
||||
|
|
||||
|
$res_data = json_decode($result,true); |
||||
|
if ($res_data['code'] != 0) throw new \Exception('请求失败'); |
||||
|
$list = (array)$res_data['data']['list']; |
||||
|
foreach ($list as $val) { |
||||
|
$insert_arr = [ |
||||
|
'groupId' => $val['groupId'], |
||||
|
'groupName' => $val['groupName'], |
||||
|
'flowInNum' => $val['flowInNum'], |
||||
|
'flowOutNum' => $val['flowOutNum'], |
||||
|
'noRepeatInNum' => $val['noRepeatInNum'], |
||||
|
'noRepeatOutNum' => $val['noRepeatOutNum'], |
||||
|
'holdValue' => $val['holdValue'], |
||||
|
'createTime' => $val['createTime'], |
||||
|
'updateTime' => $val['updateTime'], |
||||
|
'netValue' => $val['netValue'], |
||||
|
'statTime' => $val['statTime'], |
||||
|
'granularity' => $granularity, |
||||
|
'date' => $date, |
||||
|
]; |
||||
|
|
||||
|
$requestData[] = $insert_arr; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} catch (\Exception $e) { |
||||
|
return $e->getMessage(); |
||||
|
} |
||||
|
|
||||
|
$requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowAll', $config['host_path']); |
||||
|
|
||||
|
if (!$requestRes['status']) { |
||||
|
return $requestRes['msg']; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\tasks; |
||||
|
|
||||
|
use task\module\Pass\Pass; |
||||
|
|
||||
|
$Passall = new Passreal(); |
||||
|
echo $Passall->run(); |
||||
|
class Passreal |
||||
|
{ |
||||
|
public function run() |
||||
|
{ |
||||
|
include_once '../common.php'; |
||||
|
include_once '../module/Pass/Pass.php'; |
||||
|
$config = config('api_config'); |
||||
|
|
||||
|
$requestData = []; |
||||
|
|
||||
|
try{ |
||||
|
|
||||
|
$url = $config['host_url'] . "/api/cfas/v3/passenger/realTime"; |
||||
|
$dataArr = Pass::getGroupIds(2); |
||||
|
|
||||
|
$token = get_access_token(); |
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = post_token($url,$json_data,false,[],$token); |
||||
|
|
||||
|
$res_data = json_decode($result,true); |
||||
|
|
||||
|
$list = (array) $res_data['data']; |
||||
|
|
||||
|
foreach ($list as $value) { |
||||
|
|
||||
|
$insert_arr = [ |
||||
|
'groupId' => $value['groupId'], |
||||
|
'regionId' => $value['regionId'], |
||||
|
'statisticsTime' => $value['statisticsTime'], |
||||
|
'enter' => $value['enter'], |
||||
|
'exit' => $value['exit'], |
||||
|
'pass' => $value['pass'] ?: '', |
||||
|
'holdValue' => $value['holdValue'], |
||||
|
'allEnter' => $value['allEnter'], |
||||
|
'allExit' => $value['allExit'] |
||||
|
]; |
||||
|
|
||||
|
#Db::table('bt_passenger_flow_real')->insert($insert_arr); |
||||
|
$requestData[] = $insert_arr; |
||||
|
} |
||||
|
|
||||
|
} catch (\Exception $e) { |
||||
|
return $e->getMessage(); |
||||
|
} |
||||
|
|
||||
|
$requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowReal', $config['host_path']); |
||||
|
|
||||
|
if (!$requestRes['status']) { |
||||
|
return $requestRes['msg']; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace task\tasks; |
||||
|
|
||||
|
use task\module\Pass\Pass; |
||||
|
|
||||
|
$Video = new Video(); |
||||
|
echo $Video->run(); |
||||
|
class Video |
||||
|
{ |
||||
|
public function run() |
||||
|
{ |
||||
|
include_once '../common.php'; |
||||
|
include_once '../module/Pass/Pass.php'; |
||||
|
$config = config('api_config'); |
||||
|
$url = $config['host_url'] . "/api/resource/v1/cameras"; |
||||
|
$token = get_access_token(); |
||||
|
|
||||
|
# 获取视频资源 |
||||
|
try { |
||||
|
|
||||
|
$dataArr = [ |
||||
|
'pageNo' => 1, |
||||
|
'pageSize' => 100, |
||||
|
]; |
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = post_token($url,$json_data,false,[],$token); |
||||
|
|
||||
|
$res_data = json_decode($result,true); |
||||
|
if ($res_data['code'] != 0) throw new \Exception('请求失败'); |
||||
|
$list = (array)$res_data['data']['list']; |
||||
|
|
||||
|
$requestData = []; |
||||
|
foreach ($list as $row) { |
||||
|
|
||||
|
# 获取监控点视频链接 |
||||
|
$cameraIndexCode = $row['cameraIndexCode']; |
||||
|
$url2 = $config['host_url'] . "/api/video/v2/cameras/previewURLs"; |
||||
|
$dataArr2 = [ |
||||
|
'cameraIndexCode' => $cameraIndexCode, |
||||
|
'streamType' => 0, |
||||
|
'transmode' => $row['transType'], |
||||
|
'expand' => 'transcode=0', |
||||
|
'protocol' => 'rtmp', |
||||
|
'streamform' => 'ps' |
||||
|
]; |
||||
|
$json_data2 = json_encode($dataArr2); |
||||
|
$result2 = post_token($url2,$json_data2,false,[],$token); |
||||
|
$res_data2 = json_decode($result2,true); |
||||
|
if ($res_data2['code'] != 0) throw new \Exception('请求失败'); |
||||
|
$list2 = (array)$res_data2['data']; |
||||
|
foreach ($list2 as $row2) { |
||||
|
|
||||
|
$requestData[] = $insert = [ |
||||
|
'cameraIndexCode' => $cameraIndexCode, |
||||
|
'cameraName' => $row['cameraName'], |
||||
|
'cameraType' => $row['cameraType'], |
||||
|
'cameraTypeName' => $row['cameraTypeName'], |
||||
|
'regionIndexCode' => $row['regionIndexCode'], |
||||
|
'transTypeName' => $row['transTypeName'], |
||||
|
'transType' => $row['transType'], |
||||
|
'createTime' => $row['createTime'], |
||||
|
'url' => $row2 |
||||
|
]; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
$requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createVideo', $config['host_path']); |
||||
|
|
||||
|
if (!$requestRes['status']) { |
||||
|
return $requestRes['msg']; |
||||
|
} |
||||
|
|
||||
|
} catch (\Exception $e) { |
||||
|
return $e->getMessage(); |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue