Ver Fonte

修改获取新闻列表接口

15313670163 há 3 meses atrás
pai
commit
8e2a11c1ec
3 ficheiros alterados com 68 adições e 8 exclusões
  1. 31 7
      app/JsonRpc/NewsService.php
  2. 1 1
      runtime/hyperf.pid
  3. 36 0
      runtime/logs/hyperf.log

+ 31 - 7
app/JsonRpc/NewsService.php

@@ -384,6 +384,7 @@ class NewsService implements NewsServiceInterface
 
 
     /**
+     *获取新闻列表 
      * @param array $data
      * @return array
      */
@@ -396,17 +397,40 @@ class NewsService implements NewsServiceInterface
             array_push($where,['article.title','like','%'.$data['keyword'].'%']);
         }
         if(isset($data['catid'])  && !empty($data['catid'])){
-            $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->select('category_id')->first();
+            if(is_array($data['catid'])){
+                $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
+                $where[] = ['catid', 'in', $data['catid']];
+            }else{
+                $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
+                $where[] = ['catid', '=', $data['catid']];
+            }
             if(empty($category)){
                return Result::error("此网站暂无此栏目",0); 
             }
-            array_push($where,['catid',$data['catid']]);
         }
-        $rep = Article::where($where)
-            ->orderBy("created_at","desc")
-            ->limit($data['pageSize'])
-            ->offset(($data['page']-1)*$data['pageSize'])->get();
-        $count =  Article::where($where)->count();
+        // return Result::success($category);
+        $rep = Article::where(function ($query) use ($where) {
+            foreach ($where as $condition) {
+                if ($condition[1] === 'in') {
+                    $query->whereIn($condition[0], $condition[2]);
+                } else {
+                    $query->where($condition[0], $condition[1], $condition[2]);
+                }
+            }
+        })
+        ->orderBy("created_at", "desc")
+        ->limit($data['pageSize'])
+        ->offset(($data['page'] - 1) * $data['pageSize'])
+        ->get();
+        $count =  Article::where(function ($query) use ($where) {
+            foreach ($where as $condition) {
+                if ($condition[1] === 'in') {
+                    $query->whereIn($condition[0], $condition[2]);
+                } else {
+                    $query->where($condition[0], $condition[1], $condition[2]);
+                }
+            }
+        })->count();
         $data = [
             'rows'=>$rep->toArray(),
             'count'=>$count

+ 1 - 1
runtime/hyperf.pid

@@ -1 +1 @@
-12539
+48622

+ 36 - 0
runtime/logs/hyperf.log

@@ -1966,3 +1966,39 @@
 [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 [] []
+[2025-02-17T13:50:46.952375+08:00] sql.INFO: [58.56] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '17' limit 1 [] []
+[2025-02-17T13:50:46.986153+08:00] sql.INFO: [15.77] select * from `article` where (`status` = '1' and `article`.`title` like '%中国%' and `catid` = '17') order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T13:50:47.001744+08:00] sql.INFO: [13.88] select count(*) as aggregate from `article` where (`status` = '1' and `article`.`title` like '%中国%' and `catid` = '17') [] []
+[2025-02-17T13:51:01.891450+08:00] sql.INFO: [13.57] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '17' limit 1 [] []
+[2025-02-17T13:51:01.909862+08:00] sql.INFO: [17.37] select * from `article` where (`status` = '1' and `catid` = '17') order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T13:51:01.932182+08:00] sql.INFO: [14.94] select count(*) as aggregate from `article` where (`status` = '1' and `catid` = '17') [] []
+[2025-02-17T13:54:40.872027+08:00] sql.INFO: [115.4] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '17' limit 1 [] []
+[2025-02-17T13:54:40.908209+08:00] sql.INFO: [20.55] select * from `article` where (`status` = '1' and `article`.`title` like '%中国%' and `catid` = '17') order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T13:54:40.925638+08:00] sql.INFO: [15.22] select count(*) as aggregate from `article` where (`status` = '1' and `article`.`title` like '%中国%' and `catid` = '17') [] []
+[2025-02-17T13:55:42.163190+08:00] sql.INFO: [62.64] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '[154]' limit 1 [] []
+[2025-02-17T14:11:06.551279+08:00] sql.INFO: [73.85] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('[154]') [] []
+[2025-02-17T14:12:35.472573+08:00] sql.INFO: [56.91] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('{{$.5.response.body.data}}') [] []
+[2025-02-17T14:13:29.401683+08:00] sql.INFO: [16.42] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '[154,155,157,158]' [] []
+[2025-02-17T14:24:47.307360+08:00] sql.INFO: [1916.57] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17', '18', '19') [] []
+[2025-02-17T14:26:57.052823+08:00] sql.INFO: [66.42] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17', '18', '19') [] []
+[2025-02-17T14:26:58.206844+08:00] sql.INFO: [17.57] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17', '18', '19') [] []
+[2025-02-17T14:30:27.597030+08:00] sql.INFO: [61.55] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17', '18', '19') [] []
+[2025-02-17T14:30:27.622766+08:00] sql.INFO: [18.43] select * from `article` where (`status` = '1' and `catid` in ('17', '18', '19')) order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:30:27.679429+08:00] sql.INFO: [40.37] select count(*) as aggregate from `article` where (`status` = '1' and `catid` = 'in') [] []
+[2025-02-17T14:31:08.741081+08:00] sql.INFO: [282.92] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17', '18', '19') [] []
+[2025-02-17T14:31:09.241970+08:00] sql.INFO: [492.2] select * from `article` where (`status` = '1' and `catid` in ('17', '18', '19')) order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:31:09.489034+08:00] sql.INFO: [227.67] select count(*) as aggregate from `article` where (`status` = '1' and `catid` in ('17', '18', '19')) [] []
+[2025-02-17T14:31:22.951500+08:00] sql.INFO: [340.02] select * from `article` where (`status` = '1') order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:31:22.974634+08:00] sql.INFO: [18.09] select count(*) as aggregate from `article` where (`status` = '1') [] []
+[2025-02-17T14:31:26.973312+08:00] sql.INFO: [17.83] select `category_id` from `website_category` where `website_id` = '2' and `category_id` = '17' [] []
+[2025-02-17T14:31:27.011183+08:00] sql.INFO: [37.3] select * from `article` where (`status` = '1' and `catid` = '17') order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:31:27.029651+08:00] sql.INFO: [13.42] select count(*) as aggregate from `article` where (`status` = '1' and `catid` = '17') [] []
+[2025-02-17T14:31:40.541616+08:00] sql.INFO: [15.85] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17') [] []
+[2025-02-17T14:31:40.574383+08:00] sql.INFO: [31.91] select * from `article` where (`status` = '1' and `catid` in ('17')) order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:31:40.595020+08:00] sql.INFO: [16.64] select count(*) as aggregate from `article` where (`status` = '1' and `catid` in ('17')) [] []
+[2025-02-17T14:31:42.631105+08:00] sql.INFO: [17.03] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17') [] []
+[2025-02-17T14:31:42.657965+08:00] sql.INFO: [26.32] select * from `article` where (`status` = '1' and `catid` in ('17')) order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:31:42.677964+08:00] sql.INFO: [15.31] select count(*) as aggregate from `article` where (`status` = '1' and `catid` in ('17')) [] []
+[2025-02-17T14:31:45.202065+08:00] sql.INFO: [17.06] select `category_id` from `website_category` where `website_id` = '2' and `category_id` in ('17', '18') [] []
+[2025-02-17T14:31:45.229088+08:00] sql.INFO: [26.15] select * from `article` where (`status` = '1' and `catid` in ('17', '18')) order by `created_at` desc limit 20 offset 0 [] []
+[2025-02-17T14:31:45.250109+08:00] sql.INFO: [15.98] select count(*) as aggregate from `article` where (`status` = '1' and `catid` in ('17', '18')) [] []