123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class BudgetPay extends Validate{
- protected $rule = [
- 'money' => 'require|gt:0',
- 'dep_id' => 'require|gt:0',
- 'bdid' => 'require|gt:0|checkItems',
- ];
- protected $message = [
- 'bdid.require' => '未选择预算项目',
- 'bdid.gt' => '未选择预算项目',
- 'money.require' => '预算金额未填写',
- 'money.gt' => '预算金额必须大于0',
- 'dep_id.require' => '参数错误',
- 'dep_id.gt' => '参数错误',
- ];
- protected $scene = [
- 'type1' => ['money','dep_id','bdid'],
- 'type2' => ['money','dep_id'],
- ];
- protected function checkItems($value,$rule,$data=[])
- {
- $bdinfo = Db::name('budget_dep')->where('id',$data['bdid'])->find();
- if(!$bdinfo){
- return '预算项记录不存在';
- }
- if($bdinfo['dep_id'] != $data['dep_id']){
- return '预算部门与预算项不一致';
- }
- if($bdinfo['real_money'] < $data['money']){
- return '预算剩余小于支出金额';
- }
- // 检查部门是否有未处理的请款单
- if($data['id'] == 0){
- $info = Db::name('budget_pay')
- ->where('del',0)
- ->where('status',0)
- ->where('type',1) // 预算内
- ->where('apply_status','<>',2)
- ->where('dep_id',$data['dep_id'])
- ->where('bdid',$data['bdid'])
- ->find();
- if($info){
- return '该部门有未处理的请款单';
- }
- }
- return true;
- }
- }
|