<?php

namespace App\Listeners;

use App\Events\CustomerStored;
use App\OrderPackage;

class FulfillPackageCustomer
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  CustomerStored  $event
     * @return bool
     */
    public function handle(CustomerStored $event)
    {
        $packages=OrderPackage::with('WMSReflectPackage')->where('status','记录异常')->orWhere('status','已上传异常')->get();
        foreach ($packages as $package){
            if (isset($package->WMSReflectPackage->Customer)&&$package->WMSReflectPackage->Customer==$event->owner->code){
                $package->status="未测量";
                $package->owner_id=$event->owner->id;
                $package->save();
            }
        }
        return false;
    }
}
