<?php 
namespace Common\Model;
use Think\Model;
class MsgModel extends Model
{
	protected $_validate = array(
		array('msg','require','内容必须填写！',1),
	);
	protected $_auto = array (
		array('addtime','time',1,'function'),
	);

	//获取列表
	public function get_list($map='',$page=false,$sort='',$num='')
	{
		$limit=$num?$num:10;
		if ($page)
		{

			$count      = $this->where($map)->count();
			$Page		= pager($count,$limit);
			$limit      = $Page->firstRow.','.$Page->listRows;
			$page_str   = $Page->fshow();
		}
		$result = $this->where($map)->order($sort)->limit($limit)->select();
		foreach ($result as $key => $v){
				$v['msg_cut']=cut_str($v['msg'],110);
				$v['type_str']=$this->get_type_str($v['systype']);
				$v['receiver_str']=$this->get_receiver_str($v['receiver']);
				$v['addtime_str']=daterange($v['addtime']);
				$v['user']=D('User')->get_user_one($v['uid'],true,1);
				$list[]=$v;
			}
		$return['list']=$list;
		if ($page){
		$return['count']=$count;
		}else{
		$return['count']=count($list);
		}
		$return['page']=$page_str;
		//print_r($return);
		return $return;
	}
	public function get_msg_one($id='')
	{
		$map['id']  = intval($id);
		$info=$this->where($map)->find();
		return $info;
	}
	public function get_type_str($type='1')
	{
		if ($type=='1')
		{
		$str='系统消息';
		}
		if ($type=='2')
		{
		$str='注册消息';
		}
		return $str;
	}
	public function get_receiver_str($receiver='1')
	{
		$str='全部会员';
		if ($receiver=='1')
		{
		$str='全部会员';
		}
		if ($receiver=='2')
		{
		$str='部分会员';
		}
		return $str;
	}
	 
	 
}
?>