Roles.php 708 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class Roles extends Validate{
  6. protected $rule = [
  7. 'name|名称' => 'require',
  8. 'code|编码' => 'require|checkCode',
  9. ];
  10. protected $message = [
  11. ];
  12. protected $scene = [
  13. ];
  14. // 自定义验证规则
  15. protected function checkCode($value,$rule,$data=[])
  16. {
  17. $info = Db::name('roles')->where('code',$data['code'])->where('del',0)->find();
  18. if($data['id'] <= 0 && $info){
  19. return '编码已被使用';
  20. }
  21. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  22. return '编码已被使用';
  23. }
  24. return true;
  25. }
  26. }