$redis->del($findKey);
$redis->del($fofaKey);
$redis->del($findInterFollowKey);
$redis->del($findInterFansKey);
//存起来
foreach ($findSet as $uid => $score) {
$redis->zAdd($findKey, $score, $uid);
}
//求互粉集合
if ($userID != $targetUserID) { //看别人
$redis->zInter($fofaKey, array($findKey, $fansKey, $followKey));
/*
* 如果不是看自己的列表,还要求
* 1: 要查询的集合与我的关注交
* 2: 要查询的集的与我的粉丝交
*/
$redis->zInter($findInterFollowKey, array($findKey, $followKey));
$redis->zInter($findInterFansKey, array($findKey, $fansKey));
$findInterFollowSet = $redis->zRevRange($findInterFollowKey, 0, -1);
$findInterFansSet = $redis->zRevRange($findInterFansKey, 0, -1);
} else {
if ($findType == "fans") { //自己看粉丝列表
$redis->zInter($fofaKey, array($findKey, $followKey));
} else if ($findType == "follow") { //看自己关注列表
$redis->zInter($fofaKey, array($findKey, $fansKey));
}
}
//互粉集合
$fofaSet = $redis->zRevRange($fofaKey, 0, -1);
return array(
"findSet" => $findSet, //要查询的集合
"fofaSet" => $fofaSet, //互粉的集合
"findInterFollowSet" => $findInterFollowSet, //要查询的集合与我的关注交
"findInterFansSet" => $findInterFansSet //要查询的集的与我的粉丝交
);
}
以上函数已经求出了所需要的集合,然后就是关系状态判断了。
/*
* isSelf: 是否查看自己的列表
* findType: 查看的是粉丝还是关注列表 1: 关注, 2: 粉丝
* userInfoArr: 用户详细信息数组
*/
function getUserInfoList($isSelf, $findType, $userInfoArr, $findSet, $fofaSet, $interFansSet, $interFollowSet) {
$userInfoList = array();
foreach($findSet as $userID => $favoTime) {
if(!in_array($userID, array_keys($userInfoArr))) continue;
$userInfo = new UserInfo($userInfoArr[$userID]);
$userInfo = $userInfo->format();
if(in_array($userID, $fofaSet)){
$userInfo['favoFlag'] = 3; //互相关注
} else {
if($isSelf) {
$userInfo['favoFlag'] = $findType;
} else {
if(in_array($userID, $interFansSet)) {
$userInfo['favoFlag'] = 2; //我的粉丝
} else if(in_array($userID, $interFollowSet)) {
$userInfo['favoFlag'] = 1; //我的关注
} else{
$userInfo['favoFlag'] = 0; //无关系
}
}
}
$userInfo['favoTime'] = $favoTime;
array_push($userInfoList, $userInfo);
}
return $userInfoList;
}
更多信息请查看IT技术专栏