1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-28 21:31:37 +08:00

!1 精简优化代码

* 优化代码
* 重新提交LICENSE
* 测试前台支付,增加若干命令行快捷方法
* 删除文件 LICENSE
This commit is contained in:
koogua 2020-09-26 18:59:02 +08:00
parent 46d1c35d21
commit 6679214808
46 changed files with 237 additions and 180 deletions

View File

@ -29,7 +29,7 @@
#### 使用协议 #### 使用协议
虽然尝试了解过开源协议,但是理解的模棱两可,干脆用自己的协议吧,算不算开源我也不很清楚 虽然尝试了解过开源协议,但是理解的模棱两可,干脆用自己的协议吧。
1. 本系统属于强业务类型,非通用类库框架,不适合再次衍生发布。 1. 本系统属于强业务类型,非通用类库框架,不适合再次衍生发布。
2. 在保留我们版权标识的前提下,用户可以修改以满足自己的需求,可以用于商业用途。 2. 在保留我们版权标识的前提下,用户可以修改以满足自己的需求,可以用于商业用途。
@ -74,7 +74,7 @@
#### 有商业服务吗? #### 有商业服务吗?
生存是一个问题,生存才能发展,我们为用户提供的服务包括: 生存才能发展,我们目前提供的服务包括:
- 系统安装 - 系统安装
- 系统定制 - 系统定制

View File

