创建模型
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\UserModel;
|
||||
use App\Models\AdminModel;
|
||||
use App\Service\common\JWTService;
|
||||
use App\Service\common\UtilsService;
|
||||
use Exception;
|
||||
@@ -32,17 +32,17 @@ class LoginService
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param $account
|
||||
* @param $phone
|
||||
* @param $password
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function login($account, $password): array
|
||||
public function login($phone, $password): array
|
||||
{
|
||||
$userModel = UserModel::with(['roles:id,name,value'])->where('account', $account)->first();
|
||||
$userModel = AdminModel::with(['roles:id,name,value'])->where('phone', $phone)->first();
|
||||
if (empty($userModel)) {
|
||||
UtilsService::getInstance()->errorThrow('用户或密码错误!');
|
||||
// return $this->register($account, $password);
|
||||
// return $this->register($phone, $password);
|
||||
}
|
||||
|
||||
if (!password_verify($password, $userModel->password)) {
|
||||
@@ -54,7 +54,7 @@ class LoginService
|
||||
if (!in_array(get_ip(), $ipTable)) {
|
||||
$ipTable[] = get_ip();
|
||||
}
|
||||
$update = UserModel::where('id', $userModel->id)->update([
|
||||
$update = AdminModel::where('id', $userModel->id)->update([
|
||||
'ip' => get_ip(),
|
||||
'ip_table' => json_encode($ipTable),
|
||||
'updated_at' => get_time()
|
||||
@@ -64,11 +64,11 @@ class LoginService
|
||||
UtilsService::getInstance()->errorThrow('更新失败!');
|
||||
}
|
||||
|
||||
$userModel = UserModel::where('id', $userModel->id)->first();
|
||||
$userModel = AdminModel::where('id', $userModel->id)->first();
|
||||
}
|
||||
$result = [
|
||||
'id' => $userModel->id,
|
||||
'account' => $userModel->account,
|
||||
'phone' => $userModel->phone,
|
||||
'nick_name' => $userModel->nick_name,
|
||||
'avatar' => $userModel->avatar,
|
||||
'email' => $userModel->email,
|
||||
@@ -84,22 +84,22 @@ class LoginService
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @param $account
|
||||
* @param $phone
|
||||
* @param $password
|
||||
* @param $email
|
||||
* @param $code
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register($account, $password, $email, $code): array
|
||||
public function register($phone, $password, $email, $code): array
|
||||
{
|
||||
$userModel = UserModel::where('account', $account)->first();
|
||||
$userModel = AdminModel::where('phone', $phone)->first();
|
||||
if ($userModel) {
|
||||
UtilsService::getInstance()->errorThrow('账号已被占用!');
|
||||
}
|
||||
|
||||
$createModel = UserModel::create([
|
||||
'account' => $account,
|
||||
$createModel = AdminModel::create([
|
||||
'phone' => $phone,
|
||||
'email' => $email,
|
||||
'password' => password_hash($password, PASSWORD_DEFAULT),
|
||||
'nick_name' => '新用户'. Str::random(),
|
||||
@@ -114,11 +114,11 @@ class LoginService
|
||||
UtilsService::getInstance()->errorThrow('注册失败!');
|
||||
}
|
||||
|
||||
$userInfo = UserModel::with(['roles:id,name,value'])->where('id', $createModel->id)->first();
|
||||
$userInfo = AdminModel::with(['roles:id,name,value'])->where('id', $createModel->id)->first();
|
||||
|
||||
$result = [
|
||||
'id' => $userInfo->id,
|
||||
'account' => $userInfo->account,
|
||||
'phone' => $userInfo->phone,
|
||||
'nick_name' => $userInfo->nick_name,
|
||||
'avatar' => $userInfo->avatar,
|
||||
'email' => $userInfo->email?? '',
|
||||
|
||||
Reference in New Issue
Block a user