Daily.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. 'address_id|任务地点' => 'require|gt:0|checkUnique',
  17. 'enable|状态' => 'require',
  18. 'content|任务详情' => 'require',
  19. 'daily_form|工作项' => 'require',
  20. // 'roles|工作人员' => 'require',
  21. ];
  22. /**
  23. * 定义错误信息
  24. * 格式:'字段名.规则名' => '错误信息'
  25. *
  26. * @var array
  27. */
  28. protected $message = [
  29. ];
  30. protected function checkUnique($value, $rule, $data=[]){
  31. if(isset($data['id']) && $data['id'] > 0){
  32. $ret = Db::name('daily')
  33. ->where('del',0)
  34. ->where('address_id',$data['address_id'])
  35. ->where('org_id',$data['org_id'])
  36. ->where('id','<>',$data['id'])
  37. ->find();
  38. }else{
  39. $ret = Db::name('daily')
  40. ->where('del',0)
  41. ->where('address_id',$data['address_id'])
  42. ->where('org_id',$data['org_id'])
  43. ->find();
  44. }
  45. return $ret?'当前地点已被使用':true;
  46. }
  47. }