'require|checkUnique', 'name|姓名' => 'require', 'password|密码' => 'require|length:6,16', 'company_id|单位' => 'require|gt:0', 'oldPass|旧密码' => 'require', 'pass|新密码' => 'require|length:6,16', ]; protected $message = [ ]; protected $scene = [ 'add' => ['phone','name','password','company_id'], 'edit' => ['phone','name','password|密码'=>'length:6,16','company_id'], 'modifyPass' => ['oldPass','pass'] ]; protected function checkUnique($value,$rule,$data=[]) { $info = Db::name('dinner_user') ->where('phone',$data['phone']) ->where('del',0) ->find(); if($data['id'] <= 0 && $info){ return '手机号已被使用'; } if($info && $data['id'] > 0 && $info['id'] != $data['id']){ return '手机号已被使用'; } return true; } }