<?php

namespace app\admin\model;

use think\Model;


class Item extends Model
{

    

    

    // 表名
    protected $name = 'item';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

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

    // 追加属性
    protected $append = [
        'campus_text'
    ];

    public function getCampusTextAttr($value,$data){
        $cid = db('ronda')->where('id',$data['ronda_id'])->value('campus_id');
        $list = db('campus')->where('id',$cid)->value('title');
        return $list;
    }



    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function ronda()
    {
        return $this->belongsTo('Ronda', 'ronda_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function radar()
    {
        return $this->belongsTo('Radar', 'radar_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function campus()
    {
        return $this->belongsTo('Campus', 'campus_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}