[ 'class' => \yii\filters\VerbFilter::className(), 'actions' => [ 'send' => ['POST'], 'batch-send' => ['POST'], 'list' => ['GET'], 'purge' => ['POST'], 'consume' => ['POST'], 'delete' => ['POST'], 'ack' => ['POST'], ], ], ]); } /** * 发送消息 * @author: libingke * @return array */ public function actionSend() { $model = new MessageForm(); $model->setScenario('send'); $model->load(['MessageForm' => Yii::$app->request->post()]); $data = []; if ($model->validate()) { $data = $model->sendMessage(); } else { $model->handleError();//处理验证失败 } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } /** * 批量发送消息 * @author: libingke * @return array */ public function actionBatchSend() { $model = new MessageForm(); $model->setScenario('batch_send'); $model->load(['MessageForm' => Yii::$app->request->post()]); $data = []; if ($model->validate()) { $data = $model->batchSendMessage(); } else { $model->handleError(); } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } /** * 获取队列消息列表 * @author: libingke * @return array */ public function actionList() { $model = new MessageForm(); $model->setScenario('message_list'); $model->load(['MessageForm' => Yii::$app->request->get()]); $data = []; if ($model->validate()) { $data = $model->getMessageList(); } else { $model->handleError(); } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } /** * 消费消息 * @author: libingke */ public function actionConsume() { $model = new MessageForm(); $model->setScenario('consume'); $model->load(['MessageForm' => Yii::$app->request->post()]); $data = []; if ($model->validate()) { $data = $model->consumeMessage(); } else { $model->handleError(); } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } /** * 手动应答 * @author: libingke */ public function actionAck() { $model = new MessageForm(); $model->setScenario('ack'); $model->load(['MessageForm' => Yii::$app->request->post()]); $data = []; if ($model->validate()) { $data = $model->ackMessage(); } else { $model->handleError(); } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } /** * 删除消息 * @author: libingke * @return array * @throws Exception */ public function actionDelete() { $model = new MessageForm(); $model->setScenario('delete'); $model->load(['MessageForm' => Yii::$app->request->post()]); $data = []; if ($model->validate()) { $data = $model->deleteMessage(); } else { $model->handleError(); } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } /** * 清空消息 * @author: libingke * @return array */ public function actionPurge() { $model = new MessageForm(); $model->setScenario('purge'); $model->load(['MessageForm' => Yii::$app->request->post()]); $data = []; if ($model->validate()) { $data = $model->purge(); } else { $model->handleError(); } return [ 'code' => 200, 'message' => Yii::t('error', 200), 'data' => $data ]; } }