<?php


namespace App\Modules\OrangeSite\Services\CheckReport;


use App\Modules\OrangeSite\Services\OrangeSiteRechargeReportCheckContext;
use App\Modules\OrangeSite\Services\OrangeSiteReportSettingService;
use Closure;
use Log;

class RechargeAmountCheck
{
    /**
     * 判断金额回传区间
     * @param $context OrangeSiteRechargeReportCheckContext
     * @param Closure $next
     * @return mixed
     */
    public function handle($context, Closure $next)
    {
        $rechargeAmountRange = OrangeSiteReportSettingService::buildRechargeAmountRange($context->channelCallbackConfig);
        if (OrangeSiteReportSettingService::judgeRechargeAmountRange($context->order->price, $rechargeAmountRange)) {
            return $next($context);
        } else {
            Log::debug('[orangeSiteRechargeReport]充值金额不满足配置区间', [
                'orderPrice' => $context->order->price,
                'rechargeAmountRange' => $rechargeAmountRange,
                'traceInfo' => $context->traceContext->getTraceInfo()]);
            $context->result = [
                'type' => 'amount_filter',
                'firstReason' => 'RechargeAmountCheck',
                'result' => false,
                'content' => "订单金额:{$context->order->price}元不满足回传金额上下限[{$rechargeAmountRange['minStr']} - {$rechargeAmountRange['maxStr']}]",
            ];
            return $context;
        }
    }
}