123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class CoachStatistic extends Model
- {
- use HasFactory;
- protected $table = 'coach_statistics';
- protected $fillable = [
- 'coach_id',
- 'avg_score',
- 'comment_count',
- 'good_comment_count',
- 'medium_comment_count',
- 'bad_comment_count',
- 'tag_statistics',
- ];
- protected $casts = [
- 'avg_score' => 'decimal:2',
- 'comment_count' => 'integer',
- 'good_comment_count' => 'integer',
- 'medium_comment_count' => 'integer',
- 'bad_comment_count' => 'integer',
- 'tag_statistics' => 'array',
- ];
- /**
- * 获取统计所属的技师
- */
- public function coach()
- {
- return $this->belongsTo(CoachUser::class, 'coach_id');
- }
- /**
- * 更新标签统计
- */
- public function updateTagStatistics(array $tagCounts): bool
- {
- return $this->update([
- 'tag_statistics' => $tagCounts,
- ]);
- }
- /**
- * 更新评分统计
- */
- public function updateScoreStatistics(
- float $avgScore,
- int $commentCount,
- int $goodCount,
- int $mediumCount,
- int $badCount
- ): bool {
- return $this->update([
- 'avg_score' => $avgScore,
- 'comment_count' => $commentCount,
- 'good_comment_count' => $goodCount,
- 'medium_comment_count' => $mediumCount,
- 'bad_comment_count' => $badCount,
- ]);
- }
- }
|