From 1592f13ff5632ae84d68610733947772c832301a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 4 Jan 2022 14:08:03 +0800 Subject: [PATCH] Update --- app/Models/User.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index d703d361..0663f99f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -25,6 +25,7 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac public const STATUS_FROZEN = -1; // 冻结 public const STATUS_INACTIVATED = 0; // 未激活 public const STATUS_ACTIVE = 1; // 正常 + public const STATUS_DISABLED = 2; // 禁用 /** * @var array @@ -273,19 +274,17 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac /** * 禁用用户 * - * @param string|null $status_remarks + * @param string|null $statusRemark * @return void */ - public function disable(?string $status_remark = null) + public function disable(?string $statusRemark = null) { - $res = null; - if ($this->status == 1) {//只操作正常用户 - $this->status = 2; - $this->status_remark = $status_remark; - $res = $this->save(); + if ($this->status === static::STATUS_ACTIVE) { + $this->update([ + 'status' => static::STATUS_DISABLED, + 'status_remark' => $statusRemark, + ]); } - - return $res; } /** @@ -295,12 +294,12 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac */ public function enable() { - $res = null; - if ($this->status != 1) {// - $this->status = 1; - $res = $this->save(); + if ($this->status !== static::STATUS_ACTIVE) { + return $this->update([ + 'status' => static::STATUS_DISABLED, + 'status_remark' => null, + ]); } - return $res; } /**