35 lines
675 B
PHP
35 lines
675 B
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Models\Param;
|
|
use App\Models\ProfitLog;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use RuLong\Order\Events\OrderPaid as OrderPaidEvent;
|
|
|
|
class ProfitListener implements ShouldQueue
|
|
{
|
|
|
|
public $queue = 'LISTENER';
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param OrderPaidEvent $event
|
|
* @return void
|
|
*/
|
|
public function handle(OrderPaidEvent $event)
|
|
{
|
|
$order = $event->order;
|
|
$profit = 0;
|
|
|
|
foreach ($order->details as $key => $detail) {
|
|
$profit += $detail->item->profit;
|
|
}
|
|
|
|
if ($profit > 0) {
|
|
ProfitLog::addPrfit($profit);
|
|
}
|
|
}
|
|
}
|