diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e4e1fb8..4d9bf02b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### [v1.5.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.4)(2022-06-30) + +- 优化章节排序初始值和步长 + ### [v1.5.3](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.3)(2022-05-30) - 优化章节排序初始值和步长 diff --git a/app/Builders/CategoryTreeList.php b/app/Builders/CategoryTreeList.php index 6944aea8..1067c8fa 100644 --- a/app/Builders/CategoryTreeList.php +++ b/app/Builders/CategoryTreeList.php @@ -84,9 +84,9 @@ class CategoryTreeList extends Builder { $query = CategoryModel::query(); - $query->where('published = 1'); - $query->where('deleted = 0'); - $query->andWhere('parent_id = :parent_id:', ['parent_id' => $parentId]); + $query->where('parent_id = :parent_id:', ['parent_id' => $parentId]); + $query->andWhere('published = 1'); + $query->andWhere('deleted = 0'); $query->orderBy('priority ASC'); return $query->execute(); diff --git a/app/Console/Tasks/PointGiftDeliverTask.php b/app/Console/Tasks/PointGiftDeliverTask.php index ec93e357..b1553501 100644 --- a/app/Console/Tasks/PointGiftDeliverTask.php +++ b/app/Console/Tasks/PointGiftDeliverTask.php @@ -7,17 +7,16 @@ namespace App\Console\Tasks; -use App\Models\CourseUser as CourseUserModel; -use App\Models\ImGroupUser as ImGroupUserModel; use App\Models\PointGift as PointGiftModel; use App\Models\PointGiftRedeem as PointGiftRedeemModel; use App\Models\Task as TaskModel; use App\Repos\Course as CourseRepo; -use App\Repos\CourseUser as CourseUserRepo; -use App\Repos\ImGroup as ImGroupRepo; -use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\PointGift as PointGiftRepo; use App\Repos\PointGiftRedeem as PointGiftRedeemRepo; +use App\Repos\User as UserRepo; +use App\Repos\Vip as VipRepo; +use App\Services\Logic\Deliver\CourseDeliver as CourseDeliverService; +use App\Services\Logic\Deliver\VipDeliver as VipDeliverService; use App\Services\Logic\Notice\DingTalk\PointGiftRedeem as PointGiftRedeemNotice; use App\Services\Logic\Point\History\PointGiftRefund as PointGiftRefundPointHistory; use Phalcon\Mvc\Model\Resultset; @@ -52,6 +51,9 @@ class PointGiftDeliverTask extends Task case PointGiftModel::TYPE_COURSE: $this->handleCourseRedeem($redeem); break; + case PointGiftModel::TYPE_VIP: + $this->handleVipRedeem($redeem); + break; case PointGiftModel::TYPE_GOODS: $this->handleGoodsRedeem($redeem); break; @@ -112,54 +114,52 @@ class PointGiftDeliverTask extends Task throw new \RuntimeException('Course Not Found'); } - $groupRepo = new ImGroupRepo(); + $redeem->status = PointGiftRedeemModel::STATUS_FINISHED; - $group = $groupRepo->findByCourseId($course->id); - - if (!$group) { - throw new \RuntimeException('Im Group Not Found'); + if ($redeem->update() === false) { + throw new \RuntimeException('Update Point Redeem Status Failed'); } - $courseUserRepo = new CourseUserRepo(); + $userRepo = new UserRepo(); - $courseUser = $courseUserRepo->findCourseUser($course->id, $redeem->user_id); + $user = $userRepo->findById($redeem->user_id); - if (!$courseUser) { + $deliverService = new CourseDeliverService(); - $courseUser = new CourseUserModel(); + $deliverService->handle($course, $user); + } - $courseUser->user_id = $redeem->user_id; - $courseUser->course_id = $course->id; - $courseUser->expiry_time = strtotime("+{$course->study_expiry} months"); - $courseUser->role_type = CourseUserModel::ROLE_STUDENT; - $courseUser->source_type = CourseUserModel::SOURCE_POINT_REDEEM; + protected function handleVipRedeem(PointGiftRedeemModel $redeem) + { + $giftRepo = new PointGiftRepo(); - if ($courseUser->create() === false) { - throw new \RuntimeException('Create Course User Failed'); - } + $gift = $giftRepo->findById($redeem->gift_id); + + if (!$gift) { + throw new \RuntimeException('Gift Not Found'); } - $groupUserRepo = new ImGroupUserRepo(); + $vipRepo = new VipRepo(); - $groupUser = $groupUserRepo->findGroupUser($group->id, $redeem->user_id); + $vip = $vipRepo->findById($gift->attrs['id']); - if (!$groupUser) { - - $groupUser = new ImGroupUserModel(); - - $groupUser->group_id = $group->id; - $groupUser->user_id = $redeem->user_id; - - if ($groupUser->create() === false) { - throw new \RuntimeException('Create Group User Failed'); - } + if (!$vip) { + throw new \RuntimeException('Vip Not Found'); } $redeem->status = PointGiftRedeemModel::STATUS_FINISHED; if ($redeem->update() === false) { - throw new \RuntimeException('Update Redeem Status Failed'); + throw new \RuntimeException('Update Point Redeem Status Failed'); } + + $userRepo = new UserRepo(); + + $user = $userRepo->findById($redeem->user_id); + + $deliverService = new VipDeliverService(); + + $deliverService->handle($vip, $user); } protected function handleGoodsRedeem(PointGiftRedeemModel $redeem) diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index 5dd243d5..6439bb3c 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -56,11 +56,19 @@ class VodEventTask extends Task $attrs = $chapter->attrs; + /** + * 获取不到时长,尝试通过主动查询获取 + */ + if ($duration == 0) { + $duration = $this->getFileDuration($fileId); + } + /** * 获取不到时长视为失败 */ if ($duration == 0) { $attrs['file']['status'] = ChapterModel::FS_FAILED; + $attrs['duration'] = 0; $chapter->update(['attrs' => $attrs]); return; } @@ -78,7 +86,7 @@ class VodEventTask extends Task $chapter->update(['attrs' => $attrs]); - $this->updateVodAttrs($chapter); + $this->updateCourseVodAttrs($chapter->course_id); } protected function handleProcedureStateChangedEvent($event) @@ -95,6 +103,13 @@ class VodEventTask extends Task $attrs = $chapter->attrs; + /** + * 获取不到时长,尝试通过接口获得 + */ + if ($attrs['duration'] == 0) { + $attrs['duration'] = $this->getFileDuration($fileId); + } + $processResult = $event['ProcedureStateChangeEvent']['MediaProcessResultSet'] ?? []; /** @@ -156,11 +171,20 @@ class VodEventTask extends Task return $vodService->confirmEvents($handles); } - protected function updateVodAttrs(ChapterModel $chapter) + protected function updateCourseVodAttrs($courseId) { $courseStats = new CourseStatService(); - $courseStats->updateVodAttrs($chapter->course_id); + $courseStats->updateVodAttrs($courseId); + } + + protected function getFileDuration($fileId) + { + $service = new VodService(); + + $metaInfo = $service->getOriginVideoInfo($fileId); + + return $metaInfo['duration'] ?? 0; } } diff --git a/app/Http/Admin/Controllers/PointGiftController.php b/app/Http/Admin/Controllers/PointGiftController.php index 433308a5..057834db 100644 --- a/app/Http/Admin/Controllers/PointGiftController.php +++ b/app/Http/Admin/Controllers/PointGiftController.php @@ -47,9 +47,11 @@ class PointGiftController extends Controller $service = new PointGiftService(); $xmCourses = $service->getXmCourses(); + $xmVips = $service->getXmVips(); $types = $service->getTypes(); $this->view->setVar('xm_courses', $xmCourses); + $this->view->setVar('xm_vips', $xmVips); $this->view->setVar('types', $types); } diff --git a/app/Http/Admin/Services/ChapterContent.php b/app/Http/Admin/Services/ChapterContent.php index 5d257fc5..dec9abcd 100644 --- a/app/Http/Admin/Services/ChapterContent.php +++ b/app/Http/Admin/Services/ChapterContent.php @@ -133,14 +133,19 @@ class ChapterContent extends Service $vod = $chapterRepo->findChapterVod($chapter->id); - $vod->file_id = $fileId; - $vod->file_transcode = []; - $vod->update(); - $attrs = $chapter->attrs; - $attrs['duration'] = 0; - $attrs['file']['status'] = ChapterModel::FS_UPLOADED; + + if ($fileId != $vod->file_id) { + $vod->file_id = $fileId; + $vod->file_transcode = []; + $vod->update(); + + $attrs['file']['status'] = ChapterModel::FS_UPLOADED; + $attrs['duration'] = 0; + } + $chapter->attrs = $attrs; + $chapter->update(); $this->updateCourseVodAttrs($vod->course_id); diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index 0c5d3298..e76d595e 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -274,6 +274,7 @@ class Course extends Service $allCategories = $categoryRepo->findAll([ 'type' => CategoryModel::TYPE_COURSE, 'published' => 1, + 'deleted' => 0, ]); if ($allCategories->count() == 0) return []; diff --git a/app/Http/Admin/Services/FlashSale.php b/app/Http/Admin/Services/FlashSale.php index 3a90363b..8866de9a 100644 --- a/app/Http/Admin/Services/FlashSale.php +++ b/app/Http/Admin/Services/FlashSale.php @@ -50,7 +50,11 @@ class FlashSale extends Service { $courseRepo = new CourseRepo(); - $items = $courseRepo->findAll(['free' => 0, 'published' => 1]); + $items = $courseRepo->findAll([ + 'free' => 0, + 'published' => 1, + 'deleted' => 0, + ]); if ($items->count() == 0) return []; diff --git a/app/Http/Admin/Services/PointGift.php b/app/Http/Admin/Services/PointGift.php index 4ce0d39e..5b929c02 100644 --- a/app/Http/Admin/Services/PointGift.php +++ b/app/Http/Admin/Services/PointGift.php @@ -11,6 +11,7 @@ use App\Library\Paginator\Query as PagerQuery; use App\Models\PointGift as PointGiftModel; use App\Repos\Course as CourseRepo; use App\Repos\PointGift as PointGiftRepo; +use App\Repos\Vip as VipRepo; use App\Validators\PointGift as PointGiftValidator; class PointGift extends Service @@ -47,6 +48,29 @@ class PointGift extends Service return $result; } + public function getXmVips() + { + $vipRepo = new VipRepo(); + + $items = $vipRepo->findAll([ + 'published' => 1, + 'deleted' => 0, + ]); + + if ($items->count() == 0) return []; + + $result = []; + + foreach ($items as $item) { + $result[] = [ + 'name' => sprintf('%s(¥%0.2f)', $item->title, $item->price), + 'value' => $item->id, + ]; + } + + return $result; + } + public function getPointGifts() { $pagerQuery = new PagerQuery(); @@ -83,6 +107,9 @@ class PointGift extends Service case PointGiftModel::TYPE_COURSE: $gift = $this->createCoursePointGift($post); break; + case PointGiftModel::TYPE_VIP: + $gift = $this->createVipPointGift($post); + break; case PointGiftModel::TYPE_GOODS: $gift = $this->createGoodsPointGift($post); break; @@ -168,7 +195,7 @@ class PointGift extends Service $giftRepo = new PointGiftRepo(); - $gift = $giftRepo->findByCourseId($course->id); + $gift = $giftRepo->findItemGift($course->id, PointGiftModel::TYPE_COURSE); if ($gift) return $gift; @@ -188,6 +215,34 @@ class PointGift extends Service return $gift; } + protected function createVipPointGift($post) + { + $validator = new PointGiftValidator(); + + $vip = $validator->checkVip($post['xm_vip_id']); + + $giftRepo = new PointGiftRepo(); + + $gift = $giftRepo->findItemGift($vip->id, PointGiftModel::TYPE_VIP); + + if ($gift) return $gift; + + $gift = new PointGiftModel(); + + $gift->type = PointGiftModel::TYPE_VIP; + $gift->name = sprintf('会员服务(%s个月)', $vip->expiry); + $gift->cover = $vip->cover; + $gift->attrs = [ + 'id' => $vip->id, + 'title' => $vip->title, + 'price' => $vip->price, + ]; + + $gift->create(); + + return $gift; + } + protected function createGoodsPointGift($post) { $validator = new PointGiftValidator(); diff --git a/app/Http/Admin/Views/chapter/edit_lesson_vod.volt b/app/Http/Admin/Views/chapter/edit_lesson_vod.volt index eff5554f..dcdc68de 100644 --- a/app/Http/Admin/Views/chapter/edit_lesson_vod.volt +++ b/app/Http/Admin/Views/chapter/edit_lesson_vod.volt @@ -70,7 +70,7 @@