SettingController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wniu
  5. * Date: 2022/5/31
  6. * Time: 10:08 下午
  7. */
  8. namespace addons\Coupon\backend\controllers;
  9. use addons\Coupon\common\enums\AddonsCouponEnum;
  10. use addons\Coupon\common\services\SettingService;
  11. use common\enums\AddonsEnum;
  12. use common\models\common\PlatformSetting;
  13. use common\helpers\ApiCode;
  14. class SettingController extends BaseController
  15. {
  16. public $enableCsrfValidation = false;
  17. /**
  18. * 首页
  19. *
  20. * @return string
  21. */
  22. public function actionIndex()
  23. {
  24. $retuest = \Yii::$app->request;
  25. $settingService = new SettingService(['mall_id' => $this->mall_id]);
  26. if ($retuest->isAjax) {
  27. if ($retuest->isPost) {
  28. $params = \Yii::$app->request->post();
  29. $res = \Yii::$app->services->validate->validate($params,[
  30. [['give_type', 'is_effective_coupon_give'], 'safe'],
  31. ]);
  32. if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  33. $config = $settingService->setSetting($params);
  34. $this->success('保存成功', $config);
  35. } else {
  36. // 获取配置
  37. $config = $settingService->getSetting();
  38. $this->success('获取成功',$config,ApiCode::CODE_SUCCESS,0);
  39. }
  40. }
  41. return $this->render($this->action->id);
  42. }
  43. public function actionSmsDetail()
  44. {
  45. $params = \Yii::$app->request->get();
  46. $mall_id = $this->mall_id;
  47. $one = PkSms::find()->where(['sms_key' => $params['sms_key'], 'mall_id' => $mall_id])->one();
  48. if (!$one) {
  49. $one = PkSms::def();
  50. }
  51. return $this->success('success', $one);
  52. }
  53. public function actionSmsEdit()
  54. {
  55. $params = \Yii::$app->request->post();
  56. $params['mall_id'] = $this->mall_id;
  57. $model = PkSms::setData($params);
  58. return $this->success('success', $model);
  59. }
  60. }