<?php

namespace App\Jobs;

use App\Http\Controllers\Controller;
use App\OrderPackage;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

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


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

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $controller= new Controller();
        if (!$this->package){
            $controller->log(__METHOD__,'error_'.__FUNCTION__,"队列传递的package为空",null);
            return;
        }
        $pickedPackage=OrderPackage::query()->where('id',$this->package->id)->first();
        if(!$pickedPackage){
            $controller->log(__METHOD__,'error_'.__FUNCTION__,"队列查询的package为空",null);
            return;
        }
        if (!$pickedPackage->delivery_number){
            $pickedPackage->status="下发异常";
            $pickedPackage->save();
        }
        if (!$pickedPackage->weight){
            $pickedPackage->status="测量异常";
            $pickedPackage->save();
        }
    }
}
