diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index e15007da..50ec1d07 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -191,6 +191,7 @@ class DeliverTask extends Task $user = $userRepo->findById($order->owner_id); $user->vip_expiry_time = $itemInfo['vip']['expiry_time']; + $user->vip = 1; if ($user->update() === false) { throw new \RuntimeException('Update Vip Expiry Failed'); diff --git a/app/Http/Home/Controllers/Controller.php b/app/Http/Home/Controllers/Controller.php index 301b0191..983a3fac 100644 --- a/app/Http/Home/Controllers/Controller.php +++ b/app/Http/Home/Controllers/Controller.php @@ -51,7 +51,7 @@ class Controller extends \Phalcon\Mvc\Controller public function beforeExecuteRoute(Dispatcher $dispatcher) { $this->siteInfo = $this->getSiteInfo(); - $this->authUser = $this->getAuthUser(); + $this->authUser = $this->getAuthUser(true); if ($this->siteInfo['status'] == 'closed') { $dispatcher->forward([ @@ -90,14 +90,14 @@ class Controller extends \Phalcon\Mvc\Controller $this->view->setVar('im_info', $this->imInfo); } - protected function getAuthUser() + protected function getAuthUser($cache = false) { /** * @var HomeAuth $auth */ $auth = $this->getDI()->get('auth'); - return $auth->getCurrentUser(); + return $auth->getCurrentUser($cache); } protected function getSeo() diff --git a/app/Http/Home/Controllers/UserConsoleController.php b/app/Http/Home/Controllers/UserConsoleController.php index de6a035f..70725041 100644 --- a/app/Http/Home/Controllers/UserConsoleController.php +++ b/app/Http/Home/Controllers/UserConsoleController.php @@ -44,6 +44,10 @@ class UserConsoleController extends Controller public function initialize() { parent::initialize(); + + $authUser = $this->getAuthUser(false); + + $this->view->setVar('auth_user', $authUser); } /** diff --git a/app/Traits/Auth.php b/app/Traits/Auth.php index a8a87a13..919ab0e1 100644 --- a/app/Traits/Auth.php +++ b/app/Traits/Auth.php @@ -3,7 +3,9 @@ namespace App\Traits; use App\Caches\User as UserCache; +use App\Exceptions\Unauthorized as UnauthorizedException; use App\Models\User as UserModel; +use App\Repos\User as UserRepo; use App\Services\Auth as AuthService; use App\Validators\Validator as AppValidator; use Phalcon\Di as Di; @@ -12,9 +14,10 @@ trait Auth { /** + * @param bool $cache * @return UserModel */ - public function getCurrentUser() + public function getCurrentUser($cache = false) { $authUser = $this->getAuthUser(); @@ -22,15 +25,23 @@ trait Auth return $this->getGuestUser(); } - $userCache = new UserCache(); + if ($cache == false) { + $userRepo = new UserRepo(); + $user = $userRepo->findById($authUser['id']); + } else { + $userCache = new UserCache(); + $user = $userCache->get($authUser['id']); + } - return $userCache->get($authUser['id']); + return $user; } /** + * @param bool $cache * @return UserModel + * @throws UnauthorizedException */ - public function getLoginUser() + public function getLoginUser($cache = false) { $authUser = $this->getAuthUser(); @@ -38,9 +49,15 @@ trait Auth $validator->checkAuthUser($authUser['id']); - $userCache = new UserCache(); + if ($cache == false) { + $userRepo = new UserRepo(); + $user = $userRepo->findById($authUser['id']); + } else { + $userCache = new UserCache(); + $user = $userCache->get($authUser['id']); + } - return $userCache->get($authUser['id']); + return $user; } /**