Appindex.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Appindex extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function getIndexOne()
  17. {
  18. $topUrl =$this->getTopUrl();
  19. $data['topUrl']=$topUrl;
  20. $banner =$this->getBanner('轮播图');
  21. $data['banner']=$banner;
  22. $category =$this->getBanner('分类');
  23. $data['category']=$category;
  24. $this->success('',$data);
  25. }
  26. public function getBanner($code)
  27. {
  28. $banner=$this->getBlockDetail($code);
  29. $new=array();
  30. $url=input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
  31. foreach ($banner as $k=> $v){
  32. $new[$k]['title'] = $v['title'];
  33. $new[$k]['link'] = $v['link'];
  34. $new[$k]['type'] = $v['type'];
  35. $new[$k]['image'] =$url. $v['image'];
  36. }
  37. return $new;
  38. }
  39. public function getTopUrl()
  40. {
  41. $block =$this->getBlock('顶部链接');
  42. $new['title'] = $block['title'];
  43. $new['name'] = $block['name'];
  44. $new['link'] = $block['link'];
  45. $new['type'] = $block['type'];
  46. return $new;
  47. }
  48. public function getBlock($code)
  49. {
  50. $where['status']=1;
  51. $where['title']=$code;
  52. return Db::name('appindex')->where($where)->find();
  53. }
  54. public function getBlockDetail($code)
  55. {
  56. $where['status']=1;
  57. $where['title']=$code;
  58. $block= Db::name('appindex')->where($where)->find();
  59. unset($where);
  60. $where['pid']=$block['id'];
  61. return Db::name('appindexdes')->where($where)->select();
  62. }
  63. }