1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Console\Commands\Report;
- use App\Modules\Trade\Models\Order;
- use GuzzleHttp\Client;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Redis;
- class ReportOrders extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'report:orders';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '上报成功订单';
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- // 获取最新同步id
- $key = 'report:delivery:last:order:id';
- $orderId = (int)Redis::get($key);
- $client = new Client(['timeout' => 10, 'verify' => false]);
- // 获取订单
- $orders = Order::getOrdersById($orderId);
- if ($orders) {
- $reportData = [
- 'platform' => 'wangduyun',
- 'list' => []
- ];
- foreach ($orders as $order) {
- $orderId = getProp($order, 'id');
- $reportData['list'][] = [
- 'uid' => getProp($order, 'uid'),
- 'order_no' => getProp($order, 'trade_no'),
- 'price' => getProp($order, 'price'),
- 'channel_id' => getProp($order, 'distribution_channel_id'),
- 'pay_time' => getProp($order, 'pay_end_at'),
- ];
- }
- // 执行上报
- $client->post(env('REPORT_URI') . '/api/reportOrders', [
- 'headers' => [
- 'x-code' => 'Mvnx1Yr3O8i!TS5u'
- ],
- 'json' => $reportData
- ]);
- // 更新uid
- Redis::set($key, $orderId);
- }
- }
- }
|