ソースを参照

投票111最新

15313670163 1 ヶ月 前
コミット
b0213bbaa7
2 ファイル変更53 行追加38 行削除
  1. 48 33
      app/JsonRpc/NewsService.php
  2. 5 5
      app/JsonRpc/NewsServiceInterface.php

+ 48 - 33
app/JsonRpc/NewsService.php

@@ -385,37 +385,47 @@ class NewsService implements NewsServiceInterface
      * @param array $data
      * @return array
     */
-    // public function getWebsiteCatidArticle(array $data): array
-    // {
-    //     $where = [
-    //         'category.status' => 1,
-    //         'category.category_id' => $data['catid'],
-    //         'category.website_id' => $data['website_id'],
-    //         // 'article.status' => 1,
-    //     ];
-    //     $category = WebsiteCategory::where($where)
-    //     ->leftJoin('article', 'article.catid', 'category.category_id')
-    //     ->when(!empty($data['img_num']), function ($query) use ($data) {
-    //         $query->where('status',1)
-    //             ->whereNotNull('article.img_url')
-    //             ->limit($data['img_num']);
-    //     })
-    //     ->when(!empty($data['text_num']), function ($query) use ($data) {
-    //         $query->where('status',1)
-    //         ->whereNull('article.img_url')
-    //             ->limit($data['text_num']);
-    //     })
-    //     ->get();
-    //     $result = ArticleSurvey::where($where)->first();
-    //     if(!empty($result)){
-    //         return Result::error("您已点赞过", 0);
-    //     }
-    //     $result = ArticleSurvey::insertGetId($data);
-    //     if(!$result){
-    //         return Result::error("点赞失败", 0);
-    //     }
-    //     return Result::success($result);
-    // }
+    public function getWebsiteCatidArticle(array $data): array
+    {
+        $where = [
+            // 'category.status' => 1,
+            'website_category.category_id' => $data['catid'],
+            'website_category.website_id' => $data['website_id'],
+            // 'article.status' => 1,
+        ];
+        // $category = WebsiteCategory::where($where);
+        if (!empty($data['img_num'])) {
+            $category['img'] = WebsiteCategory::where($where)
+                ->leftJoin('article', 'article.catid', 'website_category.category_id')
+                ->where('article.status', 1)
+                ->whereNotNull('article.imgurl')
+                ->select('article.*','website_category.category_id','website_category.alias')
+                ->orderBy('article.updated_at', 'desc')
+                ->limit($data['img_num'])
+                ->get();
+        }
+
+        if (!empty($data['text_num'])) {
+            $category['text'] = WebsiteCategory::where($where)
+                ->leftJoin('article', 'article.catid', 'website_category.category_id')
+                ->where('article.status', 1)
+                ->where(function ($query) {
+                    $query->whereNull('article.imgurl')
+                          ->orWhere('article.imgurl', '');
+                })
+                ->select('article.*','website_category.category_id','website_category.alias')
+                ->orderBy('article.updated_at', 'desc')
+                ->limit($data['text_num'])
+                ->get();
+        }
+
+        // $category = $category->get();
+      
+        if(empty($category)){
+            return Result::error("查询失败", 0);
+        }
+        return Result::success($category);
+    }
 
     /**
      *获取新闻列表 
@@ -531,11 +541,16 @@ class NewsService implements NewsServiceInterface
             // $query = ArticleSurvey::where('art_id',$data['art_id']); 
             
         }else{
-            $survey = ArticleSurvey::where('website_id',$data['website_id'])->orderBy('created_at')->first();
+            $survey = Article::where('catid',28)
+            ->where('status',1)
+            ->where('is_survey',1)
+            ->select('survey_id')
+            ->orderBy('updated_at','desc')
+            ->first();
             if(empty($survey)){
                 return Result::error("暂无调查问卷",0); 
             }
-            $where['sur_id'] = $survey['sur_id'];
+            $where['sur_id'] = $survey['survey_id'];
             // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
         }
         // return Result::success($where);

+ 5 - 5
app/JsonRpc/NewsServiceInterface.php

@@ -127,9 +127,9 @@ interface NewsServiceInterface
      * @return array
      */
     public function selectWebsiteArticle(array $data):array;
-    //  /**
-    //  * @param array $data
-    //  * @return array
-    //  */
-    // public function getWebsiteCatidArticle(array $data):array;
+     /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteCatidArticle(array $data):array;
 }