<?php

namespace App\Console\Commands;

use App\Events\SendSmsEvent;
use App\Models\Article;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

class Shelves extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shelves';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '微聊定时上架';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Log::info('微聊定时上架正在运行 ing');
        $res=Article::where('is_timing',1)->where('shelves',0)->where('timing_shelves','<=',Carbon::now())->update([
            'shelves' => 1,'shelves_time'=>Carbon::now()
        ]);
        if($res){
            event(new SendSmsEvent());
            Log::info('微聊定时上架已完成 ed');
        }else{
            Log::info('没有需要定时上架的微聊 no');
        }
    }
}
