Ver código fonte

Merge branch 'web_sannong_fr'

15313670163 1 mês atrás
pai
commit
927b7893ad
1 arquivos alterados com 32 adições e 17 exclusões
  1. 32 17
      app/JsonRpc/NewsService.php

+ 32 - 17
app/JsonRpc/NewsService.php

@@ -645,6 +645,7 @@ class NewsService implements NewsServiceInterface
         }
         return Result::success($result);
     }
+
     /**
      *获取新闻列表
      * @param array $data
@@ -773,6 +774,7 @@ class NewsService implements NewsServiceInterface
             $where['sur_id'] = $survey['sur_id'];
             // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
         }
+        // return Result::success($where);
         $result =  ArticleSurvey::where($where)
             ->where(function ($query) {
                 $query->where('is_other', 0)
@@ -836,16 +838,17 @@ class NewsService implements NewsServiceInterface
      */
     public function addWebsiteSurveyVote(array $data): array
     {
-
+        // return Result::success($data);
         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);
+            if(isset($data['sur_id']) && !empty($data['sur_id'])){
+                $is_survey = ArticleSurvey::where('sur_id',$data['sur_id'])->first();
+                // return Result::success($survey);
+                if(empty($is_survey)){
+                    return Result::error("此调查问卷不存在",0);
                 }
                 // return Result::success($survey);
                 // 调查问卷类型   
@@ -866,14 +869,25 @@ class NewsService implements NewsServiceInterface
                     if(!empty($other)){
                         return Result::error("请选择已有的选项!",0);
                     }
-                    $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']);
+                    $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($choice['other']);
+                    $choice_id = $data['choice_id'];
+                    if(!empty($choice['other'])){
+                        // array_push($data['choice_id'],$choice['other']['other_id']);
+                        if(!empty($choice_id)){
+                            $key = array_search($choice['other']['id'], $choice_id);
+                            if ($key!== false) {
+                                unset($choice_id[$key]);
+                                $choice_id = array_values($choice_id);
+                            }
+                            array_push($choice_id,$choice['other']['other_id']);
+                        }else{
+                            $choice_id[0] = $choice['other']['other_id'];
+                        }
                         // return Result::success($data['choice_id']);
                     }
                     // return Result::success($data);
@@ -883,11 +897,12 @@ class NewsService implements NewsServiceInterface
                     if (empty($choice)) {
                         return Result::error("请选择已有的选项!", 0);
                     }
-                    $retult_survey['data'] = ArticleSurvey::where('website_id', $data['website_id'])
-                    ->where('sur_id', $data['sur_id'])
+                    $survey['data'] = ArticleSurvey::where('sur_id',$data['sur_id'])
+                    ->where('website_id',$data['website_id'])
+                    ->where('other_id', 0)
                     ->get();
-                    $retult_survey['choice'] = $data['choice_id'];
-                    return Result::success($retult_survey);
+                    $survey['choice'] = $choice_id;
+                    return Result::success($survey);
                 }
                 return Result::error("参数必填!"); 
             }