Browse Source

Merge branch 'web_sannong_fr' into dev

15313670163 1 month ago
parent
commit
c9085149a0
1 changed files with 18 additions and 8 deletions
  1. 18 8
      app/JsonRpc/NewsService.php

+ 18 - 8
app/JsonRpc/NewsService.php

@@ -784,6 +784,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)
@@ -847,7 +848,7 @@ class NewsService implements NewsServiceInterface
      */
     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)){
@@ -881,16 +882,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);
+                    $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']);
-                        $choice_id[0] = $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);