functions.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/7/16
  6. * Time: 17:46
  7. */
  8. //保留小数位数
  9. function floatPointDigit($data, $long = 2)
  10. {
  11. $long = intval($long);
  12. $for1 = "%." . $long . "f";
  13. $for2 = "%." . ($long + 1) . "f";
  14. return sprintf($for1, substr(sprintf($for2, $data), 0, -1));
  15. }
  16. /**
  17. * UUID 生成
  18. */
  19. function UUID()
  20. {
  21. $prefix = '';
  22. $uuid = '';
  23. $str = md5(uniqid(mt_rand(), true));
  24. $uuid = substr($str, 0, 8) . '-';
  25. $uuid .= substr($str, 8, 4) . '-';
  26. $uuid .= substr($str, 12, 4) . '-';
  27. $uuid .= substr($str, 16, 4) . '-';
  28. $uuid .= substr($str, 20, 12);
  29. return $prefix . $uuid;
  30. }
  31. //把订单转为带字符串的包裹的字符
  32. function orders_to_str($order_array)
  33. {
  34. return array_map(function ($i) {
  35. return strval("'$i'");
  36. }, $order_array);
  37. }
  38. //把订单转为带字符串的包裹的字符
  39. function orders_to_strval($order_array)
  40. {
  41. return array_map(function ($i) {
  42. return strval($i);
  43. }, $order_array);
  44. }