|
@@ -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("参数必填!");
|