12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class CleaningType extends Validate{
- /**
- * 定义验证规则
- * 格式:'字段名' => ['规则1','规则2'...]
- *
- * @var array
- */
- protected $rule = [
- 'title|名称' => 'require|length:1,10|checkTitle',
- ];
- /**
- * 定义错误信息R
- * 格式:'字段名.规则名' => '错误信息'
- *
- * @var array
- */
- protected $message = [
- 'title.length' => '名称必须10字以内',
- ];
- protected function checkTitle($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('cleaning_type')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('id','<>',$data['id'])
- ->where('org_id',$data['org_id'])
- ->find();
- }else{
- $ret = Db::name('cleaning_type')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->find();
- }
- return $ret?'名称已被使用':true;
- }
- }
|