123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 首页接口
- */
- class Appindex extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function getIndexOne()
- {
- /* $topUrl =$this->getTopUrl();
- $data['topUrl']=$topUrl;*/
- $banner =$this->getBanner('轮播图');
- $data['banner']=$banner;
- $category =$this->getBanner('分类');
- $data['category']=$category;
- $this->success('',$data);
- }
- public function getIndexTwo()
- {
- $data =$this->getBlockShow();
- $this->success('',$data);
- }
- public function getBlockShow()
- {
- $where['status']=1;
- $where['showType']=array('egt',1);
- $wheres['showType']=array('elt',7);
- $data=Db::name('appindex')->where($where)->where($wheres)->select();
- $new =array();
- foreach ($data as $k=> $v){
- $new[$k]=$this->doHandle($v);
- }
- return $new;
- }
- public function doHandle($v)
- {
- $data=array();
- $data['title'] = $v['name'];
- $data['showType'] = $v['showType'];// 1: best seller 2:new in 3:图片check now 4:flash deal 5:图片 wholesale 6:shop by looking 7: membership
- $data['imgUrl'] ='';
- $url=input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
- if($v['image']){
- $data['imgUrl'] =$url.$v['image'];
- }
- $data['type'] = $v['type'];
- $data['typeId'] = $v['link'];
- $data['titleArr'] = array();
- if($data['showType'] ==6){
- $ndata =array();
- foreach ($this->getDetail($v['id']) as $k=> $vs){
- $ndata[$k]['type'] = $vs['type'];
- $ndata[$k]['title'] = $vs['title'];
- $ndata[$k]['imgUrl'] = $url.$vs['image'];
- $ndata[$k]['typeId'] = $vs['link'];
- }
- $data['titleArr'] =$ndata;
- }
- $data['productList'] = array();
- if($data['showType'] ==1||$data['showType'] ==2||$data['showType'] ==4){
- $ndatas =array();
- $currencyCode='USD';
- $currency_code =$this->request->header("Content-Currency");
- if($currency_code){
- $currencyCode =$currency_code;
- }
- $priceData = $this->getPrice($currencyCode);
- foreach ($this->getDetail($v['id']) as $ks=> $vul){
- $ndatas[$ks]['entity_id'] = $vul['link'];
- $ndatas[$ks]['name'] = $vul['title'];
- $ndatas[$ks]['image'] = $vul['images'];
- if($vul['image']){
- $ndatas[$ks]['image'] =$url.$vul['image'];
- }
- $ndatas[$ks]['price'] = round($vul['oldPrice']*$priceData[0],2);
- $ndatas[$ks]['final_price'] = round($vul['nowPrice']*$priceData[0],2);
- if($ndatas[$ks]['price']){
- $percent = 100-round($vul['nowPrice']/$vul['oldPrice'],2)*100;
- $ndatas[$ks]['percent']= $percent;
- $ndatas[$ks]['discount_app']=$percent.'% Off';
- }
- $ndatas[$ks]['currencySymbol']=$priceData[1];
- //$ndatas[$ks]['sale_num'] = $vul['sale_num'];
- //$ndatas[$ks]['currencySymbol']=$currencySymbol;
- }
- $data['productList'] =$ndatas;
- }
- return $data;
- }
- public function getPrice($currencyCode)
- {
- $data['AUD']=[1.5,'A$'];
- $data['GBP']=[0.88,'£'];
- $data['CAD']=[1.33,'CA$'];
- $data['EUR']=[1.0022,'€'];
- $data['ZAR']=[17.8,'ZAR'];
- $data['USD']=[1,'$'];
- if(empty($data[$currencyCode])){
- $currencyCode='USD';
- }
- return $data[$currencyCode];
- }
- public function getBanner($code)
- {
- $banner=$this->getBlockDetail($code);
- $new=array();
- $url=input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
- foreach ($banner as $k=> $v){
- $new[$k]['title'] = $v['title'];
- $new[$k]['link'] = $v['link'];
- $new[$k]['type'] = $v['type'];
- $new[$k]['image'] =$url.$v['image'];
- }
- return $new;
- }
- public function getTopUrl($code)
- {
- $block =$this->getBlock($code);
- $new['title'] = $block['title'];
- $new['name'] = $block['name'];
- $new['link'] = $block['link'];
- $new['type'] = $block['type'];
- return $new;
- }
- public function getBlock($code)
- {
- $where['status']=1;
- $where['title']=$code;
- return Db::name('appindex')->where($where)->find();
- }
- public function getDetail($id)
- {
- $where['pid']=$id;
- return Db::name('appindexdes')->where($where)->select();
- }
- public function getBlockDetail($code)
- {
- $where['status']=1;
- $where['title']=$code;
- $block= Db::name('appindex')->where($where)->find();
- unset($where);
- $where['pid']=$block['id'];
- return Db::name('appindexdes')->where($where)->select();
- }
- }
|