123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\Model;
- use Illuminate\Support\Facades\DB;
- class Menu extends Model
- {
- /**
- * @var string
- */
- protected $table = 'base_menus';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- protected $casts = [
- 'meta' => 'json'
- ];
- const TYPE_MENU = 1;
- const TYPE_BTN = 2;
- public static function checkNameIsUnique($name, $ignore_id = 0)
- {
- return self::query()->where('name', $name)->where('type', self::TYPE_MENU)->where('id', '<>', $ignore_id)->exists();
- }
- public static function checkBtnPathIsUnique($path, $ignore_id = 0)
- {
- return self::query()->where('path', $path)->where('type', self::TYPE_BTN)->where('id', '<>', $ignore_id)->exists();
- }
- /**
- * 是否存在这个安全权限
- * @param $user_id
- * @param $btn_id
- * @return bool
- */
- public static function checkUserIsBtn($btn_id = 150, $admin_id = 0)
- {
- if (!$admin_id) $admin_id = login_admin_id();
- if (in_array($admin_id, config('site.superAdmin_ids', [1]))) return true;
- $roleIds = DB::table('base_roles_menus')->where('menu_id', $btn_id)->pluck('role_id');
- if (!count($roleIds)) return false;
- return DB::table('base_model_has_roles')->where('model_id', $admin_id)->whereIn('role_id', $roleIds)->exists();
- }
- }
|