Appindex.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. $currencyCode='USD';
  70. $currency_code =$this->request->header("Content-Currency");
  71. if($currency_code){
  72. $currencyCode =$currency_code;
  73. }
  74. $priceData = $this->getPrice($currencyCode);
  75. foreach ($this->getDetail($v['id']) as $ks=> $vul){
  76. $ndatas[$ks]['entity_id'] = $vul['link'];
  77. $ndatas[$ks]['name'] = $vul['title'];
  78. $ndatas[$ks]['image'] = $vul['images'];
  79. $ndatas[$ks]['price'] = round($vul['oldPrice']*$priceData[0],2);
  80. $ndatas[$ks]['final_price'] = round($vul['nowPrice']*$priceData[0],2);
  81. $percent=100-round($vul['nowPrice']/$vul['oldPrice'],2)*100;
  82. $ndatas[$ks]['percent']=$percent;
  83. $ndatas[$ks]['discount_app']=$percent.'% Off';
  84. $ndatas[$ks]['currencySymbol']=$priceData[1];
  85. //$ndatas[$ks]['sale_num'] = $vul['sale_num'];
  86. //$ndatas[$ks]['currencySymbol']=$currencySymbol;
  87. }
  88. $data['productList'] =$ndatas;
  89. }
  90. return $data;
  91. }
  92. public function getPrice($currencyCode)
  93. {
  94. $data['AUD']=[1.5,'A$'];
  95. $data['GBP']=[0.88,'£'];
  96. $data['CAD']=[1.33,'CA$'];
  97. $data['EUR']=[1.0022,'€'];
  98. $data['ZAR']=[17.8,'ZAR'];
  99. $data['USD']=[1,'$'];
  100. if(empty($data[$currencyCode])){
  101. $currencyCode='USD';
  102. }
  103. return $data[$currencyCode];
  104. }
  105. public function getBanner($code)
  106. {
  107. $banner=$this->getBlockDetail($code);
  108. $new=array();
  109. $url=input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
  110. foreach ($banner as $k=> $v){
  111. $new[$k]['title'] = $v['title'];
  112. $new[$k]['link'] = $v['link'];
  113. $new[$k]['type'] = $v['type'];
  114. $new[$k]['image'] =$url.$v['image'];
  115. }
  116. return $new;
  117. }
  118. public function getTopUrl($code)
  119. {
  120. $block =$this->getBlock($code);
  121. $new['title'] = $block['title'];
  122. $new['name'] = $block['name'];
  123. $new['link'] = $block['link'];
  124. $new['type'] = $block['type'];
  125. return $new;
  126. }
  127. public function getBlock($code)
  128. {
  129. $where['status']=1;
  130. $where['title']=$code;
  131. return Db::name('appindex')->where($where)->find();
  132. }
  133. public function getDetail($id)
  134. {
  135. $where['pid']=$id;
  136. return Db::name('appindexdes')->where($where)->select();
  137. }
  138. public function getBlockDetail($code)
  139. {
  140. $where['status']=1;
  141. $where['title']=$code;
  142. $block= Db::name('appindex')->where($where)->find();
  143. unset($where);
  144. $where['pid']=$block['id'];
  145. return Db::name('appindexdes')->where($where)->select();
  146. }
  147. }