2025-03-13 09:24:48 +08:00

94 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use crmeb\basic\BaseController;
use think\facade\Validate;
/**
* 基类 所有控制器继承的类
* Class AuthController
* @package app\adminapi\controller
*/
class AuthController extends BaseController
{
/**
* 当前登陆管理员信息
* @var
*/
protected $adminInfo;
/**
* 当前登陆管理员ID
* @var
*/
protected $adminId;
/**
* 当前管理员权限
* @var array
*/
protected $auth = [];
/**
* 初始化
*/
protected function initialize()
{
$this->adminId = $this->request->adminId();//获取当前登陆管理员ID
$this->adminInfo = $this->request->adminInfo();//获取当前登陆管理员信息
$this->auth = $this->request->adminInfo['rule'] ?? [];//获取当前登陆管理员权限
}
/**
* 验证数据
* @param array $data
* @param $validate
* @param null $message
* @param bool $batch
* @return bool
*/
final protected function validate(array $data, $validate, $message = null, bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();//验证器
$v->rule($validate);//验证规则
} else {
if (strpos($validate, '.')) {// 支持场景
// 支持场景
list($validate, $scene) = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);//获取验证器类名
$v = new $class();//实例化验证器
if (!empty($scene)) {
$v->scene($scene);//验证场景
}
if (is_string($message) && empty($scene)) {
$v->scene($message);
}
}
if (is_array($message))
$v->message($message);
// 是否批量验证
if ($batch) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
}