SettingController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace addons\YunfastPay\backend\controllers;
  3. use addons\YunfastPay\common\services\SettingService;
  4. /**
  5. * 设置控制器
  6. * @package addons\YunfastPay\backend\controllers
  7. */
  8. class SettingController extends BaseController
  9. {
  10. public $enableCsrfValidation = false;
  11. /**
  12. * @var SettingService
  13. */
  14. private $service;
  15. public function init()
  16. {
  17. parent::init();
  18. $this->service = new SettingService(
  19. ['mall_id' => $this->mall_id]
  20. );
  21. }
  22. /**
  23. * 设置页面
  24. *
  25. * @return void
  26. */
  27. public function actionIndex()
  28. {
  29. if ($this->request->isAjax) {
  30. return $this->success(
  31. 'ok',
  32. ['setting' => $this->service->getSetting()]
  33. );
  34. }
  35. return $this->render('index');
  36. }
  37. /**
  38. * 获取配置
  39. *
  40. * @return void
  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($this->service->getErrorMsg());
  50. }
  51. }
  52. }