<?php
namespace admin\Controller;
use Think\Controller;
class QuestionController extends CommonController {
	public function lists(){
		$key = I('request.key','','trim');
		$audit = I('request.audit','','trim');
		$issolve = I('request.issolve','','trim');
		$sort='id DESC';
		if ($key)
		{
			$key_type = I('request.key_type',0,'intval');
			if ($key_type=='1')
			{
				$map['title'] = array('like','%'.$key.'%');
			}
			if ($key_type=='2')
			{
				$map['describe'] = array('like','%'.$key.'%');
			}
			if ($key_type=='3')
			{
				$map['uid'] = intval($key);
			}
		}
		if ($audit<>'')
		{
			$map['audit'] = intval($audit);
		}
		if ($issolve<>'')
		{
			$map['issolve'] = intval($issolve);
		}		
		$list=D('Question')->get_list($map,true,$sort,10);
		$this->assign('lists',$list);
		$this->display();
	}
//修改审核
public function audit(){
	
		$ids = I('request.id');
		$audit=I('request.audit','0','intval');
		$ids = is_array($ids)?implode(",",$ids):$ids;	
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$map['id']     = array('IN',$ids);
			$data['audit'] = intval($audit);
			M('Question')->where($map)->save($data);
			if ($audit==-1)
			{
				//重新统计问题总数
				$info=M('Question')->where($map)->select();
				foreach($info as $val)
				{
					$uids[]=$val['uid'];
				}
				D('User')->update_count($uids,1);
			}
			$this->success("设置成功！");
		}
		else
		{
			$this->error('请选择项目！');
		}
	
}
public function delete(){
	
		$ids = I('request.id');
		$ids = is_array($ids)?implode(",",$ids):$ids;
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$map['id']     = array('IN',$ids);
			$info=M('Question')->where($map)->select();
			foreach($info as $val)
			{
					$uids[]=$val['uid'];
			}
			//获取标签
			$tagmap['qid']     = array('IN',$ids);
			$tags=M('QuestionTag')->where($tagmap)->select();
			foreach($tags as $t)
			{
					$set_tag[]=$t['tagid'];
			}
			//删除提问
			$s=D("Question")->del_question($ids);
			//更新标签统计
			D('Tag')->set_tag_count($set_tag,'count_question','dec');
			//更新会员问题统计
			D('User')->update_count($uids,1);
			
			$this->success("成功删除");
		}
		else
		{
		$this->error('请选择要删除的信息！');
		}
	
 	}
 
}
?>