Merge pull request 'zhangwei' (#153) from zhangwei into dev

Reviewed-on: #153
This commit is contained in:
weiz 2023-11-08 14:14:09 +08:00
commit edbf90498a

View File

@ -14,6 +14,8 @@
namespace app\api\controller;
use app\common\cache\UserTokenCache;
use app\common\model\Company;
use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
use app\api\logic\LoginLogic;
use app\api\logic\UserLogic;
@ -32,7 +34,7 @@ use app\common\service\FileService;
class LoginController extends BaseApiController
{
public array $notNeedLogin = ['register', 'account', 'logout', 'codeUrl', 'oaLogin', 'mnpLogin', 'getScanCode', 'scanLogin', 'shop_account'];
public array $notNeedLogin = ['register', 'account', 'logout', 'codeUrl', 'oaLogin', 'mnpLogin', 'getScanCode', 'scanLogin', 'shop_account','checkToken'];
/**
@ -255,4 +257,23 @@ class LoginController extends BaseApiController
LoginLogic::updateUser($params, $this->userId);
return $this->success('操作成功', [], 1, 1);
}
public function checkToken(): \think\response\Json
{
$token = $this->request->post('token');
if(empty($token)){
return $this->fail('参数错误');
}
$userInfo = (new UserTokenCache())->getUserInfo($token);
if(!$userInfo){
return $this->fail('token无效');
}
//获取公司信息
$company = Company::field('company_name,company_type')->where('id',$userInfo['company_id'])->findOrEmpty();
if(!$company->isEmpty()){
$userInfo['company_name'] = $company['company_name'];
$userInfo['company_type'] = $company['company_type'];
}
return $this->success('请求成功',$userInfo);
}
}