DailyForm.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\common\validate;
  4. use think\Db;
  5. use think\Validate;
  6. class DailyForm extends Validate
  7. {
  8. /**
  9. * 定义验证规则
  10. * 格式:'字段名' => ['规则1','规则2'...]
  11. *
  12. * @var array
  13. */
  14. protected $rule = [
  15. 'content|工作项名称' => 'require|length:1,20|checkUnique',
  16. ];
  17. /**
  18. * 定义错误信息
  19. * 格式:'字段名.规则名' => '错误信息'
  20. *
  21. * @var array
  22. */
  23. protected $message = [
  24. ];
  25. protected function checkUnique($value, $rule, $data=[]){
  26. if(isset($data['id']) && $data['id'] > 0){
  27. $ret = Db::name('daily_form')
  28. ->where('del',0)
  29. ->where('content',$data['content'])
  30. ->where('org_id',$data['org_id'])
  31. ->where('id','<>',$data['id'])
  32. ->find();
  33. }else{
  34. $ret = Db::name('daily_form')
  35. ->where('del',0)
  36. ->where('content',$data['content'])
  37. ->where('org_id',$data['org_id'])
  38. ->find();
  39. }
  40. return $ret?'名称已被使用':true;
  41. }
  42. }