From 525ac5d67ab328359f3b1bd21e611213a2184cda Mon Sep 17 00:00:00 2001 From: koogua Date: Fri, 8 Oct 2021 17:31:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E6=B6=88=E6=81=AFid=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Logic/Live/LiveChapter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Services/Logic/Live/LiveChapter.php b/app/Services/Logic/Live/LiveChapter.php index a66cb377..8efa260d 100644 --- a/app/Services/Logic/Live/LiveChapter.php +++ b/app/Services/Logic/Live/LiveChapter.php @@ -83,6 +83,7 @@ class LiveChapter extends LogicService Gateway::bindUid($clientId, $user->id); $message = kg_json_encode([ + 'id' => kg_uniqid(), 'type' => 'new_user', 'user' => [ 'id' => $user->id, From 57c7d875adbdcb439ce0a6644640f31ad7428269 Mon Sep 17 00:00:00 2001 From: koogua Date: Sat, 9 Oct 2021 09:47:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=EF=BC=91=EF=BC=8E=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E8=8E=B7=E5=8F=96answer=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=EF=BC=92=EF=BC=8Eorder=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=BC=BA=E5=A4=B1=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Api/Controllers/AnswerController.php | 2 +- app/Http/Api/Controllers/OrderController.php | 4 ++++ app/Http/Home/Controllers/AnswerController.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Api/Controllers/AnswerController.php b/app/Http/Api/Controllers/AnswerController.php index d49ed3ae..2a52ac9c 100644 --- a/app/Http/Api/Controllers/AnswerController.php +++ b/app/Http/Api/Controllers/AnswerController.php @@ -35,7 +35,7 @@ class AnswerController extends Controller $this->notFound(); } - $approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED; + $approved = $answer['published'] == AnswerModel::PUBLISH_APPROVED; $owned = $answer['me']['owned'] == 1; if (!$approved && !$owned) { diff --git a/app/Http/Api/Controllers/OrderController.php b/app/Http/Api/Controllers/OrderController.php index cd5fb1f3..866dff0f 100644 --- a/app/Http/Api/Controllers/OrderController.php +++ b/app/Http/Api/Controllers/OrderController.php @@ -33,6 +33,10 @@ class OrderController extends Controller $this->notFound(); } + if ($order['me']['owned'] == 0) { + $this->forbidden(); + } + return $this->jsonSuccess(['order' => $order]); } diff --git a/app/Http/Home/Controllers/AnswerController.php b/app/Http/Home/Controllers/AnswerController.php index a833382b..663ff936 100644 --- a/app/Http/Home/Controllers/AnswerController.php +++ b/app/Http/Home/Controllers/AnswerController.php @@ -61,7 +61,7 @@ class AnswerController extends Controller $this->notFound(); } - $approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED; + $approved = $answer['published'] == AnswerModel::PUBLISH_APPROVED; $owned = $answer['me']['owned'] == 1; if (!$approved && !$owned) { From dfe92dfb1b013a45d90323f881110768356d50b9 Mon Sep 17 00:00:00 2001 From: koogua Date: Sat, 16 Oct 2021 16:16:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96PC=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=B0=E6=89=8B=E6=9C=BA=E7=9A=84=E8=87=AA=E5=8A=A8=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=AE=A1=E7=90=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E8=8B=A5=E5=B9=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 13 ++ README.md | 10 +- app/Caches/CourseTopicList.php | 1 + app/Caches/IndexArticleList.php | 1 + .../Admin/Controllers/ArticleController.php | 2 +- app/Http/Admin/Controllers/Controller.php | 29 +++- .../Admin/Controllers/CourseController.php | 2 +- app/Http/Admin/Controllers/HelpController.php | 2 +- .../Admin/Controllers/PublicController.php | 2 +- .../Admin/Controllers/QuestionController.php | 2 +- .../Admin/Controllers/SessionController.php | 4 +- app/Http/Admin/Controllers/UserController.php | 6 +- app/Http/Admin/Services/PointGift.php | 18 ++- app/Http/Admin/Services/Session.php | 20 +-- app/Http/Admin/Services/User.php | 17 ++ .../Admin/Views/chapter/lessons_offline.volt | 1 - app/Http/Admin/Views/chapter/lessons_vod.volt | 1 - app/Http/Admin/Views/index/index.volt | 5 +- app/Http/Admin/Views/point/gift/add.volt | 2 +- app/Http/Admin/Views/point/gift/edit.volt | 12 +- .../Admin/Views/point/gift/edit_course.volt | 9 +- .../Admin/Views/point/gift/edit_goods.volt | 7 + app/Http/Admin/Views/user/add.volt | 14 +- app/Http/Admin/Views/user/edit.volt | 4 +- app/Http/Api/Services/Account.php | 4 + .../Home/Controllers/AccountController.php | 30 +++- .../Home/Controllers/AnswerController.php | 10 +- .../Home/Controllers/ArticleController.php | 15 ++ .../Home/Controllers/ChapterController.php | 8 + .../Home/Controllers/CourseController.php | 15 ++ app/Http/Home/Controllers/HelpController.php | 15 ++ app/Http/Home/Controllers/ImController.php | 2 +- .../Home/Controllers/ImGroupController.php | 15 ++ app/Http/Home/Controllers/IndexController.php | 31 +--- app/Http/Home/Controllers/OrderController.php | 2 +- app/Http/Home/Controllers/PageController.php | 8 + .../Home/Controllers/PublicController.php | 2 +- .../Home/Controllers/QuestionController.php | 15 ++ .../Home/Controllers/SearchController.php | 2 +- .../Home/Controllers/TeacherController.php | 15 ++ app/Http/Home/Controllers/UserController.php | 8 + app/Http/Home/Controllers/VipController.php | 8 + app/Http/Home/Services/Account.php | 4 + app/Http/Home/Services/FullH5Url.php | 149 ++++++++++++++++++ app/Http/Home/Services/FullWebUrl.php | 86 ++++++++++ app/Http/Home/Services/ShareUrl.php | 121 +++++--------- app/Library/AppInfo.php | 2 +- app/Repos/PointGift.php | 26 +++ app/Services/Auth/Api.php | 71 ++++++--- app/Services/Auth/Home.php | 30 ++-- app/Services/Logic/Course/ChapterList.php | 63 ++++---- app/Services/Logic/Point/GiftInfo.php | 5 + .../Logic/Teacher/Console/CourseList.php | 43 +---- app/Traits/Client.php | 7 + app/Validators/Account.php | 11 ++ app/Validators/User.php | 15 -- config/errors.php | 2 +- 57 files changed, 740 insertions(+), 284 deletions(-) create mode 100644 app/Http/Home/Services/FullH5Url.php create mode 100644 app/Http/Home/Services/FullWebUrl.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 903b5edc..283b4ca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +### [v1.4.6](https://gitee.com/koogua/course-tencent-cloud/releases/v1.4.6)(2021-10-09) + +- 完善首页文章缓存的获取条件 +- 完善热门专题的获取条件 +- 优化课程章节列表逻辑 +- 更新教学中心我的课程获取逻辑 +- 修正后台点播和面授类型课时列表宽度未100%铺满问题 +- 完善添加积分礼品的逻辑 +- 修正编辑课程类型礼品时编辑器初始化js报错 +- 修正非root用户后台添加用户时报错 +- 手机端访问web端地址自动跳转到手机端 +- 增加锁定用户逻辑(会自动登出锁定用户) + ### [v1.4.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.4.5)(2021-09-27) - 修正点击内容分享到微信会额外出现公众号二维码的问题 diff --git a/README.md b/README.md index 377dd248..16c93aba 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,15 @@ 演示账号:100015@163.com / 123456 (前后台通用) -移动端演示: +H5手机端演示: -![移动端二维码](https://images.gitee.com/uploads/images/2020/1127/093203_265221a2_23592.png) +![H5二维码](https://images.gitee.com/uploads/images/2021/1011/091358_05e79898_23592.png) + +演示账号:13507083515 / 123456 + +微信公众号演示: + +![公众号二维码](https://images.gitee.com/uploads/images/2021/1011/090813_3b88ecc3_23592.jpeg) 演示账号:13507083515 / 123456 diff --git a/app/Caches/CourseTopicList.php b/app/Caches/CourseTopicList.php index 33d612bb..0d9e95aa 100644 --- a/app/Caches/CourseTopicList.php +++ b/app/Caches/CourseTopicList.php @@ -64,6 +64,7 @@ class CourseTopicList extends Cache { return TopicModel::query() ->where('published = 1') + ->andWhere('deleted = 0') ->orderBy('RAND()') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexArticleList.php b/app/Caches/IndexArticleList.php index 6b6f20cc..c892923f 100644 --- a/app/Caches/IndexArticleList.php +++ b/app/Caches/IndexArticleList.php @@ -32,6 +32,7 @@ class IndexArticleList extends Cache $where = [ 'published' => ArticleModel::PUBLISH_APPROVED, + 'private' => 0, 'deleted' => 0, ]; diff --git a/app/Http/Admin/Controllers/ArticleController.php b/app/Http/Admin/Controllers/ArticleController.php index cc832423..d6d8a7b9 100644 --- a/app/Http/Admin/Controllers/ArticleController.php +++ b/app/Http/Admin/Controllers/ArticleController.php @@ -26,7 +26,7 @@ class ArticleController extends Controller ['type' => CategoryModel::TYPE_ARTICLE] ); - $this->response->redirect($location); + return $this->response->redirect($location); } /** diff --git a/app/Http/Admin/Controllers/Controller.php b/app/Http/Admin/Controllers/Controller.php index 451e245a..dc93c72c 100644 --- a/app/Http/Admin/Controllers/Controller.php +++ b/app/Http/Admin/Controllers/Controller.php @@ -8,6 +8,8 @@ namespace App\Http\Admin\Controllers; use App\Models\Audit as AuditModel; +use App\Models\Role as RoleModel; +use App\Models\User as UserModel; use App\Services\Auth\Admin as AdminAuth; use App\Traits\Response as ResponseTrait; use App\Traits\Security as SecurityTrait; @@ -21,6 +23,11 @@ class Controller extends \Phalcon\Mvc\Controller */ protected $authInfo; + /** + * @var UserModel + */ + protected $authUser; + use ResponseTrait; use SecurityTrait; @@ -41,10 +48,12 @@ class Controller extends \Phalcon\Mvc\Controller return false; } + $this->authUser = $this->getAuthUser(); + /** - * 管理员忽略权限检查 + * root用户忽略权限检查 */ - if ($this->authInfo['root'] == 1) { + if ($this->authUser->admin_role == RoleModel::ROLE_ROOT) { return true; } @@ -90,7 +99,7 @@ class Controller extends \Phalcon\Mvc\Controller public function initialize() { - $this->view->setVar('auth_info', $this->authInfo); + $this->view->setVar('auth_user', $this->authUser); } public function afterExecuteRoute(Dispatcher $dispatcher) @@ -99,8 +108,8 @@ class Controller extends \Phalcon\Mvc\Controller $audit = new AuditModel(); - $audit->user_id = $this->authInfo['id']; - $audit->user_name = $this->authInfo['name']; + $audit->user_id = $this->authUser->id; + $audit->user_name = $this->authUser->name; $audit->user_ip = $this->request->getClientAddress(); $audit->req_route = $this->router->getMatchedRoute()->getName(); $audit->req_path = $this->request->getServer('REQUEST_URI'); @@ -120,4 +129,14 @@ class Controller extends \Phalcon\Mvc\Controller return $auth->getAuthInfo(); } + protected function getAuthUser() + { + /** + * @var AdminAuth $auth + */ + $auth = $this->getDI()->get('auth'); + + return $auth->getCurrentUser(); + } + } diff --git a/app/Http/Admin/Controllers/CourseController.php b/app/Http/Admin/Controllers/CourseController.php index 9030307c..aab1a83f 100644 --- a/app/Http/Admin/Controllers/CourseController.php +++ b/app/Http/Admin/Controllers/CourseController.php @@ -26,7 +26,7 @@ class CourseController extends Controller ['type' => CategoryModel::TYPE_COURSE] ); - $this->response->redirect($location); + return $this->response->redirect($location); } /** diff --git a/app/Http/Admin/Controllers/HelpController.php b/app/Http/Admin/Controllers/HelpController.php index 147b7108..d81cb9e3 100644 --- a/app/Http/Admin/Controllers/HelpController.php +++ b/app/Http/Admin/Controllers/HelpController.php @@ -26,7 +26,7 @@ class HelpController extends Controller ['type' => CategoryModel::TYPE_HELP] ); - $this->response->redirect($location); + return $this->response->redirect($location); } /** diff --git a/app/Http/Admin/Controllers/PublicController.php b/app/Http/Admin/Controllers/PublicController.php index 1e7db339..7030f285 100644 --- a/app/Http/Admin/Controllers/PublicController.php +++ b/app/Http/Admin/Controllers/PublicController.php @@ -28,7 +28,7 @@ class PublicController extends \Phalcon\Mvc\Controller return $this->jsonError(['msg' => '会话已过期,请重新登录']); } - $this->response->redirect(['for' => 'admin.login']); + return $this->response->redirect(['for' => 'admin.login']); } /** diff --git a/app/Http/Admin/Controllers/QuestionController.php b/app/Http/Admin/Controllers/QuestionController.php index 4f28ed16..0bc2aebf 100644 --- a/app/Http/Admin/Controllers/QuestionController.php +++ b/app/Http/Admin/Controllers/QuestionController.php @@ -26,7 +26,7 @@ class QuestionController extends Controller ['type' => CategoryModel::TYPE_ARTICLE] ); - $this->response->redirect($location); + return $this->response->redirect($location); } /** diff --git a/app/Http/Admin/Controllers/SessionController.php b/app/Http/Admin/Controllers/SessionController.php index aa6b44ae..e554bf05 100644 --- a/app/Http/Admin/Controllers/SessionController.php +++ b/app/Http/Admin/Controllers/SessionController.php @@ -31,7 +31,7 @@ class SessionController extends \Phalcon\Mvc\Controller $user = $this->getCurrentUser(); if ($user->id > 0) { - $this->response->redirect(['for' => 'admin.index']); + return $this->response->redirect(['for' => 'admin.index']); } $sessionService = new SessionService(); @@ -66,7 +66,7 @@ class SessionController extends \Phalcon\Mvc\Controller $sessionService->logout(); - $this->response->redirect(['for' => 'admin.login']); + return $this->response->redirect(['for' => 'admin.login']); } } diff --git a/app/Http/Admin/Controllers/UserController.php b/app/Http/Admin/Controllers/UserController.php index 25dfb78f..7877b6bf 100644 --- a/app/Http/Admin/Controllers/UserController.php +++ b/app/Http/Admin/Controllers/UserController.php @@ -62,7 +62,7 @@ class UserController extends Controller $adminRole = $this->request->getPost('admin_role', 'int', 0); if ($adminRole == RoleModel::ROLE_ROOT) { - $this->response->redirect(['action' => 'list']); + return $this->response->redirect(['action' => 'list']); } $userService = new UserService(); @@ -91,7 +91,7 @@ class UserController extends Controller $adminRoles = $userService->getAdminRoles(); if ($user->admin_role == RoleModel::ROLE_ROOT) { - $this->response->redirect(['for' => 'admin.user.list']); + return $this->response->redirect(['for' => 'admin.user.list']); } $this->view->setVar('user', $user); @@ -119,7 +119,7 @@ class UserController extends Controller $adminRole = $this->request->getPost('admin_role', 'int', 0); if ($adminRole == RoleModel::ROLE_ROOT) { - $this->response->redirect(['action' => 'list']); + return $this->response->redirect(['action' => 'list']); } $type = $this->request->getPost('type', 'string', 'user'); diff --git a/app/Http/Admin/Services/PointGift.php b/app/Http/Admin/Services/PointGift.php index 23932e3f..4ce0d39e 100644 --- a/app/Http/Admin/Services/PointGift.php +++ b/app/Http/Admin/Services/PointGift.php @@ -25,7 +25,11 @@ class PointGift extends Service { $courseRepo = new CourseRepo(); - $where = ['free' => 0, 'published' => 1]; + $where = [ + 'free' => 0, + 'published' => 1, + 'deleted' => 0, + ]; $pager = $courseRepo->paginate($where, $sort = 'latest', 1, 10000); @@ -162,10 +166,22 @@ class PointGift extends Service $course = $validator->checkCourse($post['xm_course_id']); + $giftRepo = new PointGiftRepo(); + + $gift = $giftRepo->findByCourseId($course->id); + + if ($gift) return $gift; + $gift = new PointGiftModel(); $gift->type = PointGiftModel::TYPE_COURSE; $gift->name = $course->title; + $gift->cover = $course->cover; + $gift->attrs = [ + 'id' => $course->id, + 'title' => $course->title, + 'price' => $course->market_price, + ]; $gift->create(); diff --git a/app/Http/Admin/Services/Session.php b/app/Http/Admin/Services/Session.php index ff7bccab..cdffacd7 100644 --- a/app/Http/Admin/Services/Session.php +++ b/app/Http/Admin/Services/Session.php @@ -26,28 +26,30 @@ class Session extends Service public function login() { - $currentUser = $this->getCurrentUser(); + $user = $this->getCurrentUser(); - if ($currentUser->id > 0) { - $this->response->redirect(['for' => 'home.index']); + if ($user->id > 0) { + return $this->response->redirect(['for' => 'home.index']); } $post = $this->request->getPost(); - $accountValidator = new AccountValidator(); + $validator = new AccountValidator(); - $user = $accountValidator->checkAdminLogin($post['account'], $post['password']); + $user = $validator->checkAdminLogin($post['account'], $post['password']); - $captchaSettings = $this->getSettings('captcha'); + $validator->checkIfAllowLogin($user); + + $captcha = $this->getSettings('captcha'); /** * 验证码是一次性的,放到最后检查,减少第三方调用 */ - if ($captchaSettings['enabled'] == 1) { + if ($captcha['enabled'] == 1) { - $captchaValidator = new CaptchaValidator(); + $validator = new CaptchaValidator(); - $captchaValidator->checkCode($post['ticket'], $post['rand']); + $validator->checkCode($post['ticket'], $post['rand']); } $this->auth->saveAuthInfo($user); diff --git a/app/Http/Admin/Services/User.php b/app/Http/Admin/Services/User.php index 78b3c10b..97d7f694 100644 --- a/app/Http/Admin/Services/User.php +++ b/app/Http/Admin/Services/User.php @@ -18,6 +18,8 @@ use App\Repos\Account as AccountRepo; use App\Repos\Online as OnlineRepo; use App\Repos\Role as RoleRepo; use App\Repos\User as UserRepo; +use App\Services\Auth\Api as ApiAuth; +use App\Services\Auth\Home as HomeAuth; use App\Validators\Account as AccountValidator; use App\Validators\User as UserValidator; @@ -209,6 +211,10 @@ class User extends Service $user->update($data); + if ($user->locked == 1) { + $this->destroyUserLogin($user); + } + if ($oldAdminRole > 0) { $this->updateAdminUserCount($oldAdminRole); } @@ -271,6 +277,17 @@ class User extends Service $cache->rebuild($user->id); } + protected function destroyUserLogin(UserModel $user) + { + $homeAuth = new HomeAuth(); + + $homeAuth->logoutClients($user->id); + + $apiAuth = new ApiAuth(); + + $apiAuth->logoutClients($user->id); + } + protected function updateAdminUserCount($roleId) { $roleRepo = new RoleRepo(); diff --git a/app/Http/Admin/Views/chapter/lessons_offline.volt b/app/Http/Admin/Views/chapter/lessons_offline.volt index 6032519c..91b9fa67 100644 --- a/app/Http/Admin/Views/chapter/lessons_offline.volt +++ b/app/Http/Admin/Views/chapter/lessons_offline.volt @@ -15,7 +15,6 @@ - diff --git a/app/Http/Admin/Views/chapter/lessons_vod.volt b/app/Http/Admin/Views/chapter/lessons_vod.volt index db09c921..4ada53de 100644 --- a/app/Http/Admin/Views/chapter/lessons_vod.volt +++ b/app/Http/Admin/Views/chapter/lessons_vod.volt @@ -23,7 +23,6 @@ - diff --git a/app/Http/Admin/Views/index/index.volt b/app/Http/Admin/Views/index/index.volt index 7fc4383a..7f90ffa5 100644 --- a/app/Http/Admin/Views/index/index.volt +++ b/app/Http/Admin/Views/index/index.volt @@ -29,7 +29,7 @@
  • - {{ auth_info.name }} + {{ auth_user.name }}
    基本资料
    安全设置
    @@ -62,9 +62,6 @@
    - \ No newline at end of file diff --git a/app/Http/Admin/Views/point/gift/add.volt b/app/Http/Admin/Views/point/gift/add.volt index c7c8ed5f..bcd4d198 100644 --- a/app/Http/Admin/Views/point/gift/add.volt +++ b/app/Http/Admin/Views/point/gift/add.volt @@ -10,7 +10,7 @@
    {% for value,title in types %} - + {% endfor %}
    diff --git a/app/Http/Admin/Views/point/gift/edit.volt b/app/Http/Admin/Views/point/gift/edit.volt index 9e43021f..8808fb96 100644 --- a/app/Http/Admin/Views/point/gift/edit.volt +++ b/app/Http/Admin/Views/point/gift/edit.volt @@ -14,14 +14,18 @@ {% block link_css %} - {{ css_link('https://cdn.jsdelivr.net/npm/vditor/dist/index.css', false) }} + {% if gift.type == 2 %} + {{ css_link('https://cdn.jsdelivr.net/npm/vditor/dist/index.css', false) }} + {% endif %} {% endblock %} {% block include_js %} - {{ js_include('https://cdn.jsdelivr.net/npm/vditor/dist/index.min.js', false) }} - {{ js_include('admin/js/cover.upload.js') }} - {{ js_include('admin/js/vditor.js') }} + {% if gift.type == 2 %} + {{ js_include('https://cdn.jsdelivr.net/npm/vditor/dist/index.min.js', false) }} + {{ js_include('admin/js/cover.upload.js') }} + {{ js_include('admin/js/vditor.js') }} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/app/Http/Admin/Views/point/gift/edit_course.volt b/app/Http/Admin/Views/point/gift/edit_course.volt index e6c7fcd6..5e527a31 100644 --- a/app/Http/Admin/Views/point/gift/edit_course.volt +++ b/app/Http/Admin/Views/point/gift/edit_course.volt @@ -10,7 +10,7 @@
    -
    {{ gift.name }}
    +
    {{ gift.name }}({{ '¥%0.2f'|format(gift.attrs['price']) }})
    @@ -24,6 +24,13 @@
    +
    + +
    + + +
    +
    diff --git a/app/Http/Admin/Views/point/gift/edit_goods.volt b/app/Http/Admin/Views/point/gift/edit_goods.volt index ecfbc919..fbdfe772 100644 --- a/app/Http/Admin/Views/point/gift/edit_goods.volt +++ b/app/Http/Admin/Views/point/gift/edit_goods.volt @@ -49,6 +49,13 @@
    +
    + +
    + + +
    +
    diff --git a/app/Http/Admin/Views/user/add.volt b/app/Http/Admin/Views/user/add.volt index c88e85bf..d2f5244a 100644 --- a/app/Http/Admin/Views/user/add.volt +++ b/app/Http/Admin/Views/user/add.volt @@ -25,19 +25,19 @@
    - {% if auth_info.root == 1 %} -
    - -
    - +
    + +
    + + {% if auth_user.admin_role == 1 %} {% for role in admin_roles %} {% if role.id > 1 %} {% endif %} {% endfor %} -
    + {% endif %}
    - {% endif %} +
    diff --git a/app/Http/Admin/Views/user/edit.volt b/app/Http/Admin/Views/user/edit.volt index 5cd94fe7..652e4e99 100644 --- a/app/Http/Admin/Views/user/edit.volt +++ b/app/Http/Admin/Views/user/edit.volt @@ -33,7 +33,7 @@
    - {% if auth_info.root == 1 %} + {% if auth_user.admin_role == 1 %}
    @@ -75,7 +75,7 @@
    - {% if auth_info.root == 1 %} + {% if auth_user.admin_role == 1 %}
    编辑帐号 diff --git a/app/Http/Api/Services/Account.php b/app/Http/Api/Services/Account.php index b4a13dab..ea2a038b 100644 --- a/app/Http/Api/Services/Account.php +++ b/app/Http/Api/Services/Account.php @@ -59,6 +59,8 @@ class Account extends Service $user = $validator->checkUserLogin($post['account'], $post['password']); + $validator->checkIfAllowLogin($user); + $token = $this->auth->saveAuthInfo($user); $this->eventsManager->fire('Account:afterLogin', $this, $user); @@ -83,6 +85,8 @@ class Account extends Service $user = $validator->checkVerifyLogin($post['account'], $post['verify_code']); + $validator->checkIfAllowLogin($user); + $token = $this->auth->saveAuthInfo($user); $this->eventsManager->fire('Account:afterLogin', $this, $user); diff --git a/app/Http/Home/Controllers/AccountController.php b/app/Http/Home/Controllers/AccountController.php index a7f86564..4efc598a 100644 --- a/app/Http/Home/Controllers/AccountController.php +++ b/app/Http/Home/Controllers/AccountController.php @@ -8,6 +8,7 @@ namespace App\Http\Home\Controllers; use App\Http\Home\Services\Account as AccountService; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Services\Logic\Account\EmailUpdate as EmailUpdateService; use App\Services\Logic\Account\OAuthProvider as OAuthProviderService; use App\Services\Logic\Account\PasswordReset as PasswordResetService; @@ -22,8 +23,15 @@ class AccountController extends Controller */ public function registerAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getAccountRegisterUrl(); + return $this->response->redirect($location); + } + if ($this->authUser->id > 0) { - $this->response->redirect('/'); + return $this->response->redirect('/'); } $returnUrl = $this->request->getHTTPReferer(); @@ -67,8 +75,15 @@ class AccountController extends Controller */ public function loginAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getAccountLoginUrl(); + return $this->response->redirect($location); + } + if ($this->authUser->id > 0) { - $this->response->redirect('/'); + return $this->response->redirect('/'); } $service = new AccountService(); @@ -129,7 +144,7 @@ class AccountController extends Controller $service->logout(); - $this->response->redirect(['for' => 'home.index']); + return $this->response->redirect(['for' => 'home.index']); } /** @@ -137,8 +152,15 @@ class AccountController extends Controller */ public function forgetPasswordAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getAccountForgetUrl(); + return $this->response->redirect($location); + } + if ($this->authUser->id > 0) { - $this->response->redirect(['for' => 'home.index']); + return $this->response->redirect(['for' => 'home.index']); } $service = new AccountService(); diff --git a/app/Http/Home/Controllers/AnswerController.php b/app/Http/Home/Controllers/AnswerController.php index 663ff936..efb3be6b 100644 --- a/app/Http/Home/Controllers/AnswerController.php +++ b/app/Http/Home/Controllers/AnswerController.php @@ -8,6 +8,7 @@ namespace App\Http\Home\Controllers; use App\Http\Home\Services\Answer as AnswerService; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Http\Home\Services\Question as QuestionService; use App\Models\Answer as AnswerModel; use App\Services\Logic\Answer\AnswerAccept as AnswerAcceptService; @@ -53,6 +54,13 @@ class AnswerController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getAnswerInfoUrl($id); + return $this->response->redirect($location); + } + $service = new AnswerInfoService(); $answer = $service->handle($id); @@ -75,7 +83,7 @@ class AnswerController extends Controller ['answer_id' => $id], ); - $this->response->redirect($location); + return $this->response->redirect($location); } /** diff --git a/app/Http/Home/Controllers/ArticleController.php b/app/Http/Home/Controllers/ArticleController.php index cbd48b8f..e22dc7fa 100644 --- a/app/Http/Home/Controllers/ArticleController.php +++ b/app/Http/Home/Controllers/ArticleController.php @@ -9,6 +9,7 @@ namespace App\Http\Home\Controllers; use App\Http\Home\Services\Article as ArticleService; use App\Http\Home\Services\ArticleQuery as ArticleQueryService; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Models\Article as ArticleModel; use App\Services\Logic\Article\ArticleClose as ArticleCloseService; use App\Services\Logic\Article\ArticleCreate as ArticleCreateService; @@ -33,6 +34,13 @@ class ArticleController extends Controller */ public function listAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getArticleListUrl(); + return $this->response->redirect($location); + } + $service = new ArticleQueryService(); $sorts = $service->handleSorts(); @@ -101,6 +109,13 @@ class ArticleController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getArticleInfoUrl($id); + return $this->response->redirect($location); + } + $service = new ArticleInfoService(); $article = $service->handle($id); diff --git a/app/Http/Home/Controllers/ChapterController.php b/app/Http/Home/Controllers/ChapterController.php index 6e2ba588..9d6b8021 100644 --- a/app/Http/Home/Controllers/ChapterController.php +++ b/app/Http/Home/Controllers/ChapterController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Models\ChapterLive as LiveModel; use App\Models\Course as CourseModel; use App\Services\Logic\Chapter\ChapterInfo as ChapterInfoService; @@ -39,6 +40,13 @@ class ChapterController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getChapterInfoUrl($id); + return $this->response->redirect($location); + } + if ($this->authUser->id == 0) { return $this->response->redirect(['for' => 'home.account.login']); } diff --git a/app/Http/Home/Controllers/CourseController.php b/app/Http/Home/Controllers/CourseController.php index bc1ae450..9e82fc2f 100644 --- a/app/Http/Home/Controllers/CourseController.php +++ b/app/Http/Home/Controllers/CourseController.php @@ -8,6 +8,7 @@ namespace App\Http\Home\Controllers; use App\Http\Home\Services\CourseQuery as CourseQueryService; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Services\Logic\Course\ChapterList as CourseChapterListService; use App\Services\Logic\Course\ConsultList as CourseConsultListService; use App\Services\Logic\Course\CourseFavorite as CourseFavoriteService; @@ -32,6 +33,13 @@ class CourseController extends Controller */ public function listAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getCourseListUrl(); + return $this->response->redirect($location); + } + $service = new CourseQueryService(); $topCategories = $service->handleTopCategories(); @@ -73,6 +81,13 @@ class CourseController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getCourseInfoUrl($id); + return $this->response->redirect($location); + } + $service = new CourseInfoService(); $course = $service->handle($id); diff --git a/app/Http/Home/Controllers/HelpController.php b/app/Http/Home/Controllers/HelpController.php index e41ccb9a..6ea78c31 100644 --- a/app/Http/Home/Controllers/HelpController.php +++ b/app/Http/Home/Controllers/HelpController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Http\Home\Services\Index as IndexService; use App\Services\Logic\Help\HelpInfo as HelpInfoService; use App\Services\Logic\Help\HelpList as HelpListService; @@ -22,6 +23,13 @@ class HelpController extends Controller */ public function indexAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getHelpIndexUrl(); + return $this->response->redirect($location); + } + $service = new HelpListService(); $items = $service->handle(); @@ -36,6 +44,13 @@ class HelpController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getHelpInfoUrl($id); + return $this->response->redirect($location); + } + $service = new HelpInfoService(); $help = $service->handle($id); diff --git a/app/Http/Home/Controllers/ImController.php b/app/Http/Home/Controllers/ImController.php index bb530c2d..e413bf54 100644 --- a/app/Http/Home/Controllers/ImController.php +++ b/app/Http/Home/Controllers/ImController.php @@ -21,7 +21,7 @@ class ImController extends Controller parent::initialize(); if ($this->authUser->id == 0) { - $this->response->redirect(['for' => 'home.account.login']); + return $this->response->redirect(['for' => 'home.account.login']); } } diff --git a/app/Http/Home/Controllers/ImGroupController.php b/app/Http/Home/Controllers/ImGroupController.php index fdabf072..a8647226 100644 --- a/app/Http/Home/Controllers/ImGroupController.php +++ b/app/Http/Home/Controllers/ImGroupController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Http\Home\Services\ImGroup as ImGroupService; use Phalcon\Mvc\View; @@ -21,6 +22,13 @@ class ImGroupController extends Controller */ public function listAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getImGroupListUrl(); + return $this->response->redirect($location); + } + $this->seo->prependTitle('群组'); $this->view->pick('im/group/list'); @@ -47,6 +55,13 @@ class ImGroupController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getImGroupIndexUrl($id); + return $this->response->redirect($location); + } + $service = new ImGroupService(); $group = $service->getGroup($id); diff --git a/app/Http/Home/Controllers/IndexController.php b/app/Http/Home/Controllers/IndexController.php index f8c6f6cd..38dc4890 100644 --- a/app/Http/Home/Controllers/IndexController.php +++ b/app/Http/Home/Controllers/IndexController.php @@ -7,32 +7,24 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Http\Home\Services\Index as IndexService; -use App\Traits\Client as ClientTrait; -use Phalcon\Mvc\Dispatcher; class IndexController extends Controller { - use ClientTrait; - - public function beforeExecuteRoute(Dispatcher $dispatcher) - { - if ($this->isMobileBrowser() && $this->h5Enabled()) { - - $this->response->redirect('/h5', true); - - return false; - } - - return parent::beforeExecuteRoute($dispatcher); - } - /** * @Get("/", name="home.index") */ public function indexAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getHomeUrl(); + return $this->response->redirect($location); + } + $this->seo->setKeywords($this->siteInfo['keywords']); $this->seo->setDescription($this->siteInfo['description']); @@ -71,11 +63,4 @@ class IndexController extends Controller $this->view->setVar('vip_courses', $service->getSimpleVipCourses()); } - protected function h5Enabled() - { - $file = public_path('h5/index.html'); - - return file_exists($file); - } - } diff --git a/app/Http/Home/Controllers/OrderController.php b/app/Http/Home/Controllers/OrderController.php index 98310103..b8037f18 100644 --- a/app/Http/Home/Controllers/OrderController.php +++ b/app/Http/Home/Controllers/OrderController.php @@ -107,7 +107,7 @@ class OrderController extends Controller $order = $service->handle($sn); if ($order['status'] != OrderModel::STATUS_PENDING) { - $this->response->redirect(['for' => 'home.uc.orders']); + return $this->response->redirect(['for' => 'home.uc.orders']); } $this->seo->prependTitle('支付订单'); diff --git a/app/Http/Home/Controllers/PageController.php b/app/Http/Home/Controllers/PageController.php index 5689b2c9..7bb30570 100644 --- a/app/Http/Home/Controllers/PageController.php +++ b/app/Http/Home/Controllers/PageController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Http\Home\Services\Index as IndexService; use App\Services\Logic\Page\PageInfo as PageInfoService; @@ -21,6 +22,13 @@ class PageController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getPageInfoUrl($id); + return $this->response->redirect($location); + } + $service = new PageInfoService(); $page = $service->handle($id); diff --git a/app/Http/Home/Controllers/PublicController.php b/app/Http/Home/Controllers/PublicController.php index 1cb5a608..1e708c07 100644 --- a/app/Http/Home/Controllers/PublicController.php +++ b/app/Http/Home/Controllers/PublicController.php @@ -41,7 +41,7 @@ class PublicController extends \Phalcon\Mvc\Controller $location = $service->getFileUrl($file->path); - $this->response->redirect($location, true); + return $this->response->redirect($location, true); } else { diff --git a/app/Http/Home/Controllers/QuestionController.php b/app/Http/Home/Controllers/QuestionController.php index 7c92df29..a9f8526a 100644 --- a/app/Http/Home/Controllers/QuestionController.php +++ b/app/Http/Home/Controllers/QuestionController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Http\Home\Services\Question as QuestionService; use App\Http\Home\Services\QuestionQuery as QuestionQueryService; use App\Models\Question as QuestionModel; @@ -32,6 +33,13 @@ class QuestionController extends Controller */ public function listAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getQuestionListUrl(); + return $this->response->redirect($location); + } + $service = new QuestionQueryService(); $sorts = $service->handleSorts(); @@ -98,6 +106,13 @@ class QuestionController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getQuestionInfoUrl($id); + return $this->response->redirect($location); + } + $service = new QuestionInfoService(); $question = $service->handle($id); diff --git a/app/Http/Home/Controllers/SearchController.php b/app/Http/Home/Controllers/SearchController.php index df0a1b0c..7d8a2571 100644 --- a/app/Http/Home/Controllers/SearchController.php +++ b/app/Http/Home/Controllers/SearchController.php @@ -28,7 +28,7 @@ class SearchController extends Controller $type = $this->request->get('type', ['trim', 'string'], 'course'); if (empty($query)) { - $this->response->redirect(['for' => 'home.course.list']); + return $this->response->redirect(['for' => 'home.course.list']); } $this->seo->prependTitle(['搜索', $query]); diff --git a/app/Http/Home/Controllers/TeacherController.php b/app/Http/Home/Controllers/TeacherController.php index bcaa04c4..88cef3b7 100644 --- a/app/Http/Home/Controllers/TeacherController.php +++ b/app/Http/Home/Controllers/TeacherController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Services\Logic\Teacher\TeacherList as TeacherListService; use Phalcon\Mvc\View; @@ -21,6 +22,13 @@ class TeacherController extends Controller */ public function listAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getTeacherListUrl(); + return $this->response->redirect($location); + } + $this->seo->prependTitle('教师'); } @@ -44,6 +52,13 @@ class TeacherController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getTeacherIndexUrl($id); + return $this->response->redirect($location); + } + $this->dispatcher->forward([ 'controller' => 'user', 'action' => 'show', diff --git a/app/Http/Home/Controllers/UserController.php b/app/Http/Home/Controllers/UserController.php index 6870b2db..7e141f01 100644 --- a/app/Http/Home/Controllers/UserController.php +++ b/app/Http/Home/Controllers/UserController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Services\Logic\User\AnswerList as UserAnswerListService; use App\Services\Logic\User\ArticleList as UserArticleListService; use App\Services\Logic\User\CourseList as UserCourseListService; @@ -27,6 +28,13 @@ class UserController extends Controller */ public function showAction($id) { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getUserIndexUrl($id); + return $this->response->redirect($location); + } + $service = new UserInfoService(); $user = $service->handle($id); diff --git a/app/Http/Home/Controllers/VipController.php b/app/Http/Home/Controllers/VipController.php index fb52e58a..34c0b84c 100644 --- a/app/Http/Home/Controllers/VipController.php +++ b/app/Http/Home/Controllers/VipController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Http\Home\Services\FullH5Url as FullH5UrlService; use App\Services\Logic\Vip\CourseList as VipCourseListService; use App\Services\Logic\Vip\OptionList as VipOptionListService; use App\Services\Logic\Vip\UserList as VipUserListService; @@ -23,6 +24,13 @@ class VipController extends Controller */ public function indexAction() { + $service = new FullH5UrlService(); + + if ($service->isMobileBrowser() && $service->h5Enabled()) { + $location = $service->getVipIndexUrl(); + return $this->response->redirect($location); + } + $service = new VipOptionListService(); $vipOptions = $service->handle(); diff --git a/app/Http/Home/Services/Account.php b/app/Http/Home/Services/Account.php index e54767f5..929c30ac 100644 --- a/app/Http/Home/Services/Account.php +++ b/app/Http/Home/Services/Account.php @@ -51,6 +51,8 @@ class Account extends Service $user = $validator->checkUserLogin($post['account'], $post['password']); + $validator->checkIfAllowLogin($user); + $validator = new CaptchaValidator(); $validator->checkCode($post['ticket'], $post['rand']); @@ -68,6 +70,8 @@ class Account extends Service $user = $validator->checkVerifyLogin($post['account'], $post['verify_code']); + $validator->checkIfAllowLogin($user); + $this->auth->saveAuthInfo($user); $this->eventsManager->fire('Account:afterLogin', $this, $user); diff --git a/app/Http/Home/Services/FullH5Url.php b/app/Http/Home/Services/FullH5Url.php new file mode 100644 index 00000000..cd161aa1 --- /dev/null +++ b/app/Http/Home/Services/FullH5Url.php @@ -0,0 +1,149 @@ +baseUrl = $this->getBaseUrl(); + } + + public function getHomeUrl() + { + return sprintf('%s/index/index', $this->baseUrl); + } + + public function getAccountRegisterUrl() + { + return sprintf('%s/account/register', $this->baseUrl); + } + + public function getAccountLoginUrl() + { + return sprintf('%s/account/login', $this->baseUrl); + } + + public function getAccountForgetUrl() + { + return sprintf('%s/account/forget', $this->baseUrl); + } + + public function getVipIndexUrl() + { + return sprintf('%s/vip/index', $this->baseUrl); + } + + public function getHelpIndexUrl() + { + return sprintf('%s/help/index', $this->baseUrl); + } + + public function getCourseListUrl() + { + return sprintf('%s/course/list', $this->baseUrl); + } + + public function getArticleListUrl() + { + return sprintf('%s/article/list', $this->baseUrl); + } + + public function getQuestionListUrl() + { + return sprintf('%s/question/list', $this->baseUrl); + } + + public function getLiveListUrl() + { + return sprintf('%s/discovery/index', $this->baseUrl); + } + + public function getTeacherListUrl() + { + return sprintf('%s/discovery/index', $this->baseUrl); + } + + public function getImGroupListUrl() + { + return sprintf('%s/discovery/index', $this->baseUrl); + } + + public function getPointGiftListUrl() + { + return sprintf('%s/point/gift/list', $this->baseUrl); + } + + public function getPageInfoUrl($id) + { + return sprintf('%s/page/info?id=%s', $this->baseUrl, $id); + } + + public function getHelpInfoUrl($id) + { + return sprintf('%s/help/info?id=%s', $this->baseUrl, $id); + } + + public function getArticleInfoUrl($id) + { + return sprintf('%s/article/info?id=%s', $this->baseUrl, $id); + } + + public function getQuestionInfoUrl($id) + { + return sprintf('%s/question/info?id=%s', $this->baseUrl, $id); + } + + public function getAnswerInfoUrl($id) + { + return sprintf('%s/answer/info?id=%s', $this->baseUrl, $id); + } + + public function getCourseInfoUrl($id) + { + return sprintf('%s/course/info?id=%s', $this->baseUrl, $id); + } + + public function getChapterInfoUrl($id) + { + return sprintf('%s/chapter/info?id=%s', $this->baseUrl, $id); + } + + public function getUserIndexUrl($id) + { + return sprintf('%s/user/index?id=%s', $this->baseUrl, $id); + } + + public function getTeacherIndexUrl($id) + { + return sprintf('%s/teacher/index?id=%s', $this->baseUrl, $id); + } + + public function getImGroupIndexUrl($id) + { + return sprintf('%s/im/group/index?id=%s', $this->baseUrl, $id); + } + + public function getPointGiftInfoUrl($id) + { + return sprintf('%s/point/gift/info?id=%s', $this->baseUrl, $id); + } + + protected function getBaseUrl() + { + return sprintf('%s/h5/#/pages', kg_site_url()); + } + +} diff --git a/app/Http/Home/Services/FullWebUrl.php b/app/Http/Home/Services/FullWebUrl.php new file mode 100644 index 00000000..b38232a6 --- /dev/null +++ b/app/Http/Home/Services/FullWebUrl.php @@ -0,0 +1,86 @@ +baseUrl = $this->getBaseUrl(); + } + + public function getHomeUrl() + { + return $this->baseUrl; + } + + public function getArticleShowUrl($id) + { + $route = $this->url->get(['for' => 'home.article.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getQuestionShowUrl($id) + { + $route = $this->url->get(['for' => 'home.question.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getCourseShowUrl($id) + { + $route = $this->url->get(['for' => 'home.course.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getChapterShowUrl($id) + { + $route = $this->url->get(['for' => 'home.chapter.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getUserShowUrl($id) + { + $route = $this->url->get(['for' => 'home.user.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getTeacherShowUrl($id) + { + $route = $this->url->get(['for' => 'home.teacher.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getImGroupShowUrl($id) + { + $route = $this->url->get(['for' => 'home.im_group.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + public function getPointGiftShowUrl($id) + { + $route = $this->url->get(['for' => 'home.point_gift.show', 'id' => $id]); + + return $this->baseUrl . $route; + } + + protected function getBaseUrl() + { + return kg_site_url(); + } + +} \ No newline at end of file diff --git a/app/Http/Home/Services/ShareUrl.php b/app/Http/Home/Services/ShareUrl.php index 6ea6ab62..96bbc424 100644 --- a/app/Http/Home/Services/ShareUrl.php +++ b/app/Http/Home/Services/ShareUrl.php @@ -7,6 +7,8 @@ namespace App\Http\Home\Services; +use App\Traits\Client as ClientTrait; + class ShareUrl extends Service { @@ -15,150 +17,105 @@ class ShareUrl extends Service * * @var string */ - protected $webBaseUrl; + protected $fullWebUrl; /** * H5站点URL * * @var string */ - protected $h5BaseUrl; + protected $fullH5Url; + + use ClientTrait; public function __construct() { - $this->webBaseUrl = $this->getWebBaseUrl(); - $this->h5BaseUrl = $this->getH5BaseUrl(); + $this->fullWebUrl = new FullWebUrl(); + $this->fullH5Url = new FullH5Url(); } - public function handle($id, $type, $referer = 0) + public function handle($id, $type) { if ($type == 'article') { - $result = $this->getArticleUrl($id, $referer); + $result = $this->getArticleUrl($id); + } elseif ($type == 'question') { + $result = $this->getQuestionUrl($id); } elseif ($type == 'course') { - $result = $this->getCourseUrl($id, $referer); + $result = $this->getCourseUrl($id); } elseif ($type == 'chapter') { - $result = $this->getChapterUrl($id, $referer); - } elseif ($type == 'package') { - $result = $this->getPackageUrl($id, $referer); - } elseif ($type == 'vip') { - $result = $this->getVipUrl($id, $referer); + $result = $this->getChapterUrl($id); } elseif ($type == 'user') { - $result = $this->getUserUrl($id, $referer); + $result = $this->getUserUrl($id); + } elseif ($type == 'teacher') { + $result = $this->getTeacherUrl($id); } else { - $result = $this->getHomeUrl($referer); + $result = $this->getHomeUrl(); } return $this->h5Enabled() ? $result['h5'] : $result['web']; } - public function getHomeUrl($referer = 0) + public function getHomeUrl() { - $webUrl = sprintf('%s?referer=%s', $this->webBaseUrl, $referer); + $webUrl = $this->fullWebUrl->getHomeUrl(); - $h5Url = sprintf('%s?referer=%s', $this->h5BaseUrl, $referer); + $h5Url = $this->fullH5Url->getHomeUrl(); return ['web' => $webUrl, 'h5' => $h5Url]; } - public function getArticleUrl($id, $referer = 0) + public function getArticleUrl($id = 0) { - $route = $this->url->get( - ['for' => 'home.article.show', 'id' => $id], - ['referer' => $referer] - ); + $webUrl = $this->fullWebUrl->getArticleShowUrl($id); - $webUrl = $this->webBaseUrl . $route; - - $h5Url = sprintf('%s/article/info?id=%s&referer=%s', $this->h5BaseUrl, $id, $referer); + $h5Url = $this->fullH5Url->getArticleInfoUrl($id); return ['web' => $webUrl, 'h5' => $h5Url]; } - public function getCourseUrl($id, $referer = 0) + public function getQuestionUrl($id = 0) { - $route = $this->url->get( - ['for' => 'home.course.show', 'id' => $id], - ['referer' => $referer] - ); + $webUrl = $this->fullWebUrl->getQuestionShowUrl($id); - $webUrl = $this->webBaseUrl . $route; - - $h5Url = sprintf('%s/course/info?id=%s&referer=%s', $this->h5BaseUrl, $id, $referer); + $h5Url = $this->fullH5Url->getQuestionInfoUrl($id); return ['web' => $webUrl, 'h5' => $h5Url]; } - public function getChapterUrl($id, $referer = 0) + public function getCourseUrl($id = 0) { - $route = $this->url->get( - ['for' => 'home.chapter.show', 'id' => $id], - ['referer' => $referer] - ); + $webUrl = $this->fullWebUrl->getCourseShowUrl($id); - $webUrl = $this->webBaseUrl . $route; - - $h5Url = sprintf('%s/chapter/info?id=%s&referer=%s', $this->h5BaseUrl, $id, $referer); + $h5Url = $this->fullH5Url->getCourseInfoUrl($id); return ['web' => $webUrl, 'h5' => $h5Url]; } - public function getPackageUrl($id, $referer = 0) + public function getChapterUrl($id = 0) { - $route = $this->url->get( - ['for' => 'home.package.show', 'id' => $id], - ['referer' => $referer] - ); + $webUrl = $this->fullWebUrl->getChapterShowUrl($id); - $webUrl = $this->webBaseUrl . $route; - - $h5Url = sprintf('%s/package/info?id=%s&referer=%s', $this->h5BaseUrl, $id, $referer); + $h5Url = $this->fullH5Url->getChapterInfoUrl($id); return ['web' => $webUrl, 'h5' => $h5Url]; } - public function getUserUrl($id, $referer = 0) + public function getUserUrl($id = 0) { - $route = $this->url->get( - ['for' => 'home.user.show', 'id' => $id], - ['referer' => $referer] - ); + $webUrl = $this->fullWebUrl->getUserShowUrl($id); - $webUrl = $this->webBaseUrl . $route; - - $h5Url = sprintf('%s/user/index?id=%s&referer=%s', $this->h5BaseUrl, $id, $referer); + $h5Url = $this->fullH5Url->getUserIndexUrl($id); return ['web' => $webUrl, 'h5' => $h5Url]; } - public function getVipUrl($id, $referer = 0) + public function getTeacherUrl($id = 0) { - $route = $this->url->get( - ['for' => 'home.vip.index'], - ['id' => $id, 'referer' => $referer] - ); + $webUrl = $this->fullWebUrl->getTeacherShowUrl($id); - $webUrl = $this->webBaseUrl . $route; - - $h5Url = sprintf('%s/vip/index?id=%s&referer=%s', $this->h5BaseUrl, $id, $referer); + $h5Url = $this->fullH5Url->getTeacherIndexUrl($id); return ['web' => $webUrl, 'h5' => $h5Url]; } - protected function h5Enabled() - { - $file = public_path('h5/index.html'); - - return file_exists($file); - } - - protected function getWebBaseUrl() - { - return kg_site_url(); - } - - protected function getH5BaseUrl() - { - return sprintf('%s/h5/#/pages', kg_site_url()); - } - } diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index 55c22de9..fed579d7 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://koogua.com'; - protected $version = '1.4.5'; + protected $version = '1.4.6'; public function __get($name) { diff --git a/app/Repos/PointGift.php b/app/Repos/PointGift.php index 9bedf0a0..ba078a52 100644 --- a/app/Repos/PointGift.php +++ b/app/Repos/PointGift.php @@ -76,6 +76,32 @@ class PointGift extends Repository ]); } + /** + * @param int $courseId + * @return PointGiftModel|Model|bool + */ + public function findByCourseId($courseId) + { + /** + * @todo 重新设计表结构 + * + * 没有预留独立的条目编号,先这么将就实现吧 + */ + $records = PointGiftModel::query() + ->where('type = :type:', ['type' => PointGiftModel::TYPE_COURSE]) + ->execute(); + + if ($records->count() == 0) return false; + + foreach ($records as $record) { + if ($record->attrs['id'] == $courseId) { + return $record; + } + } + + return false; + } + /** * @param array $ids * @param string|array $columns diff --git a/app/Services/Auth/Api.php b/app/Services/Auth/Api.php index f3e4bd7b..afd99c84 100644 --- a/app/Services/Auth/Api.php +++ b/app/Services/Auth/Api.php @@ -24,7 +24,9 @@ class Api extends AuthService $lifetime = $this->getTokenLifetime(); - $this->logoutOtherClients($user->id); + $clientType = $this->getClientType(); + + $this->logoutClients($user->id, $clientType); $this->createUserToken($user->id, $token, $lifetime); @@ -70,6 +72,52 @@ class Api extends AuthService return $authInfo ?: null; } + public function logoutClients($userId, $clientType = null) + { + $repo = new UserTokenRepo(); + + $records = $repo->findByUserId($userId); + + if ($records->count() == 0) return; + + if ($clientType) { + $this->logoutSpecialClients($records, $clientType); + } else { + $this->logoutAllClients($records); + } + } + + /** + * @param $userTokens UserTokenModel[] + */ + protected function logoutAllClients($userTokens) + { + $cache = $this->getCache(); + + foreach ($userTokens as $record) { + $record->delete(); + $key = $this->getTokenCacheKey($record->token); + $cache->delete($key); + } + } + + /** + * @param $userTokens UserTokenModel[] + * @param int $clientType + */ + protected function logoutSpecialClients($userTokens, $clientType) + { + $cache = $this->getCache(); + + foreach ($userTokens as $record) { + if ($record->client_type == $clientType) { + $record->delete(); + $key = $this->getTokenCacheKey($record->token); + $cache->delete($key); + } + } + } + protected function createUserToken($userId, $token, $lifetime) { $userToken = new UserTokenModel(); @@ -83,27 +131,6 @@ class Api extends AuthService $userToken->create(); } - protected function logoutOtherClients($userId) - { - $repo = new UserTokenRepo(); - - $records = $repo->findByUserId($userId); - - $cache = $this->getCache(); - - $clientType = $this->getClientType(); - - if ($records->count() == 0) return; - - foreach ($records as $record) { - if ($record->client_type == $clientType) { - $record->delete(); - $key = $this->getTokenCacheKey($record->token); - $cache->delete($key); - } - } - } - protected function generateToken($userId) { return md5(uniqid() . time() . $userId); diff --git a/app/Services/Auth/Home.php b/app/Services/Auth/Home.php index 431a2d74..0cc50cc9 100644 --- a/app/Services/Auth/Home.php +++ b/app/Services/Auth/Home.php @@ -24,7 +24,7 @@ class Home extends AuthService $lifetime = $this->getSessionLifetime(); - $this->logoutOtherClients($user->id); + $this->logoutClients($user->id); $this->createUserSession($user->id, $sessionId, $lifetime); @@ -59,20 +59,7 @@ class Home extends AuthService return 'home_auth_info'; } - protected function createUserSession($userId, $sessionId, $lifetime) - { - $userSession = new UserSessionModel(); - - $userSession->user_id = $userId; - $userSession->session_id = $sessionId; - $userSession->client_type = $this->getClientType(); - $userSession->client_ip = $this->getClientIp(); - $userSession->expire_time = time() + $lifetime; - - $userSession->create(); - } - - protected function logoutOtherClients($userId) + public function logoutClients($userId) { $cache = $this->getCache(); @@ -89,6 +76,19 @@ class Home extends AuthService } } + protected function createUserSession($userId, $sessionId, $lifetime) + { + $userSession = new UserSessionModel(); + + $userSession->user_id = $userId; + $userSession->session_id = $sessionId; + $userSession->client_type = $this->getClientType(); + $userSession->client_ip = $this->getClientIp(); + $userSession->expire_time = time() + $lifetime; + + $userSession->create(); + } + protected function getSessionLifetime() { $config = $this->getConfig(); diff --git a/app/Services/Logic/Course/ChapterList.php b/app/Services/Logic/Course/ChapterList.php index d3438eae..0792ec3b 100644 --- a/app/Services/Logic/Course/ChapterList.php +++ b/app/Services/Logic/Course/ChapterList.php @@ -39,35 +39,42 @@ class ChapterList extends LogicService if (count($chapters) == 0) return []; if ($user->id > 0 && $this->courseUser) { - $mapping = $this->getLearningMapping($course->id, $user->id, $this->courseUser->plan_id); - foreach ($chapters as &$chapter) { - foreach ($chapter['children'] as &$lesson) { - /** - * @todo v1.4.1之前缓存中无published字段,临时给默认值 - */ - $lesson['published'] = $lesson['published'] ?? 1; - $owned = ($this->ownedCourse || $lesson['free'] == 1) && $lesson['published'] == 1; - $lesson['me'] = [ - 'owned' => $owned ? 1 : 0, - 'progress' => $mapping[$lesson['id']]['progress'] ?? 0, - 'duration' => $mapping[$lesson['id']]['duration'] ?? 0, - ]; - } - } + $chapters = $this->handleLoginUserChapters($chapters, $course, $user); } else { - foreach ($chapters as &$chapter) { - foreach ($chapter['children'] as &$lesson) { - /** - * @todo v1.4.1之前缓存中无published字段,临时给默认值 - */ - $lesson['published'] = $lesson['published'] ?? 1; - $owned = ($this->ownedCourse || $lesson['free'] == 1) && $lesson['published'] == 1; - $lesson['me'] = [ - 'owned' => $owned ? 1 : 0, - 'progress' => 0, - 'duration' => 0, - ]; - } + $chapters = $this->handleGuestUserChapters($chapters); + } + + return $chapters; + } + + protected function handleLoginUserChapters(array $chapters, CourseModel $course, UserModel $user) + { + $mapping = $this->getLearningMapping($course->id, $user->id, $this->courseUser->plan_id); + + foreach ($chapters as &$chapter) { + foreach ($chapter['children'] as &$lesson) { + $owned = ($this->ownedCourse || $lesson['free'] == 1) && $lesson['published'] == 1; + $lesson['me'] = [ + 'owned' => $owned ? 1 : 0, + 'progress' => $mapping[$lesson['id']]['progress'] ?? 0, + 'duration' => $mapping[$lesson['id']]['duration'] ?? 0, + ]; + } + } + + return $chapters; + } + + protected function handleGuestUserChapters(array $chapters) + { + foreach ($chapters as &$chapter) { + foreach ($chapter['children'] as &$lesson) { + $owned = ($this->ownedCourse || $lesson['free'] == 1) && $lesson['published'] == 1; + $lesson['me'] = [ + 'owned' => $owned ? 1 : 0, + 'progress' => 0, + 'duration' => 0, + ]; } } diff --git a/app/Services/Logic/Point/GiftInfo.php b/app/Services/Logic/Point/GiftInfo.php index fc7dde2f..3611ecf6 100644 --- a/app/Services/Logic/Point/GiftInfo.php +++ b/app/Services/Logic/Point/GiftInfo.php @@ -55,6 +55,11 @@ class GiftInfo extends LogicService $gift->name = $course->title; $gift->cover = $course->cover; $gift->details = $course->details; + $gift->attrs = [ + 'id' => $course->id, + 'title' => $course->title, + 'price' => $course->market_price, + ]; return $gift; } diff --git a/app/Services/Logic/Teacher/Console/CourseList.php b/app/Services/Logic/Teacher/Console/CourseList.php index ef183037..6c2527aa 100644 --- a/app/Services/Logic/Teacher/Console/CourseList.php +++ b/app/Services/Logic/Teacher/Console/CourseList.php @@ -7,56 +7,19 @@ namespace App\Services\Logic\Teacher\Console; -use App\Builders\CourseUserList as CourseUserListBuilder; -use App\Library\Paginator\Query as PagerQuery; -use App\Models\CourseUser as CourseUserModel; -use App\Repos\CourseUser as CourseUserRepo; use App\Services\Logic\Service as LogicService; -use App\Services\Logic\UserTrait; +use App\Services\Logic\Teacher\CourseList as CourseListService; class CourseList extends LogicService { - use UserTrait; - public function handle() { $user = $this->getLoginUser(); - $pagerQuery = new PagerQuery(); + $service = new CourseListService(); - $params = $pagerQuery->getParams(); - - $params['user_id'] = $user->id; - $params['role_type'] = CourseUserModel::ROLE_TEACHER; - $params['deleted'] = 0; - - $sort = $pagerQuery->getSort(); - $page = $pagerQuery->getPage(); - $limit = $pagerQuery->getLimit(); - - $courseUserRepo = new CourseUserRepo(); - - $pager = $courseUserRepo->paginate($params, $sort, $page, $limit); - - return $this->handleCourses($pager); - } - - protected function handleCourses($pager) - { - if ($pager->total_items == 0) { - return $pager; - } - - $builder = new CourseUserListBuilder(); - - $relations = $pager->items->toArray(); - - $courses = $builder->getCourses($relations); - - $pager->items = $courses; - - return $pager; + return $service->handle($user->id); } } diff --git a/app/Traits/Client.php b/app/Traits/Client.php index cce2567a..15da0c4b 100644 --- a/app/Traits/Client.php +++ b/app/Traits/Client.php @@ -67,4 +67,11 @@ trait Client return $result->isMobile(); } + public function h5Enabled() + { + $file = public_path('h5/index.html'); + + return file_exists($file); + } + } diff --git a/app/Validators/Account.php b/app/Validators/Account.php index 9fc18ba0..095bcdfa 100644 --- a/app/Validators/Account.php +++ b/app/Validators/Account.php @@ -12,6 +12,7 @@ use App\Exceptions\Forbidden as ForbiddenException; use App\Library\Utils\Password as PasswordUtil; use App\Library\Validators\Common as CommonValidator; use App\Models\Account as AccountModel; +use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; use App\Repos\User as UserRepo; @@ -166,4 +167,14 @@ class Account extends Validator return $user; } + public function checkIfAllowLogin(UserModel $user) + { + $locked = $user->locked == 1; + $expired = $user->lock_expiry_time > time(); + + if ($locked && !$expired) { + throw new ForbiddenException('account.locked'); + } + } + } diff --git a/app/Validators/User.php b/app/Validators/User.php index d64b14b7..40155790 100644 --- a/app/Validators/User.php +++ b/app/Validators/User.php @@ -14,7 +14,6 @@ use App\Library\Validators\Common as CommonValidator; use App\Models\User as UserModel; use App\Repos\Role as RoleRepo; use App\Repos\User as UserRepo; -use App\Services\Auth\Admin as AdminAuth; class User extends Validator { @@ -218,18 +217,4 @@ class User extends Validator } } - public function checkIfCanEditUser($user) - { - /** - * @var AdminAuth $auth - */ - $auth = $this->getDI()->get('auth'); - - $authUser = $auth->getAuthInfo(); - - if ($authUser['id']) { - - } - } - } diff --git a/config/errors.php b/config/errors.php index 5289cc99..57d2704e 100644 --- a/config/errors.php +++ b/config/errors.php @@ -46,7 +46,7 @@ $error['captcha.invalid_code'] = '无效的验证码'; * 帐号相关 */ $error['account.not_found'] = '账号不存在'; -$error['account.login_block'] = '账号被锁定,无法登录'; +$error['account.locked'] = '账号被锁定,无法登录'; $error['account.login_pwd_incorrect'] = '登录密码不正确'; $error['account.invalid_login_name'] = '无效的登录名'; $error['account.invalid_email'] = '无效的电子邮箱';