| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace addons\Course\backend\controllers;
- use Yii;
- use addons\Course\common\enums\CourseEnum;
- use Exception;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Course\backend\controllers
- */
- class SettingController extends BaseController
- {
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- try {
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, CourseEnum::ADDONS_NAME, 'basic');
- if (empty($config['style'])) $config['style'] = 1;
- return $this->success('获取成功', $config);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- if ($request->isPost) {
- try {
- $post = $request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [[ 'style'], 'required'],
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $res = \Yii::$app->services->setting->addons->set($this->mall_id, CourseEnum::ADDONS_NAME, ['basic' => $post]);
- if (!$res) throw new Exception('操作失败');
- return $this->success('操作成功');
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- return $this->render('index');
- }
- }
|