<?php

namespace App;

use App\Jobs\MeasuringMachineQueue;
use Illuminate\Database\Eloquent\Model;
use App\Traits\ModelTimeFormat;
use Illuminate\Support\Carbon;

use App\Traits\ModelLogChanging;

class MeasuringMachine extends Model
{
    use ModelLogChanging;

    use ModelTimeFormat;
    protected $fillable=[
        'name','code','status',
    ];


    //上线下线
    public function turnOn(){
        if($this['status']=='在线')return;
        $this['status']='在线';
        $this->save();
        /*$package=Package::with('owner','paperBox','measuringMachine')->
        where('measuring_machine_id',$measuringMachine->id)->orderBy('id','DESC')->first();
        if (!$package){
            $package=new Package();
            if ($measuringMachine)$package->measuringMachine=$measuringMachine;
        }
        event(new WeightEvent($package));*/
    }
    public function turnOffInMinutes($minutes){
        MeasuringMachineQueue::dispatch($this)->delay(Carbon::now()->addMinutes($minutes));
    }
}
