Userinfo.class.php
4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?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);
}
}