huangdong hace 6 años
padre
commit
8c693be1eb
Se han modificado 3 ficheros con 53 adiciones y 141 borrados
  1. 52 139
      data/model/room.model.php
  2. 1 2
      test/TestTalk.php
  3. BIN
      webacc

+ 52 - 139
data/model/room.model.php

@@ -14,101 +14,38 @@ class roomModel extends Model
     public function __construct() {
         parent::__construct();
     }
-    ///群聊接口/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    public function create_room($type,$name,$creator,$owner,$owner_name,$max_user = 0)
-    {
-        $params = ['type' => $type,'room_name' => $name,'room_creator' => $creator,'room_owner' => $owner,'owner_name' => $owner_name,'max_user' => $max_user,'add_time' => time()];
-        return $this->table('room')->insert($params);
-    }
-
+    ///群聊接口//////////////////////////////////////////////////////////////////////////////////////////////////////////
     public function participants($room_id)
     {
         return $this->table('room_participant')->field('*')->where(['room_id' => $room_id,'state' => 0])->limit(false)->select();
     }
-
-    public function invite($room_id,$user,$inviter)
-    {
+    public function getPartRooms($cond,$field = '*') {
+        return  $this->table('room_participant')->field($field)->where($cond)->limit(false)->select();
+    }
+    public function invite($room_id,$user,$inviter) {
         $ret = $this->table('room_participant')->insert(['room_id' => $room_id,'member_id' => $user,'inviter' => $inviter,'invite_time' => time(),'join_time' => 0,'jointimes' => 0,'state' => 0],true);
         return $ret;
     }
-
-    public function leave($room_id,$user)
-    {
+    public function leave($room_id,$user) {
         $ret = $this->table('room_participant')->where(['room_id' => $room_id,'member_id' => $user])->update(['leave_time' => time(),'state' => 1]);
         return $ret;
     }
 
-    public function getRoom($roomid)
-    {
+    ///群聊接口//////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public function create_room($type,$name,$creator,$owner,$owner_name,$max_user = 0) {
+        $params = ['type' => $type,'room_name' => $name,'room_creator' => $creator,'room_owner' => $owner,'owner_name' => $owner_name,'max_user' => $max_user,'add_time' => time()];
+        return $this->table('room')->insert($params);
+    }
+    public function getRoom($roomid) {
         return $this->table('room')->field('*')->where(['room_id' => $roomid])->limit(1)->find();
     }
-
-    public function getRoomByType($room_type,$user)
-    {
+    public function getRoomByType($room_type,$user) {
         $room = $this->table('room')->field('*')->where(['type' => $room_type, 'room_creator' => $user])->limit(1)->find();
         return $room;
     }
-
-    public function getRoomMsg($room_id,$msg_type)
-    {
-        return $this->table('room_msg')->field('*')->where(['room_id' => $room_id, 'type' => $msg_type])->order('add_time desc')->select();
-    }
-
-    public function getRoomsgList($condition, $pagesize = '', $field = '*', $order = 'msg_id desc',$master = false)
-    {
-        return $this->table('room_msg')->field($field)->where($condition)->order($order)->limit($pagesize)->master($master)->select();
-    }
-
-    public function getPartRooms($cond,$field = '*')
-    {
-        return  $this->table('room_participant')->field($field)->where($cond)->limit(false)->select();
-    }
-
-    public function getRooms($cond,$field = '*')
-    {
+    public function getRooms($cond,$field = '*') {
         return $this->table('room')->field($field)->where($cond)->select();
     }
-
-
-    public function getChatwoRooms($cond,$field = '*')
-    {
-        return $this->table('room_chatwo')->field($field)->where($cond)->select();
-    }
-
-    public function getLastRoomMsgs($cond,$order='msg_id desc')
-    {
-        $items = $this->table('room_msg')->field("MAX(msg_id) as msg_id,room_id")->where($cond)->group('room_id')->order($order)->select();
-        if(empty($items)) return [];
-
-        $msg_ids = [];
-        foreach ($items as $item) {
-            $msg_ids[] = intval($item['msg_id']);
-        }
-
-        return $this->table('room_msg')->field("*")->where(['msg_id' => ['in',$msg_ids]])->limit(count($msg_ids))->limit(false)->select();
-    }
-
-    public function addRoomMsg($datas)
-    {
-        return $this->table('room_msg')->insert($datas);
-    }
-    public function getRoomExtend($userid,$lock=false)
-    {
-        $item = $this->table('room_extend')->field('*')->where(['userid' => $userid])->lock($lock)->find();
-        return $item;
-    }
-
-    public function addExtend($userid,$datas)
-    {
-        $datas['userid'] = $userid;
-        return $this->table('room_extend')->insert($datas);
-    }
-
-    public function editExtend($userid,$datas)
-    {
-        return $this->table('room_extend')->where(['userid' => $userid])->update($datas);
-    }
-
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public function findChatid($left,$right,$lock=false)
     {
@@ -136,80 +73,56 @@ class roomModel extends Model
         return $this->table('room_chatwo')->insert(['user_left' => $left,'user_right' => $right,'add_time' => time()]);
     }
 
+    public function getChatwoRooms($cond,$field = '*') {
+        return $this->table('room_chatwo')->field($field)->where($cond)->select();
+    }
 
-    public function getRoomMsgsCount($cond){
-        return $this->table('room_msg')->where($cond)->count();
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public function getRoomMsg($room_id,$msg_type) {
+        return $this->table('room_msg')->field('*')->where(['room_id' => $room_id, 'type' => $msg_type])->order('add_time desc')->select();
     }
 
+    public function getRoomsgList($condition, $pagesize = '', $field = '*', $order = 'msg_id desc',$master = false) {
+        return $this->table('room_msg')->field($field)->where($condition)->order($order)->limit($pagesize)->master($master)->select();
+    }
+    public function getLastRoomMsgs($cond,$order='msg_id desc')
+    {
+        $items = $this->table('room_msg')->field("MAX(msg_id) as msg_id,room_id")->where($cond)->group('room_id')->order($order)->select();
+        if(empty($items)) return [];
 
+        $msg_ids = [];
+        foreach ($items as $item) {
+            $msg_ids[] = intval($item['msg_id']);
+        }
+
+        return $this->table('room_msg')->field("*")->where(['msg_id' => ['in',$msg_ids]])->limit(count($msg_ids))->limit(false)->select();
+    }
+    public function addRoomMsg($datas)
+    {
+        return $this->table('room_msg')->insert($datas);
+    }
+    public function getRoomMsgsCount($cond){
+        return $this->table('room_msg')->where($cond)->count();
+    }
     public function getUserRoomMsg($room_id,$userid,$msg_type)
     {
         return $this->table('room_msg')->field('*')->where(['room_id' => $room_id,'member_id' => $userid,'type' => $msg_type])->order('add_time desc')->select();
     }
-
-
-
-    ////////////room_chatwo_msg
-    public function addChatwoMsg($datas)
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public function getRoomExtend($userid,$lock=false)
     {
-        return $this->table('room_chatwo_msg')->insert($datas);
+        $item = $this->table('room_extend')->field('*')->where(['userid' => $userid])->lock($lock)->find();
+        return $item;
     }
 
-
-    public function getLastChatwoMsg($user)
+    public function addExtend($userid,$datas)
     {
-        $from =[
-            "condition" => ['from_user'=> $user],
-            "group" => "to_user"
-        ];
-        $to = [
-            "condition" => ['to_user'=> $user],
-            "group" => "from_user"
-        ];
-        $from_part =$this->table('room_chatwo_msg')->field("MAX(msg_id) as msg_id,to_user,from_user")->where($from['condition'])->group($from['group'])->select();
-        $to_part   =$this->table('room_chatwo_msg')->field("MAX(msg_id) as msg_id,to_user,from_user")->where($to['condition'])->group($to['group'])->select();
-
-        $mix = [];
-
-        if(!empty($from_part))
-        {
-            foreach ($from_part as $item)
-            {
-                if($item['from_user']>$item['to_user']){
-                    $key = $item['from_user'].'_'.$item['to_user'];
-                }else{
-                    $key = $item['to_user'].'_'.$item['from_user'];
-                }
-
-                $mix[$key] = $item['msg_id'];
-            }
-        }
-
-
-        if(!empty($to_part))
-        {
-            foreach ($to_part as $item)
-            {
-                if($item['from_user']>$item['to_user']){
-                    $key = $item['from_user'].'_'.$item['to_user'];
-                }else{
-                    $key = $item['to_user'].'_'.$item['from_user'];
-                }
-
-                $haskey = isset($mix[$key]);
-                if(!$haskey || ($haskey && $item['msg_id']>$mix[$key])){
-                    $mix[$key] = $item['msg_id'];
-                }
-            }
-        }
-
+        $datas['userid'] = $userid;
+        return $this->table('room_extend')->insert($datas);
+    }
 
-        if(!empty($mix))
-        {
-            $msg_ids = array_values($mix);
-            return $this->table('room_chatwo_msg')->field("*")->where(['msg_id'=>['in',$msg_ids]])->limit(count($msg_ids))->select();
-        }else{
-            return [];
-        }
+    public function editExtend($userid,$datas)
+    {
+        return $this->table('room_extend')->where(['userid' => $userid])->update($datas);
     }
 }

+ 1 - 2
test/TestTalk.php

@@ -55,8 +55,7 @@ class TestTalk extends PHPUnit_Framework_TestCase
 
         return $stCreator;
     }
-
-
+    
     public function testParam(){
         $room_item = [ "type" => "room", "room"=> 37 ,"msg_id" => 1000];
         $chatwo_item = [ "type" => "chatwo", "user"=> 39234 ,"msg_id" => 0];

BIN
webacc