From 487df09efec9f35b800d500a1ec3931fdf1e631d Mon Sep 17 00:00:00 2001 From: suyi Date: Fri, 15 Mar 2024 17:05:34 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=96=B0=E5=8A=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/functions.php | 996 ++++++++++++++++++++------------------- 1 file changed, 518 insertions(+), 478 deletions(-) diff --git a/server/app/functions.php b/server/app/functions.php index fbabed2..e843bbc 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -1,478 +1,518 @@ -download($filename,$name); - } -} -if(!function_exists('substr_symbol_behind')){ - /** - * @notes 截取某字符字符串 - * @param $str - * @param string $symbol - * @return string - * @author 乔峰 - * @date 2021/12/28 18:24 - */ - function substr_symbol_behind($str, $symbol = '.') : string - { - $result = strripos($str, $symbol); - if ($result === false) { - return $str; - } - return substr($str, $result + 1); - } -} - -if (!function_exists('root_path')) { - /** - * 获取项目根目录 - * - * @param string $path - * @return string - */ - function root_path($path = '') - { - return base_path() . DIRECTORY_SEPARATOR; - } -} - - -if (!function_exists('generate_path')) { - /** - * 获取项目根目录 - * - * @param string $path - * @return string - */ - function generate_path() - { - return root_path() . 'app/'; - } -} - - -if (!function_exists('cache')) { - /** - * 缓存管理 - * @param string $name 缓存名称 - * @param mixed $value 缓存值 - * @param mixed $options 缓存参数 - * @param string $tag 缓存标签 - * @return mixed - */ - function cache(string $name = null, $value = '', $options = null, $tag = null) - { - if (is_null($name)) { - return Cache::getFacadeClass(); - } - - if ('' === $value) { - // 获取缓存 - return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name); - } elseif (is_null($value)) { - // 删除缓存 - return Cache::delete($name); - } - - // 缓存数据 - if (is_array($options)) { - $expire = $options['expire'] ?? null; //修复查询缓存无法设置过期时间 - } else { - $expire = $options; - } - - if (is_null($tag)) { - return Cache::set($name, $value, $expire); - } else { - return Cache::tag($tag)->set($name, $value, $expire); - } - } -} -if (!function_exists('make')) { - function make(string $abstract, array $vars = [], bool $newInstance = false) - { - $container = support\Container::get(Container::class); - if (!$newInstance){ - try{ - return $container->get($abstract); - }catch (\Webman\Exception\NotFoundException $e){ - } - } - $newObj = $container->make($abstract,$vars); - $container->addDefinitions($newObj); - return $container->get($abstract); - } -} -if (!function_exists('strUcwords')){ - function strUcwords($str){ - $strArr = explode('_', $str); - $str = implode(' ', $strArr); - $str = implode('', explode(' ', ucwords($str))); - return $str; - } -} -if (!function_exists('strToUnderLineSpacing')){ - function strToUnderLineSpacing($str): string { - $tmp_array = []; - - for ($i = 0; $i < strlen($str); $i++) { - $ascii_code = ord($str[$i]); - if ($ascii_code >= 65 && $ascii_code <= 90) { - if ($i == 0) { - $tmp_array[] = chr($ascii_code + 32); - } else { - $tmp_array[] = '_' . chr($ascii_code + 32); - } - } else { - $tmp_array[] = $str[$i]; - } - } - - return implode('', $tmp_array); - } -} -if (!function_exists('url')) { - /** - * Url生成 - * @param string $url 路由地址 - * @param array $vars 变量 - * @param bool|string $suffix 生成的URL后缀 - * @param bool|string $domain 域名 - * @return string - */ - function url(string $url = '', array $vars = [], $suffix = true, $domain = false): string - { - $url = $suffix?$url.'.'.$suffix:$url; - $host = request()->host(); - $httpQuery = $vars?"?".http_build_query($vars):''; - if ($domain){ - return $host.DIRECTORY_SEPARATOR.$url.$httpQuery; - } - return DIRECTORY_SEPARATOR.$url.$httpQuery; - } -} - -if (!function_exists('format_amount')) { - - /** - * @notes 格式化金额 - * @param $float - * @return int|mixed|string - * @author 段誉 - * @date 2023/2/24 11:20 - */ - function format_amount($float) - { - if ($float == intval($float)) { - return intval($float); - } elseif ($float == sprintf('%.1f', $float)) { - return sprintf('%.1f', $float); - } - return $float; - } -} - - -if (!function_exists('del_target_dir')) { - - /** - * @notes 删除目标目录 - * @param $path - * @param $delDir - * @return bool|void - * @author bingo - * @date 2022/4/8 16:30 - */ - function del_target_dir($path, $delDir) - { - //没找到,不处理 - if (!file_exists($path)) { - return false; - } - - //打开目录句柄 - $handle = opendir($path); - if ($handle) { - while (false !== ($item = readdir($handle))) { - if ($item != "." && $item != "..") { - if (is_dir("$path/$item")) { - del_target_dir("$path/$item", $delDir); - } else { - unlink("$path/$item"); - } - } - } - closedir($handle); - if ($delDir) { - return rmdir($path); - } - } else { - if (file_exists($path)) { - return unlink($path); - } - return false; - } - } -} - -if (!function_exists('get_no_prefix_table_name')) { - - /** - * @notes 获取无前缀数据表名 - * @param $tableName - * @return mixed|string - * @author bingo - * @date 2022/12/12 15:23 - */ - function get_no_prefix_table_name($tableName) - { - $tablePrefix = getenv('DB_PREFIX'); - $prefixIndex = strpos($tableName, $tablePrefix); - if ($prefixIndex !== 0 || $prefixIndex === false) { - return $tableName; - } - $tableName = substr_replace($tableName, '', 0, strlen($tablePrefix)); - return trim($tableName); - } -} -if (!function_exists('compare_php')) { - - /** - * @notes 对比php版本 - * @param string $version - * @return bool - * @author 乔峰 - * @date 2021/12/28 18:27 - */ - function compare_php(string $version): bool - { - return version_compare(PHP_VERSION, $version) >= 0 ? true : false; - } -} -if (!function_exists('check_dir_write')) { - - /** - * @notes 检查文件是否可写 - * @param string $dir - * @return bool - * @author 乔峰 - * @date 2021/12/28 18:27 - */ - function check_dir_write(string $dir = ''): bool - { - $route = base_path() . '/' . $dir; - return is_writable($route); - } -} -if (!function_exists('create_token')) { - - /** - * @notes 随机生成token值 - * @param string $extra - * @return string - * @author 乔峰 - * @date 2021/12/28 18:24 - */ - function create_token(string $extra = ''): string - { - return md5($extra . time()); - } -} -if (!function_exists('linear_to_tree')) { - - /** - * 多级线性结构排序 - * 转换前: - * [{"id":1,"pid":0,"name":"a"},{"id":2,"pid":0,"name":"b"},{"id":3,"pid":1,"name":"c"}, - * {"id":4,"pid":2,"name":"d"},{"id":5,"pid":4,"name":"e"},{"id":6,"pid":5,"name":"f"}, - * {"id":7,"pid":3,"name":"g"}] - * 转换后: - * [{"id":1,"pid":0,"name":"a","level":1},{"id":3,"pid":1,"name":"c","level":2},{"id":7,"pid":3,"name":"g","level":3}, - * {"id":2,"pid":0,"name":"b","level":1},{"id":4,"pid":2,"name":"d","level":2},{"id":5,"pid":4,"name":"e","level":3}, - * {"id":6,"pid":5,"name":"f","level":4}] - * @param array $data 线性结构数组 - * @param string $symbol 名称前面加符号 - * @param string $name 名称 - * @param string $id_name 数组id名 - * @param string $parent_id_name 数组祖先id名 - * @param int $level 此值请勿给参数 - * @param int $parent_id 此值请勿给参数 - * @return array - */ - function linear_to_tree($data, $sub_key_name = 'sub', $id_name = 'id', $parent_id_name = 'pid', $parent_id = 0) - { - $tree = []; - foreach ($data as $row) { - if ($row[$parent_id_name] == $parent_id) { - $temp = $row; - $child = linear_to_tree($data, $sub_key_name, $id_name, $parent_id_name, $row[$id_name]); - if ($child) { - $temp[$sub_key_name] = $child; - } - $tree[] = $temp; - } - } - return $tree; - } -} - -if (!function_exists('createDir')) { - - function createDir($path) - { - if (is_dir($path)) { - return true; - } - - $parent = dirname($path); - if (!is_dir($parent)) { - if (!createDir($parent)) { - return false; - } - } - return mkdir($path); - } -} - -if (!function_exists('create_password')) { - - /** - * @notes 生成密码加密密钥 - * @param string $plaintext - * @param string $salt - * @return string - * @author 段誉 - * @date 2021/12/28 18:24 - */ - function create_password(string $plaintext, string $salt) : string - { - return md5($salt . md5($plaintext . $salt)); - } -} - -if (!function_exists('generate_sn')) { - - - /** - * @notes 生成编码 - * @param $table - * @param $field - * @param string $prefix - * @param int $randSuffixLength - * @param array $pool - * @return string - * @author 段誉 - * @date 2023/2/23 11:35 - */ - function generate_sn($table, $field, $prefix = '', $randSuffixLength = 4, $pool = []) : string - { - $suffix = ''; - for ($i = 0; $i < $randSuffixLength; $i++) { - if (empty($pool)) { - $suffix .= rand(0, 9); - } else { - $suffix .= $pool[array_rand($pool)]; - } - } - $sn = $prefix . date('YmdHis') . $suffix; - if ($table::where($field, $sn)->find()) { - return generate_sn($table, $field, $prefix, $randSuffixLength, $pool); - } - return $sn; - } -} -if (!function_exists('get_file_domain')) { - - /** - * @notes 设置内容图片域名 - * @param $content - * @return array|string|string[]|null - * @author 段誉 - * @date 2022/9/26 10:43 - */ - function get_file_domain($content) - { - $preg = '/()/is'; - $fileUrl = FileService::getFileUrl(); - return preg_replace($preg, "\${1}$fileUrl\${2}\${3}", $content); - } -} -if (!function_exists('clear_file_domain')) { - - - /** - * @notes 去除内容图片域名 - * @param $content - * @return array|string|string[] - * @author 段誉 - * @date 2022/9/26 10:43 - */ - function clear_file_domain($content) - { - $fileUrl = FileService::getFileUrl(); - return str_replace($fileUrl, '/', $content); - } -} -if (!function_exists('download_file')) { - - - - /** - * @notes 下载文件 - * @param $url - * @param $saveDir - * @param $fileName - * @return string - * @author 段誉 - * @date 2022/9/16 9:53 - */ - function download_file($url, $saveDir, $fileName) - { - if (!file_exists($saveDir)) { - mkdir($saveDir, 0775, true); - } - $fileSrc = $saveDir . $fileName; - file_exists($fileSrc) && unlink($fileSrc); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); - $file = curl_exec($ch); - curl_close($ch); - $resource = fopen($fileSrc, 'a'); - fwrite($resource, $file); - fclose($resource); - if (filesize($fileSrc) == 0) { - unlink($fileSrc); - return ''; - } - return $fileSrc; - } -} - -if (!function_exists('handle_file_url')) { - function handle_file_url($list,$fileNameList = []) - { - foreach ($list as &$item){ - foreach ($fileNameList as $name){ - if (isset($item[$name])){ - $item[$name] = $item[$name]?FileService::getFileUrl($item[$name]):$item[$name]; - } - } - } - return $list; - } -} \ No newline at end of file +download($filename,$name); + } +} +if(!function_exists('substr_symbol_behind')){ + /** + * @notes 截取某字符字符串 + * @param $str + * @param string $symbol + * @return string + * @author 乔峰 + * @date 2021/12/28 18:24 + */ + function substr_symbol_behind($str, $symbol = '.') : string + { + $result = strripos($str, $symbol); + if ($result === false) { + return $str; + } + return substr($str, $result + 1); + } +} + +if (!function_exists('root_path')) { + /** + * 获取项目根目录 + * + * @param string $path + * @return string + */ + function root_path($path = '') + { + return base_path() . DIRECTORY_SEPARATOR; + } +} + + +if (!function_exists('generate_path')) { + /** + * 获取项目根目录 + * + * @param string $path + * @return string + */ + function generate_path() + { + return root_path() . 'app/'; + } +} + + +if (!function_exists('cache')) { + /** + * 缓存管理 + * @param string $name 缓存名称 + * @param mixed $value 缓存值 + * @param mixed $options 缓存参数 + * @param string $tag 缓存标签 + * @return mixed + */ + function cache(string $name = null, $value = '', $options = null, $tag = null) + { + if (is_null($name)) { + return Cache::getFacadeClass(); + } + + if ('' === $value) { + // 获取缓存 + return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name); + } elseif (is_null($value)) { + // 删除缓存 + return Cache::delete($name); + } + + // 缓存数据 + if (is_array($options)) { + $expire = $options['expire'] ?? null; //修复查询缓存无法设置过期时间 + } else { + $expire = $options; + } + + if (is_null($tag)) { + return Cache::set($name, $value, $expire); + } else { + return Cache::tag($tag)->set($name, $value, $expire); + } + } +} +if (!function_exists('make')) { + function make(string $abstract, array $vars = [], bool $newInstance = false) + { + $container = support\Container::get(Container::class); + if (!$newInstance){ + try{ + return $container->get($abstract); + }catch (\Webman\Exception\NotFoundException $e){ + } + } + $newObj = $container->make($abstract,$vars); + $container->addDefinitions($newObj); + return $container->get($abstract); + } +} +if (!function_exists('strUcwords')){ + function strUcwords($str){ + $strArr = explode('_', $str); + $str = implode(' ', $strArr); + $str = implode('', explode(' ', ucwords($str))); + return $str; + } +} +if (!function_exists('strToUnderLineSpacing')){ + function strToUnderLineSpacing($str): string { + $tmp_array = []; + + for ($i = 0; $i < strlen($str); $i++) { + $ascii_code = ord($str[$i]); + if ($ascii_code >= 65 && $ascii_code <= 90) { + if ($i == 0) { + $tmp_array[] = chr($ascii_code + 32); + } else { + $tmp_array[] = '_' . chr($ascii_code + 32); + } + } else { + $tmp_array[] = $str[$i]; + } + } + + return implode('', $tmp_array); + } +} +if (!function_exists('url')) { + /** + * Url生成 + * @param string $url 路由地址 + * @param array $vars 变量 + * @param bool|string $suffix 生成的URL后缀 + * @param bool|string $domain 域名 + * @return string + */ + function url(string $url = '', array $vars = [], $suffix = true, $domain = false): string + { + $url = $suffix?$url.'.'.$suffix:$url; + $host = request()->host(); + $httpQuery = $vars?"?".http_build_query($vars):''; + if ($domain){ + return $host.DIRECTORY_SEPARATOR.$url.$httpQuery; + } + return DIRECTORY_SEPARATOR.$url.$httpQuery; + } +} + +if (!function_exists('format_amount')) { + + /** + * @notes 格式化金额 + * @param $float + * @return int|mixed|string + * @author 段誉 + * @date 2023/2/24 11:20 + */ + function format_amount($float) + { + if ($float == intval($float)) { + return intval($float); + } elseif ($float == sprintf('%.1f', $float)) { + return sprintf('%.1f', $float); + } + return $float; + } +} + + +if (!function_exists('del_target_dir')) { + + /** + * @notes 删除目标目录 + * @param $path + * @param $delDir + * @return bool|void + * @author bingo + * @date 2022/4/8 16:30 + */ + function del_target_dir($path, $delDir) + { + //没找到,不处理 + if (!file_exists($path)) { + return false; + } + + //打开目录句柄 + $handle = opendir($path); + if ($handle) { + while (false !== ($item = readdir($handle))) { + if ($item != "." && $item != "..") { + if (is_dir("$path/$item")) { + del_target_dir("$path/$item", $delDir); + } else { + unlink("$path/$item"); + } + } + } + closedir($handle); + if ($delDir) { + return rmdir($path); + } + } else { + if (file_exists($path)) { + return unlink($path); + } + return false; + } + } +} + +if (!function_exists('get_no_prefix_table_name')) { + + /** + * @notes 获取无前缀数据表名 + * @param $tableName + * @return mixed|string + * @author bingo + * @date 2022/12/12 15:23 + */ + function get_no_prefix_table_name($tableName) + { + $tablePrefix = getenv('DB_PREFIX'); + $prefixIndex = strpos($tableName, $tablePrefix); + if ($prefixIndex !== 0 || $prefixIndex === false) { + return $tableName; + } + $tableName = substr_replace($tableName, '', 0, strlen($tablePrefix)); + return trim($tableName); + } +} +if (!function_exists('compare_php')) { + + /** + * @notes 对比php版本 + * @param string $version + * @return bool + * @author 乔峰 + * @date 2021/12/28 18:27 + */ + function compare_php(string $version): bool + { + return version_compare(PHP_VERSION, $version) >= 0 ? true : false; + } +} +if (!function_exists('check_dir_write')) { + + /** + * @notes 检查文件是否可写 + * @param string $dir + * @return bool + * @author 乔峰 + * @date 2021/12/28 18:27 + */ + function check_dir_write(string $dir = ''): bool + { + $route = base_path() . '/' . $dir; + return is_writable($route); + } +} +if (!function_exists('create_token')) { + + /** + * @notes 随机生成token值 + * @param string $extra + * @return string + * @author 乔峰 + * @date 2021/12/28 18:24 + */ + function create_token(string $extra = ''): string + { + return md5($extra . time()); + } +} +if (!function_exists('linear_to_tree')) { + + /** + * 多级线性结构排序 + * 转换前: + * [{"id":1,"pid":0,"name":"a"},{"id":2,"pid":0,"name":"b"},{"id":3,"pid":1,"name":"c"}, + * {"id":4,"pid":2,"name":"d"},{"id":5,"pid":4,"name":"e"},{"id":6,"pid":5,"name":"f"}, + * {"id":7,"pid":3,"name":"g"}] + * 转换后: + * [{"id":1,"pid":0,"name":"a","level":1},{"id":3,"pid":1,"name":"c","level":2},{"id":7,"pid":3,"name":"g","level":3}, + * {"id":2,"pid":0,"name":"b","level":1},{"id":4,"pid":2,"name":"d","level":2},{"id":5,"pid":4,"name":"e","level":3}, + * {"id":6,"pid":5,"name":"f","level":4}] + * @param array $data 线性结构数组 + * @param string $symbol 名称前面加符号 + * @param string $name 名称 + * @param string $id_name 数组id名 + * @param string $parent_id_name 数组祖先id名 + * @param int $level 此值请勿给参数 + * @param int $parent_id 此值请勿给参数 + * @return array + */ + function linear_to_tree($data, $sub_key_name = 'sub', $id_name = 'id', $parent_id_name = 'pid', $parent_id = 0) + { + $tree = []; + foreach ($data as $row) { + if ($row[$parent_id_name] == $parent_id) { + $temp = $row; + $child = linear_to_tree($data, $sub_key_name, $id_name, $parent_id_name, $row[$id_name]); + if ($child) { + $temp[$sub_key_name] = $child; + } + $tree[] = $temp; + } + } + return $tree; + } +} + +if (!function_exists('createDir')) { + + function createDir($path) + { + if (is_dir($path)) { + return true; + } + + $parent = dirname($path); + if (!is_dir($parent)) { + if (!createDir($parent)) { + return false; + } + } + return mkdir($path); + } +} + +if (!function_exists('create_password')) { + + /** + * @notes 生成密码加密密钥 + * @param string $plaintext + * @param string $salt + * @return string + * @author 段誉 + * @date 2021/12/28 18:24 + */ + function create_password(string $plaintext, string $salt) : string + { + return md5($salt . md5($plaintext . $salt)); + } +} + +if (!function_exists('generate_sn')) { + + + /** + * @notes 生成编码 + * @param $table + * @param $field + * @param string $prefix + * @param int $randSuffixLength + * @param array $pool + * @return string + * @author 段誉 + * @date 2023/2/23 11:35 + */ + function generate_sn($table, $field, $prefix = '', $randSuffixLength = 4, $pool = []) : string + { + $suffix = ''; + for ($i = 0; $i < $randSuffixLength; $i++) { + if (empty($pool)) { + $suffix .= rand(0, 9); + } else { + $suffix .= $pool[array_rand($pool)]; + } + } + $sn = $prefix . date('YmdHis') . $suffix; + if ($table::where($field, $sn)->find()) { + return generate_sn($table, $field, $prefix, $randSuffixLength, $pool); + } + return $sn; + } +} +if (!function_exists('get_file_domain')) { + + /** + * @notes 设置内容图片域名 + * @param $content + * @return array|string|string[]|null + * @author 段誉 + * @date 2022/9/26 10:43 + */ + function get_file_domain($content) + { + $preg = '/()/is'; + $fileUrl = FileService::getFileUrl(); + return preg_replace($preg, "\${1}$fileUrl\${2}\${3}", $content); + } +} +if (!function_exists('clear_file_domain')) { + + + /** + * @notes 去除内容图片域名 + * @param $content + * @return array|string|string[] + * @author 段誉 + * @date 2022/9/26 10:43 + */ + function clear_file_domain($content) + { + $fileUrl = FileService::getFileUrl(); + return str_replace($fileUrl, '/', $content); + } +} +if (!function_exists('download_file')) { + + + + /** + * @notes 下载文件 + * @param $url + * @param $saveDir + * @param $fileName + * @return string + * @author 段誉 + * @date 2022/9/16 9:53 + */ + function download_file($url, $saveDir, $fileName) + { + if (!file_exists($saveDir)) { + mkdir($saveDir, 0775, true); + } + $fileSrc = $saveDir . $fileName; + file_exists($fileSrc) && unlink($fileSrc); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); + $file = curl_exec($ch); + curl_close($ch); + $resource = fopen($fileSrc, 'a'); + fwrite($resource, $file); + fclose($resource); + if (filesize($fileSrc) == 0) { + unlink($fileSrc); + return ''; + } + return $fileSrc; + } +} + +if (!function_exists('handle_file_url')) { + function handle_file_url($list,$fileNameList = []) + { + foreach ($list as &$item){ + foreach ($fileNameList as $name){ + if (isset($item[$name])){ + $item[$name] = $item[$name]?FileService::getFileUrl($item[$name]):$item[$name]; + } + } + } + return $list; + } +} +if (!function_exists('formatDateStrToTime')){ + /** + * 时间格式化 时间字符串 按照指定格式解析返回时间戳 + */ + function formatDateStrToTime($dateStr,$format){ + $date = DateTime::createFromFormat($format,$dateStr); + return $date->getTimestamp(); + } +} +if (!function_exists('findChildren')){ + /** + * 查找树表中 本身+子项+子子项。。。得数组 + */ + function findChildren($data, $targetId,&$list,$childrenKey = 'children',$idKey='id',$pidKey='pid') { + foreach ($data as $item) { + if ($item[$idKey] == $targetId){ + $insertData = []; + foreach ($item as $key=>$value){ + if ($key == $childrenKey){ + continue; + } + $insertData[$key] = $value; + } + $list[] = $insertData; + } + if ($item[$pidKey] == $targetId){ + $insertData = []; + foreach ($item as $key=>$value){ + if ($key == $childrenKey){ + continue; + } + $insertData[$key] = $value; + } + $list[] = $insertData; + findChildren($item[$childrenKey],$item['id'],$list,$childrenKey,$idKey,$pidKey); + } + findChildren($item[$childrenKey],$targetId,$list,$childrenKey,$idKey,$pidKey); + } + } +} -- Gitee From 1843283c0c593e78082acd628c4cd979257efb84 Mon Sep 17 00:00:00 2001 From: suyi Date: Fri, 15 Mar 2024 17:09:19 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/functions.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/server/app/functions.php b/server/app/functions.php index e843bbc..7c186c4 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -487,20 +487,10 @@ if (!function_exists('formatDateStrToTime')){ } if (!function_exists('findChildren')){ /** - * 查找树表中 本身+子项+子子项。。。得数组 + * 查找树表中 子项+子子项。。。得数组 */ - function findChildren($data, $targetId,&$list,$childrenKey = 'children',$idKey='id',$pidKey='pid') { + function findChildren($data, $targetId,&$list,$childrenKey = 'children',$pidKey='pid') { foreach ($data as $item) { - if ($item[$idKey] == $targetId){ - $insertData = []; - foreach ($item as $key=>$value){ - if ($key == $childrenKey){ - continue; - } - $insertData[$key] = $value; - } - $list[] = $insertData; - } if ($item[$pidKey] == $targetId){ $insertData = []; foreach ($item as $key=>$value){ @@ -510,9 +500,9 @@ if (!function_exists('findChildren')){ $insertData[$key] = $value; } $list[] = $insertData; - findChildren($item[$childrenKey],$item['id'],$list,$childrenKey,$idKey,$pidKey); + findChildren($item[$childrenKey],$item['id'],$list,$childrenKey,$pidKey); } - findChildren($item[$childrenKey],$targetId,$list,$childrenKey,$idKey,$pidKey); + findChildren($item[$childrenKey],$targetId,$list,$childrenKey,$pidKey); } } } -- Gitee From ac8021b2d54bc0712c4d757d258d1961e784f3e2 Mon Sep 17 00:00:00 2001 From: suyi Date: Fri, 15 Mar 2024 17:17:36 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/functions.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/app/functions.php b/server/app/functions.php index 7c186c4..e843bbc 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -487,10 +487,20 @@ if (!function_exists('formatDateStrToTime')){ } if (!function_exists('findChildren')){ /** - * 查找树表中 子项+子子项。。。得数组 + * 查找树表中 本身+子项+子子项。。。得数组 */ - function findChildren($data, $targetId,&$list,$childrenKey = 'children',$pidKey='pid') { + function findChildren($data, $targetId,&$list,$childrenKey = 'children',$idKey='id',$pidKey='pid') { foreach ($data as $item) { + if ($item[$idKey] == $targetId){ + $insertData = []; + foreach ($item as $key=>$value){ + if ($key == $childrenKey){ + continue; + } + $insertData[$key] = $value; + } + $list[] = $insertData; + } if ($item[$pidKey] == $targetId){ $insertData = []; foreach ($item as $key=>$value){ @@ -500,9 +510,9 @@ if (!function_exists('findChildren')){ $insertData[$key] = $value; } $list[] = $insertData; - findChildren($item[$childrenKey],$item['id'],$list,$childrenKey,$pidKey); + findChildren($item[$childrenKey],$item['id'],$list,$childrenKey,$idKey,$pidKey); } - findChildren($item[$childrenKey],$targetId,$list,$childrenKey,$pidKey); + findChildren($item[$childrenKey],$targetId,$list,$childrenKey,$idKey,$pidKey); } } } -- Gitee From 24a92b296be52e1d491b1c2607100c64aca6402e Mon Sep 17 00:00:00 2001 From: suyi Date: Fri, 15 Mar 2024 17:17:53 +0800 Subject: [PATCH 4/8] key --- server/app/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/app/functions.php b/server/app/functions.php index e843bbc..fe2e175 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -510,7 +510,7 @@ if (!function_exists('findChildren')){ $insertData[$key] = $value; } $list[] = $insertData; - findChildren($item[$childrenKey],$item['id'],$list,$childrenKey,$idKey,$pidKey); + findChildren($item[$childrenKey],$item[$idKey],$list,$childrenKey,$idKey,$pidKey); } findChildren($item[$childrenKey],$targetId,$list,$childrenKey,$idKey,$pidKey); } -- Gitee From f2e12d57c5ea01d6e66486864ccfa99b2a14d9ef Mon Sep 17 00:00:00 2001 From: suyi Date: Tue, 26 Mar 2024 13:01:44 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/composer.json | 3 ++- server/composer.lock | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/server/composer.json b/server/composer.json index fd8c50f..1a28dce 100644 --- a/server/composer.json +++ b/server/composer.json @@ -44,7 +44,8 @@ "taoser/webman-validate": "^1.7", "webman/redis-queue": "^1.3", "w7corp/easywechat": "^6.8", - "workerman/crontab": "^1.0" + "workerman/crontab": "^1.0", + "ext-fileinfo": "*" }, "config": { "preferred-install": "dist", diff --git a/server/composer.lock b/server/composer.lock index 2647fbc..8dd1c3f 100644 --- a/server/composer.lock +++ b/server/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f9638acbbea944964f7a699cf84815d6", + "content-hash": "e4aeffd0c3839804ba582f1b6aa16204", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -1632,16 +1632,16 @@ }, { "name": "overtrue/socialite", - "version": "4.9.0", + "version": "4.10.1", "source": { "type": "git", "url": "https://github.com/overtrue/socialite.git", - "reference": "dcbb1eed948fe036e6de8cdf0b125f5af1bc73fb" + "reference": "457b48f31414dc00d3fb445d6ab9355595067afe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/overtrue/socialite/zipball/dcbb1eed948fe036e6de8cdf0b125f5af1bc73fb", - "reference": "dcbb1eed948fe036e6de8cdf0b125f5af1bc73fb", + "url": "https://api.github.com/repos/overtrue/socialite/zipball/457b48f31414dc00d3fb445d6ab9355595067afe", + "reference": "457b48f31414dc00d3fb445d6ab9355595067afe", "shasum": "", "mirrors": [ { @@ -1655,8 +1655,7 @@ "ext-openssl": "*", "guzzlehttp/guzzle": "^7.0", "php": ">=8.0.2", - "symfony/http-foundation": "^6.0", - "symfony/psr-http-message-bridge": "^2.1" + "symfony/psr-http-message-bridge": "^2.1|^6.0" }, "require-dev": { "jetbrains/phpstorm-attributes": "^1.0", @@ -1699,7 +1698,7 @@ ], "support": { "issues": "https://github.com/overtrue/socialite/issues", - "source": "https://github.com/overtrue/socialite/tree/4.9.0" + "source": "https://github.com/overtrue/socialite/tree/4.10.1" }, "funding": [ { @@ -1707,7 +1706,7 @@ "type": "github" } ], - "time": "2023-09-01T11:01:34+00:00" + "time": "2024-03-08T06:41:54+00:00" }, { "name": "phpoffice/phpspreadsheet", @@ -4559,16 +4558,16 @@ }, { "name": "tencentcloud/tencentcloud-sdk-php", - "version": "3.0.1094", + "version": "3.0.1108", "source": { "type": "git", "url": "https://github.com/TencentCloud/tencentcloud-sdk-php.git", - "reference": "6cdc78c5e6e3ba10010d0d0516b451878ef3b566" + "reference": "f9336e6a3b7715e7ee5ea881c158c90c0c2072d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/TencentCloud/tencentcloud-sdk-php/zipball/6cdc78c5e6e3ba10010d0d0516b451878ef3b566", - "reference": "6cdc78c5e6e3ba10010d0d0516b451878ef3b566", + "url": "https://api.github.com/repos/TencentCloud/tencentcloud-sdk-php/zipball/f9336e6a3b7715e7ee5ea881c158c90c0c2072d5", + "reference": "f9336e6a3b7715e7ee5ea881c158c90c0c2072d5", "shasum": "", "mirrors": [ { @@ -4609,9 +4608,9 @@ "homepage": "https://github.com/TencentCloud/tencentcloud-sdk-php", "support": { "issues": "https://github.com/TencentCloud/tencentcloud-sdk-php/issues", - "source": "https://github.com/TencentCloud/tencentcloud-sdk-php/tree/3.0.1094" + "source": "https://github.com/TencentCloud/tencentcloud-sdk-php/tree/3.0.1108" }, - "time": "2024-03-05T20:08:01+00:00" + "time": "2024-03-24T20:09:08+00:00" }, { "name": "thenorthmemory/xml", @@ -5694,7 +5693,8 @@ "prefer-lowest": false, "platform": { "php": ">=7.2", - "ext-json": "*" + "ext-json": "*", + "ext-fileinfo": "*" }, "platform-dev": [], "plugin-api-version": "2.6.0" -- Gitee From 903a127eec635f16130bd2ee84c41c790ce8ac60 Mon Sep 17 00:00:00 2001 From: suyi Date: Tue, 26 Mar 2024 15:17:57 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=A0=A1=E9=AA=8Chttp=E5=92=8Chttps?= =?UTF-8?q?=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/README.en.md | 3 + server/README.md | 3 + server/app/api/logic/IndexLogic.php | 308 ++++++------ server/app/api/logic/PcLogic.php | 2 +- server/app/common/lists/ListsExcelTrait.php | 234 +++++----- server/app/common/service/FileService.php | 206 ++++---- .../service/generator/GenerateService.php | 440 +++++++++--------- server/app/functions.php | 11 +- 8 files changed, 611 insertions(+), 596 deletions(-) diff --git a/server/README.en.md b/server/README.en.md index be3dcbb..5f2bec5 100644 --- a/server/README.en.md +++ b/server/README.en.md @@ -46,6 +46,7 @@ Backend API proxy { proxy_pass http://ip:端口/adminapi/; proxy_set_header Host $host; + proxy_set_header AGREEMENT-HOST "http://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -79,6 +80,7 @@ pc/uniapp api proxy { proxy_pass http://ip:端口/api/; proxy_set_header Host $host; + proxy_set_header AGREEMENT-HOST "http://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -111,6 +113,7 @@ Static resource proxy { proxy_pass http://ip:端口/resource/; proxy_set_header Host $host; + proxy_set_header AGREEMENT-HOST "http://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; diff --git a/server/README.md b/server/README.md index d4a3c32..a58293c 100644 --- a/server/README.md +++ b/server/README.md @@ -42,6 +42,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/adminapi/; proxy_set_header Host $host; + proxy_set_header AGREEMENT-HOST "http://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -75,6 +76,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/api/; proxy_set_header Host $host; + proxy_set_header AGREEMENT-HOST "http://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -107,6 +109,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/resource/; proxy_set_header Host $host; + proxy_set_header AGREEMENT-HOST "http://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; diff --git a/server/app/api/logic/IndexLogic.php b/server/app/api/logic/IndexLogic.php index 765421c..7106ae7 100644 --- a/server/app/api/logic/IndexLogic.php +++ b/server/app/api/logic/IndexLogic.php @@ -1,155 +1,155 @@ -where(['is_show' => 1]) - ->order(['id' => 'desc']) - ->limit(20)->append(['click']) - ->hidden(['click_actual', 'click_virtual']) - ->select()->toArray(); - - return [ - 'page' => $decoratePage, - 'article' => $article - ]; - } - - - /** - * @notes 获取政策协议 - * @param string $type - * @return array - * @author 段誉 - * @date 2022/9/20 20:00 - */ - public static function getPolicyByType(string $type) - { - return [ - 'title' => ConfigService::get('agreement', $type . '_title', ''), - 'content' => ConfigService::get('agreement', $type . '_content', ''), - ]; - } - - - /** - * @notes 装修信息 - * @param $id - * @return array - * @author 段誉 - * @date 2022/9/21 18:37 - */ - public static function getDecorate($id) - { - return DecoratePage::field(['type', 'name', 'data']) - ->findOrEmpty($id)->toArray(); - } - - - /** - * @notes 获取配置 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author 段誉 - * @date 2022/9/21 19:38 - */ - public static function getConfigData() - { - // 底部导航 - $tabbar = DecorateTabbar::getTabbarLists(); - // 导航颜色 - $style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style')); - // 登录配置 - $loginConfig = [ - // 登录方式 - 'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')), - // 注册强制绑定手机 - 'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')), - // 政策协议 - 'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')), - // 第三方登录 开关 - 'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')), - // 微信授权登录 - 'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')), - // qq授权登录 - 'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')), - ]; - // 网址信息 - $website = [ - 'shop_name' => ConfigService::get('website', 'shop_name'), - 'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')), - ]; - // H5配置 - $webPage = [ - // 渠道状态 0-关闭 1-开启 - 'status' => ConfigService::get('web_page', 'status', 1), - // 关闭后渠道后访问页面 0-空页面 1-自定义链接 - 'page_status' => ConfigService::get('web_page', 'page_status', 0), - // 自定义链接 - 'page_url' => ConfigService::get('web_page', 'page_url', ''), - 'url' => request()->host() . '/mobile' - ]; - - return [ - 'domain' => FileService::getFileUrl(), - 'style' => $style, - 'tabbar' => $tabbar, - 'login' => $loginConfig, - 'website' => $website, - 'webPage' => $webPage, - 'version'=> config('project.version') - ]; - } - +where(['is_show' => 1]) + ->order(['id' => 'desc']) + ->limit(20)->append(['click']) + ->hidden(['click_actual', 'click_virtual']) + ->select()->toArray(); + + return [ + 'page' => $decoratePage, + 'article' => $article + ]; + } + + + /** + * @notes 获取政策协议 + * @param string $type + * @return array + * @author 段誉 + * @date 2022/9/20 20:00 + */ + public static function getPolicyByType(string $type) + { + return [ + 'title' => ConfigService::get('agreement', $type . '_title', ''), + 'content' => ConfigService::get('agreement', $type . '_content', ''), + ]; + } + + + /** + * @notes 装修信息 + * @param $id + * @return array + * @author 段誉 + * @date 2022/9/21 18:37 + */ + public static function getDecorate($id) + { + return DecoratePage::field(['type', 'name', 'data']) + ->findOrEmpty($id)->toArray(); + } + + + /** + * @notes 获取配置 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 段誉 + * @date 2022/9/21 19:38 + */ + public static function getConfigData() + { + // 底部导航 + $tabbar = DecorateTabbar::getTabbarLists(); + // 导航颜色 + $style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style')); + // 登录配置 + $loginConfig = [ + // 登录方式 + 'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')), + // 注册强制绑定手机 + 'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')), + // 政策协议 + 'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')), + // 第三方登录 开关 + 'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')), + // 微信授权登录 + 'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')), + // qq授权登录 + 'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')), + ]; + // 网址信息 + $website = [ + 'shop_name' => ConfigService::get('website', 'shop_name'), + 'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')), + ]; + // H5配置 + $webPage = [ + // 渠道状态 0-关闭 1-开启 + 'status' => ConfigService::get('web_page', 'status', 1), + // 关闭后渠道后访问页面 0-空页面 1-自定义链接 + 'page_status' => ConfigService::get('web_page', 'page_status', 0), + // 自定义链接 + 'page_url' => ConfigService::get('web_page', 'page_url', ''), + 'url' => getAgreementHost() . '/mobile' + ]; + + return [ + 'domain' => FileService::getFileUrl(), + 'style' => $style, + 'tabbar' => $tabbar, + 'login' => $loginConfig, + 'website' => $website, + 'webPage' => $webPage, + 'version'=> config('project.version') + ]; + } + } \ No newline at end of file diff --git a/server/app/api/logic/PcLogic.php b/server/app/api/logic/PcLogic.php index 7407988..8c0ba69 100644 --- a/server/app/api/logic/PcLogic.php +++ b/server/app/api/logic/PcLogic.php @@ -164,7 +164,7 @@ class PcLogic extends BaseLogic 'website' => $website, 'version' => config('project.version'), 'copyright' => $copyright, - 'admin_url' => request()->host() . '/admin', + 'admin_url' => getAgreementHost() . '/admin', 'qrcode' => [ 'oa' => $oaQrCode, 'mnp' => $mnpQrCode, diff --git a/server/app/common/lists/ListsExcelTrait.php b/server/app/common/lists/ListsExcelTrait.php index b8fc83e..ccc5d43 100644 --- a/server/app/common/lists/ListsExcelTrait.php +++ b/server/app/common/lists/ListsExcelTrait.php @@ -1,118 +1,118 @@ - $excelField) { - $fieldData = $row[$key]; - if (is_numeric($fieldData) && strlen($fieldData) >= 12) { - $fieldData .= "\t"; - } - $temp[$key] = $fieldData; - } - $data[] = $temp; - } - $spreadsheet = new Spreadsheet(); - $sheet = $spreadsheet->getActiveSheet(); - - //设置单元格内容 - foreach ($title as $key => $value) { - // 单元格内容写入 - $sheet->setCellValueByColumnAndRow($key + 1, 1, $value); - } - $row = 2; //从第二行开始 - foreach ($data as $item) { - $column = 1; - foreach ($item as $value) { - //单元格内容写入 - $sheet->setCellValueByColumnAndRow($column, $row, $value); - $column++; - } - $row++; - } - - $getHighestRowAndColumn = $sheet->getHighestRowAndColumn(); - $HighestRow = $getHighestRowAndColumn['row']; - $column = $getHighestRowAndColumn['column']; - $titleScope = 'A1:' . $column . '1';//第一(标题)范围(例:A1:D1) - - $sheet->getStyle($titleScope) - ->getFill() - ->setFillType(Fill::FILL_SOLID) // 设置填充样式 - ->getStartColor() - ->setARGB('00B0F0'); - // 设置文字颜色为白色 - $sheet->getStyle($titleScope)->getFont()->getColor() - ->setARGB('FFFFFF'); - -// $sheet->getStyle('B2')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD); - $spreadsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); - - $allCope = 'A1:' . $column . $HighestRow;//整个表格范围(例:A1:D5) - $sheet->getStyle($allCope)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); - - $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); - - //创建excel文件 - $exportCache = new ExportCache(); - $src = $exportCache->getSrc(); - - if (!file_exists($src)) { - mkdir($src, 0775, true); - } - $writer->save($src . $this->fileName); - //设置本地excel缓存并返回下载地址 - return 'http://'.request()->host().'/adminapi/download/export?file='.$exportCache->setFile($this->fileName); - } - /** - * @notes 获取导出信息 - * @return array - * @author 令狐冲 - * @date 2021/7/29 16:08 - */ - public function excelInfo() - { - $count = $this->count(); - $sum_page = max(ceil($count / $this->pageSize), 1); - return [ - 'count' => $count, //所有数据记录数 - 'page_size' => $this->pageSize,//每页记录数 - 'sum_page' => $sum_page,//一共多少页 - 'max_page' => floor($this->pageSizeMax / $this->pageSize),//最多导出多少页 - 'all_max_size' => $this->pageSizeMax,//最多导出记录数 - 'page_start' => $this->pageStart,//导出范围页码开始值 - 'page_end' => min($sum_page, $this->pageEnd),//导出范围页码结束值 - 'file_name' => $this->fileName,//默认文件名 - ]; - } + $excelField) { + $fieldData = $row[$key]; + if (is_numeric($fieldData) && strlen($fieldData) >= 12) { + $fieldData .= "\t"; + } + $temp[$key] = $fieldData; + } + $data[] = $temp; + } + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + //设置单元格内容 + foreach ($title as $key => $value) { + // 单元格内容写入 + $sheet->setCellValueByColumnAndRow($key + 1, 1, $value); + } + $row = 2; //从第二行开始 + foreach ($data as $item) { + $column = 1; + foreach ($item as $value) { + //单元格内容写入 + $sheet->setCellValueByColumnAndRow($column, $row, $value); + $column++; + } + $row++; + } + + $getHighestRowAndColumn = $sheet->getHighestRowAndColumn(); + $HighestRow = $getHighestRowAndColumn['row']; + $column = $getHighestRowAndColumn['column']; + $titleScope = 'A1:' . $column . '1';//第一(标题)范围(例:A1:D1) + + $sheet->getStyle($titleScope) + ->getFill() + ->setFillType(Fill::FILL_SOLID) // 设置填充样式 + ->getStartColor() + ->setARGB('00B0F0'); + // 设置文字颜色为白色 + $sheet->getStyle($titleScope)->getFont()->getColor() + ->setARGB('FFFFFF'); + +// $sheet->getStyle('B2')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD); + $spreadsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); + + $allCope = 'A1:' . $column . $HighestRow;//整个表格范围(例:A1:D5) + $sheet->getStyle($allCope)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); + + $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); + + //创建excel文件 + $exportCache = new ExportCache(); + $src = $exportCache->getSrc(); + + if (!file_exists($src)) { + mkdir($src, 0775, true); + } + $writer->save($src . $this->fileName); + //设置本地excel缓存并返回下载地址 + return getAgreementHost().'/adminapi/download/export?file='.$exportCache->setFile($this->fileName); + } + /** + * @notes 获取导出信息 + * @return array + * @author 令狐冲 + * @date 2021/7/29 16:08 + */ + public function excelInfo() + { + $count = $this->count(); + $sum_page = max(ceil($count / $this->pageSize), 1); + return [ + 'count' => $count, //所有数据记录数 + 'page_size' => $this->pageSize,//每页记录数 + 'sum_page' => $sum_page,//一共多少页 + 'max_page' => floor($this->pageSizeMax / $this->pageSize),//最多导出多少页 + 'all_max_size' => $this->pageSizeMax,//最多导出记录数 + 'page_start' => $this->pageStart,//导出范围页码开始值 + 'page_end' => min($sum_page, $this->pageEnd),//导出范围页码结束值 + 'file_name' => $this->fileName,//默认文件名 + ]; + } } \ No newline at end of file diff --git a/server/app/common/service/FileService.php b/server/app/common/service/FileService.php index a3a55bf..17e7778 100644 --- a/server/app/common/service/FileService.php +++ b/server/app/common/service/FileService.php @@ -1,104 +1,104 @@ -host(), 'http://') && !strstr(request()->host(), 'https://'))?'http://'.request()->host():request()->host(); - } else { - $storage = Cache::get('STORAGE_ENGINE'); - if (!$storage) { - $storage = ConfigService::get('storage', $default); - Cache::set('STORAGE_ENGINE', $storage); - } - $domain = $storage ? $storage['domain'] : ''; - } - - return self::format($domain, $uri); - } - - /** - * @notes 转相对路径 - * @param $uri - * @return mixed - * @author 乔峰 - * @date 2021/7/28 15:09 - */ - public static function setFileUrl($uri) - { - $default = ConfigService::get('storage', 'default', 'local'); - if ($default === 'local') { - $domain = 'http://'.request()->host(); - return str_replace($domain.'/', '', $uri); - } else { - $storage = ConfigService::get('storage', $default); - return str_replace($storage['domain'].'/', '', $uri); - } - } - - - /** - * @notes 格式化url - * @param $domain - * @param $uri - * @return string - * @author 乔峰 - * @date 2022/7/11 10:36 - */ - public static function format($domain, $uri) - { - // 处理域名 - $domainLen = strlen($domain); - $domainRight = substr($domain, $domainLen -1, 1); - if ('/' == $domainRight) { - $domain = substr_replace($domain,'',$domainLen -1, 1); - } - - // 处理uri - $uriLeft = substr($uri, 0, 1); - if('/' == $uriLeft) { - $uri = substr_replace($uri,'',0, 1); - } - - return trim($domain) . '/' . trim($uri); - } +generatePath = root_path() . 'runtime/generate/'; - $this->runtimePath = root_path() . 'runtime/'; - } - - - /** - * @notes 删除生成文件夹内容 - * @author bingo - * @date 2022/6/23 18:52 - */ - public function delGenerateDirContent() - { - // 删除runtime目录制定文件夹 - !is_dir($this->generatePath) && mkdir($this->generatePath, 0755, true); - del_target_dir($this->generatePath, false); - } - - - /** - * @notes 设置生成状态 - * @param $name - * @param false $status - * @author bingo - * @date 2022/6/23 18:53 - */ - public function setGenerateFlag($name, $status = false) - { - $this->flag = $name; - cache($name, (int)$status, 3600); - } - - - /** - * @notes 获取生成状态标记 - * @author bingo - * @date 2022/6/23 18:53 - */ - public function getGenerateFlag() - { - return cache($this->flag); - } - - - /** - * @notes 删除标记时间 - * @author bingo - * @date 2022/6/23 18:53 - */ - public function delGenerateFlag() - { - cache($this->flag, null); - } - - - /** - * @notes 生成器相关类 - * @return string[] - * @author bingo - * @date 2022/6/23 17:17 - */ - public function getGeneratorClass() - { - return [ - ControllerGenerator::class, - ListsGenerator::class, - ModelGenerator::class, - ValidateGenerator::class, - LogicGenerator::class, - VueApiGenerator::class, - VueIndexGenerator::class, - VueEditGenerator::class, - SqlGenerator::class, - ]; - } - - - /** - * @notes 生成文件 - * @param array $tableData - * @author bingo - * @date 2022/6/23 18:52 - */ - public function generate(array $tableData) - { - foreach ($this->getGeneratorClass() as $item) { - $generator = make($item); - $generator->initGenerateData($tableData); - $generator->generate(); - // 是否为压缩包下载 - if ($generator->isGenerateTypeZip()) { - $this->setGenerateFlag($this->flag, true); - } - // 是否构建菜单 - if ($item == 'app\common\service\generator\core\SqlGenerator') { - $generator->isBuildMenu() && $generator->buildMenuHandle(); - } - } - } - - - /** - * @notes 预览文件 - * @param array $tableData - * @return array - * @author bingo - * @date 2022/6/23 18:52 - */ - public function preview(array $tableData) - { - $data = []; - foreach ($this->getGeneratorClass() as $item) { - $generator = make($item); - $generator->initGenerateData($tableData); - $data[] = $generator->fileInfo(); - } - return $data; - } - - - /** - * @notes 压缩文件 - * @author bingo - * @date 2022/6/23 19:02 - */ - public function zipFile() - { - $fileName = 'curd-' . date('YmdHis') . '.zip'; - $this->zipTempName = $fileName; - $this->zipTempPath = $this->generatePath . $fileName; - $zip = new \ZipArchive(); - $zip->open($this->zipTempPath, \ZipArchive::CREATE); - $this->addFileZip($this->runtimePath, 'generate', $zip); - $zip->close(); - } - - - /** - * @notes 往压缩包写入文件 - * @param $basePath - * @param $dirName - * @param $zip - * @author bingo - * @date 2022/6/23 19:02 - */ - public function addFileZip($basePath, $dirName, $zip) - { - $handler = opendir($basePath . $dirName); - while (($filename = readdir($handler)) !== false) { - if ($filename != '.' && $filename != '..') { - if (is_dir($basePath . $dirName . '/' . $filename)) { - // 当前路径是文件夹 - $this->addFileZip($basePath, $dirName . '/' . $filename, $zip); - } else { - // 写入文件到压缩包 - $zip->addFile($basePath . $dirName . '/' . $filename, $dirName . '/' . $filename); - } - } - } - closedir($handler); - } - - - /** - * @notes 返回压缩包临时路径 - * @return mixed - * @author bingo - * @date 2022/6/24 9:41 - */ - public function getDownloadUrl() - { - $vars = ['file' => $this->zipTempName]; - cache('curd_file_name' . $this->zipTempName, $this->zipTempName, 3600); - $request = App::request(); - return "http://".$request->host()."/adminapi/tools/generator/download?file={$this->zipTempName}"; - } - +generatePath = root_path() . 'runtime/generate/'; + $this->runtimePath = root_path() . 'runtime/'; + } + + + /** + * @notes 删除生成文件夹内容 + * @author bingo + * @date 2022/6/23 18:52 + */ + public function delGenerateDirContent() + { + // 删除runtime目录制定文件夹 + !is_dir($this->generatePath) && mkdir($this->generatePath, 0755, true); + del_target_dir($this->generatePath, false); + } + + + /** + * @notes 设置生成状态 + * @param $name + * @param false $status + * @author bingo + * @date 2022/6/23 18:53 + */ + public function setGenerateFlag($name, $status = false) + { + $this->flag = $name; + cache($name, (int)$status, 3600); + } + + + /** + * @notes 获取生成状态标记 + * @author bingo + * @date 2022/6/23 18:53 + */ + public function getGenerateFlag() + { + return cache($this->flag); + } + + + /** + * @notes 删除标记时间 + * @author bingo + * @date 2022/6/23 18:53 + */ + public function delGenerateFlag() + { + cache($this->flag, null); + } + + + /** + * @notes 生成器相关类 + * @return string[] + * @author bingo + * @date 2022/6/23 17:17 + */ + public function getGeneratorClass() + { + return [ + ControllerGenerator::class, + ListsGenerator::class, + ModelGenerator::class, + ValidateGenerator::class, + LogicGenerator::class, + VueApiGenerator::class, + VueIndexGenerator::class, + VueEditGenerator::class, + SqlGenerator::class, + ]; + } + + + /** + * @notes 生成文件 + * @param array $tableData + * @author bingo + * @date 2022/6/23 18:52 + */ + public function generate(array $tableData) + { + foreach ($this->getGeneratorClass() as $item) { + $generator = make($item); + $generator->initGenerateData($tableData); + $generator->generate(); + // 是否为压缩包下载 + if ($generator->isGenerateTypeZip()) { + $this->setGenerateFlag($this->flag, true); + } + // 是否构建菜单 + if ($item == 'app\common\service\generator\core\SqlGenerator') { + $generator->isBuildMenu() && $generator->buildMenuHandle(); + } + } + } + + + /** + * @notes 预览文件 + * @param array $tableData + * @return array + * @author bingo + * @date 2022/6/23 18:52 + */ + public function preview(array $tableData) + { + $data = []; + foreach ($this->getGeneratorClass() as $item) { + $generator = make($item); + $generator->initGenerateData($tableData); + $data[] = $generator->fileInfo(); + } + return $data; + } + + + /** + * @notes 压缩文件 + * @author bingo + * @date 2022/6/23 19:02 + */ + public function zipFile() + { + $fileName = 'curd-' . date('YmdHis') . '.zip'; + $this->zipTempName = $fileName; + $this->zipTempPath = $this->generatePath . $fileName; + $zip = new \ZipArchive(); + $zip->open($this->zipTempPath, \ZipArchive::CREATE); + $this->addFileZip($this->runtimePath, 'generate', $zip); + $zip->close(); + } + + + /** + * @notes 往压缩包写入文件 + * @param $basePath + * @param $dirName + * @param $zip + * @author bingo + * @date 2022/6/23 19:02 + */ + public function addFileZip($basePath, $dirName, $zip) + { + $handler = opendir($basePath . $dirName); + while (($filename = readdir($handler)) !== false) { + if ($filename != '.' && $filename != '..') { + if (is_dir($basePath . $dirName . '/' . $filename)) { + // 当前路径是文件夹 + $this->addFileZip($basePath, $dirName . '/' . $filename, $zip); + } else { + // 写入文件到压缩包 + $zip->addFile($basePath . $dirName . '/' . $filename, $dirName . '/' . $filename); + } + } + } + closedir($handler); + } + + + /** + * @notes 返回压缩包临时路径 + * @return mixed + * @author bingo + * @date 2022/6/24 9:41 + */ + public function getDownloadUrl() + { + $vars = ['file' => $this->zipTempName]; + cache('curd_file_name' . $this->zipTempName, $this->zipTempName, 3600); + $request = App::request(); + return getAgreementHost()."/adminapi/tools/generator/download?file={$this->zipTempName}"; + } + } \ No newline at end of file diff --git a/server/app/functions.php b/server/app/functions.php index fe2e175..5e41ba1 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -156,7 +156,7 @@ if (!function_exists('url')) { function url(string $url = '', array $vars = [], $suffix = true, $domain = false): string { $url = $suffix?$url.'.'.$suffix:$url; - $host = request()->host(); + $host = getAgreementHost(); $httpQuery = $vars?"?".http_build_query($vars):''; if ($domain){ return $host.DIRECTORY_SEPARATOR.$url.$httpQuery; @@ -516,3 +516,12 @@ if (!function_exists('findChildren')){ } } } +if (!function_exists('getAgreementHost')){ +// proxy_set_header AGREEMENT-HOST "http://$host"; + function getAgreementHost() { + if(!strstr(request()->host(), 'http://') && !strstr(request()->host(), 'https://')){ + return request()->header('AGREEMENT-HOST',false)?:'http://'.request()->host(); + } + return request()->host(); + } +} \ No newline at end of file -- Gitee From 1bdc12cd5b6e44d6b950e6f7077e77cafe836d84 Mon Sep 17 00:00:00 2001 From: suyi Date: Tue, 26 Mar 2024 15:23:32 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/README.en.md | 6 +++--- server/README.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/README.en.md b/server/README.en.md index 5f2bec5..8304f8e 100644 --- a/server/README.en.md +++ b/server/README.en.md @@ -46,7 +46,7 @@ Backend API proxy { proxy_pass http://ip:端口/adminapi/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "http://$host"; + proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -80,7 +80,7 @@ pc/uniapp api proxy { proxy_pass http://ip:端口/api/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "http://$host"; + proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -113,7 +113,7 @@ Static resource proxy { proxy_pass http://ip:端口/resource/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "http://$host"; + proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; diff --git a/server/README.md b/server/README.md index a58293c..8de8003 100644 --- a/server/README.md +++ b/server/README.md @@ -42,7 +42,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/adminapi/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "http://$host"; + proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -76,7 +76,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/api/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "http://$host"; + proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -109,7 +109,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/resource/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "http://$host"; + proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; -- Gitee From f3d384d49cdff912f4b1139809595d82d00e58b6 Mon Sep 17 00:00:00 2001 From: suyi Date: Tue, 26 Mar 2024 15:39:01 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/README.en.md | 6 +++--- server/README.md | 6 +++--- server/app/functions.php | 9 +++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/README.en.md b/server/README.en.md index 8304f8e..ec547e9 100644 --- a/server/README.en.md +++ b/server/README.en.md @@ -46,7 +46,7 @@ Backend API proxy { proxy_pass http://ip:端口/adminapi/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; + proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -80,7 +80,7 @@ pc/uniapp api proxy { proxy_pass http://ip:端口/api/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; + proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -113,7 +113,7 @@ Static resource proxy { proxy_pass http://ip:端口/resource/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; + proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; diff --git a/server/README.md b/server/README.md index 8de8003..c388193 100644 --- a/server/README.md +++ b/server/README.md @@ -42,7 +42,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/adminapi/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; + proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -76,7 +76,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/api/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; + proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; @@ -109,7 +109,7 @@ like: https://gitee.com/MuZJun/gather-admin.git { proxy_pass http://ip:端口/resource/; proxy_set_header Host $host; - proxy_set_header AGREEMENT-HOST "$http_x_forwarded_proto://$host"; + proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; diff --git a/server/app/functions.php b/server/app/functions.php index 5e41ba1..2cac4a1 100644 --- a/server/app/functions.php +++ b/server/app/functions.php @@ -517,10 +517,15 @@ if (!function_exists('findChildren')){ } } if (!function_exists('getAgreementHost')){ -// proxy_set_header AGREEMENT-HOST "http://$host"; + /** + * proxy_set_header Scheme $scheme; + * 获取单域名配置上的协议拼接域名 + * 如果是后台有单独域名部署那么直接从 host 请求头上拿域名 + * @return array|string|null + */ function getAgreementHost() { if(!strstr(request()->host(), 'http://') && !strstr(request()->host(), 'https://')){ - return request()->header('AGREEMENT-HOST',false)?:'http://'.request()->host(); + return request()->header('Scheme','http')."://".request()->host(); } return request()->host(); } -- Gitee