SettingController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace addons\Scratch\backend\controllers;
  3. use addons\Scratch\common\enums\ScratchEnum;
  4. use addons\Scratch\common\logic\ScratchSettingLogic;
  5. use common\enums\StatusEnum;
  6. /**
  7. * Class SettingController
  8. * @package addons\Scratch\backend\controllers
  9. */
  10. class SettingController extends BaseController
  11. {
  12. public $enableCsrfValidation = false;
  13. /**
  14. * @return string
  15. */
  16. public function actionIndex()
  17. {
  18. return $this->render('index');
  19. }
  20. /**
  21. * @return string
  22. */
  23. public function actionGetSetting()
  24. {
  25. try {
  26. return $this->success('ok', ScratchSettingLogic::getData($this->mall_id));
  27. } catch (\ErrorException $errorException) {
  28. return $this->error($errorException->getMessage());
  29. } catch (\Exception $exception) {
  30. throw new \Exception($exception->getMessage());
  31. }
  32. }
  33. /**
  34. * @return string
  35. */
  36. public function actionSaveSetting()
  37. {
  38. try {
  39. $postData = \Yii::$app->request->post();
  40. $res = \Yii::$app->services->validate
  41. ->validate(
  42. $postData,
  43. [
  44. ['payment_type', 'required', 'message' => '请填写支付方式'],
  45. ['send_type', 'required', 'message' => '请填写发货方式'],
  46. [['title', 'is_sms', 'is_mail', 'is_print', 'is_wechat', 'type', 'probability', 'oppty', 'start_at', 'end_at', 'deplete_integral_num', 'rule', 'background_imgs'], 'safe'],
  47. ]
  48. );
  49. if ($res === false) {
  50. throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage());
  51. }
  52. return $this->success('保存成功', ScratchSettingLogic::saveData(
  53. $this->mall_id,
  54. $postData
  55. ));
  56. } catch (\ErrorException $errorException) {
  57. return $this->error($errorException->getMessage());
  58. } catch (\Exception $exception) {
  59. throw new \Exception($exception->getMessage());
  60. }
  61. }
  62. /**
  63. * @return string
  64. */
  65. public function actionSaveBackground()
  66. {
  67. try {
  68. $postData = \Yii::$app->request->post();
  69. $res = \Yii::$app->services->validate
  70. ->validate(
  71. $postData,
  72. [
  73. ['color', 'default', 'value' => ''],
  74. ['image', 'default', 'value' => ''],
  75. ]
  76. );
  77. if ($res === false) {
  78. throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage());
  79. }
  80. return $this->success('保存成功', ScratchSettingLogic::saveBackground(
  81. $this->mall_id,
  82. $postData
  83. ));
  84. } catch (\ErrorException $errorException) {
  85. return $this->error($errorException->getMessage());
  86. } catch (\Exception $exception) {
  87. throw new \Exception($exception->getMessage());
  88. }
  89. }
  90. }