QueryController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace backend\controllers;
  3. use components\Exception;
  4. use components\service\AmqpConfig;
  5. use components\service\Redis;
  6. use yii\helpers\ArrayHelper;
  7. use Yii;
  8. class QueryController extends BaseController
  9. {
  10. /**
  11. * behaviors
  12. * @return array
  13. */
  14. public function behaviors()
  15. {
  16. return ArrayHelper::merge(parent::behaviors(), [
  17. 'verbs' => [
  18. 'class' => \yii\filters\VerbFilter::className(),
  19. 'actions' => [
  20. 'message-status' => ['GET'],
  21. ],
  22. ],
  23. ]);
  24. }
  25. /**
  26. * 查询消息状态
  27. * @author: libingke
  28. * @return mixed
  29. * @throws Exception
  30. */
  31. public function actionMessageStatus()
  32. {
  33. $params = Yii::$app->request->queryParams;
  34. if (!isset($params['queue']))
  35. throw new Exception(1100);
  36. if (!is_string($params['queue']) || !$params['queue'])
  37. throw new Exception(1101);
  38. if (!isset($params['mid']))
  39. throw new Exception(1203);
  40. if (!is_string($params['mid']) || !$params['mid'])
  41. throw new Exception(1204);
  42. $r = Redis::get($params['queue'], $params['mid'], 'status');
  43. if ($r == null)
  44. throw new Exception(1004);
  45. return [
  46. 'code' => 200,
  47. 'message' => Yii::t('error', 200),
  48. 'data' => ['status' => $r, 'status_mark' => AmqpConfig::getMarkById($r)]
  49. ];
  50. }
  51. /**
  52. * 查询消息结果
  53. * @author: libingke
  54. * @return mixed
  55. * @throws Exception
  56. */
  57. public function actionMessageResult()
  58. {
  59. $params = Yii::$app->request->queryParams;
  60. if (!isset($params['queue']))
  61. throw new Exception(1100);
  62. if (!is_string($params['queue']) || !$params['queue'])
  63. throw new Exception(1101);
  64. if (!isset($params['mid']))
  65. throw new Exception(1203);
  66. if (!is_string($params['mid']) || !$params['mid'])
  67. throw new Exception(1204);
  68. $s = Redis::get($params['queue'], $params['mid'], 'status');
  69. if ($s != AmqpConfig::STATUS_HAND_OK)
  70. throw new Exception(1005);
  71. $r = Redis::get($params['queue'], $params['mid'], 'status');
  72. if ($r == null)
  73. throw new Exception(1004);
  74. return json_decode($r, true);
  75. }
  76. }