BudgetPay.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class BudgetPay extends Validate{
  6. protected $rule = [
  7. 'money' => 'require|gt:0',
  8. 'dep_id' => 'require|gt:0',
  9. 'bdid' => 'require|gt:0|checkItems',
  10. ];
  11. protected $message = [
  12. 'bdid.require' => '未选择预算项目',
  13. 'bdid.gt' => '未选择预算项目',
  14. 'money.require' => '预算金额未填写',
  15. 'money.gt' => '预算金额必须大于0',
  16. 'dep_id.require' => '参数错误',
  17. 'dep_id.gt' => '参数错误',
  18. ];
  19. protected $scene = [
  20. 'type1' => ['money','dep_id','bdid'],
  21. 'type2' => ['money','dep_id'],
  22. ];
  23. protected function checkItems($value,$rule,$data=[])
  24. {
  25. $bdinfo = Db::name('budget_dep')->where('id',$data['bdid'])->find();
  26. if(!$bdinfo){
  27. return '预算项记录不存在';
  28. }
  29. if($bdinfo['dep_id'] != $data['dep_id']){
  30. return '预算部门与预算项不一致';
  31. }
  32. if($bdinfo['real_money'] < $data['money']){
  33. return '预算剩余小于支出金额';
  34. }
  35. // 检查部门是否有未处理的请款单
  36. if($data['id'] == 0){
  37. $info = Db::name('budget_pay')
  38. ->where('del',0)
  39. ->where('status',0)
  40. ->where('type',1) // 预算内
  41. ->where('apply_status','<>',2)
  42. ->where('dep_id',$data['dep_id'])
  43. ->where('bdid',$data['bdid'])
  44. ->find();
  45. if($info){
  46. return '该部门有未处理的请款单';
  47. }
  48. }
  49. return true;
  50. }
  51. }