1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 20:52:44 +08:00

精简代码

This commit is contained in:
xiaochong0302 2022-10-31 09:53:24 +08:00
parent 6edbcc4638
commit 372b996365
6 changed files with 3 additions and 133 deletions

View File

@ -9,7 +9,6 @@ namespace App\Http\Admin\Services;
use App\Builders\ArticleList as ArticleListBuilder; use App\Builders\ArticleList as ArticleListBuilder;
use App\Builders\ReportList as ReportListBuilder; use App\Builders\ReportList as ReportListBuilder;
use App\Caches\Article as ArticleCache;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Library\Utils\Word as WordUtil; use App\Library\Utils\Word as WordUtil;
use App\Models\Article as ArticleModel; use App\Models\Article as ArticleModel;
@ -27,7 +26,6 @@ use App\Services\Logic\Article\XmTagList as XmTagListService;
use App\Services\Logic\Notice\Internal\ArticleApproved as ArticleApprovedNotice; use App\Services\Logic\Notice\Internal\ArticleApproved as ArticleApprovedNotice;
use App\Services\Logic\Notice\Internal\ArticleRejected as ArticleRejectedNotice; use App\Services\Logic\Notice\Internal\ArticleRejected as ArticleRejectedNotice;
use App\Services\Logic\Point\History\ArticlePost as ArticlePostPointHistory; use App\Services\Logic\Point\History\ArticlePost as ArticlePostPointHistory;
use App\Services\Sync\ArticleIndex as ArticleIndexSync;
use App\Validators\Article as ArticleValidator; use App\Validators\Article as ArticleValidator;
class Article extends Service class Article extends Service
@ -209,8 +207,6 @@ class Article extends Service
$this->saveDynamicAttrs($article); $this->saveDynamicAttrs($article);
$this->rebuildArticleIndex($article);
$owner = $this->findUser($article->owner_id); $owner = $this->findUser($article->owner_id);
$this->recountUserArticles($owner); $this->recountUserArticles($owner);
@ -230,8 +226,6 @@ class Article extends Service
$this->saveDynamicAttrs($article); $this->saveDynamicAttrs($article);
$this->rebuildArticleIndex($article);
$owner = $this->findUser($article->owner_id); $owner = $this->findUser($article->owner_id);
$this->recountUserArticles($owner); $this->recountUserArticles($owner);
@ -251,8 +245,6 @@ class Article extends Service
$this->saveDynamicAttrs($article); $this->saveDynamicAttrs($article);
$this->rebuildArticleIndex($article);
$owner = $this->findUser($article->owner_id); $owner = $this->findUser($article->owner_id);
$this->recountUserArticles($owner); $this->recountUserArticles($owner);
@ -292,7 +284,6 @@ class Article extends Service
if ($type == 'approve') { if ($type == 'approve') {
$this->rebuildArticleIndex($article);
$this->handleArticlePostPoint($article); $this->handleArticlePostPoint($article);
$this->handleArticleApprovedNotice($article, $sender); $this->handleArticleApprovedNotice($article, $sender);
@ -403,20 +394,6 @@ class Article extends Service
$user->update(); $user->update();
} }
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 handleArticlePostPoint(ArticleModel $article) protected function handleArticlePostPoint(ArticleModel $article)
{ {
if ($article->published != ArticleModel::PUBLISH_APPROVED) return; if ($article->published != ArticleModel::PUBLISH_APPROVED) return;

View File

@ -8,7 +8,6 @@
namespace App\Http\Admin\Services; namespace App\Http\Admin\Services;
use App\Builders\CourseList as CourseListBuilder; use App\Builders\CourseList as CourseListBuilder;
use App\Caches\Course as CourseCache;
use App\Caches\CourseCategoryList as CourseCategoryListCache; use App\Caches\CourseCategoryList as CourseCategoryListCache;
use App\Caches\CourseRelatedList as CourseRelatedListCache; use App\Caches\CourseRelatedList as CourseRelatedListCache;
use App\Caches\CourseTeacherList as CourseTeacherListCache; use App\Caches\CourseTeacherList as CourseTeacherListCache;
@ -25,7 +24,6 @@ use App\Repos\CourseCategory as CourseCategoryRepo;
use App\Repos\CourseRelated as CourseRelatedRepo; use App\Repos\CourseRelated as CourseRelatedRepo;
use App\Repos\CourseUser as CourseUserRepo; use App\Repos\CourseUser as CourseUserRepo;
use App\Repos\User as UserRepo; use App\Repos\User as UserRepo;
use App\Services\Sync\CourseIndex as CourseIndexSync;
use App\Validators\Course as CourseValidator; use App\Validators\Course as CourseValidator;
use App\Validators\CourseOffline as CourseOfflineValidator; use App\Validators\CourseOffline as CourseOfflineValidator;
@ -399,20 +397,6 @@ class Course extends Service
return $validator->checkCourse($id); return $validator->checkCourse($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 saveTeachers(CourseModel $course, $teacherIds) protected function saveTeachers(CourseModel $course, $teacherIds)
{ {
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();

View File

@ -7,7 +7,6 @@
namespace App\Http\Admin\Services; namespace App\Http\Admin\Services;
use App\Caches\Page as PageCache;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Models\Page as PageModel; use App\Models\Page as PageModel;
use App\Repos\Page as PageRepo; use App\Repos\Page as PageRepo;
@ -53,8 +52,6 @@ class Page extends Service
$page->create($data); $page->create($data);
$this->rebuildPageCache($page);
return $page; return $page;
} }
@ -96,8 +93,6 @@ class Page extends Service
$page->update($data); $page->update($data);
$this->rebuildPageCache($page);
return $page; return $page;
} }
@ -109,8 +104,6 @@ class Page extends Service
$page->update(); $page->update();
$this->rebuildPageCache($page);
return $page; return $page;
} }
@ -122,18 +115,9 @@ class Page extends Service
$page->update(); $page->update();
$this->rebuildPageCache($page);
return $page; return $page;
} }
protected function rebuildPageCache(PageModel $page)
{
$cache = new PageCache();
$cache->rebuild($page->id);
}
protected function findOrFail($id) protected function findOrFail($id)
{ {
$validator = new PageValidator(); $validator = new PageValidator();

View File

@ -9,7 +9,6 @@ namespace App\Http\Admin\Services;
use App\Builders\QuestionList as QuestionListBuilder; use App\Builders\QuestionList as QuestionListBuilder;
use App\Builders\ReportList as ReportListBuilder; use App\Builders\ReportList as ReportListBuilder;
use App\Caches\Question as QuestionCache;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Models\Category as CategoryModel; use App\Models\Category as CategoryModel;
use App\Models\Question as QuestionModel; use App\Models\Question as QuestionModel;
@ -26,7 +25,6 @@ use App\Services\Logic\Point\History\QuestionPost as QuestionPostPointHistory;
use App\Services\Logic\Question\QuestionDataTrait; use App\Services\Logic\Question\QuestionDataTrait;
use App\Services\Logic\Question\QuestionInfo as QuestionInfoService; use App\Services\Logic\Question\QuestionInfo as QuestionInfoService;
use App\Services\Logic\Question\XmTagList as XmTagListService; use App\Services\Logic\Question\XmTagList as XmTagListService;
use App\Services\Sync\QuestionIndex as QuestionIndexSync;
use App\Validators\Question as QuestionValidator; use App\Validators\Question as QuestionValidator;
class Question extends Service class Question extends Service
@ -191,8 +189,6 @@ class Question extends Service
$this->saveDynamicAttrs($question); $this->saveDynamicAttrs($question);
$this->rebuildQuestionIndex($question);
$owner = $this->findUser($question->owner_id); $owner = $this->findUser($question->owner_id);
$this->recountUserQuestions($owner); $this->recountUserQuestions($owner);
@ -212,8 +208,6 @@ class Question extends Service
$this->saveDynamicAttrs($question); $this->saveDynamicAttrs($question);
$this->rebuildQuestionIndex($question);
$owner = $this->findUser($question->owner_id); $owner = $this->findUser($question->owner_id);
$this->recountUserQuestions($owner); $this->recountUserQuestions($owner);
@ -231,8 +225,6 @@ class Question extends Service
$question->update(); $question->update();
$this->rebuildQuestionIndex($question);
$owner = $this->findUser($question->owner_id); $owner = $this->findUser($question->owner_id);
$this->recountUserQuestions($owner); $this->recountUserQuestions($owner);
@ -268,7 +260,6 @@ class Question extends Service
if ($type == 'approve') { if ($type == 'approve') {
$this->rebuildQuestionIndex($question);
$this->handleQuestionPostPoint($question); $this->handleQuestionPostPoint($question);
$this->handleQuestionApprovedNotice($question, $sender); $this->handleQuestionApprovedNotice($question, $sender);
@ -379,20 +370,6 @@ class Question extends Service
$user->update(); $user->update();
} }
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 handleQuestionPostPoint(QuestionModel $question) protected function handleQuestionPostPoint(QuestionModel $question)
{ {
if ($question->published != QuestionModel::PUBLISH_APPROVED) return; if ($question->published != QuestionModel::PUBLISH_APPROVED) return;

View File

@ -19,7 +19,7 @@ trait PointGiftTrait
return $validator->checkPointGift($id); return $validator->checkPointGift($id);
} }
public function checkFlashSaleCache($id) public function checkPointGiftCache($id)
{ {
$validator = new PointGiftValidator(); $validator = new PointGiftValidator();

View File

@ -183,58 +183,6 @@ class MyStorage extends Storage
return $this->upload('/resource/', self::MIME_FILE, UploadModel::TYPE_RESOURCE); return $this->upload('/resource/', self::MIME_FILE, UploadModel::TYPE_RESOURCE);
} }
/**
* @param string $url
*
* @return UploadModel|bool
*/
public function uploadRemoteImage($url)
{
$path = parse_url($url, PHP_URL_PATH);
$extension = pathinfo($path, PATHINFO_EXTENSION);
$originalName = pathinfo($path, PATHINFO_BASENAME);
$fileName = $this->generateFileName($extension);
$filePath = tmp_path($fileName);
$contents = file_get_contents($url);
if (file_put_contents($filePath, $contents) === false) {
return false;
}
$keyName = "/img/content/{$fileName}";
$uploadPath = $this->putFile($keyName, $filePath);
if (!$uploadPath) return false;
$md5 = md5_file($filePath);
$uploadRepo = new UploadRepo();
$upload = $uploadRepo->findByMd5($md5);
if ($upload == false) {
$upload = new UploadModel();
$upload->name = $originalName;
$upload->mime = mime_content_type($filePath);
$upload->size = filesize($filePath);
$upload->type = UploadModel::TYPE_CONTENT_IMG;
$upload->path = $uploadPath;
$upload->md5 = $md5;
$upload->create();
}
unlink($filePath);
return $upload;
}
/** /**
* 上传文件 * 上传文件
* *
@ -256,7 +204,7 @@ class MyStorage extends Storage
foreach ($files as $file) { foreach ($files as $file) {
if ($this->checkFile($file->getRealType(), $mimeType) == false) { if (!$this->checkFile($file->getRealType(), $mimeType)) {
continue; continue;
} }
@ -264,7 +212,7 @@ class MyStorage extends Storage
$upload = $uploadRepo->findByMd5($md5); $upload = $uploadRepo->findByMd5($md5);
if ($upload == false) { if (!$upload) {
$name = $this->filter->sanitize($file->getName(), ['trim', 'string']); $name = $this->filter->sanitize($file->getName(), ['trim', 'string']);