Webconfig.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 app\common\model\ConfigTab as configTabModel;
  13. use think\Cache;
  14. use think\Db;
  15. class Webconfig extends Permissions
  16. {
  17. protected function _initialize()
  18. {
  19. parent::_initialize();
  20. //扩展配置标签
  21. $tabs = (new configTabModel())->where('status', configTabModel::STATUS_OPEN)->order('sort desc')->select();
  22. $this->assign('tabs', $tabs);
  23. }
  24. public function index()
  25. {
  26. $this->assign('web_config', Db::name('webconfig')->where('id', 1)->find());
  27. $this->assign('is_close_site_key', (new Urlconfig())->getCloseSiteKey());
  28. $this->assign('admin_log_num', (new AdminLog())->count());
  29. $this->assign('backend_pass', (new Urlconfig())->getBackendPass());
  30. return $this->fetch();
  31. }
  32. public function publish()
  33. {
  34. if ($this->request->isPost()) {
  35. $post = $this->request->post();
  36. $validate = new \think\Validate([
  37. ['file_type', 'requireWith:name', '上传类型不能为空'],
  38. ['file_size', 'requireWith:name', '上传大小不能为空'],
  39. ['host', 'url'],
  40. ]);
  41. if (!$validate->check($post)) {
  42. $this->error('提交失败:' . $validate->getError());
  43. }
  44. if (!isset($post['is_log'])) {
  45. $post['is_log'] = 0;
  46. }
  47. if (!isset($post['is_close_site'])) {
  48. $post['is_close_site'] = 0;
  49. }
  50. $model = (new \app\common\model\Webconfig())->where('id', 1)->find();
  51. if (false == $model->allowField(true)->save($post)) {
  52. $this->error('提交失败');
  53. } else {
  54. Cache::clear();
  55. $this->success('提交成功', 'admin/webconfig/index');
  56. }
  57. }
  58. }
  59. public function appointmentConfig()
  60. {
  61. $this->assign('web_config', Db::name('webconfig')->where('id', 1)->find());
  62. return $this->fetch();
  63. }
  64. }