소스 검색

Merge branch 'web_sannong_fr'

15313670163 2 주 전
부모
커밋
5f3977b829
1개의 변경된 파일67개의 추가작업 그리고 12개의 파일을 삭제
  1. 67 12
      app/JsonRpc/NewsService.php

+ 67 - 12
app/JsonRpc/NewsService.php

@@ -821,6 +821,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'] . '%']);
@@ -847,14 +848,38 @@ class NewsService implements NewsServiceInterface
                 }
             }
         })
-            ->where(function ($query) use ($data) {
-                $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
-                    ->orWhereNull("ignore_ids");
-            })
-            ->orderBy("updated_at", "desc")
-            ->limit($data['pageSize'])
-            ->offset(($data['page'] - 1) * $data['pageSize'])
-            ->get();
+        ->where(function ($query) use ($data) {
+            $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()
+        // ;
+        ->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) {
@@ -1525,6 +1550,7 @@ class NewsService implements NewsServiceInterface
                 $textArticles = []; 
                 // return Result::error("暂无此栏目",0); 
             }else{ 
+                $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
                 // return Result::success($website);
                 // 查询图片新闻 
                 // 合并查询条件
@@ -1555,7 +1581,7 @@ class NewsService implements NewsServiceInterface
                         'website_category.alias',
                         'website_category.aLIas_pinyin'
                     )
-                    ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
+                    ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
                     ->orderBy('article.updated_at', 'desc')
                     ->limit($parentTextNum)
                     ->get()
@@ -1577,7 +1603,7 @@ class NewsService implements NewsServiceInterface
                         'website_category.alias',
                         'website_category.aLIas_pinyin'
                     )
-                    ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
+                    ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
                     ->orderBy('article.updated_at', 'desc')
                     ->where('imgurl', '!=', '')
                     ->limit($parentImgNum)
@@ -1597,8 +1623,37 @@ class NewsService implements NewsServiceInterface
             ]; 
 
 
-            return $resultItem;
-        }, $data);
+            return $resultItem; 
+        }, $data); 
+        return Result::success($result); 
+
+    }
+     /**
+     *获取头条类新闻模块-合集
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteAllArticlett(array $data): array
+    {
+        $input['id'] = $data['id'];
+        $input['website_id'] = $data['website_id'];
+        $data = json_decode($input['id'], true);
+        // 使用 array_map 处理每个元素
+        $result = array_map(function ($item) use ($input) { 
+            list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);  
+            $website = [
+                'website_id' => $input['website_id'] 
+            ];
+            $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
+            $category = array_values(array_unique($category->toArray()));
+            $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
+            $where = [
+                'status' => 1,
+            ];
+
+            return $category;
+        }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
+           
         return Result::success($result);
     }