Userinfo.class.php 4.79 KB
<?php
/**
 * 用户信息操作类
 * 
 * @author XMG 2014.2.7 
 * @copyright yoho.cn
 * @name Facade_Auth
 * @version 0.1
 *
 */
class Facade_Userinfo 
{
	const USER_STATE_DISABLED = 0 ;   //用户状态 -- 禁用
	const USER_STATE_NORMAL   = 1 ;   //用户状态 -- 正常
	
	/**
	 * 数据层
	 *
	 * @var Service_Admin_Auditing
	 */
	private static $_service = null;
	
	/**
	 * 返回Service对象
	 *
	 * @return Service_Auth
	 */
	private static function service()
	{
		if (null === self::$_service)
		{
			self::$_service = new Service_Auth();
		}
		return self::$_service;
	}

	/**
	 * 获取用户信息 -- 根据应用的订阅
	 * 
	 * @param integer $uid  用户的ID
	 * @param string $fields  需要访问的信息, 不传则默认获取订阅信息
	 * @param string $allowFields  允许访问的信息(应用订阅信息)
	 * @return array
	 */
	public static function getUserinfoForApp($uid, $fields = '', $allowFields = '')
	{
	    $result = array();
	    
	    if (is_numeric($uid) && is_string($fields) && is_string($allowFields))
	    {
	        // 调用 数据服务获取用户信息列表,返回数组格式的所有可以访问的信息
	        $result = self::service()->getUserinfo($uid, $fields, $allowFields);
	    }
	    
	    return $result;
	}
	
	/**
	 * 获取用户信息
	 * @param unknown $uid
	 */
	public static function getUserinfoByUid($uid)
	{
		return self::service()->getUserinfo($uid);
	} 
	
	/**
	 * 获取用户是否被禁用
	 * @param unknown $uid
	 */
	public static function isDisabled($uid)
	{
		if (!$uid) 
		{
			return 0 ;
		}
		$find = self::service()->getUserinfo($uid,'state');
		$state = isset($find['state'])?$find['state']:0 ;
		return ($state == self::USER_STATE_DISABLED);
	}
	
	/**
	 * 更新用户资料
	 * @param unknown $uid
	 * @param unknown $data
	 */
	public static function updateUserinfo($uid, $data)
	{
		if ($uid && $data) 
		{
			return self::service()->updateUserinfo($uid, $data);
		}
		return false ;
	}
	
	/**
	 * 清除用户缓存
	 * @param unknown $uid
	 */
	public static function cleanUserCache($uid)
	{
	    if (!$uid) 
	    {
	    	return false ;
	    }
		self::service()->cleanUserCache($uid);
	}
	
	
	/**
	 * 绑定有货账号关联
	 * @param unknown $uid  Show的UID
	 * @param unknown $sso_uid
	 */
	public static function relevanceYohobuyAccount( $uid, $yohobuy_name,$yohobuy_pwd)
	{
	    //检测是否存在有货账号
	    $result = Facade_Auth::checkLogin($yohobuy_name, $yohobuy_pwd,false,false,false);
	    if ( isset($result['uid']) )
	    {
	        //检验是否为有货账号
	        /* $userinfo = Facade_Userinfo::getUserinfoByUid($result['uid']);
	         
	        if (!in_array($userinfo['app_id'], array('1392109259')))
	        {
	             return array('code' => Config_Code::$error['user_not_exist']['code'],'message' => Config_Code::$error['user_not_exist']['message']);
	        } */
	    }else 
	    {
	        return array('code' => $result['code'],'message' => $result['message']);
	    }
	    $sso_uid = $result['uid'];
		$userinfo = self::service()->getUserinfo($sso_uid);
		if(!$userinfo)
		{
		    //用户不存在
			return array('code' => Config_Code::$error['user_not_exist']['code'],'message' => Config_Code::$error['user_not_exist']['message']);
		}
		if (self::service()->relevanceYohobuyAccount( $uid, $sso_uid))
		{
		    return array('code' => Config_Code::$success['system']['code'],'message' => Config_Code::$success['system']['message'],'sso_uid' => $sso_uid);
		}
		return array('code' => Config_Code::$error['system']['code'],'message' => Config_Code::$error['system']['message']);
	}
	
	/**
	 * 解除有货账号关联
	 * @param unknown $uid Show的UID
	 * @param unknown $sso_uid
	 */
	public static function removeYohobuyAccount( $uid, $sso_uid)
	{
	    $userinfo = self::service()->getUserinfo($sso_uid);
	    if(!$userinfo)
	    {
	        //用户不存在
	        return array('code' => Config_Code::$error['user_not_exist']['code'],'message' => Config_Code::$error['user_not_exist']['message']);
	    }
	    if (self::service()->removeYohobuyAccount( $uid, $sso_uid))
	    {
	        return array('code' => Config_Code::$success['system']['code'],'message' => Config_Code::$success['system']['message']);
	    }
	    return array('code' => Config_Code::$error['system']['code'],'message' => Config_Code::$error['system']['message']);
	}
	
	/**
	 * 获取关联有货账号
	 * @param unknown $uid Show的UID
	 */
	public static function getYohobuyAccountByShowId( $show_uid)
	{
	    return self::service()->getYohobuyAccountByShowId($show_uid);
	}
	
	/**
	 * 根据sso_uid
	 * @param unknown $sso_uid
	 * @return Ambigous <multitype:, Util_Dao_Db_PdoQuery>
	 */
	public static function getShowUidBySsoId($sso_uid)
	{
		$sso_uid = is_array($sso_uid)?$sso_uid:explode(',',$sso_uid);
	    return self::service()->getShowUidBySsoId($sso_uid);
	}
}