|
@@ -947,24 +947,42 @@ class NewsService implements NewsServiceInterface
|
|
|
{
|
|
|
if(isset($data['sur_id']) &&!empty($data['sur_id'])){
|
|
|
$where = [ 'sur_id'=>$data['sur_id']];
|
|
|
- $result['survey'] = ArticleSurvey::where($where)->where('is_other',0)
|
|
|
+ $choose = ArticleSurvey::where($where)->where('is_other',0)
|
|
|
->leftJoin('article','article_survey.art_id','article.id')
|
|
|
->select('article_survey.*','article.survey_type')
|
|
|
->get()->all();
|
|
|
- if(empty($result)){
|
|
|
+ if(empty($choose)){
|
|
|
return Result::error("此调查问卷不存在",0);
|
|
|
}
|
|
|
- $resultsArray = array_column($result['survey'], 'results');
|
|
|
+ $resultsArray = array_column($choose, 'results');
|
|
|
$total = array_sum($resultsArray);
|
|
|
- // $total = $result['survey']->sum('results');
|
|
|
- $result['other'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
|
|
|
- $result['others'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->first();
|
|
|
-
|
|
|
+ $other = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
|
|
|
+ $others = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->get()->all();
|
|
|
// $total = 0;
|
|
|
- if(!empty($result['other'])){
|
|
|
- $total = $total + $result['other']['results'];
|
|
|
+ if(!empty($other)){
|
|
|
+ $total = $total + $other['results'];
|
|
|
+ if(!empty($others)){
|
|
|
+ $other['hasChildren'] = true;
|
|
|
+ // array_push($other,['hasChildren','=',true]);
|
|
|
+ $other['children'] = $others;
|
|
|
+ $other_choices = [$other->toArray()];
|
|
|
+ $mer_choice = array_merge($choose,$other_choices);
|
|
|
+ $value_choice = array_values($mer_choice);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ // return Result::error('1111');
|
|
|
+ $other_choices = [$other->toArray()];
|
|
|
+ $other_choices = array_merge($choose,$other_choices);
|
|
|
+ $value_choice = array_values($other_choices);
|
|
|
+ // return Result::success($result);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $value_choice = $choose;
|
|
|
}
|
|
|
- $result['total'] = $total;
|
|
|
+ $result = [
|
|
|
+ 'choose'=>$value_choice,
|
|
|
+ 'total'=>$total
|
|
|
+ ];
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|