PublicData.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Tools;
  3. use Hyperf\Snowflake\IdGeneratorInterface;
  4. use Hyperf\Context\ApplicationContext;
  5. class PublicData
  6. {
  7. /**
  8. * 递归查询
  9. * @param $menuItems
  10. * @param $parentId
  11. * @return array
  12. */
  13. public static function buildMenuTree($menuItems, $parentId = 0) {
  14. $tree = [];
  15. foreach ($menuItems as $item) {
  16. if ($item['pid'] == $parentId) {
  17. // 找到子菜单
  18. $children = self::buildMenuTree($menuItems, $item['id']);
  19. // 如果子菜单存在,则添加到当前菜单的children中
  20. if ($children) {
  21. $item['children'] = $children;
  22. }
  23. // 将当前菜单添加到树中
  24. $tree[] = $item;
  25. }
  26. }
  27. return $tree;
  28. }
  29. /**
  30. * 计算两个时间差的天数
  31. * @param $sTime
  32. * @param $eTime
  33. * @return float
  34. */
  35. public static function residueDay($sTime,$eTime)
  36. {
  37. $startTime = strtotime($sTime);
  38. $endTime = strtotime($eTime);
  39. $diffDays = floor(($endTime - $startTime) / (60 * 60 * 24));
  40. return $diffDays;
  41. }
  42. public static function uuid()
  43. {
  44. $container = ApplicationContext::getContainer();
  45. $generator = $container->get(IdGeneratorInterface::class);
  46. return $generator->generate();
  47. }
  48. }