<?php
class im_messClassModel extends Model
{
	/**
		发送信息推送的
	*/
	public function send($sendid, $receid, $gname, $cont)
	{
		$onrs = $this->db->getone('[Q]im_group',"`type`=2 and `name`='$gname'");
		if(!$onrs){
			$this->db->insert('[Q]im_group', array(
				'type'		=> 2,
				'name'		=> $gname,
				'createdt'	=> $this->rock->now
			));
			$gid	= $this->db->insert_id();
		}else{
			$gid	= $onrs['id'];
		}
		
		$this->insert(array(
			'type'	=> 'system',
			'optdt'	=> $this->rock->now,
			'zt'	=> 0,
			'cont'	=> $this->rock->jm->encrypt($cont),
			'sendid'=> $gid,
			'receid'=> $receid,
			'optid'	=> $sendid
		));
		$messid	= $this->db->insert_id();

		$socket	= c('socket', true);
		return $socket->send($sendid, $receid, array(
			'cont'	=> $cont,
			'gname'	=> $gname,
			'gid'	=> $gid,
			'type'	=> 'system',
			'now'	=> $this->rock->now
		));
	}
}