Config.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * raingad IM [ThinkPHP6]
  4. * @author xiekunyu <raingad@foxmail.com>
  5. */
  6. namespace app\manage\model;
  7. use app\BaseModel;
  8. use think\facade\Cache;
  9. class Config extends BaseModel
  10. {
  11. protected $json = ['value'];
  12. protected $jsonAssoc = true;
  13. // 获取系统配置信息
  14. public static function getSystemInfo($update=false){
  15. $name='systemInfo';
  16. // $auth=request()->header('Authorization');
  17. $nameFields=['sysInfo','fileUpload','chatInfo'];
  18. // 如果是登录状态才会返回chatINfo
  19. // if($auth){
  20. // $name='all'.$name;
  21. // $nameFields[]="chatInfo";
  22. // }
  23. if(Cache::has($name) && !$update){
  24. $systemInfo=Cache::get($name);
  25. }else{
  26. $systemInfo=[];
  27. $conf=Config::where([['name','in',$nameFields]])->select()->toArray();
  28. foreach($conf as $v){
  29. $value=[];
  30. if($v['name']=='fileUpload'){
  31. $value['size'] = $v['value']['size'];
  32. $value['preview'] = $v['value']['preview'];
  33. $value['fileExt'] = $v['value']['fileExt'];
  34. }else{
  35. $value=$v['value'];
  36. }
  37. $systemInfo[$v['name']]=$value;
  38. }
  39. Cache::set($name,$systemInfo,7*86400);
  40. }
  41. return $systemInfo;
  42. }
  43. }