SettingController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace addons\ScoreMall\backend\controllers;
  3. use addons\ScoreMall\common\enums\ScoreMallEnum;
  4. use common\enums\StatusEnum;
  5. class SettingController extends BaseController
  6. {
  7. public $enableCsrfValidation = false;
  8. /**
  9. * 基础设置
  10. * @return mixed|string|null
  11. */
  12. public function actionIndex()
  13. {
  14. $retuest = \Yii::$app->request;
  15. if ($retuest->isAjax) {
  16. $mall_id = $this->mall_id;
  17. if ($retuest->isPost) {
  18. try{
  19. $params = \Yii::$app->request->post();
  20. $res = \Yii::$app->services->validate->validate($params, [
  21. [['is_limit_address', ], 'integer'],
  22. [['is_limit_address'], 'number'],
  23. ]);
  24. if ($res === false) throw new \Exception(\Yii::$app->services->validate->getErrorMessage());
  25. \Yii::$app->services->setting->addons->set($mall_id, ScoreMallEnum::ADDONS_NAME, ['base' => $params]);
  26. return $this->success('保存成功');
  27. }catch (\Exception $e){
  28. return $this->error($e->getMessage());
  29. }
  30. }else{
  31. $config = \Yii::$app->services->setting->addons->get($mall_id, ScoreMallEnum::ADDONS_NAME, 'base');
  32. return $this->success('获取成功', $config);
  33. }
  34. }
  35. return $this->render('index');
  36. }
  37. }