Config.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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';
  29. // $auth=request()->header('Authorization');
  30. $nameFields=['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. return $systemInfo;
  58. }
  59. //获取指定配置的数据
  60. public static function getFieldValue($field)
  61. {
  62. $config = self::where('field', $field)->find();
  63. if (!empty($config['type']) && $config['type'] == 'rich_text') {
  64. return $config['val'] ? json_decode($config['val'], true) : '';
  65. }
  66. return '';
  67. }
  68. }