SettingController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace addons\OperationCenter\backend\controllers;
  3. use addons\OperationCenter\common\services\SettingService;
  4. /**
  5. * 设置控制器
  6. *
  7. * Class SettingController
  8. * @package addons\OperationCenter\backend\controllers
  9. */
  10. class SettingController extends BaseController
  11. {
  12. /**
  13. * @var boolean
  14. */
  15. public $enableCsrfValidation = false;
  16. /**
  17. * @var SettingService
  18. */
  19. protected $service;
  20. public function init()
  21. {
  22. parent::init();
  23. $this->service = new SettingService(['mall_id' => $this->mall_id]);
  24. }
  25. /**
  26. * 首页
  27. *
  28. * @return string
  29. */
  30. public function actionIndex()
  31. {
  32. if ($this->request->isAjax) {
  33. return $this->success('ok', ['setting' => $this->service->getSetting()]);
  34. }
  35. return $this->render($this->action->id);
  36. }
  37. /**
  38. * 保存设置
  39. *
  40. * @return string
  41. */
  42. public function actionSave()
  43. {
  44. if ($this->request->isPost) {
  45. $data = $this->request->post();
  46. unset($data['_csrf']);
  47. return $this->service->setSetting($data)
  48. ? $this->success('ok')
  49. : $this->error('设置失败');
  50. }
  51. }
  52. }