浏览代码

修改用户权限关联

邹景立 3 年之前
父节点
当前提交
b4b43ceff2
共有 3 个文件被更改,包括 18 次插入17 次删除
  1. 0 7
      app/admin/controller/Oplog.php
  2. 6 10
      app/admin/controller/User.php
  3. 12 0
      app/admin/model/SystemUser.php

+ 0 - 7
app/admin/controller/Oplog.php

@@ -33,13 +33,6 @@ use think\exception\HttpResponseException;
  */
 class Oplog extends Controller
 {
-
-    /**
-     * 绑定数据表
-     * @var string
-     */
-    private $table = 'SystemOplog';
-
     /**
      * 系统日志管理
      * @auth true

+ 6 - 10
app/admin/controller/User.php

@@ -25,6 +25,7 @@ use think\admin\service\AdminService;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
+use think\model\Relation;
 
 /**
  * 系统用户管理
@@ -44,7 +45,11 @@ class User extends Controller
     public function index()
     {
         $this->type = input('get.type', 'index');
-        $this->_query(SystemUser::class)->layTable(function () {
+        $this->_query(SystemUser::mk()->with([
+            'userinfo' => function (Relation $relation) {
+                $relation->field('code,name,content');
+            },
+        ]))->layTable(function () {
             $this->title = '系统用户管理';
             $this->bases = SystemBase::mk()->items('身份权限');
         }, function (QueryHelper $query) {
@@ -61,15 +66,6 @@ class User extends Controller
     }
 
     /**
-     * 数据列表处理
-     * @param array $data
-     */
-    protected function _page_filter(array &$data)
-    {
-        SystemBase::mk()->items('身份权限', $data, 'usertype', 'userinfo');
-    }
-
-    /**
      * 添加系统用户
      * @auth true
      * @throws DataNotFoundException

+ 12 - 0
app/admin/model/SystemUser.php

@@ -17,6 +17,7 @@
 namespace app\admin\model;
 
 use think\admin\Model;
+use think\model\relation\HasOne;
 
 /**
  * 系统用户模型
@@ -59,6 +60,17 @@ class SystemUser extends Model
     }
 
     /**
+     * 关联身份权限
+     * @return HasOne
+     */
+    public function userinfo(): HasOne
+    {
+        return $this->hasOne(SystemBase::class, 'code', 'usertype')->where([
+            'type' => '身份权限', 'status' => 1, 'deleted' => 0,
+        ]);
+    }
+
+    /**
      * 格式化登录时间
      * @param string $value
      * @return string