orderId = $orderId; $this->queue = config('queue.names.compute_order_prize'); } public function handle() { Log::info('ComputeOrderPrize::start, orderId:' . $this->orderId); $unPublishes = OrderJczqResult::where('order_id')->where('published', BoolEnum::NO)->count(); if ($unPublishes > 0) { Log::error('ComputeOrderPrize has no publish match, orderId:' . $this->orderId); return; } $order = Order::find($this->orderId); if ($order->lottery_state != LottState::WAIT) { Log::error('ComputeOrderPrize 订单状态不是待开奖状态, orderId:' . $this->orderId); return; } $odds = $order->odds; $jczqOddsIds = array_keys($odds); $result = JczqResult::whereIn('jczq_odds_id', $jczqOddsIds)->get(); if (count($result) != count($jczqOddsIds)) { Log::error('ComputeOrderPrize 开奖结果和投注信息中的id对应不上', [ 'order_id' => $this->orderId, 'order_odds' => $odds, 'order_odds_ids' => $jczqOddsIds, 'result_odds_ids' => $result->pluck('jczq_odds_id')->toArray(), ]); return; } $results = JczqResult::whereIn('jczq_odds_id', $jczqOddsIds)->get()->keyBy('jczq_odds_id'); $orderZuhe = OrderZuhe::where('order_id', $this->orderId)->get(); foreach ($orderZuhe as $zuhe) { $this->computeZuhePrize($zuhe, $order, $results); } $winedZuhe = OrderZuhe::where('order_id', $this->orderId) ->where('wined', BoolEnum::YES) ->get(); if (count($winedZuhe) == 0) { $order->lottery_state = LottState::LOSS; $order->lottery_prize = 0; $order->lottery_tax_prize = 0; $order->save(); $order->updateUnionOrderState($order->lottery_state); return; } $winPrize = $winedZuhe->sum('win_prize'); $winTaxPrize = $winedZuhe->sum('win_tax_prize'); $gendanBrokerage = 0; if ($order->type == OrderType::GENDAN) { $gendanBrokerage = $winTaxPrize* Config::fadanAllFeeLv(); } $order->lottery_state = LottState::WIN; $order->lottery_prize = $winPrize; $order->lottery_tax_prize = $winTaxPrize; $order->lottery_should_send_prize = $winTaxPrize; $order->lottery_gendan_brokerage = 0; $order->lottery_gendan_brokerage_all = 0; $order->win_date = date('Ymd'); $order->save(); $order->updateUnionOrderState($order->lottery_state); OrderWinedEvent::dispatch($order->id); } public function computeZuhePrize(OrderZuhe $orderZuhe, $order, $results) { $odds = $order->odds; $buyOddsId = array_keys($odds); $allWin = true; $baseOdd = 1; foreach ($orderZuhe->jczq_odds_ids as $jczq_odds_id) { if (!in_array($jczq_odds_id, $buyOddsId)) { $allWin = false; break; } // dump($orderZuhe->id.'-----------------------'.$jczq_odds_id); $buyPlayKey = Arr::get($orderZuhe->info, $jczq_odds_id . '.play'); $buyResultKey = Arr::get($orderZuhe->info, $jczq_odds_id . '.result'); if ($buyPlayKey === null || $buyResultKey === null) { $allWin = false; Log::error('ComputeOrderPrize::checkZuhePrize error, 组合中没有该比赛信息', [ 'zuhe_id' => $orderZuhe->id, 'order_id' => $order->id, 'zuhe_odds_ids' => $orderZuhe->jczq_odds_ids, 'zuhe_info' => $orderZuhe->info, ]); break; } // 3.rq_odds.win = 3.85 $buyOdds = Arr::get($odds, $jczq_odds_id . '.' . $buyPlayKey . '.' . $buyResultKey); $result = Arr::get($results, $jczq_odds_id); if (!$result) { $allWin = false; Log::error('ComputeOrderPrize::checkZuhePrize error,未找到中奖结果', [ 'zuhe_id' => $orderZuhe->id, 'order_id' => $order->id, 'zuhe_odds_ids' => $orderZuhe->jczq_odds_ids, 'zuhe_info' => $orderZuhe->info, 'order_odds' => $odds, '$jczq_odds_id' => $jczq_odds_id, ]); } if($result->canceled()) { $buyOdds = 1; $baseOdd *= $buyOdds; continue; } if ($buyOdds === null) { $allWin = false; Log::error('ComputeOrderPrize::checkZuhePrize error, 购买的投注信息中和组合中的数据不一致', [ 'zuhe_id' => $orderZuhe->id, 'order_id' => $order->id, 'zuhe_odds_ids' => $orderZuhe->jczq_odds_ids, 'zuhe_info' => $orderZuhe->info, 'order_odds' => $odds, ]); break; } $buyField = str_replace('_odds', '', $buyPlayKey); if ($result->{$buyField.'_field'} == $buyResultKey) { $baseOdd *= $buyOdds; } else { $allWin = false; } } // 该组合没有中奖 if (!$allWin) { return; } $chuanNum = count($orderZuhe->jczq_odds_ids); $onePrize = JczqService::getTiCaiOneBetsPrize($baseOdd * Config::lotteryUnitPrice(),$chuanNum); $perBetsPrize = $orderZuhe->bets_num * $onePrize * $orderZuhe->repeat_num; $taxPrize = Config::getAfterTaxPrizeIfOne($perBetsPrize, 1 * $baseOdd * Config::lotteryUnitPrice()); $winPrize = $perBetsPrize; $orderZuhe->win_prize = $winPrize; $orderZuhe->win_tax_prize = $taxPrize; $orderZuhe->wined = BoolEnum::YES; $orderZuhe->save(); } }