123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Tools;
- use App\Constants\ErrorCode;
- use Hyperf\Snowflake\IdGeneratorInterface;
- use Hyperf\Context\ApplicationContext;
- class PublicData
- {
- /**
- * 递归查询
- * @param $menuItems
- * @param $parentId
- * @return array
- */
- public static function buildMenuTree($menuItems, $parentId = 0) {
- $tree = [];
- foreach ($menuItems as $item) {
- if ($item['pid'] == $parentId) {
- // 找到子菜单
- $children = self::buildMenuTree($menuItems, $item['id']);
- // 如果子菜单存在,则添加到当前菜单的children中
- if ($children) {
- $item['children'] = $children;
- }
- // 将当前菜单添加到树中
- $tree[] = $item;
- }
- }
- return $tree;
- }
- /**
- * 计算两个时间差的天数
- * @param $sTime
- * @param $eTime
- * @return float
- */
- public static function residueDay($sTime,$eTime)
- {
- $startTime = strtotime($sTime);
- $endTime = strtotime($eTime);
- $diffDays = floor(($endTime - $startTime) / (60 * 60 * 24));
- return $diffDays;
- }
- public static function uuid()
- {
- var_dump("uuid==========");
- $container = ApplicationContext::getContainer();
- $generator = $container->get(IdGeneratorInterface::class);
- var_dump("uuid==+++++++++++",$generator->generate());
- return $generator->generate();
- }
- }
|