LiuJ 14 giờ trước cách đây
mục cha
commit
33c85fd7d7
1 tập tin đã thay đổi với 25 bổ sung1 xóa
  1. 25 1
      app/JsonRpc/NewsService.php

+ 25 - 1
app/JsonRpc/NewsService.php

@@ -72,6 +72,7 @@ use Hyperf\Context\ApplicationContext as ContextApplicationContext;
 use Hyperf\Amqp\Producer;
 
 use App\Amqp\Producer\MqProducer;
+use App\Model\Web;
 
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
@@ -1197,11 +1198,34 @@ class NewsService implements NewsServiceInterface
         ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
         ->where('article.status', 1)
         ->where('website_category.website_id', $data['website_id'])
-        ->select('article.id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
+        ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
         ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
         // ->orderBy('article.updated_at', 'desc')
         ->limit(5)
         ->get();
+      //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
+      foreach ($commendArticle as $k => $v) {
+        $cat_arr_id = json_decode($v->cat_arr_id, true);
+        if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
+          $cat_arr_id = array_unique($cat_arr_id);
+          // 从website_category取出alias_pinyin
+          $cat_arr  = WebsiteCategory::where('website_id', $data['website_id'])
+            ->whereIn('category_id', $cat_arr_id)
+            ->pluck('alias_pinyin', 'category_id')
+            ->toArray();
+
+          // 将cat_arr_id的json转成路径/隔开
+          $path_parts = [];
+          foreach ($cat_arr_id as $cat_id) {
+            if (isset($cat_arr[$cat_id])) {
+              $path_parts[] = $cat_arr[$cat_id];
+            }
+          }
+          $v->alias_pinyin = implode('/', $path_parts);
+        } else {
+          $v->alias_pinyin = '';
+        }
+      }
     }
 
     $result['category_id'] = $category['category_id'];