ReportService.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Services\Report;
  3. use App\Dao\Report\ReportDao;
  4. use App\Jobs\ReportDy;
  5. use Exception;
  6. class ReportService
  7. {
  8. private $connection = 'redis';
  9. private $reportDao;
  10. public function __construct(
  11. ReportDao $reportDao
  12. )
  13. {
  14. $this->reportDao = $reportDao;
  15. }
  16. /**
  17. * 注册上报
  18. *
  19. * @param $user
  20. * @param $params
  21. * @return void
  22. */
  23. public function reportRegister($user, $params)
  24. {
  25. $eventType = 'active_register';
  26. $clickId = trim(getProp($params, 'clickid'));
  27. if (empty($clickId)) {
  28. return;
  29. }
  30. // 去重
  31. $reportLog = $this->reportDao->getReportLogByClickId($clickId, $eventType);
  32. if (getProp($reportLog, 'id')) {
  33. return;
  34. }
  35. // 记录表
  36. $this->reportDao->saveReportLog([
  37. 'adid' => trim(getProp($params, 'adid')),
  38. 'clickid' => $clickId,
  39. 'projectid' => trim(getProp($params, 'projectid')),
  40. 'promotionid' => trim(getProp($params, 'promotionid')),
  41. 'uid' => (int)getProp($user, 'uid'),
  42. 'send_order_id' => (int)getProp($params, 'send_order_id'),
  43. 'ad_params' => getProp($params, 'ad_params'),
  44. 'event_type' => $eventType,
  45. 'created_at' => date('Y-m-d H:i:s'),
  46. 'updated_at' => date('Y-m-d H:i:s'),
  47. ]);
  48. // 新用户上报
  49. $isNewUser = (bool)getProp($user, 'is_new_user');
  50. if ($isNewUser) {
  51. // 上报参数
  52. $paramss = [
  53. 'clickid' => $clickId,
  54. 'event_type' => $eventType,
  55. 'context' => [
  56. 'ad' => [
  57. 'callback' => $clickId,
  58. ]
  59. ],
  60. 'timestamp' => (int)(microtime(true) * 1000)
  61. ];
  62. // 执行上报
  63. try {
  64. ReportDy::dispatch($paramss)->onConnection($this->connection);
  65. } catch (Exception $e) {
  66. dLog('exception')->info('reportRegister', [$e->getMessage()]);
  67. }
  68. }
  69. }
  70. }