argument('lotteryType'); if (!LottType::hasValue($lotteryType)) { dd('error lotteryType:',[$lotteryType]); } $ids = $this->argument('ids'); if (!$ids) { dd('请输win结果ids'); } switch ($lotteryType) { case LottType::JCZQ: $this->winJczq($ids); return; case LottType::JCLQ: $this->winJclq($ids); return; case LottType::CTZQ_JQC: $this->winCtzqJqc($ids); return; case LottType::CTZQ_BQC: $this->winBqcJqc($ids); return; } } public function winBqcJqc($ids) { dump('CtzqBqc------:', $ids); $idArr = explode(',', $ids); foreach ($idArr as $id) { RefreshOrderCtzqBqcResult::dispatch($id); } } public function winCtzqJqc($ids) { dump('CtzqJqc------:', $ids); $idArr = explode(',', $ids); foreach ($idArr as $id) { RefreshOrderCtzqJqcResult::dispatch($id); } } public function winJclq($ids) { dump('JclqResult------:', $ids); $idArr = explode(',', $ids); foreach ($idArr as $id) { RefreshOrderJclqResult::dispatch($id); } } public function winJczq($ids) { dump('JczqResult------:', $ids); $idArr = explode(',', $ids); foreach ($idArr as $id) { RefreshOrderJczqResult::dispatch($id); } } public function testwin() { $this->orderId = 126; Log::info('ComputeBjdcOrderPrize::start, orderId:' . $this->orderId); $unPublishes = OrderBjdcResult::where('order_id')->where('published', BoolEnum::NO)->count(); if ($unPublishes > 0) { Log::error('ComputeBjdcOrderPrize has no publish match, orderId:' . $this->orderId); return; } $order = Order::find($this->orderId); if ($order->lottery_state != LottState::WAIT) { Log::error('ComputeBjdcOrderPrize 订单状态不是待开奖状态, orderId:' . $this->orderId); return; } $odds = $order->odds; $jczqOddsIds = array_keys($odds); $result = BjdcResult::whereIn('bjdc_odds_id', $jczqOddsIds)->get(); if (count($result) != count($jczqOddsIds)) { Log::error('ComputeBjdcOrderPrize 开奖结果和投注信息中的id对应不上', [ 'order_id' => $this->orderId, 'order_odds' => $odds, 'order_odds_ids' => $jczqOddsIds, 'result_odds_ids' => $result->pluck('bjdc_odds_id')->toArray(), ]); return; } $results = BjdcResult::whereIn('bjdc_odds_id', $jczqOddsIds)->get()->keyBy('bjdc_odds_id'); $orderZuhe = OrderBjdcZuhe::where('order_id', $this->orderId)->get(); foreach ($orderZuhe as $zuhe) { $this->computeZuhePrize($zuhe, $order, $results); } $winedZuhe = OrderBjdcZuhe::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(); return; } $winPrize = $winedZuhe->sum('win_prize'); $winTaxPrize = $winedZuhe->sum('win_tax_prize'); $shouldSendPrize = $winTaxPrize; $gendanBrokerage = 0; if ($order->type == OrderType::GENDAN) { $gendanBrokerage = $winTaxPrize* Config::fadanAllFeeLv(); $shouldSendPrize = $winTaxPrize - $gendanBrokerage; } $order->lottery_state = LottState::WIN; $order->lottery_prize = $winPrize; $order->lottery_tax_prize = $winTaxPrize; $order->lottery_should_send_prize = $shouldSendPrize; $order->lottery_gendan_brokerage = $gendanBrokerage; $order->win_date = date('Ymd'); $order->save(); OrderWinedEvent::dispatch($order->id); } public function computeZuhePrize(OrderBjdcZuhe $orderZuhe, $order, $results) { $odds = $order->odds; $buyOddsId = array_keys($odds); $allWin = true; $winPrize = 0; $taxPrize = 0; foreach ($orderZuhe->bjdc_odds_ids as $bjdc_odds_id) { if (!in_array($bjdc_odds_id, $buyOddsId)) { $allWin = false; break; } // dump($orderZuhe->id.'-----------------------'.$bjdc_odds_id); $buyPlayKey = Arr::get($orderZuhe->info, $bjdc_odds_id . '.play'); $buyResultKey = Arr::get($orderZuhe->info, $bjdc_odds_id . '.result'); if ($buyPlayKey === null || $buyResultKey === null) { $allWin = false; Log::error('ComputeBjdcOrderPrize::checkZuhePrize error, 组合中没有该比赛信息', [ 'zuhe_id' => $orderZuhe->id, 'order_id' => $order->id, 'zuhe_odds_ids' => $orderZuhe->bjdc_odds_ids, 'zuhe_info' => $orderZuhe->info, ]); break; } // 3.rq_odds.win = 3.85 $buyOdds = Arr::get($odds, $bjdc_odds_id . '.' . $buyPlayKey . '.' . $buyResultKey); if ($buyOdds === null) { $allWin = false; Log::error('ComputeBjdcOrderPrize::checkZuhePrize error, 购买的投注信息中和组合中的数据不一致', [ 'zuhe_id' => $orderZuhe->id, 'order_id' => $order->id, 'zuhe_odds_ids' => $orderZuhe->bjdc_odds_ids, 'zuhe_info' => $orderZuhe->info, 'order_odds' => $odds, ]); break; } $result = Arr::get($results, $bjdc_odds_id); $buyField = str_replace('_odds', '', $buyPlayKey); dump([ '$result' => $result->toArray(), '$buyField' => $buyField, '$buyResultKey' => $buyResultKey, 'comp' => $result->{$buyField.'_field'} == $buyResultKey ]); if ($result->{$buyField.'_field'} == $buyResultKey) { // 单注奖金 $perBetsPrize = $orderZuhe->bets_num * $buyOdds * Config::lotteryUnitPrice() * Config::bjdcPrizePercent(); $taxPrize += Config::getAfterTaxPrize($perBetsPrize); $winPrize += $perBetsPrize; } else { $allWin = false; } } dd($winPrize, $allWin); // 该组合没有中奖 if (!$allWin) { return; } $orderZuhe->win_prize = $winPrize; $orderZuhe->win_tax_prize = $taxPrize; $orderZuhe->wined = BoolEnum::YES; $orderZuhe->save(); } }