268 lines
9.3 KiB
PHP
Executable File
268 lines
9.3 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Http\Controllers\Api\Customer;
|
||
|
||
use App\Model\Lq\JclqCompany;
|
||
use App\Model\Lq\JclqMatch;
|
||
use App\Model\Lq\JclqZhishuDaxiao;
|
||
use App\Model\Lq\JclqZhishuOu;
|
||
use App\Model\Lq\JclqZhishuRf;
|
||
use App\Utils\ThrowException;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Arr;
|
||
|
||
class LqOverviewController extends BaseController
|
||
{
|
||
/**
|
||
* @api {GET} /api/customer/lqoverview/match_info 篮球分析-比赛信息
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} match_id 比赛id
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "id":4515,
|
||
* "match_id":446519, // 比赛id
|
||
* "competition_id":14, // 赛事id
|
||
* "competition_name":"欧冠", // 赛事名称
|
||
* "season":"22/23", // 赛季
|
||
* "start_time":"2023-05-11 03:00:00", // 开始时间
|
||
* "start_week":"周一", // 开始时间所属周
|
||
* "start_time_str":"05-11 03:00", // 开始时间
|
||
* "home_team_id":77,
|
||
* "home_team_name":"AC米兰", // 主队
|
||
* "away_team_id":"86",
|
||
* "away_team_name":"国际米兰", // 客队
|
||
* "status":0, // 比赛状态(0:未开始, 1:进行中, 2:已结束, 3:延期, 4:中断, 5:取消, 6:中场休息)
|
||
* }
|
||
* }
|
||
*/
|
||
public function matchInfo(Request $request) {
|
||
$matchId = $request->input('match_id');
|
||
|
||
$match = JclqMatch::with('score')
|
||
->where('match_id', $matchId)->first();
|
||
ThrowException::isTrue(!$match, '比赛不存在');
|
||
|
||
return $this->jsonSuccess($match);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/customer/lqoverview/zhishu 篮球分析-指数
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} match_id 比赛id
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
{
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "rf":[ // 让分指数,数组总长度就是公司数
|
||
* {
|
||
* "company":{
|
||
* "id":2,
|
||
* "company_id":2,
|
||
* "name":"立博", // 公司名
|
||
* "country":"英国",
|
||
* "created_at":"2023-05-09 22:51:05",
|
||
* "updated_at":"2023-05-09 22:51:05",
|
||
* "deleted_at":null
|
||
* },
|
||
* "items":[ // 这个数组有两项,type=0或1 (0: 初盘, 1: 即时盘)
|
||
* {
|
||
* "id":1,
|
||
* "cdate":20230509,
|
||
* "match_id":97980,
|
||
* "company_id":2,
|
||
* "type":0, // 类型(0: 初盘, 1: 即时盘)
|
||
* "handicap":"-4.50", // 让球
|
||
* "home":"0.80", // 主队赔率
|
||
* "away":"0.85", // 客队赔率
|
||
* "change_time":"2023-05-09 13:13:14", // 变盘时间
|
||
* "created_at":"2023-05-09 22:49:33",
|
||
* "updated_at":"2023-05-09 22:49:33",
|
||
* "deleted_at":null
|
||
* },
|
||
* ]
|
||
* },
|
||
* ],
|
||
* "ou":[
|
||
* {
|
||
* "company":, // 同上
|
||
* "items":[
|
||
* {
|
||
* "id":1,
|
||
* "cdate":20230509,
|
||
* "match_id":97980,
|
||
* "company_id":2,
|
||
* "type":0, // 类型(0: 初盘, 1: 即时盘)
|
||
* "win":"1.53", //主胜赔率
|
||
* "loss":"2.25", //客胜赔率
|
||
* "change_time":"2023-05-09 17:21:07", // 变盘时间
|
||
* "created_at":"2023-05-09 22:49:33",
|
||
* "updated_at":"2023-05-09 22:49:33",
|
||
* "deleted_at":null
|
||
* },
|
||
* ]
|
||
* },
|
||
* ],
|
||
* "daxiao":[
|
||
* {
|
||
* "company":, // 同上
|
||
* "items":[
|
||
* {
|
||
* "id":1,
|
||
* "cdate":20230509,
|
||
* "match_id":97980,
|
||
* "company_id":2,
|
||
* "type":0, // 类型(0: 初盘, 1: 即时盘)
|
||
* "handicap":"158.50", //盘口
|
||
* "over":"0.83", //大球赔率
|
||
* "under":"0.85", //小球赔率
|
||
* "change_time":"2023-05-09 13:13:17", // 变盘时间
|
||
* "created_at":"2023-05-09 22:49:33",
|
||
* "updated_at":"2023-05-09 22:49:33",
|
||
* "deleted_at":null
|
||
* },
|
||
* ]
|
||
* },
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function zhishu(Request $request) {
|
||
$matchId = $request->input('match_id');
|
||
|
||
$cdate = date('Ymd');
|
||
|
||
$rf = JclqZhishuRf::where('cdate',$cdate)
|
||
->where('match_id', $matchId)
|
||
->get()->groupBy('company_id')->toArray();
|
||
$ou = JclqZhishuOu::where('cdate',$cdate)
|
||
->where('match_id', $matchId)
|
||
->get()->groupBy('company_id')->toArray();
|
||
$daxiao = JclqZhishuDaxiao::where('cdate',$cdate)
|
||
->where('match_id', $matchId)
|
||
->get()->groupBy('company_id')->toArray();
|
||
|
||
|
||
$rfCompanyIds = $rf ? array_keys($rf) : [];
|
||
$ouCompanyIds = $ou ? array_keys($ou) : [];
|
||
$daxiaoCompanyIds = $daxiao ? array_keys($daxiao) : [];
|
||
|
||
$companyIds = array_merge($rfCompanyIds, $ouCompanyIds, $daxiaoCompanyIds);
|
||
if (!$companyIds) {
|
||
return $this->jsonSuccess();
|
||
}
|
||
$companys = JclqCompany::whereIn('company_id',$companyIds)->get()->keyBy('company_id');
|
||
$yas = [];
|
||
foreach ($rf 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([
|
||
'rf' => $yas,
|
||
'ou' => $ous,
|
||
'daxiao' => $daxiaos,
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/customer/lqoverview/analysis 篮球分析-分析
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} match_id 比赛id
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "history":[ // 历史交锋
|
||
* {
|
||
* "id":3266,
|
||
* "match_id":89933,
|
||
* "start_time":"2023-01-05 04:30:00", // 比赛时间
|
||
* "competition_name":"西篮联", // 赛事
|
||
* "home_team_name":"尤尼卡加", // 主队
|
||
* "away_team_name":"毕尔巴鄂", // 客队
|
||
* "home_score":92, // 主队得分
|
||
* "away_score":79, // 客队得分
|
||
* "status":2,
|
||
* "start_week":"周二",
|
||
* "start_time_str":"01-05 04:30"
|
||
* }
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function analysis(Request $request) {
|
||
$matchId = $request->input('match_id');
|
||
$match = JclqMatch::where('match_id', $matchId)->first();
|
||
if (!$match) {
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
$matchs = JclqMatch::select([
|
||
'id',
|
||
'match_id',
|
||
'start_time',
|
||
'competition_name',
|
||
'home_team_name',
|
||
'away_team_name',
|
||
'home_score',
|
||
'away_score',
|
||
'status',
|
||
])
|
||
->where(function($query) use ($match) {
|
||
$query->where(function($query) use ($match) {
|
||
$query->where('home_team_id', $match->home_team_id)
|
||
->where('away_team_id', $match->away_team_id);
|
||
|
||
})
|
||
->orWhere(function($query) use ($match) {
|
||
$query->where('away_team_id', $match->home_team_id)
|
||
->where('home_team_id', $match->away_team_id);
|
||
|
||
});
|
||
})
|
||
->where('status', 2)
|
||
->where('start_time', '>=', date('Y-01-01 00:00:00'))
|
||
->orderBy('id', 'desc')
|
||
->get();
|
||
|
||
return $this->jsonSuccess([
|
||
'history' => $matchs
|
||
]);
|
||
|
||
}
|
||
|
||
public function qingbao(Request $request) {
|
||
|
||
}
|
||
}
|