12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class CleanPlan extends Validate{
- protected $rule = [
- 'title|名称' => 'require|length:1,200',
- 'year|年份' => 'require|checkYear',
- 'forms|任务项' => 'require',
- 'addrs|地点' => 'require',
- 'user|人员' => 'require',
- 'month|月份' => 'require|checkMonth',
- ];
- protected $message = [
- 'title.length' => '名称必须200字以内',
- ];
- protected $scene = [
- 'add' => ['title','year','forms','addrs','user'],
- 'madd' => ['month','forms','addrs','user']
- ];
- protected function checkYear($value, $rule, $data=[]){
- $info = Db::name('clean_plan')->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;
- }
- protected function checkMonth($value, $rule, $data=[]){
- if(!$data['pid']){
- return '参数错误';
- }
- $info = Db::name('clean_plan')->where('month',$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;
- }
- }
|