@ -12,8 +12,6 @@ class SyncCourseIndexTask extends Task
public function mainAction() public function mainAction()
{ {
$cache = $this->getCache();
$redis = $this->getRedis(); $redis = $this->getRedis();
$key = $this->getSyncKey(); $key = $this->getSyncKey();

View File

@ -12,8 +12,6 @@ class SyncGroupIndexTask extends Task
public function mainAction() public function mainAction()
{ {
$cache = $this->getCache();
$redis = $this->getRedis(); $redis = $this->getRedis();
$key = $this->getSyncKey(); $key = $this->getSyncKey();

View File

@ -16,8 +16,6 @@ class SyncLearningTask extends Task
public function mainAction() public function mainAction()
{ {
$cache = $this->getCache();
$redis = $this->getRedis(); $redis = $this->getRedis();
$sync = new LearningSync(); $sync = new LearningSync();

View File

@ -12,8 +12,6 @@ class SyncUserIndexTask extends Task
public function mainAction() public function mainAction()
{ {
$cache = $this->getCache();
$redis = $this->getRedis(); $redis = $this->getRedis();
$key = $this->getSyncKey(); $key = $this->getSyncKey();

View File

@ -43,7 +43,7 @@ class UpgradeTask extends Task
public function resetAnnotationAction() public function resetAnnotationAction()
{ {
$config = $this->getConfig(); $config = $this->getConfig();
$cache = $this->getCache();
$redis = $this->getRedis(); $redis = $this->getRedis();
$dbIndex = $config->path('annotation.db'); $dbIndex = $config->path('annotation.db');
@ -74,7 +74,7 @@ class UpgradeTask extends Task
public function resetMetadataAction() public function resetMetadataAction()
{ {
$config = $this->getConfig(); $config = $this->getConfig();
$cache = $this->getCache();
$redis = $this->getRedis(); $redis = $this->getRedis();
$dbIndex = $config->path('metadata.db'); $dbIndex = $config->path('metadata.db');

View File

@ -14,9 +14,18 @@ class WxpayTest extends PayTest
{ {
$wxpayService = new WxpayService(); $wxpayService = new WxpayService();
$qrcode = $wxpayService->scan($trade); $code = $wxpayService->scan($trade);
return $qrcode ?: false; $codeUrl = null;
if ($code) {
$codeUrl = $this->url->get(
['for' => 'home.qrcode'],
['text' => urlencode($code)]
);
}
return $codeUrl ?: false;
} }
public function status($tradeNo) public function status($tradeNo)

View File

@ -11,7 +11,7 @@
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="model" value="1" title="点播" lay-filter="model" checked="checked"> <input type="radio" name="model" value="1" title="点播" lay-filter="model" checked="checked">
<input type="radio" name="model" value="2" title="直播" lay-filter="model"> <input type="radio" name="model" value="2" title="直播" lay-filter="model">
<input type="radio" name="model" value="3" title="图文" lay-filter="model"> <input type="radio" name="model" value="3" title="专栏" lay-filter="model">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">

View File

@ -8,7 +8,7 @@
{% elseif value == 2 %} {% elseif value == 2 %}
<span class="layui-badge layui-bg-blue">直播</span> <span class="layui-badge layui-bg-blue">直播</span>
{% elseif value == 3 %} {% elseif value == 3 %}
<span class="layui-badge layui-bg-black">图文</span> <span class="layui-badge layui-bg-black">专栏</span>
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}

View File

@ -35,7 +35,7 @@
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="model" value="1" title="点播"> <input type="radio" name="model" value="1" title="点播">
<input type="radio" name="model" value="2" title="直播"> <input type="radio" name="model" value="2" title="直播">
<input type="radio" name="model" value="3" title="图文"> <input type="radio" name="model" value="3" title="专栏">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">

View File

@ -19,7 +19,7 @@
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">API密钥</label> <label class="layui-form-label">API Key</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="key" value="{{ wxpay.key }}" lay-verify="required"> <input class="layui-input" type="text" name="key" value="{{ wxpay.key }}" lay-verify="required">
</div> </div>

View File

@ -3,7 +3,6 @@
namespace App\Http\Home\Controllers; namespace App\Http\Home\Controllers;
use App\Caches\NavTreeList as NavCache; use App\Caches\NavTreeList as NavCache;
use App\Caches\Setting as SettingCache;
use App\Library\AppInfo as AppInfo; use App\Library\AppInfo as AppInfo;
use App\Library\Seo as Seo; use App\Library\Seo as Seo;
use App\Models\User as UserModel; use App\Models\User as UserModel;
@ -116,9 +115,7 @@ class Controller extends \Phalcon\Mvc\Controller
protected function getSiteInfo() protected function getSiteInfo()
{ {
$appService = new AppService(); return $this->getSettings('site');
return $appService->getSettings('site');
} }
protected function getAppInfo() protected function getAppInfo()
@ -128,8 +125,6 @@ class Controller extends \Phalcon\Mvc\Controller
protected function getImInfo() protected function getImInfo()
{ {
$cache = new SettingCache();
$websocket = $this->getConfig()->get('websocket'); $websocket = $this->getConfig()->get('websocket');
/** /**
@ -142,8 +137,8 @@ class Controller extends \Phalcon\Mvc\Controller
} }
return [ return [
'main' => $cache->get('im.main'), 'main' => $this->getSettings('im.main'),
'cs' => $cache->get('im.cs'), 'cs' => $this->getSettings('im.cs'),
'ws' => $websocket, 'ws' => $websocket,
]; ];
} }
@ -155,4 +150,11 @@ class Controller extends \Phalcon\Mvc\Controller
return $appService->getConfig(); return $appService->getConfig();
} }
protected function getSettings($section)
{
$appService = new AppService();
return $appService->getSettings($section);
}
} }

View File

@ -67,7 +67,10 @@ class OrderController extends Controller
$order = $service->handle(); $order = $service->handle();
$location = $this->url->get(['for' => 'home.order.pay'], ['sn' => $order->sn]); $location = $this->url->get(
['for' => 'home.order.pay'],
['sn' => $order->sn]
);
return $this->jsonSuccess(['location' => $location]); return $this->jsonSuccess(['location' => $location]);
} }

View File

@ -72,9 +72,20 @@ class Trade extends Service
protected function getWxpayQrCode(TradeModel $trade) protected function getWxpayQrCode(TradeModel $trade)
{ {
$qrCode = null;
$service = new WxpayService(); $service = new WxpayService();
return $service->scan($trade); $text = $service->scan($trade);
if ($text) {
$qrCode = $this->url->get(
['for' => 'home.qrcode'],
['text' => urlencode($text)]
);
}
return $qrCode;
} }
} }

View File

@ -21,10 +21,10 @@
</table> </table>
<br> <br>
<div class="center"> <div class="center">
{% if order.status == 'pending' %} {% if order.status == 1 %}
<a class="layui-btn layui-bg-blue" href="{{ order_pay_url }}" target="_top">立即支付</a> <a class="layui-btn layui-bg-blue" href="{{ order_pay_url }}" target="_top">立即支付</a>
{% endif %} {% endif %}
{% if (order.item_type in ['course','package']) and (order.status == 'finished') %} {% if (order.item_type in [1,2]) and (order.status == 3) %}
<a class="layui-btn layui-bg-blue" href="{{ refund_confirm_url }}">申请退款</a> <a class="layui-btn layui-bg-blue" href="{{ refund_confirm_url }}">申请退款</a>
{% endif %} {% endif %}
</div> </div>

View File

@ -2,6 +2,9 @@
{% block content %} {% block content %}
{% set create_url = url({'for':'home.trade.create'}) %}
{% set status_url = url({'for':'home.trade.status'}) %}
<div class="layui-breadcrumb breadcrumb"> <div class="layui-breadcrumb breadcrumb">
<a href="/">首页</a> <a href="/">首页</a>
<a><cite>支付订单</cite></a> <a><cite>支付订单</cite></a>
@ -14,10 +17,8 @@
支付金额:<span class="amount">{{ '¥%0.2f'|format(order.amount) }}</span> 支付金额:<span class="amount">{{ '¥%0.2f'|format(order.amount) }}</span>
</div> </div>
<div class="channel"> <div class="channel">
{% set create_url = url({'for':'home.trade.create'}) %} <a class="alipay btn-pay" href="javascript:" data-channel="alipay">{{ image('home/img/alipay.png') }}</a>
{% set status_url = url({'for':'home.trade.status'}) %} <a class="wxpay btn-pay" href="javascript:" data-channel="wxpay">{{ image('home/img/wxpay.png') }}</a>
<a class="alipay btn-pay" href="javascript:" data-channel="1"></a>
<a class="wxpay btn-pay" href="javascript:" data-channel="2"></a>
</div> </div>
<div class="footer"> <div class="footer">
<span class="tips">友情提示请在12小时内完成支付有问题请联系客服</span> <span class="tips">友情提示请在12小时内完成支付有问题请联系客服</span>

View File

@ -27,7 +27,7 @@
<a href="javascript:" class="nav-search" data-type="{{ s_type }}" data-query="{{ s_query }}" data-url="{{ s_url }}"><i class="layui-icon layui-icon-search"></i> 搜索</a> <a href="javascript:" class="nav-search" data-type="{{ s_type }}" data-query="{{ s_query }}" data-url="{{ s_url }}"><i class="layui-icon layui-icon-search"></i> 搜索</a>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item">
<a href="{{ url({'for':'home.vip.index'}) }}" class="nav-vip" target="vip"><i class="layui-icon layui-icon-diamond"></i> 会员</a> <a href="{{ url({'for':'home.vip.index'}) }}" class="nav-vip"><i class="layui-icon layui-icon-diamond"></i> 会员</a>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item">
<a href="{{ url({'for':'home.im.index'}) }}" class="nav-im" target="im"><i class="layui-icon layui-icon-chat"></i> 微聊</a> <a href="{{ url({'for':'home.im.index'}) }}" class="nav-im" target="im"><i class="layui-icon layui-icon-chat"></i> 微聊</a>

View File

@ -7,7 +7,7 @@
{% set status_types = {'all':'全部','pending':'待回复','replied':'已回复'} %} {% set status_types = {'all':'全部','pending':'待回复','replied':'已回复'} %}
{% set status = request.get('status','trim','all') %} {% set status = request.get('status','trim','all') %}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('teacher/console/menu') }}</div> <div class="my-sidebar">{{ partial('teacher/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -4,7 +4,7 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('teacher/console/menu') }}</div> <div class="my-sidebar">{{ partial('teacher/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -4,7 +4,7 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('teacher/console/menu') }}</div> <div class="my-sidebar">{{ partial('teacher/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -6,7 +6,7 @@
{% set edit_phone_url = url({'for':'home.account.edit_phone'}) %} {% set edit_phone_url = url({'for':'home.account.edit_phone'}) %}
{% set edit_email_url = url({'for':'home.account.edit_email'}) %} {% set edit_email_url = url({'for':'home.account.edit_email'}) %}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -4,7 +4,7 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -4,7 +4,7 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -4,7 +4,7 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -4,7 +4,7 @@
{{ partial('macros/user') }} {{ partial('macros/user') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -9,7 +9,7 @@
{% set joined_class = scope == 'joined' ? 'layui-btn layui-btn-xs' : 'none' %} {% set joined_class = scope == 'joined' ? 'layui-btn layui-btn-xs' : 'none' %}
{% set owned_class = scope == 'owned' ? 'layui-btn layui-btn-xs' : 'none' %} {% set owned_class = scope == 'owned' ? 'layui-btn layui-btn-xs' : 'none' %}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="my-nav"> <div class="my-nav">

View File

@ -7,7 +7,7 @@
{% set status_types = {'0':'全部','1':'待支付','3':'已完成','4':'已关闭','5':'已退款'} %} {% set status_types = {'0':'全部','1':'待支付','3':'已完成','4':'已关闭','5':'已退款'} %}
{% set status = request.get('status','trim','0') %} {% set status = request.get('status','trim','0') %}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="my-nav"> <div class="my-nav">

View File

@ -7,7 +7,7 @@
{% set gender_female_checked = user.gender == 2 ? 'checked' : '' %} {% set gender_female_checked = user.gender == 2 ? 'checked' : '' %}
{% set gender_none_checked = user.gender == 3 ? 'checked' : '' %} {% set gender_none_checked = user.gender == 3 ? 'checked' : '' %}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -7,7 +7,7 @@
{% set status_types = {'0':'全部','1':'待处理','2':'已取消','3':'退款中','5':'已完成'} %} {% set status_types = {'0':'全部','1':'待处理','2':'已取消','3':'退款中','5':'已完成'} %}
{% set status = request.get('status','int','0') %} {% set status = request.get('status','int','0') %}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="my-nav"> <div class="my-nav">

View File

@ -4,7 +4,7 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
<div class="layout-main"> <div class="layout-main clearfix">
<div class="my-sidebar">{{ partial('user/console/menu') }}</div> <div class="my-sidebar">{{ partial('user/console/menu') }}</div>
<div class="my-content"> <div class="my-content">
<div class="wrap"> <div class="wrap">

View File

@ -71,6 +71,11 @@ class Audit extends Model
$this->create_time = time(); $this->create_time = time();
if (is_array($this->req_data) && !empty($this->req_data)) { if (is_array($this->req_data) && !empty($this->req_data)) {
foreach ($this->req_data as $key => $value) {
if (kg_strlen($value) > 255) {
$this->req_data[$key] = kg_substr($value, 0, 255);
}
}
$this->req_data = kg_json_encode($this->req_data); $this->req_data = kg_json_encode($this->req_data);
} else { } else {
$this->req_data = ''; $this->req_data = '';

View File

@ -367,7 +367,7 @@ class Course extends Model
return [ return [
self::MODEL_VOD => '点播', self::MODEL_VOD => '点播',
self::MODEL_LIVE => '直播', self::MODEL_LIVE => '直播',
self::MODEL_READ => '图文', self::MODEL_READ => '专栏',
]; ];
} }

View File

@ -2,6 +2,8 @@
namespace App\Providers; namespace App\Providers;
use Phalcon\Http\Response\Cookies as PhCookies;
class Cookie extends Provider class Cookie extends Provider
{ {
@ -11,6 +13,11 @@ class Cookie extends Provider
{ {
$this->di->setShared($this->serviceName, function () { $this->di->setShared($this->serviceName, function () {
$cookies = new PhCookies();
$cookies->useEncryption(true);
return $cookies;
}); });
} }

View File

@ -2,7 +2,7 @@
namespace App\Providers; namespace App\Providers;
use Phalcon\Escaper as PhalconEscaper; use Phalcon\Escaper as PhEscaper;
class Escaper extends Provider class Escaper extends Provider
{ {
@ -11,7 +11,7 @@ class Escaper extends Provider
public function register() public function register()
{ {
$this->di->setShared($this->serviceName, PhalconEscaper::class); $this->di->setShared($this->serviceName, PhEscaper::class);
} }
} }

View File

@ -87,6 +87,7 @@ class Alipay extends PayService
/** /**
* 异步通知 * 异步通知
*
* @return Response|bool * @return Response|bool
*/ */
public function notify() public function notify()

View File

@ -18,18 +18,7 @@ class Category extends Validator
*/ */
public function checkCategoryCache($id) public function checkCategoryCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxCategoryIdCache = new MaxCategoryIdCache();
$maxCategoryId = $maxCategoryIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxCategoryId) {
throw new BadRequestException('category.not_found');
}
$categoryCache = new CategoryCache(); $categoryCache = new CategoryCache();
@ -44,6 +33,8 @@ class Category extends Validator
public function checkCategory($id) public function checkCategory($id)
{ {
$this->checkId($id);
$categoryRepo = new CategoryRepo(); $categoryRepo = new CategoryRepo();
$category = $categoryRepo->findById($id); $category = $categoryRepo->findById($id);
@ -55,6 +46,19 @@ class Category extends Validator
return $category; return $category;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxCategoryIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('category.not_found');
}
}
public function checkParent($id) public function checkParent($id)
{ {
$categoryRepo = new CategoryRepo(); $categoryRepo = new CategoryRepo();

View File

@ -19,18 +19,7 @@ class Chapter extends Validator
*/ */
public function checkChapterCache($id) public function checkChapterCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxChapterIdCache = new MaxChapterIdCache();
$maxChapterId = $maxChapterIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxChapterId) {
throw new BadRequestException('chapter.not_found');
}
$chapterCache = new ChapterCache(); $chapterCache = new ChapterCache();
@ -45,6 +34,8 @@ class Chapter extends Validator
public function checkChapterVod($id) public function checkChapterVod($id)
{ {
$this->checkId($id);
$chapterRepo = new ChapterRepo(); $chapterRepo = new ChapterRepo();
$chapterVod = $chapterRepo->findChapterVod($id); $chapterVod = $chapterRepo->findChapterVod($id);
@ -58,6 +49,8 @@ class Chapter extends Validator
public function checkChapterLive($id) public function checkChapterLive($id)
{ {
$this->checkId($id);
$chapterRepo = new ChapterRepo(); $chapterRepo = new ChapterRepo();
$chapterLive = $chapterRepo->findChapterLive($id); $chapterLive = $chapterRepo->findChapterLive($id);
@ -71,6 +64,8 @@ class Chapter extends Validator
public function checkChapterRead($id) public function checkChapterRead($id)
{ {
$this->checkId($id);
$chapterRepo = new ChapterRepo(); $chapterRepo = new ChapterRepo();
$chapterRead = $chapterRepo->findChapterRead($id); $chapterRead = $chapterRepo->findChapterRead($id);
@ -84,6 +79,8 @@ class Chapter extends Validator
public function checkChapter($id) public function checkChapter($id)
{ {
$this->checkId($id);
$chapterRepo = new ChapterRepo(); $chapterRepo = new ChapterRepo();
$chapter = $chapterRepo->findById($id); $chapter = $chapterRepo->findById($id);
@ -95,6 +92,19 @@ class Chapter extends Validator
return $chapter; return $chapter;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxChapterIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('chapter.not_found');
}
}
public function checkCourse($id) public function checkCourse($id)
{ {
$validator = new Course(); $validator = new Course();

View File

@ -19,18 +19,7 @@ class Course extends Validator
*/ */
public function checkCourseCache($id) public function checkCourseCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxCache = new MaxCourseIdCache();
$maxId = $maxCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('course.not_found');
}
$courseCache = new CourseCache(); $courseCache = new CourseCache();
@ -45,6 +34,8 @@ class Course extends Validator
public function checkCourse($id) public function checkCourse($id)
{ {
$this->checkId($id);
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();
$course = $courseRepo->findById($id); $course = $courseRepo->findById($id);
@ -56,6 +47,19 @@ class Course extends Validator
return $course; return $course;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxCourseIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('course.not_found');
}
}
public function checkModel($model) public function checkModel($model)
{ {
$list = CourseModel::modelTypes(); $list = CourseModel::modelTypes();

View File

@ -18,18 +18,7 @@ class Help extends Validator
*/ */
public function checkHelpCache($id) public function checkHelpCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxHelpIdCache = new MaxHelpIdCache();
$maxHelpId = $maxHelpIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxHelpId) {
throw new BadRequestException('help.not_found');
}
$helpCache = new HelpCache(); $helpCache = new HelpCache();
@ -55,6 +44,19 @@ class Help extends Validator
return $help; return $help;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxHelpIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('help.not_found');
}
}
public function checkCategory($id) public function checkCategory($id)
{ {
$validator = new Category(); $validator = new Category();

View File

@ -19,18 +19,7 @@ class ImGroup extends Validator
*/ */
public function checkGroupCache($id) public function checkGroupCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxGroupIdCache = new MaxImGroupIdCache();
$maxGroupId = $maxGroupIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxGroupId) {
throw new BadRequestException('im_group.not_found');
}
$groupCache = new ImGroupCache(); $groupCache = new ImGroupCache();
@ -45,6 +34,8 @@ class ImGroup extends Validator
public function checkGroup($id) public function checkGroup($id)
{ {
$this->checkId($id);
$groupRepo = new ImGroupRepo(); $groupRepo = new ImGroupRepo();
$group = $groupRepo->findById($id); $group = $groupRepo->findById($id);
@ -56,6 +47,19 @@ class ImGroup extends Validator
return $group; return $group;
} }
public function checkId($id)
{
$id = intval($id);
$maxGroupIdCache = new MaxImGroupIdCache();
$maxId = $maxGroupIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('im_group.not_found');
}
}
public function checkName($name) public function checkName($name)
{ {
$value = $this->filter->sanitize($name, ['trim', 'string']); $value = $this->filter->sanitize($name, ['trim', 'string']);

View File

@ -18,18 +18,7 @@ class Package extends Validator
*/ */
public function checkPackageCache($id) public function checkPackageCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxPackageIdCache = new MaxPackageIdCache();
$maxPackageId = $maxPackageIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxPackageId) {
throw new BadRequestException('package.not_found');
}
$packageCache = new PackageCache(); $packageCache = new PackageCache();
@ -44,6 +33,8 @@ class Package extends Validator
public function checkPackage($id) public function checkPackage($id)
{ {
$this->checkId($id);
$packageRepo = new PackageRepo(); $packageRepo = new PackageRepo();
$package = $packageRepo->findById($id); $package = $packageRepo->findById($id);
@ -55,6 +46,19 @@ class Package extends Validator
return $package; return $package;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxPackageIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('package.not_found');
}
}
public function checkTitle($title) public function checkTitle($title)
{ {
$value = $this->filter->sanitize($title, ['trim', 'string']); $value = $this->filter->sanitize($title, ['trim', 'string']);

View File

@ -18,18 +18,7 @@ class Page extends Validator
*/ */
public function checkPageCache($id) public function checkPageCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxPageIdCache = new MaxPageIdCache();
$maxPageId = $maxPageIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxPageId) {
throw new BadRequestException('page.not_found');
}
$pageCache = new PageCache(); $pageCache = new PageCache();
@ -44,6 +33,8 @@ class Page extends Validator
public function checkPage($id) public function checkPage($id)
{ {
$this->checkId($id);
$pageRepo = new PageRepo(); $pageRepo = new PageRepo();
$page = $pageRepo->findById($id); $page = $pageRepo->findById($id);
@ -55,6 +46,19 @@ class Page extends Validator
return $page; return $page;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxPageIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('page.not_found');
}
}
public function checkTitle($title) public function checkTitle($title)
{ {
$value = $this->filter->sanitize($title, ['trim', 'string']); $value = $this->filter->sanitize($title, ['trim', 'string']);

View File

@ -18,18 +18,7 @@ class Topic extends Validator
*/ */
public function checkTopicCache($id) public function checkTopicCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxTopicIdCache = new MaxTopicIdCache();
$maxTopicId = $maxTopicIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxTopicId) {
throw new BadRequestException('topic.not_found');
}
$topicCache = new TopicCache(); $topicCache = new TopicCache();
@ -44,6 +33,8 @@ class Topic extends Validator
public function checkTopic($id) public function checkTopic($id)
{ {
$this->checkId($id);
$topicRepo = new TopicRepo(); $topicRepo = new TopicRepo();
$topic = $topicRepo->findById($id); $topic = $topicRepo->findById($id);
@ -55,6 +46,19 @@ class Topic extends Validator
return $topic; return $topic;
} }
public function checkId($id)
{
$id = intval($id);
$maxIdCache = new MaxTopicIdCache();
$maxId = $maxIdCache->get();
if ($id < 1 || $id > $maxId) {
throw new BadRequestException('topic.not_found');
}
}
public function checkTitle($title) public function checkTitle($title)
{ {
$value = $this->filter->sanitize($title, ['trim', 'string']); $value = $this->filter->sanitize($title, ['trim', 'string']);

View File

@ -21,18 +21,7 @@ class User extends Validator
*/ */
public function checkUserCache($id) public function checkUserCache($id)
{ {
$id = intval($id); $this->checkId($id);
$maxUserIdCache = new MaxUserIdCache();
$maxUserId = $maxUserIdCache->get();
/**
* 防止缓存穿透
*/
if ($id < 1 || $id > $maxUserId) {
throw new BadRequestException('user.not_found');
}
$userCache = new UserCache(); $userCache = new UserCache();
@ -47,6 +36,8 @@ class User extends Validator
public function checkUser($id) public function checkUser($id)
{ {
$this->checkId($id);
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$user = $userRepo->findById($id); $user = $userRepo->findById($id);
@ -58,6 +49,19 @@ class User extends Validator
return $user; return $user;
} }
public function checkId($id)
{
$id = intval($id);
$maxUserIdCache = new MaxUserIdCache();
$maxUserId = $maxUserIdCache->get();
if ($id < 1 || $id > $maxUserId) {
throw new BadRequestException('user.not_found');
}
}
public function checkName($name) public function checkName($name)
{ {
$value = $this->filter->sanitize($name, ['trim', 'string']); $value = $this->filter->sanitize($name, ['trim', 'string']);

View File

@ -104,12 +104,6 @@
list-style: decimal; list-style: decimal;
} }
body {
display: flex;
flex-flow: column;
min-height: 100vh;
}
#header { #header {
left: 0; left: 0;
top: 0; top: 0;
@ -122,7 +116,7 @@ body {
#main { #main {
margin-top: 80px; margin-top: 80px;
margin-bottom: 30px; margin-bottom: 30px;
flex: 1; min-height: 560px;
} }
#footer { #footer {
@ -1119,26 +1113,15 @@ body {
text-align: center; text-align: center;
} }
.channel .alipay, .channel .wxpay { .channel .btn-pay {
width: 200px; width: 200px;
height: 80px; height: 80px;
display: inline-block; display: inline-block;
line-height: 80px;
margin-right: 15px; margin-right: 15px;
background-color: #f2f2f2; background-color: #f2f2f2;
} }
.channel .alipay {
background-image: url("/static/web/img/alipay.png");
background-repeat: no-repeat;
background-position: center center;
}
.channel .wxpay {
background-image: url("/static/web/img/wxpay.png");
background-repeat: no-repeat;
background-position: center center;
}
.payment .footer { .payment .footer {
text-align: center; text-align: center;
} }

View File

@ -16,7 +16,10 @@ layui.use(['jquery', 'layer'], function () {
var qrHtml = $qrBlock.html(); var qrHtml = $qrBlock.html();
if (qrHtml.length === 0) { if (qrHtml.length === 0) {
var postData = {order_sn: orderSn, channel: channel}; var postData = {
order_sn: orderSn,
channel: channel === 'alipay' ? 1 : 2
};
$.post(createUrl, postData, function (res) { $.post(createUrl, postData, function (res) {
qrHtml = '<div class="qrcode"><img src="' + res.qrcode + '" alt="支付二维码"></div>'; qrHtml = '<div class="qrcode"><img src="' + res.qrcode + '" alt="支付二维码"></div>';
showQrLayer(qrTitle, qrHtml); showQrLayer(qrTitle, qrHtml);