mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?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;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class BusinessOrdersUpdate
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public $businessGoodSku;
|
|
public $num;
|
|
public $goodsSku;
|
|
public $combinationGoodsUpdate = true;
|
|
|
|
/**
|
|
* Create a new event instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($businessGoodSku, $num)
|
|
{
|
|
$this->businessGoodSku = $businessGoodSku->toArray();
|
|
$this->num = $num;
|
|
$this->updateStock();
|
|
}
|
|
|
|
private function updateStock()
|
|
{
|
|
$this->goodsSku = GoodsSku::query()
|
|
->where('external_sku_id', $this->businessGoodSku['external_sku_id'])
|
|
->first();
|
|
if ($this->goodsSku) {
|
|
$this->goodsSku->stock += $this->num;
|
|
$this->goodsSku->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the channels the event should broadcast on.
|
|
*
|
|
* @return \Illuminate\Broadcasting\Channel|array
|
|
*/
|
|
public function broadcastOn()
|
|
{
|
|
return new PrivateChannel('channel-name');
|
|
}
|
|
}
|