From 251c1348fa8b98b1fec25ae6786a5bad7dd46a41 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Mon, 8 May 2023 23:38:10 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=A9=BA=E5=8F=A3=E4=BB=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Verify.php | 4 ++++ app/Validators/Verify.php | 32 ++++++++------------------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/app/Services/Verify.php b/app/Services/Verify.php index 36fc9fcc..d304cfb6 100644 --- a/app/Services/Verify.php +++ b/app/Services/Verify.php @@ -51,6 +51,8 @@ class Verify extends Service $value = $this->cache->get($key); + if (empty($value)) return false; + return $code == $value; } @@ -60,6 +62,8 @@ class Verify extends Service $value = $this->cache->get($key); + if (empty($value)) return false; + return $code == $value; } diff --git a/app/Validators/Verify.php b/app/Validators/Verify.php index 3e991c4b..e4d2ab3d 100644 --- a/app/Validators/Verify.php +++ b/app/Validators/Verify.php @@ -45,6 +45,10 @@ class Verify extends Validator public function checkSmsCode($phone, $code) { + if (empty($code)) { + throw new BadRequestException('verify.invalid_sms_code'); + } + $service = new VerifyService(); $result = $service->checkSmsCode($phone, $code); @@ -56,6 +60,10 @@ class Verify extends Validator public function checkMailCode($email, $code) { + if (empty($code)) { + throw new BadRequestException('verify.invalid_mail_code'); + } + $service = new VerifyService(); $result = $service->checkMailCode($email, $code); @@ -65,28 +73,4 @@ class Verify extends Validator } } - public function checkRand($rand) - { - list($time, $number) = explode('-', $rand); - - if (abs($time - time()) > 300) { - throw new BadRequestException('verify.invalid_rand'); - } - - if ($number < 1000 || $number > 9999) { - throw new BadRequestException('verify.invalid_rand'); - } - - return $rand; - } - - public function checkTicket($ticket, $rand) - { - $ticket = $this->crypt->decrypt($ticket); - - if ($ticket != $rand) { - throw new BadRequestException('verify.invalid_ticket'); - } - } - } From 5405e1652e4d5c44ba68934297b6f892523e6235 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Tue, 9 May 2023 11:26:02 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E9=A1=B5=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Views/order/confirm.volt | 6 ++--- public/static/home/css/common.css | 34 ++++++++++++-------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app/Http/Home/Views/order/confirm.volt b/app/Http/Home/Views/order/confirm.volt index 88bb5c7f..0da3b7c8 100644 --- a/app/Http/Home/Views/order/confirm.volt +++ b/app/Http/Home/Views/order/confirm.volt @@ -6,7 +6,7 @@ {%- macro cart_course_card(course, user) %} {% set course_url = url({'for':'home.course.show','id':course.id}) %} -
+
{{ course.title }}
@@ -46,7 +46,7 @@ {% set course = item_info.course %} {% set reward = item_info.reward %} {% set course_url = url({'for':'home.course.show','id':course.id}) %} -
+
{{ course.title }}
@@ -70,7 +70,7 @@ {%- macro cart_vip_card(item_info) %} {% set vip = item_info.vip %} -
+
{{ vip.title }}
diff --git a/public/static/home/css/common.css b/public/static/home/css/common.css index d4f22a6f..5f5427dc 100644 --- a/public/static/home/css/common.css +++ b/public/static/home/css/common.css @@ -1447,56 +1447,56 @@ color: red; } -.cart-course-card { +.cart-item-card { + display: flex; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px dashed #ccc; } -.cart-course-card:last-child { +.cart-item-card:last-child { padding: 0; margin: 0; border-bottom: none; } -.cart-course-card .cover { - float: left; +.cart-item-card .cover { margin-right: 10px; } -.cart-course-card .cover img { +.cart-item-card .cover img { width: 175px; height: 95px; } -.cart-course-card p { +.cart-item-card p { line-height: 30px; } -.cart-course-card .info { - float: left; -} - -.cart-course-card .key { +.cart-item-card .key { margin-right: 5px; } -.cart-course-card .value { +.cart-item-card .value { margin-right: 5px; color: #666; } -.cart-course-card .origin-price { +.cart-item-card .origin-price { text-decoration: line-through; } -.cart-course-card .price { +.cart-item-card .price { margin-right: 5px; color: red; } +.cart-stats { + display: flex; + justify-content: space-between; +} + .cart-stats .info { - float: left; line-height: 38px; } @@ -1514,10 +1514,6 @@ margin-right: 15px; } -.cart-form { - float: right; -} - .payment .header { padding-bottom: 15px; border-bottom: 1px solid #f6f6f6; From 84d21d80dac204e7526f10ef21588036f96c8d7c Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 10 May 2023 21:08:15 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E4=BC=98=E5=8C=96me=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Views/course/show_order.volt | 7 +- app/Services/Logic/Answer/AnswerInfo.php | 3 + app/Services/Logic/Answer/AnswerList.php | 77 ------------------- app/Services/Logic/Article/ArticleInfo.php | 3 + app/Services/Logic/Chapter/ChapterInfo.php | 3 + app/Services/Logic/Comment/CommentInfo.php | 3 + app/Services/Logic/Comment/ListTrait.php | 1 + app/Services/Logic/Consult/ConsultInfo.php | 3 + app/Services/Logic/Course/ChapterList.php | 6 +- .../Logic/Course/ConsultListTrait.php | 1 + app/Services/Logic/Course/CourseInfo.php | 24 +++--- app/Services/Logic/Course/ReviewList.php | 1 + app/Services/Logic/Point/GiftInfo.php | 9 ++- 13 files changed, 48 insertions(+), 93 deletions(-) delete mode 100644 app/Services/Logic/Answer/AnswerList.php diff --git a/app/Http/Home/Views/course/show_order.volt b/app/Http/Home/Views/course/show_order.volt index d7286f4c..f5ab79d3 100644 --- a/app/Http/Home/Views/course/show_order.volt +++ b/app/Http/Home/Views/course/show_order.volt @@ -1,4 +1,9 @@ -{% if course.me.allow_order == 1 %} +{% if course.me.logged == 0 %} + {% set login_url = url({'for':'home.account.login'}) %} + +{% elseif course.me.allow_order == 1 %} {% set order_url = url({'for':'home.order.confirm'},{'item_id':course.id,'item_type':1}) %} - {% set share_url = full_url({'for':'home.share'},{'id':article.id,'type':'article'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Http/Home/Views/chapter/live/active.volt b/app/Http/Home/Views/chapter/live/active.volt index fdbb1946..a6b4753a 100644 --- a/app/Http/Home/Views/chapter/live/active.volt +++ b/app/Http/Home/Views/chapter/live/active.volt @@ -2,6 +2,8 @@ {% block content %} + {% set share_url = full_url('chapter',chapter.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} {% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %} {% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %} {% set live_chats_url = url({'for':'home.live.chats','id':chapter.id}) %} @@ -58,9 +60,6 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Http/Home/Views/chapter/read.volt b/app/Http/Home/Views/chapter/read.volt index 534d3f38..2566d51d 100644 --- a/app/Http/Home/Views/chapter/read.volt +++ b/app/Http/Home/Views/chapter/read.volt @@ -2,6 +2,8 @@ {% block content %} + {% set share_url = full_url('chapter',chapter.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} {% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %} {% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %} @@ -44,9 +46,6 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Http/Home/Views/chapter/vod.volt b/app/Http/Home/Views/chapter/vod.volt index 52044075..0226cd4d 100644 --- a/app/Http/Home/Views/chapter/vod.volt +++ b/app/Http/Home/Views/chapter/vod.volt @@ -2,6 +2,8 @@ {% block content %} + {% set share_url = share_url('chapter',chapter.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} {% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %} {% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %} @@ -47,9 +49,6 @@
- {% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Http/Home/Views/course/show.volt b/app/Http/Home/Views/course/show.volt index 5d429389..b3a60cca 100644 --- a/app/Http/Home/Views/course/show.volt +++ b/app/Http/Home/Views/course/show.volt @@ -4,6 +4,9 @@ {{ partial('macros/course') }} + {% set share_url = share_url('course',course.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} + - {% set share_url = full_url({'for':'home.share'},{'id':course.id,'type':'course'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Http/Home/Views/help/index.volt b/app/Http/Home/Views/help/index.volt index c691a0e4..71003dcb 100644 --- a/app/Http/Home/Views/help/index.volt +++ b/app/Http/Home/Views/help/index.volt @@ -2,6 +2,8 @@ {% block content %} + {{ partial('macros/course') }} +
-
-
客户服务
-
-

没解决你的疑问?试试联系客服吧!

- {% if contact_info.qq %} - {% set link_url = 'https://wpa.qq.com/msgrd?v=3&uin=%s&site=qq&menu=yes'|format(contact_info.qq) %} -

- 联系客服 -

- {% endif %} + {% if featured_courses %} + -
+ {% endif %}
diff --git a/app/Http/Home/Views/help/show.volt b/app/Http/Home/Views/help/show.volt index 0ccb2c8a..a816ca07 100644 --- a/app/Http/Home/Views/help/show.volt +++ b/app/Http/Home/Views/help/show.volt @@ -4,12 +4,20 @@ {{ partial('macros/course') }} + {% set share_url = share_url('help',help.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} +
@@ -34,6 +42,12 @@
+
+ + + +
+ {% endblock %} {% block link_css %} diff --git a/app/Http/Home/Views/page/show.volt b/app/Http/Home/Views/page/show.volt index 1a7f6af4..67ee4643 100644 --- a/app/Http/Home/Views/page/show.volt +++ b/app/Http/Home/Views/page/show.volt @@ -4,11 +4,19 @@ {{ partial('macros/course') }} + {% set share_url = share_url('page',page.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} +
@@ -33,6 +41,12 @@
+
+ + + +
+ {% endblock %} {% block link_css %} diff --git a/app/Http/Home/Views/question/show.volt b/app/Http/Home/Views/question/show.volt index 9f1f37a1..6f08ca1b 100644 --- a/app/Http/Home/Views/question/show.volt +++ b/app/Http/Home/Views/question/show.volt @@ -4,6 +4,8 @@ {{ partial('macros/question') }} + {% set share_url = share_url('question',question.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} {% set question_report_url = url({'for':'home.report.add'},{'item_id':question.id,'item_type':107}) %} {% set question_edit_url = url({'for':'home.question.edit','id':question.id}) %} {% set question_delete_url = url({'for':'home.question.delete','id':question.id}) %} @@ -98,9 +100,6 @@ {{ partial('question/sticky') }}
- {% set share_url = full_url({'for':'home.share'},{'id':question.id,'type':'question'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Http/Home/Views/user/show.volt b/app/Http/Home/Views/user/show.volt index 0f4517cb..29b4684d 100644 --- a/app/Http/Home/Views/user/show.volt +++ b/app/Http/Home/Views/user/show.volt @@ -4,6 +4,8 @@ {{ partial('macros/user') }} + {% set share_url = share_url('user',user.id,auth_user.id) %} + {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} {% set avatar_class = user.vip == 1 ? 'avatar vip' : 'avatar' %}
- {% set share_url = full_url({'for':'home.share'},{'id':user.id,'type':'user'}) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} -
diff --git a/app/Library/Helper.php b/app/Library/Helper.php index 69b50c1a..0240e6ec 100644 --- a/app/Library/Helper.php +++ b/app/Library/Helper.php @@ -8,8 +8,8 @@ use App\Caches\Setting as SettingCache; use App\Library\Purifier as HtmlPurifier; use App\Library\Validators\Common as CommonValidator; +use App\Services\Logic\Url\ShareUrl as ShareUrlService; use App\Services\Storage as StorageService; -use Koogua\Ip2Region\Searcher as Ip2RegionSearcher; use Phalcon\Config; use Phalcon\Di; use Phalcon\Text; @@ -727,6 +727,21 @@ function kg_full_url($uri, $args = null) return $baseUrl . $url->get($uri, $args); } +/** + * 构造分享url + * + * @param string $type + * @param int $id + * @param int $referer + * @return string + */ +function kg_share_url($type, $id, $referer = 0) +{ + $service = new ShareUrlService(); + + return $service->handle($type, $id, $referer); +} + /** * 获取H5首页地址 * diff --git a/app/Providers/Volt.php b/app/Providers/Volt.php index eedcb6be..1e4b4e3a 100644 --- a/app/Providers/Volt.php +++ b/app/Providers/Volt.php @@ -39,6 +39,10 @@ class Volt extends Provider return 'kg_full_url(' . $resolvedArgs . ')'; }); + $compiler->addFunction('share_url', function ($resolvedArgs) { + return 'kg_share_url(' . $resolvedArgs . ')'; + }); + $compiler->addFunction('static_url', function ($resolvedArgs) { return 'kg_static_url(' . $resolvedArgs . ')'; }); diff --git a/app/Services/Logic/Url/FullH5Url.php b/app/Services/Logic/Url/FullH5Url.php new file mode 100644 index 00000000..eabc5e3a --- /dev/null +++ b/app/Services/Logic/Url/FullH5Url.php @@ -0,0 +1,192 @@ +baseUrl = $this->getBaseUrl(); + } + + public function getHomeUrl() + { + return $this->getFullUrl('/index/index'); + } + + public function getAccountRegisterUrl() + { + return $this->getFullUrl('/account/register'); + } + + public function getAccountLoginUrl() + { + return $this->getFullUrl('/account/login'); + } + + public function getAccountForgetUrl() + { + return $this->getFullUrl('/account/forget'); + } + + public function getVipIndexUrl() + { + return $this->getFullUrl('/vip/index'); + } + + public function getHelpIndexUrl() + { + return $this->getFullUrl('/help/index'); + } + + public function getCourseListUrl() + { + return $this->getFullUrl('/course/list'); + } + + public function getArticleListUrl() + { + return $this->getFullUrl('/article/list'); + } + + public function getQuestionListUrl() + { + return $this->getFullUrl('/question/list'); + } + + public function getLiveListUrl() + { + return $this->getFullUrl('/live/list'); + } + + public function getTeacherListUrl() + { + return $this->getFullUrl('/teacher/list'); + } + + public function getFlashSaleListUrl() + { + return $this->getFullUrl('/flash-sale/list'); + } + + public function getPointGiftListUrl() + { + return $this->getFullUrl('/point/gift/list'); + } + + public function getPageInfoUrl($id) + { + return $this->getFullUrl('/page/info', ['id' => $id]); + } + + public function getHelpInfoUrl($id) + { + return $this->getFullUrl('/help/info', ['id' => $id]); + } + + public function getArticleInfoUrl($id) + { + return $this->getFullUrl('/article/info', ['id' => $id]); + } + + public function getQuestionInfoUrl($id) + { + return $this->getFullUrl('/question/info', ['id' => $id]); + } + + public function getAnswerInfoUrl($id) + { + return $this->getFullUrl('/answer/info', ['id' => $id]); + } + + public function getTopicInfoUrl($id) + { + return $this->getFullUrl('/topic/info', ['id' => $id]); + } + + public function getPackageInfoUrl($id) + { + return $this->getFullUrl('/package/info', ['id' => $id]); + } + + public function getCourseInfoUrl($id) + { + return $this->getFullUrl('/course/info', ['id' => $id]); + } + + public function getChapterInfoUrl($id) + { + $chapterRepo = new ChapterRepo(); + + $chapter = $chapterRepo->findById($id); + + if ($chapter->model == CourseModel::MODEL_VOD) { + return $this->getFullUrl('/chapter/vod', ['id' => $id]); + } elseif ($chapter->model == CourseModel::MODEL_LIVE) { + return $this->getFullUrl('/chapter/live', ['id' => $id]); + } elseif ($chapter->model == CourseModel::MODEL_READ) { + return $this->getFullUrl('/chapter/read', ['id' => $id]); + } else { + return $this->getHomeUrl(); + } + } + + public function getUserIndexUrl($id) + { + return $this->getFullUrl('/user/index', ['id' => $id]); + } + + public function getTeacherIndexUrl($id) + { + return $this->getFullUrl('/teacher/index', ['id' => $id]); + } + + public function getPointGiftInfoUrl($id) + { + return $this->getFullUrl('/point/gift/info', ['id' => $id]); + } + + protected function getFullUrl($path, $params = []) + { + $extra = ['source' => $this->source]; + + $data = array_merge($params, $extra); + + $query = http_build_query($data); + + return sprintf('%s%s?%s', $this->baseUrl, $path, $query); + } + + protected function getBaseUrl() + { + return sprintf('%s/h5/#/pages', kg_site_url()); + } + +} diff --git a/app/Services/Logic/Url/FullWebUrl.php b/app/Services/Logic/Url/FullWebUrl.php new file mode 100644 index 00000000..f941aba8 --- /dev/null +++ b/app/Services/Logic/Url/FullWebUrl.php @@ -0,0 +1,139 @@ +baseUrl = $this->getBaseUrl(); + } + + public function getHomeUrl() + { + return $this->baseUrl; + } + + public function getVipUrl() + { + $route = $this->url->get(['for' => 'home.vip.index']); + + return $this->getFullUrl($route); + } + + public function getHelpShowUrl($id) + { + $route = $this->url->get(['for' => 'home.help.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getPageShowUrl($id) + { + $route = $this->url->get(['for' => 'home.page.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getArticleShowUrl($id) + { + $route = $this->url->get(['for' => 'home.article.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getQuestionShowUrl($id) + { + $route = $this->url->get(['for' => 'home.question.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getTopicShowUrl($id) + { + $route = $this->url->get(['for' => 'home.topic.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getPackageShowUrl($id) + { + $route = $this->url->get(['for' => 'home.package.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getCourseShowUrl($id) + { + $route = $this->url->get(['for' => 'home.course.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getChapterShowUrl($id) + { + $route = $this->url->get(['for' => 'home.chapter.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getUserShowUrl($id) + { + $route = $this->url->get(['for' => 'home.user.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getTeacherShowUrl($id) + { + $route = $this->url->get(['for' => 'home.teacher.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + public function getPointGiftShowUrl($id) + { + $route = $this->url->get(['for' => 'home.point_gift.show', 'id' => $id]); + + return $this->getFullUrl($route); + } + + protected function getFullUrl($path, $params = []) + { + $extra = ['source' => $this->source]; + + $data = array_merge($params, $extra); + + $query = http_build_query($data); + + return sprintf('%s%s?%s', $this->baseUrl, $path, $query); + } + + protected function getBaseUrl() + { + return kg_site_url(); + } + +} \ No newline at end of file diff --git a/app/Services/Logic/Url/ShareUrl.php b/app/Services/Logic/Url/ShareUrl.php new file mode 100644 index 00000000..7741a6b6 --- /dev/null +++ b/app/Services/Logic/Url/ShareUrl.php @@ -0,0 +1,228 @@ +fullWebUrl = new FullWebUrl(); + $this->fullH5Url = new FullH5Url(); + } + + public function handle($type, $id = 0, $referer = 0) + { + if ($type == 'article') { + $result = $this->getArticleUrl($id); + } elseif ($type == 'page') { + $result = $this->getPageUrl($id); + } elseif ($type == 'question') { + $result = $this->getQuestionUrl($id); + } elseif ($type == 'course') { + $result = $this->getCourseUrl($id); + } elseif ($type == 'chapter') { + $result = $this->getChapterUrl($id); + } elseif ($type == 'user') { + $result = $this->getUserUrl($id); + } elseif ($type == 'teacher') { + $result = $this->getTeacherUrl($id); + } elseif ($type == 'topic') { + $result = $this->getTopicUrl($id); + } elseif ($type == 'package') { + $result = $this->getPackageUrl($id); + } elseif ($type == 'vip') { + $result = $this->getVipUrl(); + } elseif ($type == 'point_gift') { + $result = $this->getPointGiftUrl($id); + } else { + $result = $this->getHomeUrl(); + } + + if ($referer > 0) { + $result['h5'] = $this->withReferer($result['h5'], $referer); + $result['web'] = $this->withReferer($result['web'], $referer); + } + + $gotoH5 = $this->gotoH5Url(); + + return $gotoH5 ? $result['h5'] : $result['web']; + } + + public function getHomeUrl() + { + $webUrl = $this->fullWebUrl->getHomeUrl(); + + $h5Url = $this->fullH5Url->getHomeUrl(); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getVipUrl() + { + $webUrl = $this->fullWebUrl->getVipUrl(); + + $h5Url = $this->fullH5Url->getVipIndexUrl(); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getHelpUrl($id) + { + $webUrl = $this->fullWebUrl->getHelpShowUrl($id); + + $h5Url = $this->fullH5Url->getHelpInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getPageUrl($id) + { + $webUrl = $this->fullWebUrl->getPageShowUrl($id); + + $h5Url = $this->fullH5Url->getPageInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getArticleUrl($id) + { + $webUrl = $this->fullWebUrl->getArticleShowUrl($id); + + $h5Url = $this->fullH5Url->getArticleInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getQuestionUrl($id) + { + $webUrl = $this->fullWebUrl->getQuestionShowUrl($id); + + $h5Url = $this->fullH5Url->getQuestionInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getTopicUrl($id) + { + $webUrl = $this->fullWebUrl->getTopicShowUrl($id); + + $h5Url = $this->fullH5Url->getTopicInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getPackageUrl($id) + { + $webUrl = $this->fullWebUrl->getPackageShowUrl($id); + + $h5Url = $this->fullH5Url->getPackageInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getCourseUrl($id) + { + $webUrl = $this->fullWebUrl->getCourseShowUrl($id); + + $h5Url = $this->fullH5Url->getCourseInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getChapterUrl($id) + { + $webUrl = $this->fullWebUrl->getChapterShowUrl($id); + + $h5Url = $this->fullH5Url->getChapterInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getUserUrl($id) + { + $webUrl = $this->fullWebUrl->getUserShowUrl($id); + + $h5Url = $this->fullH5Url->getUserIndexUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getTeacherUrl($id) + { + $webUrl = $this->fullWebUrl->getTeacherShowUrl($id); + + $h5Url = $this->fullH5Url->getTeacherIndexUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function getPointGiftUrl($id) + { + + $webUrl = $this->fullWebUrl->getPointGiftShowUrl($id); + + $h5Url = $this->fullH5Url->getPointGiftInfoUrl($id); + + return ['web' => $webUrl, 'h5' => $h5Url]; + } + + public function setTargetType($targetType) + { + $this->targetType = $targetType; + } + + protected function withReferer($url, $referer) + { + $params = ['referer' => $referer]; + + if (strpos($url, '?') === false) { + $url .= '?' . http_build_query($params); + } else { + $url .= '&' . http_build_query($params); + } + + return $url; + } + + protected function gotoH5Url() + { + if (!$this->h5Enabled()) return false; + + if ($this->targetType == 'h5') return true; + + return $this->isMobileBrowser(); + } + +} From e3e5d20a7c42724f2c29be5ad3f7b9a75b3b2be7 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Fri, 12 May 2023 18:52:11 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E8=AF=84=E9=80=89=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrations/PageTrait.php | 6 +++--- db/migrations/SettingTrait.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/migrations/PageTrait.php b/db/migrations/PageTrait.php index db651abd..e0e87baf 100644 --- a/db/migrations/PageTrait.php +++ b/db/migrations/PageTrait.php @@ -11,7 +11,7 @@ trait PageTrait protected function insertPages(array $rows) { foreach ($rows as $key => $row) { - $exists = $this->pageExits($row['alias']); + $exists = $this->pageExists($row['alias']); if ($exists) unset($rows[$key]); } @@ -20,7 +20,7 @@ trait PageTrait $this->table('kg_page')->insert($rows)->save(); } - protected function pageExits($alias) + protected function pageExists($alias) { $row = $this->getQueryBuilder() ->select('*') @@ -28,7 +28,7 @@ trait PageTrait ->where(['alias' => $alias]) ->execute()->fetch(); - return $row ? true : false; + return (bool)$row; } } \ No newline at end of file diff --git a/db/migrations/SettingTrait.php b/db/migrations/SettingTrait.php index 84d39deb..02f5374e 100644 --- a/db/migrations/SettingTrait.php +++ b/db/migrations/SettingTrait.php @@ -11,7 +11,7 @@ trait SettingTrait protected function insertSettings(array $rows) { foreach ($rows as $key => $row) { - $exists = $this->settingExits($row['section'], $row['item_key']); + $exists = $this->settingExists($row['section'], $row['item_key']); if ($exists) unset($rows[$key]); } @@ -20,7 +20,7 @@ trait SettingTrait $this->table('kg_setting')->insert($rows)->save(); } - protected function settingExits($section, $itemKey) + protected function settingExists($section, $itemKey) { $row = $this->getQueryBuilder() ->select('*') @@ -28,7 +28,7 @@ trait SettingTrait ->where(['section' => $section, 'item_key' => $itemKey]) ->execute()->fetch(); - return $row ? true : false; + return (bool)$row; } } \ No newline at end of file From 2a055d9ad4574e2f9ed86841aaba091d2dc742c3 Mon Sep 17 00:00:00 2001 From: koogua Date: Mon, 22 May 2023 19:20:14 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0composer=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.lock | 181 ++++++++++++++++--------------- db/migrations/20230522141831.php | 37 +++++++ 2 files changed, 130 insertions(+), 88 deletions(-) create mode 100644 db/migrations/20230522141831.php diff --git a/composer.lock b/composer.lock index 961cfa9d..96cfbf0b 100644 --- a/composer.lock +++ b/composer.lock @@ -2365,33 +2365,34 @@ "time": "2017-10-23T01:57:42+00:00" }, { - "name": "qcloud/cos-sdk-v5", - "version": "v2.6.1", - "source": { - "type": "git", - "url": "https://github.com/tencentyun/cos-php-sdk-v5.git", - "reference": "d367ba8d0305b83364b64055594a0ac22b1cefd8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/d367ba8d0305b83364b64055594a0ac22b1cefd8", - "reference": "d367ba8d0305b83364b64055594a0ac22b1cefd8", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, + "name": "qcloud/cos-sdk-v5", + "version": "v2.6.2", + "source": { + "type": "git", + "url": "https://github.com/tencentyun/cos-php-sdk-v5.git", + "reference": "92a1ee62b85ed4e7bf6836a684df5d7e3158d0ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/92a1ee62b85ed4e7bf6836a684df5d7e3158d0ed", + "reference": "92a1ee62b85ed4e7bf6836a684df5d7e3158d0ed", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, "require": { - "ext-curl": "*", - "ext-json": "*", - "ext-simplexml": "*", - "guzzlehttp/guzzle": "^6.2.1 || ^7.0", - "guzzlehttp/guzzle-services": "^1.1", - "guzzlehttp/psr7": "^1.3.1 || ^2.0", - "php": ">=5.6" + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "guzzlehttp/guzzle": "^6.2.1 || ^7.0", + "guzzlehttp/guzzle-services": "^1.1", + "guzzlehttp/psr7": "^1.3.1 || ^2.0", + "php": ">=5.6" }, "type": "library", "extra": { @@ -2433,9 +2434,9 @@ ], "support": { "issues": "https://github.com/tencentyun/cos-php-sdk-v5/issues", - "source": "https://github.com/tencentyun/cos-php-sdk-v5/tree/v2.6.1" + "source": "https://github.com/tencentyun/cos-php-sdk-v5/tree/v2.6.2" }, - "time": "2023-02-07T09:49:12+00:00" + "time": "2023-04-07T07:38:24+00:00" }, { "name": "ralouphie/getallheaders", @@ -4908,40 +4909,43 @@ ], "time": "2022-05-27T12:56:18+00:00" }, - { - "name": "tencentcloud/tencentcloud-sdk-php", - "version": "3.0.824", - "source": { - "type": "git", - "url": "https://github.com/TencentCloud/tencentcloud-sdk-php.git", - "reference": "1d85da7e51ba02defe33fbae0b6dbae0f1d7caf5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/TencentCloud/tencentcloud-sdk-php/zipball/1d85da7e51ba02defe33fbae0b6dbae0f1d7caf5", - "reference": "1d85da7e51ba02defe33fbae0b6dbae0f1d7caf5", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, - "require": { - "guzzlehttp/guzzle": "^6.3 || ^7.0", - "php": ">=5.6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "TencentCloud\\": "./src/TencentCloud" - }, - "classmap": [ - "src/QcloudApi/QcloudApi.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", + { + "name": "tencentcloud/tencentcloud-sdk-php", + "version": "3.0.889", + "source": { + "type": "git", + "url": "https://github.com/TencentCloud/tencentcloud-sdk-php.git", + "reference": "a08031e5111f17131fceb429eebb8223c105d8b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/TencentCloud/tencentcloud-sdk-php/zipball/a08031e5111f17131fceb429eebb8223c105d8b3", + "reference": "a08031e5111f17131fceb429eebb8223c105d8b3", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "guzzlehttp/guzzle": "^6.3 || ^7.0", + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "TencentCloud\\": "./src/TencentCloud" + }, + "classmap": [ + "src/QcloudApi/QcloudApi.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", "license": [ "Apache-2.0" ], @@ -4957,9 +4961,9 @@ "homepage": "https://github.com/TencentCloud/tencentcloud-sdk-php", "support": { "issues": "https://github.com/TencentCloud/tencentcloud-sdk-php/issues", - "source": "https://github.com/TencentCloud/tencentcloud-sdk-php/tree/3.0.824" + "source": "https://github.com/TencentCloud/tencentcloud-sdk-php/tree/3.0.889" }, - "time": "2023-02-15T00:03:58+00:00" + "time": "2023-05-22T00:02:52+00:00" }, { "name": "webmozart/assert", @@ -5095,28 +5099,29 @@ }, "time": "2022-04-19T20:14:54+00:00" }, - { - "name": "workerman/gateway-worker", - "version": "v3.0.27", - "source": { - "type": "git", - "url": "https://github.com/walkor/GatewayWorker.git", - "reference": "c0cae6c0e69288ab7dcc8b25599d3b9e4f4441d2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/walkor/GatewayWorker/zipball/c0cae6c0e69288ab7dcc8b25599d3b9e4f4441d2", - "reference": "c0cae6c0e69288ab7dcc8b25599d3b9e4f4441d2", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] - }, + { + "name": "workerman/gateway-worker", + "version": "v3.0.28", + "source": { + "type": "git", + "url": "https://github.com/walkor/GatewayWorker.git", + "reference": "a7dffc53403133131a51b9fd3c6c6d70869cb6d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/walkor/GatewayWorker/zipball/a7dffc53403133131a51b9fd3c6c6d70869cb6d3", + "reference": "a7dffc53403133131a51b9fd3c6c6d70869cb6d3", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, "require": { - "workerman/workerman": "^4.0.0 || ^5.0.0" + "php": ">=7.0", + "workerman/workerman": "^4.0.30" }, "type": "library", "autoload": { @@ -5135,7 +5140,7 @@ ], "support": { "issues": "https://github.com/walkor/GatewayWorker/issues", - "source": "https://github.com/walkor/GatewayWorker/tree/v3.0.27" + "source": "https://github.com/walkor/GatewayWorker/tree/v3.0.28" }, "funding": [ { @@ -5147,7 +5152,7 @@ "type": "patreon" } ], - "time": "2023-02-09T09:16:04+00:00" + "time": "2023-03-24T03:56:27+00:00" }, { "name": "workerman/gatewayclient", @@ -5641,5 +5646,5 @@ "ext-fileinfo": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.0.0" } diff --git a/db/migrations/20230522141831.php b/db/migrations/20230522141831.php new file mode 100644 index 00000000..9f296900 --- /dev/null +++ b/db/migrations/20230522141831.php @@ -0,0 +1,37 @@ +alterReviewLikeTable(); + } + + protected function alterReviewLikeTable() + { + $table = $this->table('kg_review_like'); + + if (!$table->hasColumn('update_time')) { + $table->addColumn('update_time', 'integer', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'comment' => '更新时间', + 'after' => 'create_time', + ]); + } + + $table->save(); + } + +} From f094f10011174f1eb49bcebd9f86e772bcbcb832 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Mon, 22 May 2023 21:13:50 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E8=AF=AF=E5=88=A0?= =?UTF-8?q?=E7=9A=84AnswerList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- app/Library/Sitemap.php | 2 +- app/Services/Logic/Answer/AnswerList.php | 77 +++++++++++++++++++ .../Logic/Article/ArticleDataTrait.php | 1 - 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 app/Services/Logic/Answer/AnswerList.php diff --git a/README.md b/README.md index 05d3b71d..cfc4cf02 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Tips: 请用手机注册一个新账号,用户中心 -> 关注订阅,扫码 ### 项目组件 - 后台框架:[phalcon 3.4.5](https://phalcon.io) -- 前端框架:[layui 2.7.6](https://layui.com) +- 前端框架:[layui 2.8.2](https://layui.com) - 全文检索:[xunsearch 1.4.9](http://www.xunsearch.com) - 即时通讯:[workerman 3.5.22](https://workerman.net) - 基础依赖:[php7.3](https://php.net), [mysql5.7](https://mysql.com), [redis5.0](https://redis.io) diff --git a/app/Library/Sitemap.php b/app/Library/Sitemap.php index 6ba121ed..e857488f 100644 --- a/app/Library/Sitemap.php +++ b/app/Library/Sitemap.php @@ -46,7 +46,7 @@ class Sitemap public function build($filename = null) { $xml = '' . "\n"; - $xml .= '' . "\n"; + $xml .= '' . "\n"; foreach ($this->items as $item) { $item['loc'] = htmlentities($item['loc'], ENT_QUOTES); diff --git a/app/Services/Logic/Answer/AnswerList.php b/app/Services/Logic/Answer/AnswerList.php new file mode 100644 index 00000000..9dab30dc --- /dev/null +++ b/app/Services/Logic/Answer/AnswerList.php @@ -0,0 +1,77 @@ +getParams(); + + $params['deleted'] = 0; + + $sort = $pagerQuery->getSort(); + $page = $pagerQuery->getPage(); + $limit = $pagerQuery->getLimit(); + + $answerRepo = new AnswerRepo(); + + $pager = $answerRepo->paginate($params, $sort, $page, $limit); + + return $this->handleAnswers($pager); + } + + public function handleAnswers($pager) + { + if ($pager->total_items == 0) { + return $pager; + } + + $builder = new AnswerListBuilder(); + + $answers = $pager->items->toArray(); + + $questions = $builder->getQuestions($answers); + + $users = $builder->getUsers($answers); + + $items = []; + + foreach ($answers as $answer) { + + $question = $questions[$answer['question_id']] ?? new \stdClass(); + $owner = $users[$answer['owner_id']] ?? new \stdClass(); + + $items[] = [ + 'id' => $answer['id'], + 'summary' => $answer['summary'], + 'published' => $answer['published'], + 'accepted' => $answer['accepted'], + 'comment_count' => $answer['comment_count'], + 'like_count' => $answer['like_count'], + 'create_time' => $answer['create_time'], + 'update_time' => $answer['update_time'], + 'question' => $question, + 'owner' => $owner, + ]; + } + + $pager->items = $items; + + return $pager; + } + +} diff --git a/app/Services/Logic/Article/ArticleDataTrait.php b/app/Services/Logic/Article/ArticleDataTrait.php index 77b11d93..ef40bdfa 100644 --- a/app/Services/Logic/Article/ArticleDataTrait.php +++ b/app/Services/Logic/Article/ArticleDataTrait.php @@ -120,7 +120,6 @@ trait ArticleDataTrait $tagRepo = new TagRepo(); $tags = $tagRepo->findByIds($newTagIds); if ($tags->count() > 0) { - $articleTags = []; foreach ($tags as $tag) { $articleTags[] = ['id' => $tag->id, 'name' => $tag->name]; $this->recountTagArticles($tag->id); From 5985576065fc82fdead151b9086183d2ccfcddd6 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Tue, 23 May 2023 17:27:14 +0800 Subject: [PATCH 08/15] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E5=B1=82=E9=9D=A2=202.=E5=A2=9E=E5=8A=A0=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B|=E6=96=87=E7=AB=A0|=E8=80=83=E8=AF=95widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Caches/Article.php | 2 +- app/Caches/Chapter.php | 2 +- app/Caches/Course.php | 2 +- app/Caches/CourseCategoryList.php | 2 +- app/Caches/CoursePackageList.php | 2 +- app/Caches/CourseRecommendedList.php | 2 +- app/Caches/CourseRelatedList.php | 2 +- app/Caches/CourseTeacherList.php | 2 +- app/Caches/CourseTopicList.php | 2 +- app/Caches/FeaturedArticleList.php | 83 ++++++++++++++++++ app/Caches/FeaturedCourseList.php | 85 +++++++++++++++++++ app/Caches/FlashSale.php | 2 +- app/Caches/HotQuestionList.php | 2 +- app/Caches/IndexFeaturedCourseList.php | 2 +- app/Caches/IndexFlashSaleList.php | 2 +- app/Caches/IndexFreeCourseList.php | 2 +- app/Caches/IndexLiveList.php | 2 +- app/Caches/IndexNewCourseList.php | 2 +- app/Caches/IndexSimpleFeaturedCourseList.php | 2 +- app/Caches/IndexSimpleFreeCourseList.php | 2 +- app/Caches/IndexSimpleNewCourseList.php | 2 +- app/Caches/IndexSimpleVipCourseList.php | 2 +- app/Caches/IndexTeacherList.php | 2 +- app/Caches/IndexVipCourseList.php | 2 +- app/Caches/PackageCourseList.php | 2 +- app/Caches/PointGift.php | 2 +- app/Caches/PointHotGiftList.php | 2 +- app/Caches/Question.php | 2 +- app/Caches/TaggedArticleList.php | 2 +- app/Caches/TaggedQuestionList.php | 2 +- app/Caches/TopAnswererList.php | 2 +- app/Caches/TopAuthorList.php | 2 +- app/Caches/User.php | 2 +- app/Caches/UserDailyCounter.php | 2 +- app/Http/Home/Controllers/HelpController.php | 14 --- .../Home/Controllers/WidgetController.php | 30 +++++++ app/Http/Home/Views/help/index.volt | 28 +++--- app/Http/Home/Views/help/show.volt | 44 ++++------ app/Http/Home/Views/page/show.volt | 44 ++++------ .../Home/Views/widget/featured_articles.volt | 20 +++++ .../Home/Views/widget/featured_courses.volt | 12 +++ public/static/home/js/help.js | 10 --- 42 files changed, 309 insertions(+), 125 deletions(-) create mode 100644 app/Caches/FeaturedArticleList.php create mode 100644 app/Caches/FeaturedCourseList.php create mode 100644 app/Http/Home/Views/widget/featured_articles.volt create mode 100644 app/Http/Home/Views/widget/featured_courses.volt delete mode 100644 public/static/home/js/help.js diff --git a/app/Caches/Article.php b/app/Caches/Article.php index 3bca7d22..18baa434 100644 --- a/app/Caches/Article.php +++ b/app/Caches/Article.php @@ -12,7 +12,7 @@ use App\Repos\Article as ArticleRepo; class Article extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/Chapter.php b/app/Caches/Chapter.php index 5f237013..b2a0fe16 100644 --- a/app/Caches/Chapter.php +++ b/app/Caches/Chapter.php @@ -12,7 +12,7 @@ use App\Repos\Chapter as ChapterRepo; class Chapter extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/Course.php b/app/Caches/Course.php index 872343c0..4479466d 100644 --- a/app/Caches/Course.php +++ b/app/Caches/Course.php @@ -12,7 +12,7 @@ use App\Repos\Course as CourseRepo; class Course extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseCategoryList.php b/app/Caches/CourseCategoryList.php index 0634ffc7..12681a06 100644 --- a/app/Caches/CourseCategoryList.php +++ b/app/Caches/CourseCategoryList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CourseCategoryList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CoursePackageList.php b/app/Caches/CoursePackageList.php index c251e2e9..6c27dd1e 100644 --- a/app/Caches/CoursePackageList.php +++ b/app/Caches/CoursePackageList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CoursePackageList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseRecommendedList.php b/app/Caches/CourseRecommendedList.php index fb6c5d17..c810082f 100644 --- a/app/Caches/CourseRecommendedList.php +++ b/app/Caches/CourseRecommendedList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class CourseRecommendedList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseRelatedList.php b/app/Caches/CourseRelatedList.php index 46274fc1..d8d8f58c 100644 --- a/app/Caches/CourseRelatedList.php +++ b/app/Caches/CourseRelatedList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CourseRelatedList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseTeacherList.php b/app/Caches/CourseTeacherList.php index 70314edc..1c676f1a 100644 --- a/app/Caches/CourseTeacherList.php +++ b/app/Caches/CourseTeacherList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CourseTeacherList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseTopicList.php b/app/Caches/CourseTopicList.php index 0d9e95aa..580d7d09 100644 --- a/app/Caches/CourseTopicList.php +++ b/app/Caches/CourseTopicList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class CourseTopicList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/FeaturedArticleList.php b/app/Caches/FeaturedArticleList.php new file mode 100644 index 00000000..bd5fc0f2 --- /dev/null +++ b/app/Caches/FeaturedArticleList.php @@ -0,0 +1,83 @@ +findArticles($limit); + + if ($articles->count() == 0) { + return []; + } + + $result = []; + + foreach ($articles as $article) { + + $userCount = $article->user_count; + + if ($article->fake_user_count > $article->user_count) { + $userCount = $article->fake_user_count; + } + + $result[] = [ + 'id' => $article->id, + 'title' => $article->title, + 'cover' => $article->cover, + 'market_price' => (float)$article->market_price, + 'vip_price' => (float)$article->vip_price, + 'user_count' => $userCount, + 'favorite_count' => $article->favorite_count, + 'comment_count' => $article->comment_count, + 'view_count' => $article->view_count, + 'like_count' => $article->like_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|ArticleModel[] + */ + protected function findArticles($limit = 8) + { + return ArticleModel::query() + ->where('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') + ->orderBy('id DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/FeaturedCourseList.php b/app/Caches/FeaturedCourseList.php new file mode 100644 index 00000000..cb2817a8 --- /dev/null +++ b/app/Caches/FeaturedCourseList.php @@ -0,0 +1,85 @@ +findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'model' => $course->model, + 'level' => $course->level, + 'rating' => round($course->rating, 1), + 'market_price' => (float)$course->market_price, + 'vip_price' => (float)$course->vip_price, + 'user_count' => $userCount, + 'lesson_count' => $course->lesson_count, + 'review_count' => $course->review_count, + 'favorite_count' => $course->favorite_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') + ->orderBy('id DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/FlashSale.php b/app/Caches/FlashSale.php index 8062e03a..d8b89f43 100644 --- a/app/Caches/FlashSale.php +++ b/app/Caches/FlashSale.php @@ -12,7 +12,7 @@ use App\Repos\FlashSale as FlashSaleRepo; class FlashSale extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/HotQuestionList.php b/app/Caches/HotQuestionList.php index f557a688..64220fd8 100644 --- a/app/Caches/HotQuestionList.php +++ b/app/Caches/HotQuestionList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class HotQuestionList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexFeaturedCourseList.php b/app/Caches/IndexFeaturedCourseList.php index 54b44f4d..f7d0e6ae 100644 --- a/app/Caches/IndexFeaturedCourseList.php +++ b/app/Caches/IndexFeaturedCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexFeaturedCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexFlashSaleList.php b/app/Caches/IndexFlashSaleList.php index 587da335..7fd379b6 100644 --- a/app/Caches/IndexFlashSaleList.php +++ b/app/Caches/IndexFlashSaleList.php @@ -12,7 +12,7 @@ use App\Services\Logic\FlashSale\SaleList; class IndexFlashSaleList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index d96847c0..bc20a9dc 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexFreeCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexLiveList.php b/app/Caches/IndexLiveList.php index 6d5d0836..734150a1 100644 --- a/app/Caches/IndexLiveList.php +++ b/app/Caches/IndexLiveList.php @@ -18,7 +18,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexLiveList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 27d83172..4975cb27 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexNewCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleFeaturedCourseList.php b/app/Caches/IndexSimpleFeaturedCourseList.php index 1ea87812..b5433216 100644 --- a/app/Caches/IndexSimpleFeaturedCourseList.php +++ b/app/Caches/IndexSimpleFeaturedCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleFeaturedCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleFreeCourseList.php b/app/Caches/IndexSimpleFreeCourseList.php index 065c6066..34a6d4f7 100644 --- a/app/Caches/IndexSimpleFreeCourseList.php +++ b/app/Caches/IndexSimpleFreeCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleFreeCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleNewCourseList.php b/app/Caches/IndexSimpleNewCourseList.php index b6e0b6b9..7dffa5af 100644 --- a/app/Caches/IndexSimpleNewCourseList.php +++ b/app/Caches/IndexSimpleNewCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleNewCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleVipCourseList.php b/app/Caches/IndexSimpleVipCourseList.php index bb073985..6756b39e 100644 --- a/app/Caches/IndexSimpleVipCourseList.php +++ b/app/Caches/IndexSimpleVipCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleVipCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexTeacherList.php b/app/Caches/IndexTeacherList.php index df9d2056..0946f126 100644 --- a/app/Caches/IndexTeacherList.php +++ b/app/Caches/IndexTeacherList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexTeacherList extends Cache { - protected $lifetime = 1 * 3600; + protected $lifetime = 3600; public function getLifetime() { diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index db09222a..6b268160 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexVipCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/PackageCourseList.php b/app/Caches/PackageCourseList.php index 2843cd71..90de701b 100644 --- a/app/Caches/PackageCourseList.php +++ b/app/Caches/PackageCourseList.php @@ -13,7 +13,7 @@ use App\Repos\Package as PackageRepo; class PackageCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/PointGift.php b/app/Caches/PointGift.php index e9adc52e..07f5afa0 100644 --- a/app/Caches/PointGift.php +++ b/app/Caches/PointGift.php @@ -12,7 +12,7 @@ use App\Repos\PointGift as PointGiftRepo; class PointGift extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/PointHotGiftList.php b/app/Caches/PointHotGiftList.php index 5fe9213a..529c479c 100644 --- a/app/Caches/PointHotGiftList.php +++ b/app/Caches/PointHotGiftList.php @@ -19,7 +19,7 @@ class PointHotGiftList extends Cache * * @var int */ - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; /** * 显示个数 diff --git a/app/Caches/Question.php b/app/Caches/Question.php index f350f6cc..b832fa1f 100644 --- a/app/Caches/Question.php +++ b/app/Caches/Question.php @@ -12,7 +12,7 @@ use App\Repos\Question as QuestionRepo; class Question extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TaggedArticleList.php b/app/Caches/TaggedArticleList.php index 8113b4f8..d57faf7b 100644 --- a/app/Caches/TaggedArticleList.php +++ b/app/Caches/TaggedArticleList.php @@ -15,7 +15,7 @@ class TaggedArticleList extends Cache protected $limit = 5; - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TaggedQuestionList.php b/app/Caches/TaggedQuestionList.php index d563dabe..7495823b 100644 --- a/app/Caches/TaggedQuestionList.php +++ b/app/Caches/TaggedQuestionList.php @@ -15,7 +15,7 @@ class TaggedQuestionList extends Cache protected $limit = 5; - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TopAnswererList.php b/app/Caches/TopAnswererList.php index fe881f5d..37991604 100644 --- a/app/Caches/TopAnswererList.php +++ b/app/Caches/TopAnswererList.php @@ -16,7 +16,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class TopAnswererList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TopAuthorList.php b/app/Caches/TopAuthorList.php index 48153879..882e4cab 100644 --- a/app/Caches/TopAuthorList.php +++ b/app/Caches/TopAuthorList.php @@ -16,7 +16,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class TopAuthorList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/User.php b/app/Caches/User.php index 9e0825d3..9f8ece22 100644 --- a/app/Caches/User.php +++ b/app/Caches/User.php @@ -12,7 +12,7 @@ use App\Repos\User as UserRepo; class User extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/UserDailyCounter.php b/app/Caches/UserDailyCounter.php index afda376e..19f59830 100644 --- a/app/Caches/UserDailyCounter.php +++ b/app/Caches/UserDailyCounter.php @@ -10,7 +10,7 @@ namespace App\Caches; class UserDailyCounter extends Counter { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Http/Home/Controllers/HelpController.php b/app/Http/Home/Controllers/HelpController.php index ff1dfc70..2de44d92 100644 --- a/app/Http/Home/Controllers/HelpController.php +++ b/app/Http/Home/Controllers/HelpController.php @@ -8,7 +8,6 @@ namespace App\Http\Home\Controllers; use App\Http\Home\Services\FullH5Url as FullH5UrlService; -use App\Http\Home\Services\Index as IndexService; use App\Services\Logic\Help\HelpInfo as HelpInfoService; use App\Services\Logic\Help\HelpList as HelpListService; @@ -30,8 +29,6 @@ class HelpController extends Controller return $this->response->redirect($location); } - $featuredCourses = $this->getFeaturedCourses(); - $service = new HelpListService(); $items = $service->handle(); @@ -39,7 +36,6 @@ class HelpController extends Controller $this->seo->prependTitle('帮助'); $this->view->setVar('items', $items); - $this->view->setVar('featured_courses', $featuredCourses); } /** @@ -66,19 +62,9 @@ class HelpController extends Controller $this->notFound(); } - $featuredCourses = $this->getFeaturedCourses(); - $this->seo->prependTitle(['帮助', $help['title']]); $this->view->setVar('help', $help); - $this->view->setVar('featured_courses', $featuredCourses); - } - - protected function getFeaturedCourses() - { - $service = new IndexService(); - - return $service->getSimpleFeaturedCourses(); } } diff --git a/app/Http/Home/Controllers/WidgetController.php b/app/Http/Home/Controllers/WidgetController.php index 1df05810..1d558745 100644 --- a/app/Http/Home/Controllers/WidgetController.php +++ b/app/Http/Home/Controllers/WidgetController.php @@ -7,6 +7,8 @@ namespace App\Http\Home\Controllers; +use App\Caches\FeaturedArticleList as FeaturedArticleListCache; +use App\Caches\FeaturedCourseList as FeaturedCourseListCache; use App\Services\Logic\Article\TopAuthorList as TopAuthorListService; use App\Services\Logic\Question\HotQuestionList as HotQuestionListService; use App\Services\Logic\Question\TopAnswererList as TopAnswererListService; @@ -33,6 +35,34 @@ class WidgetController extends Controller $this->view->setVar('tags', $pager->items); } + /** + * @Get("/featured/courses", name="home.widget.featured_courses") + */ + public function featuredCoursesAction() + { + $cache = new FeaturedCourseListCache(); + + $courses = $cache->get(); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('widget/featured_courses'); + $this->view->setVar('courses', $courses); + } + + /** + * @Get("/featured/articles", name="home.widget.featured_articles") + */ + public function featuredArticlesAction() + { + $cache = new FeaturedArticleListCache(); + + $articles = $cache->get(); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('widget/featured_articles'); + $this->view->setVar('articles', $articles); + } + /** * @Get("/hot/questions", name="home.widget.hot_questions") */ diff --git a/app/Http/Home/Views/help/index.volt b/app/Http/Home/Views/help/index.volt index 71003dcb..b4078aae 100644 --- a/app/Http/Home/Views/help/index.volt +++ b/app/Http/Home/Views/help/index.volt @@ -2,7 +2,7 @@ {% block content %} - {{ partial('macros/course') }} + {% set courses_url = url({'for':'home.widget.featured_courses'}) %}
- {% if featured_courses %} - - {% endif %} +
{% endblock %} -{% block include_js %} +{% block inline_js %} - {{ js_include('home/js/help.js') }} + {% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Views/help/show.volt b/app/Http/Home/Views/help/show.volt index a816ca07..b243fd1a 100644 --- a/app/Http/Home/Views/help/show.volt +++ b/app/Http/Home/Views/help/show.volt @@ -2,10 +2,7 @@ {% block content %} - {{ partial('macros/course') }} - - {% set share_url = share_url('help',help.id,auth_user.id) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} + {% set courses_url = url({'for':'home.widget.featured_courses'}) %}
@@ -27,31 +19,29 @@
- {% if featured_courses %} - - {% endif %} +
-
- - - -
- {% endblock %} {% block link_css %} {{ css_link('home/css/content.css') }} +{% endblock %} + +{% block inline_js %} + + + {% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Views/page/show.volt b/app/Http/Home/Views/page/show.volt index 67ee4643..39938998 100644 --- a/app/Http/Home/Views/page/show.volt +++ b/app/Http/Home/Views/page/show.volt @@ -2,21 +2,13 @@ {% block content %} - {{ partial('macros/course') }} - - {% set share_url = share_url('page',page.id,auth_user.id) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} + {% set courses_url = url({'for':'home.widget.featured_courses'}) %}
@@ -26,31 +18,29 @@
- {% if featured_courses %} - - {% endif %} +
-
- - - -
- {% endblock %} {% block link_css %} {{ css_link('home/css/content.css') }} +{% endblock %} + +{% block inline_js %} + + + {% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Views/widget/featured_articles.volt b/app/Http/Home/Views/widget/featured_articles.volt new file mode 100644 index 00000000..18a2e213 --- /dev/null +++ b/app/Http/Home/Views/widget/featured_articles.volt @@ -0,0 +1,20 @@ +{% if articles|length > 0 %} +
+
推荐文章
+
+
+ {% for article in articles %} + {% set article_url = url({'for':'home.article.show','id':article.id}) %} + +
+ {{ article.view_count }} 浏览 + + {{ article.comment_count }} 评论 +
+ {% endfor %} +
+
+
+{% endif %} \ No newline at end of file diff --git a/app/Http/Home/Views/widget/featured_courses.volt b/app/Http/Home/Views/widget/featured_courses.volt new file mode 100644 index 00000000..ee00a808 --- /dev/null +++ b/app/Http/Home/Views/widget/featured_courses.volt @@ -0,0 +1,12 @@ +{{ partial('macros/course') }} + +{% if courses|length > 0 %} +
+
推荐课程
+
+ {% for course in courses %} + {{ sidebar_course_card(course) }} + {% endfor %} +
+
+{% endif %} diff --git a/public/static/home/js/help.js b/public/static/home/js/help.js deleted file mode 100644 index 0ccee9c2..00000000 --- a/public/static/home/js/help.js +++ /dev/null @@ -1,10 +0,0 @@ -layui.use(['jquery', 'helper'], function () { - - var $ = layui.jquery; - var helper = layui.helper; - - $('.btn-cs').on('click', function () { - helper.cs(); - }); - -}); \ No newline at end of file From ce2329a71c6f36679f0650afc8556f6780cde15b Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 10:55:17 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Controllers/StudentController.php | 8 ++++++-- app/Http/Admin/Services/Student.php | 3 ++- app/Http/Admin/Views/student/list.volt | 9 +++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Http/Admin/Controllers/StudentController.php b/app/Http/Admin/Controllers/StudentController.php index b846002f..324c6943 100644 --- a/app/Http/Admin/Controllers/StudentController.php +++ b/app/Http/Admin/Controllers/StudentController.php @@ -20,11 +20,13 @@ class StudentController extends Controller */ public function searchAction() { + $courseId = $this->request->getQuery('course_id', 'int', 0); + $studentService = new StudentService(); $sourceTypes = $studentService->getSourceTypes(); - $xmCourses = $studentService->getXmCourses('all'); + $xmCourses = $studentService->getXmCourses('all', $courseId); $this->view->setVar('source_types', $sourceTypes); $this->view->setVar('xm_courses', $xmCourses); @@ -56,9 +58,11 @@ class StudentController extends Controller */ public function addAction() { + $courseId = $this->request->getQuery('course_id', 'int', 0); + $studentService = new StudentService(); - $xmCourses = $studentService->getXmCourses('charge'); + $xmCourses = $studentService->getXmCourses('all', $courseId); $this->view->setVar('xm_courses', $xmCourses); } diff --git a/app/Http/Admin/Services/Student.php b/app/Http/Admin/Services/Student.php index d583d320..1743e513 100644 --- a/app/Http/Admin/Services/Student.php +++ b/app/Http/Admin/Services/Student.php @@ -20,7 +20,7 @@ use App\Validators\CourseUser as CourseUserValidator; class Student extends Service { - public function getXmCourses($scope = 'all') + public function getXmCourses($scope = 'all', $courseId = 0) { $courseRepo = new CourseRepo(); @@ -46,6 +46,7 @@ class Student extends Service $result[] = [ 'name' => sprintf('%s - %s(¥%0.2f)', $item->id, $item->title, $item->market_price), 'value' => $item->id, + 'selected' => $item->id == $courseId, ]; } diff --git a/app/Http/Admin/Views/student/list.volt b/app/Http/Admin/Views/student/list.volt index 2be6a8c1..7f3dfd71 100644 --- a/app/Http/Admin/Views/student/list.volt +++ b/app/Http/Admin/Views/student/list.volt @@ -18,8 +18,13 @@ {% endif %} {%- endmacro %} - {% set add_url = url({'for':'admin.student.add'}) %} - {% set search_url = url({'for':'admin.student.search'}) %} + {% if course %} + {% set add_url = url({'for':'admin.student.add'},{'course_id':course.id}) %} + {% set search_url = url({'for':'admin.student.search'},{'course_id':course.id}) %} + {% else %} + {% set add_url = url({'for':'admin.student.add'}) %} + {% set search_url = url({'for':'admin.student.search'}) %} + {% endif %}
From fb5feb075971a16aa34489c7895525e6273688fa Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 11:32:59 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Logic/Notice/External/AccountLogin.php | 13 ++----------- .../Logic/Notice/External/ConsultReply.php | 13 +++---------- .../Logic/Notice/External/LiveBegin.php | 16 +++------------- .../Logic/Notice/External/OrderFinish.php | 13 +++---------- .../Logic/Notice/External/PointGoodsDeliver.php | 17 +++++------------ .../Logic/Notice/External/RefundFinish.php | 13 +++---------- .../Logic/Notice/External/Sms/ConsultReply.php | 6 ++---- .../Logic/Notice/External/Sms/GoodsDeliver.php | 10 ++++------ .../Logic/Notice/External/Sms/LiveBegin.php | 10 ++++------ .../Logic/Notice/External/Sms/OrderFinish.php | 6 ++---- .../Logic/Notice/External/Sms/RefundFinish.php | 6 ++---- .../Notice/External/WeChat/AccountLogin.php | 13 +++++++++---- .../Notice/External/WeChat/ConsultReply.php | 13 +++++++++---- .../Notice/External/WeChat/GoodsDeliver.php | 12 ++++++++---- .../Logic/Notice/External/WeChat/LiveBegin.php | 13 +++++++++---- .../Notice/External/WeChat/OrderFinish.php | 12 ++++++++---- .../Notice/External/WeChat/RefundFinish.php | 11 ++++++++--- 17 files changed, 84 insertions(+), 113 deletions(-) diff --git a/app/Services/Logic/Notice/External/AccountLogin.php b/app/Services/Logic/Notice/External/AccountLogin.php index 3b146df7..9d63913d 100644 --- a/app/Services/Logic/Notice/External/AccountLogin.php +++ b/app/Services/Logic/Notice/External/AccountLogin.php @@ -9,7 +9,6 @@ namespace App\Services\Logic\Notice\External; use App\Models\Task as TaskModel; use App\Models\User as UserModel; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Notice\External\WeChat\AccountLogin as WeChatAccountLoginNotice; use App\Services\Logic\Service as LogicService; use App\Traits\Client as ClientTrait; @@ -23,19 +22,11 @@ class AccountLogin extends LogicService { $wechatNoticeEnabled = $this->wechatNoticeEnabled(); - if (!$wechatNoticeEnabled) return; - $params = $task->item_info; - $userId = $task->item_info['user']['id']; - - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($userId); - - if ($subscribe) { + if ($wechatNoticeEnabled) { $notice = new WeChatAccountLoginNotice(); - $notice->handle($subscribe, $params); + $notice->handle($params); } } diff --git a/app/Services/Logic/Notice/External/ConsultReply.php b/app/Services/Logic/Notice/External/ConsultReply.php index a5d7a35a..991d4920 100644 --- a/app/Services/Logic/Notice/External/ConsultReply.php +++ b/app/Services/Logic/Notice/External/ConsultReply.php @@ -12,7 +12,6 @@ use App\Models\Task as TaskModel; use App\Repos\Consult as ConsultRepo; use App\Repos\Course as CourseRepo; use App\Repos\User as UserRepo; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Notice\External\Sms\ConsultReply as SmsConsultReplyNotice; use App\Services\Logic\Notice\External\WeChat\ConsultReply as WeChatConsultReplyNotice; use App\Services\Logic\Service as LogicService; @@ -25,8 +24,6 @@ class ConsultReply extends LogicService $wechatNoticeEnabled = $this->wechatNoticeEnabled(); $smsNoticeEnabled = $this->smsNoticeEnabled(); - if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; - $consultId = $task->item_info['consult']['id']; $consultRepo = new ConsultRepo(); @@ -65,18 +62,14 @@ class ConsultReply extends LogicService ], ]; - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($consult->owner_id); - - if ($wechatNoticeEnabled && $subscribe) { + if ($wechatNoticeEnabled) { $notice = new WeChatConsultReplyNotice(); - $notice->handle($subscribe, $params); + $notice->handle($params); } if ($smsNoticeEnabled) { $notice = new SmsConsultReplyNotice(); - $notice->handle($user, $params); + $notice->handle($params); } } diff --git a/app/Services/Logic/Notice/External/LiveBegin.php b/app/Services/Logic/Notice/External/LiveBegin.php index 84633e69..0461736c 100644 --- a/app/Services/Logic/Notice/External/LiveBegin.php +++ b/app/Services/Logic/Notice/External/LiveBegin.php @@ -13,7 +13,6 @@ use App\Models\Task as TaskModel; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; use App\Repos\User as UserRepo; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Notice\External\Sms\LiveBegin as SmsLiveBeginNotice; use App\Services\Logic\Notice\External\WeChat\LiveBegin as WeChatLiveBeginNotice; use App\Services\Logic\Service as LogicService; @@ -26,8 +25,6 @@ class LiveBegin extends LogicService $wechatNoticeEnabled = $this->wechatNoticeEnabled(); $smsNoticeEnabled = $this->smsNoticeEnabled(); - if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; - $courseUser = $task->item_info['course_user']; $chapterId = $task->item_info['chapter']['id']; @@ -60,21 +57,16 @@ class LiveBegin extends LogicService 'start_time' => $chapter->attrs['start_time'], 'end_time' => $chapter->attrs['end_time'], ], - 'course_user' => $courseUser, ]; - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($user->id); - - if ($wechatNoticeEnabled && $subscribe) { + if ($wechatNoticeEnabled) { $notice = new WeChatLiveBeginNotice(); - $notice->handle($subscribe, $params); + $notice->handle($params); } if ($smsNoticeEnabled) { $notice = new SmsLiveBeginNotice(); - $notice->handle($user, $params); + $notice->handle($params); } } @@ -91,8 +83,6 @@ class LiveBegin extends LogicService 'course_user' => [ 'course_id' => $courseUser->course_id, 'user_id' => $courseUser->user_id, - 'role_type' => $courseUser->role_type, - 'source_type' => $courseUser->role_type, ], 'chapter' => [ 'id' => $chapter->id, diff --git a/app/Services/Logic/Notice/External/OrderFinish.php b/app/Services/Logic/Notice/External/OrderFinish.php index 05ffd272..789138d0 100644 --- a/app/Services/Logic/Notice/External/OrderFinish.php +++ b/app/Services/Logic/Notice/External/OrderFinish.php @@ -11,7 +11,6 @@ use App\Models\Order as OrderModel; use App\Models\Task as TaskModel; use App\Repos\Order as OrderRepo; use App\Repos\User as UserRepo; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Notice\External\Sms\OrderFinish as SmsOrderFinishNotice; use App\Services\Logic\Notice\External\WeChat\OrderFinish as WeChatOrderFinishNotice; use App\Services\Logic\Service as LogicService; @@ -24,8 +23,6 @@ class OrderFinish extends LogicService $wechatNoticeEnabled = $this->wechatNoticeEnabled(); $smsNoticeEnabled = $this->smsNoticeEnabled(); - if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; - $orderId = $task->item_info['order']['id']; $orderRepo = new OrderRepo(); @@ -50,18 +47,14 @@ class OrderFinish extends LogicService ], ]; - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($order->owner_id); - - if ($wechatNoticeEnabled && $subscribe) { + if ($wechatNoticeEnabled) { $notice = new WeChatOrderFinishNotice(); - $notice->handle($subscribe, $params); + $notice->handle($params); } if ($smsNoticeEnabled) { $notice = new SmsOrderFinishNotice(); - $notice->handle($user, $params); + $notice->handle($params); } } diff --git a/app/Services/Logic/Notice/External/PointGoodsDeliver.php b/app/Services/Logic/Notice/External/PointGoodsDeliver.php index ab886944..f299cd21 100644 --- a/app/Services/Logic/Notice/External/PointGoodsDeliver.php +++ b/app/Services/Logic/Notice/External/PointGoodsDeliver.php @@ -11,7 +11,6 @@ use App\Models\PointGiftRedeem as PointGiftRedeemModel; use App\Models\Task as TaskModel; use App\Repos\PointGiftRedeem as PointGiftRedeemRepo; use App\Repos\User as UserRepo; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Notice\External\Sms\GoodsDeliver as SmsGoodsDeliverNotice; use App\Services\Logic\Notice\External\WeChat\GoodsDeliver as WeChatGoodsDeliverNotice; use App\Services\Logic\Service as LogicService; @@ -24,9 +23,7 @@ class PointGoodsDeliver extends LogicService $wechatNoticeEnabled = $this->wechatNoticeEnabled(); $smsNoticeEnabled = $this->smsNoticeEnabled(); - if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; - - $redeemId = $task->item_info['point_redeem']['id']; + $redeemId = $task->item_info['redeem']['id']; $redeemRepo = new PointGiftRedeemRepo(); @@ -46,18 +43,14 @@ class PointGoodsDeliver extends LogicService 'deliver_time' => time(), ]; - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($user->id); - - if ($wechatNoticeEnabled && $subscribe) { + if ($wechatNoticeEnabled) { $notice = new WeChatGoodsDeliverNotice(); - $notice->handle($subscribe, $params); + $notice->handle($params); } if ($smsNoticeEnabled) { $notice = new SmsGoodsDeliverNotice(); - $notice->handle($user, $params); + $notice->handle($params); } } @@ -71,7 +64,7 @@ class PointGoodsDeliver extends LogicService $task = new TaskModel(); $itemInfo = [ - 'point_gift_redeem' => ['id' => $redeem->id], + 'redeem' => ['id' => $redeem->id], ]; $task->item_id = $redeem->id; diff --git a/app/Services/Logic/Notice/External/RefundFinish.php b/app/Services/Logic/Notice/External/RefundFinish.php index baaefe5f..104c4720 100644 --- a/app/Services/Logic/Notice/External/RefundFinish.php +++ b/app/Services/Logic/Notice/External/RefundFinish.php @@ -11,7 +11,6 @@ use App\Models\Refund as RefundModel; use App\Models\Task as TaskModel; use App\Repos\Refund as RefundRepo; use App\Repos\User as UserRepo; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Notice\External\Sms\RefundFinish as SmsRefundFinishNotice; use App\Services\Logic\Notice\External\WeChat\RefundFinish as WeChatRefundFinishNotice; use App\Services\Logic\Service as LogicService; @@ -24,8 +23,6 @@ class RefundFinish extends LogicService $wechatNoticeEnabled = $this->wechatNoticeEnabled(); $smsNoticeEnabled = $this->smsNoticeEnabled(); - if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; - $refundId = $task->item_info['refund']['id']; $refundRepo = new RefundRepo(); @@ -50,18 +47,14 @@ class RefundFinish extends LogicService ], ]; - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($refund->owner_id); - - if ($wechatNoticeEnabled && $subscribe) { + if ($wechatNoticeEnabled) { $notice = new WeChatRefundFinishNotice(); - $notice->handle($subscribe, $params); + $notice->handle($params); } if ($smsNoticeEnabled) { $notice = new SmsRefundFinishNotice(); - $notice->handle($user, $params); + $notice->handle($params); } } diff --git a/app/Services/Logic/Notice/External/Sms/ConsultReply.php b/app/Services/Logic/Notice/External/Sms/ConsultReply.php index 74ee6a63..ab75219c 100644 --- a/app/Services/Logic/Notice/External/Sms/ConsultReply.php +++ b/app/Services/Logic/Notice/External/Sms/ConsultReply.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\Sms; -use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Services\Smser; @@ -17,15 +16,14 @@ class ConsultReply extends Smser protected $templateCode = 'consult_reply'; /** - * @param UserModel $user * @param array $params * @return bool|null */ - public function handle(UserModel $user, array $params) + public function handle(array $params) { $accountRepo = new AccountRepo(); - $account = $accountRepo->findById($user->id); + $account = $accountRepo->findById($params['user']['id']); if (!$account->phone) return null; diff --git a/app/Services/Logic/Notice/External/Sms/GoodsDeliver.php b/app/Services/Logic/Notice/External/Sms/GoodsDeliver.php index 69324c56..a83e9fc8 100644 --- a/app/Services/Logic/Notice/External/Sms/GoodsDeliver.php +++ b/app/Services/Logic/Notice/External/Sms/GoodsDeliver.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\Sms; -use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Services\Smser; @@ -17,22 +16,21 @@ class GoodsDeliver extends Smser protected $templateCode = 'goods_deliver'; /** - * @param UserModel $user * @param array $params * @return bool|null */ - public function handle(UserModel $user, array $params) + public function handle(array $params) { - $params['deliver_time'] = date('Y-m-d H:i', $params['deliver_time']); - $accountRepo = new AccountRepo(); - $account = $accountRepo->findById($user->id); + $account = $accountRepo->findById($params['user']['id']); if (!$account->phone) return null; $templateId = $this->getTemplateId($this->templateCode); + $params['deliver_time'] = date('Y-m-d H:i', $params['deliver_time']); + $params = [ $params['goods_name'], $params['order_sn'], diff --git a/app/Services/Logic/Notice/External/Sms/LiveBegin.php b/app/Services/Logic/Notice/External/Sms/LiveBegin.php index 0ee9bf9f..fef22b23 100644 --- a/app/Services/Logic/Notice/External/Sms/LiveBegin.php +++ b/app/Services/Logic/Notice/External/Sms/LiveBegin.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\Sms; -use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Services\Smser; @@ -17,20 +16,19 @@ class LiveBegin extends Smser protected $templateCode = 'live_begin'; /** - * @param UserModel $user * @param array $params * @return bool|null */ - public function handle(UserModel $user, array $params) + public function handle(array $params) { - $params['live']['start_time'] = date('H:i', $params['live']['start_time']); - $accountRepo = new AccountRepo(); - $account = $accountRepo->findById($user->id); + $account = $accountRepo->findById($params['user']['id']); if (!$account->phone) return null; + $params['live']['start_time'] = date('H:i', $params['live']['start_time']); + $params = [ $params['course']['title'], $params['chapter']['title'], diff --git a/app/Services/Logic/Notice/External/Sms/OrderFinish.php b/app/Services/Logic/Notice/External/Sms/OrderFinish.php index 8ae436f6..881e1c76 100644 --- a/app/Services/Logic/Notice/External/Sms/OrderFinish.php +++ b/app/Services/Logic/Notice/External/Sms/OrderFinish.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\Sms; -use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Services\Smser; @@ -17,15 +16,14 @@ class OrderFinish extends Smser protected $templateCode = 'order_finish'; /** - * @param UserModel $user * @param array $params * @return bool|null */ - public function handle(UserModel $user, array $params) + public function handle(array $params) { $accountRepo = new AccountRepo(); - $account = $accountRepo->findById($user->id); + $account = $accountRepo->findById($params['user']['id']); if (!$account->phone) return null; diff --git a/app/Services/Logic/Notice/External/Sms/RefundFinish.php b/app/Services/Logic/Notice/External/Sms/RefundFinish.php index 2d7c59b3..a059a623 100644 --- a/app/Services/Logic/Notice/External/Sms/RefundFinish.php +++ b/app/Services/Logic/Notice/External/Sms/RefundFinish.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\Sms; -use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Services\Smser; @@ -17,15 +16,14 @@ class RefundFinish extends Smser protected $templateCode = 'refund_finish'; /** - * @param UserModel $user * @param array $params * @return bool|null */ - public function handle(UserModel $user, array $params) + public function handle(array $params) { $accountRepo = new AccountRepo(); - $account = $accountRepo->findById($user->id); + $account = $accountRepo->findById($params['user']['id']); if (!$account->phone) return null; diff --git a/app/Services/Logic/Notice/External/WeChat/AccountLogin.php b/app/Services/Logic/Notice/External/WeChat/AccountLogin.php index 09410124..36208a08 100644 --- a/app/Services/Logic/Notice/External/WeChat/AccountLogin.php +++ b/app/Services/Logic/Notice/External/WeChat/AccountLogin.php @@ -7,7 +7,7 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class AccountLogin extends WeChatNotice @@ -16,12 +16,17 @@ class AccountLogin extends WeChatNotice protected $templateCode = 'account_login'; /** - * @param WeChatSubscribeModel $subscribe * @param array $params - * @return bool + * @return bool|null */ - public function handle(WeChatSubscribeModel $subscribe, array $params) + public function handle(array $params) { + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + + if (!$subscribe) return null; + $first = '你好,登录系统成功!'; $remark = '如果非本人操作,请立即修改密码哦!'; diff --git a/app/Services/Logic/Notice/External/WeChat/ConsultReply.php b/app/Services/Logic/Notice/External/WeChat/ConsultReply.php index ad13f2c3..330dfbc2 100644 --- a/app/Services/Logic/Notice/External/WeChat/ConsultReply.php +++ b/app/Services/Logic/Notice/External/WeChat/ConsultReply.php @@ -7,7 +7,7 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class ConsultReply extends WeChatNotice @@ -16,12 +16,17 @@ class ConsultReply extends WeChatNotice protected $templateCode = 'consult_reply'; /** - * @param WeChatSubscribeModel $subscribe * @param array $params - * @return bool + * @return bool|null */ - public function handle(WeChatSubscribeModel $subscribe, array $params) + public function handle(array $params) { + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + + if (!$subscribe) return null; + $first = sprintf('%s 回复了你的咨询!', $params['replier']['name']); $remark = '如果还有其它疑问,请和我们保持联系哦!'; diff --git a/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php b/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php index 7d61787d..70304e3b 100644 --- a/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php +++ b/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php @@ -7,7 +7,7 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class GoodsDeliver extends WeChatNotice @@ -16,12 +16,16 @@ class GoodsDeliver extends WeChatNotice protected $templateCode = 'goods_deliver'; /** - * @param WeChatSubscribeModel $subscribe * @param array $params - * @return bool + * @return bool|null */ - public function handle(WeChatSubscribeModel $subscribe, $params) + public function handle($params) { + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + + if (!$subscribe) return null; $first = '发货已处理完成!'; $remark = '感谢您的支持,有疑问请联系客服哦!'; diff --git a/app/Services/Logic/Notice/External/WeChat/LiveBegin.php b/app/Services/Logic/Notice/External/WeChat/LiveBegin.php index 228e9d2d..3db3d77f 100644 --- a/app/Services/Logic/Notice/External/WeChat/LiveBegin.php +++ b/app/Services/Logic/Notice/External/WeChat/LiveBegin.php @@ -7,7 +7,7 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class LiveBegin extends WeChatNotice @@ -16,12 +16,17 @@ class LiveBegin extends WeChatNotice protected $templateCode = 'live_begin'; /** - * @param WeChatSubscribeModel $subscribe * @param array $params - * @return bool + * @return bool|null */ - public function handle(WeChatSubscribeModel $subscribe, array $params) + public function handle(array $params) { + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + + if (!$subscribe) return null; + $first = '你参与的课程直播就要开始了!'; $startTime = date('H:i', $params['live']['start_time']); diff --git a/app/Services/Logic/Notice/External/WeChat/OrderFinish.php b/app/Services/Logic/Notice/External/WeChat/OrderFinish.php index a8927dcc..b242b881 100644 --- a/app/Services/Logic/Notice/External/WeChat/OrderFinish.php +++ b/app/Services/Logic/Notice/External/WeChat/OrderFinish.php @@ -7,7 +7,7 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class OrderFinish extends WeChatNotice @@ -16,12 +16,16 @@ class OrderFinish extends WeChatNotice protected $templateCode = 'order_finish'; /** - * @param WeChatSubscribeModel $subscribe * @param array $params - * @return bool + * @return bool|null */ - public function handle(WeChatSubscribeModel $subscribe, $params) + public function handle($params) { + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + + if (!$subscribe) return null; $first = '订单已处理完成!'; $remark = '感谢您的支持,有疑问请联系客服哦!'; diff --git a/app/Services/Logic/Notice/External/WeChat/RefundFinish.php b/app/Services/Logic/Notice/External/WeChat/RefundFinish.php index 11d4e91c..da710593 100644 --- a/app/Services/Logic/Notice/External/WeChat/RefundFinish.php +++ b/app/Services/Logic/Notice/External/WeChat/RefundFinish.php @@ -7,7 +7,7 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class RefundFinish extends WeChatNotice @@ -16,12 +16,17 @@ class RefundFinish extends WeChatNotice protected $templateCode = 'refund_finish'; /** - * @param WeChatSubscribeModel $subscribe * @param array $params * @return bool */ - public function handle(WeChatSubscribeModel $subscribe, array $params) + public function handle(array $params) { + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + + if (!$subscribe) return null; + $first = '退款已处理完成!'; $remark = '感谢您的支持,有疑问请联系客服哦!'; From f7a3c0d73643f0be5475ed3f2c4fe227f9d40fc3 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 11:36:55 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E4=BC=98=E5=8C=96Providers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Providers/Annotation.php | 8 ++++++-- app/Providers/Cache.php | 2 +- app/Providers/Database.php | 3 +++ app/Providers/MetaData.php | 8 ++++++-- app/Providers/Session.php | 4 ++-- app/Providers/Volt.php | 10 ++++++++++ 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/Providers/Annotation.php b/app/Providers/Annotation.php index f4d4ec68..28273a94 100644 --- a/app/Providers/Annotation.php +++ b/app/Providers/Annotation.php @@ -26,15 +26,19 @@ class Annotation extends Provider $this->di->setShared($this->serviceName, function () use ($config) { if ($config->get('env') == ENV_DEV) { + $annotations = new MemoryAnnotations(); + } else { + $statsKey = '_ANNOTATION_'; + $annotations = new RedisAnnotations([ 'host' => $config->path('redis.host'), 'port' => $config->path('redis.port'), 'auth' => $config->path('redis.auth'), - 'index' => $config->path('redis.index') ?: 0, - 'lifetime' => $config->path('annotation.lifetime') ?: 30 * 86400, + 'index' => $config->path('redis.index'), + 'lifetime' => $config->path('annotation.lifetime'), 'prefix' => $statsKey . ':', 'statsKey' => $statsKey, ]); diff --git a/app/Providers/Cache.php b/app/Providers/Cache.php index 283dfcd7..dadaed95 100644 --- a/app/Providers/Cache.php +++ b/app/Providers/Cache.php @@ -33,7 +33,7 @@ class Cache extends Provider 'host' => $config->path('redis.host'), 'port' => $config->path('redis.port'), 'auth' => $config->path('redis.auth'), - 'index' => $config->path('redis.index') ?: 0, + 'index' => $config->path('redis.index'), ]); }); } diff --git a/app/Providers/Database.php b/app/Providers/Database.php index e4116a64..d39f3dfa 100644 --- a/app/Providers/Database.php +++ b/app/Providers/Database.php @@ -42,8 +42,11 @@ class Database extends Provider $connection = new MySqlAdapter($options); if ($config->get('env') == ENV_DEV) { + $eventsManager = new EventsManager(); + $eventsManager->attach('db', new DbListener()); + $connection->setEventsManager($eventsManager); } diff --git a/app/Providers/MetaData.php b/app/Providers/MetaData.php index 7c6b4426..9f0cdbb2 100644 --- a/app/Providers/MetaData.php +++ b/app/Providers/MetaData.php @@ -26,15 +26,19 @@ class MetaData extends Provider $this->di->setShared($this->serviceName, function () use ($config) { if ($config->get('env') == ENV_DEV) { + $metaData = new MemoryMetaData(); + } else { + $statsKey = '_METADATA_'; + $metaData = new RedisMetaData([ 'host' => $config->path('redis.host'), 'port' => $config->path('redis.port'), 'auth' => $config->path('redis.auth'), - 'index' => $config->path('redis.index') ?: 0, - 'lifetime' => $config->path('metadata.lifetime') ?: 30 * 86400, + 'index' => $config->path('redis.index'), + 'lifetime' => $config->path('metadata.lifetime'), 'prefix' => $statsKey . ':', 'statsKey' => $statsKey, ]); diff --git a/app/Providers/Session.php b/app/Providers/Session.php index 17226821..8bfdc2a3 100644 --- a/app/Providers/Session.php +++ b/app/Providers/Session.php @@ -28,8 +28,8 @@ class Session extends Provider 'host' => $config->path('redis.host'), 'port' => $config->path('redis.port'), 'auth' => $config->path('redis.auth'), - 'index' => $config->path('redis.index') ?: 0, - 'lifetime' => $config->path('session.lifetime') ?: 24 * 3600, + 'index' => $config->path('redis.index'), + 'lifetime' => $config->path('session.lifetime'), 'prefix' => '_SESSION_:', ]); diff --git a/app/Providers/Volt.php b/app/Providers/Volt.php index 1e4b4e3a..b2e469e5 100644 --- a/app/Providers/Volt.php +++ b/app/Providers/Volt.php @@ -99,6 +99,16 @@ class Volt extends Provider return 'kg_anonymous(' . $resolvedArgs . ')'; }); + $compiler->addFilter('split', function ($resolvedArgs, $exprArgs) use ($compiler) { + $firstArgument = $compiler->expression($exprArgs[0]['expr']); + if (isset($exprArgs[1])) { + $secondArgument = $compiler->expression($exprArgs[1]['expr']); + } else { + $secondArgument = ''; + } + return sprintf('explode(%s,%s)', $secondArgument, $firstArgument); + }); + return $volt; }); } From a72f44225fa3d9d105f47a683371d83ac6717b82 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 18:05:19 +0800 Subject: [PATCH 12/15] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E6=9D=83=E9=99=90=202.=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=92=89=E9=92=89=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Views/setting/dingtalk_robot.volt | 8 +-- app/Services/DingTalkNotice.php | 19 +++---- app/Services/Logic/ChapterTrait.php | 4 +- app/Services/Logic/Course/CourseInfo.php | 16 +++--- db/migrations/20230611193031.php | 51 +++++++++++++++++++ 5 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 db/migrations/20230611193031.php diff --git a/app/Http/Admin/Views/setting/dingtalk_robot.volt b/app/Http/Admin/Views/setting/dingtalk_robot.volt index 64bbb80e..cdc91e9a 100644 --- a/app/Http/Admin/Views/setting/dingtalk_robot.volt +++ b/app/Http/Admin/Views/setting/dingtalk_robot.volt @@ -14,15 +14,15 @@
- +
- +
- +
- +
diff --git a/app/Services/DingTalkNotice.php b/app/Services/DingTalkNotice.php index 713f6115..e1891e2c 100644 --- a/app/Services/DingTalkNotice.php +++ b/app/Services/DingTalkNotice.php @@ -135,24 +135,21 @@ class DingTalkNotice extends Service */ public function send($params) { - if (!isset($params['msgtype'])) { - $params['msgtype'] = 'text'; - } - + $webhookUrl = $this->settings['webhook_url']; $appSecret = $this->settings['app_secret']; - $appToken = $this->settings['app_token']; $timestamp = time() * 1000; $data = sprintf("%s\n%s", $timestamp, $appSecret); $sign = urlencode(base64_encode(hash_hmac('sha256', $data, $appSecret, true))); - $baseUrl = 'https://oapi.dingtalk.com/robot/send'; + $postUrl = $webhookUrl; - $postUrl = $baseUrl . '?' . http_build_query([ - 'access_token' => $appToken, - 'timestamp' => $timestamp, - 'sign' => $sign, - ]); + if (!empty($appSecret)) { + $postUrl = $webhookUrl . '&' . http_build_query([ + 'timestamp' => $timestamp, + 'sign' => $sign, + ]); + } try { diff --git a/app/Services/Logic/ChapterTrait.php b/app/Services/Logic/ChapterTrait.php index 937218c6..6a2c19a9 100644 --- a/app/Services/Logic/ChapterTrait.php +++ b/app/Services/Logic/ChapterTrait.php @@ -69,6 +69,8 @@ trait ChapterTrait public function setChapterUser(ChapterModel $chapter, UserModel $user) { + if ($user->id == 0) return; + $chapterUser = null; /** @@ -76,7 +78,7 @@ trait ChapterTrait */ $courseUser = $this->courseUser; - if ($user->id > 0 && $courseUser) { + if ($courseUser) { $chapterUserRepo = new ChapterUserRepo(); $chapterUser = $chapterUserRepo->findPlanChapterUser($chapter->id, $user->id, $courseUser->plan_id); } diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php index 5ecaeb0b..d3d822f3 100644 --- a/app/Services/Logic/Course/CourseInfo.php +++ b/app/Services/Logic/Course/CourseInfo.php @@ -66,16 +66,16 @@ class CourseInfo extends LogicService $caseModel = $course->attrs['end_date'] < date('Y-m-d'); } + if ($caseOwned && $casePrice && $caseModel) { + $me['allow_order'] = 1; + } + + if ($course->market_price == 0) { + $me['allow_reward'] = 1; + } + if ($user->id > 0) { - if ($caseOwned && $casePrice && $caseModel) { - $me['allow_order'] = 1; - } - - if ($course->market_price == 0) { - $me['allow_reward'] = 1; - } - $me['logged'] = 1; $favoriteRepo = new CourseFavoriteRepo(); diff --git a/db/migrations/20230611193031.php b/db/migrations/20230611193031.php new file mode 100644 index 00000000..33f19353 --- /dev/null +++ b/db/migrations/20230611193031.php @@ -0,0 +1,51 @@ +handleDingTalkRobotSettings(); + } + + protected function handleDingTalkRobotSettings() + { + $row = $this->getQueryBuilder() + ->select('*') + ->from('kg_setting') + ->where(['section' => 'dingtalk.robot']) + ->andWhere(['item_key' => 'app_token']) + ->execute()->fetch(PDO::FETCH_ASSOC); + + $webhookUrl = ''; + + /** + * 直接使用webhook地址,不用单独分离出access_token,简化用户操作 + */ + if (!empty($row['item_value'])) { + $webhookUrl = "https://oapi.dingtalk.com/robot/send?access_token={$row['item_value']}"; + } + + $rows = [ + [ + 'section' => 'dingtalk.robot', + 'item_key' => 'webhook_url', + 'item_value' => $webhookUrl, + ], + ]; + + $this->insertSettings($rows); + } + +} From 36ef6ca37b596b27c0a0553442977257d5cc7d45 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 18:55:31 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82handleMeInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Logic/Chapter/ChapterInfo.php | 87 ++++++++++++---------- app/Services/Logic/Course/CourseInfo.php | 35 ++++++--- 2 files changed, 70 insertions(+), 52 deletions(-) diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php index 58a01eea..cc7e34a4 100644 --- a/app/Services/Logic/Chapter/ChapterInfo.php +++ b/app/Services/Logic/Chapter/ChapterInfo.php @@ -75,47 +75,7 @@ class ChapterInfo extends LogicService $result['course'] = $service->handleCourseInfo($this->course); - $me = [ - 'role_type' => 0, - 'plan_id' => 0, - 'position' => 0, - 'logged' => 0, - 'joined' => 0, - 'owned' => 0, - 'liked' => 0, - ]; - - if ($this->joinedChapter) { - $me['joined'] = 1; - } - - if ($this->ownedChapter) { - $me['owned'] = 1; - } - - if ($user->id > 0) { - - $me['logged'] = 1; - - $likeRepo = new ChapterLikeRepo(); - - $like = $likeRepo->findChapterLike($chapter->id, $user->id); - - if ($like && $like->deleted == 0) { - $me['liked'] = 1; - } - - if ($this->courseUser) { - $me['role_type'] = $this->courseUser->role_type; - $me['plan_id'] = $this->courseUser->plan_id; - } - - if ($this->chapterUser) { - $me['position'] = $this->chapterUser->position; - } - } - - $result['me'] = $me; + $result['me'] = $this->handleMeInfo($chapter, $user); return $result; } @@ -179,6 +139,51 @@ class ChapterInfo extends LogicService $this->incrChapterUserCount($chapter); } + protected function handleMeInfo(ChapterModel $chapter, UserModel $user) + { + $me = [ + 'role_type' => 0, + 'plan_id' => 0, + 'position' => 0, + 'logged' => 0, + 'joined' => 0, + 'owned' => 0, + 'liked' => 0, + ]; + + if ($user->id > 0) { + + if ($this->joinedChapter) { + $me['joined'] = 1; + } + + if ($this->ownedChapter) { + $me['owned'] = 1; + } + + $me['logged'] = 1; + + $likeRepo = new ChapterLikeRepo(); + + $like = $likeRepo->findChapterLike($chapter->id, $user->id); + + if ($like && $like->deleted == 0) { + $me['liked'] = 1; + } + + if ($this->courseUser) { + $me['role_type'] = $this->courseUser->role_type; + $me['plan_id'] = $this->courseUser->plan_id; + } + + if ($this->chapterUser) { + $me['position'] = $this->chapterUser->position; + } + } + + return $me; + } + protected function incrUserCourseCount(UserModel $user) { $user->course_count += 1; diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php index d3d822f3..35132017 100644 --- a/app/Services/Logic/Course/CourseInfo.php +++ b/app/Services/Logic/Course/CourseInfo.php @@ -35,6 +35,13 @@ class CourseInfo extends LogicService $result = $service->handleBasicInfo($course); + $result['me'] = $this->handleMeInfo($course, $user); + + return $result; + } + + protected function handleMeInfo(CourseModel $course, UserModel $user) + { $me = [ 'plan_id' => 0, 'allow_order' => 0, @@ -47,14 +54,6 @@ class CourseInfo extends LogicService 'favorited' => 0, ]; - if ($this->joinedCourse) { - $me['joined'] = 1; - } - - if ($this->ownedCourse) { - $me['owned'] = 1; - } - $caseOwned = $this->ownedCourse == false; $casePrice = $course->market_price > 0; $caseModel = true; @@ -76,6 +75,22 @@ class CourseInfo extends LogicService if ($user->id > 0) { + if ($caseOwned && $casePrice && $caseModel) { + $me['allow_order'] = 1; + } + + if ($course->market_price == 0) { + $me['allow_reward'] = 1; + } + + if ($this->joinedCourse) { + $me['joined'] = 1; + } + + if ($this->ownedCourse) { + $me['owned'] = 1; + } + $me['logged'] = 1; $favoriteRepo = new CourseFavoriteRepo(); @@ -93,9 +108,7 @@ class CourseInfo extends LogicService } } - $result['me'] = $me; - - return $result; + return $me; } } From 9159e28b518590974ecb83e177d47f379641d758 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 19:40:44 +0800 Subject: [PATCH 14/15] v1.6.4 --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a8daee1..d58c45c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,19 @@ +### [v1.6.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.3)(2023-06-15) + +- 增加推荐课程等Widget +- 更新Composer包 +- 修正验证空口令问题 +- 优化订单确认页样式 +- 优化课程等Me相关信息 +- 优化分享URL +- 优化用户课程查找 +- 优化通知相关 +- 优化Providers +- 优化课程章节权限 +- 优化钉钉机器人 + ### [v1.6.3](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.3)(2023-05-08) + - 强化文章|提问|课程列表参数检查 - 优化HtmlPurifier内容过滤 - 优化排序条件和分页重复问题 From 41c4fc45b2635bf51dc31847858b68f1c5dbeee4 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 19:45:15 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7v1.6.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Library/AppInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index bd8308fd..1e291fc1 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://www.koogua.com'; - protected $version = '1.6.3'; + protected $version = '1.6.4'; public function __get($name) {