12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
-
-
-
-
-
-
-
-
-
-
- namespace app\admin\model;
-
- use think\Db;
- use think\Exception;
- use think\Model;
-
-
- class AuthGroup extends Model
- {
- protected static $roleList = [];
-
- public static function init()
- {
- self::beforeDelete(function ($row) {
- if ($row->id == 1) {
- throw new Exception("超级管理员角色不能被删除!");
- }
- $admin = Db::name('Admin')->where('roleid', $row->id)->find();
- if ($admin) {
- throw new Exception("该角色下有管理员!");
- }
-
- $child = explode(',', self::getArrchildid($row->id));
- if (count($child) > 1) {
- throw new Exception("该角色下有子角色,请删除子角色才可以删除!");
- }
- });
- }
-
-
-
- public static function getArrchildid($id)
- {
- if (empty(self::$roleList)) {
- self::$roleList = self::order(["id" => "desc"])->column('*', 'id');
- }
- $arrchildid = $id;
- if (is_array(self::$roleList)) {
- foreach (self::$roleList as $k => $cat) {
- if ($cat['parentid'] && $k != $id && $cat['parentid'] == $id) {
- $arrchildid .= ',' . self::getArrchildid($k);
- }
- }
- }
- return $arrchildid;
- }
- }
|