<?php
namespace app\index\model;
use \think\Db;
class Account
{
    private static $init = null;

    public static function instance($init =null){
        if($init){
            self::$init = $init;
        }elseif(!self::$init){
            self::$init = new self();
        }
        return self::$init;
    }

    public function findUser($user,$type = 'email',$db =null){
        $db or $db = Db::name('user');
        return $db->where([$type=>$user])->find();
    }

    public function adduser($data,$db = null){
        $db or $db = Db::name('user');
        $data['carte_time'] = time();
        if($data ['id'] = $db->insertGetId($data)){
             
            return $data;
        }else{
            return false;
        }
    }

    public function setUser($data,$db = null){
        $db or $db = Db::name('user');
        $db = $db->where($data['id']);
        unset($data['id'],$data['email'],$data['carte_time']);
        return $db->update($data);
    }

    
}