count(); $image_count = GoodsComment::alias('gc')->where('coach_id',$coachId)->join('goods_comment_image gci', 'gc.id = gci.comment_id')->group('gci.comment_id')->count(); $good_count = GoodsComment::where('coach_id', $coachId)->where('service_comment','>',3)->count(); $medium_bad_count = GoodsComment::where('coach_id', $coachId)->where('service_comment','<=',3)->count(); if($all_count == 0) { $percentStr = '100%'; $star = 5; }else { $percent = round((($good_count / $all_count) * 100)); $percentStr = round((($good_count / $all_count) * 100)).'%'; if ($percent >= 100) { $star = 5; } else if ($percent >= 80) { $star = 4; } else if ($percent >= 60) { $star = 3; } else if ($percent >= 40) { $star = 2; } else if ($percent >= 20) { $star = 1; } else { $star = 0; } } return ['comment'=> [ [ 'id' => 0, 'name' => '全部', 'count' => $all_count ], [ 'id' => 1, 'name' => '有图', 'count' => $image_count ], [ 'id' => 2, 'name' => '好评', 'count' => $good_count ], [ 'id' => 3, 'name' => '中差评', 'count' => $medium_bad_count ] ] , 'percent' => $percentStr, 'star' => $star, ]; } }