264 lines
7.9 KiB
PHP
264 lines
7.9 KiB
PHP
![]() |
<?php
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | Author: 流年 <liu21st@gmail.com>
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
|
|||
|
// 应用公共文件
|
|||
|
|
|||
|
|
|||
|
use think\facade\Config;
|
|||
|
|
|||
|
function get_mail_item_array($item_string)
|
|||
|
{
|
|||
|
$key = ['item_id', 'item_count'];
|
|||
|
foreach(explode('|', $item_string) as $vo) {
|
|||
|
$result[] = array_combine($key, explode(',', $vo));
|
|||
|
}
|
|||
|
return $result;
|
|||
|
}
|
|||
|
|
|||
|
function searchServerArray($server_id){
|
|||
|
$array = Config::get('game.server');
|
|||
|
foreach($array as $key=>$value){
|
|||
|
if($value['id']==$server_id){
|
|||
|
return ($array[$key]);
|
|||
|
} else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function array_string($array, $field)
|
|||
|
{
|
|||
|
$array = array_column($array,$field);
|
|||
|
$string = implode(',',$array);
|
|||
|
return $string;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if (!function_exists('get_role_agency_info')) {
|
|||
|
function get_role_agency_info(int $role_id)
|
|||
|
{
|
|||
|
$result = \think\Db::view(['qy_role' => 'role'], 'roleid,accountid')
|
|||
|
->view(['qy_account' => 'account'], 'accountid,account,invite', 'account.accountid=role.accountid')
|
|||
|
->view(['agency_admin_user' => 'agency'], 'username as agency_account,invite', 'agency.invite=account.invite')
|
|||
|
->where(['role.roleid' => $role_id])
|
|||
|
->find();
|
|||
|
return $result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (!function_exists('get_role_agency_account')) {
|
|||
|
function get_role_agency_account(int $role_id)
|
|||
|
{
|
|||
|
$result = \think\Db::view(['qy_role' => 'role'], 'roleid')
|
|||
|
->view(['qy_account' => 'account'], 'accountid', 'account.accountid=role.accountid')
|
|||
|
->view(['agency_admin_user' => 'agency'], 'username as agency_account', 'agency.invite=account.invite')
|
|||
|
->where(['role.roleid' => $role_id])
|
|||
|
->find();
|
|||
|
if (isset($result['agency_account'])) {
|
|||
|
return $result['agency_account'];;
|
|||
|
} else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (!function_exists('get_agency_info')) {
|
|||
|
function get_agency_info($agency_id) {
|
|||
|
$result = \think\Db::name('admin_user')->whereIn('id', $agency_id)->find();
|
|||
|
return $result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (!function_exists('mend_invite_length')) {
|
|||
|
function mend_invite_length($invite)
|
|||
|
{
|
|||
|
if (strlen($invite) != 5) {
|
|||
|
$result = str_pad($invite, 5, 0, STR_PAD_LEFT);
|
|||
|
} else {
|
|||
|
$result = $invite;
|
|||
|
}
|
|||
|
return $result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (!function_exists('get_middle_str')) {
|
|||
|
/**
|
|||
|
* 获取两个字符串中间的字符
|
|||
|
* @param $str
|
|||
|
* @param $leftStr
|
|||
|
* @param $rightStr
|
|||
|
* @return bool|string
|
|||
|
*/
|
|||
|
function get_middle_str($str, $leftStr, $rightStr)
|
|||
|
{
|
|||
|
$left = strpos($str, $leftStr);
|
|||
|
$right = strpos($str, $rightStr, $left);
|
|||
|
if ($right < $left || $left < 0) {
|
|||
|
return '';
|
|||
|
}
|
|||
|
return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (!function_exists('get_rand_str')) {
|
|||
|
/**
|
|||
|
* 生产随机数
|
|||
|
* @param integer $length 随机数长度
|
|||
|
* @param integer $style 产生随机数方法默认4
|
|||
|
* @return integer 返回根据规则产生的指定随机数
|
|||
|
* Author:修缘
|
|||
|
* 联系QQ:278896498
|
|||
|
* Date: 2021/12/24 4:20
|
|||
|
*/
|
|||
|
function get_rand_str($length = 5, $style = 5)
|
|||
|
{
|
|||
|
switch ($style) {
|
|||
|
case 1:
|
|||
|
$arr = range(0, 9);
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
$arr = array_merge(range('a', 'z'), range('A', 'Z'));
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
$arr = array_merge(range('a', 'z'), range(0, 9));
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
$arr = array_merge(range('A', 'Z'), range(0, 9));
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
$arr = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
$arr = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9), ['!', '@', '#', '$', '%', '^', '&', '*']);
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
$arr = array_merge(range('A', 'Z'));
|
|||
|
break;
|
|||
|
default:
|
|||
|
$arr = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9), ['!', '@', '#', '$', '%', '^', '&', '*']);
|
|||
|
}
|
|||
|
shuffle($arr);
|
|||
|
$sub_arr = array_slice($arr, 0, $length);
|
|||
|
return implode($sub_arr);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (!function_exists('format_size')) {
|
|||
|
/**
|
|||
|
* 格式化文件大小单位
|
|||
|
* @param $size
|
|||
|
* @param string $delimiter
|
|||
|
* @return string
|
|||
|
*/
|
|||
|
function format_size($size, $delimiter = '')
|
|||
|
{
|
|||
|
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
|
|||
|
for ($i = 0; $size >= 1024 && $i < 5; $i++) {
|
|||
|
$size /= 1024;
|
|||
|
}
|
|||
|
return round($size, 2) . $delimiter . $units[$i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (!function_exists('setting')) {
|
|||
|
/**
|
|||
|
* 设置相关助手函数
|
|||
|
* @param string $name
|
|||
|
* @param null $value
|
|||
|
* @return array|bool|mixed|null
|
|||
|
*/
|
|||
|
function setting($name = '', $value = null)
|
|||
|
{
|
|||
|
if ($value === null && is_string($name)) {
|
|||
|
//获取一级配置
|
|||
|
if ('.' === substr($name, -1)) {
|
|||
|
$result = Config::pull(substr($name, 0, -1));
|
|||
|
if (count($result) == 0) {
|
|||
|
//如果文件不存在,查找数据库
|
|||
|
$result = get_database_setting(substr($name, 0, -1));
|
|||
|
}
|
|||
|
|
|||
|
return $result;
|
|||
|
}
|
|||
|
//判断配置是否存在或读取配置
|
|||
|
if (0 === strpos($name, '?')) {
|
|||
|
$result = Config::has(substr($name, 1));
|
|||
|
if (!$result) {
|
|||
|
//如果配置不存在,查找数据库
|
|||
|
if ($name && false === strpos($name, '.')) {
|
|||
|
return [];
|
|||
|
}
|
|||
|
|
|||
|
if ('.' === substr($name, -1)) {
|
|||
|
|
|||
|
return get_database_setting(substr($name, 0, -1));
|
|||
|
}
|
|||
|
|
|||
|
$name = explode('.', $name);
|
|||
|
$name[0] = strtolower($name[0]);
|
|||
|
|
|||
|
$result = get_database_setting($name[0]);
|
|||
|
if ($result) {
|
|||
|
$config = $result;
|
|||
|
// 按.拆分成多维数组进行判断
|
|||
|
foreach ($name as $val) {
|
|||
|
if (isset($config[$val])) {
|
|||
|
$config = $config[$val];
|
|||
|
} else {
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return $config;
|
|||
|
|
|||
|
}
|
|||
|
return $result;
|
|||
|
}
|
|||
|
|
|||
|
return $result;
|
|||
|
}
|
|||
|
|
|||
|
$result = Config::get($name);
|
|||
|
if (!$result) {
|
|||
|
$result = get_database_setting($name);
|
|||
|
}
|
|||
|
return $result;
|
|||
|
}
|
|||
|
return Config::set($name, $value);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if (!function_exists('get_database_setting')) {
|
|||
|
function get_database_setting($name)
|
|||
|
{
|
|||
|
$result = [];
|
|||
|
$group = \app\common\model\SettingGroup::where('code', $name)->find();
|
|||
|
if ($group) {
|
|||
|
$result = [];
|
|||
|
foreach ($group->setting as $key => $setting) {
|
|||
|
$key_setting = [];
|
|||
|
foreach ($setting->content as $content) {
|
|||
|
$key_setting[$content['field']] = $content['content'];
|
|||
|
}
|
|||
|
$result[$setting->code] = $key_setting;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return $result;
|
|||
|
}
|
|||
|
}
|