mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-29 22:01:38 +08:00
53 lines
1.1 KiB
PHP
53 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Logic\Review;
|
|
|
|
use App\Models\Course as CourseModel;
|
|
use App\Services\CourseStat as CourseStatService;
|
|
use App\Services\Logic\CourseTrait;
|
|
use App\Services\Logic\ReviewTrait;
|
|
use App\Services\Logic\Service;
|
|
use App\Validators\Review as ReviewValidator;
|
|
|
|
class ReviewDelete extends Service
|
|
{
|
|
|
|
use CourseTrait;
|
|
use ReviewTrait;
|
|
|
|
public function handle($id)
|
|
{
|
|
$review = $this->checkReview($id);
|
|
|
|
$course = $this->checkCourse($review->course_id);
|
|
|
|
$user = $this->getLoginUser();
|
|
|
|
$validator = new ReviewValidator();
|
|
|
|
$validator->checkOwner($user->id, $review->owner_id);
|
|
|
|
$review->update(['deleted' => 1]);
|
|
|
|
$this->decrCourseReviewCount($course);
|
|
|
|
$this->updateCourseRating($course);
|
|
}
|
|
|
|
protected function decrCourseReviewCount(CourseModel $course)
|
|
{
|
|
if ($course->review_count > 0) {
|
|
$course->review_count -= 1;
|
|
$course->update();
|
|
}
|
|
}
|
|
|
|
protected function updateCourseRating(CourseModel $course)
|
|
{
|
|
$service = new CourseStatService();
|
|
|
|
$service->updateRating($course->id);
|
|
}
|
|
|
|
}
|