businessGoods = $item; } else { $this->businessGoods = $item->toArray(); } $this->num = $num; $this->updateStock(); } private function updateStock() { try { $this->goodsSku = GoodsSku::query() ->with([ 'combinationGoods', 'combinationGoods.goodsSkuItem:id,external_sku_id', ]) ->where('external_sku_id', $this->businessGoods['external_sku_id']) ->first(); } catch (\Exception $e) { Log::error('事件库存更新失败: ' . $e->getMessage()); return false; } if ($this->goodsSku) { $this->goodsSku->stock += $this->num; $this->goodsSku->save(); foreach ($this->goodsSku->combinationGoods as $item) { $this->businessGoods['external_sku_id'] = $item['goodsSkuItem']['external_sku_id']; event(new BusinessOrdersUpdate($this->businessGoods, 0 - $item['item_num'])); } } } /** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { return new PrivateChannel('channel-name'); } }