BanksController.php 3.2 KB
<?php
/**
+----------------------------------------------------------------------------------------------------------------------
 * 控制层:系统-轮播图 控制类
+----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Admin\Controllers\System
 * @package   App\Admin\Controllers\System
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年2月21日15:21:47
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Admin\Controllers\System;

use App\Admin\Controllers\BaseController;
use App\Admin\Rewrite\Grid;
use App\Models\System\Bank;

/**
 * Class BanksController
 *
 * @category  App\Admin\Controllers\System
 * @package   App\Admin\Controllers\System
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年2月21日15:21:47
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class BanksController extends BaseController
{
    public function __construct(Bank $model)
    {
        // 资源显示的中名称
        $this ->title       = $model::OBJ_NAME_ZH;
        #可编辑
        $this->can_create    = true;
        #可编辑
        $this->can_view    = false;
        #可编辑
        $this->can_edit     = true;
        #可删除
        $this->can_delete   = false;
        // 执行父类构造方法
        parent::__construct($model);
    }

    /**
     * 为grid增加筛选条件
     *
     * @return Grid
     */
    public function renderGridFilter()
    {
        $this->grid->filter(function ($filter) {
            // 筛选条件默认展开
            $filter->expand();

            $filter->like('name', '名称');
//            $filter->like('mobile', '手机号');

            //4.去掉默认的搜索
            $filter->disableIdFilter();
        });

        return $this->grid;
    }

    /**
     * 设置默认查询条件
     * 增加数据权限的判断。步骤:
     * 1、判断用户是否是超级管理员,并判断用户的pid,如果pid为0 则为平台总用户,不进行数据权限的判断
     * 2、如果pid大于0 则为 平台子管理员,则需要进行数据权限的判断
     */
    public function setGridQuery()
    {
        parent::setGridQuery();
        $this->grid->model()->oldest('id');
    }


    /**
     * 渲染grid字段
     *
     * @return void
     */
    public function renderGridFields()
    {
        $this->gridRowNo();
        $this->gridTextField('name', '银行名称')
           ;
        $this->gridTextField('code', '银行编码');
        $this->gridDateField('created_at', '创建时间');
    }

    /**
     * 渲染表单字段
     *
     * @param Int $id 用户id
     *
     * @return void
     */
    public function renderFormFields($id)
    {
        $this->formTextField('name', '银行名称') ->creationRules(['required', "unique:banks,name,NULL,NULL,deleted_at,NULL"])
            ->updateRules(['required', "unique:banks,name,{{id}},id,deleted_at,NULL"]);
        $this->formTextField('code', '银行编码');
    }
}