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'], ]; } /** * 获取文件内容 * * @return void */ protected function getFile() { $file = storage_path('app/command/' . env('APP_ENV') . '_' . $this->filename); if (!file_exists($file)) { $dir = dirname($file); if (null !== $dir && !is_dir($dir)) { mkdir($dir, 0777, true); } $this->saveFile(0, $this->initCursor); } $contents = file_get_contents($file); return json_decode($contents, 256); } /** * 写入文件 * * @param integer $status 状态 1运行中 0运行结束 * @param integer $cursor 游标 * @return void */ protected function saveFile(int $status, int $cursor) { $file = storage_path('app/command/' . env('APP_ENV') . '-' . $this->filename); $contents = json_encode([ 'status' => $status, 'cursor' => $cursor, ]); file_put_contents($file, $contents); } }