nk-lihaink-cn/app/admin/validate/GroupCheck.php

42 lines
1.0 KiB
PHP
Raw Normal View History

2021-01-30 20:59:12 +08:00
<?php
2021-07-26 17:41:59 +08:00
/**
* @copyright Copyright (c) 2021 勾股工作室
2021-11-24 17:17:29 +08:00
* @license https://opensource.org/licenses/Apache-2.0
2021-07-26 17:41:59 +08:00
* @link https://www.gougucms.com
*/
2021-01-30 20:59:12 +08:00
namespace app\admin\validate;
2021-07-26 17:41:59 +08:00
2021-01-30 20:59:12 +08:00
use think\Validate;
class GroupCheck extends Validate
{
protected $rule = [
2021-07-26 17:41:59 +08:00
'title' => 'require|unique:admin_group',
'id' => 'require',
'status' => 'require|checkStatus:-1,1',
2021-01-30 20:59:12 +08:00
];
protected $message = [
2021-07-26 17:41:59 +08:00
'title.require' => '名称不能为空',
'title.unique' => '同样的记录已经存在',
2021-07-26 17:41:59 +08:00
'id.require' => '缺少更新条件',
'status.require' => '状态为必选',
'status.checkStatus' => '系统所有者组不能被禁用',
2021-01-30 20:59:12 +08:00
];
protected $scene = [
2021-07-26 17:41:59 +08:00
'add' => ['title', 'status'],
2021-01-30 20:59:12 +08:00
'edit' => ['id', 'title', 'status'],
];
// 自定义验证规则
2021-07-26 17:41:59 +08:00
protected function checkStatus($value, $rule, $data)
2021-01-30 20:59:12 +08:00
{
2021-07-26 17:41:59 +08:00
if ($value == -1 and $data['id'] == 1) {
2021-01-30 20:59:12 +08:00
return $rule == false;
}
return $rule == true;
}
2021-07-26 17:41:59 +08:00
}