jczqGuanOddsId = $jczqGuanOddsId; $this->queue = config('queue.names.refresh_order_odds'); } public function getData() { return [ 'jczqGuanOddsId' => $this->jczqGuanOddsId ]; } public function handle() { Log::info('guankaijiang doing RefreshOrderGuanResult, guanOddsId:' .$this->jczqGuanOddsId); $result = JczqGuanOdds::find($this->jczqGuanOddsId); if (!$result) { Log::error("RefreshOrderGuanResult not found resultId,", $this->getData()); return; } OrderGuanResult::leftJoin('order', 'order.id', '=', 'order_guan_result.order_id') ->select('order_guan_result.*') ->where('order.lottery_state', LottState::WAIT) ->where('order_guan_result.published', BoolEnum::NO) ->where('order_guan_result.jczq_guan_odds_id', $result->id) ->chunkById(500, function ($data) { if (count($data) <= 0) { return; } // 更新发布状态 $orderResultIds = $data->pluck('id')->toArray(); OrderGuanResult::whereIn('id', $orderResultIds) ->update(['published' => BoolEnum::YES]); // 执行计算任务 $orderIds = $data->pluck('order_id')->toArray(); foreach ($orderIds as $orderId) { $this->dispatchComputeOrderPrize($orderId); } }); } private function dispatchComputeOrderPrize($orderId) { $unPublishes = OrderGuanResult::where('order_id', $orderId) ->where('published', BoolEnum::NO)->count(); Log::info('will dispatch ComputeGuanOrderPrize, orderId:', [ 'orderId' => $orderId, '$unPublishes' => $unPublishes, ]); // 如果全部已公布,则计算奖金 if ($unPublishes == 0) { Log::info('dispatch ComputeGuanOrderPrize, orderId:'.$orderId); ComputeGuanOrderPrize::dispatch($orderId); } } }