国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

webman_admin 數據權限設置

不敗少龍

plugin/admin/app/model/Admin.php

<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;

/**
 * @property integer $id ID(主鍵)
 * @property string $username 用戶名
 * @property string $nickname 昵稱
 * @property string $password 密碼
 * @property string $avatar 頭像
 * @property string $email 郵箱
 * @property string $mobile 手機
 * @property string $created_at 創(chuàng)建時間
 * @property string $updated_at 更新時間
 * @property string $login_at 登錄時間
 * @property string $roles 角色
 * @property integer $status 狀態(tài) 0正常 1禁用
 */
class Admin extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_admins';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $appends=[
        'role_key'
    ];
     public function getRoleKeyAttribute($value): string
     {
         $role_key = "null";
         $user_id = $this->id;
         if ($user_id){
             $role_id = AdminRole::where('admin_id',$user_id)->value('role_id');
             if ($role_id){
                 $role_key = Role::where('id',$role_id)->value('role_key')??"null";
             }
         }
         return $role_key;
     }

}

plugin/admin/app/controller/Base.php

 /**
     * 數據限制
     * null 不做限制,任何管理員都可以查看該表的所有數據
     * auth 管理員能看到自己以及自己的子管理員插入的數據
     * personal 管理員只能看到自己插入的數據
     * @var string
     */
    protected $dataLimit = null;

    /**
     * 數據限制字段
     */
    protected $dataLimitField = 'admin_id';

    public function __construct()
    {
        $session = request()->session();
        $admin = $session->get('admin');
        if ($admin) {
            $this->dataLimit = $admin['role_key'];
        }
    }

在子類的構造函數中加上 parent::__construct();

例如:AdminController文件中

 /**
     * 構造函數
     * @return void
     */
    public function __construct()
    {
        $this->model = new Admin;
        parent::__construct();
    }

plugin/admin/app/controller/TableController.php 第685行

/**
     * 構造函數
     * @return void
     */
    public function __construct()
    {
        \$this->model = new $model_class;
        parent::__construct();
    }

字典表插入

INSERT INTO `saas_worker`.`wa_options`(`id`, `name`, `value`, `created_at`, `updated_at`, `admin_id`) VALUES (41, 'dict_data_permissions', '[{\"value\":\"null\",\"name\":\"全部數據\"},{\"value\":\"auth\",\"name\":\"自己以及自己的子管理員的數據\"},{\"value\":\"personal\",\"name\":\"自己的數據\"}]', '2024-06-18 14:44:26', '2024-06-18 15:12:36', NULL);

在需要的表中添加admin_id字段

demo文件地址

演示圖:

截圖
截圖

942 0 0
0個評論

不敗少龍

10184
積分
0
獲贊數
0
粉絲數
2018-08-17 加入
??