2019-08-21 16:58:59 +08:00

52 lines
1.5 KiB
PHP

<?php
namespace App\Domains\Virtual\Commands\Sync;
use Carbon\Carbon;
use Illuminate\Console\Command as BaseCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Command extends BaseCommand
{
protected $filename = 'sync-command.json';
protected $initCursor = 0; // '2000-01-01 00:00:00'
/**
* Execute the console command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return mixed
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->line(printf('[%s] 开始%s', date("Y-m-d H:i:s"), $this->description));
begin_time_consuming();
parent::execute($input, $output);
}
protected function getDateTime()
{
if ($month = $this->argument('month')) {
if (!preg_match('/\d{4}-\d{1,2}/', $month)) {
throw new \App\Exceptions\InvalidArgumentException('请输入正确的年月 #示例: 2018-10');
}
return Carbon::parse($month)->startOfMonth();
}
return Carbon::now()->startOfMonth()->subMonth();
}
protected function getArguments()
{
return [
['month', InputArgument::OPTIONAL, '要同步的数据月份,默认上个月 #示例: 2018-10'],
];
}
}