瀏覽代碼

修改获取广告、获取新闻详情的接口

15313670163 3 月之前
父節點
當前提交
c7ae0f2c04
共有 3 個文件被更改,包括 18 次插入6 次删除
  1. 13 5
      app/JsonRpc/NewsService.php
  2. 1 1
      runtime/hyperf.pid
  3. 4 0
      runtime/logs/hyperf.log

+ 13 - 5
app/JsonRpc/NewsService.php

@@ -4,6 +4,7 @@ namespace App\JsonRpc;
 use App\Model\Article;
 use App\Model\ArticleData;
 use App\Model\Category;
+use App\Model\Website;
 use App\Model\WebsiteCategory;
 use Hyperf\DbConnection\Db;
 use Hyperf\RpcServer\Annotation\RpcService;
@@ -264,23 +265,30 @@ class NewsService implements NewsServiceInterface
         }
     }
     /**
+     * 获取新闻详情
      * @param array $data
      * @return array
      */
     public function getArticleInfo(array $data): array
     {
         $where = [
-            'article.id'=>$data['id']
+            'article.id'=>$data['id'],
+            'article.status'=>1
         ];
         $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
-        if($result){
-            return Result::success($result->toArray());
-        }else{
+        if(empty($result)){
             return Result::error("查询失败",0);
         }
+        $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
+        if(empty($category)){
+            return Result::error("查询失败",0);
+        }
+        $result['category_id'] = $category['category_id'];
+        $result['cat_name'] = $category['name'];
+        return Result::success($result);
     }
     /**
-     *  获取新闻
+     *  获取头条新闻
      * @param array $data
      * @return array
     */

+ 1 - 1
runtime/hyperf.pid

@@ -1 +1 @@
-58024
+12539

+ 4 - 0
runtime/logs/hyperf.log

@@ -1962,3 +1962,7 @@
 [2025-02-12T09:27:54.590410+08:00] sql.INFO: [241.68] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '17' limit 1 [] []
 [2025-02-12T09:27:54.915225+08:00] sql.INFO: [309] select * from `article` where (`catid` = '17') order by `created_at` desc limit 20 offset 20 [] []
 [2025-02-12T09:27:55.226457+08:00] sql.INFO: [310.08] select count(*) as aggregate from `article` where (`catid` = '17') [] []
+[2025-02-17T09:52:54.842438+08:00] sql.INFO: [1375.25] select * from `article` left join `article_data` on `article`.`id` = `article_data`.`article_id` where (`article`.`id` = '3404' and `article`.`status` = '1') limit 1 [] []
+[2025-02-17T09:52:54.876453+08:00] sql.INFO: [17.86] select * from `website_category` where `website_id` = '2' and (`category_id` = '2') limit 1 [] []
+[2025-02-17T09:54:40.193451+08:00] sql.INFO: [277.4] select * from `article` left join `article_data` on `article`.`id` = `article_data`.`article_id` where (`article`.`id` = '3404' and `article`.`status` = '1') limit 1 [] []
+[2025-02-17T09:54:40.226718+08:00] sql.INFO: [17.26] select * from `website_category` where `website_id` = '2' and (`category_id` = '2') limit 1 [] []