Jelajahi Sumber

获取未读

bianjunhui 2 tahun lalu
induk
melakukan
760281b0c5
1 mengubah file dengan 23 tambahan dan 3 penghapusan
  1. 23 3
      application/api/controller/Message.php

+ 23 - 3
application/api/controller/Message.php

@@ -185,21 +185,41 @@ class Message extends Api
                         $arr['addtime']=time();
                         $res[] = $arr;
                     }
-                };
+                }
                 $num = 100;//每次导入条数
                 $limit = ceil(count($res)/$num);
                 for($i=1;$i<=$limit;$i++){
                     $offset=($i-1)*$num;
                     $data=array_slice($res,$offset,$num);
                     Db::name('message_read')->insertAll($data);
-                };
+                }
             }
             $this->success();
         }
+    }
 
 
+    public function getUnRead(){
+        $post=$this->request->post();
+        $user = User::getByUserId($post['user_id']);
+        $wheres['m.status']=2;
+        $user_id=$post['user_id'];
+        $list =Db::name('message')->alias('m')
+            ->field('m.id,mr.message_id')
+            ->join('message_read mr',"m.id =mr.message_id and mr.user_id='{$user_id}'",'left')
+            ->where($wheres)
+            ->where("group_id=3 or group_id={$user->group_id}")
+            ->select();
+        $count=0;
+        if($list){
+            foreach ($list as $k => $v){
+                if(empty($v['message_id'])){
+                    $count++;
+                }
+            }
+        }
+        $this->success('',$count);
     }
 
 
-
 }