初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
namespace app\coachapi\logic;
use app\common\model\goods\GoodsComment;
class GoodsCommentLogic
{
public function commentCategory(int $coachId)
{
$all_count = GoodsComment::where('coach_id', $coachId)->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,
];
}
}