| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Models;
- use App\Services\Api\MemberService;
- use App\Services\Common\UserRoleService;
- use Earnp\GoogleAuthenticator\GoogleAuthenticator;
- use Earnp\GoogleAuthenticator\Librarys\GoogleAuthenticator as GoogleSecretAuthenticator;
- /**
- * 会员管理-模型
- * @author laravel开发员
- * @since 2020/11/10
- * Class AdminModel
- * @package App\Models
- */
- class UserModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'user';
- /**
- * 获取数据信息
- * @param int $id 用户ID
- * @return array|string
- * @author laravel开发员
- * @since 2020/11/10
- */
- public function getInfo($id)
- {
- $info = parent::getInfo($id); // TODO: Change the autogenerated stub
- if ($info) {
- // 头像
- if ($info['avatar']) {
- $info['avatar'] = get_image_url($info['avatar']);
- }
- // 性别
- if ($info['gender']) {
- $info['gender_name'] = config('admin.gender_list')[$info['gender']];
- }
- // 谷歌验证码处理
- $info['google_qrcode'] = '';
- $username = $info['username'];
- if(empty($info['google_key'])){
- $google = new GoogleSecretAuthenticator();
- $googleKey = $google->createSecret();//创建一个Secret
- $googleUrl="otpauth://totp/sbt@{$username}?secret=".$googleKey;//二维码中填充的内容
- if($googleKey && $googleUrl){
- UserModel::where(['id'=>$id])->update(['google_key'=> $googleKey,'update_time'=>time()]);
- $info['google_key'] = $googleKey;
- $info['google_qrcode'] = MemberService::make()->makeQrcode($googleUrl,'google',true);
- $info['google_qrcode'] = get_image_url($info['google_qrcode']);
- }
- }else{
- $googleUrl = "otpauth://totp/SBT@{$username}?secret={$info['google_key']}";
- $info['google_qrcode'] = MemberService::make()->makeQrcode($googleUrl,'google',true);
- $info['google_qrcode'] = get_image_url($info['google_qrcode']);
- }
- // 获取用户角色列表
- $userRoleService = new UserRoleService();
- $roleList = $userRoleService->getUserRoleList($id);
- $info['roles'] = $roleList;
- }
- return $info;
- }
- }
|