Browse Source

gf yunfei xiufu

NoteStar 5 years ago
parent
commit
20394b0692
1 changed files with 12 additions and 14 deletions
  1. 12 14
      vendor/fancyecommerce/fecshop/services/product/ProductMysqldb.php

+ 12 - 14
vendor/fancyecommerce/fecshop/services/product/ProductMysqldb.php

@@ -1062,26 +1062,24 @@ class ProductMysqldb extends Service implements ProductInterface
 
             $where = $whereArr;
         }
-        // 1.先按照score排序
+        // spu 进行group
         $subQuery = $this->_productModel->find()
-            ->select($select)
-            ->where($where)
-            ->orderBy(['score' => SORT_DESC])
-        ;
+                    ->select($select)
+                    ->where($where)
+                    ->orderBy(['score' => SORT_DESC])
+                    ;
         // 总数
-        $product_total_count = (new Query())
-            ->from(['product2' => $subQuery])
-            ->groupBy('spu')
-            ->count();
-        // 2.上面score排序的结果进行group,这样,score最大值的产品就会作为group后的产品,显示到分类中。
-        $subQuery2 =  (new Query())
-            ->from(['product2' => $subQuery])
-            ->groupBy('spu');
+        $product_total_count = $this->_productModel->find()
+                    ->select($select)
+                    ->where($where)
+                    ->groupBy('spu')
+                    ->count();
 
         // 进行查询coll
         $products = (new Query())  //->select($field)
-        ->from(['product' => $subQuery2]) // 在这里使用了子查询
+			->from(['product' => $subQuery]) // 在这里使用了子查询
             ->orderBy($orderBy)
+            ->groupBy('spu')
             ->offset(($pageNum -1) * $numPerPage)
             ->limit($numPerPage)
 			->createCommand()