DefaultController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace addons\AvoidTax\backend\controllers;
  3. use addons\AvoidTax\common\service\TaxConfigService;
  4. use Yii;
  5. /**
  6. * 配置
  7. *
  8. * Class DefaultController
  9. * @package addons\AvoidTax\backend\controllers
  10. */
  11. class DefaultController extends BaseController
  12. {
  13. public $service;
  14. public $enableCsrfValidation = false;
  15. public function __construct($id, $module, $config = [])
  16. {
  17. parent::__construct($id, $module, $config);
  18. $this->service = new TaxConfigService(['mall_id' => intval($this->mall_id)]);
  19. }
  20. /**
  21. * 首页
  22. * @return string
  23. */
  24. public function actionIndex()
  25. {
  26. if (!$this->request->isAjax) {
  27. return $this->render('index');
  28. }
  29. $data = $this->request->post();
  30. $res = $this->service->add($data);
  31. return $res ? $this->success("操作成功") : $this->error($this->service->error);
  32. }
  33. /**
  34. * 读取配置
  35. * @return string
  36. */
  37. public function actionRead()
  38. {
  39. $config = $this->service->getConfig();
  40. return $this->success_str('ok', $config);
  41. }
  42. }