love_php/app/Models/EmailMessage.php

48 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class EmailMessage extends Model
{
public $fillable = [];
public $guarded = [];
/**
* 检测验证码
* @param $email
* @param $code
* @return false|string
*/
public static function checkCode($email, $code)
{
if(!$code){
return '请填写验证码';
}
//测试用万能验证码
// if(/*config('app.debug') && */ $code=='999999' && env('APP_ENV') != 'production'){
if( env('APP_ENV') != 'production' && $code=='999999'){
self::where('email', $email)->limit(1)->orderBy('id', 'desc')->update(['confirmed'=>1]);
return false;
}
$record = self::where(['email'=>$email, 'code'=>$code])/*->orderBy('id', 'desc')*/->first();
if(empty($record)){
return '验证码有误';
}
if($record->created_at->timestamp < (time()-10*60)){
return '验证码过期';
}
if($record->confirmed){
return '验证码已使用';
}
self::where('id', $record->id)->update(['confirmed'=>1]);
return false;
}
}