소스 검색

修改投票列表-投票的接口

15313670163 1 개월 전
부모
커밋
5b34c08571
1개의 변경된 파일18개의 추가작업 그리고 18개의 파일을 삭제
  1. 18 18
      app/JsonRpc/NewsService.php

+ 18 - 18
app/JsonRpc/NewsService.php

@@ -549,7 +549,7 @@ class NewsService implements NewsServiceInterface
                     if(empty($result)){
                         return Result::error("添加失败",0);
                     }
-                    return Result::success($result);
+                    return Result::success($data);
                 }
             }
             return Result::error("添加失败",0);
@@ -564,6 +564,14 @@ class NewsService implements NewsServiceInterface
      */
     public function addWebsiteSurveyVote(array $data): array
     {
+        // $choice_id = $data['choice_id'];
+        // return Result::success($data);
+        if(is_array($data['choice_id'])){
+            if (!is_array($data['choice_id'])) {
+                $data['choice_id'] = [$data['choice_id']];
+            }
+            $data['choice_id'] = array_map('intval', $data['choice_id']);
+        }
         if(isset($data['website_id']) && !empty($data['website_id'])){
             $website = Website::where('id',$data['website_id'])->first(); 
             if(empty($website)){
@@ -575,25 +583,16 @@ class NewsService implements NewsServiceInterface
                     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);
-                        }
+                    //多选 若是json型则转化成数组类型
+                    if (strpos($data['choice_id'], '[') === 0) {
+                        $data['choice_id'] = json_decode($data['choice_id'], true);
+                    } else {
+                        // 单选  也转换成数组
                         $data['choice_id'] = [$data['choice_id']];
-                    }else{
-                        if(!is_array($data['choice_id'])){
-                            return Result::error("请传递数组!",0);
-                        }
                     }
-                    // return Result::success($data['choice_id']);
+                    $data['choice_id'] = array_map('intval', $data['choice_id']);
                     $other = ArticleSurvey::whereIn('id',$data['choice_id'])
                     ->where('website_id',$data['website_id'])
                     ->where('is_other',1)
@@ -619,9 +618,10 @@ class NewsService implements NewsServiceInterface
                     if(empty($choice)){
                         return Result::error("请选择已有的选项!",0);
                     }
-                    $retult_survey = ArticleSurvey::where('website_id', $data['website_id'])
+                    $retult_survey['data'] = ArticleSurvey::where('website_id', $data['website_id'])
                     ->where('sur_id', $data['sur_id'])
                     ->get();
+                    $retult_survey['choice'] = $data['choice_id'];
                     return Result::success($retult_survey);
                 }
                 return Result::error("参数必填!");