Queue.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Queue.php UTF-8
  4. *
  5. * @date : 2021/5/6 15:08
  6. *
  7. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  8. * @author : chenbingling <cbl@huosdk.com>
  9. * @version : HUOSDK-IDENTITY 1.0
  10. */
  11. namespace huoIdentify\lib\queue\controller;
  12. use huoIdentify\controller\Common;
  13. use huolib\status\CommonStatus;
  14. class Queue extends Common {
  15. protected $param = [];
  16. protected $job_class = '';
  17. protected $job_name = '';
  18. public function __construct() {
  19. $this->param['ts'] = time();
  20. }
  21. /**
  22. * 返回数据
  23. *
  24. * @param int $code
  25. * @param array $data
  26. *
  27. * @return array
  28. */
  29. protected function retSucMsg($code = CommonStatus::NO_ERROR, $data = []) {
  30. /* 数据录入LOG */
  31. $this->param['queue'] = '1';
  32. return $this->huoSuccess($code, CommonStatus::getMsg($code), $data);
  33. }
  34. /**
  35. * 返回数据
  36. *
  37. * @param $code
  38. *
  39. * @return array|mixed
  40. */
  41. protected function retErrMsg($code = CommonStatus::PUSH_QUEUE_ERROR) {
  42. /* 数据录入LOG */
  43. $this->param['queue'] = '0';
  44. return $this->huoError($code, CommonStatus::getMsg($code));
  45. }
  46. /**
  47. * 入队列
  48. *
  49. * @return array
  50. */
  51. public function pushQueue() {
  52. if (class_exists('think\\Queue')) {
  53. $_is_pushed = \think\Queue::push($this->job_class, $this->param, $this->job_name);
  54. if ($_is_pushed === false) {
  55. return $this->retErrMsg();
  56. }
  57. }
  58. return $this->retSucMsg();
  59. }
  60. /**
  61. * @return array
  62. */
  63. public function getParam() {
  64. return $this->param;
  65. }
  66. /**
  67. * @param array $param
  68. */
  69. public function setParam($param) {
  70. $this->param = array_merge($this->param, $param);
  71. }
  72. /**
  73. * @return string
  74. */
  75. public function getJobClass() {
  76. return $this->job_class;
  77. }
  78. /**
  79. * @param string $job_class
  80. */
  81. public function setJobClass($job_class) {
  82. $this->job_class = $job_class;
  83. }
  84. /**
  85. * @return string
  86. */
  87. public function getJobName() {
  88. return $this->job_name;
  89. }
  90. /**
  91. * @param string $job_name
  92. */
  93. public function setJobName($job_name) {
  94. $this->job_name = $job_name;
  95. }
  96. }