0
0

QueueController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 'update' => ['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 QueueForm();
  36. $model->setScenario('create_queue');
  37. $model->load(['QueueForm' => Yii::$app->request->post()]);
  38. $data = [];
  39. if ($model->validate()) {
  40. $data = $model->createQueue();
  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 QueueForm();
  59. $model->setScenario('delete_queue');
  60. $model->load(['QueueForm' => Yii::$app->request->post()]);
  61. $data = [];
  62. if ($model->validate()) {
  63. $data = $model->deleteQueue();
  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 QueueForm();
  80. $data = $model->getQueueList();
  81. return [
  82. 'code' => 200,
  83. 'message' => Yii::t('error', 200),
  84. 'data' => $data
  85. ];
  86. }
  87. /**
  88. * 移除并重置队列
  89. * @author: hanguangxu
  90. * @return array
  91. * @throws Exception
  92. */
  93. public function actionUpdate(){
  94. $model = new QueueForm();
  95. $model->setScenario('update_queue');
  96. $model->load(['QueueForm' => Yii::$app->request->post()]);
  97. $data = [];
  98. if ($model->validate()) {
  99. $data = $model->updateQueue();
  100. } else {
  101. $model->handleError();//处理验证失败
  102. }
  103. return [
  104. 'code' => 200,
  105. 'message' => Yii::t('error', 200),
  106. 'data' => $data
  107. ];
  108. }
  109. }