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