1
0

TopicController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace backend\controllers;
  3. use backend\forms\QueueForm;
  4. use backend\forms\TopicForm;
  5. use components\Exception;
  6. use yii\helpers\ArrayHelper;
  7. use Yii;
  8. class TopicController extends BaseController
  9. {
  10. /**
  11. * behaviors
  12. * @return array
  13. */
  14. public function behaviors()
  15. {
  16. return ArrayHelper::merge(parent::behaviors(), [
  17. 'verbs' => [
  18. 'class' => \yii\filters\VerbFilter::className(),
  19. 'actions' => [
  20. 'list' => ['GET'],
  21. 'create' => ['POST'],
  22. 'delete' => ['POST'],
  23. ],
  24. ],
  25. ]);
  26. }
  27. /**
  28. * [创建队列]
  29. * @author: libingke
  30. * @return array
  31. * @throws Exception
  32. */
  33. public function actionCreate()
  34. {
  35. $model = new TopicForm();
  36. $model->setScenario('create_topic');
  37. $model->load(['TopicForm' => Yii::$app->request->post()]);
  38. $data = [];
  39. if ($model->validate()) {
  40. $data = $model->createTopic();
  41. } else {
  42. $model->handleError();//处理验证失败
  43. }
  44. return [
  45. 'code' => 200,
  46. 'message' => Yii::t('error', 200),
  47. 'data' => $data
  48. ];
  49. }
  50. /**
  51. * 删除队列
  52. * @author: libingke
  53. * @return array
  54. * @throws Exception
  55. */
  56. public function actionDelete()
  57. {
  58. $model = new TopicForm();
  59. $model->setScenario('delete_topic');
  60. $model->load(['TopicForm' => Yii::$app->request->post()]);
  61. $data = [];
  62. if ($model->validate()) {
  63. $data = $model->deleteTopic();
  64. } else {
  65. $model->handleError();
  66. }
  67. return [
  68. 'code' => 200,
  69. 'message' => Yii::t('error', 200),
  70. 'data' => $data
  71. ];
  72. }
  73. /**
  74. * 获取队列列表
  75. * @author: libingke
  76. */
  77. public function actionList()
  78. {
  79. $model = new TopicForm();
  80. $data = $model->getTopicList();
  81. return [
  82. 'code' => 200,
  83. 'message' => Yii::t('error', 200),
  84. 'data' => $data
  85. ];
  86. }
  87. }