12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace backend\controllers;
- use components\Exception;
- use components\service\AmqpConfig;
- use components\service\Redis;
- use yii\helpers\ArrayHelper;
- use Yii;
- class QueryController extends BaseController
- {
- /**
- * behaviors
- * @return array
- */
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'verbs' => [
- 'class' => \yii\filters\VerbFilter::className(),
- 'actions' => [
- 'message-status' => ['GET'],
- ],
- ],
- ]);
- }
- /**
- * 查询消息状态
- * @author: libingke
- * @return mixed
- * @throws Exception
- */
- public function actionMessageStatus()
- {
- $params = Yii::$app->request->queryParams;
- if (!isset($params['queue']))
- throw new Exception(1100);
- if (!is_string($params['queue']) || !$params['queue'])
- throw new Exception(1101);
- if (!isset($params['mid']))
- throw new Exception(1203);
- if (!is_string($params['mid']) || !$params['mid'])
- throw new Exception(1204);
- $r = Redis::get($params['queue'], $params['mid'], 'status');
- if ($r == null)
- throw new Exception(1004);
- return [
- 'code' => 200,
- 'message' => Yii::t('error', 200),
- 'data' => ['status' => $r, 'status_mark' => AmqpConfig::getMarkById($r)]
- ];
- }
- /**
- * 查询消息结果
- * @author: libingke
- * @return mixed
- * @throws Exception
- */
- public function actionMessageResult()
- {
- $params = Yii::$app->request->queryParams;
- if (!isset($params['queue']))
- throw new Exception(1100);
- if (!is_string($params['queue']) || !$params['queue'])
- throw new Exception(1101);
- if (!isset($params['mid']))
- throw new Exception(1203);
- if (!is_string($params['mid']) || !$params['mid'])
- throw new Exception(1204);
- $s = Redis::get($params['queue'], $params['mid'], 'status');
- if ($s != AmqpConfig::STATUS_HAND_OK)
- throw new Exception(1005);
- $r = Redis::get($params['queue'], $params['mid'], 'status');
- if ($r == null)
- throw new Exception(1004);
- return json_decode($r, true);
- }
- }
|