123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Org extends Validate{
- protected $rule = [
- 'name|名称' => 'require|length:1,100',
- 'level' => 'require',
- 'parent_id' => 'require|gt:0',
- 'account|机构管理员账号' => 'require|length:1,16|checkUnique',
- ];
- protected $message = [
- 'name.length' => '名称必须100字以内',
- 'level.require' => '参数错误',
- 'parent_id.require' => '参数错误',
- 'parent_id.gt' => '参数错误',
- 'account.length' => '机构管理员账号1-16位'
- ];
- protected $scene = [
- 'add' => ['name','level','parent_id','account'],
- 'edit' => ['name','level','parent_id']
- ];
- // 自定义验证规则
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('user')->where('account',$data['account'])->where('del',0)->find();
- if($info){
- return '机构管理员账号已被使用';
- }
- return true;
- }
- }
|