SettingController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace addons\WechatVideoShop\backend\controllers;
  3. use addons\WechatVideoShop\common\service\SettingService;
  4. use addons\WechatVideoShop\common\service\ShopService;
  5. use Yii;
  6. use common\controllers\AddonsController;
  7. use yii\helpers\Json;
  8. /**
  9. * 默认控制器
  10. *
  11. * Class DefaultController
  12. * @package addons\WechatVideoShop\backend\controllers
  13. */
  14. class SettingController extends BaseController
  15. {
  16. public $enableCsrfValidation = false;
  17. /**
  18. * 首页
  19. *
  20. * @return string
  21. */
  22. public function actionIndex()
  23. {
  24. if (Yii::$app->request->isAjax) {
  25. $service = (new SettingService());
  26. if (Yii::$app->request->isPost) {
  27. $data = Yii::$app->request->post();
  28. $valid = Yii::$app->services->validate->validate($data, [
  29. [['is_enable', 'settlement_type', 'compute_type', 'is_open_level_limit',
  30. 'reward_commission_type', 'reward_score_type', 'is_show_at_center', 'sharer_default_apply_shop_id'], 'integer'],
  31. [['reward_commission', 'reward_score'], 'number'],
  32. ]);
  33. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  34. return $service->save($this->mall_id, $data) ? $this->success("保存成功", $data) : $this->error('保存失败');
  35. } else {
  36. $ret = $service->get($this->mall_id);
  37. return $this->success('success', $ret);
  38. }
  39. }
  40. $shop = (new ShopService())->ShopArr($this->mall_id, false);
  41. return $this->render('index',['shop' => Json::encode($shop)]);
  42. }
  43. }