SettingModel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 array $CacheConfig = [];
  15. public static function Config($key = false, $default = '##')
  16. {
  17. $config = self::$CacheConfig;
  18. if (count($config) == 0) {
  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. self::$CacheConfig = $config;
  25. }
  26. }
  27. if ($key) {
  28. if (isset($config[$key])) {
  29. return $config[$key];
  30. }
  31. if ($default !== '##') {
  32. return $default;
  33. }
  34. }
  35. return $config;
  36. }
  37. public static function refreshSetting()
  38. {
  39. Cache::delete('webConfig');
  40. }
  41. }