goodsSku = $goodsSku; $this->checkStatusAndStock($goodsSku); } private function checkStatusAndStock($goodsSku) { //新版上下架和真实库存无关 $stock = $goodsSku->sale_stock; if (0 >= $goodsSku->sale_stock) { $status = GoodsSku::$STATUS_DOWN; } else { $status = GoodsSku::$STATUS_ON_SALE; } //TODO 待确认逻辑 $arrivedTodayNum = DailyStockRecord::query() ->where('day', DateTimeUtils::getToday()) ->where('sku_id', $goodsSku->id) ->value('arrived_today_num'); if (20 < $arrivedTodayNum + $goodsSku->yesterday_num && 4 > $goodsSku->stock) { $status = GoodsSku::$STATUS_DOWN; $stock = 0; } $goodsSku->status = $status; $goodsSku->stock = $stock; $goodsSku->save(); } /** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { return new PrivateChannel('channel-name'); } }