12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- declare (strict_types = 1);
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class GreenAddr extends Validate
- {
- /**
- * 定义验证规则
- * 格式:'字段名' => ['规则1','规则2'...]
- *
- * @var array
- */
- protected $rule = [
- 'title|地点名称' => 'require|length:1,20|checkUnique',
- 'img|图片' => 'require',
- 'content|简介' => 'require',
- ];
- /**
- * 定义错误信息
- * 格式:'字段名.规则名' => '错误信息'
- *
- * @var array
- */
- protected $message = [
- ];
- protected function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('green_addr')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->where('id','<>',$data['id'])
- ->find();
- }else{
- $ret = Db::name('green_addr')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->find();
- }
- return $ret?'名称已被使用':true;
- }
- }
|