12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Roles extends Validate{
- protected $rule = [
- 'name|名称' => 'require',
- 'code|编码' => 'require|checkCode',
- ];
- protected $message = [
- ];
- protected $scene = [
- ];
- // 自定义验证规则
- protected function checkCode($value,$rule,$data=[])
- {
- $info = Db::name('roles')->where('code',$data['code'])->where('del',0)->find();
- if($data['id'] <= 0 && $info){
- return '编码已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '编码已被使用';
- }
- return true;
- }
- }
|