/**
  * 实现推荐关注换一换功能
  * 调用查找,找两个数据传显示
  * Date:2015/3/25
  * @author 徐敏威<*****@*****.**>
  */
 public function changeRecommend()
 {
     $config = _getAddonsConfig();
     $number = $config['number'];
     //获取配置,得到number(查找数量)字段。
     $data['status'] = 0;
     $list = _getRecommendList($number);
     //查找并赋值
     if ($list) {
         $data['other_follow'] = $list;
         $this->assign('recommend', $list);
         $data['html'] = $this->fetch(T('Addons://Recommend@Recommend/_user'));
         //如果有数据,返回显示数据。
         $data['status'] = 1;
     } else {
         S('recommend_follow_id_' . is_login(), null);
         //没有数据,清空缓存。
         $list = _getRecommendList($number);
         if ($list) {
             $data['other_follow'] = $list;
             $this->assign('recommend', $list);
             $data['html'] = $this->fetch(T('Addons://Recommend@Recommend/_user'));
             //重新查找后显示数据
             $data['status'] = 1;
         } else {
             $data['info'] = '换一换失败!';
         }
     }
     $this->ajaxReturn($data);
 }
 public function weiboSide()
 {
     //判断是否登录
     if (is_login()) {
         S('recommend_follow_id_' . is_login(), null);
         //加载页面时先清空缓存
         $config = _getAddonsConfig();
         $number = $config['number'];
         //获取配置参数,得到要查找的数量
         $list = _getRecommendList($number);
         //查找
         $this->assign("recommend", $list);
         //显示
     }
     if (empty($list) == 1) {
         echo '';
         return;
     }
     $this->display(T('Addons://Recommend@Recommend/recommend'));
 }
예제 #3
0
/**
 * 查找推荐数据
 * Date:2015/3/25
 * @author 徐敏威<*****@*****.**>
 */
function _getRecommendList($num)
{
    $config = _getAddonsConfig();
    $config = $config['method'];
    $list = $none_recommend = array();
    do {
        $config = array_diff($config, $none_recommend);
        sort($config);
        $rand = rand(0, count($config));
        $rand = $config[$rand];
        switch ($rand) {
            case 'rand':
                $result = _randRecommend();
                //todo 随机推荐
                if ($result) {
                    $list[] = $result;
                } else {
                    $none_recommend[] = 'rand';
                }
                break;
            case 'city':
                $result = _sameCityRecommend();
                //todo 城市
                if ($result) {
                    $list[] = $result;
                } else {
                    $none_recommend[] = 'city';
                }
                break;
            case 'admin':
                $result = _adminRecommend();
                //todo 管理员
                if ($result) {
                    $list[] = $result;
                } else {
                    $none_recommend[] = 'admin';
                }
                break;
            case 'data':
                $result = _sameDataRecommend();
                //todo 相同资料
                if ($result) {
                    $list[] = $result;
                } else {
                    $none_recommend[] = 'data';
                }
                break;
            case 'followfollow':
                $result = _followFollowId();
                //todo 关注的关注
                if ($result) {
                    $list[] = $result;
                } else {
                    $none_recommend[] = 'followfollow';
                }
                break;
            default:
                break;
        }
    } while (count($list) < $num && count($config));
    return $list;
}