1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class User extends Validate{
- protected $rule = [
- 'account|账号' => 'require|alphaNum|unique:user|length:3,16',
- 'password|原始密码' => 'require',
- 'newPassword|新密码' => 'require|alphaNum|length:6,16|different:password',
- 'phone|手机号' => 'require|checkPhone',
- 'name|姓名' => 'require',
- 'company_id' => 'require|egt:0',
- ];
- protected $message = [
- 'account.unique' => '账号已被占用',
- 'account.length' => '账号长度必须在3-16之间',
- 'newPassword.length' => '新密码长度必须在6-16之间',
- 'newPassword.different' => '新密码与原密码不能一样',
- 'company_id.require' => '未选择公司'
- ];
- protected $scene = [
- 'account' => ['account'],
- 'modifypass' => ['password','newPassword'],
- 'add' => ['phone','name','company_id']
- ];
- // 自定义验证规则
- protected function checkPhone($value,$rule,$data=[])
- {
- if(!check_mobile($value)){
- return '手机号格式不正确';
- }
- $info = Db::name('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;
- }
- }
|