<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 付款验证
 */
namespace app\ais\validate;
use think\Validate;

class Dopay extends Validate{

    protected $rule = [
        'member_miniapp_id' => 'require|number',
        'store_id'          => 'require|number',
        'user_couponr_id'   => 'integer',
        'money'             => 'require|moneys|>:0',
        'amount'            => 'require|float',
        'telphone'          => 'require|mobile',
    ];
    protected $message = [
        'member_miniapp_id' => '应用验证失败',
        'store_id'          => '店铺不存在',
        'user_couponr_id'   => '优惠券不存在',
        'money.require'     => '金额必须填写',
        'money.moneys'      => '金额输入错误,禁止大于10万',
        'money.gt'          => '金额必须大于0',
        'amount'            => '请输入支付金额',
        'telphone'          => '请输入正确的手机号',
    ];

    protected $scene = [
        'gopay'  => ['member_miniapp_id','store_id', 'user_couponr_id', 'money','amount'],
        'shop'   => ['telphone'],
    ];


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