Index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace addons\blog\controller\wxapp;
  3. use addons\blog\model\Category;
  4. use addons\blog\model\Post;
  5. /**
  6. * 首页
  7. */
  8. class Index extends Base
  9. {
  10. protected $noNeedLogin = '*';
  11. /**
  12. * 首页
  13. */
  14. public function index()
  15. {
  16. //焦点图
  17. $bannerList = Post::where('status', 'normal')
  18. ->where("FIND_IN_SET( 'index',`flag`)")
  19. ->field('id,title,image,createtime')
  20. ->limit(4)
  21. ->select();
  22. $tabList = [
  23. ['id' => 0, 'title' => '全部'],
  24. ];
  25. $categoryList = Category::where('status', 'normal')
  26. ->field('id,pid,name,nickname,diyname')
  27. ->order('weigh desc,id desc')
  28. ->cache(false)
  29. ->select();
  30. foreach ($categoryList as $index => $item) {
  31. $tabList[] = ['id' => $item['id'], 'title' => $item['name']];
  32. }
  33. $postList = Post::
  34. with('category')
  35. ->where('status', 'normal')
  36. ->field('id,category_id,title,image,summary,createtime')
  37. ->page(1)
  38. ->order('weigh desc,id desc')
  39. ->select();
  40. foreach ($postList as $index => &$item) {
  41. $item['summary'] = trim(strip_tags($item['summary']));
  42. }
  43. $data = [
  44. 'bannerList' => $bannerList,
  45. 'tabList' => $tabList,
  46. 'postList' => $postList,
  47. ];
  48. $this->success('', $data);
  49. }
  50. }