<?php

namespace App\Jobs;

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

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


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

    /**
     *
     * @param OrderService $service
     * @return void
     */
    public function handle(OrderService $service)
    {
        try{
            $service->createInstantBill($this->order);
        }catch (\Exception $e){
            LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson()." | ".$e->getMessage());
        }
    }
}
