Config.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\system;
  12. use app\common\model\SystemConfig;
  13. use app\admin\service\TriggerService;
  14. use app\common\controller\AdminController;
  15. use EasyAdmin\annotation\ControllerAnnotation;
  16. use EasyAdmin\annotation\NodeAnotation;
  17. use services\CacheServices;
  18. use think\App;
  19. use think\facade\Db;
  20. /**
  21. * Class Config
  22. * @package app\admin\controller\system
  23. * @ControllerAnnotation(title="系统配置管理")
  24. */
  25. class Config extends AdminController
  26. {
  27. public function __construct(App $app)
  28. {
  29. parent::__construct($app);
  30. $this->model = new SystemConfig();
  31. }
  32. /**
  33. * @NodeAnotation(title="列表")
  34. */
  35. public function index()
  36. {
  37. $this->assign('total_renwu', 11);
  38. $this->assign('total_shouxu', 22);
  39. return $this->fetch();
  40. }
  41. /**
  42. * @NodeAnotation(title="保存")
  43. */
  44. public function save()
  45. {
  46. $this->checkPostRequest();
  47. $post = $this->request->post();
  48. sr_log(json_encode($post));
  49. try {
  50. foreach ($post as $key => $val) {
  51. $this->model
  52. ->where('name', $key)
  53. ->update([
  54. 'value' => $val,
  55. ]);
  56. }
  57. TriggerService::updateMenu();
  58. TriggerService::updateSysconfig();
  59. } catch (\Exception $e) {
  60. $this->error('保存失败');
  61. }
  62. $this->success('保存成功');
  63. }
  64. }