2022-08-16 21:02:31 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
|
|
|
|
|
use App\Models\GoodsSku;
|
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
|
|
|
use Illuminate\Broadcasting\PresenceChannel;
|
|
|
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
|
|
class StockUpdateEvent
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
|
|
|
|
|
|
public $goodsSku;
|
|
|
|
|
public $goodsSkus;
|
2022-11-04 16:45:22 +08:00
|
|
|
public $isBatch;
|
2022-08-16 21:02:31 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new event instance.
|
|
|
|
|
*
|
2022-09-15 17:36:36 +08:00
|
|
|
* @param $data array|object
|
|
|
|
|
*
|
2022-08-16 21:02:31 +08:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2022-11-04 16:45:22 +08:00
|
|
|
public function __construct($data, $isBatch = 0)
|
2022-08-16 21:02:31 +08:00
|
|
|
{
|
2022-11-04 16:45:22 +08:00
|
|
|
$this->isBatch = $isBatch;
|
2022-08-16 21:02:31 +08:00
|
|
|
if (is_array($data)) {
|
2022-09-15 17:36:36 +08:00
|
|
|
// ids集合
|
2023-04-17 18:56:59 +08:00
|
|
|
$this->goodsSkus = GoodsSku::query()->whereIn('id', $data)->get();
|
2022-08-16 21:02:31 +08:00
|
|
|
} else {
|
2022-09-15 17:36:36 +08:00
|
|
|
// GoodsSku Elo模型对象
|
2022-08-16 21:02:31 +08:00
|
|
|
$this->goodsSku = $data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the channels the event should broadcast on.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Broadcasting\Channel|array
|
|
|
|
|
*/
|
|
|
|
|
public function broadcastOn()
|
|
|
|
|
{
|
|
|
|
|
return new PrivateChannel('channel-name');
|
|
|
|
|
}
|
|
|
|
|
}
|