feat : site
This commit is contained in:
77
app/Model/UserSite.php
Normal file
77
app/Model/UserSite.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\SiteCode;
|
||||
use Hyperf\Database\Concerns\BuildsQueries;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $site_id
|
||||
* @property int $user_id
|
||||
* @property int $is_default
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class UserSite extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'user_site';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
protected array $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'site_id' => 'integer', 'user_id' => 'integer', 'is_default' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'created_time';
|
||||
const string UPDATED_AT = 'updated_time';
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return UserSite|UserSite[]|Collection|\Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function getInfoById(int $id): Collection|\Hyperf\Database\Model\Model|UserSite|array|null
|
||||
{
|
||||
return $this->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return array
|
||||
*/
|
||||
public function getSiteIdsByUserId(int $userId): array
|
||||
{
|
||||
return $this->where('user_id', $userId)->pluck('site_id')->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return int
|
||||
*/
|
||||
public function getUserDefaultIdByUserId(int $userId): int
|
||||
{
|
||||
return $this->where('user_id', $userId)->where('is_default',SiteCode::USER_DEFAULT)->value('site_id') ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return BuildsQueries|Builder|\Hyperf\Database\Model\Model|object|null
|
||||
*/
|
||||
public function getUserNoDefaultIdByUserId(int $userId)
|
||||
{
|
||||
return $this->where('user_id', $userId)->where('is_default',SiteCode::USER_NO_DEFAULT)->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user