123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace app\common\util;
- class Util
- {
-
- public static function getChildrenList($list, $option = []){
- $field = isset($option['field'])?$option['field']:'id';
- $parent_field = isset($option['parent_field'])?$option['parent_field']:'pid';
- $children_name = isset($option['children'])?$option['children']:'children';
- $default = isset($option['default'])?$option['default']:0;
-
- $index_data = [];
- foreach ($list as $item){
- $index_data[$item[$parent_field]][] = $item;
- }
- unset($item);
- return self::setChildren($index_data,$default,$field,$children_name);
- }
-
- private static function setChildren($index_data, $pid, $field, $children_name){
- if (isset($index_data[$pid])){
- $list = $index_data[$pid];
- foreach ($list as &$item){
- $children = self::setChildren($index_data,$item[$field],$field, $children_name);
- if (count($children)>0){
- $item[$children_name] = $children;
- }
- }
- return $list;
- }else{
- return [];
- }
- }
-
- public static function getPeriodDate($start_time,$end_time){
- $start_time = strtotime($start_time);
- $end_time = strtotime($end_time);
- $i = 0;
- $arr = [];
- while ($start_time <= $end_time){
- $arr[$i] = date('Y-m-d',$start_time);
- $start_time = strtotime('+1 day',$start_time);
- $i++;
- }
- return $arr;
- }
-
- public static function numToExcelLetter($num)
- {
-
- $base = 26;
- $result = '';
- while ($num > 0 ) {
- $mod = (int)($num % $base);
- $num = (int)($num / $base);
- if($mod == 0){
- $num -= 1;
- $temp = self::numToLetter($base) . $result;
- } elseif ($num == 0) {
- $temp = self::numToLetter($mod) . $result;
- } else {
- $temp = self::numToLetter($mod) . $result;
- }
- $result = $temp;
- }
- return $result;
- }
-
- public static function numToLetter($num)
- {
- if ($num == 0) {
- return '';
- }
- $num = (int)$num - 1;
-
- $ordA = ord('A');
- return chr($ordA + $num);
- }
- }
|