原后台修改

This commit is contained in:
wanyongkang
2020-11-04 15:40:58 +08:00
parent b4e7f828d7
commit 0b433f8731
2 changed files with 70 additions and 57 deletions

View File

@@ -4,7 +4,7 @@ namespace fastphp;
//框架根目录 //框架根目录
//use function Composer\Autoload\includeFile; //use function Composer\Autoload\includeFile;
define('CORE_PATH',__DIR__); define('CORE_PATH', __DIR__);
/** /**
* fastphp框架核心 * fastphp框架核心
@@ -17,25 +17,31 @@ class Fastphp
public function __construct($config) public function __construct($config)
{ {
$this->config = $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; global $is_script;
spl_autoload_register(array($this,'loadClass')); spl_autoload_register(array($this, 'loadClass'));
$this->origin(); $this->origin();
$this->setReporting(); $this->setReporting();
$this->unregisterGlobals(); $this->unregisterGlobals();
$this->setDbConfig(); $this->setDbConfig();
if(!$is_script){ if (!$is_script) {
$this->route(); $this->route();
} else {
if (isset($_SERVER['SERVER_NAME'])) {
die;
}
} }
} }
//跨域请求处理 //跨域请求处理
public function origin(){ public function origin()
$allow_origin = $this->config['origin'];//跨域访问的时候才会存在此字段 {
$allow_origin = $this->config['origin']; //跨域访问的时候才会存在此字段
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : ''; $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
if (in_array($origin, $allow_origin)) { if (in_array($origin, $allow_origin)) {
header('Access-Control-Allow-Origin:' . $origin); header('Access-Control-Allow-Origin:' . $origin);
@@ -48,74 +54,78 @@ class Fastphp
} }
//路由处理 //路由处理
public function route(){ public function route()
{
$controllerName = $this->config['defaultController']; $controllerName = $this->config['defaultController'];
$actionName = $this->config['defaultAction']; $actionName = $this->config['defaultAction'];
$param = array(); $param = array();
$url = $_SERVER['REQUEST_URI']; $url = $_SERVER['REQUEST_URI'];
//清除?之后的内容 //清除?之后的内容
$position = strpos($url,'?'); $position = strpos($url, '?');
$url = $position === false?$url:substr($url,0,$position); $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); $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参数 //获取url参数
$param = $urlArray?$urlArray:array(); $param = $urlArray ? $urlArray : array();
} }
//判断控制器和操作是否存在 //判断控制器和操作是否存在
$controller = 'app\\'.$controllerName; $controller = 'app\\' . $controllerName;
if(!class_exists($controller)){ if (!class_exists($controller)) {
exit($controller.'控制器不存在!'); exit($controller . '控制器不存在!');
} }
if(!method_exists($controller,$actionName)){ if (!method_exists($controller, $actionName)) {
exit($actionName.'方法不存在!'); exit($actionName . '方法不存在!');
} }
//实例化控制器这个后续结合controller基类一起看 //实例化控制器这个后续结合controller基类一起看
$dispatch = new $controller($controllerName,$actionName); $dispatch = new $controller($controllerName, $actionName);
//以下等同于$dispatch->$actionName($param); //以下等同于$dispatch->$actionName($param);
call_user_func_array(array($dispatch,$actionName),$param); call_user_func_array(array($dispatch, $actionName), $param);
} }
//检测开发环境 //检测开发环境
public function setReporting(){ public function setReporting()
if(APP_DEBUG === true){ {
if (APP_DEBUG === true) {
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors','On'); ini_set('display_errors', 'On');
} else { } else {
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors','Off'); ini_set('display_errors', 'Off');
ini_set('log_errors','On'); ini_set('log_errors', 'On');
} }
} }
//删除敏感字符 //删除敏感字符
public function stripSlashesDeep($value){ public function stripSlashesDeep($value)
$value = is_array($value)?array_map(array($this,'stripSlashesDeep'),$value):stripSlashes($value); {
$value = is_array($value) ? array_map(array($this, 'stripSlashesDeep'), $value) : stripSlashes($value);
return $value; return $value;
} }
//检测自定义全局变量并移除 //检测自定义全局变量并移除
public function unregisterGlobals(){ public function unregisterGlobals()
if(ini_get('register_globals')){ {
$array = array('_SESSION','_POST','_GET','_COOKIE','_REQUEST','_SERVER','_ENV','_FILES'); if (ini_get('register_globals')) {
foreach ($array as $value){ $array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
foreach ($GLOBALS[$value] as $key=>$var){ foreach ($array as $value) {
if($var===$GLOBALS[$key]){ foreach ($GLOBALS[$value] as $key => $var) {
if ($var === $GLOBALS[$key]) {
unset($GLOBALS[$key]); unset($GLOBALS[$key]);
} }
} }
@@ -124,24 +134,26 @@ class Fastphp
} }
//配置数据库信息 //配置数据库信息
public function setDbConfig(){ public function setDbConfig()
if(isset($this->config['db'])){ {
define('DB_HOST',$this->config['db']['host']); if (isset($this->config['db'])) {
define('DB_PORT',$this->config['db']['port']); define('DB_HOST', $this->config['db']['host']);
define('DB_NAME',$this->config['db']['dbname']); define('DB_PORT', $this->config['db']['port']);
define('DB_USER',$this->config['db']['username']); define('DB_NAME', $this->config['db']['dbname']);
define('DB_PASS',$this->config['db']['password']); define('DB_USER', $this->config['db']['username']);
define('DB_PASS', $this->config['db']['password']);
} }
} }
//自动加载类 //自动加载类
public function loadClass($className){ public function loadClass($className)
$vendor = substr($className,0,strpos($className,'\\')); {
$vendor = substr($className, 0, strpos($className, '\\'));
$vendorDIR = $this->config['namespace'][$vendor]; $vendorDIR = $this->config['namespace'][$vendor];
$filePath = substr($className,strlen($vendor)).'.php'; $filePath = substr($className, strlen($vendor)) . '.php';
//包含应用文件 //包含应用文件
$file = strtr($vendorDIR.$filePath,'\\',DIRECTORY_SEPARATOR); $file = strtr($vendorDIR . $filePath, '\\', DIRECTORY_SEPARATOR);
if(!is_file($file)){ if (!is_file($file)) {
return; return;
} }

View File

@@ -5,7 +5,7 @@
* @Author: kangkang * @Author: kangkang
* @Date: 2020-10-03 18:23:43 * @Date: 2020-10-03 18:23:43
* @LastEditors: kangkang * @LastEditors: kangkang
* @LastEditTime: 2020-11-02 15:15:16 * @LastEditTime: 2020-11-03 15:05:26
*/ */
$is_script = 1; $is_script = 1;
include __DIR__ . '/../index.php'; 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); $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); $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['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); $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); $list['xianfeng'] = $yesterday_data['xianfeng'] - $xianfeng_rule_result['cost'] + $xianfeng_rule_result['refund'] + ($buyi_data['xianfeng'] ?? 0);
$jinrui_rule_result = jinrui($jinrui, $jinrui_refund); $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'); $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) function qx_rule($product, $refunds, $product_type = true)
{ {
$tian = $product_type ? 10 : 12; $tian = 12;
$cost = 0; $cost = 0;
foreach ($product as $package) { foreach ($product as $package) {
switch ($package['PackageName']) { switch ($package['PackageName']) {
@@ -289,8 +289,9 @@ function qx_rule($product, $refunds, $product_type = true)
return $count; return $count;
} }
//天天,老鹰退款规则 //天天,老鹰退款规则
function tl_rule($product, $refunds) function tl_rule($product, $refunds, $product_type = false)
{ {
$month = $product_type ? 40 : 30;
$cost = 0; $cost = 0;
foreach ($product as $package) { foreach ($product as $package) {
switch ($package['PackageName']) { switch ($package['PackageName']) {
@@ -338,10 +339,10 @@ function tl_rule($product, $refunds)
} }
break; break;
case '月卡': case '月卡':
if ((86400 * 30 - handle_time($info['RefundRestTime'])) < 1800) { if ((86400 * $month - handle_time($info['RefundRestTime'])) < 1800) {
$refund += $info['ConnectCount'] * 60; $refund += $info['ConnectCount'] * 60;
} else { } 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; break;
case '季卡': case '季卡':
@@ -464,7 +465,7 @@ function jinrui($product, $refunds)
} }
$refund = 0; $refund = 0;
foreach ($refunds as $info) { 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['cost'] = $cost;
$count['refund'] = $refund; $count['refund'] = $refund;