<?php  namespace  App\Http\Requests\Shop;

use App\Http\Requests\BaseRequest;
use Illuminate\Validation\Rule;

/**
 * 账号管理
 *
 * */
class AdminUser extends BaseRequest{

    /**
     *
     * @return  array
     */
    public  function  rules(){
        // 编辑时排除ID 
        $id			= request('uid',0);
		// 非重规则
		$unique  	= Rule::unique('admin_shop')->where(function ($query) {
						return $query->where([['username','=',request('username','')]]);
					})->ignore($id,'uid');
        // 规则
        return [
            'username'         => ['required',$unique,'max:20'],
            'phone'            => ['required','phone'],
            'uid'              => 'required|integer|gt:0',
            'password'         => 'required|min:6|max:20|same:password_confirmation'
        ];
    }

    // 场景列表
    protected   $scenes         = [
		'add'  		            => ['username','phone'],
        'edit'  		        => ['uid','username','phone'],
        'get_detail'            => ['uid'],
        'set_status'  		    => ['uid'],
        'alter_password'  		=> ['password'],
	];

    /**
     *
     * @return  array
     */
    public  function  messages()    {
        return [
            'username.required'     => '请输入登录账号',
            'username.unique'       => '账号名已存在',
            'username.max'          => '登录账号最长20个字符',
            'phone.required'        => '请输入手机号',
            'phone.phone'           => '手机号格式有误',
            'uid.required'          => '账号ID不能为空',
            'uid.integer'   	    => '账号ID格式错误',
            'uid.gt'   		        => '账号ID格式错误',
            'password.required'     => '请输入密码',
            'password.min'          => '密码长度不能小于6位',
            'password.max'          => '密码长度不能大于16位',
            'password.same'         => '确认密码不一致',
        ];
    }

}
