<?php
class userAction extends baseAction {
    public function index(){
    	$id = I('id');
        $s_r = M("users")->where("id='".$id."'")->find();
        if($s_r['id'] < 1){
            $this->error('没有这个用户哦');
            exit;
        }
        //访客
        $myuser = $this->user_info();
        if($myuser['id'] && $myuser['id'] != $id) {
        $s = M("users_visitor")->where("fk_uid='".$myuser['id']."' and uid='". $id ."'")->find();
        if($s){
            M("users_visitor")->where("fk_uid='".$myuser['id']."' and uid='". $id ."'")->save(array("addtime"=>time()));
        }else{
            M("users_visitor")->data(array("uid"=>$id,"fk_uid"=>$myuser['id'],"addtime"=>time()))->add();
        }
        }
    	if(I('app') == 'comment'){
    	$user_info = M('users')->where("id='". $id ."'")->find();
        $user_info['g'] = M('users_group')->where("min_integral <= ". $user_info['integral'] ."")->order("min_integral desc")->find();
  		$this->assign('user_info',$user_info);
  		$userl = datediffage($user_info['addtime'],time());//加入时间
        $this->assign('userl',$userl);
       	$qs_result = M("content_content")->where("authorid='". $user_info['id'] ."'")->count();//糗事数量
        $pl_result = M("content_comment")->where("uid='". $user_info['id'] ."'")->count();//评论数量
        $xl_result = M("content_yesno_data")->where("uid='". $user_info['id'] ."' and type='1'")->count();//笑脸数量
        $this->assign('qs_result',$qs_result);
        $this->assign('pl_result',$pl_result);
        $this->assign('xl_result',$xl_result);
        //我发布的糗事
        $result = M('content_comment')->join("left join ". C('DB_PREFIX') ."content_content
			on ". C('DB_PREFIX') ."content_comment.cid=". C('DB_PREFIX') ."content_content.id 
			left join ". C('DB_PREFIX') ."users on ". C('DB_PREFIX') ."content_content.authorid=". C('DB_PREFIX') ."users.id
        	")->where("". C('DB_PREFIX') ."content_comment.uid = '". $user_info['id'] ."'")->order("". C('DB_PREFIX') ."content_comment.id desc")->field(''.C('DB_PREFIX').'content_comment.*,'.C('DB_PREFIX').'users.username,'.C('DB_PREFIX').'content_content.content as text,'.C('DB_PREFIX').'content_content.yes,'.C('DB_PREFIX').'content_content.addtime as fb_time,'.C('DB_PREFIX').'content_content.comment,'.C('DB_PREFIX').'users.authpic')->limit(10)->select();
         // print_r($result);
        // echo M('content_comment')->getLastSql();
        $this->assign('qs_list',$result);
        $this->assign('user_info',$user_info);
        $map = " 1=1 and a.uid = '". $user_info['id'] ."'";
        $order = " order by addtime desc ";
        $data = D('users_visitor');
        $list = $data->query("select b.* from ". C('DB_PREFIX') ."users_visitor as a left join ". C('DB_PREFIX') ."users as b on a.fk_uid=b.id where ". $map ." ". $order ." limit 15");
            // echo $data->getLastSql();
        $this->assign('fk_list',$list);
    	$this->display(C('default_tpl').'/Index/user_comment');
    	}else{
    	$user_info = M('users')->where("id='". $id ."'")->find();
        $user_info['g'] = M('users_group')->where("min_integral <= ". $user_info['integral'] ."")->order("min_integral desc")->find();
  		$this->assign('user_info',$user_info);

  		$userl = datediffage($user_info['addtime'],time());//加入时间
        $this->assign('userl',$userl);
       	$qs_result = M("content_content")->where("authorid='". $user_info['id'] ."'")->count();//糗事数量
        $pl_result = M("content_comment")->where("uid='". $user_info['id'] ."'")->count();//评论数量
        $xl_result = M("content_yesno_data")->where("uid='". $user_info['id'] ."' and type='1'")->count();//笑脸数量
        $this->assign('qs_result',$qs_result);
        $this->assign('pl_result',$pl_result);
        $this->assign('xl_result',$xl_result);
        //我发布的糗事
        $result = M('content_content')->where("authorid = '". $user_info['id'] ."'")->order("id desc")->limit(10)->select();
        $this->assign('qs_list',$result);
        $this->assign('user_info',$user_info);
        $map = " 1=1 and a.uid = '". $user_info['id'] ."'";
        $order = " order by addtime desc ";
        $data = D('users_visitor');
        $list = $data->query("select b.* from ". C('DB_PREFIX') ."users_visitor as a left join ". C('DB_PREFIX') ."users as b on a.fk_uid=b.id where ". $map ." ". $order ." limit 15");
            // echo $data->getLastSql();
        $this->assign('fk_list',$list);
    	$this->display(C('default_tpl').'/Index/user_index');
    	}
    }
    public function comment(){
    	echo 123;
    }
    
}