5 changed files with 166 additions and 19 deletions
@ -0,0 +1,89 @@ |
|||||
|
<?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 passengerFlow 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(); |
||||
|
|
||||
|
$arr = [ |
||||
|
'hourly' => [ |
||||
|
'startTime' => $dateData['day']['c_start_time'], |
||||
|
'endTime' => $dateData['day']['c_end_time'], |
||||
|
], |
||||
|
'daily' => [ |
||||
|
'startTime' => $dateData['month']['c_start_time'], |
||||
|
'endTime' => $dateData['month']['c_end_time'], |
||||
|
], |
||||
|
'monthly' => [ |
||||
|
'startTime' => $dateData['year']['c_start_time'], |
||||
|
'endTime' => date('c'), |
||||
|
] |
||||
|
]; |
||||
|
|
||||
|
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups"; |
||||
|
|
||||
|
try { |
||||
|
foreach ($arr as $granularity => $value) { |
||||
|
|
||||
|
$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, |
||||
|
]; |
||||
|
|
||||
|
Db::table('tp_passenger_flow')->insert($insert_arr); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$output->writeln('完成'); |
||||
|
} catch (\Exception $e) { |
||||
|
$output->writeln($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//return $res_data['data']['list']; |
||||
Loading…
Reference in new issue