12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Console\Commands\Report;
- use GuzzleHttp\Client;
- use App\Modules\User\Models\User;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Redis;
- class ReportUsers extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'report:users';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '上报注册用户';
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- // 获取最新同步uid
- $key = 'report:delivery:last:uid';
- $uid = (int)Redis::get($key);
- $client = new Client(['timeout' => 10, 'verify' => false]);
- // 获取批量用户信息
- $users = User::getUsersByUid($uid);
- if ($users) {
- $reportData = [
- 'platform' => 'wangduyun',
- 'list' => []
- ];
- foreach ($users as $user) {
- $uid = getProp($user, 'id');
- $reportData['list'][] = [
- 'uid' => $uid,
- 'channel_id' => getProp($user, 'distribution_channel_id'),
- 'register_time' => $user->created_at->format('Y-m-d H:i:s')
- ];
- }
- // 执行上报
- $client->post(env('REPORT_URI') . '/api/reportRegisters', [
- 'headers' => [
- 'x-code' => 'Mvnx1Yr3O8i!TS5u'
- ],
- 'json' => $reportData
- ]);
- // 更新uid
- Redis::set($key, $uid);
- }
- }
- }
|