Org.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class Org extends Validate{
  6. protected $rule = [
  7. 'name|名称' => 'require|length:1,100',
  8. 'level' => 'require',
  9. 'parent_id' => 'require|gt:0',
  10. 'account|机构管理员账号' => 'require|length:1,16|checkUnique',
  11. ];
  12. protected $message = [
  13. 'name.length' => '名称必须100字以内',
  14. 'level.require' => '参数错误',
  15. 'parent_id.require' => '参数错误',
  16. 'parent_id.gt' => '参数错误',
  17. 'account.length' => '机构管理员账号1-16位'
  18. ];
  19. protected $scene = [
  20. 'add' => ['name','level','parent_id','account'],
  21. 'edit' => ['name','level','parent_id']
  22. ];
  23. // 自定义验证规则
  24. protected function checkUnique($value,$rule,$data=[])
  25. {
  26. $info = Db::name('user')->where('account',$data['account'])->where('del',0)->find();
  27. if($info){
  28. return '机构管理员账号已被使用';
  29. }
  30. return true;
  31. }
  32. }