Config.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 autoTask(){
  14. $autoTask=Config::getFieldValue('autoTask');
  15. if($autoTask){
  16. return $autoTask;
  17. }
  18. }
  19. public static function changeList($list) {
  20. foreach($list as &$item) {
  21. $item['name'] = $item['field'];
  22. $item['value'] = $item['val'];
  23. }
  24. return $list;
  25. }
  26. // 获取系统配置信息
  27. public static function getSystemInfo($update=false){
  28. $name='systemInfo_config';
  29. // $auth=request()->header('Authorization');
  30. $nameFields=['translate','sysInfo','fileUpload','chatInfo','compass','kefu_cancel_message','user_open_comment', 'user_open_special_comment', 'user_send_gap_time', 'user_open_speech', 'user_show_kefu_read','user_cancel_message','user_cancel_message_time','platform_head_logo','platform_head_logo_night','pc_title_color','platform_logo','platform_name','platform_logo_night'];
  31. // 如果是登录状态才会返回chatINfo
  32. // if($auth){
  33. // $name='all'.$name;
  34. // $nameFields[]="chatInfo";
  35. // }
  36. if(Cache::has($name) && !$update){
  37. $systemInfo=Cache::get($name);
  38. }else{
  39. $systemInfo=[];
  40. $conf=Config::where([['field','in',$nameFields]])->select()->toArray();
  41. foreach($conf as $v){
  42. $value=[];
  43. if ($v['type'] == 'rich_text') {
  44. $v['val'] = json_decode($v['val'], true);
  45. }
  46. if($v['field']=='fileUpload'){
  47. $value['size'] = $v['val']['size'];
  48. $value['preview'] = $v['val']['preview'];
  49. $value['fileExt'] = $v['val']['fileExt'];
  50. }else{
  51. $value=$v['val'];
  52. }
  53. $systemInfo[$v['field']]=$value;
  54. }
  55. Cache::set($name,$systemInfo,7*86400);
  56. }
  57. if (isset($systemInfo['translate']) && empty(getEnvValue('GOOGLE_KEY') )) {
  58. $systemInfo['translate'] = '0';
  59. }
  60. return $systemInfo;
  61. }
  62. //获取指定配置的数据
  63. public static function getFieldValue($field, $language_code = '')
  64. {
  65. $where['field'] = $field;
  66. if($language_code){
  67. $where['language_code'] = $language_code;
  68. }
  69. $config = self::where($where)->find();
  70. if (!empty($config['type']) && $config['type'] == 'rich_text') {
  71. return $config['val'] ? json_decode($config['val'], true) : '';
  72. }
  73. return $config['val'];
  74. }
  75. }