1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-25 04:07:17 +08:00

1.精简chapter/lessons.volt

2.使用ServiceTrait精简代码
This commit is contained in:
xiaochong0302 2023-12-27 16:05:23 +08:00
parent ce9f0eade0
commit 33fc75b9f8
10 changed files with 113 additions and 380 deletions

View File

@ -34,12 +34,6 @@ H5手机端演示
演示账号13507083515 / 123456 演示账号13507083515 / 123456
微信公众号演示:
![公众号二维码](https://portal-1255691183.file.myqcloud.com/img/content/616f998270eca.png)
演示账号13507083515 / 123456
支付流程演示: 支付流程演示:
- [MySQL提升课程全面讲解MySQL架构设计0.01元)](https://ctc.koogua.com/order/confirm?item_id=1390&item_type=1) - [MySQL提升课程全面讲解MySQL架构设计0.01元)](https://ctc.koogua.com/order/confirm?item_id=1390&item_type=1)

View File

@ -7,7 +7,11 @@
namespace App\Console\Migrations; namespace App\Console\Migrations;
use App\Traits\Service as ServiceTrait;
abstract class Migration abstract class Migration
{ {
use ServiceTrait;
abstract public function run(); abstract public function run();
} }

View File

@ -2,6 +2,40 @@
{% block content %} {% block content %}
{{ partial('macros/course') }}
{%- macro attrs_info(model,attrs) %}
{% if model == 1 %}
<span>类型:{{ model_type(model) }}</span>
{% if attrs['duration'] > 0 %}
<span>时长:{{ attrs['duration']|duration }}</span>
{% else %}
<span>时长N/A</span>
{% endif %}
{% elseif model == 2 %}
<span>类型:{{ model_type(model) }}</span>
{% if attrs['start_time'] > 0 %}
<span>时间:{{ date('Y-m-d H:i',attrs['start_time']) }}</span>
{% else %}
<span>时间N/A</span>
{% endif %}
{% elseif model == 3 %}
<span>类型:{{ model_type(model) }}</span>
{% if attrs['word_count'] > 0 %}
<span>字数:{{ attrs['word_count'] }}</span>
{% else %}
<span>字数N/A</span>
{% endif %}
{% elseif model == 4 %}
<span>类型:{{ model_type(model) }}</span>
{% if attrs['start_time'] > 0 %}
<span>时间:{{ date('Y-m-d H:i',attrs['start_time']) }}</span>
{% else %}
<span>时间N/A</span>
{% endif %}
{% endif %}
{%- endmacro %}
{% set back_url = url({'for':'admin.course.chapters','id':course.id}) %} {% set back_url = url({'for':'admin.course.chapters','id':course.id}) %}
{% set add_chapter_url = url({'for':'admin.chapter.add'},{'type':'chapter','course_id':course.id}) %} {% set add_chapter_url = url({'for':'admin.chapter.add'},{'type':'chapter','course_id':course.id}) %}
{% set add_lesson_url = url({'for':'admin.chapter.add'},{'type':'lesson','course_id':course.id,'parent_id':chapter.id}) %} {% set add_lesson_url = url({'for':'admin.chapter.add'},{'type':'lesson','course_id':course.id,'parent_id':chapter.id}) %}
@ -21,14 +55,75 @@
</div> </div>
</div> </div>
{% if course.model == 1 %} <table class="layui-table layui-form kg-table">
{{ partial('chapter/lessons_vod') }} <colgroup>
{% elseif course.model == 2 %} <col>
{{ partial('chapter/lessons_live') }} <col>
{% elseif course.model == 3 %} <col>
{{ partial('chapter/lessons_read') }} <col>
{% elseif course.model == 4 %} <col>
{{ partial('chapter/lessons_offline') }} <col>
{% endif %} <col>
<col width="10%">
</colgroup>
<thead>
<tr>
<th>名称</th>
<th>学员</th>
<th>点赞</th>
<th>评论</th>
<th>排序</th>
<th>免费</th>
<th>发布</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in lessons %}
{% set chapter_url = url({'for':'home.chapter.show','id':item.id}) %}
{% set edit_url = url({'for':'admin.chapter.edit','id':item.id}) %}
{% set update_url = url({'for':'admin.chapter.update','id':item.id}) %}
{% set delete_url = url({'for':'admin.chapter.delete','id':item.id}) %}
{% set restore_url = url({'for':'admin.chapter.restore','id':item.id}) %}
{% set comment_url = url({'for':'admin.comment.list'},{'item_id':item.id,'item_type':1}) %}
<tr>
<td>
<p>
<a href="{{ edit_url }}">{{ item.title }}</a>
<span>({{ item.id }})</span>
<span class="layui-badge layui-bg-green">课</span>
</p>
<p>{{ attrs_info(item.model,item.attrs) }}</p>
</td>
<td>{{ item.user_count }}</td>
<td>{{ item.like_count }}</td>
<td>{{ item.comment_count }}</td>
<td><input class="layui-input kg-priority" type="text" name="priority" title="数值越小排序越靠前" value="{{ item.priority }}" data-url="{{ update_url }}"></td>
<td><input type="checkbox" name="free" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}" {% if item.free == 1 %}checked="checked"{% endif %}>
</td>
<td><input type="checkbox" name="published" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.published == 1 %}checked="checked"{% endif %}></td>
<td class="center">
<div class="kg-dropdown">
<button class="layui-btn layui-btn-sm">操作 <i class="layui-icon layui-icon-triangle-d"></i></button>
<ul>
{% if item.published == 1 %}
<li><a href="{{ chapter_url }}" target="_blank">浏览</a></li>
{% endif %}
<li><a href="{{ edit_url }}">编辑</a></li>
{% if item.deleted == 0 %}
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除</a></li>
{% else %}
<li><a href="javascript:" class="kg-restore" data-url="{{ restore_url }}">还原</a></li>
{% endif %}
<hr>
<li><a href="javascript:" class="kg-comment" data-url="{{ comment_url }}">评论管理</a></li>
</ul>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %} {% endblock %}

