You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.1 KiB

  1. <?php
  2. namespace addons\unishop\model;
  3. use think\Cache;
  4. use think\Model;
  5. class Config extends Model
  6. {
  7. // 表名
  8. protected $name = 'unishop_config';
  9. // 开启自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. /**
  15. * 获取系统配置
  16. * @param $name
  17. * @return mixed|\think\db\Query
  18. */
  19. public static function getByName($name)
  20. {
  21. if (Cache::has('configGetByName_'. $name)) {
  22. $config = Cache::get('configGetByName_'. $name);
  23. } else {
  24. $config = parent::__callStatic('getByName', [$name]);
  25. $expire = self::__callStatic('getByName', ['cache_expire'])['value'];
  26. Cache::set('configGetByName_'. $name, $config, $expire);
  27. }
  28. return $config;
  29. }
  30. /**
  31. * 判断当前是不是使用悲观锁
  32. * @return bool
  33. */
  34. public static function isPessimism()
  35. {
  36. return self::getByName('lock')['value'] == 'pessimism' ? true : false;
  37. }
  38. /**
  39. * 获取图片完整连接
  40. */
  41. public static function getImagesFullUrl($value = '')
  42. {
  43. if (stripos($value, 'http') === 0 || $value === '' || stripos($value, 'data:image') === 0) {
  44. return $value;
  45. } else {
  46. $upload = \think\Config::get('upload');
  47. if (!empty($upload['cdnurl'])) {
  48. return $upload['cdnurl'] . $value;
  49. } else {
  50. $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
  51. return $http_type . $_SERVER['HTTP_HOST'] . $value;
  52. }
  53. }
  54. }
  55. /**
  56. * 时间戳 - 精确到毫秒
  57. * @return float
  58. */
  59. public static function getMillisecond() {
  60. list($t1, $t2) = explode(' ', microtime());
  61. return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
  62. }
  63. }