| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace addons\Scratch\backend\controllers;
- use addons\Scratch\common\enums\ScratchEnum;
- use addons\Scratch\common\logic\ScratchSettingLogic;
- use common\enums\StatusEnum;
- /**
- * Class SettingController
- * @package addons\Scratch\backend\controllers
- */
- class SettingController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('index');
- }
- /**
- * @return string
- */
- public function actionGetSetting()
- {
- try {
- return $this->success('ok', ScratchSettingLogic::getData($this->mall_id));
- } catch (\ErrorException $errorException) {
- return $this->error($errorException->getMessage());
- } catch (\Exception $exception) {
- throw new \Exception($exception->getMessage());
- }
- }
- /**
- * @return string
- */
- public function actionSaveSetting()
- {
- try {
- $postData = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate
- ->validate(
- $postData,
- [
- ['payment_type', 'required', 'message' => '请填写支付方式'],
- ['send_type', 'required', 'message' => '请填写发货方式'],
- [['title', 'is_sms', 'is_mail', 'is_print', 'is_wechat', 'type', 'probability', 'oppty', 'start_at', 'end_at', 'deplete_integral_num', 'rule', 'background_imgs'], 'safe'],
- ]
- );
- if ($res === false) {
- throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage());
- }
- return $this->success('保存成功', ScratchSettingLogic::saveData(
- $this->mall_id,
- $postData
- ));
- } catch (\ErrorException $errorException) {
- return $this->error($errorException->getMessage());
- } catch (\Exception $exception) {
- throw new \Exception($exception->getMessage());
- }
- }
- /**
- * @return string
- */
- public function actionSaveBackground()
- {
- try {
- $postData = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate
- ->validate(
- $postData,
- [
- ['color', 'default', 'value' => ''],
- ['image', 'default', 'value' => ''],
- ]
- );
- if ($res === false) {
- throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage());
- }
- return $this->success('保存成功', ScratchSettingLogic::saveBackground(
- $this->mall_id,
- $postData
- ));
- } catch (\ErrorException $errorException) {
- return $this->error($errorException->getMessage());
- } catch (\Exception $exception) {
- throw new \Exception($exception->getMessage());
- }
- }
- }
|