<?php


namespace app\lib\model;


use think\Db;
use think\Model;

class FamilyPeopleModel extends Model
{

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

    // 追加属性
    protected $append = [
        'sex_text',
        'ext_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 function getExtTextAttr($value,$data){
        if(isset($data['ext0']) && $data['ext0']==0){
            $value="生者";
        }else if(isset($data['ext0']) && $data['ext0']==1){
            $value="辞世";
        }else if(isset($data['ext0']) && $data['ext0']==2){
            $value="未知";
        }
        return $value;
    }


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

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



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

        $data['number'] = getNumbersn("user");

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

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

        return $res;
    }

    /**
     * 查询列表
     */
    public static function dataList($where,$order="id DESC"){
        $data = self::where($where)->order($order)->select();
        return $data;
    }


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

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


}