From 21f92166d26b447e9722c49e9652dcbc45620be0 Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 16 Jun 2022 09:12:43 +0800 Subject: [PATCH] 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 @@
- +
@@ -21,15 +21,17 @@ {% if captcha.enabled == 1 %}
- +
{% endif %}
- - - + + + + +
@@ -72,12 +74,7 @@ {{ js_include('lib/jquery.min.js') }} {{ js_include('lib/jquery.buoyant.min.js') }} - - {% if captcha.enabled == 1 %} - - {{ js_include('https://ssl.captcha.qq.com/TCaptcha.js', false) }} - - {% endif %} + {{ js_include('https://ssl.captcha.qq.com/TCaptcha.js', false) }} {% endblock %} @@ -98,24 +95,27 @@ }); - {% if captcha.enabled == 1 %} - - {% endif %} + } + + }); + {% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Services/Account.php b/app/Http/Home/Services/Account.php index 8516bcad..0c3f0dfc 100644 --- a/app/Http/Home/Services/Account.php +++ b/app/Http/Home/Services/Account.php @@ -62,7 +62,7 @@ class Account 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/Home/Views/account/forget_password.volt b/app/Http/Home/Views/account/forget_password.volt index 8872c571..39cbef41 100644 --- a/app/Http/Home/Views/account/forget_password.volt +++ b/app/Http/Home/Views/account/forget_password.volt @@ -29,10 +29,10 @@
- - - - + + + +
diff --git a/app/Http/Home/Views/account/login_by_password.volt b/app/Http/Home/Views/account/login_by_password.volt index b5a7e100..2de28228 100644 --- a/app/Http/Home/Views/account/login_by_password.volt +++ b/app/Http/Home/Views/account/login_by_password.volt @@ -4,7 +4,7 @@ \ No newline at end of file diff --git a/app/Http/Home/Views/account/register.volt b/app/Http/Home/Views/account/register.volt index 2fc97fb4..4d86fdb1 100644 --- a/app/Http/Home/Views/account/register.volt +++ b/app/Http/Home/Views/account/register.volt @@ -45,10 +45,10 @@
- - - - + + + +
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();