SettingController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace addons\Printer\backend\controllers;
  3. use addons\Printer\common\services\SettingService;
  4. use Yii;
  5. /**
  6. * 设置控制器
  7. *
  8. * Class SettingController
  9. * @package addons\Printer\backend\controllers
  10. */
  11. class SettingController extends BaseController
  12. {
  13. public $enableCsrfValidation = false;
  14. /**
  15. * 设置
  16. *
  17. * @return mixed
  18. */
  19. public function actionIndex()
  20. {
  21. if ($this->request->isAjax) {
  22. $service = new SettingService(['mall_id' => $this->mall_id]);
  23. return $this->success('ok', $service->getSetting());
  24. }
  25. return $this->render($this->action->id);
  26. }
  27. /**
  28. * 保存设置
  29. *
  30. * @return mixed
  31. */
  32. public function actionSave()
  33. {
  34. $service = new SettingService(['mall_id' => $this->mall_id]);
  35. $params = $this->request->post();
  36. $res = Yii::$app->services->validate->validate($params, [
  37. [['pickup_code_name'], 'required'],
  38. ]);
  39. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  40. return $service->setSetting($params)
  41. ? $this->success('ok')
  42. : $this->error($service->getError());
  43. }
  44. }