From 7945644f3a67ed5d3dfdecc5ae286f531941a28e Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 9 Jun 2022 10:26:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96VodEventTask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/VodEventTask.php | 95 ++++++++++++++++-------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index 6439bb3c..861f1ae9 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -25,18 +25,24 @@ class VodEventTask extends Task foreach ($events as $event) { - $handles[] = $event['EventHandle']; + $result = true; if ($event['EventType'] == 'NewFileUpload') { - $this->handleNewFileUploadEvent($event); + $result = $this->handleNewFileUploadEvent($event); } elseif ($event['EventType'] == 'ProcedureStateChanged') { - $this->handleProcedureStateChangedEvent($event); + $result = $this->handleProcedureStateChangedEvent($event); } elseif ($event['EventType'] == 'FileDeleted') { - $this->handleFileDeletedEvent($event); + $result = $this->handleFileDeletedEvent($event); + } + + if ($result) { + $handles[] = $event['EventHandle']; } } - $this->confirmEvents($handles); + if (count($handles) > 0) { + $this->confirmEvents($handles); + } } protected function handleNewFileUploadEvent($event) @@ -46,13 +52,13 @@ class VodEventTask extends Task $height = $event['FileUploadEvent']['MetaData']['Width'] ?? 0; $duration = $event['FileUploadEvent']['MetaData']['Duration'] ?? 0; - if ($fileId == 0) return; + if ($fileId == 0) return false; $chapterRepo = new ChapterRepo(); $chapter = $chapterRepo->findByFileId($fileId); - if (!$chapter) return; + if (!$chapter) return false; $attrs = $chapter->attrs; @@ -63,43 +69,43 @@ class VodEventTask extends Task $duration = $this->getFileDuration($fileId); } - /** - * 获取不到时长视为失败 - */ - if ($duration == 0) { - $attrs['file']['status'] = ChapterModel::FS_FAILED; - $attrs['duration'] = 0; - $chapter->update(['attrs' => $attrs]); - return; - } + $isVideo = $width > 0 && $height > 0; $vodService = new VodService(); - if ($width == 0 && $height == 0) { - $vodService->createTransAudioTask($fileId); + if ($duration > 0) { + if ($isVideo) { + $vodService->createTransVideoTask($fileId); + } else { + $vodService->createTransAudioTask($fileId); + } + $attrs['file']['status'] = ChapterModel::FS_TRANSLATING; } else { - $vodService->createTransVideoTask($fileId); + $attrs['file']['status'] = ChapterModel::FS_FAILED; } - $attrs['file']['status'] = ChapterModel::FS_TRANSLATING; $attrs['duration'] = (int)$duration; - $chapter->update(['attrs' => $attrs]); + $chapter->attrs = $attrs; + + $chapter->update(); $this->updateCourseVodAttrs($chapter->course_id); + + return true; } protected function handleProcedureStateChangedEvent($event) { $fileId = $event['ProcedureStateChangeEvent']['FileId'] ?? 0; - if ($fileId == 0) return; + if ($fileId == 0) return false; $chapterRepo = new ChapterRepo(); $chapter = $chapterRepo->findByFileId($fileId); - if (!$chapter) return; + if (!$chapter) return false; $attrs = $chapter->attrs; @@ -110,31 +116,28 @@ class VodEventTask extends Task $attrs['duration'] = $this->getFileDuration($fileId); } - $processResult = $event['ProcedureStateChangeEvent']['MediaProcessResultSet'] ?? []; - - /** - * 获取不到处理结果视为失败 - */ - if (empty($processResult)) { - $attrs['file']['status'] = ChapterModel::FS_FAILED; - $chapter->update(['attrs' => $attrs]); - return; - } - $failCount = $successCount = 0; - foreach ($processResult as $item) { - if ($item['Type'] == 'Transcode') { - if ($item['TranscodeTask']['Status'] == 'SUCCESS') { - $successCount++; - } elseif ($item['TranscodeTask']['Status'] == 'FAIL') { - $failCount++; + $processResult = $event['ProcedureStateChangeEvent']['MediaProcessResultSet'] ?? []; + + if ($processResult) { + foreach ($processResult as $item) { + if ($item['Type'] == 'Transcode') { + if ($item['TranscodeTask']['Status'] == 'SUCCESS') { + $successCount++; + } elseif ($item['TranscodeTask']['Status'] == 'FAIL') { + $failCount++; + } } } } $fileStatus = ChapterModel::FS_TRANSLATING; + if (!$processResult) { + $fileStatus = ChapterModel::FS_FAILED; + } + /** * 当有一个成功标记为成功 */ @@ -144,17 +147,21 @@ class VodEventTask extends Task $fileStatus = ChapterModel::FS_FAILED; } - if ($fileStatus == ChapterModel::FS_TRANSLATING) return; - $attrs['file']['id'] = $fileId; $attrs['file']['status'] = $fileStatus; - $chapter->update(['attrs' => $attrs]); + $chapter->attrs = $attrs; + + $chapter->update(); + + $this->updateCourseVodAttrs($chapter->course_id); + + return true; } protected function handleFileDeletedEvent($event) { - + return true; } protected function pullEvents() From 35a87851775ffc66d3e706fcb5f0a46f5577663b Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 9 Jun 2022 20:32:17 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Views/chapter/edit_lesson_vod.volt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Http/Admin/Views/chapter/edit_lesson_vod.volt b/app/Http/Admin/Views/chapter/edit_lesson_vod.volt index dcdc68de..ca7f90ef 100644 --- a/app/Http/Admin/Views/chapter/edit_lesson_vod.volt +++ b/app/Http/Admin/Views/chapter/edit_lesson_vod.volt @@ -48,8 +48,15 @@
-
- 选择视频 +
+ +
+
+ {% if vod.file_id > 0 %} + 重新上传 + {% else %} + 选择视频 + {% endif %}
@@ -61,12 +68,6 @@
-
- -
- -
-
From 21f92166d26b447e9722c49e9652dcbc45620be0 Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 16 Jun 2022 09:12:43 +0800 Subject: [PATCH 3/3] v1.5.4 --- CHANGELOG.md | 11 ++++- app/Caches/CategoryList.php | 10 ++-- app/Caches/CategoryTreeList.php | 8 ++-- app/Console/Tasks/DeliverTask.php | 41 ++++++++++++++++ app/Http/Admin/Services/Article.php | 1 + app/Http/Admin/Services/FlashSale.php | 5 +- app/Http/Admin/Services/Question.php | 1 + app/Http/Admin/Services/Session.php | 2 +- app/Http/Admin/Views/public/login.volt | 48 +++++++++---------- app/Http/Home/Services/Account.php | 2 +- .../Home/Views/account/forget_password.volt | 8 ++-- .../Home/Views/account/login_by_password.volt | 12 +++-- .../Home/Views/account/login_by_verify.volt | 8 ++-- app/Http/Home/Views/account/register.volt | 8 ++-- .../Views/user/console/account_email.volt | 8 ++-- .../Views/user/console/account_phone.volt | 8 ++-- app/Models/Account.php | 2 +- app/Services/Logic/Article/XmTagList.php | 5 +- app/Services/Logic/Course/XmTagList.php | 5 +- app/Services/Logic/Question/XmTagList.php | 5 +- app/Services/Logic/Tag/TagList.php | 1 + app/Services/Logic/Verify/MailCode.php | 2 +- app/Services/Logic/Verify/SmsCode.php | 2 +- app/Services/Logic/Verify/Ticket.php | 27 ----------- db/migrations/20220607014823.php | 2 +- db/migrations/SettingTrait.php | 2 +- public/static/home/js/captcha.login.js | 12 ++--- public/static/home/js/captcha.verify.js | 14 +++--- 28 files changed, 151 insertions(+), 109 deletions(-) delete mode 100644 app/Services/Logic/Verify/Ticket.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d9bf02b..ae1935b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ -### [v1.5.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.4)(2022-06-30) +### [v1.5.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.4)(2022-06-15) +- 增加migration助手SettingTrait +- 增加积分兑换会员 +- 增加ISP备案和电子执照配置 +- 增加获取视频时长补偿机制 +- 优化课程和套餐发货 +- 优化验证码 +- 优化视频点播回调处理任务 - 优化章节排序初始值和步长 +- 优化后台视频上传和转码 +- 修正获取子分类查询条件 ### [v1.5.3](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.3)(2022-05-30) diff --git a/app/Caches/CategoryList.php b/app/Caches/CategoryList.php index acde5f8a..78a203eb 100644 --- a/app/Caches/CategoryList.php +++ b/app/Caches/CategoryList.php @@ -20,23 +20,23 @@ class CategoryList extends Cache return $this->lifetime; } - public function getKey($type = null) + public function getKey($id = null) { - return "category_list:{$type}"; + return "category_list:{$id}"; } /** - * @param null $type + * @param null $id * @return array */ - public function getContent($type = null) + public function getContent($id = null) { /** * @var Resultset $categories */ $categories = CategoryModel::query() ->columns(['id', 'parent_id', 'name', 'priority', 'level', 'path']) - ->where('type = :type:', ['type' => $type]) + ->where('type = :type:', ['type' => $id]) ->andWhere('published = 1') ->andWhere('deleted = 0') ->orderBy('level ASC, priority ASC') diff --git a/app/Caches/CategoryTreeList.php b/app/Caches/CategoryTreeList.php index 7ccc23f4..c5c7c78e 100644 --- a/app/Caches/CategoryTreeList.php +++ b/app/Caches/CategoryTreeList.php @@ -19,16 +19,16 @@ class CategoryTreeList extends Cache return $this->lifetime; } - public function getKey($type = null) + public function getKey($id = null) { - return "category_tree_list:{$type}"; + return "category_tree_list:{$id}"; } - public function getContent($type = null) + public function getContent($id = null) { $builder = new CategoryTreeListBuilder(); - $list = $builder->handle($type); + $list = $builder->handle($id); return $list ?: []; } diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index 521847a2..aec87f1d 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -145,6 +145,33 @@ class DeliverTask extends Task $service = new VipDeliverService(); $service->handle($vip, $user); + + /** + * 先下单购买课程,发现会员有优惠,于是购买会员,再回头购买课程 + * 自动关闭未支付订单,让用户可以使用会员价再次下单 + */ + $this->closePendingOrders($user->id); + } + + protected function closePendingOrders($userId) + { + $orders = $this->findUserPendingOrders($userId); + + if ($orders->count() == 0) return; + + $itemTypes = [ + OrderModel::ITEM_COURSE, + OrderModel::ITEM_PACKAGE, + ]; + + foreach ($orders as $order) { + $case1 = in_array($order->item_type, $itemTypes); + $case2 = $order->promotion_type == 0; + if ($case1 && $case2) { + $order->status = OrderModel::STATUS_CLOSED; + $order->update(); + } + } } protected function handleOrderConsumePoint(OrderModel $order) @@ -209,6 +236,20 @@ class DeliverTask extends Task ]); } + /** + * @param int $userId + * @return ResultsetInterface|Resultset|OrderModel[] + */ + protected function findUserPendingOrders($userId) + { + $status = OrderModel::STATUS_PENDING; + + return OrderModel::query() + ->where('owner_id = :owner_id:', ['owner_id' => $userId]) + ->andWhere('status = :status:', ['status' => $status]) + ->execute(); + } + /** * @param int $limit * @return ResultsetInterface|Resultset|TaskModel[] diff --git a/app/Http/Admin/Services/Article.php b/app/Http/Admin/Services/Article.php index e1855fdc..e796ee74 100644 --- a/app/Http/Admin/Services/Article.php +++ b/app/Http/Admin/Services/Article.php @@ -50,6 +50,7 @@ class Article extends Service 'type' => CategoryModel::TYPE_ARTICLE, 'level' => 1, 'published' => 1, + 'deleted' => 0, ]); } diff --git a/app/Http/Admin/Services/FlashSale.php b/app/Http/Admin/Services/FlashSale.php index 8866de9a..45c0ad8e 100644 --- a/app/Http/Admin/Services/FlashSale.php +++ b/app/Http/Admin/Services/FlashSale.php @@ -74,7 +74,10 @@ class FlashSale extends Service { $packageRepo = new PackageRepo(); - $items = $packageRepo->findAll(['published' => 1]); + $items = $packageRepo->findAll([ + 'published' => 1, + 'deleted' => 0, + ]); if ($items->count() == 0) return []; diff --git a/app/Http/Admin/Services/Question.php b/app/Http/Admin/Services/Question.php index 58c8386c..ac514eda 100644 --- a/app/Http/Admin/Services/Question.php +++ b/app/Http/Admin/Services/Question.php @@ -49,6 +49,7 @@ class Question extends Service 'type' => CategoryModel::TYPE_ARTICLE, 'level' => 1, 'published' => 1, + 'deleted' => 0, ]); } diff --git a/app/Http/Admin/Services/Session.php b/app/Http/Admin/Services/Session.php index 48f318de..53978d19 100644 --- a/app/Http/Admin/Services/Session.php +++ b/app/Http/Admin/Services/Session.php @@ -43,7 +43,7 @@ class Session extends Service $validator = new CaptchaValidator(); - $validator->checkCode($post['ticket'], $post['rand']); + $validator->checkCode($post['captcha']['ticket'], $post['captcha']['rand']); } $this->auth->saveAuthInfo($user); diff --git a/app/Http/Admin/Views/public/login.volt b/app/Http/Admin/Views/public/login.volt index 0e254821..b4c31fec 100644 --- a/app/Http/Admin/Views/public/login.volt +++ b/app/Http/Admin/Views/public/login.volt @@ -12,7 +12,7 @@ diff --git a/app/Http/Home/Views/user/console/account_email.volt b/app/Http/Home/Views/user/console/account_email.volt index b478c723..36d1a793 100644 --- a/app/Http/Home/Views/user/console/account_email.volt +++ b/app/Http/Home/Views/user/console/account_email.volt @@ -34,10 +34,10 @@
- - - - + + + +
diff --git a/app/Http/Home/Views/user/console/account_phone.volt b/app/Http/Home/Views/user/console/account_phone.volt index a27ff982..67e90edd 100644 --- a/app/Http/Home/Views/user/console/account_phone.volt +++ b/app/Http/Home/Views/user/console/account_phone.volt @@ -34,10 +34,10 @@
- - - - + + + +
diff --git a/app/Models/Account.php b/app/Models/Account.php index 923e9067..8b49561b 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -100,7 +100,7 @@ class Account extends Model $user = new User(); $user->id = $this->id; - $user->name = "user:{$this->id}"; + $user->name = "user_{$this->id}"; if ($user->create() === false) { throw new \RuntimeException('Create User Failed'); diff --git a/app/Services/Logic/Article/XmTagList.php b/app/Services/Logic/Article/XmTagList.php index 485cc70d..9a9be385 100644 --- a/app/Services/Logic/Article/XmTagList.php +++ b/app/Services/Logic/Article/XmTagList.php @@ -19,7 +19,10 @@ class XmTagList extends LogicService { $tagRepo = new TagRepo(); - $allTags = $tagRepo->findAll(['published' => 1]); + $allTags = $tagRepo->findAll([ + 'published' => 1, + 'deleted' => 0, + ]); if ($allTags->count() == 0) return []; diff --git a/app/Services/Logic/Course/XmTagList.php b/app/Services/Logic/Course/XmTagList.php index 700da77b..e25ec51e 100644 --- a/app/Services/Logic/Course/XmTagList.php +++ b/app/Services/Logic/Course/XmTagList.php @@ -19,7 +19,10 @@ class XmTagList extends LogicService { $tagRepo = new TagRepo(); - $allTags = $tagRepo->findAll(['published' => 1]); + $allTags = $tagRepo->findAll([ + 'published' => 1, + 'deleted' => 0, + ]); if ($allTags->count() == 0) return []; diff --git a/app/Services/Logic/Question/XmTagList.php b/app/Services/Logic/Question/XmTagList.php index a43a664b..78a0f4c9 100644 --- a/app/Services/Logic/Question/XmTagList.php +++ b/app/Services/Logic/Question/XmTagList.php @@ -19,7 +19,10 @@ class XmTagList extends LogicService { $tagRepo = new TagRepo(); - $allTags = $tagRepo->findAll(['published' => 1]); + $allTags = $tagRepo->findAll([ + 'published' => 1, + 'deleted' => 0, + ]); if ($allTags->count() == 0) return []; diff --git a/app/Services/Logic/Tag/TagList.php b/app/Services/Logic/Tag/TagList.php index 875bf61c..08b57af1 100644 --- a/app/Services/Logic/Tag/TagList.php +++ b/app/Services/Logic/Tag/TagList.php @@ -23,6 +23,7 @@ class TagList extends LogicService $params = $pagerQuery->getParams(); $params['published'] = 1; + $params['deleted'] = 0; $sort = $pagerQuery->getSort(); $page = $pagerQuery->getPage(); diff --git a/app/Services/Logic/Verify/MailCode.php b/app/Services/Logic/Verify/MailCode.php index d3cb7768..20bc4567 100644 --- a/app/Services/Logic/Verify/MailCode.php +++ b/app/Services/Logic/Verify/MailCode.php @@ -29,7 +29,7 @@ class MailCode extends LogicService $validator = new CaptchaValidator(); - $validator->checkCode($post['ticket'], $post['rand']); + $validator->checkCode($post['captcha']['ticket'], $post['captcha']['rand']); } $service = new MailVerifyService(); diff --git a/app/Services/Logic/Verify/SmsCode.php b/app/Services/Logic/Verify/SmsCode.php index adcbb080..5e54575b 100644 --- a/app/Services/Logic/Verify/SmsCode.php +++ b/app/Services/Logic/Verify/SmsCode.php @@ -29,7 +29,7 @@ class SmsCode extends LogicService $validator = new CaptchaValidator(); - $validator->checkCode($post['ticket'], $post['rand']); + $validator->checkCode($post['captcha']['ticket'], $post['captcha']['rand']); } $service = new SmsVerifyService(); diff --git a/app/Services/Logic/Verify/Ticket.php b/app/Services/Logic/Verify/Ticket.php deleted file mode 100644 index b42c1915..00000000 --- a/app/Services/Logic/Verify/Ticket.php +++ /dev/null @@ -1,27 +0,0 @@ -request->getPost('rand', ['trim', 'string']); - - $validator = new VerifyValidator(); - - $rand = $validator->checkRand($rand); - - return $this->crypt->encryptBase64($rand); - } - -} diff --git a/db/migrations/20220607014823.php b/db/migrations/20220607014823.php index 02a12daf..5c8a5778 100644 --- a/db/migrations/20220607014823.php +++ b/db/migrations/20220607014823.php @@ -1,7 +1,7 @@ 0) { + if ($('#cl-captcha-enabled').val() === '1') { var captcha = new TencentCaptcha( - $('#captcha-btn')[0], - $('#captcha-btn').data('app-id'), + $('#cl-emit-btn')[0], + $('#cl-captcha-appId').val(), function (res) { if (res.ret === 0) { - $('#ticket').val(res.ticket); - $('#rand').val(res.randstr); + $('#cl-captcha-ticket').val(res.ticket); + $('#cl-captcha-rand').val(res.randstr); + $('#cl-submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); $('#captcha-block').hide(); - $('#submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); } } ); diff --git a/public/static/home/js/captcha.verify.js b/public/static/home/js/captcha.verify.js index 1cc4a05c..5340f9fb 100644 --- a/public/static/home/js/captcha.verify.js +++ b/public/static/home/js/captcha.verify.js @@ -9,14 +9,14 @@ layui.use(['jquery', 'layer', 'util'], function () { var $emit = $('#cv-emit-btn'); var $submit = $('#cv-submit-btn'); - if ($('#cv-enabled').val() === '1') { + if ($('#cv-captcha-enabled').val() === '1') { var captcha = new TencentCaptcha( $emit[0], - $('#cv-app-id').val(), + $('#cv-captcha-appId').val(), function (res) { if (res.ret === 0) { - $('#cv-ticket').val(res.ticket); - $('#cv-rand').val(res.randstr); + $('#cv-captcha-ticket').val(res.ticket); + $('#cv-captcha-rand').val(res.randstr); sendVerifyCode(); } } @@ -49,8 +49,10 @@ layui.use(['jquery', 'layer', 'util'], function () { if (isEmail($account.val()) || isPhone($account.val())) { var postUrl; var postData = { - ticket: $('#cv-ticket').val(), - rand: $('#cv-rand').val(), + captcha: { + ticket: $('#cv-captcha-ticket').val(), + rand: $('#cv-captcha-rand').val(), + } }; if (isPhone($account.val())) { postData.phone = $account.val();