QueryController.php 1.9 KB

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