<?php


namespace app\lib\model;


use think\Db;
use think\Model;

class FamilyTreeMateModel extends Model
{

    // 表名
    protected $name = 'family_tree_mate';

    // 追加属性
    protected $append = [
        'sex_text',
    ];

    public function getSexTextAttr($value,$data){
        if(isset($data['sex']) && $data['sex']==0){
            $value="未知";
        }else if(isset($data['sex']) && $data['sex']==1){
            $value="男";
        }else if(isset($data['sex']) && $data['sex']==2){
            $value="女";
        }
        return $value;
    }

    /**
     * @功能说明:
     */
    public static function dataInfo($where){

        return  self::where($where)->find();
    }



    /**
     * @功能说明:添加
     */
    public static function dataAdd($data){

        $data['createtime'] = time();

        $res = self::create($data);

        return $res;
    }

    /**
     * @功能说明:编辑
     */
    public static function dataUpdate($where,$data){

        return self::where($where)->update($data);
    }


    /**
     * @功能说明:删除
     */
    public static function dataDel($where){

        return self::where($where)->delete();
    }

    /**
     *
     */
    public static function familyTreeMatePeopleList($where){
        $data=self::alias("ftm")
            ->join("family_people fp","ftm.people_id=fp.id","LEFT")
            ->field("ftm.id,ftm.name,ftm.photo,ftm.sex,ftm.people_id,fp.number,fp.firstname,fp.ext0,fp.ext5,fp.is_pay,fp.status,fp.fastim_id")
            ->where($where)
            ->order("ftm.id asc")
            ->select();
        return $data;
    }

}