优化部分代码,增加微信公众号模板
This commit is contained in:
@@ -96,7 +96,17 @@ class AdminService extends BaseService
|
||||
{
|
||||
$params['ip_table'] = json_encode([]);
|
||||
$params['password'] = password_hash($params['password'], PASSWORD_DEFAULT);
|
||||
$existsUser = $this->model::where('phone', $params['phone'])->whereOr('email', $params['email'])->exists();
|
||||
// 手机号或邮箱任一重复都拒绝,且必须排除软删记录(deleted_at=0)。
|
||||
// 原写法 whereOr('email',...) 是 Laravel 动态 where 的空操作(等于只按 phone 判断且不排软删),
|
||||
// 这里用闭包 orWhere 正确表达「phone OR email」;email 为空时不参与判重,避免误伤空邮箱账号
|
||||
$email = $params['email'] ?? '';
|
||||
$existsUser = $this->model::where('deleted_at', 0)
|
||||
->where(function ($q) use ($params, $email) {
|
||||
$q->where('phone', $params['phone']);
|
||||
if ($email !== '') {
|
||||
$q->orWhere('email', $email);
|
||||
}
|
||||
})->exists();
|
||||
if ($existsUser) {
|
||||
$this->utils->errorThrow('账号或邮箱已存在');
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ class LoginService extends BaseNotAuthService
|
||||
$ua = UserAgentService::getInstance();
|
||||
$equipment = $ua->parseEquipment();
|
||||
$browser = $ua->parseBrowser();
|
||||
$userModel = AdminModel::with(['role:id,name,value'])->where('phone', $phone)->first();
|
||||
// 必须排除软删账号(deleted_at=0),否则被删管理员仍能用原密码登录
|
||||
$userModel = AdminModel::with(['role:id,name,value'])->where('phone', $phone)->where('deleted_at', 0)->first();
|
||||
if (empty($userModel)) {
|
||||
$this->writeLoginLog(0, (string) $phone, '', 1, '用户或密码错误', $equipment, $browser);
|
||||
UtilsService::getInstance()->errorThrow('用户或密码错误!');
|
||||
@@ -111,7 +112,7 @@ class LoginService extends BaseNotAuthService
|
||||
*/
|
||||
public function register($phone, $password, $email, $code): array
|
||||
{
|
||||
$userModel = AdminModel::where('phone', $phone)->first();
|
||||
$userModel = AdminModel::where('phone', $phone)->where('deleted_at', 0)->first();
|
||||
if ($userModel) {
|
||||
UtilsService::getInstance()->errorThrow('账号已被占用!');
|
||||
}
|
||||
|
||||
@@ -153,7 +153,10 @@ class RoleService extends BaseService
|
||||
*/
|
||||
public function delete($id): mixed
|
||||
{
|
||||
if (in_array($id, [1, 2])) {
|
||||
// BaseController::delete 传入的是 ids 数组,直接 in_array($id,[1,2]) 会因「数组与标量比较恒 false」绕过保护,
|
||||
// 这里统一归一为数组后用 array_intersect 判断是否命中内置角色(1超管 / 2默认)
|
||||
$ids = is_array($id) ? $id : [$id];
|
||||
if (array_intersect(array_map('intval', $ids), [1, 2])) {
|
||||
$this->utils->errorThrow('管理员角色禁止删除');
|
||||
}
|
||||
return $this->del($id);
|
||||
|
||||
Reference in New Issue
Block a user