1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Post;
- use App\Models\PostData;
- use App\Repositories\PostRepositories;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class PostCreate extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'post:create';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '根据数据创建帖子';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct(PostRepositories $postRepositories)
- {
- parent::__construct();
- $this->postRepositories = $postRepositories;
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->line(date('Y-m-d H:i:s').'开始创建帖子');
- $key = "community_post_create";
- $posts = Redis::smembers($key);
- Log::debug('帖子数据:' . json_encode($posts));
- foreach ($posts as $post) {
- $row = $this->postRepositories->createPost(json_decode($post));
- Log::debug(date("Y-m-d H:i:s") . "创建帖子:" . json_encode($row));
- }
- $this->line(date('Y-m-d H:i:s').' 创建帖子结束');
- }
- }
|