Config.php 2.5 KB

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