| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace addons\WangDianTong\backend\controllers;
- use addons\WangDianTong\common\service\SettingService;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\WangDianTong\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- $service = new SettingService();
- if (\Yii::$app->request->isGet) {
- $ret = $service->get($this->mall_id);
- if (empty($ret)) {
- $ret = [
- 'is_enable' => 1,
- 'env' => 0,
- 'app_sid' => '',
- 'app_key' => '',
- 'app_secret_key' => '',
- 'shop_no' => '',
- 'app_version' => ''
- ];
- }
- return $this->success('success', $ret);
- } else if (\Yii::$app->request->isPost) {
- $data = Yii::$app->request->post();
- $valid = Yii::$app->services->validate->validate($data, [
- [['is_enable', 'env'], 'integer'],
- [['app_sid', 'app_key', 'app_secret_key', 'shop_no', 'app_version'], 'string'],
- [['app_sid', 'app_key', 'app_secret_key', 'shop_no', 'app_version'], 'required'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- return $service->save($this->mall_id, $data) ? $this->success("保存成功", $data) : $this->error('保存失败');
- }
- }
- return $this->render('index');
- }
- }
|