Przeglądaj źródła

pc权限,管理员,管理组

lizhen_gitee 8 miesięcy temu
rodzic
commit
962f1d62a2

+ 9 - 9
application/company/controller/auth/Admin.php

@@ -1,10 +1,10 @@
 <?php
 
-namespace app\admin\controller\auth;
+namespace app\company\controller\auth;
 
-use app\admin\model\AuthGroup;
-use app\admin\model\AuthGroupAccess;
-use app\common\controller\Backend;
+use app\company\model\AuthGroup;
+use app\company\model\AuthGroupAccess;
+use app\common\controller\Apic;
 use fast\Random;
 use fast\Tree;
 use think\Db;
@@ -16,11 +16,11 @@ use think\Validate;
  * @icon   fa fa-users
  * @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
  */
-class Admin extends Backend
+class Admin extends Apic
 {
 
     /**
-     * @var \app\admin\model\Admin
+     * @var \app\company\model\Admin
      */
     protected $model = null;
     protected $selectpageFields = 'id,username,nickname,avatar';
@@ -190,9 +190,9 @@ class Admin extends Backend
                     //这里需要针对username和email做唯一验证
                     $adminValidate = \think\Loader::validate('Admin');
                     $adminValidate->rule([
-                        'username' => 'require|regex:\w{3,30}|unique:admin,username,' . $row->id,
-                        'email'    => 'require|email|unique:admin,email,' . $row->id,
-                        'mobile'   => 'regex:1[3-9]\d{9}|unique:admin,mobile,' . $row->id,
+                        'username' => 'require|regex:\w{3,30}|unique:PcAdmin,username,' . $row->id,
+                        'email'    => 'require|email|unique:PcAdmin,email,' . $row->id,
+                        'mobile'   => 'regex:1[3-9]\d{9}|unique:PcAdmin,mobile,' . $row->id,
                         'password' => 'regex:\S{32}',
                     ]);
                     $result = $row->validate('Admin.edit')->save($params);

+ 5 - 5
application/company/controller/auth/Group.php

@@ -1,9 +1,9 @@
 <?php
 
-namespace app\admin\controller\auth;
+namespace app\company\controller\auth;
 
-use app\admin\model\AuthGroup;
-use app\common\controller\Backend;
+use app\company\model\AuthGroup;
+use app\common\controller\Apic;
 use fast\Tree;
 use think\Db;
 use think\Exception;
@@ -14,11 +14,11 @@ use think\Exception;
  * @icon   fa fa-group
  * @remark 角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别下级的角色组或管理员
  */
-class Group extends Backend
+class Group extends Apic
 {
 
     /**
-     * @var \app\admin\model\AuthGroup
+     * @var \app\company\model\AuthGroup
      */
     protected $model = null;
     //当前登录管理员所有子组别

+ 4 - 7
application/company/model/Admin.php

@@ -1,22 +1,19 @@
 <?php
 
-namespace app\admin\model;
+namespace app\company\model;
 
 use think\Model;
-use think\Session;
 
 class Admin extends Model
 {
-
+    // 表名
+    protected $table = 'pc_admin';
     // 开启自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
-    protected $hidden = [
-        'password',
-        'salt'
-    ];
+
 
     public static function init()
     {

+ 4 - 96
application/company/model/AdminLog.php

@@ -1,117 +1,25 @@
 <?php
 
-namespace app\admin\model;
+namespace app\company\model;
 
-use app\admin\library\Auth;
 use think\Model;
-use think\Loader;
 
 class AdminLog extends Model
 {
 
+    // 表名
+    protected $table = 'pc_admin_log';
     // 开启自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = '';
-    //自定义日志标题
-    protected static $title = '';
-    //自定义日志内容
-    protected static $content = '';
+
     //忽略的链接正则列表
     protected static $ignoreRegex = [
         '/^(.*)\/(selectpage|index)$/i',
     ];
 
-    public static function setTitle($title)
-    {
-        self::$title = $title;
-    }
-
-    public static function setContent($content)
-    {
-        self::$content = $content;
-    }
-
-    public static function setIgnoreRegex($regex = [])
-    {
-        $regex = is_array($regex) ? $regex : [$regex];
-        self::$ignoreRegex = array_merge(self::$ignoreRegex, $regex);
-    }
-
-    /**
-     * 记录日志
-     * @param string $title   日志标题
-     * @param string $content 日志内容
-     */
-    public static function record($title = '', $content = '')
-    {
-        $auth = Auth::instance();
-        $admin_id = $auth->isLogin() ? $auth->id : 0;
-        $username = $auth->isLogin() ? $auth->username : __('Unknown');
-
-        // 设置过滤函数
-        request()->filter('trim,strip_tags,htmlspecialchars');
-
-        $controllername = Loader::parseName(request()->controller());
-        $actionname = strtolower(request()->action());
-        $path = str_replace('.', '/', $controllername) . '/' . $actionname;
-        if (self::$ignoreRegex) {
-            foreach (self::$ignoreRegex as $index => $item) {
-                if (preg_match($item, $path)) {
-                    return;
-                }
-            }
-        }
-        $content = $content ?: self::$content;
-        if (!$content) {
-            $content = request()->param('') ?: file_get_contents("php://input");
-            $content = self::getPureContent($content);
-        }
-        $title = $title ?: self::$title;
-        if (!$title) {
-            $title = [];
-            $breadcrumb = Auth::instance()->getBreadcrumb($path);
-            foreach ($breadcrumb as $k => $v) {
-                $title[] = $v['title'];
-            }
-            $title = implode(' / ', $title);
-        }
-        self::create([
-            'title'     => $title,
-            'content'   => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,
-            'url'       => substr(xss_clean(strip_tags(request()->url())), 0, 1500),
-            'admin_id'  => $admin_id,
-            'username'  => $username,
-            'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
-            'ip'        => xss_clean(strip_tags(request()->ip()))
-        ]);
-    }
 
-    /**
-     * 获取已屏蔽关键信息的数据
-     * @param $content
-     * @return array
-     */
-    protected static function getPureContent($content)
-    {
-        if (!is_array($content)) {
-            return $content;
-        }
-        foreach ($content as $index => &$item) {
-            if (preg_match("/(password|salt|token)/i", $index)) {
-                $item = "***";
-            } else {
-                if (is_array($item)) {
-                    $item = self::getPureContent($item);
-                }
-            }
-        }
-        return $content;
-    }
 
-    public function admin()
-    {
-        return $this->belongsTo('Admin', 'admin_id')->setEagerlyType(0);
-    }
 }

+ 3 - 5
application/company/model/AuthGroup.php

@@ -1,21 +1,19 @@
 <?php
 
-namespace app\admin\model;
+namespace app\company\model;
 
 use think\Model;
 
 class AuthGroup extends Model
 {
 
+    // 表名
+    protected $table = 'pc_auth_group';
     // 开启自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
 
-    public function getNameAttr($value, $data)
-    {
-        return __($value);
-    }
 
 }

+ 3 - 2
application/company/model/AuthGroupAccess.php

@@ -1,10 +1,11 @@
 <?php
 
-namespace app\admin\model;
+namespace app\company\model;
 
 use think\Model;
 
 class AuthGroupAccess extends Model
 {
-    //
+    // 表名
+    protected $table = 'pc_auth_group_access';
 }

+ 3 - 45
application/company/model/AuthRule.php

@@ -1,62 +1,20 @@
 <?php
 
-namespace app\admin\model;
+namespace app\company\model;
 
-use think\Cache;
 use think\Model;
 
 class AuthRule extends Model
 {
 
+    // 表名
+    protected $table = 'pc_auth_rule';
     // 开启自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
-    // 数据自动完成字段
-    protected $insert = ['py', 'pinyin'];
-    protected $update = ['py', 'pinyin'];
-    // 拼音对象
-    protected static $pinyin = null;
 
-    protected static function init()
-    {
-        self::$pinyin = new \Overtrue\Pinyin\Pinyin('Overtrue\Pinyin\MemoryFileDictLoader');
 
-        self::beforeWrite(function ($row) {
-            if (isset($_POST['row']) && is_array($_POST['row']) && isset($_POST['row']['condition'])) {
-                $originRow = $_POST['row'];
-                $row['condition'] = $originRow['condition'] ?? '';
-            }
-        });
-        self::afterWrite(function ($row) {
-            Cache::rm('__menu__');
-        });
-    }
 
-    public function getTitleAttr($value, $data)
-    {
-        return __($value);
-    }
-
-    public function getMenutypeList()
-    {
-        return ['addtabs' => __('Addtabs'), 'dialog' => __('Dialog'), 'ajax' => __('Ajax'), 'blank' => __('Blank')];
-    }
-
-    public function setPyAttr($value, $data)
-    {
-        if (isset($data['title']) && $data['title']) {
-            return self::$pinyin->abbr(__($data['title']));
-        }
-        return '';
-    }
-
-    public function setPinyinAttr($value, $data)
-    {
-        if (isset($data['title']) && $data['title']) {
-            return self::$pinyin->permalink(__($data['title']), '');
-        }
-        return '';
-    }
 }

+ 4 - 4
application/company/validate/Admin.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\admin\validate;
+namespace app\company\validate;
 
 use think\Validate;
 
@@ -11,11 +11,11 @@ class Admin extends Validate
      * 验证规则
      */
     protected $rule = [
-        'username' => 'require|regex:\w{3,30}|unique:admin',
+        'username' => 'require|regex:\w{3,30}|unique:PcAdmin',
         'nickname' => 'require',
         'password' => 'require|regex:\S{32}',
-        'email'    => 'require|email|unique:admin,email',
-        'mobile'   => 'regex:1[3-9]\d{9}|unique:admin,mobile',
+        'email'    => 'require|email|unique:PcAdmin,email',
+        'mobile'   => 'regex:1[3-9]\d{9}|unique:PcAdmin,mobile',
     ];
 
     /**

+ 2 - 2
application/company/validate/AuthRule.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\admin\validate;
+namespace app\company\validate;
 
 use think\Validate;
 
@@ -16,7 +16,7 @@ class AuthRule extends Validate
      * 验证规则
      */
     protected $rule = [
-        'name'  => 'require|unique:AuthRule',
+        'name'  => 'require|unique:PcAuthRule',
         'title' => 'require',
     ];