| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -16,16 +16,13 @@ class MessageController extends Controller | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public function index() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$list = Message::where('agent_id', $this->agent_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$list = Message::query()->where('agent_id', $this->agent_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->whereIn('user_id', [$this->user_id, 0]) //0是所有人都接收的系统消息
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->select('id', 'user_id', 'title', 'created_at') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->select('id', 'title', 'created_at') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->selectRaw('IF(( SELECT 1 FROM `message_reads` AS `mr` WHERE mr.id = messages.id AND mr.user_id = messages.user_id ), 1, 0) AS `is_read`') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->orderBy('id', 'DESC') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->simplePaginate(15); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							if (!empty($list->items())) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								foreach ($list->items() as &$v) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$v->is_read = (int)MessageRead::where(['id' => $v->id, 'user_id' => $this->user_id])->exists(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return $this->success($list); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |