erp/app/Utils/FormatUtils.php

51 lines
1.3 KiB
PHP

<?php
namespace App\Utils;
class FormatUtils
{
/**
* 格式化为树形结构
* @param $menus
* @param $parentValue
* @param string $juniorTitle //下级标题
* @param string $parentKey
* @param string $subKey
* @param string $useKey
* @return array
*/
public static function formatTreeData($menus, $parentValue, $juniorTitle = 'children', $parentKey = 'parent_id', $subKey = 'id', $useKey = '')
{
$data = [];
foreach ($menus as $menu) {
if ($menu[$parentKey] == $parentValue) {
$res = self::formatTreeData($menus, $menu[$subKey], $juniorTitle, $parentKey, $subKey, $useKey);
if (!empty($res)) {
$menu[$juniorTitle] = $res;
}
if ($useKey) {
$data[$menu[$useKey]] = $menu;
} else {
$data[] = $menu;
}
}
}
return $data;
}
/**
* 今天7点到明天7点算作今天
*/
public static function date()
{
$time = time();
$inventoryTime = strtotime(date('Y-m-d 07:00:00'));
if ($time < $inventoryTime) {
$time = strtotime('-1 day');
}
return date('Y-m-d', $time);
}
}