<?php

namespace App\Console\Commands\Upgrade;

use App\Models\Log\FeedLogModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class SliceTableFeedLog extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'upgrade:sliceTableFeedLog';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'feedLog表分表操作的升级脚本';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        FeedLogModel::where('id', '>', 0)->orderBy('id', 'asc')->each(function (/** @var FeedLogModel $item */ $item) {
            FeedLogModel::create([
                'created_at' => $item->created_at,
                'updated_at' => $item->updated_at,
                'uid' => $item->uid,
                'partner_id' => $item->partner_id,
                'ismock' => $item->ismock
            ]);
            Redis::set("upgrade:sliceTableFeedLog", $item->id);
        });
    }
}
