<?php

namespace app\common\model;

use think\Model;

class TrainJoin extends Model
{
    // 设置字段信息
    protected $schema = [
        'id'          => 'int',
        'train_id'    => 'int',
        'user_id'     => 'int',
        'comment'     => 'string',
        'create_time' => 'int',
        'status'      => 'int',
    ];

    // 设置字段自动转换类型
    protected $type = [
        'create_time' => 'timestamp:Y-m-d H:i',
    ];

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    public function train()
    {
        return $this->hasOne(Train::class, 'id', 'train_id');
    }

    public function getStatusTextAttr($value, $data)
    {
        $status = [1 => '未处理', 2 => '已处理'];
        return $status[$data['status']];
    }
}