Appindex.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 getIndexTwo()
  27. {
  28. $data =$this->getBlockShow();
  29. $this->success('',$data);
  30. }
  31. public function getBlockShow()
  32. {
  33. $where['status']=1;
  34. $where['showType']=array('egt',1);
  35. $wheres['showType']=array('elt',7);
  36. $data=Db::name('appindex')->where($where)->where($wheres)->select();
  37. $new =array();
  38. foreach ($data as $k=> $v){
  39. $new[$k]=$this->doHandle($v);
  40. }
  41. return $new;
  42. }
  43. public function doHandle($v)
  44. {
  45. $data=array();
  46. $data['title'] = $v['name'];
  47. $data['showType'] = $v['showType'];// 1: best seller 2:new in 3:图片check now 4:flash deal 5:图片 wholesale 6:shop by looking 7: membership
  48. $data['imgUrl'] ='';
  49. $url=input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
  50. if($v['image']){
  51. $data['imgUrl'] =$url.$v['image'];
  52. }
  53. $data['type'] = $v['type'];
  54. $data['typeId'] = $v['link'];
  55. $data['titleArr'] = array();
  56. if($data['showType'] ==6){
  57. $ndata =array();
  58. foreach ($this->getDetail($v['id']) as $k=> $vs){
  59. $ndata[$k]['type'] = $vs['type'];
  60. $ndata[$k]['title'] = $vs['title'];
  61. $ndata[$k]['imgUrl'] = $url.$vs['image'];
  62. $ndata[$k]['typeId'] = $vs['link'];
  63. }
  64. $data['titleArr'] =$ndata;
  65. }
  66. $data['productList'] = array();
  67. if($data['showType'] ==1||$data['showType'] ==2||$data['showType'] ==4){
  68. $ndatas =array();
  69. foreach ($this->getDetail($v['id']) as $ks=> $vul){
  70. if($vul['images']){
  71. $ndatas[$ks]['img'] = $vul['images'];
  72. }else{
  73. $ndatas[$ks]['img'] = $url.$vul['image'];
  74. }
  75. $ndatas[$ks]['Id'] = $vul['link'];
  76. $ndatas[$ks]['title'] = $vul['title'];
  77. $ndatas[$ks]['oldPrice'] = $vul['oldPrice'];
  78. $ndatas[$ks]['nowPrice'] = $vul['nowPrice'];
  79. $ndatas[$ks]['sale_num'] = $vul['sale_num'];
  80. }
  81. $data['productList'] =$ndatas;
  82. }
  83. return $data;
  84. }
  85. public function getBanner($code)
  86. {
  87. $banner=$this->getBlockDetail($code);
  88. $new=array();
  89. $url=input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
  90. foreach ($banner as $k=> $v){
  91. $new[$k]['title'] = $v['title'];
  92. $new[$k]['link'] = $v['link'];
  93. $new[$k]['type'] = $v['type'];
  94. $new[$k]['image'] =$url.$v['image'];
  95. }
  96. return $new;
  97. }
  98. public function getTopUrl($code)
  99. {
  100. $block =$this->getBlock($code);
  101. $new['title'] = $block['title'];
  102. $new['name'] = $block['name'];
  103. $new['link'] = $block['link'];
  104. $new['type'] = $block['type'];
  105. return $new;
  106. }
  107. public function getBlock($code)
  108. {
  109. $where['status']=1;
  110. $where['title']=$code;
  111. return Db::name('appindex')->where($where)->find();
  112. }
  113. public function getDetail($id)
  114. {
  115. $where['pid']=$id;
  116. return Db::name('appindexdes')->where($where)->select();
  117. }
  118. public function getBlockDetail($code)
  119. {
  120. $where['status']=1;
  121. $where['title']=$code;
  122. $block= Db::name('appindex')->where($where)->find();
  123. unset($where);
  124. $where['pid']=$block['id'];
  125. return Db::name('appindexdes')->where($where)->select();
  126. }
  127. }