Webconfig.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. $this->assign('web_config', \app\common\model\Webconfig::get(1));
  24. }
  25. public function index()
  26. {
  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. if ($this->request->isPost()) {
  62. $post = $this->request->post();
  63. $weeks = $post['weeks']??[];
  64. $weeks = array_keys($weeks);
  65. $post['weeks'] = implode(',', $weeks);
  66. $post['morning_time_periods'] = json_encode($post['morning_time_periods']??[]);
  67. $post['afternoon_time_periods'] = json_encode($post['afternoon_time_periods']??[]);
  68. $model = (new \app\common\model\Webconfig())->where('id', 1)->find();
  69. if (false == $model->allowField(true)->save($post)) {
  70. $this->error('提交失败');
  71. } else {
  72. //修改系统放号记录, 新增放号记录
  73. $speciaIds = (new \app\common\model\Specialist())->column('id');
  74. foreach ($speciaIds as $pid) {
  75. if ((new \app\common\model\Appointment())->where('provider_id', $pid)->count() == 0) {
  76. $post['provider_id'] = $pid;
  77. (new \app\common\model\Appointment())->allowField(true)->save($post);
  78. }
  79. }
  80. $this->success('提交成功');
  81. }
  82. } else {
  83. $webconfig = \app\common\model\Webconfig::get(1);
  84. $this->assign('morning_time_periods_json', json_decode($webconfig->morning_time_periods, true));
  85. $this->assign('afternoon_time_periods_json', json_decode($webconfig->afternoon_time_periods, true));
  86. return $this->fetch();
  87. }
  88. }
  89. public function applicationConfig()
  90. {
  91. return $this->fetch();
  92. }
  93. public function noticeConfig()
  94. {
  95. return $this->fetch();
  96. }
  97. }