Przeglądaj źródła

修改c端接口:处理路由问题、搜索新闻、获取头条新闻

15313670163 5 miesięcy temu
rodzic
commit
7f97c875db
1 zmienionych plików z 30 dodań i 38 usunięć
  1. 30 38
      app/JsonRpc/NewsService.php

+ 30 - 38
app/JsonRpc/NewsService.php

@@ -319,8 +319,8 @@ class NewsService implements NewsServiceInterface
         ];
         // $website_id = $data['website_id'];
         $month = date("Y-m-d H:i:s", strtotime("-30 day"));
-         //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
-            // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
+        //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
+        // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
         switch($data['level']){
             case 1:
             case 2:
@@ -401,7 +401,7 @@ class NewsService implements NewsServiceInterface
             ->limit($data['textnum'])
             ->get()->all();
             foreach ($result['text'] as $k => $v) {
-                $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
+                $result['text'][$k]->pinyin = $catiall[$v->catid];
             }
         }
         if($data['imgnum'] > 0){
@@ -416,7 +416,7 @@ class NewsService implements NewsServiceInterface
             ->limit($data['imgnum'])
             ->get()->all();
             foreach ($result['img'] as $k => $v) {
-                $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
+                $result['img'][$k]->pinyin = $catiall[$v->catid];
             }
         }
         
@@ -909,12 +909,17 @@ class NewsService implements NewsServiceInterface
      */
     public function selectWebsiteArticle(array $data): array
     {
-        $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
-         $website_id = $data['website_id'];
-        $categorys = $this->processArticlePro($website_id); 
-        $catiall = $categorys['catiall'];
+        $category = WebsiteCategory::where('website_id', $data['website_id'])->get()->all();
+        $website_id = $data['website_id'];
+        // $categorys = $this->processArticlePro($website_id); 
+        $categoryIds = array_column($category, 'category_id');
+        $aliasPinyins = array_column($category, 'path');
+        $alias = array_column($category, 'alias');
+        $cat_arr = array_combine($categoryIds, $aliasPinyins);
+        $cat_alias_arr = array_combine($categoryIds, $alias);
+        // return Result::success($cat_arr['205']);
         $query = Article::where('status', 1)
-            ->whereIn('catid', $category)
+            ->whereIn('catid', $categoryIds)
             ->leftJoinSub(function ($query) use ($website_id) {
                 $query->from('article_ignore')
                     ->where('website_id', $website_id);
@@ -925,7 +930,8 @@ class NewsService implements NewsServiceInterface
                 $query->whereNull('article_ignore.article_id')
                     ->orWhere('article_ignore.website_id', '!=', $website_id);
             });
-        // return Result::success($all_articles);
+        //     ->get()->all();
+        // return Result::success($query);
         if (isset($data['cityid']) && !empty($data['cityid'])) {
             $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
         }
@@ -957,10 +963,10 @@ class NewsService implements NewsServiceInterface
             ->offset(($data['page'] - 1) * $data['pageSize'])
             ->limit($data['pageSize'])
             ->get();
-       
+      //  return Result::success($articles);
         foreach ($articles as $k => $v) {
-            $articles[$k]->category_name = $catiall[$v->catid]['alias'];
-            $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
+            $articles[$k]->category_name = $cat_alias_arr[$v->catid];
+            $articles[$k]->pinyin = $cat_arr[$v->catid];
         }
         if (empty($articles)) {
             return Result::error("没有符合条件的资讯数据");
@@ -1075,6 +1081,7 @@ class NewsService implements NewsServiceInterface
     $categorys = $this->processArticlePro($wetbsite_id);
     $cat_1st_arr = $categorys['cat_1st_arr'];
     $catiall = $categorys['catiall'];
+    
     $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
     $parent_category = array_column($data, 'parent');
     $parent_cat = [];        
@@ -1684,37 +1691,22 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
      */
     function processArticlePro($website_id){
         $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
-        $websiteInfoIndexed = array_column($categorys, null, 'category_id');
+        // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
         // 取出category_id 对应的aLIas_pinyin 
         $categoryIds = array_column($categorys, 'category_id');
         $categoryPIds = array_column($categorys, 'pid');
-        $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
+        $aliasPinyins = array_column($categorys, 'path');
+        $alias = array_column($categorys, 'alias');
         $cat_arr = array_combine($categoryIds, $aliasPinyins);
-        // return Result::success($categorys);
-        $catiall = [];
+        $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
+        // return Result::success($cat_arr);
+        // $catiall = [];
         //一级所有子级的记录
-        $cat_1st_arr = [];
-        foreach ($categorys as $key => $value) {
-            $category_arr_id = json_decode($value->category_arr_id);
-            $pinyin_str = '';
-            // 算出一级  并且算出子级
-            if ($value->pid != 0) {
-                $cat_1st_arr[$value->pid][] = $value->category_id;
-            } 
-            foreach ($category_arr_id as $k => $v) {
-                $pinyin_str .= $cat_arr[$v] . '/';
-            }
-            $pinyin_str = rtrim($pinyin_str, '/');
-            $catiall[$value->category_id]['alias'] = $value->alias;
-            $catiall[$value->category_id]['category_id'] = $value->category_id;
-            $catiall[$value->category_id]['type'] = $value->type;
-            $catiall[$value->category_id]['pinyin'] = $pinyin_str; 
-            $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
-        }
+        $cat_alias_arr = array_combine($categoryIds, $alias);
         return [
-            'cat_1st_arr' => $cat_1st_arr,
-            'catiall' => $catiall,
-            'websiteInfoIndexed' => $websiteInfoIndexed,
+            'cat_1st_arr' => $cat_alias_arr,
+            'catiall' => $cat_arr,
+            // 'websiteInfoIndexed' => $websiteInfoIndexed,
             'categoryIds' => $categoryIds,
         ];