StampDuty.php 906 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class StampDuty extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require|length:1,100|checkUnique',
  8. 'type|类型' => 'require|in:0,1,2',
  9. ];
  10. protected $message = [
  11. 'title.length' => '名称必须100字以内',
  12. 'type.require' => '未选择类型',
  13. 'type.in' => '类型错误'
  14. ];
  15. protected $scene = [
  16. ];
  17. // 自定义验证规则
  18. protected function checkUnique($value,$rule,$data=[])
  19. {
  20. $info = Db::name('stamp_duty')->where('title',$value)->where('org_id',$data['org_id'])->where('del',0)->find();
  21. if($data['id'] <= 0 && $info){
  22. return '名称已被使用';
  23. }
  24. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  25. return '名称已被使用';
  26. }
  27. return true;
  28. }
  29. }