diff --git a/app/Builders/FriendUserList.php b/app/Builders/ImFriendUserList.php similarity index 76% rename from app/Builders/FriendUserList.php rename to app/Builders/ImFriendUserList.php index 962e3291..3f44e4b1 100644 --- a/app/Builders/FriendUserList.php +++ b/app/Builders/ImFriendUserList.php @@ -4,7 +4,7 @@ namespace App\Builders; use App\Repos\User as UserRepo; -class FriendUserList extends Builder +class ImFriendUserList extends Builder { public function handleFriends(array $relations) @@ -24,7 +24,12 @@ class FriendUserList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar', 'about', 'vip']); + $columns = [ + 'id', 'name', 'avatar', 'gender', 'vip', + 'location', 'about', 'active_time', + ]; + + $users = $userRepo->findByIds($ids, $columns); $baseUrl = kg_ci_base_url(); diff --git a/app/Builders/ImGroupUserList.php b/app/Builders/ImGroupUserList.php new file mode 100644 index 00000000..e8f7a03d --- /dev/null +++ b/app/Builders/ImGroupUserList.php @@ -0,0 +1,43 @@ +getGroups($relations); + + foreach ($relations as $key => $value) { + $relations[$key]['group'] = $groups[$value['group_id']] ?? new \stdClass(); + } + + return $relations; + } + + public function getGroups(array $relations) + { + $ids = kg_array_column($relations, 'group_id'); + + $groupRepo = new ImGroupRepo(); + + $columns = ['id', 'type', 'name', 'avatar', 'about', 'user_count']; + + $groups = $groupRepo->findByIds($ids, $columns); + + $baseUrl = kg_ci_base_url(); + + $result = []; + + foreach ($groups->toArray() as $group) { + $group['group'] = $baseUrl . $group['avatar']; + $result[$group['id']] = $group; + } + + return $result; + } + +} diff --git a/app/Http/Admin/Services/Chapter.php b/app/Http/Admin/Services/Chapter.php index 30daec62..a4b1e4ab 100644 --- a/app/Http/Admin/Services/Chapter.php +++ b/app/Http/Admin/Services/Chapter.php @@ -5,6 +5,9 @@ namespace App\Http\Admin\Services; use App\Caches\Chapter as ChapterCache; use App\Caches\CourseChapterList as CourseChapterListCache; use App\Models\Chapter as ChapterModel; +use App\Models\ChapterLive as ChapterLiveModel; +use App\Models\ChapterRead as ChapterReadModel; +use App\Models\ChapterVod as ChapterVodModel; use App\Models\Course as CourseModel; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; @@ -47,6 +50,8 @@ class Chapter extends Service $chapterRepo = new ChapterRepo(); + $parentId = 0; + if (isset($post['parent_id'])) { $parent = $validator->checkParent($post['parent_id']); $data['parent_id'] = $parent->id; @@ -54,21 +59,72 @@ class Chapter extends Service $data['priority'] = $chapterRepo->maxLessonPriority($post['parent_id']); } else { $data['priority'] = $chapterRepo->maxChapterPriority($post['course_id']); + $data['parent_id'] = $parentId; } $data['priority'] += 1; - $chapter = new ChapterModel(); + try { - $chapter->create($data); + $this->db->begin(); - $this->updateChapterStats($chapter); + $chapter = new ChapterModel(); - $this->updateCourseStats($chapter); + if ($chapter->create($data) === false) { + throw new \RuntimeException('Create Chapter Failed'); + } - $this->rebuildChapterCache($chapter); + $data = [ + 'course_id' => $course->id, + 'chapter_id' => $chapter->id, + ]; - return $chapter; + if ($parentId > 0) { + + $attrs = false; + + switch ($course->model) { + case CourseMOdel::MODEL_VOD: + $chapterVod = new ChapterVodModel(); + $attrs = $chapterVod->create($data); + break; + case CourseModel::MODEL_LIVE: + $chapterLive = new ChapterLiveModel(); + $attrs = $chapterLive->create($data); + break; + case CourseModel::MODEL_READ: + $chapterRead = new ChapterReadModel(); + $attrs = $chapterRead->create($data); + break; + } + + if ($attrs === false) { + throw new \RuntimeException("Create Chapter {$course->model} Attrs Failed"); + } + } + + $this->db->commit(); + + $this->updateChapterStats($chapter); + + $this->updateCourseStats($chapter); + + return $chapter; + + } catch (\Exception $e) { + + $this->db->rollback(); + + $logger = $this->getLogger(); + + $logger->error('Create Chapter Error ' . kg_json_encode([ + 'line' => $e->getLine(), + 'code' => $e->getCode(), + 'message' => $e->getMessage(), + ])); + + throw new \RuntimeException('sys.trans_rollback'); + } } public function updateChapter($id) @@ -110,8 +166,6 @@ class Chapter extends Service $this->updateCourseStats($chapter); - $this->rebuildChapterCache($chapter); - return $chapter; } @@ -131,8 +185,6 @@ class Chapter extends Service $this->updateCourseStats($chapter); - $this->rebuildChapterCache($chapter); - return $chapter; } @@ -148,8 +200,6 @@ class Chapter extends Service $this->updateCourseStats($chapter); - $this->rebuildChapterCache($chapter); - return $chapter; } diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index b2a86046..672a393c 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -10,8 +10,10 @@ use App\Caches\CourseTeacherList as CourseTeacherListCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\Course as CourseModel; use App\Models\CourseCategory as CourseCategoryModel; +use App\Models\CourseRating as CourseRatingModel; use App\Models\CourseRelated as CourseRelatedModel; use App\Models\CourseUser as CourseUserModel; +use App\Models\ImGroup as ImGroupModel; use App\Repos\Category as CategoryRepo; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; @@ -65,20 +67,57 @@ class Course extends Service $validator = new CourseValidator(); - $data = []; + $model = $validator->checkModel($post['model']); + $title = $validator->checkTitle($post['title']); - $data['model'] = $validator->checkModel($post['model']); - $data['title'] = $validator->checkTitle($post['title']); + try { - $course = new CourseModel(); + $this->db->begin(); - $course->create($data); + $course = new CourseModel(); - $this->rebuildCourseCache($course); + $course->model = $model; + $course->title = $title; - $this->rebuildCourseIndex($course); + if ($course->create() === false) { + throw new \RuntimeException('Create Course Failed'); + } - return $course; + $courseRating = new CourseRatingModel(); + + $courseRating->course_id = $course->id; + + if ($courseRating->create() === false) { + throw new \RuntimeException('Create CourseRating Failed'); + } + + $imGroup = new ImGroupModel(); + + $imGroup->course_id = $course->id; + $imGroup->name = $course->title; + $imGroup->about = $course->summary; + + if ($imGroup->create() === false) { + throw new \RuntimeException('Create ImGroup Failed'); + } + + $this->db->commit(); + + return $course; + + } catch (\Exception $e) { + + $this->db->rollback(); + + $logger = $this->getLogger(); + + $logger->error('Create Course Error ' . kg_json_encode([ + 'code' => $e->getCode(), + 'message' => $e->getMessage(), + ])); + + throw new \RuntimeException('sys.trans_rollback'); + } } public function updateCourse($id) @@ -149,8 +188,6 @@ class Course extends Service $course->update($data); - $this->rebuildCourseCache($course); - $this->rebuildCourseIndex($course); return $course; @@ -164,8 +201,6 @@ class Course extends Service $course->update(); - $this->rebuildCourseCache($course); - $this->rebuildCourseIndex($course); return $course; @@ -179,8 +214,6 @@ class Course extends Service $course->update(); - $this->rebuildCourseCache($course); - $this->rebuildCourseIndex($course); return $course; diff --git a/app/Http/Web/Controllers/AccountController.php b/app/Http/Web/Controllers/AccountController.php index 59316fb1..a5d850f4 100644 --- a/app/Http/Web/Controllers/AccountController.php +++ b/app/Http/Web/Controllers/AccountController.php @@ -7,6 +7,7 @@ use App\Services\Frontend\Account\EmailUpdate as EmailUpdateService; use App\Services\Frontend\Account\PasswordReset as PasswordResetService; use App\Services\Frontend\Account\PasswordUpdate as PasswordUpdateService; use App\Services\Frontend\Account\PhoneUpdate as PhoneUpdateService; +use Phalcon\Mvc\View; /** * @RoutePrefix("/account") @@ -149,6 +150,7 @@ class AccountController extends Controller $captcha = $service->getSectionSettings('captcha'); + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->pick('account/edit_password'); $this->view->setVar('captcha', $captcha); } @@ -166,6 +168,7 @@ class AccountController extends Controller $captcha = $service->getSectionSettings('captcha'); + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->pick('account/edit_phone'); $this->view->setVar('captcha', $captcha); } @@ -183,6 +186,7 @@ class AccountController extends Controller $captcha = $service->getSectionSettings('captcha'); + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->pick('account/edit_email'); $this->view->setVar('captcha', $captcha); } @@ -215,10 +219,7 @@ class AccountController extends Controller $service->handle(); - $content = [ - 'location' => $this->url->get(['for' => 'web.my.account']), - 'msg' => '更新手机成功', - ]; + $content = ['msg' => '更新手机成功']; return $this->jsonSuccess($content); } @@ -232,10 +233,7 @@ class AccountController extends Controller $service->handle(); - $content = [ - 'location' => $this->url->get(['for' => 'web.my.account']), - 'msg' => '更新邮箱成功', - ]; + $content = ['msg' => '更新邮箱成功']; return $this->jsonSuccess($content); } @@ -249,10 +247,7 @@ class AccountController extends Controller $service->handle(); - $content = [ - 'location' => $this->url->get(['for' => 'web.my.account']), - 'msg' => '更新密码成功', - ]; + $content = ['msg' => '更新密码成功']; return $this->jsonSuccess($content); } diff --git a/app/Http/Web/Controllers/MyController.php b/app/Http/Web/Controllers/MyController.php index c80104cd..69d7a423 100644 --- a/app/Http/Web/Controllers/MyController.php +++ b/app/Http/Web/Controllers/MyController.php @@ -9,6 +9,8 @@ use App\Services\Frontend\My\RefundList as MyRefundListService; use App\Services\Frontend\My\ReviewList as MyReviewListService; use App\Services\Frontend\My\UserInfo as UserInfoService; use App\Services\Frontend\My\UserUpdate as UserUpdateService; +use App\Services\Frontend\User\FriendList as UserFriendListService; +use App\Services\Frontend\User\GroupList as UserGroupListService; /** * @RoutePrefix("/my") @@ -16,6 +18,15 @@ use App\Services\Frontend\My\UserUpdate as UserUpdateService; class MyController extends Controller { + public function initialize() + { + parent::initialize(); + + if ($this->authUser->id == 0) { + $this->response->redirect(['for' => 'web.account.login']); + } + } + /** * @Get("/home", name="web.my.home") */ @@ -127,6 +138,34 @@ class MyController extends Controller $this->view->setVar('pager', $pager); } + /** + * @Get("/friends", name="web.my.friends") + */ + public function friendsAction() + { + $service = new UserFriendListService(); + + $pager = $service->handle($this->authUser->id); + + $pager->items = kg_array_object($pager->items); + + $this->view->setVar('pager', $pager); + } + + /** + * @Get("/groups", name="web.my.groups") + */ + public function groupsAction() + { + $service = new UserGroupListService(); + + $pager = $service->handle($this->authUser->id); + + $pager->items = kg_array_object($pager->items); + + $this->view->setVar('pager', $pager); + } + /** * @Post("/profile/update", name="web.my.update_profile") */ @@ -141,4 +180,20 @@ class MyController extends Controller return $this->jsonSuccess($content); } + /** + * @Post("/friend/delete", name="web.my.delete_friend") + */ + public function deleteFriendAction() + { + + } + + /** + * @Post("/group/delete", name="web.my.delete_group") + */ + public function deleteGroupAction() + { + + } + } diff --git a/app/Http/Web/Controllers/UserController.php b/app/Http/Web/Controllers/UserController.php index 479030c2..ff83d8d7 100644 --- a/app/Http/Web/Controllers/UserController.php +++ b/app/Http/Web/Controllers/UserController.php @@ -5,6 +5,7 @@ namespace App\Http\Web\Controllers; use App\Services\Frontend\User\CourseList as UserCourseListService; use App\Services\Frontend\User\FavoriteList as UserFavoriteListService; use App\Services\Frontend\User\FriendList as UserFriendListService; +use App\Services\Frontend\User\GroupList as UserGroupListService; use App\Services\Frontend\User\UserInfo as UserInfoService; use Phalcon\Mvc\View; @@ -74,4 +75,20 @@ class UserController extends Controller $this->view->setVar('pager', $pager); } + /** + * @Get("/{id:[0-9]+}/groups", name="web.user.groups") + */ + public function groupsAction($id) + { + $service = new UserGroupListService(); + + $pager = $service->handle($id); + $pager->items = kg_array_object($pager->items); + $pager->target = 'tab-groups'; + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('user/groups'); + $this->view->setVar('pager', $pager); + } + } diff --git a/app/Http/Web/Views/account/edit_email.volt b/app/Http/Web/Views/account/edit_email.volt index e2ef15a3..b624bdd3 100644 --- a/app/Http/Web/Views/account/edit_email.volt +++ b/app/Http/Web/Views/account/edit_email.volt @@ -1,43 +1,36 @@ -{% extends 'templates/full.volt' %} +{% extends 'templates/layer.volt' %} {% block content %} - - -
-
-
-
- -
+ +

+
+
+
-
-
- -
+
+
+
+
-
-
- -
-
- -
+
+
+
+
-
-
- - - - -
+
+
- -
+
+
+
+ + + + +
+
+ {% endblock %} diff --git a/app/Http/Web/Views/account/edit_password.volt b/app/Http/Web/Views/account/edit_password.volt index 2b09754c..ce8804e4 100644 --- a/app/Http/Web/Views/account/edit_password.volt +++ b/app/Http/Web/Views/account/edit_password.volt @@ -1,36 +1,29 @@ -{% extends 'templates/full.volt' %} +{% extends 'templates/layer.volt' %} {% block content %} - - -