0
0

Roles.php 875 B

123456789101112131415161718192021222324252627282930313233343536
  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|length:1,50|checkTitle',
  8. 'parent_id|类型' => 'require|gt:0',
  9. ];
  10. protected $message = [
  11. 'name.length' => '名称必须50字以内',
  12. 'parent_id.require' => '未选择类型',
  13. 'parent_id.gt' => '未选择类型',
  14. ];
  15. protected $scene = [
  16. ];
  17. protected function checkTitle($value,$rule,$data=[])
  18. {
  19. $info = Db::name('roles')->where('name',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
  20. if($data['id'] <= 0 && $info){
  21. return '名称已被使用';
  22. }
  23. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  24. return '名称已被使用';
  25. }
  26. return true;
  27. }
  28. }