<?php namespace App\Jobs\Company\LiveLuckyBag;

use App\Facades\Servers\Logs\Log;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class LuckyBagJobs implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /** 奖项列表 **/
    protected $winList;

    /**
     * 任务可尝试的次数
     *
     * @var int
     */
    public $tries = 3;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($list)
    {
        $this->winList    = $list;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // 获取数据
        $winList                               = $this->winList;
        try {
            // 循环分派任务
            foreach ($winList as $item)           {
                // 上锁
                LuckyBagRewardJobs::dispatch($item);
            }
        } catch (Throwable $th) {
            Log::info('job_error/live_Lucky_bag_jobs', $th->getMessage(), $winList);
        }
    }


}
