CancelOrder.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace hook\queue\redis;
  3. use app\admin\model\Orders;
  4. use Webman\RedisQueue\Consumer;
  5. /**
  6. * 订单超时自动取消
  7. * Class CancelOrder
  8. * @package hook\queue\redis
  9. */
  10. class CancelOrder implements Consumer
  11. {
  12. public $queue = 'order-cancel';//消费队列名称
  13. public $connection = 'default';//连接名称
  14. /**
  15. * Notes:业务逻辑处理
  16. * @param $data
  17. * User: yym
  18. * Date: 2022/8/1
  19. */
  20. public function consume($data)
  21. {
  22. try {
  23. if(!isset($data['order_id']) || empty($data['order_id']))
  24. {
  25. throw new \Exception('缺少订单编号!');
  26. }
  27. $order = Orders::getOrderData($data['order_id']);
  28. if(empty($order))
  29. {
  30. throw new \Exception('查无此订单信息');
  31. }
  32. if($order['order_pay_status'] == Orders::SUCCESS)
  33. {
  34. //订单已支付成功
  35. return true;
  36. }
  37. $result = Orders::updateOrder($data['order_id'], ['order_pay_status' => Orders::CANCEL]);
  38. if($result)
  39. {
  40. return true;
  41. }
  42. throw new \Exception('取消失败~');
  43. }catch (\Exception $exception){
  44. throw new \Exception($exception->getMessage(), $exception->getCode());
  45. }
  46. }
  47. }