SyncOrder.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\queue\redis\slow;
  3. use app\extra\tools\LifeWeb;
  4. use app\model\saas\SaasOrder;
  5. use Webman\RedisQueue\Consumer;
  6. class SyncOrder implements Consumer
  7. {
  8. /**
  9. * 延迟30秒获取达人信息
  10. * 消费队列名
  11. * @var string
  12. */
  13. public string $queue = "sync-order-info";
  14. /**
  15. * 连接配置
  16. * @var string
  17. */
  18. public string $connection = "default";
  19. public function consume($data): bool
  20. {
  21. try {
  22. if(empty($data['order'])) return true;
  23. echo getDateFull()."==开始获取订单达人信息\n";
  24. $order = (new SaasOrder)->where("order_sn",$data['order'])->findOrEmpty();
  25. if ($order->isEmpty()) return true;
  26. [$state,$resp] = (new LifeWeb)->token()->getOrderData($order['order_sn']);
  27. if (!$state) {
  28. echo getDateFull()."=={$order['order_sn']}==获取数据失败了==\n";
  29. return true;
  30. }
  31. echo getDateFull()."=={$order['order_sn']}==更新订单数据成功\n";
  32. $order->douyin_uid = $resp['douyin_uid'];
  33. $order->life_fee = $resp['life_fee'];
  34. $order->star_fee = $resp['star_fee'];
  35. $order->save();
  36. } catch (\Throwable $throwable) {
  37. echo getDateFull()."====获取达人信息失败\n";
  38. echo $throwable->getMessage()."\n";
  39. echo $throwable->getLine()."\n";
  40. echo $throwable->getFile()."\n";
  41. }
  42. return true;
  43. }
  44. }