Appindex.php 5.1 KB

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