|
|
@ -21,13 +21,13 @@ use app\service\core\sys\CoreSysConfigService; |
|
|
* @param int $http_code |
|
|
* @param int $http_code |
|
|
* @return Response |
|
|
* @return Response |
|
|
*/ |
|
|
*/ |
|
|
function success($msg = 'SUCCESS', $data = [], int $code = 1, int $http_code = 200) : Response |
|
|
function success($msg = 'SUCCESS', $data = [], int $code = 1, int $http_code = 200): Response |
|
|
{ |
|
|
{ |
|
|
if (is_array($msg)) { |
|
|
if (is_array($msg)) { |
|
|
$data = $msg; |
|
|
$data = $msg; |
|
|
$msg = 'SUCCESS'; |
|
|
$msg = 'SUCCESS'; |
|
|
} |
|
|
} |
|
|
return Response::create([ 'data' => $data, 'msg' => get_lang($msg), 'code' => $code ], 'json', $http_code); |
|
|
return Response::create(['data' => $data, 'msg' => get_lang($msg), 'code' => $code], 'json', $http_code); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -39,13 +39,13 @@ function success($msg = 'SUCCESS', $data = [], int $code = 1, int $http_code = 2 |
|
|
* @param int $http_code |
|
|
* @param int $http_code |
|
|
* @return Response |
|
|
* @return Response |
|
|
*/ |
|
|
*/ |
|
|
function fail($msg = 'FAIL', ?array $data = [], int $code = 0, int $http_code = 200) : Response |
|
|
function fail($msg = 'FAIL', ?array $data = [], int $code = 0, int $http_code = 200): Response |
|
|
{ |
|
|
{ |
|
|
if (is_array($msg)) { |
|
|
if (is_array($msg)) { |
|
|
$data = $msg; |
|
|
$data = $msg; |
|
|
$msg = 'FAIL'; |
|
|
$msg = 'FAIL'; |
|
|
} |
|
|
} |
|
|
return Response::create([ 'data' => $data, 'msg' => get_lang($msg), 'code' => $code ], 'json', $http_code); |
|
|
return Response::create(['data' => $data, 'msg' => get_lang($msg), 'code' => $code], 'json', $http_code); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -76,17 +76,17 @@ function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'child', $root = |
|
|
// 创建基于主键的数组引用 |
|
|
// 创建基于主键的数组引用 |
|
|
$refer = array(); |
|
|
$refer = array(); |
|
|
foreach ($list as $key => $data) { |
|
|
foreach ($list as $key => $data) { |
|
|
$refer[ $data[ $pk ] ] =& $list[ $key ]; |
|
|
$refer[$data[$pk]] =& $list[$key]; |
|
|
} |
|
|
} |
|
|
foreach ($list as $key => $data) { |
|
|
foreach ($list as $key => $data) { |
|
|
// 判断是否存在parent |
|
|
// 判断是否存在parent |
|
|
$parent_id = $data[ $pid ]; |
|
|
$parent_id = $data[$pid]; |
|
|
if ($root == $parent_id) { |
|
|
if ($root == $parent_id) { |
|
|
$tree[] =& $list[ $key ]; |
|
|
$tree[] =& $list[$key]; |
|
|
} else { |
|
|
} else { |
|
|
if (isset($refer[ $parent_id ])) { |
|
|
if (isset($refer[$parent_id])) { |
|
|
$parent =& $refer[ $parent_id ]; |
|
|
$parent =& $refer[$parent_id]; |
|
|
$parent[ $child ][] =& $list[ $key ]; |
|
|
$parent[$child][] =& $list[$key]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -137,11 +137,11 @@ function array_keys_search($array, $keys, $index = '', $is_sort = true) |
|
|
$list = array(); |
|
|
$list = array(); |
|
|
|
|
|
|
|
|
foreach ($keys as $key) { |
|
|
foreach ($keys as $key) { |
|
|
if (isset($array[ $key ])) { |
|
|
if (isset($array[$key])) { |
|
|
if ($is_sort) { |
|
|
if ($is_sort) { |
|
|
$list[] = $array[ $key ]; |
|
|
$list[] = $array[$key]; |
|
|
} else { |
|
|
} else { |
|
|
$list[ $key ] = $array[ $key ]; |
|
|
$list[$key] = $array[$key]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -166,7 +166,7 @@ function del_target_dir($path, $delDir) |
|
|
//打开目录句柄 |
|
|
//打开目录句柄 |
|
|
$handle = opendir($path); |
|
|
$handle = opendir($path); |
|
|
if ($handle) { |
|
|
if ($handle) { |
|
|
while (false !== ( $item = readdir($handle) )) { |
|
|
while (false !== ($item = readdir($handle))) { |
|
|
if ($item != "." && $item != "..") { |
|
|
if ($item != "." && $item != "..") { |
|
|
if (is_dir("$path/$item")) { |
|
|
if (is_dir("$path/$item")) { |
|
|
del_target_dir("$path/$item", $delDir); |
|
|
del_target_dir("$path/$item", $delDir); |
|
|
@ -200,7 +200,7 @@ function system_name(?string $key = '') |
|
|
'channel_name' => env('system.channel_name', 'channel'), |
|
|
'channel_name' => env('system.channel_name', 'channel'), |
|
|
]; |
|
|
]; |
|
|
if (!empty($key)) { |
|
|
if (!empty($key)) { |
|
|
return $params[ $key ]; |
|
|
return $params[$key]; |
|
|
} else { |
|
|
} else { |
|
|
return $params; |
|
|
return $params; |
|
|
} |
|
|
} |
|
|
@ -219,11 +219,11 @@ function get_date_by_time(?int $time = null) |
|
|
|
|
|
|
|
|
function get_start_and_end_time_by_day($day = '') |
|
|
function get_start_and_end_time_by_day($day = '') |
|
|
{ |
|
|
{ |
|
|
$date = $day ? : date('Y-m-d'); |
|
|
$date = $day ?: date('Y-m-d'); |
|
|
$day_start_time = strtotime($date); |
|
|
$day_start_time = strtotime($date); |
|
|
//当天结束之间 |
|
|
//当天结束之间 |
|
|
$day_end_time = $day_start_time + 86400; |
|
|
$day_end_time = $day_start_time + 86400; |
|
|
return [ $day_start_time, $day_end_time ]; |
|
|
return [$day_start_time, $day_end_time]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -361,7 +361,7 @@ function format_money($number) |
|
|
function format_float_money($number, $precision = 2) |
|
|
function format_float_money($number, $precision = 2) |
|
|
{ |
|
|
{ |
|
|
if ($precision > 0) { |
|
|
if ($precision > 0) { |
|
|
return sprintf('%.' . $precision . 'f', floor($number * ( 10 ** $precision )) / ( 10 ** $precision )); |
|
|
return sprintf('%.' . $precision . 'f', floor($number * (10 ** $precision)) / (10 ** $precision)); |
|
|
} else { |
|
|
} else { |
|
|
return sprintf('%.' . $precision . 'f', floor($number)); |
|
|
return sprintf('%.' . $precision . 'f', floor($number)); |
|
|
} |
|
|
} |
|
|
@ -491,19 +491,19 @@ function array_merge2(array $array1, array $array2) |
|
|
if (array_key_exists($array2_k, $array1)) { |
|
|
if (array_key_exists($array2_k, $array1)) { |
|
|
if (is_array($array2_v)) { |
|
|
if (is_array($array2_v)) { |
|
|
foreach ($array2_v as $array2_kk => $array2_vv) { |
|
|
foreach ($array2_v as $array2_kk => $array2_vv) { |
|
|
if (array_key_exists($array2_kk, $array1[ $array2_k ])) { |
|
|
if (array_key_exists($array2_kk, $array1[$array2_k])) { |
|
|
if (is_array($array2_vv)) { |
|
|
if (is_array($array2_vv)) { |
|
|
$array1[ $array2_k ][ $array2_kk ] = array_merge($array1[ $array2_k ][ $array2_kk ], $array2_vv); |
|
|
$array1[$array2_k][$array2_kk] = array_merge($array1[$array2_k][$array2_kk], $array2_vv); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$array1[ $array2_k ][ $array2_kk ] = $array2_vv; |
|
|
$array1[$array2_k][$array2_kk] = $array2_vv; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$array1[ $array2_k ] = $array2_v; |
|
|
$array1[$array2_k] = $array2_v; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
$array1[ $array2_k ] = $array2_v; |
|
|
$array1[$array2_k] = $array2_v; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $array1; |
|
|
return $array1; |
|
|
@ -550,8 +550,8 @@ function dir_copy(string $src = '', string $dst = '', &$files = [], $exclude_dir |
|
|
} |
|
|
} |
|
|
$dir = opendir($src); |
|
|
$dir = opendir($src); |
|
|
dir_mkdir($dst); |
|
|
dir_mkdir($dst); |
|
|
while (false !== ( $file = readdir($dir) )) { |
|
|
while (false !== ($file = readdir($dir))) { |
|
|
if (( $file != '.' ) && ( $file != '..' )) { |
|
|
if (($file != '.') && ($file != '..')) { |
|
|
if (is_dir($src . '/' . $file)) { |
|
|
if (is_dir($src . '/' . $file)) { |
|
|
// 排除目录 |
|
|
// 排除目录 |
|
|
if (count($exclude_dirs) && in_array($file, $exclude_dirs)) continue; |
|
|
if (count($exclude_dirs) && in_array($file, $exclude_dirs)) continue; |
|
|
@ -631,7 +631,7 @@ function parse_sql($content = '', $string = false, $replace = []) |
|
|
// 多行注释标记 |
|
|
// 多行注释标记 |
|
|
$comment = false; |
|
|
$comment = false; |
|
|
// 按行分割,兼容多个平台 |
|
|
// 按行分割,兼容多个平台 |
|
|
$content = str_replace([ "\r\n", "\r" ], "\n", $content); |
|
|
$content = str_replace(["\r\n", "\r"], "\n", $content); |
|
|
$content = explode("\n", trim($content)); |
|
|
$content = explode("\n", trim($content)); |
|
|
// 循环处理每一行 |
|
|
// 循环处理每一行 |
|
|
foreach ($content as $line) { |
|
|
foreach ($content as $line) { |
|
|
@ -723,10 +723,10 @@ function getFileMap($path, $arr = []) |
|
|
if ($file_path != '.' && $file_path != '..') { |
|
|
if ($file_path != '.' && $file_path != '..') { |
|
|
$temp_path = $path . '/' . $file_path; |
|
|
$temp_path = $path . '/' . $file_path; |
|
|
if (is_dir($temp_path)) { |
|
|
if (is_dir($temp_path)) { |
|
|
$arr[ $temp_path ] = $file_path; |
|
|
$arr[$temp_path] = $file_path; |
|
|
$arr = getFileMap($temp_path, $arr); |
|
|
$arr = getFileMap($temp_path, $arr); |
|
|
} else { |
|
|
} else { |
|
|
$arr[ $temp_path ] = $file_path; |
|
|
$arr[$temp_path] = $file_path; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -751,9 +751,9 @@ function cache_remember(string $name = null, $value = '', $tag = null, $options |
|
|
$value = Container::getInstance()->invokeFunction($value); |
|
|
$value = Container::getInstance()->invokeFunction($value); |
|
|
} |
|
|
} |
|
|
if (is_null($tag)) { |
|
|
if (is_null($tag)) { |
|
|
Cache::set($name, $value, $options[ 'expire' ] ?? null); |
|
|
Cache::set($name, $value, $options['expire'] ?? null); |
|
|
} else { |
|
|
} else { |
|
|
Cache::tag($tag)->set($name, $value, $options[ 'expire' ] ?? null); |
|
|
Cache::tag($tag)->set($name, $value, $options['expire'] ?? null); |
|
|
} |
|
|
} |
|
|
return $value; |
|
|
return $value; |
|
|
|
|
|
|
|
|
@ -778,7 +778,7 @@ function image_to_base64(string $path, $is_delete = false) |
|
|
{ |
|
|
{ |
|
|
if (!file_exists($path)) return 'image not exist'; |
|
|
if (!file_exists($path)) return 'image not exist'; |
|
|
|
|
|
|
|
|
$mime = getimagesize($path)[ 'mime' ]; |
|
|
$mime = getimagesize($path)['mime']; |
|
|
$image_data = file_get_contents($path); |
|
|
$image_data = file_get_contents($path); |
|
|
// 将图片转换为 base64 |
|
|
// 将图片转换为 base64 |
|
|
$base64_data = base64_encode($image_data); |
|
|
$base64_data = base64_encode($image_data); |
|
|
@ -799,7 +799,7 @@ function image_to_base64(string $path, $is_delete = false) |
|
|
function get_thumb_images($image, $thumb_type = 'all', bool $is_throw_exception = false) |
|
|
function get_thumb_images($image, $thumb_type = 'all', bool $is_throw_exception = false) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
return ( new CoreImageService() )->thumb($image, $thumb_type, $is_throw_exception); |
|
|
return (new CoreImageService())->thumb($image, $thumb_type, $is_throw_exception); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -811,10 +811,10 @@ function version_to_int($version) |
|
|
{ |
|
|
{ |
|
|
$version_array = explode(".", $version); |
|
|
$version_array = explode(".", $version); |
|
|
|
|
|
|
|
|
$v1 = sprintf('%03s', (int) $version_array[ 0 ] ?? 0); |
|
|
$v1 = sprintf('%03s', (int)$version_array[0] ?? 0); |
|
|
$v2 = sprintf('%03s', (int) $version_array[ 1 ] ?? 0); |
|
|
$v2 = sprintf('%03s', (int)$version_array[1] ?? 0); |
|
|
$v3 = sprintf('%03s', (int) $version_array[ 2 ] ?? 0); |
|
|
$v3 = sprintf('%03s', (int)$version_array[2] ?? 0); |
|
|
return (int) "{$v1}{$v2}{$v3}"; |
|
|
return (int)"{$v1}{$v2}{$v3}"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -827,13 +827,13 @@ function version_to_string($ver) |
|
|
if ($ver > 999) { |
|
|
if ($ver > 999) { |
|
|
if ($ver > 999999) { |
|
|
if ($ver > 999999) { |
|
|
$ver .= ""; |
|
|
$ver .= ""; |
|
|
$v3 = (int) substr($ver, -3); |
|
|
$v3 = (int)substr($ver, -3); |
|
|
$v2 = (int) substr($ver, -6, 3); |
|
|
$v2 = (int)substr($ver, -6, 3); |
|
|
$v1 = (int) substr($ver, 0, -6); |
|
|
$v1 = (int)substr($ver, 0, -6); |
|
|
} else { |
|
|
} else { |
|
|
$ver .= ""; |
|
|
$ver .= ""; |
|
|
$v3 = (int) substr($ver, -3); |
|
|
$v3 = (int)substr($ver, -3); |
|
|
$v2 = (int) substr($ver, 0, -3); |
|
|
$v2 = (int)substr($ver, 0, -3); |
|
|
$v1 = 0; |
|
|
$v1 = 0; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
@ -889,10 +889,10 @@ function file_copy(string $source_file, string $to_file) |
|
|
* @param $size |
|
|
* @param $size |
|
|
* @return string |
|
|
* @return string |
|
|
*/ |
|
|
*/ |
|
|
function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = [ 'is_transparent' => true ], $outfile = true) |
|
|
function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = ['is_transparent' => true], $outfile = true) |
|
|
{ |
|
|
{ |
|
|
if ($outfile) { |
|
|
if ($outfile) { |
|
|
$dir = $dir ? : 'upload' . '/' . 'qrcode/';//二维码默认存储位置 |
|
|
$dir = $dir ?: 'upload' . '/' . 'qrcode/';//二维码默认存储位置 |
|
|
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { |
|
|
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { |
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
|
|
} |
|
|
} |
|
|
@ -911,8 +911,8 @@ function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = [ 'is_t |
|
|
'channel' => $channel, |
|
|
'channel' => $channel, |
|
|
'outfile' => $outfile |
|
|
'outfile' => $outfile |
|
|
]))); |
|
|
]))); |
|
|
if (!empty($result[ 0 ])) { |
|
|
if (!empty($result[0])) { |
|
|
$path = $result[ 0 ]; |
|
|
$path = $result[0]; |
|
|
} |
|
|
} |
|
|
return $path; |
|
|
return $path; |
|
|
} |
|
|
} |
|
|
@ -928,7 +928,7 @@ function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = [ 'is_t |
|
|
*/ |
|
|
*/ |
|
|
function poster($id, $type, array $param = [], string $channel = '', bool $is_throw_exception = true) |
|
|
function poster($id, $type, array $param = [], string $channel = '', bool $is_throw_exception = true) |
|
|
{ |
|
|
{ |
|
|
return ( new \app\service\core\poster\CorePosterService() )->get($id, $type, $param, $channel, $is_throw_exception); |
|
|
return (new \app\service\core\poster\CorePosterService())->get($id, $type, $param, $channel, $is_throw_exception); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -949,7 +949,7 @@ function is_url($string) |
|
|
* 获取站点插件 |
|
|
* 获取站点插件 |
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
function get_site_addons() : array |
|
|
function get_site_addons(): array |
|
|
{ |
|
|
{ |
|
|
$addons = Cache::get("local_install_addons"); |
|
|
$addons = Cache::get("local_install_addons"); |
|
|
return is_null($addons) ? [] : $addons; |
|
|
return is_null($addons) ? [] : $addons; |
|
|
@ -957,7 +957,7 @@ function get_site_addons() : array |
|
|
|
|
|
|
|
|
function get_wap_domain() |
|
|
function get_wap_domain() |
|
|
{ |
|
|
{ |
|
|
$wap_url = ( new CoreSysConfigService() )->getSceneDomain()[ 'wap_url' ]; |
|
|
$wap_url = (new CoreSysConfigService())->getSceneDomain()['wap_url']; |
|
|
return $wap_url; |
|
|
return $wap_url; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -970,7 +970,7 @@ function get_wap_domain() |
|
|
*/ |
|
|
*/ |
|
|
function str_sub($str, $length = 10, $is_need_apostrophe = true) |
|
|
function str_sub($str, $length = 10, $is_need_apostrophe = true) |
|
|
{ |
|
|
{ |
|
|
return mb_substr($str, 0, $length, 'UTF-8') . ( $is_need_apostrophe ? '...' : '' ); |
|
|
return mb_substr($str, 0, $length, 'UTF-8') . ($is_need_apostrophe ? '...' : ''); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -1010,10 +1010,10 @@ function get_last_time($time = null) |
|
|
$text = floor($t / 60) . '分钟前'; //一小时内 |
|
|
$text = floor($t / 60) . '分钟前'; //一小时内 |
|
|
break; |
|
|
break; |
|
|
case $t < 60 * 60 * 24: |
|
|
case $t < 60 * 60 * 24: |
|
|
$text = floor($t / ( 60 * 60 )) . '小时前'; // 一天内 |
|
|
$text = floor($t / (60 * 60)) . '小时前'; // 一天内 |
|
|
break; |
|
|
break; |
|
|
case $t < 60 * 60 * 24 * 3: |
|
|
case $t < 60 * 60 * 24 * 3: |
|
|
$text = floor($time / ( 60 * 60 * 24 )) == 1 ? '昨天' . date('H:i', $time) : '前天' . date('H:i', $time); //昨天和前天 |
|
|
$text = floor($time / (60 * 60 * 24)) == 1 ? '昨天' . date('H:i', $time) : '前天' . date('H:i', $time); //昨天和前天 |
|
|
break; |
|
|
break; |
|
|
case $t < 60 * 60 * 24 * 30: |
|
|
case $t < 60 * 60 * 24 * 30: |
|
|
$text = date('m-d H:i', $time); //一个月内 |
|
|
$text = date('m-d H:i', $time); //一个月内 |
|
|
@ -1028,21 +1028,22 @@ function get_last_time($time = null) |
|
|
return $text; |
|
|
return $text; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function get_campus_where($user_id){ |
|
|
function get_campus_where($user_id) |
|
|
|
|
|
{ |
|
|
$where = []; |
|
|
$where = []; |
|
|
if($user_id == 1){ |
|
|
if ($user_id == 1) { |
|
|
return $where; |
|
|
return $where; |
|
|
} |
|
|
} |
|
|
$personnel = new Personnel(); |
|
|
$personnel = new Personnel(); |
|
|
$role = new CampusPersonRole(); |
|
|
$role = new CampusPersonRole(); |
|
|
$personnel_id = $personnel->where(['sys_user_id' => $user_id])->value('id'); |
|
|
$personnel_id = $personnel->where(['sys_user_id' => $user_id])->value('id'); |
|
|
if(!$personnel_id){ |
|
|
if (!$personnel_id) { |
|
|
$where[] = ['campus_id','in',[]]; |
|
|
$where[] = ['campus_id', 'in', []]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$campus_ids = $role->where(['person_id' => $personnel_id])->column('campus_id'); |
|
|
$campus_ids = $role->where(['person_id' => $personnel_id])->column('campus_id'); |
|
|
|
|
|
|
|
|
$where[] = ['campus_id','in',$campus_ids]; |
|
|
$where[] = ['campus_id', 'in', $campus_ids]; |
|
|
|
|
|
|
|
|
return $where; |
|
|
return $where; |
|
|
} |
|
|
} |
|
|
@ -1074,3 +1075,13 @@ function getModifiedFields(array $oldData, array $newData): array |
|
|
'new_values' => json_encode($newValues, JSON_UNESCAPED_UNICODE), |
|
|
'new_values' => json_encode($newValues, JSON_UNESCAPED_UNICODE), |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取员工编号 |
|
|
|
|
|
function getEmployeeNumber() |
|
|
|
|
|
{ |
|
|
|
|
|
$personnel = new Personnel(); |
|
|
|
|
|
// 获取最新id |
|
|
|
|
|
$max_id = $personnel->max('id') + 1; |
|
|
|
|
|
$max_id = str_pad($max_id, 5, '0', STR_PAD_LEFT); |
|
|
|
|
|
return date('Ymd') . $max_id; |
|
|
|
|
|
} |