<?php
/**
 * Created by FFB.
 * Company: Shenzhen Zhixun Information Tec. Nanchang Com.
 * Copyright: ShenzhenZhixun
 * Email: eastbus@126.com
 * User: FFB
 * Date: {{$map['datetime']}}
 * Desc: {{$map['desc']}}  
 * 文件不允许修改，自动生成
 */
 
namespace {{$namespace}};

{section name=tmp loop=$use}
{{$use[tmp]}}
{/section}

class {{$map['className']}} extends {{$extends}} {
    public static function tableName()
    {
        return '{literal}{{{/literal}{{$map['table']}}{literal}}}{/literal}';
    }

    {section name=tmp loop=$map['columns']}
/** ------------ 字段 {{$map['columns'][tmp]['name']}} ------------ */
    /**
     * {{$map['columns'][tmp]['name']}}字段筛选, 表字段注释: {{$map['columns'][tmp]['comment']}}
     */
    public function filterBy{{$map['columns'][tmp]['nameHumpH']}}($val): self
    {
        $this->filterByColumn("{{$map['columns'][tmp]['name']}}", $val);
        return $this;
    }

    /**
     * 设置{{$map['columns'][tmp]['name']}}字段, 表字段注释: {{$map['columns'][tmp]['comment']}}
     */
    public function set{{$map['columns'][tmp]['nameHumpH']}}($val): self
    {
        if(!isset($this->{{$map['columns'][tmp]['name']}}) || $this->{{$map['columns'][tmp]['name']}} != $val){
            $this->setColumns[] = "{{$map['columns'][tmp]['name']}}";
        }
        $this->setAttr("{{$map['columns'][tmp]['name']}}", $val);
        return $this;
    }

    /**
     * 获取{{$map['columns'][tmp]['name']}}字段, 表字段注释: {{$map['columns'][tmp]['comment']}}
     */
    public function get{{$map['columns'][tmp]['nameHumpH']}}()
    {
        return $this->{{$map['columns'][tmp]['name']}} ?? null;
    }

    {if $map['columns'][tmp]['isPri']}
/**
     * 获取主键值
     */
    public function getPrimaryValue()
    {
        return $this->{{$map['columns'][tmp]['name']}} ?? null;
    }
    {/if}

    /** ----------------------------------------------- */


    {/section}

    /**
     * 获取{{$map['table']}}表所有字段, 返回字段MAP
     */
     public function getAttr(): array
     {
        if(empty($this->setColumns)){
            return [];
        }
        $res = [];
        foreach($this->setColumns as $column){
            $res[$column] = $this->{literal}{{/literal}$column{literal}}{/literal};
        }
        return $res;
     }
}