<?php

namespace App\Listeners;

use App\Events\CommissionGotEvent;
use App\Jobs\UnfreezeCommission;
use Illuminate\Support\Facades\Log;

class UnfreezeCommissionListener
{
    public function __construct()
    {
    }

    public function handle(CommissionGotEvent $event): void
    {
        $order_commission = $event->order_commission;
        Log::info('order_commission'.$order_commission->id.'佣金解锁任务start');
        // 解冻佣金任务入队
        if (config('app.env')== 'production'){
//            $delay = now()->addDays(7);
            $delay = now()->addDays($order_commission->delay)->addSecond(10);
            UnfreezeCommission::dispatch($order_commission)->onQueue('health')->delay($delay);
        }else{
            UnfreezeCommission::dispatch($order_commission);
        }

        Log::info('order_commission'.$order_commission->id.'佣金解锁任务end');
    }
}
