1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-28 13:21:37 +08:00
2020-09-17 21:29:29 +08:00

58 lines
1.3 KiB
PHP

<?php
namespace App\Services\Logic\Consult;
use App\Models\Chapter as ChapterModel;
use App\Models\Course as CourseModel;
use App\Services\Logic\ChapterTrait;
use App\Services\Logic\ConsultTrait;
use App\Services\Logic\CourseTrait;
use App\Services\Logic\Service;
use App\Validators\Consult as ConsultValidator;
class ConsultDelete extends Service
{
use CourseTrait;
use ChapterTrait;
use ConsultTrait;
public function handle($id)
{
$consult = $this->checkConsult($id);
$course = $this->checkCourse($consult->course_id);
$chapter = $this->checkChapter($consult->chapter_id);
$user = $this->getLoginUser();
$validator = new ConsultValidator();
$validator->checkOwner($user->id, $consult->owner_id);
$consult->update(['deleted' => 1]);
$this->decrCourseConsultCount($course);
$this->decrChapterConsultCount($chapter);
}
protected function decrCourseConsultCount(CourseModel $course)
{
if ($course->consult_count > 0) {
$course->consult_count -= 1;
$course->update();
}
}
protected function decrChapterConsultCount(ChapterModel $chapter)
{
if ($chapter->consult_count > 0) {
$chapter->consult_count -= 1;
$chapter->update();
}
}
}