Budget.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class Budget extends Validate{
  6. protected $rule = [
  7. 'title|标题' => 'require',
  8. 'year|年份' => 'require|checkUnique',
  9. 'start_time' => 'require|date',
  10. 'end_time' => 'require|date',
  11. 'items' => 'require',
  12. 'auths' => 'require',
  13. ];
  14. protected $message = [
  15. 'year.require' => '未选择年份',
  16. 'start_time.require' => '未选择日期',
  17. 'start_time.date' => '未选择日期',
  18. 'end_time.require' => '未选择日期',
  19. 'end_time.date' => '未选择日期',
  20. 'items.require' => '未选择预算项目',
  21. 'auths.require' => '未选择接收部门',
  22. ];
  23. protected $scene = [
  24. ];
  25. protected function checkUnique($value,$rule,$data=[])
  26. {
  27. $info = Db::name('budget')->where('year',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
  28. if($data['id'] <= 0 && $info){
  29. return '该年份已有记录';
  30. }
  31. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  32. return '该年份已有记录';
  33. }
  34. return true;
  35. }
  36. }