1,controller中调用
event( new OrderApproved ( $reportTaskModel )) ;
2,app/Event/
OrderApproved .php中继承event
class OrderApproved extends Event
{
use SerializesModels ;
/**
* @var InventoryHistoryDetailsReportTask
*/
public $reportTask ;
/**
* Create a new event instance.
*
* @param ReportTask $reportTask
*/
public function __construct (ReportTask $reportTask )
{
//
$this -> reportTask = $reportTask ;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn ()
{
return [] ;
}
} 3,app/Providers/EventServiceProvider.php中绑定
protected $listen = [
'SocialiteProviders\Manager\SocialiteWasCalled' => [
// add your listeners (aka providers) here
'SocialiteProviders\Thebizark\ThebizarkExtendSocialite@handle' ,
'SocialiteProviders\Qq\QqExtendSocialite@handle' ,
'SocialiteProviders\Weibo\WeiboExtendSocialite@handle' ,
'SocialiteProviders\Weixin\WeixinExtendSocialite@handle' ,
'SocialiteProviders\Live\LiveExtendSocialite@handle' ,
] ,
\App\Events\OrderApproved:: class => [
\App\Listeners\OrderApprovedEventListenerNotification:: class ,
] ,]
4,
OrderApprovedEventListenerNotification.php中处理物理逻辑(
updateInventoryStatus )
class
OrderApprovedEventListenerNotification
{
/**
*
@var
DetailsReportServiceTask
*/
private
$detailsReportServiceTask
;
/**
* Create the event listener.
*
*
@param
DetailsReportServiceTask $detailsReportServiceTask
*/
public function
__construct
(DetailsReportServiceTask
$detailsReportServiceTask
)
{
//
$this
->
detailsReportServiceTask
=
$detailsReportServiceTask
;
}
/**
* Handle the event.
*
*
@param
DetailsReportTaskApproved $event
*
@return
void
*/
public function
handle
(DetailsReportTaskApproved
$event
)
{
//
try
{
$this
->
detailsReportServiceTask
->
updateInventoryStatus
(
$event
->
detailsReportTask
,
[
'task_status'
=>DetailsReportTaskRepository::
TASKSTATUS_QUEUED
,
])
;
}
catch
(AppRuntimeException
$ex
){
// Log::error('Event updateInventoryStatus Exception',['code'=>$ex->getCode(),'message'=>$ex->getMessage()]);
}
}
}