This commit is contained in:
pomjay
2025-06-25 09:35:09 +08:00
parent 81a95f47a0
commit 7e3eba92e2
16 changed files with 154 additions and 44 deletions

View File

@ -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');
}

View File

@ -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));

View File

@ -28,7 +28,7 @@ class FollowHistoryModel extends ApiBaseModel
*/
function addFollowHistory($method, $uid, $follow_uid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
if(!in_array($method,self::METHOD)) throw new ModelException('method error');
if(!array_key_exists($method,self::METHOD)) throw new ModelException('method error');
$aItem['method'] = $method;
$aItem['uid'] = $uid;
$aItem['follow_uid'] = $follow_uid;