11
This commit is contained in:
@ -46,11 +46,27 @@ class CustomerUserExtendModel extends ApiBaseModel
|
||||
return $this->addItem($aItem);
|
||||
}
|
||||
|
||||
function initExtend($uid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
|
||||
{
|
||||
if (!$uid) throw new ModelException('uid error');
|
||||
if ($this->findItem($uid, ['uid'])) return null; //已存在
|
||||
|
||||
$sDateTime = date('Y-m-d H:i:s');
|
||||
$aItem = [
|
||||
'uid' => $uid,
|
||||
'is_active' => 1,
|
||||
'fans_num' => 0,
|
||||
'follow_num' => 0,
|
||||
'updated_at' => $sDateTime,
|
||||
];
|
||||
return $this->addItem($aItem);
|
||||
}
|
||||
|
||||
//增加当前粉丝总数
|
||||
function incrFansNum($uid): int
|
||||
{
|
||||
$oExtend = $this->findItem($uid, 'uid');
|
||||
if (!$oExtend) throw new ModelException('user extend not found');
|
||||
if (!$oExtend) $this->initExtend($uid);
|
||||
return $this->newQuery()->where('uid', $uid)->increment('fans_num');
|
||||
}
|
||||
|
||||
@ -58,7 +74,7 @@ class CustomerUserExtendModel extends ApiBaseModel
|
||||
function decrFansNum($uid): int
|
||||
{
|
||||
$oExtend = $this->findItem($uid, 'uid');
|
||||
if (!$oExtend) throw new ModelException('user extend not found');
|
||||
if (!$oExtend)$this->addExtend();
|
||||
return $this->newQuery()->where('uid', $uid)->decrement('fans_num');
|
||||
}
|
||||
|
||||
@ -66,7 +82,7 @@ class CustomerUserExtendModel extends ApiBaseModel
|
||||
function incrFollowNum($uid): int
|
||||
{
|
||||
$oExtend = $this->findItem($uid, 'uid');
|
||||
if (!$oExtend) throw new ModelException('user extend not found');
|
||||
if (!$oExtend) $this->initExtend($uid);
|
||||
return $this->newQuery()->where('uid', $uid)->increment('follow_num');
|
||||
}
|
||||
|
||||
@ -74,7 +90,7 @@ class CustomerUserExtendModel extends ApiBaseModel
|
||||
function decrFollowNum($uid): int
|
||||
{
|
||||
$oExtend = $this->findItem($uid, 'uid');
|
||||
if (!$oExtend) throw new ModelException('user extend not found');
|
||||
if (!$oExtend) $this->initExtend($uid);
|
||||
return $this->newQuery()->where('uid', $uid)->decrement('follow_num');
|
||||
}
|
||||
|
||||
|
||||
@ -109,12 +109,15 @@ class CustomerUserModel extends ApiBaseModel
|
||||
{
|
||||
$oTableCustomerUserCache = new TableCustomerUserCache();
|
||||
$oTableCustomerUserCache->setPrimaryKey($iUid);
|
||||
|
||||
return $oTableCustomerUserCache->getCacheData();
|
||||
// return Cache::remember($this->getCacheKey($iUid), RedisConst::ORM_FIND_CACHE_SECOND, function () use ($iUid) {
|
||||
// return $this->findItem($iUid);
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
// function delItemFromCache($iUid): bool
|
||||
// {
|
||||
// return Cache::delete($this->getCacheKey($iUid));
|
||||
|
||||
Reference in New Issue
Block a user