JuliangAccountReportRanse.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Jobs\Callback;
  3. use App\Service\Callback\Tiktok\TiktokEventReportService;
  4. use App\Service\Callback\TrackService;
  5. use App\Service\User\UserRanseService;
  6. use App\Service\Util\Support\Trace\TraceContext;
  7. use Illuminate\Bus\Queueable;
  8. use Illuminate\Contracts\Queue\ShouldBeUnique;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Queue\SerializesModels;
  13. use Illuminate\Support\Facades\DB;
  14. class JuliangAccountReportRanse implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. private $info;
  18. /**
  19. * Create a new job instance.
  20. * <pre>
  21. * [
  22. * 'ip' => 'xxx',
  23. * 'ranseId' => 'xxx',
  24. * 'ranseStartAt' =>'xxx',
  25. * 'ranseEndAt' => 'xxx,
  26. * 'uid' => 'xxx',
  27. * 'traceInfo' => []
  28. * ]
  29. * </pre>
  30. */
  31. public function __construct($info)
  32. {
  33. $this->info = $info;
  34. }
  35. /**
  36. * Execute the job.
  37. */
  38. public function handle(): void
  39. {
  40. /**
  41. * 1, ip , ranseId, 在最近的3 分钟里 找到检测链接记录
  42. * 2, 如果找到了,就执行回传.
  43. * 3, 将信息记录入库.
  44. */
  45. $traceContext = TraceContext::newFromParent($this->info['traceInfo']);
  46. myLog('JuliangAccountReportRanse')->info('开始执行回传', [
  47. 'uid' => $this->info['uid'], 'ip' => $this->info['ip'], 'ranseId' => $this->info['ranseId'],
  48. 'traceInfo' => $traceContext->getTraceInfo()
  49. ]);
  50. $trackRecord = TrackService::getTrackRecord('juliangAccount', [
  51. 'ip' => $this->info['ip'], 'ranseId' => $this->info['ranseId']
  52. ]);
  53. if(is_null($trackRecord)) {
  54. myLog('JuliangAccountReportRanse')->warning('没有找到监测记录', [
  55. 'traceInfo' => $traceContext->getTraceInfo()
  56. ]);
  57. return ;
  58. }
  59. $promotion = DB::table('promotions')
  60. ->where(['id' => $this->info['ranseId'], 'is_enabled' => 1])
  61. ->select('callback_type', 'callback_config_id')->first();
  62. if(!$promotion) {
  63. myLog('JuliangAccountReportRanse')->warning('end:染色推广记录不存在', [
  64. 'traceInfo' => $traceContext->getTraceInfo()
  65. ]);
  66. return ;
  67. }
  68. if(1 != $promotion->callback_type) {
  69. myLog('JuliangAccountReportRanse')->warning('end:推广记录不是巨量账户级回传', [
  70. 'traceInfo' => $traceContext->getTraceInfo()
  71. ]);
  72. return ;
  73. }
  74. $callbackConfig = DB::table('juliang_account_callback_config')
  75. ->where(['id' => $promotion->callback_config_id])->first();
  76. if(!$callbackConfig) {
  77. myLog('JuliangAccountReportRanse')->warning('end:推广记录没有回传配置', [
  78. 'traceInfo' => $traceContext->getTraceInfo()
  79. ]);
  80. return ;
  81. }
  82. if(0 == $callbackConfig->state) {
  83. myLog('JuliangAccountReportRanse')->info('end:推广记录对应回传配置关闭', [
  84. 'traceInfo' => $traceContext->getTraceInfo()
  85. ]);
  86. return ;
  87. }
  88. if($callbackConfig->adv_account_id != $trackRecord['advertiser_id']) {
  89. myLog('JuliangAccountReportRanse')->warning('end:推广配置的广告主id和监测记录广告主id不一致', [
  90. 'tuiguang_advertiser_id' => $callbackConfig->adv_account_id,
  91. 'jiance_advertiser_id' => $trackRecord['advertiser_id'],
  92. 'traceInfo' => $traceContext->getTraceInfo()
  93. ]);
  94. return ;
  95. }
  96. $service = new TiktokEventReportService();
  97. $reportResult = $service->reportActive((object)[
  98. 'callback' => $trackRecord['callback']
  99. ]);
  100. myLog('JuliangAccountReportRanse')->debug('执行回传结果', [
  101. 'reportResult' => $reportResult,
  102. 'traceInfo' => $traceContext->getTraceInfo()
  103. ]);
  104. $now = date('Y-m-d H:i:s');
  105. DB::table('callback_report_ranse_record')
  106. ->insert([
  107. 'uid' => $this->info['uid'],
  108. 'ranse_id' => $this->info['ranseId'],
  109. 'callback' => $trackRecord['callback'],
  110. 'advertiser_id' => $trackRecord['advertiser_id'],
  111. 'adv_promotion_id' => $trackRecord['adv_promotion_id'],
  112. 'report_result' => \json_encode($reportResult, JSON_UNESCAPED_UNICODE),
  113. 'created_at' => $now,
  114. 'updated_at' => $now,
  115. 'ranse_start_at' => $this->info['ranseStartAt'],
  116. 'ranse_end_at' => $this->info['ranseEndAt'],
  117. 'optimizer_uid' => $promotion->uid,
  118. ]);
  119. }
  120. }