Appindex.php 5.0 KB

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