vr-shopxo-source/application/common.php

1686 lines
47 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// 应用公共文件
/**
* 路径解析指定参数
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-08-06
* @desc description
* @param [string] $key [指定key]
* @param [mixed] $default [默认值]
* @param [string] $path [参数字符串 格式如: a/aa/b/bb/c/cc ]
*/
function PathToParams($key = null, $default = null, $path = '')
{
if(empty($path) && isset($_REQUEST['s']))
{
$path = $_REQUEST['s'];
}
if(!empty($path))
{
if(substr($path, 0, 1) == '/')
{
$path = mb_substr($path, 1, mb_strlen($path, 'utf-8')-1, 'utf-8');
}
$position = strrpos($path, '.');
if($position !== false)
{
$path = mb_substr($path, 0, $position, 'utf-8');
}
$arr = explode('/', $path);
$data = [];
$index = 0;
foreach($arr as $k=>$v)
{
if($index != $k)
{
$data[$arr[$index]] = $v;
$index = $k;
}
}
if($key !== null)
{
return array_key_exists($key, $data) ? $data[$key] : $default;
}
return $data;
}
return null;
}
/**
* 调用插件方法 - 访问为静态
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-07-10T22:03:48+0800
* @param [string] $plugins [插件名称]
* @param [string] $service [服务层名称]
* @param [string] $method [方法名称]
* @param [mixed] $params [参数]
*/
function CallPluginsServiceMethod($plugins, $service, $method, $params = null)
{
$plugins_class = 'app\plugins\\'.$plugins.'\service\\'.$service;
if(class_exists($plugins_class))
{
if(method_exists($plugins_class, $method))
{
return $plugins_class::$method($params);
} else {
return DataReturn('类方法未定义['.$plugins.'-'.$service.'-'.$method.']', -1);
}
}
return DataReturn('类未定义['.$plugins.'-'.$service.']', -1);
}
/**
* 判断当前是否小程序环境中
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-29T22:21:44+0800
*/
function MiniAppEnv()
{
if(!empty($_SERVER['HTTP_USER_AGENT']))
{
// 微信小程序 miniProgram
if(stripos($_SERVER['HTTP_USER_AGENT'], 'miniProgram') !== false)
{
return 'weixin';
}
// 支付宝客户端 AlipayClient
if(stripos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false)
{
return 'alipay';
}
// 百度小程序
if(stripos($_SERVER['HTTP_USER_AGENT'], 'swan-baiduboxapp') !== false)
{
return 'baidu';
}
}
return null;
}
/**
* RGB 转 十六进制
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-08T18:38:16+0800
* @param [string] $rgb [reg颜色值]
*/
function RgbToHex($rgb)
{
$regexp = "/^rgb\(([0-9]{0,3})\,\s*([0-9]{0,3})\,\s*([0-9]{0,3})\)/";
preg_match($regexp, $rgb, $match);
$re = array_shift($match);
$hex_color = "#";
$hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
for ($i = 0; $i < 3; $i++)
{
$r = null;
$c = $match[$i];
$hex_array = [];
while ($c > 16)
{
$r = $c % 16;
$c = ($c / 16) >> 0;
array_push($hex_array, $hex[$r]);
}
array_push($hex_array, $hex[$c]);
$ret = array_reverse($hex_array);
$item = implode('', $ret);
$item = str_pad($item, 2, '0', STR_PAD_LEFT);
$hex_color .= $item;
}
return $hex_color;
}
/**
* 十六进制 转 RGB
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-08T18:33:45+0800
* @param [string] $hex_color [十六进制颜色值]
*/
function HexToRgb($hex_color) {
$color = str_replace('#', '', $hex_color);
if(strlen($color) > 3)
{
$rgb = [
'r' => hexdec(substr($color, 0, 2)),
'g' => hexdec(substr($color, 2, 2)),
'b' => hexdec(substr($color, 4, 2))
];
} else {
$color = $hex_color;
$r = substr($color, 0, 1) . substr($color, 0, 1);
$g = substr($color, 1, 1) . substr($color, 1, 1);
$b = substr($color, 2, 1) . substr($color, 2, 1);
$rgb = [
'r' => hexdec($r),
'g' => hexdec($g),
'b' => hexdec($b)
];
}
return $rgb;
}
/**