73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Customer;
|
|
|
|
use App\Exceptions\ModelException;
|
|
use App\Models\Base\CustomerBaseModel;
|
|
|
|
class CustomerUserExtendModel extends CustomerBaseModel
|
|
{
|
|
|
|
protected $table = 'customer_user_extend';
|
|
protected $primaryKey = 'uid';
|
|
|
|
protected $fillable = [
|
|
'uid',
|
|
'is_active',
|
|
'fans_num',
|
|
'follow_num',
|
|
'updated_at',
|
|
];
|
|
|
|
//是否活跃用户
|
|
const IS_ACTIVE_YES = 1;
|
|
const IS_ACTIVE_NO = 2;
|
|
const IS_ACTIVE = [
|
|
self::IS_ACTIVE_YES => '活跃',
|
|
self::IS_ACTIVE_NO => '不活跃',
|
|
];
|
|
|
|
//增加用户扩展信息
|
|
function addExtend($aItem): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
|
|
{
|
|
if(empty($aItem['uid'])) throw new ModelException('uid error');
|
|
if($this->findItem($aItem['uid'],['uid'])) return null; //已存在
|
|
$sDateTime = date('Y-m-d H:i:s');
|
|
$aItem['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');
|
|
return $this->newQuery()->where('uid',$uid)->increment('fans_num');
|
|
}
|
|
|
|
//减去当前追随者总数
|
|
function decrFansNum($uid): int
|
|
{
|
|
$oExtend = $this->findItem($uid,'uid');
|
|
if(!$oExtend) throw new ModelException('user extend not found');
|
|
return $this->newQuery()->where('uid',$uid)->decrement('fans_num');
|
|
}
|
|
|
|
//增加当前订阅总数
|
|
function incrFollowNum($uid): int
|
|
{
|
|
$oExtend = $this->findItem($uid,'uid');
|
|
if(!$oExtend) throw new ModelException('user extend not found');
|
|
return $this->newQuery()->where('uid',$uid)->increment('follow_num');
|
|
}
|
|
|
|
//减去当前订阅总数
|
|
function decrFollowNum($uid): int
|
|
{
|
|
$oExtend = $this->findItem($uid,'uid');
|
|
if(!$oExtend) throw new ModelException('user extend not found');
|
|
return $this->newQuery()->where('uid',$uid)->decrement('follow_num');
|
|
}
|
|
|
|
}
|