mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-27 21:10:24 +08:00
v1.44 beta
This commit is contained in:
parent
74f34752e5
commit
c1d3a98620
44
app/Caches/IndexArticleList.php
Normal file
44
app/Caches/IndexArticleList.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Caches;
|
||||
|
||||
use App\Models\Article as ArticleModel;
|
||||
use App\Repos\Article as ArticleRepo;
|
||||
use App\Services\Logic\Article\ArticleList as ArticleListService;
|
||||
|
||||
class IndexArticleList extends Cache
|
||||
{
|
||||
|
||||
protected $lifetime = 1 * 86400;
|
||||
|
||||
public function getLifetime()
|
||||
{
|
||||
return $this->lifetime;
|
||||
}
|
||||
|
||||
public function getKey($id = null)
|
||||
{
|
||||
return 'index_article_list';
|
||||
}
|
||||
|
||||
public function getContent($id = null)
|
||||
{
|
||||
$articleRepo = new ArticleRepo();
|
||||
|
||||
$where = ['published' => ArticleModel::PUBLISH_APPROVED];
|
||||
|
||||
$pager = $articleRepo->paginate($where, 'latest', 1, 10);
|
||||
|
||||
$service = new ArticleListService();
|
||||
|
||||
$pager = $service->handleArticles($pager);
|
||||
|
||||
return $pager->items ?: [];
|
||||
}
|
||||
|
||||
}
|
@ -7,14 +7,14 @@
|
||||
|
||||
namespace App\Caches;
|
||||
|
||||
use App\Models\Chapter as ChapterModel;
|
||||
use App\Models\ChapterLive as ChapterLiveModel;
|
||||
use App\Repos\Chapter as ChapterRepo;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
use Phalcon\Mvc\Model\Resultset;
|
||||
use Phalcon\Mvc\Model\ResultsetInterface;
|
||||
|
||||
/**
|
||||
* 直播课程
|
||||
*/
|
||||
class IndexLiveList extends Cache
|
||||
{
|
||||
|
||||
@ -32,32 +32,11 @@ class IndexLiveList extends Cache
|
||||
|
||||
public function getContent($id = null)
|
||||
{
|
||||
/**
|
||||
* 限制输出多少天数(一维限额)
|
||||
*/
|
||||
$dayLimit = 3;
|
||||
$limit = 8;
|
||||
|
||||
/**
|
||||
* 限制每天维度下的输出数(二维限额)
|
||||
*/
|
||||
$perDayLimit = 10;
|
||||
$lives = $this->findChapterLives();
|
||||
|
||||
$beginTime = strtotime('today');
|
||||
$endTime = strtotime("+30 days");
|
||||
|
||||
/**
|
||||
* @var Resultset|ChapterLiveModel[] $lives
|
||||
*/
|
||||
$lives = ChapterLiveModel::query()
|
||||
->betweenWhere('start_time', $beginTime, $endTime)
|
||||
->orderBy('start_time ASC')
|
||||
->execute();
|
||||
|
||||
if ($lives->count() == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
if ($lives->count() == 0) return [];
|
||||
|
||||
$chapterIds = kg_array_column($lives->toArray(), 'chapter_id');
|
||||
|
||||
@ -77,53 +56,85 @@ class IndexLiveList extends Cache
|
||||
|
||||
$courses = $courseRepo->findByIds($courseIds);
|
||||
|
||||
$teacherIds = kg_array_column($courses->toArray(), 'teacher_id');
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$users = $userRepo->findByIds($teacherIds);
|
||||
|
||||
$courseMapping = [];
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$courseMapping[$course->id] = $course;
|
||||
}
|
||||
|
||||
$userMapping = [];
|
||||
|
||||
foreach ($users as $user) {
|
||||
$userMapping[$user->id] = $user;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
$flag = [];
|
||||
|
||||
foreach ($lives as $live) {
|
||||
|
||||
if (count($result) >= $dayLimit) {
|
||||
break;
|
||||
}
|
||||
|
||||
$day = date('y-m-d', $live->start_time);
|
||||
|
||||
if (isset($result[$day]) && count($result[$day]) >= $perDayLimit) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$chapter = $chapterMapping[$live->chapter_id];
|
||||
$course = $courseMapping[$chapter->course_id];
|
||||
$teacher = $userMapping[$course->teacher_id];
|
||||
|
||||
$teacherInfo = [
|
||||
'id' => $teacher->id,
|
||||
'name' => $teacher->name,
|
||||
'title' => $teacher->title,
|
||||
'avatar' => $teacher->avatar,
|
||||
];
|
||||
|
||||
$chapterInfo = [
|
||||
'id' => $chapter->id,
|
||||
'title' => $chapter->title,
|
||||
'start_time' => $live->start_time,
|
||||
'end_time' => $live->end_time,
|
||||
];
|
||||
|
||||
$courseInfo = [
|
||||
'id' => $course->id,
|
||||
'title' => $course->title,
|
||||
'cover' => $course->cover,
|
||||
'market_price' => $course->market_price,
|
||||
'vip_price' => $course->vip_price,
|
||||
'model' => $course->model,
|
||||
'level' => $course->level,
|
||||
'user_count' => $course->user_count,
|
||||
'lesson_count' => $course->lesson_count,
|
||||
'teacher' => $teacherInfo,
|
||||
];
|
||||
|
||||
$result[$day][] = [
|
||||
'course' => $courseInfo,
|
||||
'chapter' => $chapterInfo,
|
||||
];
|
||||
if (!isset($flag[$course->id]) && count($flag) < $limit) {
|
||||
$flag[$course->id] = 1;
|
||||
$result[] = [
|
||||
'id' => $live->id,
|
||||
'status' => $live->status,
|
||||
'start_time' => $live->start_time,
|
||||
'end_time' => $live->end_time,
|
||||
'course' => $courseInfo,
|
||||
'chapter' => $chapterInfo,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResultsetInterface|Resultset|ChapterLiveModel[]
|
||||
*/
|
||||
protected function findChapterLives()
|
||||
{
|
||||
$startTime = strtotime('today');
|
||||
$endTime = strtotime('+30 days');
|
||||
|
||||
return $this->modelsManager->createBuilder()
|
||||
->columns('cl.*')
|
||||
->addFrom(ChapterLiveModel::class, 'cl')
|
||||
->join(ChapterModel::class, 'cl.chapter_id = c.id', 'c')
|
||||
->betweenWhere('start_time', $startTime, $endTime)
|
||||
->orderBy('start_time ASC')
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
44
app/Caches/IndexQuestionList.php
Normal file
44
app/Caches/IndexQuestionList.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Caches;
|
||||
|
||||
use App\Models\Question as QuestionModel;
|
||||
use App\Repos\Question as QuestionRepo;
|
||||
use App\Services\Logic\Question\QuestionList as QuestionListService;
|
||||
|
||||
class IndexQuestionList extends Cache
|
||||
{
|
||||
|
||||
protected $lifetime = 1 * 86400;
|
||||
|
||||
public function getLifetime()
|
||||
{
|
||||
return $this->lifetime;
|
||||
}
|
||||
|
||||
public function getKey($id = null)
|
||||
{
|
||||
return 'index_question_list';
|
||||
}
|
||||
|
||||
public function getContent($id = null)
|
||||
{
|
||||
$questionRepo = new QuestionRepo();
|
||||
|
||||
$where = ['published' => QuestionModel::PUBLISH_APPROVED];
|
||||
|
||||
$pager = $questionRepo->paginate($where, 'latest', 1, 10);
|
||||
|
||||
$service = new QuestionListService();
|
||||
|
||||
$pager = $service->handleQuestions($pager);
|
||||
|
||||
return $pager->items ?: [];
|
||||
}
|
||||
|
||||
}
|
@ -66,6 +66,7 @@ class IndexSimpleVipCourseList extends Cache
|
||||
{
|
||||
return CourseModel::query()
|
||||
->where('published = 1')
|
||||
->andWhere('market_price > vip_price')
|
||||
->andWhere('vip_price >= 0')
|
||||
->orderBy('score DESC')
|
||||
->limit($limit)
|
||||
|
@ -114,6 +114,7 @@ class IndexVipCourseList extends Cache
|
||||
return CourseModel::query()
|
||||
->inWhere('category_id', $categoryIds)
|
||||
->andWhere('published = 1')
|
||||
->andWhere('market_price > vip_price')
|
||||
->andWhere('vip_price >= 0')
|
||||
->orderBy('score DESC')
|
||||
->limit($limit)
|
||||
|
@ -54,12 +54,11 @@ class AnswerController extends Controller
|
||||
|
||||
$answer = $service->handle();
|
||||
|
||||
$content = [
|
||||
'answer' => $answer,
|
||||
'msg' => '创建回答成功',
|
||||
];
|
||||
$service = new AnswerInfoService();
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
$answer = $service->handle($answer->id);
|
||||
|
||||
return $this->jsonSuccess(['answer' => $answer]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,12 +70,7 @@ class AnswerController extends Controller
|
||||
|
||||
$answer = $service->handle($id);
|
||||
|
||||
$content = [
|
||||
'answer' => $answer,
|
||||
'msg' => '更新回答成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['answer' => $answer]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,20 +99,6 @@ class AnswerController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unaccept", name="api.answer.unaccept")
|
||||
*/
|
||||
public function unacceptAction($id)
|
||||
{
|
||||
$service = new AnswerAcceptService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '采纳成功' : '取消采纳成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.answer.like")
|
||||
*/
|
||||
@ -133,18 +113,4 @@ class AnswerController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.answer.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new AnswerLikeService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -82,20 +82,6 @@ class ArticleController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unfavorite", name="api.article.unfavorite")
|
||||
*/
|
||||
public function unfavoriteAction($id)
|
||||
{
|
||||
$service = new ArticleFavoriteService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '收藏成功' : '取消收藏成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.article.like")
|
||||
*/
|
||||
@ -110,18 +96,4 @@ class ArticleController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.article.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new ArticleLikeService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,18 +102,4 @@ class CommentController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="home.comment.like")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new CommentLikeService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,18 +89,4 @@ class ConsultController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unlike", name="api.consult.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new ConsultLikeService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -120,18 +120,4 @@ class CourseController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unfavorite", name="api.course.unfavorite")
|
||||
*/
|
||||
public function unfavoriteAction($id)
|
||||
{
|
||||
$service = new CourseFavoriteService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '收藏成功' : '取消收藏成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Caches\IndexArticleList;
|
||||
use App\Caches\IndexLiveList;
|
||||
use App\Caches\IndexQuestionList;
|
||||
use App\Caches\IndexSimpleFeaturedCourseList;
|
||||
use App\Caches\IndexSimpleFreeCourseList;
|
||||
use App\Caches\IndexSimpleNewCourseList;
|
||||
@ -31,6 +34,42 @@ class IndexController extends Controller
|
||||
return $this->jsonSuccess(['slides' => $slides]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/articles", name="api.index.articles")
|
||||
*/
|
||||
public function articlesAction()
|
||||
{
|
||||
$cache = new IndexArticleList();
|
||||
|
||||
$articles = $cache->get();
|
||||
|
||||
return $this->jsonSuccess(['articles' => $articles]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/questions", name="api.index.questions")
|
||||
*/
|
||||
public function questionsAction()
|
||||
{
|
||||
$cache = new IndexQuestionList();
|
||||
|
||||
$questions = $cache->get();
|
||||
|
||||
return $this->jsonSuccess(['questions' => $questions]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/lives", name="api.index.lives")
|
||||
*/
|
||||
public function livesAction()
|
||||
{
|
||||
$cache = new IndexLiveList();
|
||||
|
||||
$lives = $cache->get();
|
||||
|
||||
return $this->jsonSuccess(['lives' => $lives]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/courses/featured", name="api.index.featured_courses")
|
||||
*/
|
||||
|
@ -95,20 +95,6 @@ class QuestionController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unfavorite", name="api.question.unfavorite")
|
||||
*/
|
||||
public function unfavoriteAction($id)
|
||||
{
|
||||
$service = new QuestionFavoriteService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '收藏成功' : '取消收藏成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.question.like")
|
||||
*/
|
||||
@ -123,18 +109,4 @@ class QuestionController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.question.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new QuestionLikeService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,18 +89,4 @@ class ReviewController extends Controller
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unlike", name="api.review.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new ReviewLikeService();
|
||||
|
||||
$data = $service->handle($id);
|
||||
|
||||
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,10 +7,11 @@
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Search\Article as ArticleSearchService;
|
||||
use App\Services\Logic\Search\Course as CourseSearchService;
|
||||
use App\Services\Logic\Search\Group as GroupSearchService;
|
||||
use App\Services\Logic\Search\User as UserSearchService;
|
||||
use App\Services\Logic\Search\Article as ArticleSearch;
|
||||
use App\Services\Logic\Search\Course as CourseSearch;
|
||||
use App\Services\Logic\Search\Group as GroupSearch;
|
||||
use App\Services\Logic\Search\Question as QuestionSearch;
|
||||
use App\Services\Logic\Search\User as UserSearch;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/search")
|
||||
@ -45,22 +46,25 @@ class SearchController extends Controller
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return ArticleSearchService|CourseSearchService|GroupSearchService|UserSearchService
|
||||
* @return ArticleSearch|QuestionSearch|CourseSearch|GroupSearch|UserSearch
|
||||
*/
|
||||
protected function getSearchService($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'article':
|
||||
$service = new ArticleSearchService();
|
||||
$service = new ArticleSearch();
|
||||
break;
|
||||
case 'question':
|
||||
$service = new QuestionSearch();
|
||||
break;
|
||||
case 'group':
|
||||
$service = new GroupSearchService();
|
||||
$service = new GroupSearch();
|
||||
break;
|
||||
case 'user':
|
||||
$service = new UserSearchService();
|
||||
$service = new UserSearch();
|
||||
break;
|
||||
default:
|
||||
$service = new CourseSearchService();
|
||||
$service = new CourseSearch();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
||||
{%- endmacro %}
|
||||
|
||||
{%- macro live_status_info(lesson) %}
|
||||
{% if lesson.attrs.stream.status == 'active' %}
|
||||
{% if lesson.attrs.start_time < time() and lesson.attrs.end_time > time() %}
|
||||
<span class="active">{{ date('m月d日 H:i',lesson.attrs.start_time) }} 直播中</span>
|
||||
{% elseif lesson.attrs.start_time > time() %}
|
||||
<span class="pending">{{ date('m月d日 H:i',lesson.attrs.start_time) }} 倒计时</span>
|
||||
|
@ -16,7 +16,7 @@ class AppInfo
|
||||
|
||||
protected $link = 'https://koogua.com';
|
||||
|
||||
protected $version = '1.4.3';
|
||||
protected $version = '1.4.4';
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
|
@ -72,8 +72,6 @@ class ArticleList extends LogicService
|
||||
'source_type' => $article['source_type'],
|
||||
'source_url' => $article['source_url'],
|
||||
'tags' => $article['tags'],
|
||||
'category' => $category,
|
||||
'owner' => $owner,
|
||||
'private' => $article['private'],
|
||||
'published' => $article['published'],
|
||||
'closed' => $article['closed'],
|
||||
@ -83,6 +81,8 @@ class ArticleList extends LogicService
|
||||
'favorite_count' => $article['favorite_count'],
|
||||
'create_time' => $article['create_time'],
|
||||
'update_time' => $article['update_time'],
|
||||
'category' => $category,
|
||||
'owner' => $owner,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class CommentLike extends LogicService
|
||||
|
||||
$isFirstTime = false;
|
||||
|
||||
$commentLike->comment_id = $commentLike->deleted == 1 ? 0 : 1;
|
||||
$commentLike->deleted = $commentLike->deleted == 1 ? 0 : 1;
|
||||
|
||||
$commentLike->update();
|
||||
}
|
||||
|
@ -52,12 +52,17 @@ class LiveList extends LogicService
|
||||
$items = [];
|
||||
|
||||
foreach ($lives as $live) {
|
||||
|
||||
$course = $courses[$live['course_id']] ?? new \stdClass();
|
||||
$chapter = $chapters[$live['chapter_id']] ?? new \stdClass();
|
||||
|
||||
$items[] = [
|
||||
'course' => $courses[$live['course_id']] ?? new \stdClass(),
|
||||
'chapter' => $chapters[$live['chapter_id']] ?? new \stdClass(),
|
||||
'id' => $live['id'],
|
||||
'status' => $live['status'],
|
||||
'start_time' => $live['start_time'],
|
||||
'end_time' => $live['end_time'],
|
||||
'course' => $course,
|
||||
'chapter' => $chapter,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,8 @@ class QuestionList extends LogicService
|
||||
|
||||
$builder = new QuestionListBuilder();
|
||||
|
||||
$categories = $builder->getCategories();
|
||||
|
||||
$questions = $pager->items->toArray();
|
||||
|
||||
$users = $builder->getUsers($questions);
|
||||
@ -57,6 +59,8 @@ class QuestionList extends LogicService
|
||||
|
||||
$question['tags'] = json_decode($question['tags'], true);
|
||||
|
||||
$category = $categories[$question['category_id']] ?? new \stdClass();
|
||||
|
||||
$owner = $users[$question['owner_id']] ?? new \stdClass();
|
||||
|
||||
$lastReplier = $users[$question['last_replier_id']] ?? new \stdClass();
|
||||
@ -81,6 +85,7 @@ class QuestionList extends LogicService
|
||||
'create_time' => $question['create_time'],
|
||||
'update_time' => $question['update_time'],
|
||||
'last_replier' => $lastReplier,
|
||||
'category' => $category,
|
||||
'owner' => $owner,
|
||||
];
|
||||
}
|
||||
|
@ -64,6 +64,16 @@ class Article extends Handler
|
||||
|
||||
foreach ($pager->items as $item) {
|
||||
|
||||
$category = json_decode($item['category'], true);
|
||||
$owner = json_decode($item['owner'], true);
|
||||
$tags = json_decode($item['tags'], true);
|
||||
|
||||
$owner['avatar'] = $owner['avatar'] ?: kg_default_user_avatar_path();
|
||||
|
||||
if (!empty($owner['avatar']) && !Text::startsWith($owner['avatar'], 'http')) {
|
||||
$owner['avatar'] = $baseUrl . $owner['avatar'];
|
||||
}
|
||||
|
||||
if (!empty($item['cover']) && !Text::startsWith($item['cover'], 'http')) {
|
||||
$item['cover'] = $baseUrl . $item['cover'];
|
||||
}
|
||||
@ -78,9 +88,9 @@ class Article extends Handler
|
||||
'like_count' => (int)$item['like_count'],
|
||||
'favorite_count' => (int)$item['favorite_count'],
|
||||
'comment_count' => (int)$item['comment_count'],
|
||||
'tags' => json_decode($item['tags'], true),
|
||||
'owner' => json_decode($item['owner'], true),
|
||||
'category' => json_decode($item['category'], true),
|
||||
'category' => $category,
|
||||
'owner' => $owner,
|
||||
'tags' => $tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ namespace App\Services\Logic\Search;
|
||||
use App\Library\Paginator\Adapter\XunSearch as XunSearchPaginator;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Services\Search\CourseSearcher as CourseSearcherService;
|
||||
use Phalcon\Text;
|
||||
|
||||
class Course extends Handler
|
||||
{
|
||||
@ -63,7 +64,24 @@ class Course extends Handler
|
||||
|
||||
foreach ($pager->items as $item) {
|
||||
|
||||
$item['cover'] = $baseUrl . $item['cover'];
|
||||
/**
|
||||
* 后补的字段,给默认值防止出错
|
||||
*/
|
||||
$item['tags'] = $item['tags'] ?: '[]';
|
||||
|
||||
$category = json_decode($item['category'], true);
|
||||
$teacher = json_decode($item['teacher'], true);
|
||||
$tags = json_decode($item['tags'], true);
|
||||
|
||||
$teacher['avatar'] = $teacher['avatar'] ?: kg_default_user_avatar_path();
|
||||
|
||||
if (!empty($teacher['avatar']) && !Text::startsWith($teacher['avatar'], 'http')) {
|
||||
$teacher['avatar'] = $baseUrl . $teacher['avatar'];
|
||||
}
|
||||
|
||||
if (!empty($item['cover']) && !Text::startsWith($item['cover'], 'http')) {
|
||||
$item['cover'] = $baseUrl . $item['cover'];
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
'id' => (int)$item['id'],
|
||||
@ -78,8 +96,9 @@ class Course extends Handler
|
||||
'lesson_count' => (int)$item['lesson_count'],
|
||||
'review_count' => (int)$item['review_count'],
|
||||
'favorite_count' => (int)$item['favorite_count'],
|
||||
'teacher' => json_decode($item['teacher'], true),
|
||||
'category' => json_decode($item['category'], true),
|
||||
'category' => $category,
|
||||
'teacher' => $teacher,
|
||||
'tags' => $tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ namespace App\Services\Logic\Search;
|
||||
use App\Library\Paginator\Adapter\XunSearch as XunSearchPaginator;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Services\Search\GroupSearcher as GroupSearcherService;
|
||||
use Phalcon\Text;
|
||||
|
||||
class Group extends Handler
|
||||
{
|
||||
@ -63,7 +64,11 @@ class Group extends Handler
|
||||
|
||||
foreach ($pager->items as $item) {
|
||||
|
||||
$item['avatar'] = $baseUrl . $item['avatar'];
|
||||
$owner = json_decode($item['owner'], true);
|
||||
|
||||
if (!empty($item['avatar']) && !Text::startsWith($item['avatar'], 'http')) {
|
||||
$item['avatar'] = $baseUrl . $item['avatar'];
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
'id' => (int)$item['id'],
|
||||
@ -73,7 +78,7 @@ class Group extends Handler
|
||||
'about' => (string)$item['about'],
|
||||
'user_count' => (int)$item['user_count'],
|
||||
'msg_count' => (int)$item['msg_count'],
|
||||
'owner' => json_decode($item['owner'], true),
|
||||
'owner' => $owner,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,17 @@ class Question extends Handler
|
||||
|
||||
foreach ($pager->items as $item) {
|
||||
|
||||
$lastReplier = json_decode($item['last_replier'], true);
|
||||
$category = json_decode($item['category'], true);
|
||||
$owner = json_decode($item['owner'], true);
|
||||
$tags = json_decode($item['tags'], true);
|
||||
|
||||
$owner['avatar'] = $owner['avatar'] ?: kg_default_user_avatar_path();
|
||||
|
||||
if (!empty($owner['avatar']) && !Text::startsWith($owner['avatar'], 'http')) {
|
||||
$owner['avatar'] = $baseUrl . $owner['avatar'];
|
||||
}
|
||||
|
||||
if (!empty($item['cover']) && !Text::startsWith($item['cover'], 'http')) {
|
||||
$item['cover'] = $baseUrl . $item['cover'];
|
||||
}
|
||||
@ -71,13 +82,13 @@ class Question extends Handler
|
||||
$lastAnswer = json_decode($item['last_answer'], true);
|
||||
|
||||
if (!empty($lastAnswer['cover']) && !Text::startsWith($lastAnswer['cover'], 'http')) {
|
||||
$item['last_answer'] = $baseUrl . $lastAnswer['cover'];
|
||||
$lastAnswer['cover'] = $baseUrl . $lastAnswer['cover'];
|
||||
}
|
||||
|
||||
$acceptAnswer = json_decode($item['accept_answer'], true);
|
||||
|
||||
if (!empty($acceptAnswer['cover']) && !Text::startsWith($acceptAnswer['cover'], 'http')) {
|
||||
$item['accept_answer'] = $baseUrl . $acceptAnswer['cover'];
|
||||
$acceptAnswer['cover'] = $baseUrl . $acceptAnswer['cover'];
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
@ -95,12 +106,12 @@ class Question extends Handler
|
||||
'answer_count' => (int)$item['answer_count'],
|
||||
'comment_count' => (int)$item['comment_count'],
|
||||
'favorite_count' => (int)$item['favorite_count'],
|
||||
'category' => json_decode($item['category'], true),
|
||||
'tags' => json_decode($item['tags'], true),
|
||||
'owner' => json_decode($item['owner'], true),
|
||||
'last_replier' => json_decode($item['last_replier'], true),
|
||||
'last_answer' => $item['last_answer'],
|
||||
'accept_answer' => $item['accept_answer'],
|
||||
'accept_answer' => $acceptAnswer,
|
||||
'last_answer' => $lastAnswer,
|
||||
'last_replier' => $lastReplier,
|
||||
'category' => $category,
|
||||
'owner' => $owner,
|
||||
'tags' => $tags,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
namespace App\Services\Search;
|
||||
|
||||
use App\Models\Article as ArticleModel;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Repos\Category as CategoryRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
use Phalcon\Di\Injectable;
|
||||
@ -80,9 +81,12 @@ class ArticleDocument extends Injectable
|
||||
|
||||
$user = $userRepo->findById($id);
|
||||
|
||||
$user->avatar = UserModel::getAvatarPath($user->avatar);
|
||||
|
||||
return kg_json_encode([
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,10 @@
|
||||
|
||||
namespace App\Services\Search;
|
||||
|
||||
use App\Models\Category as CategoryModel;
|
||||
use App\Models\Course as CourseModel;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Repos\Category as CategoryRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
use Phalcon\Di\Injectable;
|
||||
|
||||
class CourseDocument extends Injectable
|
||||
@ -44,24 +45,20 @@ class CourseDocument extends Injectable
|
||||
$course->attrs = kg_json_encode($course->attrs);
|
||||
}
|
||||
|
||||
if (is_array($course->tags) || is_object($course->tags)) {
|
||||
$course->tags = kg_json_encode($course->tags);
|
||||
}
|
||||
|
||||
$teacher = '{}';
|
||||
|
||||
if ($course->teacher_id > 0) {
|
||||
$record = UserModel::findFirst($course->teacher_id);
|
||||
$teacher = kg_json_encode([
|
||||
'id' => $record->id,
|
||||
'name' => $record->name,
|
||||
]);
|
||||
$teacher = $this->handleUser($course->teacher_id);
|
||||
}
|
||||
|
||||
$category = '{}';
|
||||
|
||||
if ($course->category_id > 0) {
|
||||
$record = CategoryModel::findFirst($course->category_id);
|
||||
$category = kg_json_encode([
|
||||
'id' => $record->id,
|
||||
'name' => $record->name,
|
||||
]);
|
||||
$category = $this->handleCategory($course->category_id);
|
||||
}
|
||||
|
||||
$course->cover = CourseModel::getCoverPath($course->cover);
|
||||
@ -83,6 +80,7 @@ class CourseDocument extends Injectable
|
||||
'model' => $course->model,
|
||||
'level' => $course->level,
|
||||
'attrs' => $course->attrs,
|
||||
'tags' => $course->tags,
|
||||
'category' => $category,
|
||||
'teacher' => $teacher,
|
||||
'user_count' => $course->user_count,
|
||||
@ -92,4 +90,31 @@ class CourseDocument extends Injectable
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleUser($id)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($id);
|
||||
|
||||
$user->avatar = UserModel::getAvatarPath($user->avatar);
|
||||
|
||||
return kg_json_encode([
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function handleCategory($id)
|
||||
{
|
||||
$categoryRepo = new CategoryRepo();
|
||||
|
||||
$category = $categoryRepo->findById($id);
|
||||
|
||||
return kg_json_encode([
|
||||
'id' => $category->id,
|
||||
'name' => $category->name,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace App\Services\Search;
|
||||
|
||||
use App\Models\ImGroup as GroupModel;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Repos\User as UserRepo;
|
||||
use Phalcon\Di\Injectable;
|
||||
|
||||
class GroupDocument extends Injectable
|
||||
@ -42,11 +43,7 @@ class GroupDocument extends Injectable
|
||||
$owner = '{}';
|
||||
|
||||
if ($group->owner_id > 0) {
|
||||
$record = UserModel::findFirst($group->owner_id);
|
||||
$owner = kg_json_encode([
|
||||
'id' => $record->id,
|
||||
'name' => $record->name,
|
||||
]);
|
||||
$owner = $this->handleUser($group->owner_id);
|
||||
}
|
||||
|
||||
$group->avatar = GroupModel::getAvatarPath($group->avatar);
|
||||
@ -62,4 +59,19 @@ class GroupDocument extends Injectable
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleUser($id)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($id);
|
||||
|
||||
$user->avatar = UserModel::getAvatarPath($user->avatar);
|
||||
|
||||
return kg_json_encode([
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
namespace App\Services\Search;
|
||||
|
||||
use App\Models\Question as QuestionModel;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Repos\Answer as AnswerRepo;
|
||||
use App\Repos\Category as CategoryRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
@ -93,11 +94,11 @@ class QuestionDocument extends Injectable
|
||||
'answer_count' => $question->answer_count,
|
||||
'comment_count' => $question->comment_count,
|
||||
'favorite_count' => $question->favorite_count,
|
||||
'accept_answer' => $acceptAnswer,
|
||||
'last_answer' => $lastAnswer,
|
||||
'last_replier' => $lastReplier,
|
||||
'category' => $category,
|
||||
'owner' => $owner,
|
||||
'last_replier' => $lastReplier,
|
||||
'last_answer' => $lastAnswer,
|
||||
'accept_answer' => $acceptAnswer,
|
||||
];
|
||||
}
|
||||
|
||||
@ -107,9 +108,12 @@ class QuestionDocument extends Injectable
|
||||
|
||||
$user = $userRepo->findById($id);
|
||||
|
||||
$user->avatar = UserModel::getAvatarPath($user->avatar);
|
||||
|
||||
return kg_json_encode([
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'avatar' => $user->avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class Answer extends Validator
|
||||
|
||||
public function checkContent($content)
|
||||
{
|
||||
$value = $this->filter->sanitize($content, ['trim', 'string']);
|
||||
$value = $this->filter->sanitize($content, ['trim']);
|
||||
|
||||
$length = kg_strlen($value);
|
||||
|
||||
|
@ -84,7 +84,7 @@ class PointGift extends Validator
|
||||
|
||||
public function checkDetails($details)
|
||||
{
|
||||
$value = $this->filter->sanitize($details, ['trim', 'string']);
|
||||
$value = $this->filter->sanitize($details, ['trim']);
|
||||
|
||||
$length = kg_strlen($value);
|
||||
|
||||
|
@ -61,6 +61,9 @@ tokenizer = full
|
||||
[attrs]
|
||||
type = string
|
||||
|
||||
[tags]
|
||||
type = string
|
||||
|
||||
[category]
|
||||
type = string
|
||||
|
||||
|
27
db/migrations/20210825111618.php
Normal file
27
db/migrations/20210825111618.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class V20210825111618 extends AbstractMigration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->alterUploadTable();
|
||||
}
|
||||
|
||||
protected function alterUploadTable()
|
||||
{
|
||||
$table = $this->table('kg_upload');
|
||||
|
||||
$table->removeIndexByName('md5')->save();
|
||||
|
||||
$table->addIndex('md5')->save();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user