diff --git a/app/Http/Api/Controllers/ChapterController.php b/app/Http/Api/Controllers/ChapterController.php index 3e0a75eb..1897b9d1 100644 --- a/app/Http/Api/Controllers/ChapterController.php +++ b/app/Http/Api/Controllers/ChapterController.php @@ -4,6 +4,7 @@ namespace App\Http\Api\Controllers; use App\Services\Logic\Chapter\ChapterInfo as ChapterInfoService; use App\Services\Logic\Chapter\ChapterLike as ChapterLikeService; +use App\Services\Logic\Chapter\ConsultList as ChapterConsultListService; use App\Services\Logic\Chapter\Learning as ChapterLearningService; use App\Services\Logic\Chapter\ResourceList as ChapterResourceListService; @@ -13,6 +14,18 @@ use App\Services\Logic\Chapter\ResourceList as ChapterResourceListService; class ChapterController extends Controller { + /** + * @Get("/{id:[0-9]+}/consults", name="api.chapter.consults") + */ + public function consultsAction($id) + { + $service = new ChapterConsultListService(); + + $pager = $service->handle($id); + + return $this->jsonSuccess(['pager' => $pager]); + } + /** * @Get("/{id:[0-9]+}/resources", name="api.chapter.resourses") */ diff --git a/app/Http/Api/Controllers/SearchController.php b/app/Http/Api/Controllers/SearchController.php index e2a8dd32..3f25c42a 100644 --- a/app/Http/Api/Controllers/SearchController.php +++ b/app/Http/Api/Controllers/SearchController.php @@ -45,7 +45,7 @@ class SearchController extends Controller { switch ($type) { case 'group': - $service = new GroupSearchService; + $service = new GroupSearchService(); break; case 'user': $service = new UserSearchService(); diff --git a/app/Http/Home/Controllers/SearchController.php b/app/Http/Home/Controllers/SearchController.php index e722a23e..279300c3 100644 --- a/app/Http/Home/Controllers/SearchController.php +++ b/app/Http/Home/Controllers/SearchController.php @@ -47,7 +47,7 @@ class SearchController extends Controller { switch ($type) { case 'group': - $service = new GroupSearchService; + $service = new GroupSearchService(); break; case 'user': $service = new UserSearchService(); diff --git a/app/Http/Home/Views/course/show_catalog.volt b/app/Http/Home/Views/course/show_catalog.volt index 60500c47..445f8feb 100644 --- a/app/Http/Home/Views/course/show_catalog.volt +++ b/app/Http/Home/Views/course/show_catalog.volt @@ -17,7 +17,6 @@ {%- macro live_lesson_info(lesson) %} {% set url = lesson.me.owned ? url({'for':'home.chapter.show','id':lesson.id}) : '' %} {% set priv = lesson.me.owned ? 'allow' : 'deny' %} - {% set over_flag = lesson.attrs.end_time < time() ? '已结束' : '' %} {{ lesson.title }} diff --git a/app/Repos/Consult.php b/app/Repos/Consult.php index a62a1a23..78f97eec 100644 --- a/app/Repos/Consult.php +++ b/app/Repos/Consult.php @@ -28,10 +28,18 @@ class Consult extends Repository $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['owner_id'])) { $builder->andWhere('owner_id = :owner_id:', ['owner_id' => $where['owner_id']]); } + if (!empty($where['replied'])) { + $builder->andWhere('reply_time > 0'); + } + if (isset($where['private'])) { $builder->andWhere('private = :private:', ['private' => $where['private']]); } diff --git a/app/Services/Logic/Chapter/BasicInfo.php b/app/Services/Logic/Chapter/BasicInfo.php index 50e7b66a..65e88b25 100644 --- a/app/Services/Logic/Chapter/BasicInfo.php +++ b/app/Services/Logic/Chapter/BasicInfo.php @@ -72,6 +72,7 @@ class BasicInfo extends Service 'model' => $chapter->model, 'play_urls' => $playUrls, 'resource_count' => $chapter->resource_count, + 'consult_count' => $chapter->consult_count, 'user_count' => $chapter->user_count, 'like_count' => $chapter->like_count, ]; @@ -99,6 +100,7 @@ class BasicInfo extends Service 'end_time' => $live->end_time, 'status' => $live->status, 'resource_count' => $chapter->resource_count, + 'consult_count' => $chapter->consult_count, 'user_count' => $chapter->user_count, 'like_count' => $chapter->like_count, ]; @@ -117,6 +119,7 @@ class BasicInfo extends Service 'model' => $chapter->model, 'content' => $read->content, 'resource_count' => $chapter->resource_count, + 'consult_count' => $chapter->consult_count, 'user_count' => $chapter->user_count, 'like_count' => $chapter->like_count, ]; diff --git a/app/Services/Logic/Chapter/ConsultList.php b/app/Services/Logic/Chapter/ConsultList.php new file mode 100644 index 00000000..d014298a --- /dev/null +++ b/app/Services/Logic/Chapter/ConsultList.php @@ -0,0 +1,36 @@ +checkChapter($id); + + $pagerQuery = new PagerQuery(); + + $sort = $pagerQuery->getSort(); + $page = $pagerQuery->getPage(); + $limit = $pagerQuery->getLimit(); + + $params = [ + 'chapter_id' => $chapter->id, + 'private' => 0, + 'published' => 1, + ]; + + $service = new ConsultListHandler(); + + return $service->paginate($params, $sort, $page, $limit); + } + +} diff --git a/app/Services/Logic/Consult/ConsultList.php b/app/Services/Logic/Consult/ConsultList.php new file mode 100644 index 00000000..44b52f9f --- /dev/null +++ b/app/Services/Logic/Consult/ConsultList.php @@ -0,0 +1,56 @@ +paginate($params, $sort, $page, $limit); + + return $this->handleConsults($pager); + } + + protected function handleConsults($pager) + { + if ($pager->total_items == 0) { + return $pager; + } + + $consults = $pager->items->toArray(); + + $builder = new ConsultListBuilder(); + + $users = $builder->getUsers($consults); + + $items = []; + + foreach ($consults as $consult) { + + $owner = $users[$consult['owner_id']] ?? new \stdClass(); + + $items[] = [ + 'id' => $consult['id'], + 'question' => $consult['question'], + 'answer' => $consult['answer'], + 'like_count' => $consult['like_count'], + 'reply_time' => $consult['reply_time'], + 'create_time' => $consult['create_time'], + 'update_time' => $consult['update_time'], + 'owner' => $owner, + ]; + } + + $pager->items = $items; + + return $pager; + } + +} diff --git a/app/Services/Logic/Search/Group.php b/app/Services/Logic/Search/Group.php index bf2d43c0..bd956015 100644 --- a/app/Services/Logic/Search/Group.php +++ b/app/Services/Logic/Search/Group.php @@ -67,6 +67,7 @@ class Group extends Handler 'avatar' => $item['avatar'], 'about' => $item['about'], 'user_count' => (int)$item['user_count'], + 'msg_count' => (int)$item['msg_count'], 'owner' => json_decode($item['owner'], true), ]; } diff --git a/app/Services/Logic/Teacher/TeacherList.php b/app/Services/Logic/Teacher/TeacherList.php index 4155b1d9..e20b4b48 100644 --- a/app/Services/Logic/Teacher/TeacherList.php +++ b/app/Services/Logic/Teacher/TeacherList.php @@ -3,7 +3,7 @@ namespace App\Services\Logic\Teacher; use App\Library\Paginator\Query as PagerQuery; -use App\Models\User; +use App\Models\User as UserModel; use App\Repos\User as UserRepo; use App\Services\Logic\Service; @@ -16,7 +16,7 @@ class TeacherList extends Service $params = $pagerQuery->getParams(); - $params['edu_role'] = User::EDU_ROLE_TEACHER; + $params['edu_role'] = UserModel::EDU_ROLE_TEACHER; $params['deleted'] = 0; $sort = $pagerQuery->getSort(); @@ -52,6 +52,8 @@ class TeacherList extends Service 'avatar' => $user['avatar'], 'title' => $user['title'], 'about' => $user['about'], + 'gender' => $user['gender'], + 'area' => $user['area'], ]; } diff --git a/config/xs.group.default.ini b/config/xs.group.default.ini index 97b2bf02..8f97485c 100644 --- a/config/xs.group.default.ini +++ b/config/xs.group.default.ini @@ -26,3 +26,6 @@ type = string [user_count] type = string + +[msg_count] +type = string \ No newline at end of file