mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
feat: 完成三方平台发布管理
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -14,50 +15,55 @@
|
||||
use app\model\Admin;
|
||||
use app\model\AdminPermission;
|
||||
use app\model\SystemConfig;
|
||||
use think\facade\Cache;
|
||||
use League\Flysystem\Util\MimeType;
|
||||
use think\File;
|
||||
use think\facade\Filesystem;
|
||||
use app\model\UploadFiles;
|
||||
use think\facade\Session;
|
||||
use League\Flysystem\Util\MimeType;
|
||||
use think\app\Url;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Filesystem;
|
||||
use think\facade\Session;
|
||||
use think\File;
|
||||
use think\Response;
|
||||
use think\response\Htmx;
|
||||
|
||||
function json_message($data = [], $code = 0, $msg = '')
|
||||
{
|
||||
if (is_string($data)) {
|
||||
|
||||
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
|
||||
$data = [
|
||||
'jump_to_url' => $data
|
||||
'jump_to_url' => $data,
|
||||
];
|
||||
} else {
|
||||
|
||||
$code = $code === 0 ? 500 : $code;
|
||||
$msg = $data;
|
||||
$data = [];
|
||||
}
|
||||
} else if ($data instanceof Url) {
|
||||
} elseif ($data instanceof Url) {
|
||||
$data = [
|
||||
'jump_to_url' => (string)$data
|
||||
'jump_to_url' => (string) $data,
|
||||
];
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
function htmx($data = '', $code = 200) : Htmx
|
||||
{
|
||||
return Response::create($data, 'htmx', $code);
|
||||
}
|
||||
|
||||
function get_system_config($name = '', $default = '')
|
||||
{
|
||||
$list = Cache::get('system_config');
|
||||
|
||||
if (empty($list)) {
|
||||
try {
|
||||
|
||||
$list = SystemConfig::column('value', 'name');
|
||||
Cache::set('system_config', $list);
|
||||
} catch (\Throwable $th) {
|
||||
} catch (Throwable $th) {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +81,6 @@ function get_system_config($name = '', $default = '')
|
||||
|
||||
function get_source_link($url)
|
||||
{
|
||||
|
||||
if (empty($url)) {
|
||||
$url = '/static/images/avatar.png';
|
||||
}
|
||||
@@ -90,6 +95,7 @@ function get_source_link($url)
|
||||
if (empty($resource_domain)) {
|
||||
$resource_domain = request()->domain();
|
||||
}
|
||||
|
||||
return $resource_domain . '/' . $url;
|
||||
}
|
||||
}
|
||||
@@ -100,12 +106,12 @@ function de_source_link($url)
|
||||
if (strpos($url, $domain) === 0) {
|
||||
return str_replace($domain, '', $url);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function save_url_file($url, $type)
|
||||
{
|
||||
|
||||
$file_data = geturl($url);
|
||||
|
||||
$mime_type = MimeType::detectByContent($file_data);
|
||||
@@ -130,16 +136,17 @@ function save_url_file($url, $type)
|
||||
$model_file->save_name = $save_name;
|
||||
$model_file->save();
|
||||
unlink($temp_file);
|
||||
|
||||
return $save_name;
|
||||
}
|
||||
|
||||
function geturl($url)
|
||||
{
|
||||
$headerArray = array();
|
||||
$headerArray = [];
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
$output = curl_exec($ch);
|
||||
@@ -148,48 +155,41 @@ function geturl($url)
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function posturl($url, $data)
|
||||
{
|
||||
$data = json_encode($data);
|
||||
$headerArray = array();
|
||||
$data = json_encode($data);
|
||||
$headerArray = [];
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function format_size($filesize)
|
||||
{
|
||||
|
||||
if ($filesize >= 1073741824) {
|
||||
|
||||
$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
|
||||
} elseif ($filesize >= 1048576) {
|
||||
|
||||
$filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
|
||||
} elseif ($filesize >= 1024) {
|
||||
|
||||
$filesize = round($filesize / 1024 * 100) / 100 . ' KB';
|
||||
} else {
|
||||
|
||||
$filesize = $filesize . ' 字节';
|
||||
}
|
||||
|
||||
return $filesize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 数组层级缩进转换
|
||||
* 数组层级缩进转换.
|
||||
* @param array $array 源数组
|
||||
* @param int $pid
|
||||
* @param int $level
|
||||
@@ -197,17 +197,16 @@ function format_size($filesize)
|
||||
*/
|
||||
function array2level($array, $pid = 0, $level = 1)
|
||||
{
|
||||
|
||||
static $list = [];
|
||||
if ($level == 0) {
|
||||
$list = [];
|
||||
$level = 1;
|
||||
}
|
||||
foreach ($array as $v) {
|
||||
if(!empty($v)) {
|
||||
if (!empty($v)) {
|
||||
if ($v['pid'] == $pid) {
|
||||
$v['level'] = $level;
|
||||
$list[] = $v;
|
||||
$list[] = $v;
|
||||
array2level($array, $v['id'], $level + 1);
|
||||
}
|
||||
}
|
||||
@@ -217,7 +216,6 @@ function array2level($array, $pid = 0, $level = 1)
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
function check_permission($key, $admin_id = null)
|
||||
{
|
||||
if (is_null($admin_id)) {
|
||||
@@ -238,7 +236,6 @@ function check_permission($key, $admin_id = null)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$cache_key = 'permission_' . $key;
|
||||
|
||||
$model_permission = Cache::get($cache_key);
|
||||
@@ -249,7 +246,7 @@ function check_permission($key, $admin_id = null)
|
||||
|
||||
if (empty($model_permission)) {
|
||||
$model_permission = AdminPermission::create([
|
||||
'key' => $key
|
||||
'key' => $key,
|
||||
]);
|
||||
Cache::set($cache_key, $model_permission, 60);
|
||||
}
|
||||
@@ -261,29 +258,24 @@ function check_permission($key, $admin_id = null)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多应用下的url生成器
|
||||
* 在这里的@后面跟随的首先被认为成应用名而不是源文档的域名(或子域名)
|
||||
* 程序会尝试找到应用对应的域名来生成地址,如果没找到,则按照源文档的逻辑执行
|
||||
* @param string $url
|
||||
* 程序会尝试找到应用对应的域名来生成地址,如果没找到,则按照源文档的逻辑执行.
|
||||
* @param string $url
|
||||
* @param array $vars
|
||||
* @param boolean $suffix
|
||||
* @param boolean $domain
|
||||
* @param bool $suffix
|
||||
* @param bool $domain
|
||||
* @return void
|
||||
*/
|
||||
function app_url(string $url = '', array $vars = [], $suffix = true, $domain = false)
|
||||
{
|
||||
|
||||
|
||||
return url($url, $vars, $suffix, $domain);
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('ua_htmlspecialchars')) {
|
||||
function ua_htmlspecialchars($string)
|
||||
{
|
||||
|
||||
if (is_null($string)) {
|
||||
$string = '';
|
||||
}
|
||||
@@ -295,7 +287,6 @@ if (!function_exists('ua_htmlspecialchars')) {
|
||||
if (!function_exists('ua_htmlentities')) {
|
||||
function ua_htmlentities($string)
|
||||
{
|
||||
|
||||
if (is_null($string)) {
|
||||
$string = '';
|
||||
}
|
||||
@@ -304,7 +295,8 @@ if (!function_exists('ua_htmlentities')) {
|
||||
}
|
||||
}
|
||||
|
||||
function show_time_ago($timestamp) {
|
||||
function show_time_ago($timestamp)
|
||||
{
|
||||
$current_time = new DateTime();
|
||||
$target_time = new DateTime("@$timestamp");
|
||||
$interval = $current_time->diff($target_time);
|
||||
@@ -324,4 +316,4 @@ function show_time_ago($timestamp) {
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user