1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- declare (strict_types = 1);
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class QualityCate extends Validate
- {
-
- protected $rule = [
- 'title|名称' => 'require|length:1,20|checkUnique',
- ];
-
- protected $message = [
- ];
- protected function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('quality_cate')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->where('pid',$data['pid'])
- ->where('id','<>',$data['id'])
- ->find();
- }else{
- $ret = Db::name('quality_cate')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->where('pid',$data['pid'])
- ->find();
- }
- return $ret?'名称已被使用':true;
- }
- }
|