common.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  12. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  13. use PhpOffice\PhpSpreadsheet\Reader\Xls;
  14. use PhpOffice\PhpSpreadsheet\IOFactory;
  15. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  16. use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
  17. use PhpOffice\PhpSpreadsheet\Cell\DataType;
  18. use PhpOffice\PhpSpreadsheet\Style\Fill;
  19. use PhpOffice\PhpSpreadsheet\Style\Color;
  20. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  21. use PhpOffice\PhpSpreadsheet\Style\Border;
  22. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  23. // 应用公共文件
  24. /**
  25. * 删除目录以及其下的文件
  26. * @param $directory
  27. * @return bool
  28. */
  29. function removeDir($directory)
  30. {
  31. if (false == is_dir($directory)) {
  32. return false;
  33. }
  34. $handle = opendir($directory);
  35. while (false !== ($file = readdir($handle))) {
  36. if ('.' != $file && '..' != $file) {
  37. is_dir("$directory/$file") ? removeDir("$directory/$file") : @unlink("$directory/$file");
  38. }
  39. }
  40. if (readdir($handle) == false) {
  41. closedir($handle);
  42. rmdir($directory);
  43. }
  44. return true;
  45. }
  46. function Kfid($uid)
  47. {
  48. return trim($uid, 'KF');
  49. }
  50. function kfUid($id)
  51. {
  52. return 'KF' . $id;
  53. }
  54. //数组转为健的数组
  55. function kftoKey($uidArray, $type = 0)
  56. {
  57. $return = [];
  58. foreach ($uidArray as $val) {
  59. if ($type == 0) {
  60. $return[$val] = 0;
  61. } elseif ($type == 1) {
  62. $return[$val] = [];
  63. } else {
  64. $return[$val] = $val;
  65. }
  66. }
  67. return $return;
  68. }
  69. //保留小数位数
  70. function floatPointDigit($data, $long = 2)
  71. {
  72. $long = intval($long);
  73. $for1 = "%." . $long . "f";
  74. $for2 = "%." . ($long + 1) . "f";
  75. return sprintf($for1, substr(sprintf($for2, $data), 0, -1));
  76. }
  77. //秒格式化为 小时分秒
  78. function secendToHourMinit($sec)
  79. {
  80. $array = ['h' => 0, 'm' => 0, 's' => 0];
  81. $sec = intval($sec);
  82. $array['h'] = floor($sec / 3600);
  83. $array['m'] = floor(($sec - 3600 * $array['h']) / 60);
  84. $array['s'] = $sec - 3600 * $array['h'] - 60 * $array['m'];
  85. $return = '';
  86. if ($array['h']) {
  87. $return .= $array['h'] . '小时';
  88. }
  89. if ($array['m']) {
  90. $return .= $array['m'] . '分';
  91. }
  92. if ($array['s']) {
  93. $return .= $array['s'] . '秒';
  94. }
  95. return $return;
  96. }
  97. //小数转百分比显示
  98. function perDisplay($dit, $xiaos = 2)
  99. {
  100. return floatPointDigit(floor(100 * $dit), $xiaos) . '%';
  101. }