feat : role
This commit is contained in:
@@ -59,10 +59,38 @@ class AdminMenu extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $url
|
||||
* @return array
|
||||
*/
|
||||
public function getAllIds()
|
||||
{
|
||||
return $this
|
||||
->where('status', AuthCode::MENU_STATUS_ENABLE)
|
||||
->orderBy('sort', 'desc')
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
* @return array|false
|
||||
*/
|
||||
public function getRoleMenu($ids): array|false
|
||||
{
|
||||
$res = $this
|
||||
->where('status', AuthCode::MENU_STATUS_ENABLE)
|
||||
->whereIn('id',$ids)
|
||||
->orderBy('sort', 'desc')
|
||||
->get();
|
||||
if (empty($res)) return false;
|
||||
|
||||
return $res->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return Builder|\Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function getMenuByUrl(int $url): \Hyperf\Database\Model\Model|Builder|null
|
||||
public function getMenuByUrl(string $url): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this
|
||||
->where('url', $url)
|
||||
@@ -73,7 +101,7 @@ class AdminMenu extends Model
|
||||
* @param int $id
|
||||
* @return HigherOrderTapProxy|mixed|null
|
||||
*/
|
||||
public function getChildMenuType(int $id)
|
||||
public function getChildMenuType(int $id): mixed
|
||||
{
|
||||
return $this->where('parent_id', $id)->value('type');
|
||||
}
|
||||
|
||||
39
app/Model/AdminRoleMenu.php
Normal file
39
app/Model/AdminRoleMenu.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $role_id
|
||||
* @property int $menu_id
|
||||
*/
|
||||
class AdminRoleMenu extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'admin_role_menu';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['role_id' => 'integer', 'menu_id' => 'integer'];
|
||||
|
||||
/**
|
||||
* 获取角色菜单列表
|
||||
* @param int $roleId
|
||||
* @return array
|
||||
*/
|
||||
public function getMenuByRoleId(int $roleId): array
|
||||
{
|
||||
return $this->where('role_id', $roleId)->pluck('menu_id')->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user