<?php
namespace admin\Controller;
use Think\Controller;
class AnswerController extends CommonController {
	public function lists(){
		$key = I('request.key','','trim');
		$optimal = I('request.optimal','','trim');
		$sort='id DESC';
		if ($key)
		{
			$key_type = I('request.key_type',0,'intval');
			if ($key_type=='1')
			{
				$map['content'] = array('like','%'.$key.'%');
			}
			if ($key_type=='2')
			{
				$map['uid'] = intval($key);
			}
		}
		if ($optimal<>'')
		{
			$map['optimal'] = intval($optimal);
		}	
		$list=D('Answer')->get_list($map,true,$sort,10);
		$this->assign('lists',$list);
		$this->display();
	}
 
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('Answer')->where($map)->select();
			foreach($info as $val)
				{
					$qid[]=$val['qid'];
			}
			$s=M("Answer")->delete($ids);
			D('Question')->edit_answercount($qid);
			$this->success("成功删除{$s}条数据");
		}
		else
		{
		$this->error('请选择要删除的信息！');
		}
	
 	}
 
}
?>