SubscribeController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 SubscribeForm();
  60. $model->setScenario('delete_subscribe');
  61. $model->load(['SubscribeForm' => Yii::$app->request->post()]);
  62. $data = [];
  63. if ($model->validate()) {
  64. $data = $model->Unsubscribe();
  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 SubscribeForm();
  81. $data = $model->getSubscribeList();
  82. return [
  83. 'code' => 200,
  84. 'message' => Yii::t('error', 200),
  85. 'data' => $data
  86. ];
  87. }
  88. }