input('match_id'); $match = ZqMatch::with('score') ->where('match_id', $matchId)->first(); ThrowException::isTrue(!$match, '比赛不存在'); return $this->jsonSuccess($match); } /** * @api {GET} /api/customer/zqoverview/zhishu 足球分析-指数 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code":200, * "message":"", * "data":{ * "ya":[ // 亚指,数组总长度就是公司数 * { * "company":{ // 公司信息 * "id":3, * "company_id":3, // 公司id * "name":"澳门", // 公司名 * "country":"中国澳门", * }, * "items":[ // 这个数组有两项,type=0或1 * { * "id":1, * "cdate":20230508, * "match_id":390979, * "company_id":3, * "type":0, // 类型(0: 初盘, 1: 即时盘) * "handicap":"-0.50", // 让球 * "home":"0.86", // 主队赔率 * "away":"0.94", // 客队赔率 * "change_time":"2023-05-02 23:02:14", // 变盘时间 * "created_at":"2023-05-08 20:44:28", * "updated_at":"2023-05-08 20:44:28", * "deleted_at":null * }, * ] * }, * ], * "ou":[// 欧指,数组总长度就是公司数 * { * "company":, // 同上 * "items":[ // 这个数组有两项,type=0或1 * { * "id":1, * "cdate":20230508, * "match_id":390979, * "company_id":3, * "type":0, // 类型(0: 初盘, 1: 即时盘) * "win":"1.86", //主胜赔率 * "draw":"3.55", //平局赔率 * "loss":"3.35", //客胜赔率 * "change_time":"2023-05-03 00:21:15", // 变盘时间 * "created_at":"2023-05-08 20:44:28", * "updated_at":"2023-05-08 20:44:28", * "deleted_at":null * }, * ] * }, * ], * "daxiao":[ // 大小,数组总长度就是公司数 * { * "company": // 同上 * "items":[ // 这个数组有两项,type=0或1 * { * "id":1, * "cdate":20230508, * "match_id":390979, * "company_id":13, * "type":0, // 类型(0: 初盘, 1: 即时盘) * "handicap":"2.75", //盘口 * "over":"0.90", //大球赔率 * "under":"1.00", //小球赔率 * "change_time":"2023-05-02 00:11:25", * "created_at":"2023-05-08 20:44:28", * "updated_at":"2023-05-08 20:44:28", * "deleted_at":null * }, * ] * }, * ] * } * } */ public function zhishu(Request $request) { $matchId = $request->input('match_id'); $ya = JczqZhishuYa::where('match_id', $matchId) ->get()->groupBy('company_id')->toArray(); $ou = JczqZhishuOu::where('match_id', $matchId) ->get()->groupBy('company_id')->toArray(); $daxiao = JczqZhishuDaxiao::where('match_id', $matchId) ->get()->groupBy('company_id')->toArray(); $yaCompanyIds = $ya ? array_keys($ya) : []; $ouCompanyIds = $ou ? array_keys($ou) : []; $daxiaoCompanyIds = $daxiao ? array_keys($daxiao) : []; $companyIds = array_merge($yaCompanyIds, $ouCompanyIds, $daxiaoCompanyIds); if (!$companyIds) { return $this->jsonSuccess(); } $companys = ZqCompany::whereIn('company_id',$companyIds)->get()->keyBy('company_id'); $yas = []; foreach ($ya as $companyId => $items) { $yas[] = [ 'company' => Arr::get($companys, $companyId), 'items' => $items ]; } $ous = []; foreach ($ou as $companyId => $items) { $ous[] = [ 'company' => Arr::get($companys, $companyId), 'items' => $items ]; } $daxiaos = []; foreach ($daxiao as $companyId => $items) { $daxiaos[] = [ 'company' => Arr::get($companys, $companyId), 'items' => $items ]; } return $this->jsonSuccess([ 'ya' => $yas, 'ou' => $ous, 'daxiao' => $daxiaos, ]); } /** * @api {GET} /api/customer/zqoverview/score_ranking 足球分析-积分排行 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "home" :{ // 主队 * "all":{}, // 总 * "home": { // 主 * "id": 18, * "competition_score_id": 81121, // 数据Id * "competition_id": 1, // 赛事Id * "team_id": 20, * "group_id": "0", * "season": "23/24", // 赛季 * "team_name": "伯恩利", // 球队名称 * "matches": 38, // 比赛场次 * "wins": 5, //获胜场次 * "draws": 9, //平局场次 * "losts": 24, //失利场次 * "goal_for": 41, //进球 * "goal_aga": 78, //失球 * "goal_diff": -37, //净胜球 * "points": 24, //积分 * "position": 19, //排名 * "qualificate": "降级", //入围 * "created_at": "2024-06-15 16:43:32", * "updated_at": "2024-06-15 16:43:32", * "deleted_at": null * }, * "away": { // 客 * ... * } * }, * "away":{ // 客队 * "all":{}, * "home": { * "id": 18, * "competition_score_id": 81121, // 数据Id * "competition_id": 1, // 赛事Id * "team_id": 20, * "group_id": "0", * "season": "23/24", // 赛季 * "team_name": "伯恩利", // 球队名称 * "matches": 38, // 比赛场次 * "wins": 5, //获胜场次 * "draws": 9, //平局场次 * "losts": 24, //失利场次 * "goal_for": 41, //进球 * "goal_aga": 78, //失球 * "goal_diff": -37, //净胜球 * "points": 24, //积分 * "position": 19, //排名 * "qualificate": "降级", //入围 * "created_at": "2024-06-15 16:43:32", * "updated_at": "2024-06-15 16:43:32", * "deleted_at": null * }, * "away": { * ... * } * } * } * } */ public function scoreRanking(Request $request) { $matchId = $request->input('match_id'); if (!$matchId) { return $this->jsonSuccess(); } $match = ZqMatch::where('match_id', $matchId)->first(); ThrowException::isTrue(!$match, '比赛不存在'); $homeAll = ZqCompetitionScore::where('competition_id', $match->competition_id) ->where('type', 1) ->where('season', $match->season) ->where('team_id', $match->home_team_id) ->first(); $homeHome = ZqCompetitionScore::where('competition_id', $match->competition_id) ->where('type', 2) ->where('season', $match->season) ->where('team_id', $match->home_team_id) ->first(); $homeAway = ZqCompetitionScore::where('competition_id', $match->competition_id) ->where('type', 3) ->where('season', $match->season) ->where('team_id', $match->home_team_id) ->first(); $awayAll = ZqCompetitionScore::where('competition_id', $match->competition_id) ->where('type', 1) ->where('season', $match->season)->where('team_id', $match->away_team_id)->first(); $awayHome = ZqCompetitionScore::where('competition_id', $match->competition_id) ->where('type', 2) ->where('season', $match->season)->where('team_id', $match->away_team_id)->first(); $awayAway = ZqCompetitionScore::where('competition_id', $match->competition_id) ->where('type', 3) ->where('season', $match->season)->where('team_id', $match->away_team_id)->first(); return $this->jsonSuccess([ 'home' => [ 'all' => $homeAll, 'home' => $homeHome, 'away' => $homeAway, ], 'away' => [ 'all' => $awayAll, 'home' => $awayHome, 'away' => $awayAway, ], ]); } /** * @api {GET} /api/customer/zqoverview/future_match 足球分析-未来赛事 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "home": [ * { * "id": 26918, * "match_id": 443257, * "competition_id": 165, * "competition_name": "欧U21预", // 赛事名称 * "season": "23/24", // 赛季 * "stage": "小组赛", // * "group_id": 1229653, * "group_name": "D", * "start_time": "2024-09-04 23:00:00", // 比赛开始时间 * "home_team_id": 3394, * "home_team_name": "以色列U21", // 主队 * "away_team_id": "3410", * "away_team_name": "德国U21", // 客队 * "status": 0, * "half_time_score": "", * "full_time_score": "", * "extra_time_score": "", * "penal_score": "", * "final_score": "", * "win_team_id": 0, * "man_id": "", * "created_at": "2023-07-26 22:04:22", * "updated_at": "2024-06-15 20:08:03", * "deleted_at": null, * "start_week": "周三", * "start_time_str": "09-04 23:00", * "competition_logo_url": "http://img.aistat.cn/competitions/165.png", * "home_team_logo_url": "http://img.aistat.cn/teams/3394.png", * "away_team_logo_url": "http://img.aistat.cn/teams/3410.png" * }, * ... * ], * "away": [ * ... * ] * } * } */ public function futureMatch(Request $request) { $matchId = $request->input('match_id'); if (!$matchId) { return $this->jsonSuccess(); } $match = ZqMatch::where('match_id', $matchId)->first(); ThrowException::isTrue(!$match, '比赛不存在'); $home = ZqMatch::where('status', 0)->where('home_team_id', $match->home_team_id) ->orderBy('start_time', 'asc') ->get(); $away = ZqMatch::where('status', 0)->where('away_team_id', $match->away_team_id) ->orderBy('start_time', 'asc') ->get(); return $this->jsonSuccess([ 'home' => $home, 'away' => $away, ]); } /** * @api {GET} /api/customer/zqoverview/history_match 足球分析-历史交锋 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "home": [ * { * "id": 26918, * "match_id": 443257, * "competition_id": 165, * "competition_name": "欧U21预", // 赛事名称 * "season": "23/24", // 赛季 * "stage": "小组赛", // * "group_id": 1229653, * "group_name": "D", * "start_time": "2024-09-04 23:00:00", // 比赛开始时间 * "home_team_id": 3394, * "home_team_name": "以色列U21", // 主队 * "away_team_id": "3410", * "away_team_name": "德国U21", // 客队 * "status": 0, * "half_time_score": "", * "full_time_score": "", * "extra_time_score": "", * "penal_score": "", * "final_score": "", * "win_team_id": 0, * "man_id": "", * "created_at": "2023-07-26 22:04:22", * "updated_at": "2024-06-15 20:08:03", * "deleted_at": null, * "start_week": "周三", * "start_time_str": "09-04 23:00", * "competition_logo_url": "http://img.aistat.cn/competitions/165.png", * "home_team_logo_url": "http://img.aistat.cn/teams/3394.png", * "away_team_logo_url": "http://img.aistat.cn/teams/3410.png", * "ya_handicap": 0, // 盘路 * "ya_result": "赢", // 盘路 * "win_result": "胜", // 比赛结果 * }, * ... * ], * "away": [ * ... * ] * } * } */ public function historyMatch(Request $request) { $matchId = $request->input('match_id'); if (!$matchId) { return $this->jsonSuccess(); } $match = ZqMatch::where('match_id', $matchId)->first(); ThrowException::isTrue(!$match, '比赛不存在'); $home = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time)->where(function($query) use ($match) { $query->where('home_team_id', $match->home_team_id) ->orWhere('away_team_id', $match->home_team_id); }) ->orderBy('start_time', 'desc') ->limit(30) ->get(); $away = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time)->where(function($query) use ($match) { $query->where('home_team_id', $match->away_team_id) ->orWhere('away_team_id', $match->away_team_id); }) ->orderBy('start_time', 'desc') ->limit(30) ->get(); $yaZhi = null; /** @var ZqMatch $item */ foreach ($home as $item) { $item->ya_handicap = $item->getYaZhiHandicap($yaZhi); $item->ya_result = $item->getYaZhiResult($yaZhi); } foreach ($away as $item) { $item->ya_handicap = $item->getYaZhiHandicap($yaZhi); $item->ya_result = $item->getYaZhiResult($yaZhi); } return $this->jsonSuccess([ 'home' => $home, 'away' => $away, ]); } /** * @api {GET} /api/customer/zqoverview/battle_match 足球分析-战绩统计 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * @apiParam {Int} num 多少场,默认10 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "jiao_feng": { // 交锋 * "home": { * "win": 0, // 胜 * "loss": 0,// 负 * "draw": 0// 平 * }, * "away": { * "win": 0, * "loss": 0, * "draw": 0 * } * }, * "jin_kuang": { // 近况 * "home": { * "win": 1, * "loss": 2, * "draw": 0 * }, * "away": { * "win": 0, * "loss": 0, * "draw": 0 * } * }, * "zhu_ke": { // 主客 * "home": { * "win": 1, * "loss": 1, * "draw": 0 * }, * "away": { * "win": 0, * "loss": 0, * "draw": 0 * } * } * } * } */ public function battleMatch(Request $request) { $matchId = $request->input('match_id'); $num = $request->input('num'); if (!$matchId) { return $this->jsonSuccess(); } if ($num <= 0) { $num = 10; } if ($num >= 30) { $num = 30; } $match = ZqMatch::where('match_id', $matchId)->first(); ThrowException::isTrue(!$match, '比赛不存在'); $jiaofen = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time) ->where('home_team_id', $match->home_team_id) ->where('away_team_id', $match->away_team_id) ->limit($num) ->get(); $jiaofengHome = $jiaofengAway = $jinKuangHomeResult = $jinKuangAwayResult = $zhukeHomeResult = $zhukeAwayResult = [ 'win' => 0, 'loss' => 0, 'draw' => 0, ]; foreach ($jiaofen as $item) { if ($item->home_score > $item->away_score) { $jiaofengHome['win'] += 1; $jiaofengAway['loss'] += 1; } else if ($item->home_score == $item->away_score) { $jiaofengHome['draw'] += 1; $jiaofengAway['draw'] += 1; } else { $jiaofengHome['loss'] += 1; $jiaofengAway['win'] += 1; } } $jinkuangHome = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time) ->where(function($query) use ($match) { $query->where('home_team_id', $match->home_team_id) ->orWhere('away_team_id', $match->home_team_id); }) ->limit($num) ->get(); foreach ($jinkuangHome as $item) { if ($item->home_score > $item->away_score) { $jinKuangHomeResult['win'] += 1; } else if ($item->home_score == $item->away_score) { $jinKuangHomeResult['draw'] += 1; } else { $jinKuangHomeResult['loss'] += 1; } } $jinkuangAway = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time) ->where(function($query) use ($match) { $query->where('home_team_id', $match->away_team_id) ->orWhere('away_team_id', $match->away_team_id); }) ->limit($num) ->get(); foreach ($jinkuangAway as $item) { if ($item->home_score > $item->away_score) { $jinKuangAwayResult['loss'] += 1; } else if ($item->home_score == $item->away_score) { $jinKuangAwayResult['draw'] += 1; } else { $jinKuangAwayResult['win'] += 1; } } // 主客 $zhukeHome = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time) ->where('home_team_id', $match->home_team_id) ->limit($num) ->get(); foreach ($zhukeHome as $item) { if ($item->home_score > $item->away_score) { $zhukeHomeResult['win'] += 1; } else if ($item->home_score == $item->away_score) { $zhukeHomeResult['draw'] += 1; } else { $zhukeHomeResult['loss'] += 1; } } $zhukeAway = ZqMatch::where('status', 2) ->where('start_time', '<', $match->start_time) ->where('away_team_id', $match->away_team_id) ->limit($num) ->get(); foreach ($zhukeAway as $item) { if ($item->home_score > $item->away_score) { $zhukeAwayResult['loss'] += 1; } else if ($item->home_score == $item->away_score) { $zhukeAwayResult['draw'] += 1; } else { $zhukeAwayResult['win'] += 1; } } return $this->jsonSuccess([ 'jiao_feng' => [ 'home' => $jiaofengHome, 'away' => $jiaofengAway, ], 'jin_kuang' => [ 'home' => $jinKuangHomeResult, 'away' => $jinKuangAwayResult, ], 'zhu_ke' => [ 'home' => $zhukeHomeResult, 'away' => $zhukeAwayResult, ], ]); } /** * @api {GET} /api/customer/zqoverview/probability 足球分析-概率 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code":200, * "message":"", * "data":{ * "predict":[ // 概率预测,第一项为表头数据 * { * "result":"", * "spf":"胜平负", * "rq":"让球胜平负" * }, * { * "result":"胜", * "spf":"43.00%", * "rq":"-" * }, * ] * } * } */ public function probability(Request $request) { $matchId = $request->input('match_id'); if (!$matchId) { return $this->jsonSuccess(); } /** @var ZqPredict $predict */ $predict = ZqPredict::where('match_id', $matchId) ->orderBy('id', 'desc') ->first(); if (!$predict) { return $this->jsonSuccess(); } return $this->jsonSuccess([ 'predict' => $predict->formatViewData(), ]); } /** * @api {GET} /api/customer/zqoverview/qingbao 足球分析-情报 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code":200, * "message":"", * "data":[ * { * "id":890486, * "teamId":162, * "homeAway":"home", // home主队; away客队 * "type":"good", // 类型(good: 有利, bad:不利, neutral: 中性) * "tag":"strength", // 标签(strength: 近期战力, absences: 伤停情况, players: 球员状态, pk: 两队交锋) * "content":"近10场防守不俗,4场无丢球,占比40%" // 详细内容 * }, * ... * ] * } */ public function qingbao(Request $request, AlStatService $service) { $matchId = $request->input('match_id'); if (!$matchId) { return $this->jsonSuccess(); } $info = $service->getZqQingBao($matchId); return $this->jsonSuccess(Arr::get($info, 'items')); } /** * @api {GET} /api/customer/zqoverview/live 足球分析-实况 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} match_id 比赛id * * @apiSuccessExample {json} 返回结果 * { * "code":200, * "message":"", * "data":{ * "teamStats":[ // 赛事统计 * { * "homeRate":7.03, // 主队数据 * "title":"评分", // 标题 * "awayRate":6.45, // 客队数据 * "homeProgress":0.52, // 主队进度条 0-1之间 * "awayProgress":0.48 // 客队进度条 0-1之间 * }, * ] * } * } */ public function live(Request $request, AlStatService $service) { $matchId = $request->input('match_id'); if (!$matchId) { return $this->jsonSuccess(); } $teamStats = $this->getLiveTeamStats($matchId); return $this->jsonSuccess([ 'teamStats' => $teamStats, ]); } // 赛事统计,实时球队数据 private function getLiveTeamStats($matchId) { /** @var AlStatService $service */ $service = app(AlStatService::class); $data = $service->getZqLiveTeamStats($matchId); if (!$data || !Arr::get($data, 'stats')) { return []; } $stats = Arr::get($data, 'stats'); $fieldNames = [ 'rate' => '评分', 'goals' => '进球', 'assists' => '助攻次数', 'penaltyScored' => '点球得分', 'penaltyMissd' => '射失点球', 'yelCards' => '黄牌', 'redCards' => '红牌', 'shots' => '射门次数', 'shotsOT' => '射正次数', 'shotsOffTag' => '射偏次数', 'shotsBlocked' => '射门被封堵次数', 'dribblesSucc' => '过人成功率', 'offsides' => '越位次数', 'unsTouches' => '失误次数', 'passSucc' => '传球成功率', 'accLB' => '准确长传次数', 'aerialDuelScc' => '争顶成功率', 'possession' => '控球率', 'bigChanceCreated' => '创造绝佳机会次数', 'corners' => '角球次数', 'totalSaves' => '扑救次数', 'freeKicks' => '任意球', 'throwIn' => '界外球', 'attacks' => '进攻次数', 'dangerousAttacks' => '危险进攻次数', ]; $lvField = [ 'dribblesSucc','passSucc','aerialDuelScc','possession' ]; $result = []; foreach ($stats as $item) { foreach ($fieldNames as $fieldName => $showName) { $val = Arr::get($item, $fieldName); if ($val === null) { continue; } $teamFieldName = sprintf('%s%s', $item['homeAway'], ucfirst($fieldName)); $result[$fieldName][$teamFieldName] = $val; $result[$fieldName]['title'] = $showName; } } foreach ($result as $fieldName => &$val) { $home = sprintf('home%s', ucfirst($fieldName)); $away = sprintf('away%s', ucfirst($fieldName)); $homeVal = Arr::get($val, $home); $awayVal = Arr::get($val, $away); if (!$homeVal && !$awayVal) { unset($result[$fieldName]); continue; } if ($fieldName == 'penaltyScored') { // dd( // $homeVal, // $awayVal, // !$homeVal && !$awayVal // ); } if (in_array($fieldName, $lvField)) { $homeProgress = $this->getPercent($homeVal, 100); $awayProgress = $this->getPercent($awayVal, 100); } else { $all = $homeVal + $awayVal; $homeProgress = $this->getPercent($homeVal, $all); $awayProgress = $this->getPercent($awayVal, $all); } $val['homeProgress'] = $homeProgress; $val['awayProgress'] = $awayProgress; } return array_values($result); } private function getPercent($zi, $mu) { if ($mu == 0) { return 0; } return Helps::floatFormat($zi / $mu, 2); } }