Archive.php 909 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace addons\blog\controller\wxapp;
  3. use addons\blog\model\Post;
  4. /**
  5. * 归档
  6. */
  7. class Archive extends Base
  8. {
  9. protected $noNeedLogin = '*';
  10. /**
  11. * 首页
  12. */
  13. public function index()
  14. {
  15. $postlist = Post::where('status', 'normal')
  16. ->field('id,title,createtime')
  17. ->cache(3600 * 365)
  18. ->order('weigh desc,id desc')
  19. ->select();
  20. $list = [];
  21. foreach ($postlist as $k => $v) {
  22. $list[date("Y", $v['createtime'])][] = ['id' => $v['id'], 'title' => $v['title']];
  23. }
  24. $archiveList = [];
  25. foreach ($list as $index => $item) {
  26. $archiveList[] = [
  27. 'title' => $index . '年',
  28. 'postList' => $item
  29. ];
  30. }
  31. $data = [
  32. 'archiveList' => $archiveList
  33. ];
  34. $this->success('', $data);
  35. }
  36. }