View File

@ -1,88 +0,0 @@
{%- macro live_time_info(attrs) %}
{% if attrs['start_time'] > 0 %}
<p>开始:{{ date('Y-m-d H:i',attrs['start_time']) }}</p>
<p>结束:{{ date('Y-m-d H:i',attrs['end_time']) }}</p>
{% else %}
N/A
{% endif %}
{%- endmacro %}
{%- macro live_status_info(status) %}
{% if status == 'active' %}
<span class="layui-badge layui-bg-blue">活跃</span>
{% elseif status == 'inactive' %}
<span class="layui-badge layui-bg-gray">沉默</span>
{% elseif status == 'forbid' %}
<span class="layui-badge layui-bg-red">禁播</span>
{% endif %}
{%- endmacro %}
<table class="layui-table layui-form kg-table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col width="10%">
</colgroup>
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>学员</th>
<th>点赞</th>
<th>时间</th>
<th>推流</th>
<th>排序</th>
<th>免费</th>
<th>发布</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in lessons %}
{% set chapter_url = url({'for':'home.chapter.show','id':item.id}) %}
{% set edit_url = url({'for':'admin.chapter.edit','id':item.id}) %}
{% set update_url = url({'for':'admin.chapter.update','id':item.id}) %}
{% set delete_url = url({'for':'admin.chapter.delete','id':item.id}) %}
{% set restore_url = url({'for':'admin.chapter.restore','id':item.id}) %}
<tr>
<td>{{ item.id }}</td>
<td>
<a href="{{ edit_url }}">{{ item.title }}</a>
<span class="layui-badge layui-bg-green">课</span>
</td>
<td>{{ item.user_count }}</td>
<td>{{ item.like_count }}</td>
<td>{{ live_time_info(item.attrs) }}</td>
<td>{{ live_status_info(item.attrs['stream']['status']) }}</td>
<td><input class="layui-input kg-priority" type="text" name="priority" title="数值越小排序越靠前" value="{{ item.priority }}" data-url="{{ update_url }}"></td>
<td><input type="checkbox" name="free" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.free == 1 %}checked="checked"{% endif %}></td>
<td><input type="checkbox" name="published" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.published == 1 %}checked="checked"{% endif %}></td>
<td class="center">
<div class="kg-dropdown">
<button class="layui-btn layui-btn-sm">操作 <i class="layui-icon layui-icon-triangle-d"></i></button>
<ul>
{% if item.published == 1 %}
<li><a href="{{ chapter_url }}" target="_blank">浏览</a></li>
{% endif %}
<li><a href="{{ edit_url }}">编辑</a></li>
{% if item.deleted == 0 %}
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除</a></li>
{% else %}
<li><a href="javascript:" class="kg-restore" data-url="{{ delete_url }}">还原</a></li>
{% endif %}
</ul>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,65 +0,0 @@
{%- macro offline_time_info(attrs) %}
{% if attrs['start_time'] > 0 %}
<p>开始:{{ date('Y-m-d H:i',attrs['start_time']) }}</p>
<p>结束:{{ date('Y-m-d H:i',attrs['end_time']) }}</p>
{% else %}
N/A
{% endif %}
{%- endmacro %}
<table class="layui-table layui-form kg-table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col width="12%">
</colgroup>
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>时间</th>
<th>排序</th>
<th>免费</th>
<th>发布</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in lessons %}
{% set edit_url = url({'for':'admin.chapter.edit','id':item.id}) %}
{% set update_url = url({'for':'admin.chapter.update','id':item.id}) %}
{% set delete_url = url({'for':'admin.chapter.delete','id':item.id}) %}
{% set restore_url = url({'for':'admin.chapter.restore','id':item.id}) %}
<tr>
<td>{{ item.id }}</td>
<td>
<span><a href="{{ edit_url }}">{{ item.title }}</a></span>
<span class="layui-badge layui-bg-green">课</span>
</td>
<td>{{ offline_time_info(item.attrs) }}</td>
<td><input class="layui-input kg-priority" type="text" name="priority" title="数值越小排序越靠前" value="{{ item.priority }}" data-url="{{ update_url }}"></td>
<td><input type="checkbox" name="free" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.free == 1 %}checked="checked"{% endif %}></td>
<td><input type="checkbox" name="published" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.published == 1 %}checked="checked"{% endif %}></td>
<td class="center">
<div class="kg-dropdown">
<button class="layui-btn layui-btn-sm">操作 <i class="layui-icon layui-icon-triangle-d"></i></button>
<ul>
<li><a href="{{ edit_url }}">编辑</a></li>
{% if item.deleted == 0 %}
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除</a></li>
{% else %}
<li><a href="javascript:" class="kg-restore" data-url="{{ delete_url }}">还原</a></li>
{% endif %}
</ul>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,71 +0,0 @@
<table class="layui-table layui-form kg-table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col width="10%">
</colgroup>
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>学员</th>
<th>点赞</th>
<th>评论</th>
<th>排序</th>
<th>免费</th>
<th>发布</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in lessons %}
{% set chapter_url = url({'for':'home.chapter.show','id':item.id}) %}
{% set edit_url = url({'for':'admin.chapter.edit','id':item.id}) %}
{% set update_url = url({'for':'admin.chapter.update','id':item.id}) %}
{% set delete_url = url({'for':'admin.chapter.delete','id':item.id}) %}
{% set restore_url = url({'for':'admin.chapter.restore','id':item.id}) %}
{% set comments_url = url({'for':'admin.comment.list'},{'item_id':item.id,'item_type':1}) %}
<tr>
<td>{{ item.id }}</td>
<td>
<p>
<a href="{{ edit_url }}">{{ item.title }}</a>
<span class="layui-badge layui-bg-green">课</span>
</p>
</td>
<td>{{ item.user_count }}</td>
<td>{{ item.like_count }}</td>
<td>{{ item.comment_count }}</td>
<td><input class="layui-input kg-priority" type="text" name="priority" title="数值越小排序越靠前" value="{{ item.priority }}" data-url="{{ update_url }}"></td>
<td><input type="checkbox" name="free" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.free == 1 %}checked="checked"{% endif %}></td>
<td><input type="checkbox" name="published" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.published == 1 %}checked="checked"{% endif %}></td>
<td class="center">
<div class="kg-dropdown">
<button class="layui-btn layui-btn-sm">操作 <i class="layui-icon layui-icon-triangle-d"></i></button>
<ul>
{% if item.published == 1 %}
<li><a href="{{ chapter_url }}" target="_blank">浏览</a></li>
{% endif %}
<li><a href="{{ edit_url }}">编辑</a></li>
{% if item.deleted == 0 %}
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除</a></li>
{% else %}
<li><a href="javascript:" class="kg-restore" data-url="{{ restore_url }}">还原</a></li>
{% endif %}
<hr>
<li><a href="{{ comments_url }}">评论管理</a></li>
</ul>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,89 +0,0 @@
{%- macro file_status(value) %}
{% if value == 'pending' %}
待上传
{% elseif value == 'uploaded' %}
已上传
{% elseif value == 'translating' %}
转码中
{% elseif value == 'translated' %}
已转码
{% elseif value == 'failed' %}
已失败
{% endif %}
{%- endmacro %}
<table class="layui-table layui-form kg-table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col width="10%">
</colgroup>
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>学员</th>
<th>点赞</th>
<th>评论</th>
<th>排序</th>
<th>免费</th>
<th>发布</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in lessons %}
{% set chapter_url = url({'for':'home.chapter.show','id':item.id}) %}
{% set edit_url = url({'for':'admin.chapter.edit','id':item.id}) %}
{% set update_url = url({'for':'admin.chapter.update','id':item.id}) %}
{% set delete_url = url({'for':'admin.chapter.delete','id':item.id}) %}
{% set restore_url = url({'for':'admin.chapter.restore','id':item.id}) %}
{% set comments_url = url({'for':'admin.comment.list'},{'item_id':item.id,'item_type':1}) %}
<tr>
<td>{{ item.id }}</td>
<td>
<p>
<a href="{{ edit_url }}">{{ item.title }}</a>
<span class="layui-badge layui-bg-green">课</span>
</p>
<p class="meta">
<span>状态:{{ file_status(item.attrs['file']['status']) }}</span>
<span>时长:{{ item.attrs['duration']|duration }}</span>
</p>
</td>
<td>{{ item.user_count }}</td>
<td>{{ item.like_count }}</td>
<td>{{ item.comment_count }}</td>
<td><input class="layui-input kg-priority" type="text" name="priority" title="数值越小排序越靠前" value="{{ item.priority }}" data-url="{{ update_url }}"></td>
<td><input type="checkbox" name="free" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.free == 1 %}checked="checked"{% endif %}></td>
<td><input type="checkbox" name="published" value="1" lay-text="是|否" lay-skin="switch" lay-filter="go" data-url="{{ update_url }}"
{% if item.published == 1 %}checked="checked"{% endif %}></td>
<td class="center">
<div class="kg-dropdown">
<button class="layui-btn layui-btn-sm">操作 <i class="layui-icon layui-icon-triangle-d"></i></button>
<ul>
{% if item.published == 1 %}
<li><a href="{{ chapter_url }}" target="_blank">浏览</a></li>
{% endif %}
<li><a href="{{ edit_url }}">编辑</a></li>
{% if item.deleted == 0 %}
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除</a></li>
{% else %}
<li><a href="javascript:" class="kg-restore" data-url="{{ restore_url }}">还原</a></li>
{% endif %}
<hr>
<li><a href="{{ comments_url }}">评论管理</a></li>
</ul>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -11,7 +11,6 @@ use App\Models\User as UserModel;
use App\Services\Auth\Api as ApiAuth; use App\Services\Auth\Api as ApiAuth;
use App\Traits\Response as ResponseTrait; use App\Traits\Response as ResponseTrait;
use App\Traits\Security as SecurityTrait; use App\Traits\Security as SecurityTrait;
use App\Validators\Validator as AppValidator;
use Phalcon\Mvc\Dispatcher; use Phalcon\Mvc\Dispatcher;
class Controller extends \Phalcon\Mvc\Controller class Controller extends \Phalcon\Mvc\Controller
@ -31,10 +30,6 @@ class Controller extends \Phalcon\Mvc\Controller
$this->setCors(); $this->setCors();
} }
$validator = new AppValidator();
$validator->checkSiteStatus();
$this->checkRateLimit(); $this->checkRateLimit();
return true; return true;

