| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | 
							- <?php
 
- namespace app\common\validate;
 
- use think\Db;
 
- use think\Validate;
 
- class User extends Validate{
 
-     protected $rule = [
 
-         'account|账号'  =>  'require|length:4,20|checkAccount',
 
-         'real_name|姓名' => 'require|length:1,20',
 
-         'mobile|手机号' => 'checkMobile',
 
-         'password|密码' => 'length:6,16|checkPassword',
 
-         'oldpass|旧密码' => 'require',
 
-         'pass|新密码' => 'require|length:6,16|different:oldpass',
 
-         'pass_confirm|重复新密码' => 'require|confirm:pass',
 
-         'depId' => 'require|gt:0',
 
-         'rolesId' => 'require|gt:0',
 
-     ];
 
-     protected $message = [
 
-         'account.length' => '账号长度必须在4-20字之间',
 
-         'password.length' => '密码长度必须在6-16字之间',
 
-         'depId.require' => '未选择部门',
 
-         'depId.gt' => '未选择部门',
 
-         'rolesId.require' => '未选择角色',
 
-         'rolesId.gt' => '未选择角色',
 
-     ];
 
-     protected $scene = [
 
-         'add' => ['account','real_name','mobile','password','depId','rolesId'],
 
-         'addCompany' => ['account','real_name','mobile','password','rolesId'],
 
-         'modifyPass' => ['oldpass','pass','newpass'],
 
-         'wxadd' => ['mobile','real_name','password'],
 
-         'wxedit' => ['real_name'],
 
-         'bachAdd' => ['account','real_name','mobile'],
 
-     ];
 
-     protected function checkAccount($value,$rule,$data=[])
 
-     {
 
-         $info = Db::name('user')->where('account',$value)->where('del',0)->find();
 
-         if($data['id'] <= 0 && $info){
 
-             return '账号已被使用';
 
-         }
 
-         if($info && $data['id'] > 0 && $info['id'] != $data['id']){
 
-             return '账号已被使用';
 
-         }
 
-         return true;
 
-     }
 
-     protected function checkMobile($value,$rule,$data=[])
 
-     {
 
-         if($value && !check_mobile($value)){
 
-             return '手机号格式不正确';
 
-         }
 
-         if($value){
 
-             $info = Db::name('user')->where('mobile',$value)->where('del',0)->find();
 
-             if($data['id'] <= 0 && $info){
 
-                 return '手机号已被使用';
 
-             }
 
-             if($info && $data['id'] > 0 && $info['id'] != $data['id']){
 
-                 return '手机号已被使用';
 
-             }
 
-         }
 
-         return true;
 
-     }
 
-     protected function checkPassword($value,$rule,$data=[])
 
-     {
 
-         if($data['id'] <= 0 && !$value){
 
-             return '未输入密码';
 
-         }
 
- //        $res = preg_match('/(?=.*?[A-Z])(?=.*[0-9])(?=.*[#@!~%^&*])[A-Z0-9#@!~%^&*]{6,16}/i', $value);
 
- //        if(!$res){
 
- //            return '密码必须有数字和字母并且包含‘~!@#$%^&*’符号';
 
- //        }
 
-         $res = preg_match('/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[A-Za-z0-9]{6,16}/', $value);
 
-         if(!$res){
 
-             return '密码必须有大小写字母和数字';
 
-         }
 
-         return true;
 
-     }
 
- }
 
 
  |