0
0

TopicController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. 'update' => ['POST'],
  24. ],
  25. ],
  26. ]);
  27. }
  28. /**
  29. * [创建队列]
  30. * @author: libingke
  31. * @return array
  32. * @throws Exception
  33. */
  34. public function actionCreate()
  35. {
  36. $model = new TopicForm();
  37. $model->setScenario('create_topic');
  38. $model->load(['TopicForm' => Yii::$app->request->post()]);
  39. $data = [];
  40. if ($model->validate()) {
  41. $data = $model->createTopic();
  42. } else {
  43. $model->handleError();//处理验证失败
  44. }
  45. return [
  46. 'code' => 200,
  47. 'message' => Yii::t('error', 200),
  48. 'data' => $data
  49. ];
  50. }
  51. /**
  52. * 删除队列
  53. * @author: libingke
  54. * @return array
  55. * @throws Exception
  56. */
  57. public function actionDelete()
  58. {
  59. $model = new TopicForm();
  60. $model->setScenario('delete_topic');
  61. $model->load(['TopicForm' => Yii::$app->request->post()]);
  62. $data = [];
  63. if ($model->validate()) {
  64. $data = $model->deleteTopic();
  65. } else {
  66. $model->handleError();
  67. }
  68. return [
  69. 'code' => 200,
  70. 'message' => Yii::t('error', 200),
  71. 'data' => $data
  72. ];
  73. }
  74. /**
  75. * 获取队列列表
  76. * @author: libingke
  77. */
  78. public function actionList()
  79. {
  80. $model = new TopicForm();
  81. $data = $model->getTopicList();
  82. return [
  83. 'code' => 200,
  84. 'message' => Yii::t('error', 200),
  85. 'data' => $data
  86. ];
  87. }
  88. /**
  89. * [修改队列]
  90. * @author: hanguangxu
  91. * @return array
  92. * @throws Exception
  93. */
  94. public function actionUpdate()
  95. {
  96. $model = new TopicForm();
  97. $model->setScenario('update_topic');
  98. $model->load(['TopicForm' => Yii::$app->request->post()]);
  99. $data = [];
  100. if ($model->validate()) {
  101. $data = $model->updateTopic();
  102. } else {
  103. $model->handleError();//处理验证失败
  104. }
  105. return [
  106. 'code' => 200,
  107. 'message' => Yii::t('error', 200),
  108. 'data' => $data
  109. ];
  110. }
  111. }