DefaultController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\modules\admin\controllers\q_and_a;
  3. use app\models\QAndAAdSetting;
  4. use app\models\QAndASetting;
  5. use app\modules\admin\controllers\BaseController;
  6. use app\modules\admin\models\q_and_a\DefaultForm;
  7. class DefaultController extends BaseController
  8. {
  9. public function actionSetting()
  10. {
  11. $model = QAndASetting::find()->where(['store_id' => get_store_id()])->one();
  12. if (!$model) {
  13. $model = new QAndASetting();
  14. $model->store_id = get_store_id();
  15. }
  16. if (\Yii::$app->request->isPost) {
  17. $form = new DefaultForm();
  18. $form->attributes = post_params();
  19. $form->model =$model;
  20. return $this->asJson($form->save());
  21. }
  22. return $this->asJson([
  23. 'code' => 0,
  24. 'data' => [
  25. 'model' => $model
  26. ]
  27. ]);
  28. }
  29. public function actionAdSetting()
  30. {
  31. $model = QAndAAdSetting::find()->where(['store_id' => get_store_id()])->one();
  32. if (!$model) {
  33. $model = new QAndAAdSetting();
  34. $model->store_id = get_store_id();
  35. }
  36. if (\Yii::$app->request->isPost) {
  37. $form = new DefaultForm();
  38. $form->attributes = post_params();
  39. $form->model =$model;
  40. return $this->asJson($form->ad_save());
  41. }
  42. return $this->asJson([
  43. 'code' => 0,
  44. 'data' => [
  45. 'model' => $model,
  46. 'callback_url' => \Yii::$app->request->hostInfo . '/index.php/ad/callback/'.get_store_id(),
  47. ]
  48. ]);
  49. }
  50. }