<?php
/*
 * @Author: taowj 965042433@qq.com
 * @Date: 2022-11-08 16:21:34
 * @LastEditors: taowj 965042433@qq.com
 * @LastEditTime: 2023-08-30 15:02:39
 * @FilePath: \introducer\application\admin\model\users\Agent.php
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

namespace app\admin\model\users;

use think\Model;


class Agent extends Model
{

    

    

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

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

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


    public function getTypeList()
    {
        return ['1' => __('Type 1')];
    }

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

    public function getLevelList()
    {
        return ['0' => __('Level 0'),'1' => __('Level 1'),'2' => __('Level 2'),'3' => __('Level 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 getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getLevelTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['level']) ? $data['level'] : '');
        $list = $this->getLevelList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function area()
    {
        return self::hasOne("app\admin\model\Addr",'ID',"area_id");

    }


}
