mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 22:50:44 +00:00
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Models\DailyStockRecord;
|
|
use App\Models\GoodsSku;
|
|
use App\Utils\DateTimeUtils;
|
|
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 $combinationGoodsUpdate = true;
|
|
|
|
/**
|
|
* Create a new event instance.
|
|
*
|
|
* @param $goodsSku
|
|
*/
|
|
public function __construct($goodsSku)
|
|
{
|
|
$this->goodsSku = $goodsSku;
|
|
$this->checkStatusAndStock($goodsSku);
|
|
}
|
|
|
|
private function checkStatusAndStock($goodsSku)
|
|
{
|
|
//新版上下架和真实库存无关
|
|
if (0 >= $goodsSku->sale_stock) {
|
|
$status = GoodsSku::$STATUS_DOWN;
|
|
} else {
|
|
$status = GoodsSku::$STATUS_ON_SALE;
|
|
}
|
|
|
|
$goodsSku->status = $status;
|
|
$goodsSku->save();
|
|
}
|
|
|
|
/**
|
|
* Get the channels the event should broadcast on.
|
|
*
|
|
* @return \Illuminate\Broadcasting\Channel|array
|
|
*/
|
|
public function broadcastOn()
|
|
{
|
|
return new PrivateChannel('channel-name');
|
|
}
|
|
}
|