<?php

namespace app\common\validate;

use think\Validate;
use app\common\model\Person as PersonModel;

class Person extends Validate {

    protected $rule = [
        'username' => 'require|max:50|unique:un_person',
        'password' => 'require',
        'name' => 'require|max:100',
        'idCard' => 'require|idCard|unique:un_person',
        'sex' => 'require',
        'phone' => 'require|mobile|unique:un_person',
        'verificationCode' => 'require'
    ];
    protected $message = [
        'username.require' => '请填写账号!',
        'username.max' => '账号最多50个字符!',
        'username.unique' => '该账号已被注册',
        'password.require' => '请填写密码!',
        'name.require' => '请输入姓名',
        'name.max' => '姓名最多100个字符!',
        'idCard.require' => '请填写身份证!',
        'idCard.idCard' => '请填写正确的身份证！',
        'idCard.unique' => '该身份证已存在',
        'sex.require' => '性别必须选择',
        'phone.require' => '请填写手机号',
        "phone.mobile" => "请填写正确的手机号",
        'phone.unique' => '该手机号已存在',
        'verificationCode.require' => '请输入手机验证码'
    ];

    protected function checkID($value,$rule,$data=[]){
        $info = PersonModel::where('idCard',$value)->where('active',1)->where('id','<>',$data['id'])->find();
        if($info){
            return "该身份证已存在";
        }else{
            return true;
        }
    }

}