<?php

namespace App\Jobs;

use App\Services\LogService;
use App\Services\WaybillService;
use App\Waybill;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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


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

    /**
     * Execute the job.
     *
     * @param WaybillService $service
     * @return void
     * @throws
     */
    public function handle(WaybillService $service)
    {
        try{
            $service->createInstantBill($this->waybill);
        }catch (\Exception $e){
            LogService::log(__METHOD__,"ERROR-运输计算运费失败",$this->waybill->toJson()." | ".$e->getMessage());
            throw new \Exception($e->getMessage());
        }
    }
}
