QuestionTemplateController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\modules\admin\controllers\q_and_a;
  3. use app\models\QAndAQuestionTemplate;
  4. use app\modules\admin\controllers\BaseController;
  5. use app\modules\admin\models\q_and_a\QuestionTemplateForm;
  6. class QuestionTemplateController extends BaseController
  7. {
  8. /**
  9. * 列表
  10. */
  11. public function actionList()
  12. {
  13. $param = get_params();
  14. $form = new QuestionTemplateForm();
  15. $form->attributes = $param;
  16. $form->store_id = get_store_id();
  17. return $this->asJson($form->search());
  18. }
  19. /**
  20. * 获取热门问答
  21. */
  22. public function actionHotList()
  23. {
  24. $list = QAndAQuestionTemplate::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'is_hot' => 1])
  25. ->orderBy(['id' => SORT_DESC])->all();
  26. return $this->asJson([
  27. 'code' => 0,
  28. 'data' => [
  29. 'list' => $list,
  30. ]
  31. ]);
  32. }
  33. /**
  34. * 获取详情
  35. */
  36. public function actionInfo($id = null)
  37. {
  38. return $this->asJson([
  39. 'code' => 0,
  40. 'data' => [
  41. 'model' => QAndAQuestionTemplate::findOne($id)
  42. ]
  43. ]);
  44. }
  45. /**
  46. * 保存
  47. */
  48. public function actionSave()
  49. {
  50. $form = new QuestionTemplateForm();
  51. $form->attributes = post_params();
  52. return $this->asJson($form->save());
  53. }
  54. /**
  55. * 删除
  56. * @param $id
  57. */
  58. public function actionDel($id)
  59. {
  60. $model = QAndAQuestionTemplate::findOne($id);
  61. if (empty($model)) {
  62. $res = ['code' => 1, 'msg' => '参数错误'];
  63. } else {
  64. $model->is_delete = 1;
  65. $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
  66. }
  67. return $this->asJson($res);
  68. }
  69. public function actionState($id = null, $state = 1)
  70. {
  71. $id = json_decode($id, true);
  72. foreach ($id as $v) {
  73. $model = QAndAQuestionTemplate::findOne($v);
  74. if (!$model) {
  75. return $this->asJson([
  76. 'code' => 1,
  77. 'msg' => '请刷新重试'
  78. ]);
  79. }
  80. $model->state = $state;
  81. $model->save();
  82. }
  83. return $this->asJson([
  84. 'code' => 0,
  85. 'msg' => '成功'
  86. ]);
  87. }
  88. }