diff --git a/app/Console/Tasks/MaintainTask.php b/app/Console/Tasks/MaintainTask.php index 4b526448..f360db8f 100644 --- a/app/Console/Tasks/MaintainTask.php +++ b/app/Console/Tasks/MaintainTask.php @@ -5,10 +5,19 @@ namespace App\Console\Tasks; use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache; use App\Caches\IndexNewCourseList as IndexNewCourseListCache; use App\Caches\IndexVipCourseList as IndexVipCourseListCache; +use App\Http\Admin\Services\Setting as SettingService; +use App\Library\Utils\Password as PasswordUtil; +use App\Validators\Account as AccountValidator; class MaintainTask extends Task { + /** + * 重建首页课程缓存 + * + * @param array $params + * @command: php console.php maintain reset_index_course_cache + */ public function rebuildIndexCourseCacheAction($params) { $section = $params[0] ?? null; @@ -29,4 +38,63 @@ class MaintainTask extends Task } } + /** + * 修改密码 + * + * @param array $params + * @command: php console.php maintain reset_password 13507083515 123456 + */ + public function resetPasswordAction($params) + { + if (empty($params[0])) { + echo 'account is required' . PHP_EOL; + } + + if (empty($params[1])) { + echo 'password is required' . PHP_EOL; + } + + $validator = new AccountValidator(); + + $account = $validator->checkAccount($params[0]); + + $salt = PasswordUtil::salt(); + $hash = PasswordUtil::hash($params[1], $salt); + + $account->salt = $salt; + $account->password = $hash; + + $account->update(); + + echo 'reset password success' . PHP_EOL; + } + + /** + * 关闭验证码 + * + * @command: php console.php maintain disable_captcha + */ + public function disableCaptchaAction() + { + $service = new SettingService(); + + $service->updateSettings('captcha', ['enabled' => 0]); + + echo 'disable captcha success' . PHP_EOL; + } + + /** + * 启用验证码 + * + * @command: php console.php maintain enable_captcha + */ + public function enableCaptchaAction() + { + $service = new SettingService(); + + $service->updateSettings('captcha', ['enabled' => 1]); + + echo 'enable captcha success' . PHP_EOL; + } + } diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index c51e0c1d..0189960b 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -28,6 +28,8 @@ class VodEventTask extends Task $this->handleNewFileUploadEvent($event); } elseif ($event['EventType'] == 'ProcedureStateChanged') { $this->handleProcedureStateChangedEvent($event); + } elseif ($event['EventType'] == 'FileDeleted') { + $this->handleFileDeletedEvent($event); } $count++; @@ -123,6 +125,11 @@ class VodEventTask extends Task $chapter->update(['attrs' => $attrs]); } + protected function handleFileDeletedEvent($event) + { + + } + protected function pullEvents() { $vodService = new VodService(); diff --git a/app/Http/Admin/Services/ChapterContent.php b/app/Http/Admin/Services/ChapterContent.php index 665992bf..f02962d1 100644 --- a/app/Http/Admin/Services/ChapterContent.php +++ b/app/Http/Admin/Services/ChapterContent.php @@ -10,6 +10,7 @@ use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; use App\Services\ChapterVod as ChapterVodService; use App\Services\CourseStat as CourseStatService; +use App\Services\Vod as VodService; use App\Validators\ChapterLive as ChapterLiveValidator; use App\Validators\ChapterRead as ChapterReadValidator; use App\Validators\ChapterVod as ChapterVodValidator; @@ -100,9 +101,11 @@ class ChapterContent extends Service $chapter->update(['attrs' => $attrs]); - $courseStats = new CourseStatService(); + $this->updateCourseVodAttrs($vod->course_id); - $courseStats->updateVodAttrs($chapter->course_id); + if (!empty($vod->file_id)) { + $this->deleteVodFile($vod->file_id); + } } protected function updateChapterLive(ChapterModel $chapter) @@ -135,9 +138,7 @@ class ChapterContent extends Service $chapter->update(['attrs' => $attrs]); - $courseStats = new CourseStatService(); - - $courseStats->updateLiveAttrs($chapter->course_id); + $this->updateCourseLiveAttrs($live->course_id); } protected function updateChapterRead(ChapterModel $chapter) @@ -164,9 +165,35 @@ class ChapterContent extends Service $chapter->update(['attrs' => $attrs]); - $courseStats = new CourseStatService(); + $this->updateCourseReadAttrs($read->course_id); + } - $courseStats->updateReadAttrs($chapter->course_id); + protected function updateCourseVodAttrs($courseId) + { + $statService = new CourseStatService(); + + $statService->updateVodAttrs($courseId); + } + + protected function updateCourseLiveAttrs($courseId) + { + $statService = new CourseStatService(); + + $statService->updateLiveAttrs($courseId); + } + + protected function updateCourseReadAttrs($courseId) + { + $statService = new CourseStatService(); + + $statService->updateReadAttrs($courseId); + } + + protected function deleteVodFile($fileId) + { + $vodService = new VodService(); + + $vodService->deleteMedia($fileId); } protected function rebuildCatalogCache(ChapterModel $chapter) diff --git a/app/Http/Admin/Views/public/login.volt b/app/Http/Admin/Views/public/login.volt index d2afecea..9b51cbd7 100644 --- a/app/Http/Admin/Views/public/login.volt +++ b/app/Http/Admin/Views/public/login.volt @@ -2,6 +2,9 @@ {% block content %} + {% set disabled_submit = captcha.enabled == 1 ? 'disabled="disabled"' : '' %} + {% set disabled_class = captcha.enabled == 1 ? 'layui-btn-disabled' : '' %} +
管理登录
@@ -26,8 +29,8 @@ {% endif %}
- {% set disabled = captcha.enabled ? 'disabled="disabled"' : '' %} - + +
diff --git a/app/Http/Admin/Views/setting/vod.volt b/app/Http/Admin/Views/setting/vod.volt index fc8b7d55..9017d7a2 100644 --- a/app/Http/Admin/Views/setting/vod.volt +++ b/app/Http/Admin/Views/setting/vod.volt @@ -113,7 +113,7 @@
- +
diff --git a/app/Services/Live.php b/app/Services/Live.php index 539a24be..fc0f08ad 100644 --- a/app/Services/Live.php +++ b/app/Services/Live.php @@ -271,7 +271,7 @@ class Live extends Service return http_build_query([ 'txSecret' => $txSecret, - 'txTime' => $txTime + 'txTime' => $txTime, ]); } diff --git a/app/Services/Smser.php b/app/Services/Smser.php index 6a4d2efd..d0b26985 100644 --- a/app/Services/Smser.php +++ b/app/Services/Smser.php @@ -37,6 +37,8 @@ Abstract class Smser extends Service { $sender = $this->createSingleSender(); + $params = $this->formatParams($params); + $signature = $this->getSignature(); try { @@ -71,6 +73,17 @@ Abstract class Smser extends Service return new SmsSingleSender($this->settings['app_id'], $this->settings['app_key']); } + protected function formatParams($params) + { + if (!empty($params)) { + $params = array_map(function ($value) { + return strval($value); + }, $params); + } + + return $params; + } + protected function getTemplateId($code) { $template = json_decode($this->settings['template'], true); diff --git a/app/Services/Storage.php b/app/Services/Storage.php index 1f723851..cb7e4d31 100644 --- a/app/Services/Storage.php +++ b/app/Services/Storage.php @@ -173,7 +173,7 @@ class Storage extends Service */ protected function generateFileName($extension = '', $prefix = '') { - $randName = date('YmdHis') . rand(1000, 9999); + $randName = date('YmdHis') . rand(100, 999) . rand(100, 999); return $prefix . $randName . '.' . $extension; } diff --git a/app/Services/Vod.php b/app/Services/Vod.php index 82f50680..d30351bd 100644 --- a/app/Services/Vod.php +++ b/app/Services/Vod.php @@ -8,9 +8,10 @@ use TencentCloud\Common\Exception\TencentCloudSDKException; use TencentCloud\Common\Profile\ClientProfile; use TencentCloud\Common\Profile\HttpProfile; use TencentCloud\Vod\V20180717\Models\ConfirmEventsRequest; -use TencentCloud\Vod\V20180717\Models\DescribeAudioTrackTemplatesRequest; +use TencentCloud\Vod\V20180717\Models\DeleteMediaRequest; use TencentCloud\Vod\V20180717\Models\DescribeMediaInfosRequest; use TencentCloud\Vod\V20180717\Models\DescribeTaskDetailRequest; +use TencentCloud\Vod\V20180717\Models\DescribeTranscodeTemplatesRequest; use TencentCloud\Vod\V20180717\Models\ProcessMediaRequest; use TencentCloud\Vod\V20180717\Models\PullEventsRequest; use TencentCloud\Vod\V20180717\VodClient; @@ -53,21 +54,21 @@ class Vod extends Service { try { - $request = new DescribeAudioTrackTemplatesRequest(); + $request = new DescribeTranscodeTemplatesRequest(); $params = '{}'; $request->fromJsonString($params); - $response = $this->client->DescribeAudioTrackTemplates($request); + $response = $this->client->DescribeTranscodeTemplates($request); - $this->logger->debug('Describe Audio Track Templates Response ' . $response->toJsonString()); + $this->logger->debug('Describe Transcode Templates Response ' . $response->toJsonString()); $result = $response->TotalCount > 0; } catch (TencentCloudSDKException $e) { - $this->logger->error('Describe Audio Track Templates Exception ' . kg_json_encode([ + $this->logger->error('Describe Transcode Templates Exception ' . kg_json_encode([ 'code' => $e->getErrorCode(), 'message' => $e->getMessage(), 'requestId' => $e->getRequestId(), @@ -274,6 +275,44 @@ class Vod extends Service return $result; } + /** + * 删除媒体 + * + * @param string $fileId + * @return bool + */ + public function deleteMedia($fileId) + { + try { + + $request = new DeleteMediaRequest(); + + $params = json_encode(['FileId' => $fileId]); + + $request->fromJsonString($params); + + $this->logger->debug('Delete Media Request ' . $params); + + $response = $this->client->DeleteMedia($request); + + $this->logger->debug('Delete Media Response ' . $response->toJsonString()); + + $result = !empty($response->RequestId); + + } catch (TencentCloudSDKException $e) { + + $this->logger->error('Delete Media Exception ' . kg_json_encode([ + 'code' => $e->getErrorCode(), + 'message' => $e->getMessage(), + 'requestId' => $e->getRequestId(), + ])); + + $result = false; + } + + return $result; + } + /** * 获取媒体信息 * @@ -574,7 +613,7 @@ class Vod extends Service { $result = null; - if ($this->settings['wmk_enabled'] && $this->settings['wmk_tpl_id'] > 0) { + if ($this->settings['wmk_enabled'] == 1 && $this->settings['wmk_tpl_id'] > 0) { $result = (int)$this->settings['wmk_tpl_id']; } diff --git a/bootstrap/ConsoleErrorHandler.php b/bootstrap/ConsoleErrorHandler.php index 3ad28acd..45060b2c 100644 --- a/bootstrap/ConsoleErrorHandler.php +++ b/bootstrap/ConsoleErrorHandler.php @@ -27,17 +27,13 @@ class ConsoleErrorHandler extends Component */ public function handleException($e) { - $config = $this->getConfig(); - $logger = $this->getLogger(); $content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage()); $logger->error($content); - if ($config->get('env') == ENV_DEV) { - echo $content; - } + echo $content . PHP_EOL; } /** diff --git a/db/migrations/20200827063842_init_table.php b/db/migrations/20200827063842_init_table.php index 5547e5b3..f11f2b42 100644 --- a/db/migrations/20200827063842_init_table.php +++ b/db/migrations/20200827063842_init_table.php @@ -3668,10 +3668,6 @@ class InitTable extends Phinx\Migration\AbstractMigration 'limit' => MysqlAdapter::INT_REGULAR, 'after' => 'create_time', ]) - ->addIndex(['item_type', 'status'], [ - 'name' => 'type_status', - 'unique' => false, - ]) ->create(); $this->table('kg_topic', [ 'id' => false, diff --git a/db/migrations/schema.php b/db/migrations/schema.php index adbdfff9..b43fdd28 100644 --- a/db/migrations/schema.php +++ b/db/migrations/schema.php @@ -12983,39 +12983,6 @@ return array( 'Index_comment' => '', ), ), - 'type_status' => - array( - 1 => - array( - 'Table' => 'kg_task', - 'Non_unique' => '1', - 'Key_name' => 'type_status', - 'Seq_in_index' => '1', - 'Column_name' => 'item_type', - 'Collation' => 'A', - 'Sub_part' => NULL, - 'Packed' => NULL, - 'Null' => '', - 'Index_type' => 'BTREE', - 'Comment' => '', - 'Index_comment' => '', - ), - 2 => - array( - 'Table' => 'kg_task', - 'Non_unique' => '1', - 'Key_name' => 'type_status', - 'Seq_in_index' => '2', - 'Column_name' => 'status', - 'Collation' => 'A', - 'Sub_part' => NULL, - 'Packed' => NULL, - 'Null' => '', - 'Index_type' => 'BTREE', - 'Comment' => '', - 'Index_comment' => '', - ), - ), ), 'foreign_keys' => NULL, ),