diff --git a/fastphp/Fastphp.php b/fastphp/Fastphp.php index 550468f..af51cfb 100644 --- a/fastphp/Fastphp.php +++ b/fastphp/Fastphp.php @@ -4,7 +4,7 @@ namespace fastphp; //框架根目录 //use function Composer\Autoload\includeFile; -define('CORE_PATH',__DIR__); +define('CORE_PATH', __DIR__); /** * fastphp框架核心 @@ -17,26 +17,32 @@ class Fastphp public function __construct($config) { $this->config = $config; - require CORE_PATH.'/func/common.php'; + require CORE_PATH . '/func/common.php'; } //运行程序 - public function run(){ + public function run() + { global $is_script; - spl_autoload_register(array($this,'loadClass')); + spl_autoload_register(array($this, 'loadClass')); $this->origin(); $this->setReporting(); $this->unregisterGlobals(); $this->setDbConfig(); - if(!$is_script){ + if (!$is_script) { $this->route(); + } else { + if (isset($_SERVER['SERVER_NAME'])) { + die; + } } } //跨域请求处理 - public function origin(){ - $allow_origin = $this->config['origin'];//跨域访问的时候才会存在此字段 - $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : ''; + public function origin() + { + $allow_origin = $this->config['origin']; //跨域访问的时候才会存在此字段 + $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : ''; if (in_array($origin, $allow_origin)) { header('Access-Control-Allow-Origin:' . $origin); header("Access-Control-Allow-Methods: *"); @@ -48,74 +54,78 @@ class Fastphp } //路由处理 - public function route(){ + public function route() + { $controllerName = $this->config['defaultController']; $actionName = $this->config['defaultAction']; $param = array(); $url = $_SERVER['REQUEST_URI']; //清除?之后的内容 - $position = strpos($url,'?'); - $url = $position === false?$url:substr($url,0,$position); + $position = strpos($url, '?'); + $url = $position === false ? $url : substr($url, 0, $position); //删除前后的/ - $url = trim($url,'/'); + $url = trim($url, '/'); - if($url){ + if ($url) { //使用 / 分割 - $urlArray = explode('/',$url); + $urlArray = explode('/', $url); //删除空的数组元素 $urlArray = array_filter($urlArray); //获取控制器名 - $controllerName = array_shift($urlArray).'\\controller\\'.ucfirst(array_shift($urlArray)); + $controllerName = array_shift($urlArray) . '\\controller\\' . ucfirst(array_shift($urlArray)); //获取动作名 - $actionName = $urlArray?array_shift($urlArray):$actionName; + $actionName = $urlArray ? array_shift($urlArray) : $actionName; //获取url参数 - $param = $urlArray?$urlArray:array(); + $param = $urlArray ? $urlArray : array(); } //判断控制器和操作是否存在 - $controller = 'app\\'.$controllerName; - if(!class_exists($controller)){ - exit($controller.'控制器不存在!'); + $controller = 'app\\' . $controllerName; + if (!class_exists($controller)) { + exit($controller . '控制器不存在!'); } - if(!method_exists($controller,$actionName)){ - exit($actionName.'方法不存在!'); + if (!method_exists($controller, $actionName)) { + exit($actionName . '方法不存在!'); } //实例化控制器,这个后续结合controller基类一起看 - $dispatch = new $controller($controllerName,$actionName); + $dispatch = new $controller($controllerName, $actionName); //以下等同于$dispatch->$actionName($param); - call_user_func_array(array($dispatch,$actionName),$param); + call_user_func_array(array($dispatch, $actionName), $param); } //检测开发环境 - public function setReporting(){ - if(APP_DEBUG === true){ + public function setReporting() + { + if (APP_DEBUG === true) { error_reporting(E_ALL); - ini_set('display_errors','On'); + ini_set('display_errors', 'On'); } else { error_reporting(E_ALL); - ini_set('display_errors','Off'); - ini_set('log_errors','On'); + ini_set('display_errors', 'Off'); + ini_set('log_errors', 'On'); } } //删除敏感字符 - public function stripSlashesDeep($value){ - $value = is_array($value)?array_map(array($this,'stripSlashesDeep'),$value):stripSlashes($value); + public function stripSlashesDeep($value) + { + $value = is_array($value) ? array_map(array($this, 'stripSlashesDeep'), $value) : stripSlashes($value); return $value; } //检测自定义全局变量并移除 - public function unregisterGlobals(){ - if(ini_get('register_globals')){ - $array = array('_SESSION','_POST','_GET','_COOKIE','_REQUEST','_SERVER','_ENV','_FILES'); - foreach ($array as $value){ - foreach ($GLOBALS[$value] as $key=>$var){ - if($var===$GLOBALS[$key]){ + public function unregisterGlobals() + { + if (ini_get('register_globals')) { + $array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES'); + foreach ($array as $value) { + foreach ($GLOBALS[$value] as $key => $var) { + if ($var === $GLOBALS[$key]) { unset($GLOBALS[$key]); } } @@ -124,24 +134,26 @@ class Fastphp } //配置数据库信息 - public function setDbConfig(){ - if(isset($this->config['db'])){ - define('DB_HOST',$this->config['db']['host']); - define('DB_PORT',$this->config['db']['port']); - define('DB_NAME',$this->config['db']['dbname']); - define('DB_USER',$this->config['db']['username']); - define('DB_PASS',$this->config['db']['password']); + public function setDbConfig() + { + if (isset($this->config['db'])) { + define('DB_HOST', $this->config['db']['host']); + define('DB_PORT', $this->config['db']['port']); + define('DB_NAME', $this->config['db']['dbname']); + define('DB_USER', $this->config['db']['username']); + define('DB_PASS', $this->config['db']['password']); } } //自动加载类 - public function loadClass($className){ - $vendor = substr($className,0,strpos($className,'\\')); + public function loadClass($className) + { + $vendor = substr($className, 0, strpos($className, '\\')); $vendorDIR = $this->config['namespace'][$vendor]; - $filePath = substr($className,strlen($vendor)).'.php'; + $filePath = substr($className, strlen($vendor)) . '.php'; //包含应用文件 - $file = strtr($vendorDIR.$filePath,'\\',DIRECTORY_SEPARATOR); - if(!is_file($file)){ + $file = strtr($vendorDIR . $filePath, '\\', DIRECTORY_SEPARATOR); + if (!is_file($file)) { return; } diff --git a/script/finance_check_script.php b/script/finance_check_script.php index cf907fa..a4f3ace 100644 --- a/script/finance_check_script.php +++ b/script/finance_check_script.php @@ -5,7 +5,7 @@ * @Author: kangkang * @Date: 2020-10-03 18:23:43 * @LastEditors: kangkang - * @LastEditTime: 2020-11-02 15:15:16 + * @LastEditTime: 2020-11-03 15:05:26 */ $is_script = 1; include __DIR__ . '/../index.php'; @@ -158,7 +158,7 @@ $list['qiangzi'] = $yesterday_data['qiangzi'] - $qiangzi_rule_result['cost'] + $ $list['xunlian'] = $yesterday_data['xunlian'] - $xunlian_rule_result['cost'] + $xunlian_rule_result['refund'] + ($buyi_data['xunlian'] ?? 0); $tiantian_rule_result = tl_rule($tiantian, $tiantian_refund); -$laoying_rule_result = tl_rule($laoying, $laoying_refund); +$laoying_rule_result = tl_rule($laoying, $laoying_refund, true); $list['tiantian'] = $yesterday_data['tiantian'] - $tiantian_rule_result['cost'] + $tiantian_rule_result['refund'] + ($buyi_data['tiantian'] ?? 0); $list['laoying'] = $yesterday_data['laoying'] - $laoying_rule_result['cost'] + $laoying_rule_result['refund'] + ($buyi_data['laoying'] ?? 0); @@ -166,7 +166,7 @@ $xianfeng_rule_result = xianfeng($xianfeng, $xianfeng_refund); $list['xianfeng'] = $yesterday_data['xianfeng'] - $xianfeng_rule_result['cost'] + $xianfeng_rule_result['refund'] + ($buyi_data['xianfeng'] ?? 0); $jinrui_rule_result = jinrui($jinrui, $jinrui_refund); -$list['jinrui'] = $yesterday_data['jinrui'] - $jinrui_rule_result['cost'] + $xianfeng_rule_result['refund'] + ($buyi_data['jinrui'] ?? 0); +$list['jinrui'] = $yesterday_data['jinrui'] - $jinrui_rule_result['cost'] + $jinrui_rule_result['refund'] + ($buyi_data['jinrui'] ?? 0); $list['riqi'] = date('Y-m-d H:i:s'); @@ -228,7 +228,7 @@ function no_jike($product) //强子,讯连规则 function qx_rule($product, $refunds, $product_type = true) { - $tian = $product_type ? 10 : 12; + $tian = 12; $cost = 0; foreach ($product as $package) { switch ($package['PackageName']) { @@ -289,8 +289,9 @@ function qx_rule($product, $refunds, $product_type = true) return $count; } //天天,老鹰退款规则 -function tl_rule($product, $refunds) +function tl_rule($product, $refunds, $product_type = false) { + $month = $product_type ? 40 : 30; $cost = 0; foreach ($product as $package) { switch ($package['PackageName']) { @@ -338,10 +339,10 @@ function tl_rule($product, $refunds) } break; case '月卡': - if ((86400 * 30 - handle_time($info['RefundRestTime'])) < 1800) { + if ((86400 * $month - handle_time($info['RefundRestTime'])) < 1800) { $refund += $info['ConnectCount'] * 60; } else { - $refund += $info['ConnectCount'] * 60 - ceil((86400 * 30 - handle_time($info['RefundRestTime']))/86400) * $info['ConnectCount'] * 4; + $refund += $info['ConnectCount'] * 60 - ceil((86400 * $month - handle_time($info['RefundRestTime']))/86400) * $info['ConnectCount'] * 4; } break; case '季卡': @@ -464,7 +465,7 @@ function jinrui($product, $refunds) } $refund = 0; foreach ($refunds as $info) { - $refund += handle_time($info['RefundRestTime']) / 86400 * 2 * $info['ConnectCount']; + $refund += intval(handle_time($info['RefundRestTime']) / 86400) * 2 * $info['ConnectCount']; } $count['cost'] = $cost; $count['refund'] = $refund;