Browse Source

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/news_producer

LiuJ 1 month ago
parent
commit
9f0875e040
3 changed files with 82 additions and 7 deletions
  1. 74 6
      app/JsonRpc/NewsService.php
  2. 7 0
      app/JsonRpc/NewsServiceInterface.php
  3. 1 1
      runtime/hyperf.pid

+ 74 - 6
app/JsonRpc/NewsService.php

@@ -1003,7 +1003,9 @@ class NewsService implements NewsServiceInterface
       'article.status' => 1,
     ];
 
-    $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
+    $result = Article::where($where)
+        ->leftJoin("article_data", "article.id", "article_data.article_id")
+        ->leftJoin ("article_extend", "article_extend.article_id", "article.id")
       ->where(function ($query) use ($data) {
         $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
           ->orWhereNull("ignore_ids");
@@ -5368,9 +5370,9 @@ class NewsService implements NewsServiceInterface
     $container = \Hyperf\Context\ApplicationContext::getContainer();
     $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
 
-    if ($cachedData = $cache->get($cacheKey)) {
-      return Result::success(unserialize($cachedData));
-    }
+     if ($cachedData = $cache->get($cacheKey)) {
+       return Result::success(unserialize($cachedData));
+     }
 
     //查询老黄历
     try {
@@ -5453,7 +5455,11 @@ class NewsService implements NewsServiceInterface
       ->limit(6)
       ->get();
     // 获取分类文章数据
-    $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
+      $categoryIds =  WebsiteCategory::where(['website_id'=> $data['website_id'], 'pid'=>0])
+    ->pluck('category_id')
+    ->toArray();
+
+//    $categoryIds = [627, 628, 629, 630, 631, 632, 633, 634, 635, 636];
 
     // 使用子查询优化
     $articlesList = DB::table('article')
@@ -5508,7 +5514,7 @@ class NewsService implements NewsServiceInterface
       ->toArray();
 
     $result = [
-      // 'almanac' => $almanacInfo,
+       'almanac' => $almanacInfo,
       'historyTodayList' => [
         'category_name' => '历史上的今天',
         'list' => $historyTodayList,
@@ -5680,4 +5686,66 @@ class NewsService implements NewsServiceInterface
     }
     return Result::success($result);
   }
+
+
+  /**
+   * 农网导航首页数据
+   */
+  public function getWebsiteNwHomeList(array $data): array{
+      $categoryIds =  WebsiteCategory::where(['website_id'=> $data['website_id']])->where("pid","!=",0)
+          ->pluck('category_id')
+          ->toArray();
+      // 使用子查询优化
+      $articlesList = DB::table('article')
+          ->select([
+              'article.id',
+              'article.title',
+              'article.imgurl',
+              'article.created_at',
+              'category.name as category_name',
+              'category.id as category_id',
+              'website_category.aLIas_pinyin as pinyin',
+              DB::raw('100 as type')
+          ])
+          ->join('category', 'article.catid', '=', 'category.id')
+          ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
+          ->where('website_category.website_id', $data['website_id'])
+          ->where('article.status', 1)
+          ->whereIn('category.id', $categoryIds)
+          // ->whereRaw('article.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)')
+          ->orderBy('article.created_at', 'desc')
+          ->get()
+          ->groupBy('category_id')
+          ->map(function ($group) {
+              // 确保第一条数据有图片
+              $firstWithImage = $group->first(function ($item) {
+                  return !empty($item->imgurl);
+              });
+
+              if ($firstWithImage) {
+                  // 如果有带图片的文章,将其放在第一位
+                  $group = $group->filter(function ($item) use ($firstWithImage) {
+                      return $item->id !== $firstWithImage->id;
+                  })->prepend($firstWithImage);
+              }
+
+              return [
+                  'category_name' => $group->first()->category_name,
+                  'catid' => $group->first()->category_id,
+                  'pinyin' => $group->first()->pinyin,
+//                  'type' => 100,
+                  'list' => $group->take(4)->map(function ($item) {
+                      return [
+                          'id' => $item->id,
+                          'title' => $item->title,
+//                          'imgurl' => $item->imgurl,
+//                          'created_at' => $item->created_at
+                      ];
+                  })->values()
+              ];
+          })
+          ->values()
+          ->toArray();
+      return Result::success($articlesList);
+  }
 }

+ 7 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -396,4 +396,11 @@ interface NewsServiceInterface
      */
     public function getWebsiteTsbbDetail(array $data):array;
     public function getWebsiteLevelJob(array $data):array;
+
+    /**
+     * 农网导航首页
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteNwHomeList(array $data):array;
 }

+ 1 - 1
runtime/hyperf.pid

@@ -1 +1 @@
-61331
+17978