Files
hyperf_service/app/Model/AdminMenu.php
2024-10-28 11:55:57 +08:00

81 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use App\Constants\Admin\AuthCode;
use Hyperf\Database\Model\Builder;
use Hyperf\DbConnection\Model\Model;
use Hyperf\Tappable\HigherOrderTapProxy;
/**
* @property int $id
* @property int $parent_id
* @property string $title
* @property string $icon
* @property int $type
* @property string $url
* @property string $value
* @property int $status
* @property int $sort
* @property string $create_time
* @property string $update_time
*/
class AdminMenu extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'admin_menu';
/**
* 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', 'parent_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'sort' => 'integer'];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
/**
* 获取所有
* @return array
*/
public function getAllMenu(): array
{
return $this
->where('status', AuthCode::MENU_STATUS_ENABLE)
->orderBy('sort', 'desc')
->get()
->toArray();
}
/**
* @param int $url
* @return Builder|\Hyperf\Database\Model\Model|null
*/
public function getMenuByUrl(int $url): \Hyperf\Database\Model\Model|Builder|null
{
return $this
->where('url', $url)
->first();
}
/**
* @param int $id
* @return HigherOrderTapProxy|mixed|null
*/
public function getChildMenuType(int $id)
{
return $this->where('parent_id', $id)->value('type');
}
}