牟新芬 4 years ago
parent
commit
e5805401c4
2 changed files with 13 additions and 11 deletions
  1. 11 10
      app/api/controller/v1/Index.php
  2. 2 1
      app/model/api/Product.php

+ 11 - 10
app/api/controller/v1/Index.php

@@ -40,19 +40,19 @@ class Index extends BaseController
      * 获取产品列表
      * 获取产品列表
      */
      */
     public function productList(Request $request){
     public function productList(Request $request){
-        $data = UtilService::getMore([
+        $where = UtilService::getMore([
             ['cid', 0],
             ['cid', 0],
             ['sort', ''],
             ['sort', ''],
             ['keyword', ''],
             ['keyword', ''],
             ['page', 1],
             ['page', 1],
             ['limit', 24]
             ['limit', 24]
         ], $request);
         ], $request);
-        $list = Product::getProductList($data);
-        foreach ($list as $k => $v) {
+        $data = Product::getProductList($where);
+        foreach ($data['list'] as $k => $v) {
             if($v['price'] == 0) {
             if($v['price'] == 0) {
-                $list[$k]['price'] = round($v['ot_price'] * 1.15, 2);
+                $data['list'][$k]['price'] = round($v['ot_price'] * 1.15, 2);
             }
             }
-            $list[$k]['market_price'] = round($list[$k]['price'] * 1.3, 2);
+            $data['list'][$k]['market_price'] = round($data['list'][$k]['price'] * 1.3, 2);
             $score = Db::name("product_score")->where('product_id', $v['id'])->find();
             $score = Db::name("product_score")->where('product_id', $v['id'])->find();
             if($score) {
             if($score) {
                 $attr = json_decode($score['attribute'], true);
                 $attr = json_decode($score['attribute'], true);
@@ -68,16 +68,16 @@ class Index extends BaseController
                 if($attr[2]['other'] > $max)
                 if($attr[2]['other'] > $max)
                     $max = $attr[2]['other'];
                     $max = $attr[2]['other'];
                 if($max)
                 if($max)
-                    $list[$k]['market_price'] = $max;
+                    $data['list'][$k]['market_price'] = $max;
             }
             }
             if($v['label'] != ""){
             if($v['label'] != ""){
-                $list[$k]['label'] = explode('、',$v['label']);
+                $data['list'][$k]['label'] = explode('、',$v['label']);
             }else{
             }else{
-                $list[$k]['label'] = [];
+                $data['list'][$k]['label'] = [];
             }
             }
-            $list[$k]['saler'] = random_int(1, 100);
+            $data['list'][$k]['saler'] = random_int(1, 100);
         }
         }
-        return app('json')->success($list);
+        return app('json')->success($data);
     }
     }
 
 
     /**
     /**
@@ -129,6 +129,7 @@ class Index extends BaseController
         $data['productValue'] = $productValue;
         $data['productValue'] = $productValue;
         $data['sku'] = $sku;
         $data['sku'] = $sku;
         $data['priceName'] = 0;
         $data['priceName'] = 0;
+        $data['good_list'] = Product::getGoodList(18, 'image,store_name,price,id,ot_price,stock,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,unit_name');
         return app('json')->successful($data);
         return app('json')->successful($data);
     }
     }
 
 

+ 2 - 1
app/model/api/Product.php

@@ -54,9 +54,10 @@ class Product extends Model
         if($data['sort'] == 'new'){
         if($data['sort'] == 'new'){
             $model->order('add_time DESC');
             $model->order('add_time DESC');
         }
         }
+        $count = $model->count();
         $list = $model->page((int)$page, (int)$limit)->field('id,store_name,image,price,cost,ot_price,(price-ot_price) as commission,IFNULL(sales,0) + IFNULL(ficti,0) as sales,label,is_new')->select();
         $list = $model->page((int)$page, (int)$limit)->field('id,store_name,image,price,cost,ot_price,(price-ot_price) as commission,IFNULL(sales,0) + IFNULL(ficti,0) as sales,label,is_new')->select();
         $list = count($list) ? $list->toArray() : [];
         $list = count($list) ? $list->toArray() : [];
-        return $list;
+        return ['count' => $count, 'list' => $list];
     }
     }
 
 
     public static function getValidProduct($productId, $field = 'add_time,browse,cate_id,code_path,cost,ficti,id,image,is_sub,is_best,is_del,is_hot,is_show,keyword,ot_price,postage,price,(price-ot_price) as commission,sales,slider_image,detail_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link,description,code,is_new')
     public static function getValidProduct($productId, $field = 'add_time,browse,cate_id,code_path,cost,ficti,id,image,is_sub,is_best,is_del,is_hot,is_show,keyword,ot_price,postage,price,(price-ot_price) as commission,sales,slider_image,detail_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link,description,code,is_new')