DefaultController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace addons\WangDianTong\backend\controllers;
  3. use addons\WangDianTong\common\service\SettingService;
  4. use Yii;
  5. /**
  6. * 默认控制器
  7. *
  8. * Class DefaultController
  9. * @package addons\WangDianTong\backend\controllers
  10. */
  11. class DefaultController extends BaseController
  12. {
  13. public $enableCsrfValidation = false;
  14. /**
  15. * 首页
  16. *
  17. * @return string
  18. */
  19. public function actionIndex()
  20. {
  21. if (\Yii::$app->request->isAjax) {
  22. $service = new SettingService();
  23. if (\Yii::$app->request->isGet) {
  24. $ret = $service->get($this->mall_id);
  25. if (empty($ret)) {
  26. $ret = [
  27. 'is_enable' => 1,
  28. 'env' => 0,
  29. 'app_sid' => '',
  30. 'app_key' => '',
  31. 'app_secret_key' => '',
  32. 'shop_no' => '',
  33. 'app_version' => ''
  34. ];
  35. }
  36. return $this->success('success', $ret);
  37. } else if (\Yii::$app->request->isPost) {
  38. $data = Yii::$app->request->post();
  39. $valid = Yii::$app->services->validate->validate($data, [
  40. [['is_enable', 'env'], 'integer'],
  41. [['app_sid', 'app_key', 'app_secret_key', 'shop_no', 'app_version'], 'string'],
  42. [['app_sid', 'app_key', 'app_secret_key', 'shop_no', 'app_version'], 'required'],
  43. ]);
  44. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  45. return $service->save($this->mall_id, $data) ? $this->success("保存成功", $data) : $this->error('保存失败');
  46. }
  47. }
  48. return $this->render('index');
  49. }
  50. }