SettingController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace addons\SmartForm\backend\controllers;
  3. use Yii;
  4. use common\helpers\FormatHelper;
  5. use common\controllers\AddonsController;
  6. use common\enums\StatusEnum;
  7. use addons\SmartForm\common\models\AddonsSmartFormSetting; # 配置
  8. /**
  9. * 配置页
  10. *
  11. * Class SettingController
  12. * @package addons\SmartForm\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. try {
  25. $request = Yii::$app->request;
  26. if ($request->isAjax) {
  27. if ($request->isPost) {
  28. $post = Yii::$app->request->post();
  29. $post['mall_id'] = $this->mall_id;
  30. $status = AddonsSmartFormSetting::setData($post);
  31. if(!$status){
  32. Yii::error(AddonsSmartFormSetting::getStaticError());
  33. return $this->error(AddonsSmartFormSetting::getStaticError());
  34. }
  35. return $this->success('操作成功');
  36. }
  37. }else{
  38. return $this->render('index',[]);
  39. }
  40. } catch (\Exception $e) {
  41. $exception = FormatHelper::exception($e, "保存失败");
  42. Yii::error($exception);
  43. return $this->error($exception);
  44. }
  45. }
  46. /**
  47. * @method actionInfo
  48. * 获取配置明细
  49. * @author zqh
  50. * @datetime 2022-05-31T16:23:57+0800
  51. * @return [type] [description]
  52. */
  53. public function actionInfo()
  54. {
  55. try {
  56. $request = Yii::$app->request;
  57. if ($request->isAjax) {
  58. if ($request->isGet) {
  59. $where['mall_id'] = $this->mall_id;
  60. $where['status'] = StatusEnum::ENABLED;
  61. $find = AddonsSmartFormSetting::findOne($where,true);
  62. return $this->success('获取成功', $find);
  63. }
  64. }
  65. } catch (\Exception $e) {
  66. $exception = FormatHelper::exception($e, "获取失败");
  67. Yii::error($exception);
  68. return $this->error($exception);
  69. }
  70. }
  71. }