<?php
/**
 * 钱和积分的表单验证器
 */
namespace app\ais\validate;
use think\Validate;

class Bank extends Validate{

    protected $rule = [
        'id'             => 'require|integer',
        'uid'            => 'require|integer',
        'money'          => 'require|moneys|>:0',
        'realmoney'      => 'require|float',
        'safepassword'   => 'require',
        'phone_id'       => 'require|mobile',
        'sms_code'       => 'require|min:4|max:6',
        'ispass'         => 'require|integer|egt:0|elt:1',
    ];

    protected $message = [
        'id'               => '配置ID丢失',
        'uid'              => '未找到对应用户',
        'money.require'    => '金额必须填写',
        'money.moneys'     => '金额输入错误,禁止大于10万',
        'money.gt'         => '金额必须大于0',
        'realmoney'        => '实际到账必须填写',
        'safepassword'     => '安全验证密码没有输入',
        'phone_id.require' => '手机号必须填写',
        'phone_id.mobile'  => '手机号输入格式错误',
        'sms_code'         => '验证码填写不正确',
        'ispass'           => '是否通过必须选择',
    ];

    protected $scene = [
        'cash'      => ['id','ispass','realmoney'],    //后台提现审核
        'cash_out'  => ['money','safepassword'], //提现申请
    ];

    //人民币验证
    protected function moneys($value){
        $rule = '/^(0|[1-9]\d{0,4})(\.\d{1,2})?$/';
        $rel = preg_match($rule, $value);
        return $rel ? true : false;
    }
}