MatchItems.php 1.2 KB
<?php

namespace app\school\model\match;

use app\school\model\basic\User;
use think\Exception;
use think\Model;
use traits\model\SoftDelete;

class MatchItems extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'match_items';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    protected $append = [
        'user_text',
        'match_title',
        'match_type_text'
    ];
    public function remark()
    {
        return $this->hasMany('app\\school\\model\\review\\ReviewScore','match_items_id','id');//hasMany是一对多
    }
    public function getuserTextAttr($value,$data)
    {
        return (new User())->where('id',$data['user_id'])->value('nickname');
    }
    public function getmatchTitleAttr($value,$data)
    {
        return (new Match())->where('id',$data['match_id'])->value('match_title');
    }
    public function getmatchTypeTextAttr($value,$data)
    {
        return (new MatchType())->where('id',$data['match_type'])->value('name');
    }
}