diff --git a/app/Http/Web/Controllers/IndexController.php b/app/Http/Web/Controllers/IndexController.php index e3ebb7b3..ab02d7cd 100644 --- a/app/Http/Web/Controllers/IndexController.php +++ b/app/Http/Web/Controllers/IndexController.php @@ -24,4 +24,12 @@ class IndexController extends Controller $this->view->setVar('vip_courses', $indexService->getVipCourses()); } + /** + * @Get("/im", name="web.im") + */ + public function imAction() + { + + } + } diff --git a/app/Http/Web/Controllers/LiveController.php b/app/Http/Web/Controllers/LiveController.php index 18a7fd7a..2c3b8816 100644 --- a/app/Http/Web/Controllers/LiveController.php +++ b/app/Http/Web/Controllers/LiveController.php @@ -2,47 +2,81 @@ namespace App\Http\Web\Controllers; -class LiveController extends Controller +use App\Http\Web\Services\Live as LiveService; +use App\Traits\Response as ResponseTrait; + +/** + * @RoutePrefix("/live") + */ +class LiveController extends \Phalcon\Mvc\Controller { + use ResponseTrait; + /** - * @Get("/stats", name="web.live.stats") + * @Get("/{id:[0-9]+}/members", name="web.live.members") */ - public function statsAction() + public function membersAction($id) + { + $list = [ + [ + 'username' => '直飞机', + 'avatar' => 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1', + 'status' => 'online', + 'sign' => '高舍炮打的准', + 'id' => 1, + ], + [ + 'username' => '直飞机2', + 'avatar' => 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1', + 'status' => 'online', + 'sign' => '高舍炮打的准', + 'id' => 2, + ], + [ + 'username' => '直飞机3', + 'avatar' => 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1', + 'status' => 'online', + 'sign' => '高舍炮打的准', + 'id' => 3, + ], + ]; + + $content = ['data' => ['list' => $list]]; + + return $this->jsonSuccess($content); + } + + /** + * @Post("/{id:[0-9]+}/bind", name="web.live.bind") + */ + public function bindAction($id) + { + $service = new LiveService(); + + $service->bindUser($id); + + return $this->jsonSuccess(); + } + + /** + * @Post("/{id:[0-9]+}/unbind", name="web.live.unbind") + */ + public function unbindAction($id) { } /** - * @Get("/users", name="web.live.users") + * @Post("/{id:[0-9]+}/message", name="web.live.message") */ - public function usersAction() + public function messageAction($id) { + $service = new LiveService(); - } - - /** - * @Post("/login", name="web.live.login") - */ - public function loginAction() - { - - } - - /** - * @Post("/logout", name="web.live.logout") - */ - public function logoutAction() - { - - } - - /** - * @Post("/message", name="web.live.message") - */ - public function messageAction() - { + $service->sendMessage($id); + return $this->jsonSuccess(); } } diff --git a/app/Http/Web/Controllers/MessengerController.php b/app/Http/Web/Controllers/MessengerController.php new file mode 100644 index 00000000..940df23a --- /dev/null +++ b/app/Http/Web/Controllers/MessengerController.php @@ -0,0 +1,27 @@ +siteSeo->setKeywords($this->siteSettings['keywords']); + $this->siteSeo->setDescription($this->siteSettings['description']); + + $indexService = new IndexService(); + + $this->view->setVar('slides', $indexService->getSlides()); + $this->view->setVar('lives', $indexService->getLives()); + $this->view->setVar('new_courses', $indexService->getNewCourses()); + $this->view->setVar('free_courses', $indexService->getFreeCourses()); + $this->view->setVar('vip_courses', $indexService->getVipCourses()); + } + +} diff --git a/app/Http/Web/Controllers/PublicController.php b/app/Http/Web/Controllers/PublicController.php index b02b14f6..435d120d 100644 --- a/app/Http/Web/Controllers/PublicController.php +++ b/app/Http/Web/Controllers/PublicController.php @@ -53,13 +53,13 @@ class PublicController extends \Phalcon\Mvc\Controller } /** - * @Post("/learning", name="web.learning") + * @Post("/{id:[0-9]+}/learning", name="web.learning") */ - public function learningAction() + public function learningAction($id) { $service = new LearningService(); - $service->handle(); + $service->handle($id); return $this->jsonSuccess(); } diff --git a/app/Http/Web/Services/Live.php b/app/Http/Web/Services/Live.php new file mode 100644 index 00000000..a3373c34 --- /dev/null +++ b/app/Http/Web/Services/Live.php @@ -0,0 +1,67 @@ +checkChapterCache($id); + + $user = $this->getCurrentUser(); + + $userId = $user->id > 0 ?: $this->session->getId(); + + $clientId = $this->request->getPost('client_id'); + + $groupName = $this->getGroupName($chapter->id); + + Gateway::$registerAddress = '127.0.0.1:1238'; + + Gateway::bindUid($clientId, $userId); + + Gateway::joinGroup($clientId, $groupName); + } + + public function sendMessage($id) + { + $chapter = $this->checkChapterCache($id); + + $from = $this->request->getPost('from'); + $to = $this->request->getPost('to'); + + $content = [ + 'username' => $from['username'], + 'avatar' => $from['avatar'], + 'content' => $from['content'], + 'fromid' => $from['id'], + 'id' => $to['id'], + 'type' => $to['type'], + 'timestamp' => 1000 * time(), + 'mine' => false, + ]; + + $message = json_encode([ + 'type' => 'show_message', + 'content' => $content, + ]); + + $groupName = $this->getGroupName($chapter->id); + + Gateway::$registerAddress = '127.0.0.1:1238'; + + Gateway::sendToGroup($groupName, $message); + } + + protected function getGroupName($groupId) + { + return "chapter_{$groupId}"; + } + +} diff --git a/app/Http/Web/Views/chapter/show_live.volt b/app/Http/Web/Views/chapter/show_live.volt index 06fea4d5..575f2150 100644 --- a/app/Http/Web/Views/chapter/show_live.volt +++ b/app/Http/Web/Views/chapter/show_live.volt @@ -2,32 +2,28 @@ {% block content %} - {% set course_url = url({'for':'web.course.show','id':chapter.course.id}) %} - -