bjdcResultId = $bjdcResultId; $this->queue = config('queue.names.refresh_order_odds'); } public function getData() { return [ 'bjdcResultId' => $this->bjdcResultId ]; } public function handle() { $result = BjdcResult::find($this->bjdcResultId); if (!$result) { Log::error("RefreshOrderBjdcResult not found resultId,", $this->getData()); return; } OrderBjdcResult::leftJoin('order', 'order.id', '=', 'order_bjdc_result.order_id') ->select('order_bjdc_result.*') ->where('order.lottery_state', LottState::WAIT) ->where('order_bjdc_result.published', BoolEnum::NO) ->where('order_bjdc_result.bjdc_odds_id', $result->bjdc_odds_id) ->chunkById(500, function ($data) { if (count($data) <= 0) { return; } // 更新发布状态 $orderResultIds = $data->pluck('id')->toArray(); OrderBjdcResult::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 = OrderBjdcResult::where('order_id', $orderId) ->where('published', BoolEnum::NO)->count(); // 如果全部已公布,则计算奖金 if ($unPublishes == 0) { Log::info('dispatch ComputeBjdcOrderPrize, orderId:'.$orderId); ComputeBjdcOrderPrize::dispatch($orderId); } } }