Daily.php 1.3 KB

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