<?php

namespace App\Http\Controllers\Manage\Finance;
use App\Http\Controllers\Manage\BaseController as ManageBaseController;
use Illuminate\Http\Request;

class BaseController extends ManageBaseController
{
    /**
     * 检测参数有没有为空的
     * @param Request $request
     * @param $params
     * @return bool
     */
    public static function checkParamValueEmpty(Request $request, $params) {
        $isCheck = false;
        foreach ($params as $keyName) {
            $value = $request->has($keyName) ? $request->input($keyName) : '';
            if(empty($value)) {
                $isCheck = true;
            }
        }
        return $isCheck;
    }

    /**
     * 检测参数有没有不是数字的
     * @param Request $request
     * @param $params
     * @return bool
     */
    public static function checkParamValueNumber(Request $request, $params) {
        $isCheck = false;
        foreach ($params as $keyName) {
            $value = $request->has($keyName) ? $request->input($keyName) : '';
            if(!is_numeric($value)) {
                $isCheck = true;
            }
        }
        return $isCheck;
    }

    /**
     * 获取当天最小时间
     * @param string $dayTime
     * @return mixed
     */
    public static function getMinDay($dayTime = '') {
        if(date('Y-m-d H:i:s', strtotime($dayTime))  == $dayTime) {
            $inputTime = strtotime($dayTime);
            $dayTime = date('Y-m-d', $inputTime);
        }

        //2018-01-01
        if(!empty($dayTime) && strlen(trim($dayTime)) == 8) {
            $inputTime = strtotime($dayTime);
            $dayTime = date('Y-m-d', $inputTime);
        }
        if(!empty($dayTime) && strlen(trim($dayTime)) == 10) {
            $dayTime = $dayTime." 00:00:00";
        }
        return $dayTime;
    }

    /**
     * 获取当天最大时间
     * @param string $dayTime
     * @return mixed
     */
    public static function getMaxDay($dayTime = '') {
        if(date('Y-m-d H:i:s', strtotime($dayTime))  == $dayTime) {
            $inputTime = strtotime($dayTime);
            $dayTime = date('Y-m-d', $inputTime);
        }

        //2018-01-01
        if(!empty($dayTime) && strlen(trim($dayTime)) == 8) {
            $inputTime = strtotime($dayTime);
            $dayTime = date('Y-m-d', $inputTime);
        }
        if(!empty($dayTime) && strlen(trim($dayTime)) == 10) {
            $dayTime = $dayTime." 23:59:59";
        }
        return $dayTime;
    }
}