<?php 
namespace Common\Model;
use Think\Model;
class UserBanModel extends Model
{
	//获取禁言用户时间
	public function chenk_ban($uid='')
	{
		$map['uid']  =intval($uid);
		$ban=$this->where($map)->find();
		if (!empty($ban))
		{
			$time=time();
			if ($ban['endtime']>$time || $ban['endtime']==0)
			{
				$ban['addtime_str']=date("Y-m-d H:i",$ban['addtime']);
				if ($ban['endtime']==0)
				{
				$ban['endtime_str']='永久';
				}
				else
				{
				$ban['endtime_str']=date("Y-m-d H:i",$ban['endtime']);
				}
				return $ban;
			}
		}
		return false;
	}
	//清除禁言
	public function clear_ban($uid='')
	{
		$map['uid']=array('IN',$uid);
		$this->where($map)->delete();
		return true;
	}
	//设置禁言
	public function set_ban($uid='',$day='1',$txt='')
	{
		$this->clear_ban($uid);
		$s=0;
		$day=intval($day);
		$data['addtime']=time();
		if ($day==0)
		{
		$data['endtime']=0;
		}
		else
		{
		$data['endtime']=strtotime("+{$day} day");
		}
		$data['txt']=trim($txt);
		$uidarray=explode(",",$uid);
		if(!empty($uidarray))
		{
			foreach($uidarray as $u)
			{
				$data['uid']=$u;
				$this->add($data);
				$s++;
			}
		
		}
		return $s;
	}
}
?>