jingcai-php/app/Model/Zq/ZqMatch.php

129 lines
3.2 KiB
PHP
Executable File

<?php
namespace App\Model\Zq;
use App\Model\BaseModel;
use App\Model\Lq\JclqScore;
use App\Service\JingcaiLogoService;
use App\Utils\Helps;
class ZqMatch extends BaseModel
{
protected $appends = [
'start_week',
'start_time_str',
'competition_logo_url',
'home_team_logo_url',
'away_team_logo_url',
'win_result',
'home_score',
'away_score',
];
public function getHomeScoreAttribute()
{
$finalScore = explode(':', trim($this->final_score, '*'));
$homeScore = intval(trim(@$finalScore[0], ' '));
return $homeScore;
}
public function getAwayScoreAttribute()
{
$finalScore = explode(':', trim($this->final_score, '*'));
$awayScore = intval(trim(@$finalScore[1], ' '));
return $awayScore;
}
public function getWinResultAttribute()
{
$finalScore = explode(':', trim($this->final_score, '*'));
if (!$finalScore) {
return '';
}
$homeScore = intval(trim(@$finalScore[0], ' '));
$awayScore = intval(trim(@$finalScore[1], ' '));
if ($homeScore > $awayScore) {
return '胜';
}
if ($homeScore > $awayScore) {
return '负';
}
return '平';
}
public function getCompetitionLogoUrlAttribute()
{
if (!$this->competition_id) {
return '';
}
return JingcaiLogoService::zqCompetition($this->competition_id);
}
public function getHomeTeamLogoUrlAttribute()
{
if (!$this->home_team_id) {
return '';
}
return JingcaiLogoService::zqTeam($this->home_team_id);
}
public function getAwayTeamLogoUrlAttribute()
{
if (!$this->competition_id) {
return '';
}
return JingcaiLogoService::zqTeam($this->away_team_id);
}
public function home()
{
return $this->hasOne(ZqTeam::class, 'team_id', 'home_team_id');
}
public function away()
{
return $this->hasOne(ZqTeam::class, 'team_id', 'away_team_id');
}
public function score()
{
return $this->belongsTo(JczqScore::class, 'match_id','match_id');
}
public function getStartWeekAttribute()
{
if (!$this->start_time) {
return '';
}
return Helps::getWeek($this->start_time);
}
public function getStartTimeStrAttribute()
{
if (!$this->start_time) {
return '';
}
return date('m-d H:i', strtotime($this->start_time));
}
public function getYaZhiHandicap($yaZhi) {
return $yaZhi ? $yaZhi->handicap : 0;
}
public function getYaZhiResult($yaZhi) {
$yaZhi = $yaZhi ? $yaZhi->handicap : 0;
if ($this->home_score == $this->away_score) {
if ($yaZhi > 0) {
return '输';
}
if ($yaZhi < 0) {
return '赢';
}
return '平';
}
$homeScore = $this->home_score - $yaZhi;
$awayScore = $this->away_score;
if ($homeScore > $awayScore) {
return '赢';
}
if ($homeScore < $awayScore) {
return '输';
}
return '平';
}
}