1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-29 05:41:37 +08:00
koogua 4cae5ece11 !16 v1.2.0阶段性合并
* 更换README.md中的简书图床为gitee本地
* 修复编辑器图片上传,增加上传文件身份认证,markdown内容解析
* 移除Mobile模块,修复API请求章节信息权限问题
2020-11-27 09:38:54 +08:00

64 lines
1.4 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);
$user = $this->getLoginUser();
$validator = new ConsultValidator();
$validator->checkOwner($user->id, $consult->owner_id);
$consult->update(['deleted' => 1]);
if ($consult->course_id > 0) {
$course = $this->checkCourse($consult->course_id);
$this->decrCourseConsultCount($course);
}
if ($consult->chapter_id > 0) {
$chapter = $this->checkChapter($consult->chapter_id);
$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();
}
}
}