ReportOrders.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Console\Commands\Report;
  3. use App\Modules\Trade\Models\Order;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Redis;
  7. class ReportOrders extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'report:orders';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '上报成功订单';
  21. /**
  22. * Execute the console command.
  23. *
  24. * @return mixed
  25. */
  26. public function handle()
  27. {
  28. // 获取最新同步id
  29. $key = 'report:delivery:last:order:id';
  30. $orderId = (int)Redis::get($key);
  31. $client = new Client(['timeout' => 10, 'verify' => false]);
  32. // 获取订单
  33. $orders = Order::getOrdersById($orderId);
  34. if ($orders) {
  35. $reportData = [
  36. 'platform' => 'wangduyun',
  37. 'list' => []
  38. ];
  39. foreach ($orders as $order) {
  40. $orderId = getProp($order, 'id');
  41. $reportData['list'][] = [
  42. 'uid' => getProp($order, 'uid'),
  43. 'order_no' => getProp($order, 'trade_no'),
  44. 'price' => getProp($order, 'price'),
  45. 'channel_id' => getProp($order, 'distribution_channel_id'),
  46. 'pay_time' => getProp($order, 'pay_end_at'),
  47. ];
  48. }
  49. // 执行上报
  50. $client->post(env('REPORT_URI') . '/api/reportOrders', [
  51. 'headers' => [
  52. 'x-code' => 'Mvnx1Yr3O8i!TS5u'
  53. ],
  54. 'json' => $reportData
  55. ]);
  56. // 更新uid
  57. Redis::set($key, $orderId);
  58. }
  59. }
  60. }