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

68 lines
1.4 KiB
PHP
Executable File

<?php
/**
* @createtime 2023/4/26
* @author wild
* @copyright PhpStorm
*/
namespace App\Model\Zq;
use App\Model\BaseModel;
use Illuminate\Support\Arr;
class CtzqBqc extends BaseModel
{
protected $appends = [
'result_array',
];
protected $casts = [
'matchs' => 'array',
];
public function matches() {
return $this->hasMany(CtzqBqcMatch::class, 'ctzq_bqc_id', 'id');
}
public static function resultConvert($result) {
$results = [
'0' => '负',
'1' => '平',
'3' => '胜',
];
return Arr::get($results, $result, '-');
}
public function getResultArrayAttribute() {
if (!$this->result_info) {
return [];
}
$result = [];
$len = strlen($this->result_info);
for($i=0;$i<$len;$i++) {
$val = $this->result_info[$i];
if ($val == 0) {
$result[] = '负';
} else if ($val == 1) {
$result[] = '平';
} else if ($val == 3) {
$result[] = '胜';
} else {
$result[] = '-';
}
}
return $result;
}
public function getCloseTime($earlySecond) {
$time = strtotime($this->end_time);
return date('Y-m-d H:i:s', $time - $earlySecond);
}
}