AccountOrderQueue.php 2.7 KB

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