1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Budget extends Validate{
- protected $rule = [
- 'title|标题' => 'require',
- 'year|年份' => 'require|checkUnique',
- 'start_time' => 'require|date',
- 'end_time' => 'require|date',
- 'items' => 'require',
- 'auths' => 'require',
- ];
- protected $message = [
- 'year.require' => '未选择年份',
- 'start_time.require' => '未选择日期',
- 'start_time.date' => '未选择日期',
- 'end_time.require' => '未选择日期',
- 'end_time.date' => '未选择日期',
- 'items.require' => '未选择预算项目',
- 'auths.require' => '未选择接收部门',
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('budget')->where('year',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
- if($data['id'] <= 0 && $info){
- return '该年份已有记录';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '该年份已有记录';
- }
- return true;
- }
- }
|