12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?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 '未输入密码';
- }
- return true;
- }
- }
|