Jelajahi Sumber

获取商品分类解决路由问题

15313670163 4 hari lalu
induk
melakukan
2fda95c4e3
1 mengubah file dengan 8 tambahan dan 6 penghapusan
  1. 8 6
      app/JsonRpc/NewsService.php

+ 8 - 6
app/JsonRpc/NewsService.php

@@ -1427,7 +1427,7 @@ class NewsService implements NewsServiceInterface
     function processGoods($goods, $data) {
         return $goods->map(function ($good) use ($data) {
             $catid = $good->catid ?? 0;
-            $pinyin = '';
+        //     $pinyin = '';
             $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
             if (!empty($category->pid) && $category->pid != 0) {
                 $level = json_decode($category->category_arr_id);
@@ -1498,7 +1498,8 @@ class NewsService implements NewsServiceInterface
                     ->offset($goodStart)
                     ->limit($goodNum)
                     ->get();
-                $all_goods = $this->processGoods($all_goods, $website);
+                $web['website_id'] = $website;
+                $all_goods = $this->processGoods($all_goods, $web);
                     
             }
             return  $all_goods;
@@ -1551,7 +1552,8 @@ class NewsService implements NewsServiceInterface
         if(empty($category)){
             return Result::error("栏目查询失败", 0);
         }
-        // $cat_tree = $this->processGoods($cat, $website);
+        $cat_tree = Result::buildMenuTree($category);
+        $web['website_id'] = $website;
         $goods = Good::where('website_id', $website)
             ->where('status', 2)
             ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
@@ -1559,11 +1561,12 @@ class NewsService implements NewsServiceInterface
             ->offset(($data['page']-1)*$data['pageSize'])
             ->limit($data['pageSize'])
             ->get();
+        
         if($goods->isEmpty()){
             return Result::error("商品查询失败", 0);
         }
-        if(count($goods) > 1){
-            $goods = $this->processGoods($goods, $website);
+        if($goods->count() > 1){
+            $goods = $this->processGoods($goods, $web);
         }else{
             $catid = $goods[0]['catid'] ?? 0;
             $good_category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
@@ -1579,7 +1582,6 @@ class NewsService implements NewsServiceInterface
             }
             $goods[0]['pinyin'] = $pinyin;
         }
-        $cat_tree = Result::buildMenuTree($category);
         $result = [
             'category' => $cat_tree,
             'goods' => $goods,