<?php

namespace app\admin\model\fastim;

use think\Model;


class User extends Model
{
    // 表名
    protected $name = 'fastim_user';

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

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

    // 追加属性
    protected $append = [
        'type_text',
        'gender_text',
        'status_text'
    ];

    public function getTypeList()
    {
        return ['csr' => __('Type csr'), 'user' => __('Type user'), 'tourist' => __('Type tourist')];
    }

    public function getGenderList()
    {
        return ['secrecy' => __('Gender secrecy'), 'male' => __('Gender male'), 'female' => __('Gender female')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list  = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list  = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list  = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function fauser()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function csrgroup()
    {
        return $this->belongsTo('app\admin\model\fastim\CsrGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
