| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | <?phpnamespace Task\Lib;use Dever;use Passport\Src\User;use Passport\Src\Login;class Base{	# 定义返回数据	protected $data;	public function __construct()	{		# 获取用户信息		$user = new User();		$this->user = $user->data();		$this->data['config'] = Dever::db('main/config')->one(1);		$this->data['time'] = time();		$this->data['uid'] = -1;		if ($this->user) {			$this->data['uid'] = $this->user['id'];            if (!$this->user['avatar']) {                $this->user['avatar'] = Dever::config('host', 'main')->assets . 'mobile/images/avatar.jpg';            }		}	}    /**     * 获取refer     *     * @return mixed     */    protected function refer()    {        $refer = Dever::input('refer');        $project = 'main';        if ($refer) {            $refer = Dever::decode($refer);            return $refer;        } else {            return Dever::url('home', $project);        }    }    /**     * 检测用户是否登录     *     * @return mixed     */    protected function checkLogin()    {        if ($this->data['uid'] <= 0) {            # 需要登录            $login = new Login();            $login->location();        }    }	/**	 * 检测用户信息	 *	 * @return mixed	 */	protected function checkUser($state = false)	{		$this->checkLogin();		$where['uid'] = $this->data['uid'];		# 获取用户积分		$this->data['user_score'] = Dever::db('task/user_score')->one($where);		if (!$this->data['user_score']) {            $refer = Dever::url();            $qrcode = Dever::input('qrcode');            $url = Dever::url('user/set?refer=' . Dever::encode($refer) . '&qrcode=' . $qrcode, 'main');            Dever::location($url);            /*			$this->data['user_score'] = array();        	$this->data['user_score']['score'] = 0;        	$this->data['user_score']['uid'] = $where['uid'];        	$this->data['user_score']['id'] = Dever::db('task/user_score')->insert($this->data['user_score']);            */        }		# 检测用户是否认证		$this->data['user_info'] = Dever::db('task/user_info')->one($where);		if ($this->data['user_info'] && $this->data['user_info']['status'] == 2) {			# 已认证			return true;		} else {			if ($state == true) {				# 未认证 code = 110 就是需要认证,需要跳转到认证页面				//Dever::alert('资料认证通过后才能领取任务', 110);			}			return false;		}	}	public function token($request = array())    {    	$request['uid'] = Dever::encode($this->data['uid']);        return http_build_query(Dever::token($request));    }    public function url($method, $request = array())    {        return Dever::proxy($method, $this->token($request));    }}
 |