|
@@ -36,6 +36,7 @@ use App\Services\Client\Traits\HandlesPayments;
|
|
|
use App\Services\Client\Traits\HandlesOrderRecords;
|
|
|
use App\Services\Client\Traits\ValidatesServiceTime;
|
|
|
use App\Services\Client\Traits\CalculatesOrderAmounts;
|
|
|
+use App\Models\CoachStatistic;
|
|
|
|
|
|
readonly class OrderService
|
|
|
{
|
|
@@ -2568,7 +2569,7 @@ readonly class OrderService
|
|
|
|
|
|
// 3. 更新技师评分
|
|
|
// TODO: 更新技师评分
|
|
|
- // $this->updateCoachScore($order->coach_id);
|
|
|
+ $this->updateCoachScore($order->coach_id);
|
|
|
|
|
|
// 4. 更新订单状态
|
|
|
$this->updateOrderEvaluationStatus($order);
|
|
@@ -2621,27 +2622,6 @@ readonly class OrderService
|
|
|
return $order;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新技师评分
|
|
|
- */
|
|
|
- // private function updateCoachScore(int $coachId): void
|
|
|
- // {
|
|
|
- // $coach = CoachUser::findOrFail($coachId);
|
|
|
-
|
|
|
- // // 计算平均分
|
|
|
- // $avgScore = OrderEvaluation::where('coach_id', $coachId)
|
|
|
- // ->where('state', 'normal')
|
|
|
- // ->avg('score');
|
|
|
-
|
|
|
- // // 更新技师评分
|
|
|
- // $coach->info()->update([
|
|
|
- // 'score' => round($avgScore, 1),
|
|
|
- // 'evaluation_count' => OrderEvaluation::where('coach_id', $coachId)
|
|
|
- // ->where('state', 'normal')
|
|
|
- // ->count(),
|
|
|
- // ]);
|
|
|
- // }
|
|
|
-
|
|
|
/**
|
|
|
* 更新订单评价状态
|
|
|
*/
|
|
@@ -2814,7 +2794,7 @@ readonly class OrderService
|
|
|
$order->update(['state' => OrderStatus::COMPLETED->value]);
|
|
|
|
|
|
// 更新技师评分
|
|
|
- // $this->updateCoachScore($order->coach_id);
|
|
|
+ $this->updateCoachScore($order->coach_id);
|
|
|
|
|
|
// 记录订单状态变更
|
|
|
OrderRecord::create([
|
|
@@ -2852,7 +2832,17 @@ readonly class OrderService
|
|
|
DB::raw('AVG(service_score) as avg_service_score'),
|
|
|
DB::raw('AVG(appearance_score) as avg_appearance_score'),
|
|
|
DB::raw('AVG(attitude_score) as avg_attitude_score'),
|
|
|
- DB::raw('AVG(professional_score) as avg_professional_score')
|
|
|
+ DB::raw('AVG(professional_score) as avg_professional_score'),
|
|
|
+ DB::raw('COUNT(*) as total_comments')
|
|
|
+ ])
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ // 获取订单统计
|
|
|
+ $orderCounts = DB::table('order')
|
|
|
+ ->where('coach_id', $coachId)
|
|
|
+ ->select([
|
|
|
+ DB::raw('COUNT(*) as total_orders'),
|
|
|
+ DB::raw('COUNT(CASE WHEN state = ' . OrderStatus::COMPLETED->value . ' THEN 1 END) as completed_orders')
|
|
|
])
|
|
|
->first();
|
|
|
|
|
@@ -2863,14 +2853,20 @@ readonly class OrderService
|
|
|
$avgScores->avg_attitude_score +
|
|
|
$avgScores->avg_professional_score) / 4, 1);
|
|
|
|
|
|
- // 更新技师评分
|
|
|
- $coach->update([
|
|
|
- 'score' => $overallScore,
|
|
|
- 'service_score' => round($avgScores->avg_service_score, 1),
|
|
|
- 'appearance_score' => round($avgScores->avg_appearance_score, 1),
|
|
|
- 'attitude_score' => round($avgScores->avg_attitude_score, 1),
|
|
|
- 'professional_score' => round($avgScores->avg_professional_score, 1)
|
|
|
- ]);
|
|
|
+ // 更新或创建统计记录
|
|
|
+ CoachStatistic::updateOrCreate(
|
|
|
+ ['coach_id' => $coachId],
|
|
|
+ [
|
|
|
+ 'score' => $overallScore,
|
|
|
+ 'service_score' => round($avgScores->avg_service_score, 1),
|
|
|
+ 'appearance_score' => round($avgScores->avg_appearance_score, 1),
|
|
|
+ 'attitude_score' => round($avgScores->avg_attitude_score, 1),
|
|
|
+ 'professional_score' => round($avgScores->avg_professional_score, 1),
|
|
|
+ 'comment_count' => $avgScores->total_comments,
|
|
|
+ 'order_count' => $orderCounts->total_orders,
|
|
|
+ 'completed_order_count' => $orderCounts->completed_orders
|
|
|
+ ]
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
}
|