SettingModel.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * @description:
  4. * @Date: 2022-09-26 20:27:01
  5. * @LastEditTime: 2022-09-26 20:27:53
  6. */
  7. namespace app\model;
  8. use think\facade\Cache;
  9. use think\Model;
  10. class SettingModel extends Model
  11. {
  12. protected $name = "setting";
  13. protected $pk = "keys";
  14. static $CacheConfig = false;
  15. public static function Config($key = false, $default = '##')
  16. {
  17. $config = self::$CacheConfig;
  18. if (!$config) {
  19. $config = Cache::get('webConfig');
  20. if (!$config) {
  21. $config = self::select()->toArray();
  22. $config = array_column($config, 'value', 'keys');
  23. Cache::set('webConfig', $config, 300);
  24. }
  25. }
  26. if ($key) {
  27. if (isset($config[$key])) {
  28. return $config[$key];
  29. }
  30. if ($default !== '##') {
  31. return $default;
  32. }
  33. }
  34. return $config;
  35. }
  36. public static function refreshSetting()
  37. {
  38. Cache::delete('webConfig');
  39. }
  40. }