PublicData.php 1.5 KB

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