Przeglądaj źródła

Merge branch 'talksec' of 121.43.114.153:/home/git/repositories/shopnc into talksec

stanley-king 6 lat temu
rodzic
commit
155dcaafaa
2 zmienionych plików z 57 dodań i 49 usunięć
  1. 16 17
      data/model/room.model.php
  2. 41 32
      mobile/control/member_talk.php

+ 16 - 17
data/model/room.model.php

@@ -65,27 +65,26 @@ class roomModel extends Model
 
     }
 
-    public function getLastRoomMsg($user)
+    public function getJoinedRooms($cond)
     {
-        $join_rooms = $this->table('room_participant')->field('room_id')->where(['member_id'=>$user,'state'=>0])->select();
-        if(!empty($join_rooms))
-        {
-            $roomids = [];
-            foreach ($join_rooms as $room){$roomids[] = $room['room_id'];}
-            $chat_rooms =  $this->table('room')->field('room_id')->where(['type'=>\room\proto_type::room_chat,'room_id'=>['in',$roomids]])->select();
+        return  $this->table('room_participant')->field('*')->where($cond)->select();
+    }
 
-            $roomids = [];
-            if(!empty($chat_rooms)){
-                foreach ($chat_rooms as $room){$roomids[] = $room['room_id'];}
-            }else{
-                return [];
-            }
+    public function getRooms($cond)
+    {
+        return $this->table('room')->field('room_id')->where($cond)->select();
+    }
 
-            $msgs = $this->table('room_msg')->field("MAX(msg_id) as msg_id,room_id")->where(['room_id'=>['in',$roomids]])->group('room_id')->select();
-            if(!empty($msgs))
+
+    public function getLastRoomMsgs($roomids)
+    {
+        if(!empty($roomids))
+        {
+            $last_msgs = $this->table('room_msg')->field("MAX(msg_id) as msg_id,room_id")->where(['room_id'=>['in',$roomids]])->group('room_id')->select();
+            if(!empty($last_msgs))
             {
                 $msg_ids = [];
-                foreach ($msgs as $msg){$msg_ids[] = $msg['msg_id'];}
+                foreach ($last_msgs as $msg){$msg_ids[] = $msg['msg_id'];}
                 return $this->table('room_msg')->field("*")->where(['msg_id'=>['in',$msg_ids]])->limit(count($msg_ids))->select();
             }else{
                 return [];
@@ -95,6 +94,7 @@ class roomModel extends Model
         }
     }
 
+
     public function getLastChatwoMsg($user)
     {
         $from =[
@@ -172,7 +172,6 @@ class roomModel extends Model
         return $this->table($table)->where($condtion)->count();
     }
 
-
     public function getChatsRoom($user)
     {
         return $this->table('room_participant,room')

+ 41 - 32
mobile/control/member_talk.php

@@ -347,8 +347,23 @@ class member_talkControl extends mbMemberControl
     private function talk_rooms($user,$local_last)
     {
         $mod_room = Model('room');
-        $items = $mod_room->getLastRoomMsg($user);
-        $ret = $this->talk_format($items,'room',$user,$local_last);
+
+        $join_rooms = $mod_room->getJoinedRooms(['member_id'=>$user,'state'=>0]);
+        $roomids = [];
+        if(!empty($join_rooms)) {
+            foreach ($join_rooms as $room){$roomids[] = $room['room_id'];}
+        }
+
+        $chat_rooms = $mod_room->getRooms(['type'=>proto_type::room_chat,'room_id'=>['in',$roomids]]);
+        $roomids = [];
+        if(!empty($chat_rooms)){
+            foreach ($chat_rooms as $room){$roomids[] = $room['room_id'];}
+        }
+
+
+        $last_msgs = $mod_room->getLastRoomMsgs($roomids);
+
+        $ret = $this->talk_format($last_msgs,'room',$user,$local_last);
 
         return $ret;
     }
@@ -370,46 +385,40 @@ class member_talkControl extends mbMemberControl
 
         foreach($talks as $last_msg)
         {
-            if($type == 'room')
-            {
+            if($type == "room"){
                 $id = $last_msg['room_id'];
+            }elseif($type=='chatwo'){
+                $id = $last_msg['from_user'] == $user?$last_msg['to_user']:$last_msg['from_user'];
+            }else{
+                continue;
+            }
 
-                if(isset($local_last[$id]) && $local_last[$id]<$last_msg["msg_id"]) {
+
+            if(isset($local_last[$id]) && $local_last[$id]>0) {
+                if($local_last[$id]<$last_msg["msg_id"])
+                {
                     $not_read = $mod_room->getNotReadCnt($type,$local_last[$id],$last_msg["msg_id"],$id);
-                }else{
+                }
+                elseif($local_last[$id] == $last_msg["msg_id"])
+                {
                     $not_read = 0;
                 }
-
-                $item = [
-                    "msg_id"    => $last_msg['msg_id'],
-                    "msg"       => $last_msg['msg'],
-                    "add_time"  => $last_msg['add_time'],
-                    "not_read"  => $not_read,
-                    "room_id"   => $id
-                ];
-            }
-            elseif($type=='chatwo')
-            {
-                $id = $last_msg['from_user'] == $user?$last_msg['to_user']:$last_msg['from_user'];
-
-                if(isset($local_last[$id]) && $local_last[$id]<$last_msg["msg_id"]) {
-                    $not_read = $mod_room->getNotReadCnt($type,$local_last[$id],$last_msg["msg_id"],$id);
-                }else{
+                else{
                     $not_read = 0;
                 }
-
-                $item = [
-                    "msg_id"    => $last_msg['msg_id'],
-                    "msg"       => $last_msg['msg'],
-                    "add_time"  => $last_msg['add_time'],
-                    "not_read"  => $not_read,
-                    "member_id" => $id
-                ];
             }else{
-                $id = 0;
-                $item = [];
+                $not_read = 0;
             }
 
+
+            $item = [
+                "msg_id"    => $last_msg['msg_id'],
+                "msg"       => $last_msg['msg'],
+                "add_time"  => $last_msg['add_time'],
+                "not_read"  => $not_read,
+                "item_id"   => $id
+            ];
+
             $items[$id] = $item;
         }
         return $items;