0
0

QueueController.php 1.7 KB

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