From 3ce6897de1e87cfc5570534696d7fa5c3bb9afa7 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Wed, 11 Nov 2020 20:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=82=B9=E6=92=AD=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Logic/Chapter/Learning.php | 4 ++-- app/Services/Logic/Teacher/CourseList.php | 2 +- app/Services/Sync/Learning.php | 8 ++++---- app/Validators/Learning.php | 6 +++--- app/Validators/Refund.php | 7 ++++++- config/errors.php | 2 +- public/static/home/js/chapter.live.player.js | 9 ++------- public/static/home/js/chapter.vod.player.js | 6 ++---- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/Services/Logic/Chapter/Learning.php b/app/Services/Logic/Chapter/Learning.php index 7b08b06d..25fb9f09 100644 --- a/app/Services/Logic/Chapter/Learning.php +++ b/app/Services/Logic/Chapter/Learning.php @@ -38,13 +38,13 @@ class Learning extends Service $data['position'] = $validator->checkPosition($post['position']); } - $interval = $validator->checkInterval($post['interval']); + $intervalTime = $validator->checkIntervalTime($post['interval_time']); $learning = new LearningModel($data); $sync = new LearningSyncService(); - $sync->addItem($learning, $interval); + $sync->addItem($learning, $intervalTime); } } \ No newline at end of file diff --git a/app/Services/Logic/Teacher/CourseList.php b/app/Services/Logic/Teacher/CourseList.php index 80e5c181..76079073 100644 --- a/app/Services/Logic/Teacher/CourseList.php +++ b/app/Services/Logic/Teacher/CourseList.php @@ -49,7 +49,7 @@ class CourseList extends Service $courses = $builder->getCourses($relations); - $pager->items = $courses; + $pager->items = array_values($courses); return $pager; } diff --git a/app/Services/Sync/Learning.php b/app/Services/Sync/Learning.php index fb5a3576..fe5ba353 100644 --- a/app/Services/Sync/Learning.php +++ b/app/Services/Sync/Learning.php @@ -18,9 +18,9 @@ class Learning extends Service /** * @param LearningModel $learning - * @param int $interval + * @param int $intervalTime */ - public function addItem(LearningModel $learning, $interval = 10) + public function addItem(LearningModel $learning, $intervalTime = 10) { $cache = $this->getCache(); @@ -37,14 +37,14 @@ class Learning extends Service $learning->client_type = $this->getClientType(); $learning->client_ip = $this->getClientIp(); - $learning->duration = $interval; + $learning->duration = $intervalTime; $learning->active_time = time(); $cache->save($itemKey, $learning, $this->lifetime); } else { - $cacheLearning->duration += $interval; + $cacheLearning->duration += $intervalTime; $cacheLearning->position = $learning->position; $cacheLearning->active_time = time(); diff --git a/app/Validators/Learning.php b/app/Validators/Learning.php index 97365394..aa539a1e 100644 --- a/app/Validators/Learning.php +++ b/app/Validators/Learning.php @@ -26,9 +26,9 @@ class Learning extends Validator return $requestId; } - public function checkInterval($interval) + public function checkIntervalTime($intervalTime) { - $value = $this->filter->sanitize($interval, ['trim', 'int']); + $value = $this->filter->sanitize($intervalTime, ['trim', 'int']); /** * 兼容秒和毫秒 @@ -38,7 +38,7 @@ class Learning extends Validator } if ($value < 5) { - throw new BadRequestException('learning.invalid_interval'); + throw new BadRequestException('learning.invalid_interval_time'); } return $value; diff --git a/app/Validators/Refund.php b/app/Validators/Refund.php index 70cf91b5..1b309b91 100644 --- a/app/Validators/Refund.php +++ b/app/Validators/Refund.php @@ -108,7 +108,12 @@ class Refund extends Validator public function checkIfAllowCancel(RefundModel $refund) { - if ($refund->status != RefundModel::STATUS_PENDING) { + $scopes = [ + RefundModel::STATUS_PENDING, + RefundModel::STATUS_APPROVED, + ]; + + if (!in_array($refund->status, $scopes)) { throw new BadRequestException('refund.cancel_not_allowed'); } } diff --git a/config/errors.php b/config/errors.php index 94e90723..4ccb1907 100644 --- a/config/errors.php +++ b/config/errors.php @@ -321,8 +321,8 @@ $error['course_query.invalid_sort'] = '无效的排序类别'; */ $error['learning.invalid_plan_id'] = '无效的计划编号'; $error['learning.invalid_request_id'] = '无效的请求编号'; +$error['learning.invalid_interval_time'] = '无效的间隔时间'; $error['learning.invalid_position'] = '无效的播放位置'; -$error['learning.invalid_interval'] = '无效的间隔时间'; /** * 即时通讯 diff --git a/public/static/home/js/chapter.live.player.js b/public/static/home/js/chapter.live.player.js index 87c2bb84..915c50fa 100644 --- a/public/static/home/js/chapter.live.player.js +++ b/public/static/home/js/chapter.live.player.js @@ -6,7 +6,6 @@ layui.use(['jquery', 'helper'], function () { var interval = null; var intervalTime = 15000; var userId = window.user.id; - var chapterId = $('input[name="chapter.id"]').val(); var planId = $('input[name="chapter.plan_id"]').val(); var learningUrl = $('input[name="chapter.learning_url"]').val(); var playUrls = JSON.parse($('input[name="chapter.play_urls"]').val()); @@ -17,7 +16,7 @@ layui.use(['jquery', 'helper'], function () { autoplay: true, h5_flv: true, width: 760, - height: 428 + height: 428, }; var formats = ['rtmp', 'flv', 'm3u8']; @@ -32,14 +31,12 @@ layui.use(['jquery', 'helper'], function () { }); }); - console.log(options); - options.listener = function (msg) { if (msg.type === 'play') { start(); } else if (msg.type === 'pause') { stop(); - } else if (msg.type === 'end') { + } else if (msg.type === 'ended') { stop(); } }; @@ -68,10 +65,8 @@ layui.use(['jquery', 'helper'], function () { url: learningUrl, data: { plan_id: planId, - chapter_id: chapterId, request_id: requestId, interval: intervalTime, - position: player.currentTime(), } }); } diff --git a/public/static/home/js/chapter.vod.player.js b/public/static/home/js/chapter.vod.player.js index 03dadd7a..628b9067 100644 --- a/public/static/home/js/chapter.vod.player.js +++ b/public/static/home/js/chapter.vod.player.js @@ -7,7 +7,6 @@ layui.use(['jquery', 'helper'], function () { var intervalTime = 15000; var userId = window.user.id; var requestId = helper.getRequestId(); - var chapterId = $('input[name="chapter.id"]').val(); var planId = $('input[name="chapter.plan_id"]').val(); var lastPosition = $('input[name="chapter.position"]').val(); var learningUrl = $('input[name="chapter.learning_url"]').val(); @@ -16,7 +15,7 @@ layui.use(['jquery', 'helper'], function () { var options = { autoplay: false, width: 760, - height: 428 + height: 428, }; if (playUrls.hasOwnProperty('od')) { @@ -84,10 +83,9 @@ layui.use(['jquery', 'helper'], function () { url: learningUrl, data: { plan_id: planId, - chapter_id: chapterId, request_id: requestId, interval: intervalTime, - position: player.currentTime() + position: player.currentTime(), } }); }