common.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. // 应用公共函数库文件
  13. use app\store\service\Auth;
  14. use app\common\service\store\User as StoreUserService;
  15. /**
  16. * 验证指定url是否有访问权限
  17. * @param string|array $url
  18. * @param bool $strict 严格模式
  19. * @return bool
  20. */
  21. function checkPrivilege($url, $strict = true)
  22. {
  23. try {
  24. return Auth::getInstance()->checkPrivilege($url, $strict);
  25. } catch (\Exception $e) {
  26. return false;
  27. }
  28. }
  29. /**
  30. * 日期转换时间戳(不保留时间)
  31. * 例如: 2020-04-01 08:15:08 => 1585670400
  32. * @param string $date
  33. * @return false|int
  34. */
  35. function str2time_date(string $date)
  36. {
  37. return strtotime(date('Y-m-d', strtotime($date)));
  38. }
  39. /**
  40. * 格式化起止时间(为了兼容前端RangePicker组件)
  41. * 2020-04-01T08:15:08.891Z => 1585670400
  42. * @param array $times
  43. * @return array
  44. */
  45. function between_time(array $times)
  46. {
  47. foreach ($times as &$time) {
  48. $time = trim($time, '&quot;');
  49. $time = str2time_date($time);
  50. }
  51. return ['start_time' => current($times), 'end_time' => next($times)];
  52. }