Config.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = ['val'];
  12. protected $jsonAssoc = true;
  13. public static function changeList($list) {
  14. foreach($list as &$item) {
  15. $item['name'] = $item['field'];
  16. $item['value'] = $item['val'];
  17. }
  18. return $list;
  19. }
  20. // 获取系统配置信息
  21. public static function getSystemInfo($update=false){
  22. $name='systemInfo';
  23. // $auth=request()->header('Authorization');
  24. $nameFields=['sysInfo','fileUpload','chatInfo','compass'];
  25. // 如果是登录状态才会返回chatINfo
  26. // if($auth){
  27. // $name='all'.$name;
  28. // $nameFields[]="chatInfo";
  29. // }
  30. if(Cache::has($name) && !$update){
  31. $systemInfo=Cache::get($name);
  32. }else{
  33. $systemInfo=[];
  34. $conf=Config::where([['field','in',$nameFields]])->select()->toArray();
  35. foreach($conf as $v){
  36. $value=[];
  37. if($v['field']=='fileUpload'){
  38. $value['size'] = $v['val']['size'];
  39. $value['preview'] = $v['val']['preview'];
  40. $value['fileExt'] = $v['val']['fileExt'];
  41. }else{
  42. $value=$v['val'];
  43. }
  44. $systemInfo[$v['field']]=$value;
  45. }
  46. Cache::set($name,$systemInfo,7*86400);
  47. }
  48. return $systemInfo;
  49. }
  50. }