diff --git a/beike/Repositories/VerifyCodeRepo.php b/beike/Repositories/VerifyCodeRepo.php index a6124526..fe8b97bc 100644 --- a/beike/Repositories/VerifyCodeRepo.php +++ b/beike/Repositories/VerifyCodeRepo.php @@ -41,6 +41,11 @@ class VerifyCodeRepo return VerifyCode::query()->where('account', $account)->first(); } + public static function deleteByAccount($account) + { + return VerifyCode::query()->where('account', $account)->delete(); + } + /** * @param $id * @return void diff --git a/beike/Shop/Services/AccountService.php b/beike/Shop/Services/AccountService.php index 2d2caa4d..d1b8061e 100644 --- a/beike/Shop/Services/AccountService.php +++ b/beike/Shop/Services/AccountService.php @@ -52,6 +52,7 @@ class AccountService public static function sendVerifyCodeForForgotten($email, $type) { $code = str_pad(mt_rand(10, 999999), 6, '0', STR_PAD_LEFT); + VerifyCodeRepo::deleteByAccount($email); VerifyCodeRepo::create([ 'account' => $email, 'code' => $code, @@ -90,6 +91,6 @@ class AccountService throw new \Exception("找回密码类型错误"); } CustomerRepo::update($customer, ['password' => $password]); - + $verifyCode->delete(); } }