Index.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace addons\cms\controller\wxapp;
  3. use addons\cms\model\Archives;
  4. use addons\cms\model\Block;
  5. use addons\cms\model\Channel;
  6. /**
  7. * 首页
  8. */
  9. class Index extends Base
  10. {
  11. protected $noNeedLogin = '*';
  12. /**
  13. * 首页
  14. */
  15. public function index()
  16. {
  17. $bannerList = [];
  18. $list = Block::getBlockList(['name' => 'indexfocus', 'row' => 5]);
  19. foreach ($list as $index => $item) {
  20. $bannerList[] = ['image' => cdnurl($item['image'], true), 'url' => '/', 'title' => $item['title']];
  21. }
  22. $tabList = [
  23. ['id' => 0, 'title' => '全部'],
  24. ];
  25. $channelList = Channel::where('status', 'normal')
  26. ->where('type', 'in', ['list'])
  27. ->field('id,parent_id,name,diyname')
  28. ->order('weigh desc,id desc')
  29. ->cache(false)
  30. ->select();
  31. foreach ($channelList as $index => $item) {
  32. $tabList[] = ['id' => $item['id'], 'title' => $item['name']];
  33. }
  34. $archivesList = Archives::getArchivesList(['cache' => false]);
  35. $archivesList = collection($archivesList)->toArray();
  36. foreach ($archivesList as $index => &$item) {
  37. $item['url'] = $item['fullurl'];
  38. //小程序只显示3张图
  39. $item['images_list'] = array_slice(array_filter(explode(',', $item['images'])), 0, 3);
  40. unset($item['imglink'], $item['textlink'], $item['channellink'], $item['taglist'], $item['weigh'], $item['status'], $item['deletetime'], $item['memo'], $item['img']);
  41. }
  42. $data = [
  43. 'bannerList' => $bannerList,
  44. 'tabList' => $tabList,
  45. 'archivesList' => $archivesList,
  46. ];
  47. $this->success('', $data);
  48. }
  49. }