4 changed files with 156 additions and 13 deletions
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
namespace app\command; |
||||
|
|
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Argument; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
class passengerFlowAll extends Command |
||||
|
{ |
||||
|
|
||||
|
protected function configure() |
||||
|
{ |
||||
|
$this->setName('passengerFlow') |
||||
|
->addArgument('name', Argument::OPTIONAL, "your name") |
||||
|
->addOption('city', null, Option::VALUE_REQUIRED, 'city name') |
||||
|
->setDescription('Say Hello'); |
||||
|
} |
||||
|
|
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
$config = config('app'); |
||||
|
$dateData = getTargetDate(); |
||||
|
$token = getAccessToken(); |
||||
|
|
||||
|
$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' |
||||
|
] |
||||
|
|
||||
|
]; |
||||
|
|
||||
|
try { |
||||
|
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' => '01' // --- <replace> --- // |
||||
|
]; |
||||
|
|
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = postToken($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, |
||||
|
]; |
||||
|
|
||||
|
Db::table('tp_passenger_flow_all')->insert($insert_arr); |
||||
|
} |
||||
|
} |
||||
|
$output->writeln('完成'); |
||||
|
} catch (\Exception $e) { |
||||
|
$output->writeln($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
<?php |
||||
|
namespace app\command; |
||||
|
|
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Argument; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
class passengerFlowReal extends Command |
||||
|
{ |
||||
|
|
||||
|
protected function configure() |
||||
|
{ |
||||
|
$this->setName('passengerFlow') |
||||
|
->addArgument('name', Argument::OPTIONAL, "your name") |
||||
|
->addOption('city', null, Option::VALUE_REQUIRED, 'city name') |
||||
|
->setDescription('Say Hello'); |
||||
|
} |
||||
|
|
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
$config = config('app'); |
||||
|
|
||||
|
try{ |
||||
|
|
||||
|
$url = $config['host_url'] . "/api/cfas/v3/passenger/realTime"; |
||||
|
$dataArr = [ |
||||
|
'01' // --- <replace> --- // |
||||
|
]; |
||||
|
|
||||
|
$token = getAccessToken(); |
||||
|
$json_data = json_encode($dataArr); |
||||
|
$result = postToken($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('tp_passenger_flow_real')->insert($insert_arr); |
||||
|
} |
||||
|
|
||||
|
$output->writeln('完成'); |
||||
|
} catch (\Exception $e) { |
||||
|
$output->writeln($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue