Переглянути джерело

优化获取列表-精确字段

15313670163 2 тижнів тому
батько
коміт
e3d967b464
1 змінених файлів з 26 додано та 1 видалено
  1. 26 1
      app/JsonRpc/NewsService.php

+ 26 - 1
app/JsonRpc/NewsService.php

@@ -444,6 +444,7 @@ class NewsService implements NewsServiceInterface
      */
     public function getWebsiteArticleList(array $data): array 
     {
+        // return Result::success($data);
         $where[] = ['status', '=', 1];
        if(isset($data['keyword'])  && !empty($data['keyword'])){
             array_push($where,['article.title','like','%'.$data['keyword'].'%']);
@@ -474,10 +475,34 @@ class NewsService implements NewsServiceInterface
             $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
                   ->orWhereNull("ignore_ids");
         })
+        ->select(
+            'article.id',
+            'article.title',
+            'article.imgurl',
+            'article.author',
+            'article.updated_at',
+            'article.introduce',
+            'article.islink',
+            'article.linkurl',
+            'article.copyfrom',
+            'article.catid')
         ->orderBy("updated_at", "desc")
         ->limit($data['pageSize'])
         ->offset(($data['page'] - 1) * $data['pageSize'])
-        ->get();
+        ->get()
+        // ;
+        ->map(function ($article ) use ($data) {
+            $catid = $article->catid ?? 0;
+            $pinyin = '';
+            $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
+            $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
+            if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
+                $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
+                $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
+            }
+            $article->pinyin = $pinyin;
+            return $article;
+            });
 
         $count =  Article::where(function ($query) use ($where) {
             foreach ($where as $condition) {