소스 검색

c端-*修改获取新闻列表

15313670163 1 개월 전
부모
커밋
f76690a858
7개의 변경된 파일188개의 추가작업 그리고 37개의 파일을 삭제
  1. 2 2
      .env
  2. 166 35
      app/JsonRpc/NewsService.php
  3. 17 0
      app/JsonRpc/NewsServiceInterface.php
  4. 0 0
      runtime/container/classes.cache
  5. 1 0
      runtime/hyperf.pid
  6. 1 0
      vendor/composer/autoload_classmap.php
  7. 1 0
      vendor/composer/autoload_static.php

+ 2 - 2
.env

@@ -2,11 +2,11 @@ APP_NAME=news_producer
 APP_ENV=dev
 HOST = http://101.254.114.211:13306/
 DB_DRIVER=mysql
-DB_HOST=101.254.114.211
+DB_HOST=192.168.1.123
 DB_PORT=13306
 DB_DATABASE=hyperf
 DB_USERNAME=root
-DB_PASSWORD=xKmapDpKCxMMSkbe
+DB_PASSWORD=zxt_mysql_dev
 DB_CHARSET=utf8mb4
 DB_COLLATION=utf8mb4_unicode_ci
 DB_PREFIX=

+ 166 - 35
app/JsonRpc/NewsService.php

@@ -12,7 +12,7 @@ use Hyperf\RpcServer\Annotation\RpcService;
 use App\Tools\Result;
 use Ramsey\Uuid\Uuid;
 use Hyperf\Utils\Random;
-
+use App\Model\ArticleSurvey;
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
 {
@@ -562,25 +562,24 @@ class NewsService implements NewsServiceInterface
      */
     public function getWebsiteArticleList(array $data): array
     {
-
         $where[] = ['status', '=', 1];
-
-        if (isset($data['keyword']) && !empty($data['keyword'])) {
-            array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
-        }
-        if (isset($data['catid']) && !empty($data['catid'])) {
-            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(isset($data['keyword'])  && !empty($data['keyword'])){
+            array_push($where,['article.title','like','%'.$data['keyword'].'%']);
+        }
+        if(isset($data['catid'])  && !empty($data['catid'])){
+            if(is_array($data['catid'])){
+                $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
+                array_push($where,['catid', 'in', $data['catid']]);
+            }else{
+                $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
+                array_push($where,['catid', '=', $data['catid']]);
             }
             if (empty($category)) {
                 return Result::error("此网站暂无此栏目", 0);
             }
         }
-        // return Result::success($category);
+        // return Result::success($where);
+
         $rep = Article::where(function ($query) use ($where) {
             foreach ($where as $condition) {
                 if ($condition[1] === 'in') {
@@ -590,11 +589,12 @@ class NewsService implements NewsServiceInterface
                 }
             }
         })
-            ->orderBy("created_at", "desc")
-            ->limit($data['pageSize'])
-            ->offset(($data['page'] - 1) * $data['pageSize'])
-            ->get();
-        $count = Article::where(function ($query) use ($where) {
+        ->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]);
@@ -603,14 +603,17 @@ class NewsService implements NewsServiceInterface
                 }
             }
         })->count();
+
         $data = [
             'rows' => $rep->toArray(),
             'count' => $count,
         ];
-        if (empty($rep)) {
+        
+        if(empty($rep)){
             return Result::error("没有信息数据");
         }
         return Result::success($data);
+        
     }
     /**
      * 前端-获取新闻详情
@@ -635,25 +638,153 @@ class NewsService implements NewsServiceInterface
         $result['cat_name'] = $category['name'];
         return Result::success($result);
     }
-
     /**
-     * 验证导航名称是否重复
-     * @return void
+     * 前端-获取网站调查问卷
+     * @param array $data
+     * @return array
      */
