<?php

namespace app\common\model;

use think\Model;

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

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

    public function getStatusTextAttr($value, $data)
    {
        $status = [1 => '报名成功', 2 => '取消'];
        return $status[$data['status']];
    }

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

    public function activity()
    {
        return $this->hasOne(Activity::class,'id','activity_id');
    }
}