PushStats.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands\Push;
  3. use App\Cache\Push\PushCache;
  4. use App\Modules\Push\Models\QappPushTask;
  5. use Illuminate\Console\Command;
  6. class PushStats extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'push:stats';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '推送PVUV统计';
  20. public function handle()
  21. {
  22. $date = date('Ymd', strtotime('-1 day'));
  23. // 获取所有有效的推送任务
  24. $tasks = QappPushTask::getAllValidTasks();
  25. if (empty($tasks)) {
  26. return false;
  27. }
  28. foreach ($tasks as $task) {
  29. $pushId = getProp($task, 'id');
  30. $pv = getProp($task, 'pv');
  31. $uv = getProp($task, 'uv');
  32. // 获取缓存数据
  33. $cachePv = PushCache::getPushyPv($pushId, $date);
  34. $cacheUv = PushCache::getPushUv($pushId, $date);
  35. if(!empty($cachePv) || !empty($cacheUv)){
  36. myLog('pushStats')->info('', compact('date', 'pushId', 'pv', 'uv', 'cachePv', 'cacheUv'));
  37. // 更新pv uv
  38. QappPushTask::updatePushTask($pushId, [
  39. 'pv' => $pv + $cachePv,
  40. 'uv' => $uv + $cacheUv,
  41. ]);
  42. }
  43. }
  44. return true;
  45. }
  46. }