12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace addons\unishop\model;
- use think\Cache;
- use think\Model;
- class Config extends Model
- {
-
- protected $name = 'unishop_config';
-
- protected $autoWriteTimestamp = 'int';
-
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- public static function getByName($name)
- {
- if (Cache::has('configGetByName_'. $name)) {
- $config = Cache::get('configGetByName_'. $name);
- } else {
- $config = parent::__callStatic('getByName', [$name]);
- $expire = self::__callStatic('getByName', ['cache_expire'])['value'];
- Cache::set('configGetByName_'. $name, $config, $expire);
- }
- return $config;
- }
-
- public static function isPessimism()
- {
- return self::getByName('lock')['value'] == 'pessimism' ? true : false;
- }
-
- public static function getImagesFullUrl($value = '')
- {
- if (stripos($value, 'http') === 0 || $value === '' || stripos($value, 'data:image') === 0) {
- return $value;
- } else {
- $upload = \think\Config::get('upload');
- if (!empty($upload['cdnurl'])) {
- return $upload['cdnurl'] . $value;
- } else {
- return self::getHttpLocation() . $value;
- }
- }
- }
-
- public static function getHttpLocation() {
- $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
- return $http_type . $_SERVER['HTTP_HOST'];
- }
-
- public static function getMillisecond() {
- list($t1, $t2) = explode(' ', microtime());
- return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
- }
- }
|