View File

@ -8,50 +8,19 @@
namespace App\Listeners; namespace App\Listeners;
use App\Services\Service as AppService; use App\Services\Service as AppService;
use App\Traits\Auth as AuthTrait; use App\Traits\Service as ServiceTrait;
use Phalcon\Mvc\User\Plugin as UserPlugin; use Phalcon\Mvc\User\Plugin as UserPlugin;
class Listener extends UserPlugin class Listener extends UserPlugin
{ {
use AuthTrait; use ServiceTrait;
public function getConfig() public function getLogger($channel = 'listen')
{ {
$appService = new AppService(); $appService = new AppService();
return $appService->getConfig();
}
public function getCache()
{
$appService = new AppService();
return $appService->getCache();
}
public function getRedis()
{
$appService = new AppService();
return $appService->getRedis();
}
public function getLogger($channel = null)
{
$appService = new AppService();
$channel = $channel ?: 'listen';
return $appService->getLogger($channel); return $appService->getLogger($channel);
} }
public function getSettings($section)
{
$appService = new AppService();
return $appService->getSettings($section);
}
} }

View File

@ -8,25 +8,14 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\Forbidden as ForbiddenException; use App\Exceptions\Forbidden as ForbiddenException;
use App\Exceptions\ServiceUnavailable;
use App\Exceptions\ServiceUnavailable as ServiceUnavailableException;
use App\Exceptions\Unauthorized as UnauthorizedException; use App\Exceptions\Unauthorized as UnauthorizedException;
use App\Services\Service as AppService; use App\Traits\Service as ServiceTrait;
use Phalcon\Di\Injectable; use Phalcon\Di\Injectable;
class Validator extends Injectable class Validator extends Injectable
{ {
public function checkSiteStatus() use ServiceTrait;
{
$service = new AppService();
$siteInfo = $service->getSettings('site');
if ($siteInfo['status'] == 'closed') {
throw new ServiceUnavailableException('sys.service_unavailable');
}
}
public function checkAuthUser($userId) public function checkAuthUser($userId)
{ {