| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -4,27 +4,44 @@ namespace App\Http\Controllers\Api; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Http\Controllers\Controller; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Models\Article; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Http\Request; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * 文章 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * Class ArticleController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * @package App\Http\Controllers\Api | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					class ArticleController extends Controller | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						//文章列表
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public function index() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$list = Article::where('agent_id', $this->agent_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							//TODO 此处仅为演示数据,调用数据需要再修改
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$list = Article::query() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->where('agent_id', $this->agent_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->select('id', 'image', 'title', 'updated_at') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->orderBy('id', 'DESC') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->simplePaginate(15); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->simplePaginate()->toArray(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$new_data = []; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							foreach ($list['data'] as $k => $item) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$new_key = floor($k / 4); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($k % 4 == 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$new_data[$new_key] = [ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										'big' => $item, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										'children' => [] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$new_data[$new_key]['children'][] = $item; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$list['data'] = $new_data; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return $this->success($list); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						//文章详情
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						public function show() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$id = request()->input('id'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							if (!$id || !ctype_digit($id)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								return $this->error('未指定文章ID'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$id = (int)request()->input('id'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$article = Article::where('agent_id', $this->agent_id)->find($id); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							if (!$article) { | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |