1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-29 05:41:37 +08:00
koogua 0336a54911 1.源文件增加版权信息
2.群组状态和课程协同
2021-06-13 15:49:47 +08:00

81 lines
1.9 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Consult;
use App\Models\Chapter as ChapterModel;
use App\Models\Course as CourseModel;
use App\Repos\Chapter as ChapterRepo;
use App\Repos\Course as CourseRepo;
use App\Services\Logic\ChapterTrait;
use App\Services\Logic\ConsultTrait;
use App\Services\Logic\CourseTrait;
use App\Services\Logic\Service as LogicService;
use App\Validators\Consult as ConsultValidator;
class ConsultDelete extends LogicService
{
use CourseTrait;
use ChapterTrait;
use ConsultTrait;
public function handle($id)
{
$consult = $this->checkConsult($id);
$user = $this->getLoginUser();
$validator = new ConsultValidator();
$validator->checkOwner($user->id, $consult->owner_id);
$consult->deleted = 1;
$consult->update();
if ($consult->course_id > 0) {
$course = $this->checkCourse($consult->course_id);
$this->recountCourseConsults($course);
}
if ($consult->chapter_id > 0) {
$chapter = $this->checkChapter($consult->chapter_id);
$this->recountChapterConsults($chapter);
}
$this->eventsManager->fire('Consult:afterDelete', $this, $consult);
}
protected function recountCourseConsults(CourseModel $course)
{
$courseRepo = new CourseRepo();
$consultCount = $courseRepo->countConsults($course->id);
$course->consult_count = $consultCount;
$course->update();
}
protected function recountChapterConsults(ChapterModel $chapter)
{
$chapterRepo = new ChapterRepo();
$consultCount = $chapterRepo->countConsults($chapter->id);
$chapter->consult_count = $consultCount;
$chapter->update();
}
}