<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use App\Jobs\Settlement as JobSettlement;

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

    /**
     * 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()
    {
        $date = date('YmdHis', strtotime("-1 seconds"));
        $room_list = Redis::lrange("Game_settlement_{$date}", 0, -1);
        foreach ($room_list as $k => $room) {
            //加入任务队列
            JobSettlement::dispatch($room)->onQueue('settlement');
        }
        Redis::del("Game_settlement_{$date}");
    }
}
