Browse Source

首页接口

bianjunhui 1 year ago
parent
commit
bf159f8a5d
2 changed files with 35 additions and 13 deletions
  1. 6 5
      application/admin/controller/Appindex.php
  2. 29 8
      application/api/controller/Appindex.php

+ 6 - 5
application/admin/controller/Appindex.php

@@ -84,9 +84,9 @@ class Appindex extends Backend
                         $new[$k]['type']=1;
                         $new[$k]['oldPrice']=$v['price'];
                         $new[$k]['nowPrice']=number_format($v['final_price'], 2);
-                        $new[$k]['sale_num']=$v['sold'];
+                        //$new[$k]['sale_num']=$v['sold'];
                         $new[$k]['sort_order']=$k+1;
-                        $new[$k]['images']='https://www.bilisar.com/media/catalog/product'.$v['image'];
+                        $new[$k]['images']=$v['image'];
                     }
                     Db::name('appindexdes')->insertAll($new);
                 }else{
@@ -157,11 +157,12 @@ class Appindex extends Backend
                         $new[$k]['title']=$v['name'];
                         $new[$k]['link']=$v['entity_id'];
                         $new[$k]['type']=1;
-                        $new[$k]['oldPrice']=$v['price'];
-                        $new[$k]['nowPrice']=number_format($v['final_price'], 2);
+                        $new[$k]['oldPrice']=$v['base_price'];
+                        $new[$k]['nowPrice']=number_format($v['base_final_price'], 2);
                         $new[$k]['sale_num']=$v['sold'];
                         $new[$k]['sort_order']=$k+1;
-                        $new[$k]['images']='https://www.bilisar.com/media/catalog/product'.$v['image'];
+                       // $new[$k]['images']='https://www.bilisar.com/media/catalog/product'.$v['image'];
+                        $new[$k]['images']=$v['image'];
                     }
                     Db::name('appindexdes')->insertAll($new);
                 }else{

+ 29 - 8
application/api/controller/Appindex.php

@@ -73,23 +73,44 @@ class Appindex extends Api
         $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){
-                if($vul['images']){
-                    $ndatas[$ks]['image'] = $vul['images'];
-                }else{
-                    $ndatas[$ks]['image'] = $url.$vul['image'];
-                }
                 $ndatas[$ks]['entity_id'] = $vul['link'];
                 $ndatas[$ks]['name'] = $vul['title'];
-                $ndatas[$ks]['price'] = $vul['oldPrice'];
-                $ndatas[$ks]['final_price'] = $vul['nowPrice'];
-                $ndatas[$ks]['sale_num'] = $vul['sale_num'];
+                $ndatas[$ks]['image'] = $vul['images'];
+                $ndatas[$ks]['price'] = round($vul['oldPrice']*$priceData[0],2);
+                $ndatas[$ks]['final_price'] = round($vul['nowPrice']*$priceData[0],2);
+                $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);