AdminMenuValidate.php
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\validate;
use think\Validate;
use think\Db;
class AdminMenuValidate extends Validate
{
protected $rule = [
'name' => 'require',
'app' => 'require',
'controller' => 'require',
'parent_id' => 'checkParentId',
'action' => 'require|unique:AdminMenu,app^controller^action',
];
protected $message = [
'name.require' => '名称不能为空',
'app.require' => '应用不能为空',
'parent_id' => '超过了4级',
'controller.require' => '名称不能为空',
'action.require' => '名称不能为空',
'action.unique' => '同样的记录已经存在!',
];
protected $scene = [
'add' => ['name', 'app', 'controller', 'action', 'parent_id'],
'edit' => ['name', 'app', 'controller', 'action', 'id', 'parent_id'],
];
// 自定义验证规则
protected function checkParentId($value)
{
$find = Db::name('AdminMenu')->where(["id" => $value])->value('parent_id');
if ($find) {
$find2 = Db::name('AdminMenu')->where(["id" => $find])->value('parent_id');
if ($find2) {
$find3 = Db::name('AdminMenu')->where(["id" => $find2])->value('parent_id');
if ($find3) {
return false;
}
}
}
return true;
}
}