<?php
class memberAction extends baseAction {
    public function index(){
    /*$Data = D('content_content');
    $news_list = $Data->field('id,title')->where("cid = '4'")->order("id desc")->limit(6)->select();// 首页网站公告
    $this->assign('news_list',$news_list);

    $evebts_list = $Data->field('id,title,thumb,description')->where("cid = '12'")->order("id desc")->limit(6)->select();//首页热门活动
    $this->assign('evebts_list',$evebts_list);
	$this->display(C('default_tpl').'/account/index');*/
    }
    public function post_yesno(){
    if(IS_POST){
            $user = $this->user_info();
            $data[0]['uid'] = $user['id'];
            if($user['id']) {
            $cid = I('id');
            $type = I('type');
            $result = M('content_yesno')->where("cid='$cid'")->find();
            $addtime = time();
            $data[0]['addtime'] = $addtime;
            $data[0]['type'] = $type;
            $insert_data['cid'] = $cid;
            $insert_data['value'] = serialize($data);
            //print_r($data);
            if(isset($result)){
                $is_yes = '';
                foreach(unserialize($result['value']) as $k=>$v){
                    if($v['uid'] == $user['id']){
                        $this->ajaxReturn("","已经发表过意见了","-1");
                    }
                }
                $data_arr = array_merge(unserialize($result['value']),unserialize($insert_data['value']));
                $update_data['value'] = serialize($data_arr);
                if(M('content_yesno')->where("id='". $result['id'] ."'")->save($update_data)){
                    M('content_yesno_data')->data(array('cid'=>$cid,'uid'=>$user['id'],'type'=>$type,'addtime'=>$addtime))->add();
                    if($type == '1'){
                        M('content_content')->query("update ". C('DB_PREFIX') ."content_content set yes=yes+1 where id='$cid'");
                    }else{
                        M('content_content')->query("update ". C('DB_PREFIX') ."content_content set no=no+1 where id='$cid'");
                    }
                    if($type == '1') {
                    $this->ajaxReturn("","操作成功","1");
                    }else{
                    $this->ajaxReturn("","操作成功","2");
                    }
                }else{
                    $this->ajaxReturn("","操作失败","-1");
                }
            }else{
                if(M('content_yesno')->data($insert_data)->add()){
                    M('content_yesno_data')->data(array('cid'=>$cid,'uid'=>$user['id'],'type'=>$type,'addtime'=>$addtime))->add();
                    if($type == '1'){
                        M('content_content')->query("update ". C('DB_PREFIX') ."content_content set yes=yes+1 where id='$cid'");
                    }else{
                        M('content_content')->query("update ". C('DB_PREFIX') ."content_content set no=no+1 where id='$cid'");
                    }
                    if($type == '1') {
                    $this->ajaxReturn("","操作成功","1");
                    }else{
                    $this->ajaxReturn("","操作成功","2");
                    }
                }else{
                    $this->ajaxReturn("","操作失败","-1");
                }
            }
        }else{
            $this->ajaxReturn("","您还没有登录哦","-2");
        }
        }else{
            echo false;//参数错误
        }
    }
    public function edit(){
        $user = $this->user_info();
        if($user['id']) {
            $userl = datediffage($user['addtime'],time());//加入时间
            $this->assign('userl',$userl);
            $qs_result = M("content_content")->where("authorid='". $user['id'] ."'")->count();//糗事数量
            $pl_result = M("content_comment")->where("uid='". $user['id'] ."'")->count();//评论数量
            $xl_result = M("content_yesno_data")->where("uid='". $user['id'] ."' and type='1'")->count();//笑脸数量
            $this->assign('qs_result',$qs_result);
            $this->assign('pl_result',$pl_result);
            $this->assign('xl_result',$xl_result);
            $map = " 1=1 and a.uid = '". $user['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/my_edit');
        }
    }

}