From f6c1dd3356bccff0e286d71ec6b519ec0215ceec Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Thu, 22 Nov 2018 18:20:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=BA=E5=B0=91=E4=B8=A4=E4=B8=AA=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 24 +++++++++++++++++++ extend/service/UtilService.php | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/application/common.php b/application/common.php index 5dbc159f..519a6707 100644 --- a/application/common.php +++ b/application/common.php @@ -33,4 +33,28 @@ function sensitive_words_filter($str) } } return ''; +} + +/** + * 上传路径转化,默认路径 UPLOAD_PATH + * $type 类型 + */ +function makePathToUrl($path,$type = 2) +{ + $path = DS.ltrim(rtrim($path)); + switch ($type){ + case 1: + $path .= DS.date('Y'); + break; + case 2: + $path .= DS.date('Y').DS.date('m'); + break; + case 3: + $path .= DS.date('Y').DS.date('m').DS.date('d'); + break; + } + if (is_dir(ROOT_PATH.UPLOAD_PATH.$path) == true || mkdir(ROOT_PATH.UPLOAD_PATH.$path, 0777, true) == true) { + return trim(str_replace(DS, '/',UPLOAD_PATH.$path),'.'); + }else return ''; + } \ No newline at end of file diff --git a/extend/service/UtilService.php b/extend/service/UtilService.php index 2c5f94fe..18b5b865 100644 --- a/extend/service/UtilService.php +++ b/extend/service/UtilService.php @@ -177,6 +177,49 @@ class UtilService } return $list; } + /** + * 分级返回多维数组 + * @param $data + * @param int $pid + * @param string $field + * @param string $pk + * @param int $level + * @return array + */ + public static function getChindNode($data, $pid = 0, $field = 'pid', $pk = 'id', $level = 1) + { + + static $list = []; + foreach ($data as $k => $res) { + if ($res['pid'] == $pid) { + $list[] = $res; + unset($data[$k]); + self::getChindNode($data, $res['id'], $field, $pk, $level + 1); + + } + } + return $list; + + + } + /**分级返回下级所有分类ID + * @param $data + * @param string $children + * @param string $field + * @param string $pk + * @return string + */ + public static function getChildrenPid($data,$pid, $field = 'pid', $pk = 'id') + { + static $pids = ''; + foreach ($data as $k => $res) { + if ($res[$field] == $pid) { + $pids .= ','.$res[$pk]; + self::getChildrenPid($data, $res[$pk], $field, $pk); + } + } + return $pids; + } /**