syncOdds(); $sellingCount = BjdcSfggOdds::selling()->where('close_time', '>', date('Y-m-d H:i:s'))->count(); $lotteryType = LotteryType::withTrashed()->where('type', LottType::BJDC_SFGG)->first(); if (!$lotteryType) { return; } $lotteryType->info = sprintf('%d场赛事可投', $sellingCount); $lotteryType->save(); } public function syncOdds() { /** @var AlStatService $alStatService */ $alStatService = app(AlStatService::class); $odds = $alStatService->getZqBjdcSfggOdds(); if (!$odds) { return; } foreach ($odds as $item) { $id = $item['id']; $odd = BjdcSfggOdds::where('odds_id',$id)->first(); if (!$odd) { $odd = new BjdcSfggOdds(); } $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->sfgg_odds = Arr::get($item, 'sfggOdds', []); $odd->sfgg_odds_last = $this->oddsLast($odd->sfgg_odds_last, $odd->sfgg_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; } }