SettingController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace addons\ElectronCoupon\backend\controllers;
  3. use addons\ElectronCoupon\common\services\SettingService;
  4. use common\models\common\PlatformSetting;
  5. use Yii;
  6. class SettingController extends BaseController
  7. {
  8. public $enableCsrfValidation = false;
  9. /**
  10. * 基础配置
  11. *
  12. * @author hpi
  13. * @return array|mixed
  14. */
  15. public function actionIndex()
  16. {
  17. $service = new SettingService(['mall_id' => $this->mall_id]);
  18. if (Yii::$app->request->isAjax) {
  19. if (Yii::$app->request->isPost) {
  20. $params = Yii::$app->request->post();
  21. $res = Yii::$app->services->validate->validate($params, [
  22. [['is_open', 'customize_name', 'receive_num', 'payed_url', 'is_payed_url', 'agreement', 'images'], 'safe'],
  23. [['is_allow_deal', 'source_transfer_permission', 'transfer_num', 'images', 'logo', 'is_notice', 'settlement_type'], 'safe'],
  24. [['center_url'], 'safe'],
  25. ]);
  26. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  27. return $service->setSetting($params)
  28. ? $this->success('操作成功')
  29. : $this->error('操作失败');
  30. } else {
  31. $setting = $service->getSetting();
  32. $platform_config = PlatformSetting::getConfByGroup('system', true);
  33. $config['web_url'] = $platform_config['h5_url']['value'];
  34. $config['mall_sign'] = $this->mall['mall_sign'];
  35. return $this->success('操作成功', compact('setting', 'config'));
  36. }
  37. }
  38. return $this->render('index');
  39. }
  40. }