This commit is contained in:
2023-12-21 22:01:33 +08:00
parent 439bb4afd1
commit 4d44f0206c
14 changed files with 506 additions and 20 deletions

View File

@ -6,6 +6,7 @@ use App\Const\RedisConst;
use App\Models\Base\CustomerBaseModel;
use App\Service\AuthService;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
@ -45,17 +46,43 @@ class CustomerUser extends CustomerBaseModel
return Hash::check($sPasswd,$oUser->password);
}
function addUser($aItem): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
function addUser($aItem): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
// if(isset($aItem['password']) && !empty($aItem['password'])) $aItem['password'] = Hash::make($aItem['password']);
$sDateTime = Carbon::now()->toDateTimeString();
$aItem['created_at'] = $sDateTime;
$aItem['updated_at'] = $sDateTime;
return $this->addItem($aItem);
}
function findItemByUsername($sUsername,$col=['*']): \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
function findItemByAccount($aData,$col=['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
if(!empty($aData['username'])){
return $this->findItemByUsername($aData['username'],$col);
}
if(!empty($aData['phone_area']) && !empty($aData['phone'])){
return $this->findItemByPhone($aData['phone_area'],$aData['phone'],$col);
}
if(!empty($aData['email'])){
return $this->findItemByEmail($aData['email'],$col);
}
return null;
}
function findItemByUsername($sUsername,$col=['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
return $this->newQuery()->where('username',$sUsername)->first($col);
}
function findItemByPhone($sPhoneArea,$sPhone,$col=['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
return $this->newQuery()->where('phone_area',$sPhoneArea)->where('phone',$sPhone)->first($col);
}
function findItemByEmail($sEmail,$col=['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
return $this->newQuery()->where('email',$sEmail)->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){
@ -63,6 +90,16 @@ class CustomerUser extends CustomerBaseModel
});
}
// function setUserInfo($iUid,$sNickname): bool|int
// {
// return $this->updateItem([
// 'id' => $iUid,
// 'nickname' => $sNickname,
// 'email' => $sNickname,
// 'phone_area' => $sNickname,
// ]);
// }
}