1
0

SubscribeController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace backend\controllers;
  3. use backend\forms\QueueForm;
  4. use backend\forms\SubscribeForm;
  5. use backend\forms\TopicForm;
  6. use components\Exception;
  7. use yii\helpers\ArrayHelper;
  8. use Yii;
  9. class SubscribeController extends BaseController
  10. {
  11. /**
  12. * behaviors
  13. * @return array
  14. */
  15. public function behaviors()
  16. {
  17. return ArrayHelper::merge(parent::behaviors(), [
  18. 'verbs' => [
  19. 'class' => \yii\filters\VerbFilter::className(),
  20. 'actions' => [
  21. 'list' => ['GET'],
  22. 'create' => ['POST'],
  23. 'delete' => ['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 SubscribeForm();
  37. $model->setScenario('create_subscribe');
  38. $model->load(['SubscribeForm' => Yii::$app->request->post()]);
  39. $data = [];
  40. if ($model->validate()) {
  41. $data = $model->Subscribe();
  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->getQueueList();
  82. return [
  83. 'code' => 200,
  84. 'message' => Yii::t('error', 200),
  85. 'data' => $data
  86. ];
  87. }
  88. }