orderId = $orderId; $this->queue = config('queue.names.compute_order_prize'); } public function handle() { Log::info('ComputeCtzqSfc9OrderPrize::start, orderId:' . $this->orderId); $order = Order::find($this->orderId); if (!$order) { Log::error('ComputeCtzqBqcOrderPrize 订单状不存在, orderId:' . $this->orderId); return; } if ($order->lottery_state != LottState::WAIT) { Log::error('ComputeCtzqSfc9OrderPrize 订单状态不是待开奖状态, orderId:' . $this->orderId); return; } $unPublishes = OrderCtzqSfcResult::where('order_id', $this->orderId) ->where('lottery_type', LottType::CTZQ_SFC9) ->where('published', BoolEnum::NO) ->count(); if ($unPublishes > 0) { Log::error('ComputeCtzqSfc9OrderPrize has no publish match, orderId:' . $this->orderId); return; } $orderResults = OrderCtzqSfcResult::where('order_id', $this->orderId) ->where('lottery_type', LottType::CTZQ_SFC9) ->get(); if (!$orderResults || count($orderResults) < 9) { Log::error('ComputeCtzqSfc9OrderPrize 不够9场比赛数据, orderId:' . $this->orderId); return; } $win = true; $ctzqSfcId = 0; foreach ($orderResults as $orderResult) { $ctzqSfcId = $orderResult->ctzq_sfc_id; if ($orderResult->result != '*' && !in_array($orderResult->result, $orderResult->odds)) { $win = false; break; } } $winPrize = 0; if ($win) { $ctzqSfc = CtzqSfc::find($ctzqSfcId); $winPrize = $ctzqSfc->first_prize_val_nine; } $winTaxPrize = Config::getAfterTaxPrize($winPrize); $winPrize = $winPrize * $order->bets_num; $winTaxPrize = $winTaxPrize * $order->bets_num; $order->lottery_state = $win ? LottState::WIN : LottState::LOSS; $order->lottery_prize = $winPrize; $order->lottery_tax_prize = $winTaxPrize; $order->lottery_should_send_prize = $winTaxPrize; if ($win) { $order->win_date = date('Ymd'); } $order->save(); $order->updateUnionOrderState($order->lottery_state); if ($win) { OrderWinedEvent::dispatch($order->id); } } }