From 199845cfd0d655917ecf83249e20235f9772f85e Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 23 Jul 2020 20:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E6=88=B7=EF=BC=8C=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E7=AB=A0=E8=8A=82=E5=85=B3=E8=81=94=E8=A1=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=81=9A=E6=88=90=E4=BA=8B=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...riendUserList.php => ImFriendUserList.php} | 9 +- app/Builders/ImGroupUserList.php | 43 + app/Http/Admin/Services/Chapter.php | 74 +- app/Http/Admin/Services/Course.php | 61 +- .../Web/Controllers/AccountController.php | 19 +- app/Http/Web/Controllers/MyController.php | 55 + app/Http/Web/Controllers/UserController.php | 17 + app/Http/Web/Views/account/edit_email.volt | 59 +- app/Http/Web/Views/account/edit_password.volt | 47 +- app/Http/Web/Views/account/edit_phone.volt | 59 +- app/Http/Web/Views/my/account.volt | 26 +- app/Http/Web/Views/my/friends.volt | 64 + app/Http/Web/Views/my/groups.volt | 55 + app/Http/Web/Views/my/menu.volt | 4 +- app/Http/Web/Views/my/profile.volt | 24 + app/Library/Helper.php | 6 +- app/Listeners/Pay.php | 9 +- app/Models/Account.php | 13 - app/Models/Chapter.php | 25 - app/Models/Course.php | 4 - app/Models/ImFriendGroup.php | 12 +- app/Models/ImFriendMessage.php | 14 +- app/Models/ImFriendUser.php | 16 +- app/Models/ImGroup.php | 29 +- app/Models/ImGroupMessage.php | 12 +- app/Models/ImGroupUser.php | 14 +- app/Models/ImSystemMessage.php | 16 +- app/Repos/ImGroupUser.php | 41 + app/Services/Frontend/Account/Register.php | 46 +- app/Services/Frontend/My/UserInfo.php | 16 +- app/Services/Frontend/My/UserUpdate.php | 4 + app/Services/Frontend/User/FavoriteList.php | 2 +- app/Services/Frontend/User/FriendList.php | 6 +- app/Services/Frontend/User/GroupList.php | 61 + app/Validators/User.php | 9 + config/errors.php | 2 + public/static/lib/layui/extends/layarea.js | 4041 +++++++++++++++++ public/static/web/js/my.account.js | 45 + public/static/web/js/my.im.js | 36 + public/static/web/js/my.js | 1 + public/static/web/js/my.profile.js | 12 + 41 files changed, 4859 insertions(+), 249 deletions(-) rename app/Builders/{FriendUserList.php => ImFriendUserList.php} (76%) create mode 100644 app/Builders/ImGroupUserList.php create mode 100644 app/Http/Web/Views/my/friends.volt create mode 100644 app/Http/Web/Views/my/groups.volt create mode 100644 app/Services/Frontend/User/GroupList.php create mode 100644 public/static/lib/layui/extends/layarea.js create mode 100644 public/static/web/js/my.account.js create mode 100644 public/static/web/js/my.im.js create mode 100644 public/static/web/js/my.profile.js 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 %} - - -
-