Просмотр исходного кода

从 xhGoods 查询出来的数据,按 xhGoodsCategory 的排序展示商品数据

shizhongqi 1 год назад
Родитель
Сommit
f27fc7c375

+ 18 - 2
biz-hd/goods/classes/GoodsClass.php

@@ -343,8 +343,10 @@ class GoodsClass extends BaseClass
     }
 
     //组装商品基本信息 ssh 2019.12.2
-    public static function groupGoodsBaseInfo($list, $getItem = false)
+    public static function groupGoodsBaseInfo($list, $getItem = false, $sortIds= [])
     {
+        $newList = [];
+        
         //注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!!!!!
         $currentData = current($list);
         $mainId = $currentData['mainId'] ?? 0;
@@ -411,8 +413,22 @@ class GoodsClass extends BaseClass
             }
             //前端使用字段
             $val['bigCount'] = 0;
-            $list[$key] = $val;
+            if (is_array($sortIds) && !empty($sortIds)) {
+                $sortIndex = array_search($id, $sortIds);
+                $newList[$sortIndex] = $val;
+                // $val['sortWeight'] = $sortIndex !== false ? $sortIndex : count($sortIds);
+            } else {
+                $list[$key] = $val;
+            }
         }
+
+        if (is_array($sortIds) && !empty($sortIds)) {
+            // usort($list, function($a, $b) {
+            //     return ($a['sortWeight'] ?? PHP_INT_MAX) - ($b['sortWeight'] ?? PHP_INT_MAX);
+            // });
+            $list = $newList;
+        }
+
         return $list;
     }
 

+ 4 - 6
biz-hd/goods/services/GoodsCategoryService.php

@@ -5,8 +5,6 @@ namespace bizHd\goods\services;
 use bizHd\base\services\BaseService;
 use bizHd\goods\classes\GoodsCategoryClass;
 use bizHd\goods\classes\GoodsClass;
-use Yii;
-use linslin\yii2\curl;
 
 class GoodsCategoryService extends BaseService
 {
@@ -17,14 +15,14 @@ class GoodsCategoryService extends BaseService
     public static function getGoodsList($where)
     {
         unset($where['delStatus']);//这个后面改进
-        $data = GoodsCategoryClass::getList('*', $where, 'status DESC,inTurn DESC');
-        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
+        $list = isset($data['list']) ? $data['list'] : [];
         if (empty($list)) {
             return $data;
         }
         $ids = array_column($list, 'gId');
-        $list = GoodsService::getAllByCondition(['id' => ['in', $ids]], 'inTurn DESC, sold DESC', '*');
-        $data['list'] = GoodsClass::groupGoodsBaseInfo($list);
+        $goodsList = GoodsClass::getAllByCondition(['id' => ['in', $ids]], null, '*');
+        $data['list'] = GoodsClass::groupGoodsBaseInfo($goodsList, false, $ids);
         return $data;
     }