|
|
@@ -4,9 +4,11 @@ namespace App\Console\Commands;
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
use App\Models\Sport as SportModel;
|
|
|
+use App\Models\SportOdds as SportOddsModel;
|
|
|
use App\Services\SportClientService;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use App\Models\Config;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
class SportOdds extends Command
|
|
|
{
|
|
|
@@ -113,7 +115,8 @@ class SportOdds extends Command
|
|
|
$data = $data['response'];
|
|
|
foreach($data as $item) {
|
|
|
$data_id = $item['fixture']['id'];
|
|
|
- $odds = json_encode($item['odds']);
|
|
|
+ $odds = $this->doOdds($item['odds']);
|
|
|
+ $odds = !empty($odds) ? json_encode($odds) : null;
|
|
|
|
|
|
$update_data = [
|
|
|
'is_send' => 0,
|
|
|
@@ -196,4 +199,24 @@ class SportOdds extends Command
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //去掉无效的赔率
|
|
|
+ private function doOdds($odds) {
|
|
|
+ // 1. 获取赔率,缓存数据
|
|
|
+ $sport_odds = cache('sport_odds');
|
|
|
+ if (!$sport_odds) {
|
|
|
+ $sport_odds = SportOddsModel::where('function_name', '<>', null)->select()->toArray();
|
|
|
+ Cache::set('sport_odds', $sport_odds, 300); //有效期5分钟
|
|
|
+ }
|
|
|
+
|
|
|
+ $sport_odds = array_column($sport_odds, null,'odd_name_en');
|
|
|
+ $new_odds = [];
|
|
|
+ foreach($odds as $item) {
|
|
|
+ if (!isset($sport_odds[$item['name']])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $new_odds[] = $item;
|
|
|
+ }
|
|
|
+ return $new_odds;
|
|
|
+ }
|
|
|
+
|
|
|
}
|