1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-25 12:09:09 +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,25 +17,39 @@ 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;
foreach ($courses as $course) {
$lessons = $courseRepo->findLessons($course->id);
foreach ($lessons as $lesson) {
$this->handleLesson($lesson);
}
$statService = new CourseStatService();
$statService->updateLiveAttrs($course->id);
$cache = new CourseChapterListCache();
$cache->rebuild($course->id);
}
}
protected function handleLesson(ChapterModel $chapter)
{
$chapterRepo = new ChapterRepo(); $chapterRepo = new ChapterRepo();
foreach ($chapters as $chapter) {
$live = $chapterRepo->findChapterLive($chapter->id); $live = $chapterRepo->findChapterLive($chapter->id);
if ($live->start_time > time()) { if ($live->start_time > time()) return;
continue;
}
$startTime = strtotime('+1 month', $live->start_time); $startTime = strtotime('+1 month', $live->start_time);
$endTime = strtotime('+1 month', $live->end_time); $endTime = strtotime('+1 month', $live->end_time);
@ -53,13 +69,13 @@ class RenewDemoLiveCourseTask extends Task
$chapter->update(); $chapter->update();
} }
$statService = new CourseStatService(); protected function findLiveCourses($limit = 8)
{
$statService->updateLiveAttrs($course->id); return CourseModel::query()
->where('model = :model:', ['model' => CourseModel::MODEL_LIVE])
$cache = new CourseChapterListCache(); ->orderBy('id DESC')
->limit($limit)
$cache->rebuild($course->id); ->execute();
} }
} }