FCleanPlan.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class FCleanPlan extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require|length:1,200',
  8. 'year|年份' => 'require|checkYear',
  9. 'forms|任务项' => 'require',
  10. 'addrs|地点' => 'require',
  11. 'user|人员' => 'require',
  12. 'month|月份' => 'require|checkMonth',
  13. ];
  14. protected $message = [
  15. 'title.length' => '名称必须200字以内',
  16. ];
  17. protected $scene = [
  18. 'add' => ['title','year','forms','addrs','user'],
  19. 'madd' => ['month','forms','addrs','user']
  20. ];
  21. protected function checkYear($value, $rule, $data=[]){
  22. $info = Db::name('f_clean_plan')->where('year',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
  23. if($data['id'] <= 0 && $info){
  24. return '该年份已设置计划';
  25. }
  26. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  27. return '该年份已设置计划';
  28. }
  29. return true;
  30. }
  31. protected function checkMonth($value, $rule, $data=[]){
  32. if(!$data['pid']){
  33. return '参数错误';
  34. }
  35. $info = Db::name('f_clean_plan')->where('month',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
  36. if($data['id'] <= 0 && $info){
  37. return '该月份已设置计划';
  38. }
  39. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  40. return '该月份已设置计划';
  41. }
  42. return true;
  43. }
  44. }