1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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(empty($value)) return $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);
- }
- }
|