Config.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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::where(['field'=>'autoTask'])->value('val');
  15. if($autoTask){
  16. return $autoTask;
  17. }else{
  18. $autoTask=[
  19. 'group_id'=>0, //群聊ID
  20. 'group_num'=>1, //群聊序号
  21. 'user_id'=>0, //上一次的客服ID
  22. ];
  23. Config::create(['field'=>'autoTask','val'=>$autoTask]);
  24. return $autoTask;
  25. }
  26. }
  27. public static function changeList($list) {
  28. foreach($list as &$item) {
  29. $item['name'] = $item['field'];
  30. $item['value'] = $item['val'];
  31. }
  32. return $list;
  33. }
  34. // 获取系统配置信息
  35. public static function getSystemInfo($update=false){
  36. $name='systemInfo';
  37. // $auth=request()->header('Authorization');
  38. $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'];
  39. // 如果是登录状态才会返回chatINfo
  40. // if($auth){
  41. // $name='all'.$name;
  42. // $nameFields[]="chatInfo";
  43. // }
  44. if(Cache::has($name) && !$update){
  45. $systemInfo=Cache::get($name);
  46. }else{
  47. $systemInfo=[];
  48. $conf=Config::where([['field','in',$nameFields]])->select()->toArray();
  49. foreach($conf as $v){
  50. $value=[];
  51. if($v['field']=='fileUpload'){
  52. $value['size'] = $v['val']['size'];
  53. $value['preview'] = $v['val']['preview'];
  54. $value['fileExt'] = $v['val']['fileExt'];
  55. }else{
  56. $value=$v['val'];
  57. }
  58. $systemInfo[$v['field']]=$value;
  59. }
  60. Cache::set($name,$systemInfo,7*86400);
  61. }
  62. return $systemInfo;
  63. }
  64. }