1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-25 04:07:17 +08:00

更新重置演示直播课程逻辑

This commit is contained in:
koogua 2021-08-28 21:57:07 +08:00
parent 08163fc649
commit b842649fd0

View File

@ -3,6 +3,8 @@
namespace App\Console\Tasks; namespace App\Console\Tasks;
use App\Caches\CourseChapterList as CourseChapterListCache; use App\Caches\CourseChapterList as CourseChapterListCache;
use App\Models\Chapter as ChapterModel;
use App\Models\Course as CourseModel;
use App\Repos\Chapter as ChapterRepo; use App\Repos\Chapter as ChapterRepo;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Services\CourseStat as CourseStatService; use App\Services\CourseStat as CourseStatService;
@ -15,51 +17,65 @@ class RenewDemoLiveCourseTask extends Task
*/ */
public function mainAction() public function mainAction()
{ {
$day = date('d'); if (date('d') != 25) return;
if ($day != 25) return;
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();
$course = $courseRepo->findById(1393); $courses = $this->findLiveCourses();
$chapters = $courseRepo->findLessons($course->id); if ($courses->count() == 0) return;
$chapterRepo = new ChapterRepo(); foreach ($courses as $course) {
foreach ($chapters as $chapter) { $lessons = $courseRepo->findLessons($course->id);
$live = $chapterRepo->findChapterLive($chapter->id); foreach ($lessons as $lesson) {
$this->handleLesson($lesson);
if ($live->start_time > time()) {
continue;
} }
$startTime = strtotime('+1 month', $live->start_time); $statService = new CourseStatService();
$endTime = strtotime('+1 month', $live->end_time);
$live->start_time = $startTime; $statService->updateLiveAttrs($course->id);
$live->end_time = $endTime;
$live->update(); $cache = new CourseChapterListCache();
$attrs = $chapter->attrs; $cache->rebuild($course->id);
$attrs['start_time'] = $startTime;
$attrs['end_time'] = $endTime;
$chapter->attrs = $attrs;
$chapter->update();
} }
}
$statService = new CourseStatService(); protected function handleLesson(ChapterModel $chapter)
{
$chapterRepo = new ChapterRepo();
$statService->updateLiveAttrs($course->id); $live = $chapterRepo->findChapterLive($chapter->id);
$cache = new CourseChapterListCache(); if ($live->start_time > time()) return;
$cache->rebuild($course->id); $startTime = strtotime('+1 month', $live->start_time);
$endTime = strtotime('+1 month', $live->end_time);
$live->start_time = $startTime;
$live->end_time = $endTime;
$live->update();
$attrs = $chapter->attrs;
$attrs['start_time'] = $startTime;
$attrs['end_time'] = $endTime;
$chapter->attrs = $attrs;
$chapter->update();
}
protected function findLiveCourses($limit = 8)
{
return CourseModel::query()
->where('model = :model:', ['model' => CourseModel::MODEL_LIVE])
->orderBy('id DESC')
->limit($limit)
->execute();
} }
} }