syncOdds(); $sellingCount = BjdcOdds::selling()->where('close_time', '>', date('Y-m-d H:i:s'))->count(); $lotteryType = LotteryType::withTrashed()->where('type', LottType::BJDC)->first(); if (!$lotteryType) { return; } $lotteryType->info = sprintf('%d场赛事可投', $sellingCount); $lotteryType->save(); } public function syncOdds() { /** @var AlStatService $alStatService */ $alStatService = app(AlStatService::class); $odds = $alStatService->getZqBjdcOdds(); if (!$odds) { return; } foreach ($odds as $item) { $id = $item['id']; $odd = BjdcOdds::where('odds_id',$id)->first(); if (!$odd) { $odd = new BjdcOdds(); } $odd->odds_id = $id; $odd->match_id = strval(Arr::get($item, 'matchId')); $odd->issue_num = strval(Arr::get($item, 'issueNum')); $odd->play_num = strval(Arr::get($item, 'playNum')); $odd->bd_competition_name = strval(Arr::get($item, 'bdComptName')); $odd->bd_competition_name_full = strval(Arr::get($item, 'bdComptNameFull')); $odd->bd_home_team_name = strval(Arr::get($item, 'bdHomeTeamName')); $odd->bd_home_team_name_full = strval(Arr::get($item, 'bdHomeTeamNameFull')); $odd->bd_away_team_name = strval(Arr::get($item, 'bdAwayTeamName')); $odd->bd_away_team_name_full = strval(Arr::get($item, 'bdAwayTeamNameFull')); $odd->sale_state = strval(Arr::get($item, 'salesState')); $odd->is_reverse = strval(Arr::get($item, 'isReverse')); $odd->close_time = strval(Arr::get($item, 'closeTime')); $odd->spf_odds = Arr::get($item, 'spfOdds'); $odd->spf_odds_last = $this->oddsLast($odd->spf_odds_last, $odd->spf_odds); $odd->rq_odds = Arr::get($item, 'rqOdds'); $odd->rq_odds_last = $this->oddsLast($odd->rq_odds_last, $odd->rq_odds); $odd->sxpds_odds = Arr::get($item, 'sxpdsOdds'); $odd->sxpds_odds_last = $this->oddsLast($odd->sxpds_odds_last, $odd->sxpds_odds); $odd->bf_odds =Arr::get($item, 'bfOdds'); $odd->bf_odds_last = $this->oddsLast($odd->bf_odds_last, $odd->bf_odds); $odd->jq_odds = Arr::get($item, 'jqOdds'); $odd->jq_odds_last = $this->oddsLast($odd->jq_odds_last, $odd->jq_odds); $odd->bqc_odds = Arr::get($item, 'bqcOdds'); $odd->bqc_odds_last = $this->oddsLast($odd->bqc_odds_last, $odd->bqc_odds); $odd->save(); } } protected function oddsLast($fieldOldData, $fieldNewData) { if (!$fieldOldData) { return $fieldNewData; } foreach ($fieldNewData as $k => $v) { if (Arr::get($fieldOldData, $k) != $v) { return $fieldNewData; } } return $fieldOldData; } }