海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Article;
  5. /**
  6. * 文章
  7. * Class ArticleController
  8. * @package App\Http\Controllers\Api
  9. */
  10. class ArticleController extends Controller
  11. {
  12. //文章列表
  13. public function index()
  14. {
  15. //TODO 此处仅为演示数据,调用数据需要再修改
  16. $list = Article::query()
  17. ->where('agent_id', $this->agent_id)
  18. ->select('id', 'image', 'title', 'updated_at')
  19. ->orderBy('id', 'DESC')
  20. ->simplePaginate()->toArray();
  21. $new_data = [];
  22. foreach ($list['data'] as $k => $item) {
  23. $new_key = floor($k / 4);
  24. if ($k % 4 == 0) {
  25. $new_data[$new_key] = [
  26. 'big' => $item,
  27. 'children' => []
  28. ];
  29. } else {
  30. $new_data[$new_key]['children'][] = $item;
  31. }
  32. }
  33. $list['data'] = $new_data;
  34. return $this->success($list);
  35. }
  36. //文章详情
  37. public function show()
  38. {
  39. $id = (int)request()->input('id');
  40. $article = Article::where('agent_id', $this->agent_id)->find($id);
  41. if (!$article) {
  42. return $this->error('文章不存在或已被删除');
  43. }
  44. return $this->success($article);
  45. }
  46. }