123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace crmeb\repositories;
- use app\models\system\SystemAttachment;
- use app\models\system\SystemAdmin;
- use app\models\user\User;
- use app\models\user\UserToken;
- use crmeb\exceptions\AuthException;
- use crmeb\services\CacheService;
- use Firebase\JWT\ExpiredException;
- use think\db\exception\ModelNotFoundException;
- use think\db\exception\DataNotFoundException;
- use think\exception\DbException;
- use think\facade\Cache;
- /**
- * Class UserRepository
- * @package crmeb\repositories
- */
- class UserRepository
- {
- /**
- * 管理员后台给用户添加金额
- * @param $user
- * $user 用户信息
- * @param $money
- * $money 添加的金额
- */
- public static function adminAddMoney($user, $money)
- {
- }
- /**
- * 管理员后台给用户减少金额
- * @param $user
- * $user 用户信息
- * @param $money
- * $money 减少的金额
- */
- public static function adminSubMoney($user, $money)
- {
- }
- /**
- * 管理员后台给用户增加的积分
- * @param $user
- * $user 用户信息
- * @param $integral
- * $integral 增加的积分
- */
- public static function adminAddIntegral($user, $integral)
- {
- }
- /**
- * 管理员后台给用户减少的积分
- * @param $user
- * $user 用户信息
- * @param $integral
- * $integral 减少的积分
- */
- public static function adminSubIntegral($user, $integral)
- {
- }
- /**
- * 获取授权信息
- * @param string $token
- * @return array
- * @throws AuthException
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public static function parseToken($token): array
- {
- if (!$token || !$tokenData = CacheService::getTokenBucket($token))
- throw new AuthException('请登录', 410000);
- if (!is_array($tokenData) || empty($tokenData) || !isset($tokenData['uid'])) {
- throw new AuthException('请登录', 410000);
- }
-
- try {
- [$user, $type] = User::parseToken($token);
- } catch (\Throwable $e) {
- CacheService::clearToken($token);
- throw new AuthException('登录已过期,请重新登录', 410001);
- }
- if (!$user || $user->uid != $tokenData['uid']) {
- CacheService::clearToken($token);
- throw new AuthException('登录状态有误,请重新登录', 410002);
- }
- $tokenData['type'] = $type;
- return compact('user', 'tokenData');
- }
- }
|