牟新芬 4 years ago
parent
commit
79eb2231f8
2 changed files with 10 additions and 3 deletions
  1. 1 0
      app/api/controller/v1/Index.php
  2. 9 3
      app/model/api/Product.php

+ 1 - 0
app/api/controller/v1/Index.php

@@ -29,6 +29,7 @@ class Index extends BaseController
     public function productList(Request $request){
         $data = UtilService::getMore([
             ['cid', 0],
+            ['sort', ''],
             ['page', 1],
             ['limit', 24]
         ], $request);

+ 9 - 3
app/model/api/Product.php

@@ -22,13 +22,19 @@ class Product extends Model
         }else{
             $model = self::where('is_best', 1);
         }
-        $model->order('sort DESC, add_time DESC');
-        $list = $model->page((int)$page, (int)$limit)->field('id,store_name,image,price,cost,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales')->select();
+        if($data['sort'] == 'sales'){
+            $model->orderRaw('sales+ficti desc');
+        }else if($data['sort'] == 'commission'){
+            $model->orderRaw('price-ot_price desc');
+        }else{
+            $model->order('sort DESC, add_time DESC');
+        }
+        $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')->select();
         $list = count($list) ? $list->toArray() : [];
         return $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,sales,slider_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link,description')
+    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,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link,description')
     {
         $Product = self::where('is_del', 0)->where('is_show', 1)->where('id', $productId)->field($field)->find();
         if ($Product) return $Product->toArray();