\ No newline at end of file
diff --git a/app/Http/Web/Views/course/ajax_teachers.volt b/app/Http/Web/Views/course/teachers.volt
similarity index 100%
rename from app/Http/Web/Views/course/ajax_teachers.volt
rename to app/Http/Web/Views/course/teachers.volt
diff --git a/app/Http/Web/Views/course/ajax_topics.volt b/app/Http/Web/Views/course/topics.volt
similarity index 100%
rename from app/Http/Web/Views/course/ajax_topics.volt
rename to app/Http/Web/Views/course/topics.volt
diff --git a/app/Http/Web/Views/partials/macro_course.volt b/app/Http/Web/Views/partials/macro_course.volt
index 6b567a73..d70caa3e 100644
--- a/app/Http/Web/Views/partials/macro_course.volt
+++ b/app/Http/Web/Views/partials/macro_course.volt
@@ -20,6 +20,13 @@
{% endif %}
{%- endmacro %}
+{%- macro star_info(rating) %}
+ {% set stars = [1,2,3,4,5] %}
+ {% for val in stars if val <= rating %}
+
+ {% endfor %}
+{%- endmacro %}
+
{%- macro course_card(course) %}
{% set course_url = url({'for':'web.course.show','id':course.id}) %}
diff --git a/app/Http/Web/Views/course/rating.volt b/app/Http/Web/Views/review/add.volt
similarity index 97%
rename from app/Http/Web/Views/course/rating.volt
rename to app/Http/Web/Views/review/add.volt
index 46e317a8..58bad1fe 100644
--- a/app/Http/Web/Views/course/rating.volt
+++ b/app/Http/Web/Views/review/add.volt
@@ -30,7 +30,7 @@
-
+
diff --git a/app/Http/Web/Views/teacher/ajax_pager.volt b/app/Http/Web/Views/teacher/pager.volt
similarity index 100%
rename from app/Http/Web/Views/teacher/ajax_pager.volt
rename to app/Http/Web/Views/teacher/pager.volt
diff --git a/app/Http/Web/Views/user/ajax_courses.volt b/app/Http/Web/Views/user/courses.volt
similarity index 100%
rename from app/Http/Web/Views/user/ajax_courses.volt
rename to app/Http/Web/Views/user/courses.volt
diff --git a/app/Http/Web/Views/user/ajax_favorites.volt b/app/Http/Web/Views/user/favorites.volt
similarity index 100%
rename from app/Http/Web/Views/user/ajax_favorites.volt
rename to app/Http/Web/Views/user/favorites.volt
diff --git a/app/Http/Web/Views/user/ajax_friends.volt b/app/Http/Web/Views/user/friends.volt
similarity index 100%
rename from app/Http/Web/Views/user/ajax_friends.volt
rename to app/Http/Web/Views/user/friends.volt
diff --git a/app/Library/Cache/Backend/Redis.php b/app/Library/Cache/Backend/Redis.php
index c78ad6f2..57422183 100644
--- a/app/Library/Cache/Backend/Redis.php
+++ b/app/Library/Cache/Backend/Redis.php
@@ -143,9 +143,10 @@ class Redis extends \Phalcon\Cache\Backend\Redis
* {@inheritdoc}
*
* @param string $prefix
+ * @param int $limit
* @return array
*/
- public function queryKeys($prefix = null): array
+ public function queryKeys($prefix = null, $limit = 1000): array
{
$result = [];
@@ -158,6 +159,7 @@ class Redis extends \Phalcon\Cache\Backend\Redis
$it = null;
while ($keys = $redis->scan($it, $pattern)) {
+ if (count($result) > $limit) break;
$result = array_merge($result, $keys);
}
diff --git a/app/Listeners/ChapterCounter.php b/app/Listeners/ChapterCounter.php
index 4e248227..5933da47 100644
--- a/app/Listeners/ChapterCounter.php
+++ b/app/Listeners/ChapterCounter.php
@@ -31,16 +31,16 @@ class ChapterCounter extends Listener
$this->syncChapterCounter($chapter);
}
- public function incrCommentCount(Event $event, $source, ChapterModel $chapter)
+ public function incrConsultCount(Event $event, $source, ChapterModel $chapter)
{
- $this->counter->hIncrBy($chapter->id, 'comment_count');
+ $this->counter->hIncrBy($chapter->id, 'consult_count');
$this->syncChapterCounter($chapter);
}
- public function decrCommentCount(Event $event, $source, ChapterModel $chapter)
+ public function decrConsultCount(Event $event, $source, ChapterModel $chapter)
{
- $this->counter->hDecrBy($chapter->id, 'comment_count');
+ $this->counter->hDecrBy($chapter->id, 'consult_count');
$this->syncChapterCounter($chapter);
}
diff --git a/app/Listeners/CommentCounter.php b/app/Listeners/CommentCounter.php
deleted file mode 100644
index 1185e077..00000000
--- a/app/Listeners/CommentCounter.php
+++ /dev/null
@@ -1,55 +0,0 @@
-counter = new CacheCommentCounter();
- }
-
- public function incrReplyCount(Event $event, $source, CommentModel $comment)
- {
- $this->counter->hIncrBy($comment->id, 'reply_count');
-
- $this->syncCommentCounter($comment);
- }
-
- public function decrReplyCount(Event $event, $source, CommentModel $comment)
- {
- $this->counter->hDecrBy($comment->id, 'reply_count');
-
- $this->syncCommentCounter($comment);
- }
-
- public function incrLikeCount(Event $event, $source, CommentModel $comment)
- {
- $this->counter->hIncrBy($comment->id, 'like_count');
-
- $this->syncCommentCounter($comment);
- }
-
- public function decrLikeCount(Event $event, $source, CommentModel $comment)
- {
- $this->counter->hDecrBy($comment->id, 'like_count');
-
- $this->syncCommentCounter($comment);
- }
-
- protected function syncCommentCounter(CommentModel $comment)
- {
- $syncer = new CommentCounterSyncer();
-
- $syncer->addItem($comment->id);
- }
-
-}
\ No newline at end of file
diff --git a/app/Listeners/CourseCounter.php b/app/Listeners/CourseCounter.php
index 55efb03f..36febf58 100644
--- a/app/Listeners/CourseCounter.php
+++ b/app/Listeners/CourseCounter.php
@@ -68,20 +68,6 @@ class CourseCounter extends Listener
$this->syncCourseIndex($course);
}
- public function incrCommentCount(Event $event, $source, CourseModel $course)
- {
- $this->counter->hIncrBy($course->id, 'comment_count');
-
- $this->syncCourseCounter($course);
- }
-
- public function decrCommentCount(Event $event, $source, CourseModel $course)
- {
- $this->counter->hDecrBy($course->id, 'comment_count');
-
- $this->syncCourseCounter($course);
- }
-
public function incrFavoriteCount(Event $event, $source, CourseModel $course)
{
$this->counter->hIncrBy($course->id, 'favorite_count');
diff --git a/app/Listeners/UserDailyCounter.php b/app/Listeners/UserDailyCounter.php
index dc313e83..88cee653 100644
--- a/app/Listeners/UserDailyCounter.php
+++ b/app/Listeners/UserDailyCounter.php
@@ -21,11 +21,6 @@ class UserDailyCounter extends Listener
$this->counter->hIncrBy($user->id, 'favorite_count');
}
- public function incrCommentCount(Event $event, $source, UserModel $user)
- {
- $this->counter->hIncrBy($user->id, 'comment_count');
- }
-
public function incrDanmuCount(Event $event, $source, UserModel $user)
{
$this->counter->hIncrBy($user->id, 'danmu_count');
@@ -46,11 +41,6 @@ class UserDailyCounter extends Listener
$this->counter->hIncrBy($user->id, 'order_count');
}
- public function incrCommentLikeCount(Event $event, $source, UserModel $user)
- {
- $this->counter->hIncrBy($user->id, 'comment_like_count');
- }
-
public function incrConsultLikeCount(Event $event, $source, UserModel $user)
{
$this->counter->hIncrBy($user->id, 'consult_like_count');
diff --git a/app/Models/Comment.php b/app/Models/Comment.php
deleted file mode 100644
index 35c5758d..00000000
--- a/app/Models/Comment.php
+++ /dev/null
@@ -1,132 +0,0 @@
-addBehavior(
- new SoftDelete([
- 'field' => 'deleted',
- 'value' => 1,
- ])
- );
- }
-
- public function beforeCreate()
- {
- $this->create_time = time();
- }
-
- public function beforeUpdate()
- {
- $this->update_time = time();
-
- if ($this->deleted == 1) {
- $this->published = 0;
- }
- }
-
-}
diff --git a/app/Models/CommentLike.php b/app/Models/CommentLike.php
deleted file mode 100644
index f3cbc300..00000000
--- a/app/Models/CommentLike.php
+++ /dev/null
@@ -1,79 +0,0 @@
-addBehavior(
- new SoftDelete([
- 'field' => 'deleted',
- 'value' => 1,
- ])
- );
- }
-
- public function beforeCreate()
- {
- $this->create_time = time();
- }
-
- public function beforeUpdate()
- {
- $this->update_time = time();
- }
-
-}
diff --git a/app/Models/Consult.php b/app/Models/Consult.php
index df708aea..15939fc3 100644
--- a/app/Models/Consult.php
+++ b/app/Models/Consult.php
@@ -7,6 +7,13 @@ use Phalcon\Mvc\Model\Behavior\SoftDelete;
class Consult extends Model
{
+ /**
+ * 优先级
+ */
+ const PRIORITY_HIGH = 10; // 高
+ const PRIORITY_MIDDLE = 20; // 中
+ const PRIORITY_LOW = 30; // 低
+
/**
* 主键编号
*
@@ -21,6 +28,13 @@ class Consult extends Model
*/
public $course_id;
+ /**
+ * 章节编号
+ *
+ * @var int
+ */
+ public $chapter_id;
+
/**
* 用户编号
*
diff --git a/app/Models/ImGroup.php b/app/Models/ImGroup.php
index 0d5b4005..884afb76 100644
--- a/app/Models/ImGroup.php
+++ b/app/Models/ImGroup.php
@@ -51,7 +51,14 @@ class ImGroup extends Model
public $about;
/**
- * 状态
+ * 发布状态
+ *
+ * @var integer
+ */
+ public $published;
+
+ /**
+ * 删除状态
*
* @var integer
*/
@@ -109,6 +116,10 @@ class ImGroup extends Model
public function beforeUpdate()
{
$this->update_time = time();
+
+ if ($this->deleted == 1) {
+ $this->published = 0;
+ }
}
public function afterFetch()
diff --git a/app/Repos/Comment.php b/app/Repos/Comment.php
deleted file mode 100644
index a1f55c41..00000000
--- a/app/Repos/Comment.php
+++ /dev/null
@@ -1,111 +0,0 @@
-modelsManager->createBuilder();
-
- $builder->from(CommentModel::class);
-
- $builder->where('1 = 1');
-
- if (!empty($where['id'])) {
- $builder->andWhere('id = :id:', ['id' => $where['id']]);
- }
-
- if (!empty($where['parent_id'])) {
- $builder->andWhere('parent_id = :parent_id:', ['parent_id' => $where['parent_id']]);
- }
-
- if (!empty($where['course_id'])) {
- $builder->andWhere('course_id = :course_id:', ['course_id' => $where['course_id']]);
- }
-
- if (!empty($where['chapter_id'])) {
- $builder->andWhere('chapter_id = :chapter_id:', ['chapter_id' => $where['chapter_id']]);
- }
-
- if (!empty($where['user_id'])) {
- $builder->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]);
- }
-
- if (isset($where['published'])) {
- $builder->andWhere('published = :published:', ['published' => $where['published']]);
- }
-
- if (isset($where['deleted'])) {
- $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]);
- }
-
- switch ($sort) {
- default:
- $orderBy = 'id DESC';
- break;
- }
-
- $builder->orderBy($orderBy);
-
- $pager = new PagerQueryBuilder([
- 'builder' => $builder,
- 'page' => $page,
- 'limit' => $limit,
- ]);
-
- return $pager->paginate();
- }
-
- /**
- * @param int $id
- * @return CommentModel|Model|bool
- */
- public function findById($id)
- {
- return CommentModel::findFirst($id);
- }
-
- /**
- * @param array $ids
- * @param string|array $columns
- * @return ResultsetInterface|Resultset|CommentModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- return CommentModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
- }
-
- public function countComments()
- {
- return (int)CommentModel::count(['conditions' => 'deleted = 0']);
- }
-
- public function countReplies($commentId)
- {
- return (int)CommentModel::count([
- 'conditions' => 'parent_id = :parent_id: AND deleted = 0',
- 'bind' => ['parent_id' => $commentId],
- ]);
- }
-
- public function countLikes($commentId)
- {
- return (int)CommentLikeModel::count([
- 'conditions' => 'comment_id = :comment_id: AND deleted = 0',
- 'bind' => ['comment_id' => $commentId],
- ]);
- }
-
-}
diff --git a/app/Repos/CommentLike.php b/app/Repos/CommentLike.php
deleted file mode 100644
index 8e9bd8be..00000000
--- a/app/Repos/CommentLike.php
+++ /dev/null
@@ -1,24 +0,0 @@
- 'comment_id = :comment_id: AND user_id = :user_id:',
- 'bind' => ['comment_id' => $commentId, 'user_id' => $userId],
- ]);
- }
-
-}
diff --git a/app/Services/Frontend/Comment/CommentCreate.php b/app/Services/Frontend/Comment/CommentCreate.php
deleted file mode 100644
index 3de237c5..00000000
--- a/app/Services/Frontend/Comment/CommentCreate.php
+++ /dev/null
@@ -1,77 +0,0 @@
-request->getPost();
-
- $user = $this->getLoginUser();
-
- $chapter = $this->checkChapter($post['chapter_id']);
-
- $course = $this->checkCourse($chapter->course_id);
-
- $validator = new UserDailyLimitValidator();
-
- $validator->checkCommentLimit($user);
-
- $validator = new CommentValidator();
-
- $data = [];
-
- $data['content'] = $validator->checkContent($post['content']);
-
- if (isset($post['parent_id'])) {
- $parent = $validator->checkParent($post['parent_id']);
- $data['parent_id'] = $parent->id;
- }
-
- $comment = new CommentModel();
-
- $data['course_id'] = $course->id;
- $data['chapter_id'] = $chapter->id;
- $data['user_id'] = $user->id;
-
- $comment->create($data);
-
- $this->incrChapterCommentCount($chapter);
-
- $this->incrCourseCommentCount($course);
-
- $this->incrUserDailyCommentCount($user);
-
- return $comment;
- }
-
- protected function incrChapterCommentCount(ChapterModel $chapter)
- {
- $this->eventsManager->fire('chapterCounter:incrCommentCount', $this, $chapter);
- }
-
- protected function incrCourseCommentCount(CourseModel $course)
- {
- $this->eventsManager->fire('courseCounter:incrCommentCount', $this, $course);
- }
-
- protected function incrUserDailyCommentCount(UserModel $user)
- {
- $this->eventsManager->fire('userDailyCounter:incrCommentCount', $this, $user);
- }
-
-}
diff --git a/app/Services/Frontend/Comment/CommentDelete.php b/app/Services/Frontend/Comment/CommentDelete.php
deleted file mode 100644
index 29e78e8e..00000000
--- a/app/Services/Frontend/Comment/CommentDelete.php
+++ /dev/null
@@ -1,49 +0,0 @@
-checkComment($id);
-
- $chapter = $this->checkChapter($comment->chapter_id);
-
- $course = $this->checkCourse($comment->course_id);
-
- $user = $this->getLoginUser();
-
- $validator = new CommentValidator();
-
- $validator->checkOwner($user->id, $comment->user_id);
-
- $comment->delete();
-
- $this->decrChapterCommentCount($chapter);
-
- $this->decrCourseCommentCount($course);
- }
-
- protected function decrChapterCommentCount(ChapterModel $chapter)
- {
- $this->eventsManager->fire('chapterCounter:decrCommentCount', $this, $chapter);
- }
-
- protected function decrCourseCommentCount(CourseModel $course)
- {
- $this->eventsManager->fire('courseCounter:decrCommentCount', $this, $course);
- }
-
-}
diff --git a/app/Services/Frontend/Comment/CommentInfo.php b/app/Services/Frontend/Comment/CommentInfo.php
deleted file mode 100644
index 62659d1e..00000000
--- a/app/Services/Frontend/Comment/CommentInfo.php
+++ /dev/null
@@ -1,45 +0,0 @@
-checkComment($id);
-
- return $this->handleComment($comment);
- }
-
- protected function handleComment(CommentModel $comment)
- {
- $result = [
- 'id' => $comment->id,
- 'content' => $comment->content,
- 'like_count' => $comment->like_count,
- 'create_time' => $comment->create_time,
- 'update_time' => $comment->update_time,
- ];
-
- $userRepo = new UserRepo();
-
- $owner = $userRepo->findById($comment->user_id);
-
- $result['user'] = [
- 'id' => $owner->id,
- 'name' => $owner->name,
- 'avatar' => $owner->avatar,
- ];
-
- return $result;
- }
-
-}
diff --git a/app/Services/Frontend/Comment/CommentLike.php b/app/Services/Frontend/Comment/CommentLike.php
deleted file mode 100644
index 46e5ca4f..00000000
--- a/app/Services/Frontend/Comment/CommentLike.php
+++ /dev/null
@@ -1,88 +0,0 @@
-checkComment($id);
-
- $user = $this->getLoginUser();
-
- $validator = new UserDailyLimitValidator();
-
- $validator->checkCommentLikeLimit($user);
-
- $validator = new CommentValidator();
-
- $commentLike = $validator->checkIfLiked($comment->id, $user->id);
-
- if (!$commentLike) {
-
- $commentLike = new CommentLikeModel();
-
- $commentLike->create([
- 'comment_id' => $comment->id,
- 'user_id' => $user->id,
- ]);
-
- $this->incrLikeCount($comment);
-
- } else {
-
- if ($commentLike->deleted == 0) {
-
- $commentLike->update(['deleted' => 1]);
-
- $this->decrLikeCount($comment);
-
- } else {
-
- $commentLike->update(['deleted' => 0]);
-
- $this->incrLikeCount($comment);
- }
- }
-
- $this->incrUserDailyCommentLikeCount($user);
-
- return $comment;
- }
-
- protected function incrLikeCount(CommentModel $comment)
- {
- $this->getPhEventsManager()->fire('commentCounter:incrLikeCount', $this, $comment);
- }
-
- protected function decrLikeCount(CommentModel $comment)
- {
- $this->getPhEventsManager()->fire('commentCounter:decrLikeCount', $this, $comment);
- }
-
- protected function incrUserDailyCommentLikeCount(UserModel $user)
- {
- $this->getPhEventsManager()->fire('userDailyCounter:incrCommentLikeCount', $this, $user);
- }
-
- /**
- * @return EventsManager
- */
- protected function getPhEventsManager()
- {
- return $this->getDI()->get('eventsManager');
- }
-
-}
diff --git a/app/Services/Frontend/Comment/CommentUpdate.php b/app/Services/Frontend/Comment/CommentUpdate.php
deleted file mode 100644
index a8d1823f..00000000
--- a/app/Services/Frontend/Comment/CommentUpdate.php
+++ /dev/null
@@ -1,42 +0,0 @@
-request->getPost();
-
- $user = $this->getLoginUser();
-
- $comment = $this->checkComment($id);
-
- $validator = new CommentValidator();
-
- $validator->checkOwner($user->id, $comment->user_id);
-
- $data = [];
-
- $data['content'] = $validator->checkContent($post['content']);
-
- if (isset($post['mentions'])) {
- $data['mentions'] = $validator->checkMentions($post['mentions']);
- }
-
- $comment->update($data);
- }
-
- protected function handleMentions($mentions)
- {
-
- }
-
-}
diff --git a/app/Services/Frontend/CommentTrait.php b/app/Services/Frontend/CommentTrait.php
deleted file mode 100644
index 0a98fbc3..00000000
--- a/app/Services/Frontend/CommentTrait.php
+++ /dev/null
@@ -1,17 +0,0 @@
-checkComment($id);
- }
-
-}
diff --git a/app/Services/Frontend/Consult/ConsultCreate.php b/app/Services/Frontend/Consult/ConsultCreate.php
index d4a7a59a..94b94a3a 100644
--- a/app/Services/Frontend/Consult/ConsultCreate.php
+++ b/app/Services/Frontend/Consult/ConsultCreate.php
@@ -2,9 +2,11 @@
namespace App\Services\Frontend\Consult;
+use App\Models\Chapter as ChapterModel;
use App\Models\Consult as ConsultModel;
use App\Models\Course as CourseModel;
use App\Models\User as UserModel;
+use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Consult as ConsultValidator;
@@ -13,7 +15,7 @@ use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class ConsultCreate extends FrontendService
{
- use CourseTrait;
+ use CourseTrait, ChapterTrait;
public function handle()
{
@@ -21,7 +23,9 @@ class ConsultCreate extends FrontendService
$user = $this->getLoginUser();
- $course = $this->checkCourseCache($post['course_id']);
+ $chapter = $this->checkChapter($post['chapter_id']);
+
+ $course = $this->checkCourse($chapter->course_id);
$validator = new UserDailyLimitValidator();
@@ -31,26 +35,51 @@ class ConsultCreate extends FrontendService
$question = $validator->checkQuestion($post['question']);
+ $priority = $this->getPriority($course, $user);
+
$consult = new ConsultModel();
- $consult->course_id = $course->id;
- $consult->user_id = $user->id;
$consult->question = $question;
+ $consult->priority = $priority;
+ $consult->course_id = $course->id;
+ $consult->chapter_id = $chapter->id;
+ $consult->user_id = $user->id;
$consult->create();
$this->incrCourseConsultCount($course);
-
+ $this->incrChapterConsultCount($chapter);
$this->incrUserDailyConsultCount($user);
return $consult;
}
+ protected function getPriority(CourseModel $course, UserModel $user)
+ {
+ $charge = $course->market_price > 0;
+ $vip = $user->vip == 1;
+
+ if ($vip && $charge) {
+ $priority = ConsultModel::PRIORITY_HIGH;
+ } elseif ($charge) {
+ $priority = ConsultModel::PRIORITY_MIDDLE;
+ } else {
+ $priority = ConsultModel::PRIORITY_LOW;
+ }
+
+ return $priority;
+ }
+
protected function incrCourseConsultCount(CourseModel $course)
{
$this->eventsManager->fire('courseCounter:incrConsultCount', $this, $course);
}
+ protected function incrChapterConsultCount(ChapterModel $chapter)
+ {
+ $this->eventsManager->fire('chapterCounter:incrConsultCount', $this, $chapter);
+ }
+
protected function incrUserDailyConsultCount(UserModel $user)
{
$this->eventsManager->fire('userDailyCounter:incrConsultCount', $this, $user);
diff --git a/app/Services/Frontend/Course/ConsultList.php b/app/Services/Frontend/Course/ConsultList.php
index f06fbaba..0ec190ef 100644
--- a/app/Services/Frontend/Course/ConsultList.php
+++ b/app/Services/Frontend/Course/ConsultList.php
@@ -27,7 +27,6 @@ class ConsultList extends FrontendService
'course_id' => $course->id,
'private' => 0,
'published' => 1,
- 'deleted' => 0,
];
$consultRepo = new ConsultRepo();
diff --git a/app/Services/Frontend/Course/CourseInfo.php b/app/Services/Frontend/Course/CourseInfo.php
index 83b00738..d5ebe858 100644
--- a/app/Services/Frontend/Course/CourseInfo.php
+++ b/app/Services/Frontend/Course/CourseInfo.php
@@ -4,6 +4,7 @@ namespace App\Services\Frontend\Course;
use App\Models\Course as CourseModel;
use App\Models\User as UserModel;
+use App\Repos\Course as CourseRepo;
use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service as FrontendService;
@@ -26,6 +27,17 @@ class CourseInfo extends FrontendService
protected function handleCourse(CourseModel $course, UserModel $user)
{
+ $repo = new CourseRepo();
+
+ $rating = $repo->findCourseRating($course->id);
+
+ $ratings = [
+ 'rating' => $rating->rating,
+ 'rating1' => $rating->rating1,
+ 'rating2' => $rating->rating2,
+ 'rating3' => $rating->rating3,
+ ];
+
$result = [
'id' => $course->id,
'title' => $course->title,
@@ -39,7 +51,7 @@ class CourseInfo extends FrontendService
'vip_price' => $course->vip_price,
'study_expiry' => $course->study_expiry,
'refund_expiry' => $course->refund_expiry,
- 'rating' => $course->rating,
+ 'ratings' => $ratings,
'model' => $course->model,
'level' => $course->level,
'attrs' => $course->attrs,
@@ -47,7 +59,6 @@ class CourseInfo extends FrontendService
'lesson_count' => $course->lesson_count,
'package_count' => $course->package_count,
'review_count' => $course->review_count,
- 'comment_count' => $course->comment_count,
'consult_count' => $course->consult_count,
'favorite_count' => $course->favorite_count,
];
diff --git a/app/Services/Frontend/Course/ReviewList.php b/app/Services/Frontend/Course/ReviewList.php
index e5b87331..9c035219 100644
--- a/app/Services/Frontend/Course/ReviewList.php
+++ b/app/Services/Frontend/Course/ReviewList.php
@@ -26,7 +26,6 @@ class ReviewList extends FrontendService
$params = [
'course_id' => $course->id,
'published' => 1,
- 'deleted' => 0,
];
$reviewRepo = new ReviewRepo();
diff --git a/app/Validators/Comment.php b/app/Validators/Comment.php
deleted file mode 100644
index 1c20ad6c..00000000
--- a/app/Validators/Comment.php
+++ /dev/null
@@ -1,94 +0,0 @@
-findById($id);
-
- if (!$comment) {
- throw new BadRequestException('comment.not_found');
- }
-
- return $comment;
- }
-
- public function checkChapter($chapterId)
- {
- $chapterRepo = new ChapterRepo();
-
- $chapter = $chapterRepo->findById($chapterId);
-
- if (!$chapter) {
- throw new BadRequestException('comment.invalid_chapter_id');
- }
-
- return $chapter;
- }
-
- public function checkParent($parentId)
- {
- $commentRepo = new CourseRepo();
-
- $parent = $commentRepo->findById($parentId);
-
- if (!$parent) {
- throw new BadRequestException('comment.invalid_parent_id');
- }
-
- return $parent;
- }
-
- public function checkContent($content)
- {
- $value = $this->filter->sanitize($content, ['trim', 'string']);
-
- $length = kg_strlen($value);
-
- if ($length < 1) {
- throw new BadRequestException('comment.content_too_short');
- }
-
- if ($length > 1000) {
- throw new BadRequestException('comment.content_too_long');
- }
-
- return $value;
- }
-
- public function checkPublishStatus($status)
- {
- if (!in_array($status, [0, 1])) {
- throw new BadRequestException('consult.invalid_publish_status');
- }
-
- return $status;
- }
-
- public function checkIfLiked($chapterId, $userId)
- {
- $repo = new CommentLikeRepo();
-
- $like = $repo->findCommentLike($chapterId, $userId);
-
- if ($like) {
- if ($like->deleted == 0 && time() - $like->create_time > 5 * 60) {
- throw new BadRequestException('comment.has_liked');
- }
- }
-
- return $like;
- }
-
-}
diff --git a/app/Validators/Consult.php b/app/Validators/Consult.php
index 15f4b815..93ef050e 100644
--- a/app/Validators/Consult.php
+++ b/app/Validators/Consult.php
@@ -29,6 +29,13 @@ class Consult extends Validator
return $validator->checkCourse($id);
}
+ public function checkChapter($id)
+ {
+ $validator = new Chapter();
+
+ return $validator->checkChapter($id);
+ }
+
public function checkQuestion($question)
{
$value = $this->filter->sanitize($question, ['trim', 'string']);
diff --git a/app/Validators/UserDailyLimit.php b/app/Validators/UserDailyLimit.php
index 2f14c65e..c5e002dc 100644
--- a/app/Validators/UserDailyLimit.php
+++ b/app/Validators/UserDailyLimit.php
@@ -27,17 +27,6 @@ class UserDailyLimit extends Validator
}
}
- public function checkCommentLimit(UserModel $user)
- {
- $count = $this->counter->hGet($user->id, 'comment_count');
-
- $limit = $user->vip ? 100 : 50;
-
- if ($count > $limit) {
- throw new BadRequestException('user_daily_limit.reach_comment_limit');
- }
- }
-
public function checkDanmuLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'danmu_count');
@@ -89,17 +78,6 @@ class UserDailyLimit extends Validator
}
}
- public function checkCommentLikeLimit(UserModel $user)
- {
- $count = $this->counter->hGet($user->id, 'comment_like_count');
-
- $limit = $user->vip ? 200 : 100;
-
- if ($count > $limit) {
- throw new BadRequestException('user_daily_limit.reach_like_limit');
- }
- }
-
public function checkConsultLikeLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'consult_like_count');
diff --git a/config/errors.php b/config/errors.php
index 4c5321da..35c5e904 100644
--- a/config/errors.php
+++ b/config/errors.php
@@ -201,21 +201,12 @@ $error['review.has_liked'] = '你已经点过赞啦';
$error['consult.not_found'] = '咨询不存在';
$error['consult.invalid_private_status'] = '无效的私密状态';
$error['consult.invalid_publish_status'] = '无效的发布状态';
-$error['consult.question_too_short'] = '提问太短(少于5个字符)';
-$error['consult.question_too_long'] = '提问太长(多于1000个字符)';
-$error['consult.answer_too_short'] = '回复太短(少于5个字符)';
-$error['consult.answer_too_long'] = '回复太长(多于1000个字符)';
+$error['consult.question_too_short'] = '问题内容太短(少于5个字符)';
+$error['consult.question_too_long'] = '问题内容太长(多于1000个字符)';
+$error['consult.answer_too_short'] = '回复内容太短(少于5个字符)';
+$error['consult.answer_too_long'] = '回复内容太长(多于1000个字符)';
$error['consult.has_liked'] = '你已经点过赞啦';
-/**
- * 评论相关
- */
-$error['comment.not_found'] = '评价不存在';
-$error['comment.invalid_publish_status'] = '无效的发布状态';
-$error['comment.content_too_short'] = '评价太短(少于1个字符)';
-$error['comment.content_too_long'] = '评价太长(多于1000个字符)';
-$error['comment.has_liked'] = '你已经点过赞啦';
-
/**
* 单页相关
*/
diff --git a/config/events.php b/config/events.php
index 4df77f01..09383864 100644
--- a/config/events.php
+++ b/config/events.php
@@ -1,7 +1,6 @@
Pay::class,
'courseCounter' => CourseCounter::class,
'chapterCounter' => ChapterCounter::class,
- 'commentCounter' => CommentCounter::class,
'consultCounter' => ConsultCounter::class,
'reviewCounter' => ReviewCounter::class,
'userDailyCounter' => UserDailyCounter::class,
diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css
index 04aab267..3db71a4e 100644
--- a/public/static/web/css/common.css
+++ b/public/static/web/css/common.css
@@ -432,38 +432,17 @@ body {
}
.course-meta .info {
- position: relative;
float: left;
- width: 80%;
+ width: 400px;
}
-.course-meta .share {
- position: absolute;
- top: 0;
- right: 0;
+.course-meta .rating {
+ float: right;
+ padding: 10px 50px 0 0;
}
-.course-meta .share a {
- margin-right: 5px;
- color: #999;
-}
-
-.course-meta .share a:hover {
- color: #000;
-}
-
-.course-meta .price {
- color: red;
- font-size: 14px;
-}
-
-.course-meta .free {
- color: green;
-}
-
-.course-meta span {
- color: #666;
- margin: 0 5px;
+.course-meta p {
+ line-height: 30px;
}
.course-meta .cover img {
@@ -471,8 +450,30 @@ body {
height: 118px;
}
-.course-meta p {
- line-height: 30px;
+.course-meta .info .price {
+ color: red;
+ font-size: 14px;
+}
+
+.course-meta .info .free {
+ color: green;
+}
+
+.course-meta .info span {
+ color: #666;
+ margin: 0 5px;
+}
+
+.course-meta .rating span {
+ margin: 0 3px;
+}
+
+.course-meta .rating .layui-icon {
+ color: orange;
+}
+
+.course-meta .rating .score {
+ color: #666;
}
.layui-tab-title li {
diff --git a/public/static/web/js/chapter.vod.js b/public/static/web/js/chapter.vod.js
new file mode 100644
index 00000000..d8bc4881
--- /dev/null
+++ b/public/static/web/js/chapter.vod.js
@@ -0,0 +1,21 @@
+layui.use(['jquery', 'helper'], function () {
+
+ var $ = layui.jquery;
+ var helper = layui.helper;
+
+ /**
+ * 咨询
+ */
+ $('.icon-help').on('click', function () {
+ var url = $(this).parent().data('url');
+ helper.checkLogin(function () {
+ layer.open({
+ type: 2,
+ title: '课程咨询',
+ content: [url, 'no'],
+ area: ['640px', '300px']
+ });
+ });
+ });
+
+});
\ No newline at end of file
diff --git a/public/static/web/js/course.rating.js b/public/static/web/js/course.rating.js
index 5708de77..0bfbe6eb 100644
--- a/public/static/web/js/course.rating.js
+++ b/public/static/web/js/course.rating.js
@@ -3,12 +3,13 @@ layui.use(['jquery', 'rate'], function () {
var $ = layui.jquery;
var rate = layui.rate;
- $('.cancel-rating').on('click', function () {
+ $('.btn-cancel').on('click', function () {
parent.layer.closeAll();
});
rate.render({
elem: '#rating1',
+ value: 5,
choose: function (value) {
$('input[name=rating1]').val(value);
}
@@ -16,6 +17,7 @@ layui.use(['jquery', 'rate'], function () {
rate.render({
elem: '#rating2',
+ value: 5,
choose: function (value) {
$('input[name=rating2]').val(value);
}
@@ -23,6 +25,7 @@ layui.use(['jquery', 'rate'], function () {
rate.render({
elem: '#rating3',
+ value: 5,
choose: function (value) {
$('input[name=rating3]').val(value);
}
diff --git a/public/static/web/js/course.show.js b/public/static/web/js/course.show.js
index 6d5d2e38..c7bddff0 100644
--- a/public/static/web/js/course.show.js
+++ b/public/static/web/js/course.show.js
@@ -4,6 +4,9 @@ layui.use(['jquery', 'layer', 'helper'], function () {
var layer = layui.layer;
var helper = layui.helper;
+ /**
+ * 收藏
+ */
$('.icon-star').on('click', function () {
var $this = $(this);
helper.checkLogin(function () {
@@ -23,6 +26,9 @@ layui.use(['jquery', 'layer', 'helper'], function () {
});
});
+ /**
+ * 打赏
+ */
$('.btn-reward').on('click', function () {
var url = $(this).data('url');
helper.checkLogin(function () {
@@ -30,7 +36,10 @@ layui.use(['jquery', 'layer', 'helper'], function () {
});
});
- $('.btn-buy').on('click', function () {
+ /**
+ * 购买(课程|套餐)
+ */
+ $('body').on('click', '.btn-buy', function () {
var url = $(this).data('url');
helper.checkLogin(function () {
window.location.href = url;
@@ -47,6 +56,22 @@ layui.use(['jquery', 'layer', 'helper'], function () {
});
});
+ /**
+ * 浏览章节
+ */
+ $('body').on('click', '.view-lesson', function () {
+ if ($(this).hasClass('deny')) {
+ return false;
+ }
+ var url = $(this).data('url');
+ helper.checkLogin(function () {
+ window.location.href = url;
+ });
+ });
+
+ /**
+ * 点赞(咨询|评价)
+ */
$('body').on('click', '.icon-praise', function () {
var $this = $(this);
var $likeCount = $this.next();