BudgetDep.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class BudgetDep extends Validate{
  6. protected $rule = [
  7. 'money' => 'require|gt:0',
  8. 'dep_id' => 'require|gt:0',
  9. 'budget_id' => 'require|gt:0',
  10. 'items_id' => 'require|gt:0|checkItems',
  11. ];
  12. protected $message = [
  13. 'budget_id.require' => '未选择预算',
  14. 'budget_id.gt' => '未选择预算',
  15. 'items_id.require' => '未选择预算项目',
  16. 'items_id.gt' => '未选择预算项目',
  17. 'money.require' => '预算金额未填写',
  18. 'money.gt' => '预算金额必须大于0',
  19. 'dep_id.require' => '未选择部门',
  20. 'dep_id.gt' => '未选择部门',
  21. ];
  22. protected $scene = [
  23. ];
  24. protected function checkItems($value,$rule,$data=[])
  25. {
  26. // 检查是否在合法时间范围
  27. $info = Db::name('budget')
  28. ->where('id',$data['budget_id'])
  29. ->find();
  30. if(!$info||$info['del'] == 1){
  31. return '预算不存在';
  32. }
  33. $ret = Db::name('budget_dep')
  34. ->where('org_id',$data['org_id'])
  35. ->where('items_id',$data['items_id'])
  36. ->where('budget_id',$data['budget_id'])
  37. ->where('dep_id',$data['dep_id'])
  38. ->where('del',0)
  39. ->find();
  40. if($ret){
  41. return '该预算项目已存在,不可添加';
  42. }
  43. return true;
  44. }
  45. }