Procházet zdrojové kódy

回传redis队列配置

liuzejian před 2 roky
rodič
revize
480cb92128

+ 1 - 0
app/Jobs/Callback/JuliangAccountReportRanse.php

@@ -123,6 +123,7 @@ class JuliangAccountReportRanse implements ShouldQueue
                 'ranse_start_at' => $this->info['ranseStartAt'],
                 'ranse_end_at' => $this->info['ranseEndAt'],
                 'optimizer_uid' => $promotion->uid,
+                'ranse_ip' => $trackRecord['ip'],
             ]);
     }
 }

+ 15 - 0
app/Service/Callback/JuliangAccountReportChargeService.php

@@ -94,12 +94,17 @@ class JuliangAccountReportChargeService
                         'filter_reason' => $this->result['info_str'] ?? '允许回传',
                         'report_success' => intval($this->result['report_success'] ?? false),
                         'report_result' => \json_encode($this->result['report_result'] ?? []),
+                        'report_param' => \json_encode($this->result['report_param'] ?? []),
                         'created_at' => $now,
                         'updated_at' => $now,
                         'advertiser_id' => $this->trackRecord->advertiser_id ?? '',
                         'adv_promotion_id' => $this->trackRecord->adv_promotion_id ?? '',
                         'config_rate' => $this->result['config_rate'],
                         'current_rate' => $this->result['current_rate'],
+                        'user_ranse_start_at' => $this->trackRecord->ranse_start_at ?? null,
+                        'order_price' => $this->order->price,
+                        'order_created_at' => $this->order->created_at,
+                        'user_ranse_ip' => $this->trackRecord->ranse_ip ?? '',
                     ]);
             } else {
                 DB::table('callback_report_charge_record')
@@ -113,11 +118,16 @@ class JuliangAccountReportChargeService
                         'filter_reason' => $this->result['info_str'] ?? '允许回传',
                         'report_success' => intval($this->result['report_success'] ?? false),
                         'report_result' => \json_encode($this->result['report_result'] ?? []),
+                        'report_param' => \json_encode($this->result['report_param'] ?? []),
                         'updated_at' => $now,
                         'advertiser_id' => $this->trackRecord->advertiser_id ?? '',
                         'adv_promotion_id' => $this->trackRecord->adv_promotion_id ?? '',
                         'config_rate' => $this->result['config_rate'],
                         'current_rate' => $this->result['current_rate'],
+                        'user_ranse_start_at' => $this->trackRecord->ranse_start_at ?? null,
+                        'order_price' => $this->order->price,
+                        'order_created_at' => $this->order->created_at,
+                        'user_ranse_ip' => $this->trackRecord->ranse_ip ?? '',
                     ]);
             }
 
@@ -327,6 +337,11 @@ class JuliangAccountReportChargeService
             $this->result['need_report'] = false;
             $this->result['info_type'] = 'no_track_info';
             $this->result['info_str'] = '无匹配用户';
+            return;
         }
+
+        $this->result['report_param'] = [
+            'callback' => $this->trackRecord->callback,
+        ];
     }
 }

+ 6 - 1
config/database.php

@@ -165,7 +165,12 @@ return [
             'port' => env('REDIS_PORT', '6379'),
             'database' => env('REDIS_CACHE_DB', '1'),
         ],
-
+        'report-redis' => [//专门处理回传队列的服务器
+            'host' => env('REPORT_QUEUE_REDIS_HOST', 'localhost'),
+            'password' => env('REPORT_QUEUE_REDIS_PASSWORD', null),
+            'port' => env('REPORT_QUEUE_REDIS_PORT', 6379),
+            'database' => 2,
+        ],
     ],
 
 ];

+ 6 - 1
config/queue.php

@@ -70,7 +70,12 @@ return [
             'block_for' => null,
             'after_commit' => false,
         ],
-
+        'report-queue' => [
+            'driver' => 'redis',
+            'connection' => 'report-queue',
+            'queue' => 'default',
+            'expire' => 60,
+        ]
     ],
 
     /*

+ 24 - 0
tests/Jobs/Callback/ReportChargeTest.php

@@ -19,6 +19,13 @@ class ReportChargeTest extends \Tests\TestCase
                 'traceInfo' => $traceContext->getTraceInfo()]);
             $reportCharge->handle();
         }
+
+        foreach (range(151, 163) as $i) {
+            $traceContext = new TraceContext();
+            $reportCharge = new ReportCharge(['uid' => 1000 + $i -150, 'orderId' => 10000 + $i,
+                'traceInfo' => $traceContext->getTraceInfo()]);
+            $reportCharge->handle();
+        }
     }
 
     private function prepareData() {
@@ -48,6 +55,23 @@ class ReportChargeTest extends \Tests\TestCase
                 'report_result' => '[]',
                 'created_at' => date('Y-m-d H:i:s'),
                 'updated_at' => date('Y-m-d H:i:s'),
+                'ranse_ip' =>'192.168.1.123',
+                'optimizer_uid' => 5
+            ];
+        }
+
+        foreach (range(151, 163) as $i) {
+            $orders[] = [
+                'id' => 10000 + $i,
+                'uid' => 1000 + $i - 150,
+                'promotion_id' => $promotionId,
+                'user_id' => $optimizerId,
+                'price' => rand(40, 70),
+                'pay_product_id' => 1,
+                'status' => 'PAID',
+                'trade_no' => uniqid(),
+                'created_at' => '2023-05-19 14:'.(44 + rand(5, 10)),
+                'updated_at' => date('Y-m-d H:i:s'),
             ];
         }
         DB::table('orders')->where('id', '>=', 10001)->delete();