mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-24 08:51:43 +08:00
日常优化
This commit is contained in:
parent
65b5190a05
commit
138b9d45ce
58
app/Console/Migrations/V20230817240809.php
Normal file
58
app/Console/Migrations/V20230817240809.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 深圳市酷瓜软件有限公司
|
||||
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Console\Migrations;
|
||||
|
||||
use App\Models\Course as CourseModel;
|
||||
use App\Repos\Chapter as ChapterRepo;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
|
||||
class V20230817240809 extends Migration
|
||||
{
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->handleCourseResourceCount();
|
||||
}
|
||||
|
||||
protected function handleCourseResourceCount()
|
||||
{
|
||||
$courses = CourseModel::find();
|
||||
|
||||
if ($courses->count() == 0) return;
|
||||
|
||||
foreach ($courses as $course) {
|
||||
if ($course->resource_count > 0) {
|
||||
$this->recountCourseResources($course);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function recountCourseResources(CourseModel $course)
|
||||
{
|
||||
$courseRepo = new CourseRepo();
|
||||
|
||||
$lessons = $courseRepo->findLessons($course->id);
|
||||
|
||||
$chapterRepo = new ChapterRepo();
|
||||
|
||||
$resourceCount = 0;
|
||||
|
||||
if ($lessons->count() > 0) {
|
||||
foreach ($lessons as $lesson) {
|
||||
if ($lesson->deleted == 0) {
|
||||
$resourceCount += $chapterRepo->countResources($lesson->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$course->resource_count = $resourceCount;
|
||||
|
||||
$course->update();
|
||||
}
|
||||
|
||||
}
|
@ -59,7 +59,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function editAction($id)
|
||||
{
|
||||
$pageService = new PageService;
|
||||
$pageService = new PageService();
|
||||
|
||||
$page = $pageService->getPage($id);
|
||||
|
||||
|
@ -9,6 +9,7 @@ namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Builders\ArticleList as ArticleListBuilder;
|
||||
use App\Builders\ReportList as ReportListBuilder;
|
||||
use App\Caches\Article as ArticleCache;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Library\Utils\Word as WordUtil;
|
||||
use App\Models\Article as ArticleModel;
|
||||
@ -26,6 +27,7 @@ use App\Services\Logic\Article\XmTagList as XmTagListService;
|
||||
use App\Services\Logic\Notice\Internal\ArticleApproved as ArticleApprovedNotice;
|
||||
use App\Services\Logic\Notice\Internal\ArticleRejected as ArticleRejectedNotice;
|
||||
use App\Services\Logic\Point\History\ArticlePost as ArticlePostPointHistory;
|
||||
use App\Services\Sync\ArticleIndex as ArticleIndexSync;
|
||||
use App\Validators\Article as ArticleValidator;
|
||||
|
||||
class Article extends Service
|
||||
@ -140,7 +142,8 @@ class Article extends Service
|
||||
$article->create();
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
|
||||
$this->rebuildArticleCache($article);
|
||||
$this->rebuildArticleIndex($article);
|
||||
$this->recountUserArticles($user);
|
||||
|
||||
$this->eventsManager->fire('Article:afterCreate', $this, $article);
|
||||
@ -205,10 +208,11 @@ class Article extends Service
|
||||
|
||||
$article->update($data);
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
|
||||
$owner = $this->findUser($article->owner_id);
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
$this->rebuildArticleCache($article);
|
||||
$this->rebuildArticleIndex($article);
|
||||
$this->recountUserArticles($owner);
|
||||
|
||||
$this->eventsManager->fire('Article:afterUpdate', $this, $article);
|
||||
@ -224,10 +228,11 @@ class Article extends Service
|
||||
|
||||
$article->update();
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
|
||||
$owner = $this->findUser($article->owner_id);
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
$this->rebuildArticleCache($article);
|
||||
$this->rebuildArticleIndex($article);
|
||||
$this->recountUserArticles($owner);
|
||||
|
||||
$this->eventsManager->fire('Article:afterDelete', $this, $article);
|
||||
@ -243,10 +248,11 @@ class Article extends Service
|
||||
|
||||
$article->update();
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
|
||||
$owner = $this->findUser($article->owner_id);
|
||||
|
||||
$this->saveDynamicAttrs($article);
|
||||
$this->rebuildArticleCache($article);
|
||||
$this->rebuildArticleIndex($article);
|
||||
$this->recountUserArticles($owner);
|
||||
|
||||
$this->eventsManager->fire('Article:afterRestore', $this, $article);
|
||||
@ -278,6 +284,8 @@ class Article extends Service
|
||||
|
||||
$owner = $this->findUser($article->owner_id);
|
||||
|
||||
$this->rebuildArticleCache($article);
|
||||
$this->rebuildArticleIndex($article);
|
||||
$this->recountUserArticles($owner);
|
||||
|
||||
$sender = $this->getLoginUser();
|
||||
@ -331,6 +339,12 @@ class Article extends Service
|
||||
}
|
||||
|
||||
$article->update();
|
||||
|
||||
$owner = $this->findUser($article->owner_id);
|
||||
|
||||
$this->rebuildArticleCache($article);
|
||||
$this->rebuildArticleIndex($article);
|
||||
$this->recountUserArticles($owner);
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
@ -347,6 +361,54 @@ class Article extends Service
|
||||
return $userRepo->findById($id);
|
||||
}
|
||||
|
||||
protected function rebuildArticleCache(ArticleModel $article)
|
||||
{
|
||||
$cache = new ArticleCache();
|
||||
|
||||
$cache->rebuild($article->id);
|
||||
}
|
||||
|
||||
protected function rebuildArticleIndex(ArticleModel $article)
|
||||
{
|
||||
$sync = new ArticleIndexSync();
|
||||
|
||||
$sync->addItem($article->id);
|
||||
}
|
||||
|
||||
protected function recountUserArticles(UserModel $user)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$articleCount = $userRepo->countArticles($user->id);
|
||||
|
||||
$user->article_count = $articleCount;
|
||||
|
||||
$user->update();
|
||||
}
|
||||
|
||||
protected function handleArticlePostPoint(ArticleModel $article)
|
||||
{
|
||||
if ($article->published != ArticleModel::PUBLISH_APPROVED) return;
|
||||
|
||||
$service = new ArticlePostPointHistory();
|
||||
|
||||
$service->handle($article);
|
||||
}
|
||||
|
||||
protected function handleArticleApprovedNotice(ArticleModel $article, UserModel $sender)
|
||||
{
|
||||
$notice = new ArticleApprovedNotice();
|
||||
|
||||
$notice->handle($article, $sender);
|
||||
}
|
||||
|
||||
protected function handleArticleRejectedNotice(ArticleModel $article, UserModel $sender, $reason)
|
||||
{
|
||||
$notice = new ArticleRejectedNotice();
|
||||
|
||||
$notice->handle($article, $sender, $reason);
|
||||
}
|
||||
|
||||
protected function handleArticles($pager)
|
||||
{
|
||||
if ($pager->total_items > 0) {
|
||||
@ -383,38 +445,4 @@ class Article extends Service
|
||||
return $pager;
|
||||
}
|
||||
|
||||
protected function recountUserArticles(UserModel $user)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$articleCount = $userRepo->countArticles($user->id);
|
||||
|
||||
$user->article_count = $articleCount;
|
||||
|
||||
$user->update();
|
||||
}
|
||||
|
||||
protected function handleArticlePostPoint(ArticleModel $article)
|
||||
{
|
||||
if ($article->published != ArticleModel::PUBLISH_APPROVED) return;
|
||||
|
||||
$service = new ArticlePostPointHistory();
|
||||
|
||||
$service->handle($article);
|
||||
}
|
||||
|
||||
protected function handleArticleApprovedNotice(ArticleModel $article, UserModel $sender)
|
||||
{
|
||||
$notice = new ArticleApprovedNotice();
|
||||
|
||||
$notice->handle($article, $sender);
|
||||
}
|
||||
|
||||
protected function handleArticleRejectedNotice(ArticleModel $article, UserModel $sender, $reason)
|
||||
{
|
||||
$notice = new ArticleRejectedNotice();
|
||||
|
||||
$notice->handle($article, $sender, $reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,8 +103,9 @@ class Chapter extends Service
|
||||
$this->db->commit();
|
||||
|
||||
$this->updateChapterStats($chapter);
|
||||
|
||||
$this->updateCourseStat($chapter);
|
||||
$this->rebuildCatalogCache($chapter);
|
||||
$this->rebuildChapterCache($chapter);
|
||||
|
||||
return $chapter;
|
||||
|
||||
@ -160,10 +161,9 @@ class Chapter extends Service
|
||||
$chapter->update($data);
|
||||
|
||||
$this->updateChapterStats($chapter);
|
||||
|
||||
$this->updateCourseStat($chapter);
|
||||
|
||||
$this->rebuildCatalogCache($chapter);
|
||||
$this->rebuildChapterCache($chapter);
|
||||
|
||||
return $chapter;
|
||||
}
|
||||
@ -181,10 +181,9 @@ class Chapter extends Service
|
||||
$chapter->update();
|
||||
|
||||
$this->updateChapterStats($chapter);
|
||||
|
||||
$this->updateCourseStat($chapter);
|
||||
|
||||
$this->rebuildCatalogCache($chapter);
|
||||
$this->rebuildChapterCache($chapter);
|
||||
|
||||
return $chapter;
|
||||
}
|
||||
@ -198,14 +197,20 @@ class Chapter extends Service
|
||||
$chapter->update();
|
||||
|
||||
$this->updateChapterStats($chapter);
|
||||
|
||||
$this->updateCourseStat($chapter);
|
||||
|
||||
$this->rebuildCatalogCache($chapter);
|
||||
$this->rebuildChapterCache($chapter);
|
||||
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new ChapterValidator();
|
||||
|
||||
return $validator->checkChapter($id);
|
||||
}
|
||||
|
||||
protected function updateChapterStats(ChapterModel $chapter)
|
||||
{
|
||||
$chapterRepo = new ChapterRepo();
|
||||
@ -254,11 +259,4 @@ class Chapter extends Service
|
||||
$cache->rebuild($chapter->course_id);
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new ChapterValidator();
|
||||
|
||||
return $validator->checkChapter($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Builders\CourseList as CourseListBuilder;
|
||||
use App\Caches\Course as CourseCache;
|
||||
use App\Caches\CourseCategoryList as CourseCategoryListCache;
|
||||
use App\Caches\CourseRelatedList as CourseRelatedListCache;
|
||||
use App\Caches\CourseTeacherList as CourseTeacherListCache;
|
||||
@ -24,6 +25,7 @@ use App\Repos\CourseCategory as CourseCategoryRepo;
|
||||
use App\Repos\CourseRelated as CourseRelatedRepo;
|
||||
use App\Repos\CourseUser as CourseUserRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Sync\CourseIndex as CourseIndexSync;
|
||||
use App\Validators\Course as CourseValidator;
|
||||
use App\Validators\CourseOffline as CourseOfflineValidator;
|
||||
|
||||
@ -86,6 +88,9 @@ class Course extends Service
|
||||
|
||||
$this->db->commit();
|
||||
|
||||
$this->rebuildCourseCache($course);
|
||||
$this->rebuildCourseIndex($course);
|
||||
|
||||
return $course;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@ -208,6 +213,9 @@ class Course extends Service
|
||||
|
||||
$course->update($data);
|
||||
|
||||
$this->rebuildCourseCache($course);
|
||||
$this->rebuildCourseIndex($course);
|
||||
|
||||
return $course;
|
||||
}
|
||||
|
||||
@ -219,6 +227,9 @@ class Course extends Service
|
||||
|
||||
$course->update();
|
||||
|
||||
$this->rebuildCourseCache($course);
|
||||
$this->rebuildCourseIndex($course);
|
||||
|
||||
return $course;
|
||||
}
|
||||
|
||||
@ -230,6 +241,9 @@ class Course extends Service
|
||||
|
||||
$course->update();
|
||||
|
||||
$this->rebuildCourseCache($course);
|
||||
$this->rebuildCourseIndex($course);
|
||||
|
||||
return $course;
|
||||
}
|
||||
|
||||
@ -562,6 +576,20 @@ class Course extends Service
|
||||
$cache->rebuild($course->id);
|
||||
}
|
||||
|
||||
protected function rebuildCourseCache(CourseModel $course)
|
||||
{
|
||||
$cache = new CourseCache();
|
||||
|
||||
$cache->rebuild($course->id);
|
||||
}
|
||||
|
||||
protected function rebuildCourseIndex(CourseModel $course)
|
||||
{
|
||||
$sync = new CourseIndexSync();
|
||||
|
||||
$sync->addItem($course->id);
|
||||
}
|
||||
|
||||
protected function handleCourses($pager)
|
||||
{
|
||||
if ($pager->total_items > 0) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Caches\FlashSale as FlashSaleCache;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\Course as CourseModel;
|
||||
use App\Models\FlashSale as FlashSaleModel;
|
||||
@ -157,6 +158,8 @@ class FlashSale extends Service
|
||||
break;
|
||||
}
|
||||
|
||||
$this->rebuildFlashSaleCache($sale);
|
||||
|
||||
return $sale;
|
||||
}
|
||||
|
||||
@ -198,7 +201,8 @@ class FlashSale extends Service
|
||||
|
||||
$sale->update($data);
|
||||
|
||||
$this->initFlashSaleQueue($sale->id);
|
||||
$this->initFlashSaleQueue($sale);
|
||||
$this->rebuildFlashSaleCache($sale);
|
||||
|
||||
return $sale;
|
||||
}
|
||||
@ -211,6 +215,8 @@ class FlashSale extends Service
|
||||
|
||||
$sale->update();
|
||||
|
||||
$this->rebuildFlashSaleCache($sale);
|
||||
|
||||
return $sale;
|
||||
}
|
||||
|
||||
@ -222,9 +228,32 @@ class FlashSale extends Service
|
||||
|
||||
$sale->update();
|
||||
|
||||
$this->rebuildFlashSaleCache($sale);
|
||||
|
||||
return $sale;
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new FlashSaleValidator();
|
||||
|
||||
return $validator->checkFlashSale($id);
|
||||
}
|
||||
|
||||
protected function initFlashSaleQueue(FlashSaleModel $sale)
|
||||
{
|
||||
$queue = new FlashSaleQueue();
|
||||
|
||||
$queue->init($sale->id);
|
||||
}
|
||||
|
||||
protected function rebuildFlashSaleCache(FlashSaleModel $sale)
|
||||
{
|
||||
$cache = new FlashSaleCache();
|
||||
|
||||
$cache->rebuild($sale->id);
|
||||
}
|
||||
|
||||
protected function createCourseFlashSale($post)
|
||||
{
|
||||
$validator = new FlashSaleValidator();
|
||||
@ -348,18 +377,4 @@ class FlashSale extends Service
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function initFlashSaleQueue($id)
|
||||
{
|
||||
$queue = new FlashSaleQueue();
|
||||
|
||||
$queue->init($id);
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new FlashSaleValidator();
|
||||
|
||||
return $validator->checkFlashSale($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Builders\HelpList as HelpListBuilder;
|
||||
use App\Caches\Help as HelpCache;
|
||||
use App\Caches\HelpList as HelpListCache;
|
||||
use App\Models\Category as CategoryModel;
|
||||
use App\Models\Help as HelpModel;
|
||||
@ -75,6 +76,7 @@ class Help extends Service
|
||||
|
||||
$help->create($data);
|
||||
|
||||
$this->rebuildHelpCache($help);
|
||||
$this->rebuildHelpListCache();
|
||||
|
||||
return $help;
|
||||
@ -117,6 +119,7 @@ class Help extends Service
|
||||
|
||||
$help->update($data);
|
||||
|
||||
$this->rebuildHelpCache($help);
|
||||
$this->rebuildHelpListCache();
|
||||
|
||||
return $help;
|
||||
@ -130,6 +133,7 @@ class Help extends Service
|
||||
|
||||
$help->update();
|
||||
|
||||
$this->rebuildHelpCache($help);
|
||||
$this->rebuildHelpListCache();
|
||||
|
||||
return $help;
|
||||
@ -143,18 +147,12 @@ class Help extends Service
|
||||
|
||||
$help->update();
|
||||
|
||||
$this->rebuildHelpCache($help);
|
||||
$this->rebuildHelpListCache();
|
||||
|
||||
return $help;
|
||||
}
|
||||
|
||||
protected function rebuildHelpListCache()
|
||||
{
|
||||
$cache = new HelpListCache();
|
||||
|
||||
$cache->rebuild();
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new HelpValidator();
|
||||
@ -162,6 +160,20 @@ class Help extends Service
|
||||
return $validator->checkHelp($id);
|
||||
}
|
||||
|
||||
protected function rebuildHelpCache(HelpModel $help)
|
||||
{
|
||||
$cache = new HelpCache();
|
||||
|
||||
$cache->rebuild($help->id);
|
||||
}
|
||||
|
||||
protected function rebuildHelpListCache()
|
||||
{
|
||||
$cache = new HelpListCache();
|
||||
|
||||
$cache->rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Resultset $helps
|
||||
* @return array|object
|
||||
|
@ -186,6 +186,13 @@ class Package extends Service
|
||||
return $package;
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new PackageValidator();
|
||||
|
||||
return $validator->checkPackage($id);
|
||||
}
|
||||
|
||||
protected function saveCourses(PackageModel $package, $courseIds)
|
||||
{
|
||||
$packageRepo = new PackageRepo();
|
||||
@ -297,11 +304,4 @@ class Package extends Service
|
||||
$course->update();
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new PackageValidator();
|
||||
|
||||
return $validator->checkPackage($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Caches\Page as PageCache;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\Page as PageModel;
|
||||
use App\Repos\Page as PageRepo;
|
||||
@ -52,6 +53,8 @@ class Page extends Service
|
||||
|
||||
$page->create($data);
|
||||
|
||||
$this->rebuildPageCache($page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
@ -93,6 +96,8 @@ class Page extends Service
|
||||
|
||||
$page->update($data);
|
||||
|
||||
$this->rebuildPageCache($page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
@ -104,6 +109,8 @@ class Page extends Service
|
||||
|
||||
$page->update();
|
||||
|
||||
$this->rebuildPageCache($page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
@ -115,6 +122,8 @@ class Page extends Service
|
||||
|
||||
$page->update();
|
||||
|
||||
$this->rebuildPageCache($page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
@ -125,4 +134,11 @@ class Page extends Service
|
||||
return $validator->checkPage($id);
|
||||
}
|
||||
|
||||
protected function rebuildPageCache(PageModel $page)
|
||||
{
|
||||
$cache = new PageCache();
|
||||
|
||||
$cache->rebuild($page->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Caches\PointGift as PointGiftCache;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\PointGift as PointGiftModel;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
@ -115,6 +116,8 @@ class PointGift extends Service
|
||||
break;
|
||||
}
|
||||
|
||||
$this->rebuildPointGiftCache($gift);
|
||||
|
||||
return $gift;
|
||||
}
|
||||
|
||||
@ -162,6 +165,8 @@ class PointGift extends Service
|
||||
|
||||
$gift->update($data);
|
||||
|
||||
$this->rebuildPointGiftCache($gift);
|
||||
|
||||
return $gift;
|
||||
}
|
||||
|
||||
@ -173,6 +178,8 @@ class PointGift extends Service
|
||||
|
||||
$gift->update();
|
||||
|
||||
$this->rebuildPointGiftCache($gift);
|
||||
|
||||
return $gift;
|
||||
}
|
||||
|
||||
@ -184,9 +191,25 @@ class PointGift extends Service
|
||||
|
||||
$gift->update();
|
||||
|
||||
$this->rebuildPointGiftCache($gift);
|
||||
|
||||
return $gift;
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new PointGiftValidator();
|
||||
|
||||
return $validator->checkPointGift($id);
|
||||
}
|
||||
|
||||
protected function rebuildPointGiftCache(PointGiftModel $gift)
|
||||
{
|
||||
$cache = new PointGiftCache();
|
||||
|
||||
$cache->rebuild($gift->id);
|
||||
}
|
||||
|
||||
protected function createCoursePointGift($post)
|
||||
{
|
||||
$validator = new PointGiftValidator();
|
||||
@ -257,11 +280,4 @@ class PointGift extends Service
|
||||
return $gift;
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new PointGiftValidator();
|
||||
|
||||
return $validator->checkPointGift($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Builders\QuestionList as QuestionListBuilder;
|
||||
use App\Builders\ReportList as ReportListBuilder;
|
||||
use App\Caches\Question as QuestionCache;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\Category as CategoryModel;
|
||||
use App\Models\Question as QuestionModel;
|
||||
@ -25,6 +26,7 @@ use App\Services\Logic\Point\History\QuestionPost as QuestionPostPointHistory;
|
||||
use App\Services\Logic\Question\QuestionDataTrait;
|
||||
use App\Services\Logic\Question\QuestionInfo as QuestionInfoService;
|
||||
use App\Services\Logic\Question\XmTagList as XmTagListService;
|
||||
use App\Services\Sync\QuestionIndex as QuestionIndexSync;
|
||||
use App\Validators\Question as QuestionValidator;
|
||||
|
||||
class Question extends Service
|
||||
@ -134,7 +136,8 @@ class Question extends Service
|
||||
$question->create();
|
||||
|
||||
$this->saveDynamicAttrs($question);
|
||||
|
||||
$this->rebuildQuestionCache($question);
|
||||
$this->rebuildQuestionIndex($question);
|
||||
$this->recountUserQuestions($user);
|
||||
|
||||
$this->eventsManager->fire('Question:afterCreate', $this, $question);
|
||||
@ -187,10 +190,11 @@ class Question extends Service
|
||||
|
||||
$question->update($data);
|
||||
|
||||
$this->saveDynamicAttrs($question);
|
||||
|
||||
$owner = $this->findUser($question->owner_id);
|
||||
|
||||
$this->saveDynamicAttrs($question);
|
||||
$this->rebuildQuestionCache($question);
|
||||
$this->rebuildQuestionIndex($question);
|
||||
$this->recountUserQuestions($owner);
|
||||
|
||||
$this->eventsManager->fire('Question:afterUpdate', $this, $question);
|
||||
@ -206,10 +210,11 @@ class Question extends Service
|
||||
|
||||
$question->update();
|
||||
|
||||
$this->saveDynamicAttrs($question);
|
||||
|
||||
$owner = $this->findUser($question->owner_id);
|
||||
|
||||
$this->saveDynamicAttrs($question);
|
||||
$this->rebuildQuestionCache($question);
|
||||
$this->rebuildQuestionIndex($question);
|
||||
$this->recountUserQuestions($owner);
|
||||
|
||||
$this->eventsManager->fire('Question:afterDelete', $this, $question);
|
||||
@ -227,6 +232,8 @@ class Question extends Service
|
||||
|
||||
$owner = $this->findUser($question->owner_id);
|
||||
|
||||
$this->rebuildQuestionCache($question);
|
||||
$this->rebuildQuestionIndex($question);
|
||||
$this->recountUserQuestions($owner);
|
||||
|
||||
$this->eventsManager->fire('Question:afterRestore', $this, $question);
|
||||
@ -254,6 +261,8 @@ class Question extends Service
|
||||
|
||||
$owner = $this->findUser($question->owner_id);
|
||||
|
||||
$this->rebuildQuestionCache($question);
|
||||
$this->rebuildQuestionIndex($question);
|
||||
$this->recountUserQuestions($owner);
|
||||
|
||||
$sender = $this->getLoginUser();
|
||||
@ -307,6 +316,12 @@ class Question extends Service
|
||||
}
|
||||
|
||||
$question->update();
|
||||
|
||||
$owner = $this->findUser($question->owner_id);
|
||||
|
||||
$this->rebuildQuestionCache($question);
|
||||
$this->rebuildQuestionIndex($question);
|
||||
$this->recountUserQuestions($owner);
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
@ -323,6 +338,54 @@ class Question extends Service
|
||||
return $userRepo->findById($id);
|
||||
}
|
||||
|
||||
protected function rebuildQuestionCache(QuestionModel $question)
|
||||
{
|
||||
$cache = new QuestionCache();
|
||||
|
||||
$cache->rebuild($question->id);
|
||||
}
|
||||
|
||||
protected function rebuildQuestionIndex(QuestionModel $question)
|
||||
{
|
||||
$sync = new QuestionIndexSync();
|
||||
|
||||
$sync->addItem($question->id);
|
||||
}
|
||||
|
||||
protected function recountUserQuestions(UserModel $user)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$questionCount = $userRepo->countQuestions($user->id);
|
||||
|
||||
$user->question_count = $questionCount;
|
||||
|
||||
$user->update();
|
||||
}
|
||||
|
||||
protected function handleQuestionPostPoint(QuestionModel $question)
|
||||
{
|
||||
if ($question->published != QuestionModel::PUBLISH_APPROVED) return;
|
||||
|
||||
$service = new QuestionPostPointHistory();
|
||||
|
||||
$service->handle($question);
|
||||
}
|
||||
|
||||
protected function handleQuestionApprovedNotice(QuestionModel $question, UserModel $sender)
|
||||
{
|
||||
$notice = new QuestionApprovedNotice();
|
||||
|
||||
$notice->handle($question, $sender);
|
||||
}
|
||||
|
||||
protected function handleQuestionRejectedNotice(QuestionModel $question, UserModel $sender, $reason)
|
||||
{
|
||||
$notice = new QuestionRejectedNotice();
|
||||
|
||||
$notice->handle($question, $sender, $reason);
|
||||
}
|
||||
|
||||
protected function handleQuestions($pager)
|
||||
{
|
||||
if ($pager->total_items > 0) {
|
||||
@ -359,38 +422,4 @@ class Question extends Service
|
||||
return $pager;
|
||||
}
|
||||
|
||||
protected function recountUserQuestions(UserModel $user)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$questionCount = $userRepo->countQuestions($user->id);
|
||||
|
||||
$user->question_count = $questionCount;
|
||||
|
||||
$user->update();
|
||||
}
|
||||
|
||||
protected function handleQuestionPostPoint(QuestionModel $question)
|
||||
{
|
||||
if ($question->published != QuestionModel::PUBLISH_APPROVED) return;
|
||||
|
||||
$service = new QuestionPostPointHistory();
|
||||
|
||||
$service->handle($question);
|
||||
}
|
||||
|
||||
protected function handleQuestionApprovedNotice(QuestionModel $question, UserModel $sender)
|
||||
{
|
||||
$notice = new QuestionApprovedNotice();
|
||||
|
||||
$notice->handle($question, $sender);
|
||||
}
|
||||
|
||||
protected function handleQuestionRejectedNotice(QuestionModel $question, UserModel $sender, $reason)
|
||||
{
|
||||
$notice = new QuestionRejectedNotice();
|
||||
|
||||
$notice->handle($question, $sender, $reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ use App\Models\Resource as ResourceModel;
|
||||
use App\Models\Upload as UploadModel;
|
||||
use App\Repos\Chapter as ChapterRepo;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
use App\Repos\Upload as UploadRepo;
|
||||
use App\Services\Storage as StorageService;
|
||||
use App\Validators\Chapter as ChapterValidator;
|
||||
use App\Validators\Resource as ResourceValidator;
|
||||
use App\Validators\Upload as UploadValidator;
|
||||
@ -31,26 +29,16 @@ class Resource extends Service
|
||||
$chapter = $validator->checkChapter($post['chapter_id']);
|
||||
$course = $validator->checkCourse($chapter->course_id);
|
||||
|
||||
$uploadRepo = new UploadRepo();
|
||||
$upload = new UploadModel();
|
||||
|
||||
$upload = $uploadRepo->findByMd5($post['upload']['md5']);
|
||||
$upload->type = UploadModel::TYPE_RESOURCE;
|
||||
$upload->name = $post['upload']['name'];
|
||||
$upload->size = $post['upload']['size'];
|
||||
$upload->path = $post['upload']['path'];
|
||||
$upload->md5 = $post['upload']['md5'];
|
||||
$upload->mime = $post['upload']['mime'];
|
||||
|
||||
/**
|
||||
* 腾讯COS存储可能不会返回文件md5值
|
||||
*/
|
||||
if (!$upload || empty($post['upload']['md5'])) {
|
||||
|
||||
$upload = new UploadModel();
|
||||
|
||||
$upload->type = UploadModel::TYPE_RESOURCE;
|
||||
$upload->name = $post['upload']['name'];
|
||||
$upload->size = $post['upload']['size'];
|
||||
$upload->path = $post['upload']['path'];
|
||||
$upload->md5 = $post['upload']['md5'];
|
||||
$upload->mime = $post['upload']['mime'];
|
||||
|
||||
$upload->create();
|
||||
}
|
||||
$upload->create();
|
||||
|
||||
$resource = new ResourceModel();
|
||||
|
||||
@ -124,7 +112,9 @@ class Resource extends Service
|
||||
$resourceCount = 0;
|
||||
|
||||
foreach ($lessons as $lesson) {
|
||||
$resourceCount += $chapterRepo->countResources($lesson->id);
|
||||
if ($lesson->deleted == 0) {
|
||||
$resourceCount += $chapterRepo->countResources($lesson->id);
|
||||
}
|
||||
}
|
||||
|
||||
$parent->resource_count = $resourceCount;
|
||||
@ -136,7 +126,21 @@ class Resource extends Service
|
||||
{
|
||||
$courseRepo = new CourseRepo();
|
||||
|
||||
$course->resource_count = $courseRepo->countResources($course->id);
|
||||
$lessons = $courseRepo->findLessons($course->id);
|
||||
|
||||
$chapterRepo = new ChapterRepo();
|
||||
|
||||
$resourceCount = 0;
|
||||
|
||||
if ($lessons->count() > 0) {
|
||||
foreach ($lessons as $lesson) {
|
||||
if ($lesson->deleted == 0) {
|
||||
$resourceCount += $chapterRepo->countResources($lesson->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$course->resource_count = $resourceCount;
|
||||
|
||||
$course->update();
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ class Slide extends Service
|
||||
$slide = $this->createLinkSlide($post);
|
||||
}
|
||||
|
||||
$this->rebuildSlideCache();
|
||||
$this->rebuildIndexSlideListCache();
|
||||
|
||||
return $slide;
|
||||
}
|
||||
@ -138,7 +138,7 @@ class Slide extends Service
|
||||
|
||||
$slide->update($data);
|
||||
|
||||
$this->rebuildSlideCache();
|
||||
$this->rebuildIndexSlideListCache();
|
||||
|
||||
return $slide;
|
||||
}
|
||||
@ -151,7 +151,7 @@ class Slide extends Service
|
||||
|
||||
$slide->update();
|
||||
|
||||
$this->rebuildSlideCache();
|
||||
$this->rebuildIndexSlideListCache();
|
||||
|
||||
return $slide;
|
||||
}
|
||||
@ -164,7 +164,7 @@ class Slide extends Service
|
||||
|
||||
$slide->update();
|
||||
|
||||
$this->rebuildSlideCache();
|
||||
$this->rebuildIndexSlideListCache();
|
||||
|
||||
return $slide;
|
||||
}
|
||||
@ -236,7 +236,7 @@ class Slide extends Service
|
||||
return $slide;
|
||||
}
|
||||
|
||||
protected function rebuildSlideCache()
|
||||
protected function rebuildIndexSlideListCache()
|
||||
{
|
||||
$cache = new IndexSlideListCache();
|
||||
|
||||
|
@ -162,6 +162,13 @@ class Topic extends Service
|
||||
return $topic;
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new TopicValidator();
|
||||
|
||||
return $validator->checkTopic($id);
|
||||
}
|
||||
|
||||
protected function saveCourses(TopicModel $topic, $courseIds)
|
||||
{
|
||||
$topicRepo = new TopicRepo();
|
||||
@ -220,11 +227,4 @@ class Topic extends Service
|
||||
$cache->rebuild($topic->id);
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new TopicValidator();
|
||||
|
||||
return $validator->checkTopic($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use App\Builders\UserList as UserListBuilder;
|
||||
use App\Caches\User as UserCache;
|
||||
use App\Library\Paginator\Query as PaginateQuery;
|
||||
use App\Library\Utils\Password as PasswordUtil;
|
||||
use App\Library\Validators\Common as CommonValidator;
|
||||
use App\Models\Account as AccountModel;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Repos\Account as AccountRepo;
|
||||
@ -61,6 +62,24 @@ class User extends Service
|
||||
$pageQuery = new PaginateQuery();
|
||||
|
||||
$params = $pageQuery->getParams();
|
||||
|
||||
$accountRepo = new AccountRepo();
|
||||
|
||||
/**
|
||||
* 兼容用户编号|手机号码|邮箱地址查询
|
||||
*/
|
||||
if (!empty($params['id'])) {
|
||||
if (CommonValidator::phone($params['id'])) {
|
||||
$account = $accountRepo->findByPhone($params['id']);
|
||||
$params['id'] = $account ? $account->id : -1000;
|
||||
} elseif (CommonValidator::email($params['id'])) {
|
||||
$account = $accountRepo->findByEmail($params['id']);
|
||||
$params['id'] = $account ? $account->id : -1000;
|
||||
}
|
||||
}
|
||||
|
||||
$params['deleted'] = $params['deleted'] ?? 0;
|
||||
|
||||
$sort = $pageQuery->getSort();
|
||||
$page = $pageQuery->getPage();
|
||||
$limit = $pageQuery->getLimit();
|
||||
@ -132,6 +151,8 @@ class User extends Service
|
||||
$this->updateAdminUserCount($adminRole);
|
||||
}
|
||||
|
||||
$this->rebuildUserCache($user);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->db->rollback();
|
||||
@ -223,6 +244,8 @@ class User extends Service
|
||||
$this->updateAdminUserCount($user->admin_role);
|
||||
}
|
||||
|
||||
$this->rebuildUserCache($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
@ -2,46 +2,26 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form class="layui-form kg-form" method="POST" action="{{ url({'for':'admin.topic.update','id':topic.id}) }}">
|
||||
<fieldset class="layui-elem-field layui-field-title">
|
||||
<legend>编辑专题</legend>
|
||||
</fieldset>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">标题</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="title" value="{{ topic.title }}" lay-verify="required">
|
||||
{% set action_url = url({'for':'admin.topic.update','id':topic.id}) %}
|
||||
|
||||
<fieldset class="layui-elem-field layui-field-title">
|
||||
<legend>编辑专题</legend>
|
||||
</fieldset>
|
||||
|
||||
<div class="layui-tab layui-tab-brief">
|
||||
<ul class="layui-tab-title kg-tab-title">
|
||||
<li class="layui-this">基本信息</li>
|
||||
<li>相关课程</li>
|
||||
</ul>
|
||||
<div class="layui-tab-content">
|
||||
<div class="layui-tab-item layui-show">
|
||||
{{ partial('topic/edit_basic') }}
|
||||
</div>
|
||||
<div class="layui-tab-item">
|
||||
{{ partial('topic/edit_course') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">封面</label>
|
||||
<div class="layui-input-inline">
|
||||
<img id="img-cover" class="kg-cover" src="{{ topic.cover }}">
|
||||
<input type="hidden" name="cover" value="{{ topic.cover }}">
|
||||
</div>
|
||||
<div class="layui-input-inline" style="padding-top:35px;">
|
||||
<button id="change-cover" class="layui-btn layui-btn-sm" type="button">更换</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">简介</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea class="layui-textarea" name="summary">{{ topic.summary }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">相关课程</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="xm-course-ids"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="kg-submit layui-btn" lay-submit="true" lay-filter="go">提交</button>
|
||||
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
38
app/Http/Admin/Views/topic/edit_basic.volt
Normal file
38
app/Http/Admin/Views/topic/edit_basic.volt
Normal file
@ -0,0 +1,38 @@
|
||||
<form class="layui-form kg-form" method="POST" action="{{ action_url }}">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">标题</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="title" value="{{ topic.title }}" lay-verify="required">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">封面</label>
|
||||
<div class="layui-input-inline">
|
||||
<img id="img-cover" class="kg-cover" src="{{ topic.cover }}">
|
||||
<input type="hidden" name="cover" value="{{ topic.cover }}">
|
||||
</div>
|
||||
<div class="layui-input-inline" style="padding-top:35px;">
|
||||
<button id="change-cover" class="layui-btn layui-btn-sm" type="button">更换</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">简介</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea class="layui-textarea" name="summary">{{ topic.summary }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">发布</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="published" value="1" title="是" {% if topic.published == 1 %}checked="checked"{% endif %}>
|
||||
<input type="radio" name="published" value="0" title="否" {% if topic.published == 0 %}checked="checked"{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="kg-submit layui-btn" lay-submit="true" lay-filter="go">提交</button>
|
||||
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
15
app/Http/Admin/Views/topic/edit_course.volt
Normal file
15
app/Http/Admin/Views/topic/edit_course.volt
Normal file
@ -0,0 +1,15 @@
|
||||
<form class="layui-form kg-form" method="POST" action="{{ action_url }}">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">相关课程</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="xm-course-ids"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="kg-submit layui-btn" lay-submit="true" lay-filter="go">提交</button>
|
||||
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -7,15 +7,15 @@
|
||||
<legend>搜索用户</legend>
|
||||
</fieldset>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">编号</label>
|
||||
<label class="layui-form-label">用户帐号</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="id" placeholder="编号精确匹配">
|
||||
<input class="layui-input" type="text" name="id" placeholder="用户编号 / 手机号码 / 邮箱地址 精确匹配">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">昵称</label>
|
||||
<label class="layui-form-label">用户昵称</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="name" placeholder="昵称模糊匹配">
|
||||
<input class="layui-input" type="text" name="name" placeholder="用户昵称模糊匹配">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
|
@ -278,35 +278,6 @@ class UserConsoleController extends Controller
|
||||
$this->view->setVar('pager', $pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/friends", name="home.uc.friends")
|
||||
*/
|
||||
public function friendsAction()
|
||||
{
|
||||
$service = new FriendListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
$this->view->pick('user/console/friends');
|
||||
$this->view->setVar('pager', $pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/groups", name="home.uc.groups")
|
||||
*/
|
||||
public function groupsAction()
|
||||
{
|
||||
$scope = $this->request->getQuery('scope', 'string', 'joined');
|
||||
|
||||
$service = new GroupListService();
|
||||
|
||||
$pager = $service->handle($scope);
|
||||
|
||||
$this->view->pick('user/console/groups');
|
||||
$this->view->setVar('scope', $scope);
|
||||
$this->view->setVar('pager', $pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/notifications", name="home.uc.notifications")
|
||||
*/
|
||||
|
75
app/Services/Logic/Course/ResourceList.php
Normal file
75
app/Services/Logic/Course/ResourceList.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Services\Logic\Course;
|
||||
|
||||
use App\Builders\ResourceList as ResourceListBuilder;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
use App\Repos\Resource as ResourceRepo;
|
||||
use App\Services\Logic\CourseTrait;
|
||||
use App\Services\Logic\Service as LogicService;
|
||||
|
||||
class ResourceList extends LogicService
|
||||
{
|
||||
|
||||
use CourseTrait;
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$course = $this->checkCourse($id);
|
||||
|
||||
$user = $this->getCurrentUser(true);
|
||||
|
||||
$this->setCourseUser($course, $user);
|
||||
|
||||
$courseRepo = new CourseRepo();
|
||||
|
||||
$lessons = $courseRepo->findLessons($course->id);
|
||||
|
||||
if ($lessons->count() == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$lessonIds = [];
|
||||
|
||||
/**
|
||||
* 过滤掉未发布和已删除的课时
|
||||
*/
|
||||
foreach ($lessons as $lesson) {
|
||||
if ($lesson->published == 1 && $lesson->deleted == 0) {
|
||||
$lessonIds[] = $lesson->id;
|
||||
}
|
||||
}
|
||||
|
||||
$resourceRepo = new ResourceRepo();
|
||||
|
||||
$resources = $resourceRepo->findByCourseId($course->id);
|
||||
|
||||
if ($resources->count() == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$builder = new ResourceListBuilder();
|
||||
|
||||
$relations = $resources->toArray();
|
||||
|
||||
foreach ($relations as $key => $relation) {
|
||||
if (!in_array($relation['chapter_id'], $lessonIds)) {
|
||||
unset($relations[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$uploads = $builder->getUploads($relations);
|
||||
|
||||
foreach ($uploads as $key => $upload) {
|
||||
$uploads[$key]['me'] = ['owned' => $this->ownedCourse ? 1 : 0];
|
||||
}
|
||||
|
||||
return array_values($uploads);
|
||||
}
|
||||
|
||||
}
|
@ -61,6 +61,8 @@ class FavoriteList extends LogicService
|
||||
|
||||
return $this->handleQuestions($pager);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function handleCourses($pager)
|
||||
|
@ -39,7 +39,7 @@ class Account extends Validator
|
||||
$account = $accountRepo->findById($name);
|
||||
}
|
||||
|
||||
if (!$account) {
|
||||
if (!$account || $account->deleted == 1) {
|
||||
throw new BadRequestException('account.not_found');
|
||||
}
|
||||
|
||||
@ -144,7 +144,13 @@ class Account extends Validator
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
return $userRepo->findById($account->id);
|
||||
$user = $userRepo->findById($account->id);
|
||||
|
||||
if ($user->deleted == 1) {
|
||||
throw new BadRequestException('user.not_found');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function checkUserLogin($name, $password)
|
||||
@ -161,7 +167,13 @@ class Account extends Validator
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
return $userRepo->findById($account->id);
|
||||
$user = $userRepo->findById($account->id);
|
||||
|
||||
if ($user->deleted == 1) {
|
||||
throw new BadRequestException('user.not_found');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function checkAdminLogin($name, $password)
|
||||
|
@ -65,7 +65,6 @@ $error['account.login_pwd_incorrect'] = '登录密码不正确';
|
||||
$error['user.not_found'] = '用户不存在';
|
||||
$error['user.name_taken'] = '用户名被占用';
|
||||
$error['user.title_too_long'] = '头衔过长(超过30个字符)';
|
||||
$error['user.sign_too_long'] = '签名过长(超过50个字符)';
|
||||
$error['user.about_too_long'] = '简介过长(超过255个字符)';
|
||||
$error['user.invalid_gender'] = '无效的性别类型';
|
||||
$error['user.invalid_area'] = '无效的省市地区';
|
||||
|
37
db/migrations/20230816234130.php
Normal file
37
db/migrations/20230816234130.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class V20230816234130 extends AbstractMigration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->alterReviewLikeTable();
|
||||
}
|
||||
|
||||
protected function alterReviewLikeTable()
|
||||
{
|
||||
$table = $this->table('kg_review_like');
|
||||
|
||||
if (!$table->hasColumn('deleted')) {
|
||||
$table->addColumn('deleted', 'integer', [
|
||||
'null' => false,
|
||||
'default' => '0',
|
||||
'limit' => MysqlAdapter::INT_REGULAR,
|
||||
'signed' => false,
|
||||
'comment' => '删除标识',
|
||||
'after' => 'user_id',
|
||||
]);
|
||||
}
|
||||
|
||||
$table->save();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user