login
This commit is contained in:
68
app/Models/Customer/CustomerUser.php
Normal file
68
app/Models/Customer/CustomerUser.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Customer;
|
||||
|
||||
use App\Const\RedisConst;
|
||||
use App\Models\Base\CustomerBaseModel;
|
||||
use App\Service\AuthService;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class CustomerUser extends CustomerBaseModel
|
||||
{
|
||||
protected $table = 'customer_users';
|
||||
protected $primaryKey = 'id';
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'status',
|
||||
'im_user_id',
|
||||
'country_name',
|
||||
'username',
|
||||
'password',
|
||||
'nickname',
|
||||
'email',
|
||||
'phone_area',
|
||||
'phone',
|
||||
'is_google_auth',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected function password(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: fn (string $value) => Hash::make($value),
|
||||
);
|
||||
}
|
||||
|
||||
function checkPasswd($iUid,$sPasswd):bool
|
||||
{
|
||||
$oUser = $this->where('id',$iUid)->first();
|
||||
if(empty($oUser)) return false;
|
||||
return Hash::check($sPasswd,$oUser->password);
|
||||
}
|
||||
|
||||
function addUser($aItem): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||
{
|
||||
// if(isset($aItem['password']) && !empty($aItem['password'])) $aItem['password'] = Hash::make($aItem['password']);
|
||||
return $this->addItem($aItem);
|
||||
}
|
||||
|
||||
function findItemByUsername($sUsername,$col=['*']): \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||
{
|
||||
return $this->newQuery()->where('username',$sUsername)->first($col);
|
||||
}
|
||||
|
||||
function findUserByUidWithCache($iUid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||
{
|
||||
return Cache::remember(RedisConst::ORM_CACHE_USER.$iUid,RedisConst::ORM_FIND_CACHE_SECOND,function ()use ($iUid){
|
||||
return $this->findItem($iUid);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user