12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class BudgetDep extends Validate{
- protected $rule = [
- 'money' => 'require|gt:0',
- 'dep_id' => 'require|gt:0',
- 'budget_id' => 'require|gt:0',
- 'items_id' => 'require|gt:0|checkItems',
- ];
- protected $message = [
- 'budget_id.require' => '未选择预算',
- 'budget_id.gt' => '未选择预算',
- 'items_id.require' => '未选择预算项目',
- 'items_id.gt' => '未选择预算项目',
- 'money.require' => '预算金额未填写',
- 'money.gt' => '预算金额必须大于0',
- 'dep_id.require' => '未选择部门',
- 'dep_id.gt' => '未选择部门',
- ];
- protected $scene = [
- ];
- protected function checkItems($value,$rule,$data=[])
- {
- // 检查是否在合法时间范围
- $info = Db::name('budget')
- ->where('id',$data['budget_id'])
- ->find();
- if(!$info||$info['del'] == 1){
- return '预算不存在';
- }
- $ret = Db::name('budget_dep')
- ->where('org_id',$data['org_id'])
- ->where('items_id',$data['items_id'])
- ->where('budget_id',$data['budget_id'])
- ->where('dep_id',$data['dep_id'])
- ->where('del',0)
- ->find();
- if($ret){
- return '该预算项目已存在,不可添加';
- }
- return true;
- }
- }
|