feat : role

This commit is contained in:
2024-10-28 17:56:19 +08:00
parent c86c6c1baf
commit d6465b21d8
12 changed files with 485 additions and 90 deletions

View File

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

View 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();
}
}