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

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

@@ -90,6 +90,7 @@ class Index extends BaseController
     public function productDetail(Request $request, $id)
     {
         if (!$id || !($storeInfo = Product::getValidProduct($id))) return app('json')->fail('商品不存在或已下架');
+        $storeInfo['saler'] = random_int(1, 100);
         $storeInfo['slider_image'] = json_decode($storeInfo['slider_image'], true);
         $storeInfo['detail_image'] = json_decode($storeInfo['detail_image'], true);
         $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_product_detail_wap.jpg', '/h5/pages/product/detail?id=' . $id);
@@ -128,7 +129,6 @@ class Index extends BaseController
         $data['productValue'] = $productValue;
         $data['sku'] = $sku;
         $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);
     }
 

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

@@ -27,6 +27,8 @@ class Product extends Model
                 $model->where('issuing', 1);
             }else if($cid == -2){
                 $model->where('is_leftover', 1);
+            }else if($cid == -3){
+                $model->where('is_best', 1);
             }else{
                 $model->where('cate_id', $cid);
             }
@@ -34,8 +36,9 @@ class Product extends Model
                 $model->order('sort DESC, add_time DESC');
             }
         }else{
+            $model->where('stars', '>', 1);
             if($data['sort'] == 'sort'){
-                $model->where('stars', '>', 1)->order('stars DESC, sort DESC, add_time DESC');
+                $model->order('stars DESC, sort DESC, add_time DESC');
             }
         }
         if($data['sort'] == 'sales'){
@@ -47,12 +50,12 @@ class Product extends Model
         if($data['sort'] == 'new'){
             $model->order('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,label')->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() : [];
         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,(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')
+    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')
     {
         $Product = self::where('is_del', 0)->where('is_show', 1)->where('id', $productId)->field($field)->find();
         if ($Product) return $Product->toArray();