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

webman-admin管理員數(shù)據(jù)限制的方法

2494911084@qq.com

需求:

每個(gè)賬號(hào)只能管理自己的下級(jí)賬號(hào),admin賬號(hào)可以管理所有賬號(hào)的數(shù)據(jù)
功能模塊進(jìn)行數(shù)據(jù)限制僅添加人,以及添加人的上級(jí)賬號(hào)可以看到。
截圖

實(shí)現(xiàn)代碼寫的好垃圾,有沒(méi)有大哥感興趣順便幫幫小弟優(yōu)化一下。

實(shí)現(xiàn)

crudlimit 文件

<?php

namespace plugin\admin\app\controller;

use plugin\admin\app\model\Option;
use plugin\admin\app\model\Admin;
use plugin\admin\app\Util;
use support\Db;
use support\Model;
use support\Request;

trait Crudlimit
{

    use Crud;

    /**
     * @var Model
     */
    protected $model = null;

    protected $sonids = [];

    /**
     * 查詢
     *
     * @param Request $request
     * @return \support\Response
     */
    public function select(Request $request)
    {
        [$where, $format, $page_size, $field, $order] = $this->selectInput($request);

        $model = $this->model;

        // 數(shù)據(jù)限制
        $ids = $this->getAllSonAmdin(admin_id());
        $ids[] = admin_id();
        $model = $model->whereIn('admin_id', $ids);
        // 數(shù)據(jù)限制結(jié)束

        foreach ($where as $column => $value) {
            if (is_array($value)) {
                if (in_array($value[0], ['>', '=', '<', '<>'])) {
                    $model = $model->where($column, $value[0], $value[1]);
                } elseif ($value[0] == 'in') {
                    $model = $model->whereIn($column, $value[1]);
                } else {
                    $model = $model->whereBetween($column, $value);
                }
            } else {
                $model = $model->where($column, $value);
            }
        }
        $model = $model->orderBy($field, $order);
        if (in_array($format, ['select', 'tree', 'table_tree'])) {
            $items = $model->get();
            if ($format == 'select') {
                return $this->formatSelect($items);
            } elseif ($format == 'tree') {
                return $this->formatTree($items);
            }
            return $this->formatTableTree($items);
        }

        $paginator = $model->paginate($page_size);
        return $this->json(0, 'ok', [
            'items' => $paginator->items(),
            'total' => $paginator->total()
        ]);
    }

    // select下拉列表獲取下級(jí)所有賬戶
    public function getAdminSelect()
    {
        $ids = $this->getAllSonAmdin(admin_id());
        $ids[] = admin_id();
        $model = new Admin();
        $items = $model->whereIn('id', $ids)->get();
        return $this->formatSelect($items);
    }

    // 查詢所有下級(jí)賬戶ID
    public function getAllSonAmdin($id,$sonids = [])
    {
        $model = new Admin();
        $ids = $model->where('parent_id',$id)->where('id', '!=', $id)->pluck('id')->toArray();

        $sonids = array_merge($ids,$sonids);
        if ($ids) {
            foreach ($ids as $id) {
                $sonids = array_merge($sonids, $this->getAllSonAmdin($id));
            }
        } else {
            return $sonids;
        }

        return $sonids;
    }
}
1745 0 5
0個(gè)評(píng)論

年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表評(píng)論

2494911084@qq.com

-140
積分
0
獲贊數(shù)
0
粉絲數(shù)
2022-08-17 加入
??