Webconfig.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2019/12/5
  6. * Time: 17:44
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\controller\base\Permissions;
  10. use app\admin\model\AdminLog;
  11. use app\admin\model\Urlconfig;
  12. use think\Cache;
  13. use think\Db;
  14. class Webconfig extends Permissions
  15. {
  16. public function index()
  17. {
  18. $this->assign('web_config', Db::name('webconfig')->where('id', 1)->find());
  19. $this->assign('is_close_site_key', (new Urlconfig())->getCloseSiteKey());
  20. $this->assign('admin_log_num', (new AdminLog())->count());
  21. $this->assign('backend_pass', (new Urlconfig())->getBackendPass());
  22. $this->assign('default_static_path', \app\common\model\Templet::DEFAULT_STATIC_PATH);
  23. $this->assign('default_templet_path', \app\common\model\Templet::DEFAULT_TEMPLET_PATH);
  24. $this->assign('default_backup_path', Databackup::DEFAULT_PATH);
  25. $grouptabs = (new \app\common\model\ConfigTab())->order('sort desc')->select();
  26. $this->assign('tabs', $grouptabs);
  27. return $this->fetch();
  28. }
  29. public function publish()
  30. {
  31. if ($this->request->isPost()) {
  32. $post = $this->request->post();
  33. $validate = new \think\Validate([
  34. ['file_type', 'requireWith:name', '上传类型不能为空'],
  35. ['file_size', 'requireWith:name', '上传大小不能为空'],
  36. ['host', 'url'],
  37. ]);
  38. if (!$validate->check($post)) {
  39. $this->error('提交失败:' . $validate->getError());
  40. }
  41. if (isset($post['article_ftp_config']) && !empty($post['article_ftp_config'])) {
  42. $json = json_decode($post['article_ftp_config'], true);
  43. if (!is_array($json)) {
  44. $this->error('ftp配置格式错误');
  45. } else {
  46. $post['article_ftp_config'] = json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
  47. }
  48. }
  49. if (!isset($post['is_log'])) {
  50. $post['is_log'] = 0;
  51. }
  52. if (!isset($post['is_close_site'])) {
  53. $post['is_close_site'] = 0;
  54. }
  55. $model = (new \app\common\model\Webconfig())->where('id', 1)->find();
  56. if (false == $model->allowField(true)->save($post)) {
  57. $this->error('提交失败');
  58. } else {
  59. Cache::clear();
  60. $this->success('提交成功', 'admin/webconfig/index');
  61. }
  62. }
  63. }
  64. }