Config.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User Julyssn
  5. * Date 2022/12/14 17:24
  6. */
  7. namespace app\manage\controller;
  8. use app\BaseController;
  9. use app\manage\model\{Config as Conf};
  10. use think\facade\Cache;
  11. class Config extends BaseController
  12. {
  13. /**
  14. * 获取单个配置
  15. * @return \think\response\Json
  16. */
  17. public function getInfo()
  18. {
  19. $name=$this->request->param('name');
  20. $data = Conf::where(['name'=>$name])->value('value');
  21. return success('', $data);
  22. }
  23. /**
  24. * 获取配置
  25. * @return \think\response\Json
  26. */
  27. public function getAllConfig()
  28. {
  29. $name=['sysInfo','chatInfo','smtp','fileUpload'];
  30. $list = Conf::where(['name'=>$name])->select();
  31. return success('', $list);
  32. }
  33. /**
  34. * 修改配置
  35. * @return \think\response\Json
  36. */
  37. public function setConfig()
  38. {
  39. $name = $this->request->param('name');
  40. $value = $this->request->param('value');
  41. if(Conf::where(['name'=>$name])->find()){
  42. Conf::where(['name'=>$name])->update(['value'=>$value]);
  43. }else{
  44. Conf::create(['name'=>$name,'value'=>$value]);
  45. }
  46. if($name=='fileUpload'){
  47. updateEnv('driver',$value['disk']);
  48. updateEnv('own',$value['preview']);
  49. foreach ($value['aliyun'] as $k=>$v){
  50. if($v){
  51. updateEnv('aliyun_'.$k,$v);
  52. }
  53. }
  54. foreach ($value['qiniu'] as $k=>$v){
  55. if($v){
  56. updateEnv('qiniu_'.$k,$v);
  57. }
  58. }
  59. foreach ($value['qcloud'] as $k=>$v){
  60. if($v){
  61. updateEnv('qcloud_'.$k,$v);
  62. }
  63. }
  64. }else{
  65. // 更新系统缓存
  66. Conf::getSystemInfo(true);
  67. }
  68. return success('保存成功');
  69. }
  70. /**
  71. * 获取邀请链接
  72. * @return \think\response\Json
  73. */
  74. public function getInviteLink(){
  75. $uid=$this->userInfo['user_id'];
  76. // 邀请码仅两天有效
  77. $code=\utils\Str::random(8);
  78. Cache::set($code,$uid,172800);
  79. $url=request()->domain().'/index.html/#/register?inviteCode='.$code;
  80. return success('',$url);
  81. }
  82. // 发送测试邮件
  83. public function sendTestEmail(){
  84. $email=$this->request->param('email');
  85. if(!$email || !(\utils\Regular::is_email($email))){
  86. return warning('请输入正确的邮箱');
  87. }
  88. $conf=Conf::where(['name'=>'smtp'])->value('value');
  89. $mail=new \mail\Mail($conf);
  90. $mail->sendEmail([$email],'测试邮件','这是一封测试邮件,当您收到之后表明您的所有配置都是正确的!');
  91. return success('发送成功');
  92. }
  93. }