ctzqSfcId = $ctzqSfcId; $this->queue = config('queue.names.refresh_order_odds'); } public function getData() { return [ 'ctzqSfcId' => $this->ctzqSfcId ]; } public function handle() { $ctzq = CtzqSfc::find($this->ctzqSfcId); if (!$ctzq) { Log::error("RefreshOrderCtzqSfc14Result not found ctzqSfcId:". $this->ctzqSfcId); return; } $matches = CtzqSfcMatch::where('ctzq_sfc_id', $ctzq->id)->get()->keyBy('id'); OrderCtzqSfcResult::select('*') ->where('ctzq_sfc_id', $ctzq->id) ->where('lottery_type', LottType::CTZQ_SFC14) ->where('published', BoolEnum::NO) ->chunkById(500, function ($data) use ($matches, $ctzq) { if (count($data) <= 0) { return; } $orderIds = []; foreach ($data as $orderResult) { $matchResult = Arr::get($matches, $orderResult->ctzq_sfc_match_id); if (!$matchResult) { Log::error("RefreshOrderCtzqSfc14Result not found ctzq_jqc_match",[ 'ctzq_sfc_match_id' => $orderResult->ctzq_sfc_match_id, 'ctzq_sfc_id' => $ctzq->id, 'order_id' => $orderResult->order_id, 'OrderCtzqJqcResult_id' => $orderResult->id, ]); continue; } $orderIds[$orderResult->order_id] = $orderResult->order_id; // 更新状态 $orderResult->published = BoolEnum::YES; $orderResult->result = $matchResult->result; $orderResult->save(); } // 执行计算任务 foreach ($orderIds as $orderId) { $this->dispatchComputeOrderPrize($orderId); } }); } private function dispatchComputeOrderPrize($orderId) { $unPublishes = OrderCtzqSfcResult::where('order_id', $orderId) ->where('published', BoolEnum::NO)->count(); // 如果全部已公布,则计算奖金 if ($unPublishes == 0) { Log::info('dispatch ComputeCtzqSfc14OrderPrize, orderId:'.$orderId); ComputeCtzqSfc14OrderPrize::dispatch($orderId); } } }