You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
244 lines
6.1 KiB
244 lines
6.1 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
// 应用公共文件
|
|
|
|
/**
|
|
* 敏感词过滤
|
|
*
|
|
* @param string
|
|
* @return string
|
|
*/
|
|
function sensitive_words_filter($str)
|
|
{
|
|
header('content-type:text/html;charset=utf-8');
|
|
if (!$str) return '';
|
|
$file = ROOT_PATH . 'public/static/plug/censorwords/CensorWords';
|
|
$words = file($file);
|
|
foreach ($words as $word) {
|
|
$word = str_replace(array("\r\n", "\r", "\n", " "), '', $word);
|
|
if (!$word) continue;
|
|
$ret = @preg_match("/$word/", $str, $match);
|
|
if ($ret) {
|
|
return $match[0];
|
|
}
|
|
}
|
|
return '';
|
|
}
|
|
|
|
function getController()
|
|
{
|
|
return strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', think\Request::instance()->controller()));
|
|
}
|
|
|
|
function getNewOrderId($title){
|
|
/*
|
|
* Time - 42 bits
|
|
*/
|
|
$time = floor(microtime(true) * 1000);
|
|
/*
|
|
* Substract custom epoch from current time
|
|
*/
|
|
$time -= 1479533469598;
|
|
/*
|
|
* Create a base and add time to it
|
|
*/
|
|
$base = decbin(1099511627775 + $time);
|
|
/*
|
|
* Configured machine id - 10 bits - up to 1024 machines
|
|
*/
|
|
$machineid = str_pad(decbin(1), 10, "0", STR_PAD_LEFT);
|
|
/*
|
|
* sequence number - 12 bits - up to 4096 random numbers per machine
|
|
*/
|
|
$random = str_pad(decbin(mt_rand(0,4095)), 12, "0", STR_PAD_LEFT);
|
|
/*
|
|
* Pack
|
|
*/
|
|
$base = $base.$machineid.$random;
|
|
/*
|
|
* Return unique time id no
|
|
*/
|
|
return $title . bindec($base);
|
|
|
|
}
|
|
function getModule()
|
|
{
|
|
return strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', think\Request::instance()->module()));
|
|
}
|
|
|
|
function processingData($browse_count)
|
|
{
|
|
if ($browse_count > 9999) {
|
|
$browse_count = bcdiv($browse_count, 10000, 1) . 'W';
|
|
}
|
|
return $browse_count;
|
|
}
|
|
|
|
/**
|
|
* 获取图片库链接地址
|
|
* @param $key
|
|
* @return string
|
|
*/
|
|
function get_image_Url($key)
|
|
{
|
|
return think\Url::build('admin/widget.images/index', ['fodder' => $key]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取链接对应的key
|
|
* @param $value
|
|
* @param bool $returnType
|
|
* @param string $rep
|
|
* @return array|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
function get_key_attr($value, $returnType = true, $rep = '')
|
|
{
|
|
if (!$value) return '';
|
|
$inif = \app\admin\model\system\SystemAttachment::where('att_dir', $value)->find();
|
|
if ($inif) {
|
|
return [
|
|
'key' => $inif->name,
|
|
'pic' => $value,
|
|
];
|
|
} else {
|
|
if ($returnType) {
|
|
return [
|
|
'key' => '',
|
|
'pic' => $value,
|
|
];
|
|
} else {
|
|
return [
|
|
'key' => '',
|
|
'pic' => '',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取系统配置内容
|
|
* @param $name
|
|
* @param string $default
|
|
* @return string
|
|
*/
|
|
function get_config_content($name, $default = '')
|
|
{
|
|
try {
|
|
return \app\admin\model\system\SystemConfigContent::getValue($name);
|
|
} catch (\Throwable $e) {
|
|
return $default;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 打印日志
|
|
* @param $name
|
|
* @param $data
|
|
* @param int $type
|
|
*/
|
|
function live_log($name, $data, $type = 8)
|
|
{
|
|
file_put_contents($name . '.txt', '[' . date('Y-m-d H:i:s', time()) . ']' . print_r($data, true) . "\r\n", $type);
|
|
}
|
|
|
|
/**获取当前登录用户的角色信息
|
|
* @return mixed
|
|
*/
|
|
function get_login_role()
|
|
{
|
|
$role['role_id'] = \think\Session::get("adminInfo")['roles'];
|
|
$role['role_sign'] = \think\Session::get("adminInfo")['role_sign'];
|
|
return $role;
|
|
}
|
|
|
|
/**获取登录用户账户信息
|
|
* @return mixed
|
|
*/
|
|
function get_login_id()
|
|
{
|
|
$admin['admin_id'] = \think\Session::get("adminId");
|
|
return $admin;
|
|
}
|
|
|
|
|
|
function money_rate_num($money, $type)
|
|
{
|
|
if (!$money) $money = 0;
|
|
if (!$type) return \service\JsonService::fail('非法参数2');
|
|
switch ($type) {
|
|
case "gold":
|
|
$goldRate = \service\SystemConfigService::get("gold_rate");
|
|
$num = bcmul($money, $goldRate, 0);
|
|
return $num;
|
|
default:
|
|
return \service\JsonService::fail('汇率类型缺失');
|
|
|
|
}
|
|
}
|
|
|
|
function getUrlToDomain()
|
|
{
|
|
$site_url = \service\SystemConfigService::get('site_url');
|
|
if ($site_url == '') $site_url = $_SERVER['PHP_SELF'];
|
|
$arr = parse_url($site_url);
|
|
if (!isset($arr['host'])) $arr['host'] = $arr['path'];
|
|
$array = explode('.', $arr['host']);
|
|
return implode('_', $array);
|
|
}
|
|
|
|
if (!function_exists('filter_emoji')) {
|
|
|
|
// 过滤掉emoji表情
|
|
function filter_emoji($str)
|
|
{
|
|
$str = preg_replace_callback( //执行一个正则表达式搜索并且使用一个回调进行替换
|
|
'/./u',
|
|
function (array $match) {
|
|
return strlen($match[0]) >= 4 ? '' : $match[0];
|
|
},
|
|
$str);
|
|
return $str;
|
|
}
|
|
}
|
|
|
|
function lightTypeNmae($light_type)
|
|
{
|
|
switch ($light_type) {
|
|
case 1:
|
|
$type = '图文';
|
|
break;
|
|
case 2:
|
|
$type = '音频';
|
|
break;
|
|
case 3:
|
|
$type = '视频';
|
|
break;
|
|
}
|
|
return $type;
|
|
}
|
|
|
|
//读取版本号
|
|
function getversion()
|
|
{
|
|
$version_arr = [];
|
|
$curent_version = @file(dirname(__DIR__) . '/.version');
|
|
foreach ($curent_version as $val) {
|
|
list($k, $v) = explode('=', $val);
|
|
$version_arr[$k] = trim($v);
|
|
}
|
|
return $version_arr;
|
|
}
|
|
|