-    public function checkCategoryName(array $data): array
+     public function getWebsiteSurvey(array $data): array
     {
-        $result = Category::when($data, function ($query) use ($data) {
-            if (isset($data['name']) && $data['name']) {
-                $query->where("name", $data['name']);
+        if(isset($data['survey_id']) && !empty($data['survey_id'])){
+            $website = Website::where('id',$data['website_id'])->first();
+            if(empty($website)){
+                return Result::error("暂无此网站",0);
             }
-            if (isset($data['id']) && $data['id']) {
-                $query->where("id", "!=", $data['id']);
+        }
+        if(isset($data['art_id'])  && !empty($data['art_id'])){
+            $article = Article::where('id',$data['art_id'])->first();
+            if(empty($article)){
+                return Result::error("暂无此文章",0);
             }
-        })->first();
-        if ($result) {
-            return Result::error("已存在");
-        } else {
-            return Result::success();
+            // return Result::error($data,0);
+            $where['art_id'] = $data['art_id'];
+            // $query = ArticleSurvey::where('art_id',$data['art_id']); 
+            
+        }else{
+            $survey = ArticleSurvey::where('website_id',$data['website_id'])->orderBy('created_at')->first();
+            if(empty($survey)){
+                return Result::error("暂无调查问卷",0); 
+            }
+            $where['sur_id'] = $survey['sur_id'];
+            // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
+        }
+        $result['survey'] =  ArticleSurvey::where($where)->where('is_other',0)
+        ->leftJoin('article','article_survey.art_id','article.id')
+        ->select('article_survey.*','article.survey_type')
+        ->get()->all();
+        $result['others'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
+        $result['other'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->first();
+        if(empty($result)){
+            return Result::error("此文章暂无调查问卷",0); 
+        }
+        return Result::success($result);
+    }
+    /**
+     * 前端-添加网站调查问卷选项
+     * @param array $data
+     * @return array
+     */
+    public function addWebsiteSurveyOption(array $data): array
+    {
+        if(isset($data['website_id']) && !empty($data['website_id'])){
+            $website = Website::where('id',$data['website_id'])->first();
+            if(empty($website)){
+                return Result::error("暂无此网站",0);
+            }
+            if(isset($data['sur_id']) && !empty($data['sur_id'])){
+                $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first(); 
+                if(empty($survey)){
+                    return Result::error("此调查问卷不可添加选项",0); 
+                }
+                if(isset($data['choice_name']) &&!empty($data['choice_name'])){
+                    $choice = [
+                        'art_id'=>$survey['art_id'],
+                        'website_id'=>$data['website_id'],
+                        'survey_name'=>$survey['survey_name'],
+                        'choice_name'=>$data['choice_name'],
+                        'sur_id'=>$survey['sur_id'],                   
+                        'is_other'=>1,
+                        'other_id'=>$survey['id'],
+    
+                    ];
+                    $result = ArticleSurvey::insertGetId($choice);
+                    if(empty($result)){
+                        return Result::error("添加失败",0);
+                    }
+                    return Result::success($result);
+                }
+            }
+            return Result::error("添加失败",0);
+        }
+        return Result::error("添加失败",0);
+        
+    }
+    /**
+     * 前端-调查问卷投票   
+     * @param array $data
+     * @return array
+     */
+    public function addWebsiteSurveyVote(array $data): array
+    {
+        
+        if(isset($data['website_id']) && !empty($data['website_id'])){
+            $website = Website::where('id',$data['website_id'])->first(); 
+            if(empty($website)){
+                return Result::error("暂无此网站",0); 
+            }
+            if(isset($data['sur_id']) && !empty($data['sur_id'])){
+                $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->pluck('sur_id');
+                if(empty($survey)){
+                    return Result::error("此调查问卷不存在",0);
+                }
+                // return Result::success($survey);
+                // 调查问卷类型   0:单选 1:多选
+                $type = Article::where('survey_id',$data['sur_id'])->pluck('survey_type');
+                // return Result::success($type);
+                if(empty($type) || ($type[0]!= 1 && $type[0]!= 0)){
+                    return Result::error("此调查问卷不可投票",0); 
+                }
+                // return Result::success($type[0]);
+                if(isset($data['choice_id']) &&!empty($data['choice_id'])){
+                    if($type[0] == 0){
+                        if(is_array($data['choice_id'])){
+                            return Result::error("请选择一个选项!",0);
+                        }
+                        $data['choice_id'] = [$data['choice_id']];
+                    }else{
+                        if(!is_array($data['choice_id'])){
+                            return Result::error("请传递数组!",0);
+                        }
+                    }
+                    // return Result::success($data['choice_id']);
+                    $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
+                    ->where('website_id',$data['website_id'])
+                    ->where('is_other',1)
+                    ->where('other_id','!=',0)
+                    ->first();
+                    // return Result::success($data);
+                    if(!empty($choice['other'])){
+                        array_push($data['choice_id'],$choice['other']['other_id']);
+                        // return Result::success($data['choice_id']);
+                    }
+                    // return Result::success($data);
+                    $choice = ArticleSurvey::whereIn('id',$data['choice_id'])
+                    ->where('website_id',$data['website_id'])
+                    ->increment('results', 1);                 
+                    if(empty($choice)){
+                        return Result::error("请选择已有的选项!",0);
+                    }
+ 
+                    return Result::success($choice);
+
+                }
+                return Result::error("参数必填!");
+                // if(isset($data['choice_id']) && !empty($data['choice_id'])){
+                //     $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
+                // }
+            }
+            return Result::error("此调查问卷不存在",0);
         }
+        return Result::error("参数必填!");
     }
-}
+}

+ 17 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -108,5 +108,22 @@ interface NewsServiceInterface
      * @return array
      */
     public function selectWebsiteArticleInfo(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteSurvey(array $data):array;
+
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function addWebsiteSurveyOption(array $data):array;
+
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function addWebsiteSurveyVote(array $data):array;
 
 }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
runtime/container/classes.cache


+ 1 - 0
runtime/hyperf.pid

@@ -0,0 +1 @@
+64458

+ 1 - 0
vendor/composer/autoload_classmap.php

@@ -17,6 +17,7 @@ return array(
     'App\\Listener\\ResumeExitCoordinatorListener' => $baseDir . '/app/Listener/ResumeExitCoordinatorListener.php',
     'App\\Model\\Article' => $baseDir . '/app/Model/Article.php',
     'App\\Model\\ArticleData' => $baseDir . '/app/Model/ArticleData.php',
+    'App\\Model\\ArticleSurvey' => $baseDir . '/app/Model/ArticleSurvey.php',
     'App\\Model\\Category' => $baseDir . '/app/Model/Category.php',
     'App\\Model\\Link' => $baseDir . '/app/Model/Link.php',
     'App\\Model\\Model' => $baseDir . '/app/Model/Model.php',

+ 1 - 0
vendor/composer/autoload_static.php

@@ -701,6 +701,7 @@ class ComposerStaticInit88f2a4d4a4e81dc7d415bcdf39930654
         'App\\Listener\\ResumeExitCoordinatorListener' => __DIR__ . '/../..' . '/app/Listener/ResumeExitCoordinatorListener.php',
         'App\\Model\\Article' => __DIR__ . '/../..' . '/app/Model/Article.php',
         'App\\Model\\ArticleData' => __DIR__ . '/../..' . '/app/Model/ArticleData.php',
+        'App\\Model\\ArticleSurvey' => __DIR__ . '/../..' . '/app/Model/ArticleSurvey.php',
         'App\\Model\\Category' => __DIR__ . '/../..' . '/app/Model/Category.php',
         'App\\Model\\Link' => __DIR__ . '/../..' . '/app/Model/Link.php',
         'App\\Model\\Model' => __DIR__ . '/../..' . '/app/Model/Model.php',

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.