RepeatQueue.php 2.5 KB

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