54 lines
1.5 KiB
PHP
54 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('开始'.$this->description);
|
|
|
|
set_time_limit(0);
|
|
ini_set('memory_limit', '4096m');
|
|
ini_set('default_socket_timeout', -1);
|
|
|
|
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'],
|
|
];
|
|
}
|
|
}
|