|
@@ -24,6 +24,15 @@ class User
|
|
|
$this->userObj = new UserModel();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户登录
|
|
|
+ * @param array $data
|
|
|
+ * @return array|bool
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
public function login(array $data)
|
|
|
{
|
|
|
$redisCode = cache(config('redis.code_pre') . $data['phoneNumber']);
|
|
@@ -83,4 +92,28 @@ class User
|
|
|
}
|
|
|
return $user->toArray();
|
|
|
}
|
|
|
+
|
|
|
+ public function getNormalUserByUsername(string $username): array
|
|
|
+ {
|
|
|
+ $user = $this->userObj->getUserByUsername($username);
|
|
|
+ if (!$user || $user->status !== config('status.mysql.table_normal')) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ return $user->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function update(int $id, array $data)
|
|
|
+ {
|
|
|
+ $user = $this->getNormalUserById($id);
|
|
|
+ if (!$user) {
|
|
|
+ throw new \think\Exception('不存在该用户');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查用户名是否存在
|
|
|
+ $userResult = $this->getNormalUserByUsername($data['username']);
|
|
|
+ if ($userResult && $userResult['id'] !== $id) {
|
|
|
+ throw new \think\Exception('该用户已经存在请重新设置');
|
|
|
+ }
|
|
|
+ return $this->userObj->updateById($id, $data);
|
|
|
+ }
|
|
|
}
|