|
@@ -0,0 +1,127 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Jobs\Callback;
|
|
|
+
|
|
|
+use App\Service\Callback\Tiktok\TiktokEventReportService;
|
|
|
+use App\Service\Callback\TrackService;
|
|
|
+use App\Service\User\UserRanseService;
|
|
|
+use App\Service\Util\Support\Trace\TraceContext;
|
|
|
+use Illuminate\Bus\Queueable;
|
|
|
+use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
+use Illuminate\Queue\SerializesModels;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class JuliangAccountReportRanse implements ShouldQueue
|
|
|
+{
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
+
|
|
|
+ private $info;
|
|
|
+ /**
|
|
|
+ * Create a new job instance.
|
|
|
+ * <pre>
|
|
|
+ * [
|
|
|
+ * 'ip' => 'xxx',
|
|
|
+ * 'ranseId' => 'xxx',
|
|
|
+ * 'ranseStartAt' =>'xxx',
|
|
|
+ * 'ranseEndAt' => 'xxx,
|
|
|
+ * 'uid' => 'xxx',
|
|
|
+ * 'traceInfo' => []
|
|
|
+ * ]
|
|
|
+ * </pre>
|
|
|
+ */
|
|
|
+ public function __construct($info)
|
|
|
+ {
|
|
|
+ $this->info = $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Execute the job.
|
|
|
+ */
|
|
|
+ public function handle(): void
|
|
|
+ {
|
|
|
+ /**
|
|
|
+ * 1, ip , ranseId, 在最近的3 分钟里 找到检测链接记录
|
|
|
+ * 2, 如果找到了,就执行回传.
|
|
|
+ * 3, 将信息记录入库.
|
|
|
+ */
|
|
|
+ $traceContext = TraceContext::newFromParent($this->info['traceInfo']);
|
|
|
+ myLog('JuliangAccountReportRanse')->info('开始执行回传', [
|
|
|
+ 'uid' => $this->info['uid'], 'ip' => $this->info['ip'], 'ranseId' => $this->info['ranseId'],
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ $trackRecord = TrackService::getTrackRecord('juliangAccount', [
|
|
|
+ 'ip' => $this->info['ip'], 'ranseId' => $this->info['ranseId']
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(is_null($trackRecord)) {
|
|
|
+ myLog('JuliangAccountReportRanse')->warning('没有找到监测记录', [
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ $promotion = DB::table('promotions')
|
|
|
+ ->where(['id' => $this->info['ranseId'], 'is_enabled' => 1])
|
|
|
+ ->select('callback_type', 'callback_config_id')->first();
|
|
|
+ if(!$promotion) {
|
|
|
+ myLog('JuliangAccountReportRanse')->warning('end:染色推广记录不存在', [
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(1 != $promotion->callback_type) {
|
|
|
+ myLog('JuliangAccountReportRanse')->warning('end:推广记录不是巨量账户级回传', [
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ $callbackConfig = DB::table('juliang_account_callback_config')
|
|
|
+ ->where(['id' => $promotion->callback_config_id])->first();
|
|
|
+ if(!$callbackConfig) {
|
|
|
+ myLog('JuliangAccountReportRanse')->warning('end:推广记录没有回传配置', [
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if(0 == $callbackConfig->state) {
|
|
|
+ myLog('JuliangAccountReportRanse')->info('end:推广记录对应回传配置关闭', [
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if($callbackConfig->adv_account_id != $trackRecord['advertiser_id']) {
|
|
|
+ myLog('JuliangAccountReportRanse')->warning('end:推广配置的广告主id和监测记录广告主id不一致', [
|
|
|
+ 'tuiguang_advertiser_id' => $callbackConfig->adv_account_id,
|
|
|
+ 'jiance_advertiser_id' => $trackRecord['advertiser_id'],
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ $service = new TiktokEventReportService();
|
|
|
+ $reportResult = $service->reportActive((object)[
|
|
|
+ 'callback' => $trackRecord['callback']
|
|
|
+ ]);
|
|
|
+ myLog('JuliangAccountReportRanse')->debug('执行回传结果', [
|
|
|
+ 'reportResult' => $reportResult,
|
|
|
+ 'traceInfo' => $traceContext->getTraceInfo()
|
|
|
+ ]);
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
+ DB::table('callback_report_ranse_record')
|
|
|
+ ->insert([
|
|
|
+ 'uid' => $this->info['uid'],
|
|
|
+ 'ranse_id' => $this->info['ranseId'],
|
|
|
+ 'callback' => $trackRecord['callback'],
|
|
|
+ 'advertiser_id' => $trackRecord['advertiser_id'],
|
|
|
+ 'adv_promotion_id' => $trackRecord['adv_promotion_id'],
|
|
|
+ 'report_result' => \json_encode($reportResult, JSON_UNESCAPED_UNICODE),
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ 'ranse_start_at' => $this->info['ranseStartAt'],
|
|
|
+ 'ranse_end_at' => $this->info['ranseEndAt'],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+}
|