牟新芬 4 years ago
parent
commit
08bae674ac
2 changed files with 6 additions and 4 deletions
  1. 4 3
      app/api/controller/v1/Index.php
  2. 2 1
      app/model/api/Product.php

+ 4 - 3
app/api/controller/v1/Index.php

@@ -40,14 +40,15 @@ class Index extends BaseController
      * 获取产品列表
      */
     public function productList(Request $request){
-        $data = UtilService::getMore([
+        $where = UtilService::getMore([
             ['cid', 0],
             ['sort', ''],
             ['keyword', ''],
             ['page', 1],
             ['limit', 24]
         ], $request);
-        $list = Product::getProductList($data);
+        $data = Product::getProductList($where);
+        $list = $data['list'];
         foreach ($list as $k => $v) {
             if($v['price'] == 0) {
                 $list[$k]['price'] = round($v['ot_price'] * 1.15, 2);
@@ -77,7 +78,7 @@ class Index extends BaseController
             }
             $list[$k]['saler'] = random_int(1, 100);
         }
-        return app('json')->success($list);
+        return app('json')->success(['list' => $list, 'count' => $data['count']]);
     }
 
     /**

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

@@ -54,9 +54,10 @@ class Product extends Model
         if($data['sort'] == 'new'){
             $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 = 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')