onlinetest 4 years ago
parent
commit
2d011770d4

+ 65 - 0
app/Jobs/QappTikTok/NewQappTikTokUserCharge.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Jobs\QappTikTok;
+
+use App\Consts\SysConsts;
+use GuzzleHttp\Client;
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+
+/**
+ * 抖音用户充值
+ */
+class NewQappTikTokUserCharge implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $reportParams;
+
+    protected $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/new_charge';
+
+    /**
+     * QappTikTokUserCharge constructor.
+     * @param QappTikTokUserChargeRequest $reportParams
+     */
+    public function __construct(QappTikTokUserChargeRequest $reportParams)
+    {
+        $this->reportParams = $reportParams;
+    }
+
+    /**
+     * Execute the job.
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'uid'         => (int)$this->reportParams->uid,
+            'amount'      => (float)$this->reportParams->amount,
+            'pay_time'    => (string)$this->reportParams->pay_time,
+            'order_no'     => (string)$this->reportParams->order_no,
+            'book_id'     => (string)$this->reportParams->book_id,
+            'book_name'   => (string)$this->reportParams->book_name,
+            'source'      => 'zsy',
+        ];
+
+        // 避免签名错误
+        if ($this->reportParams->send_order_id) {
+            $params['send_order_id'] = $this->reportParams->send_order_id;
+        }
+
+        $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
+        $response       = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
+        myLog('qapp_user_charge')->info($response);
+        $result = json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('qapp_user_charge')->info($response);
+            }
+        }
+    }
+}

+ 6 - 2
app/Jobs/QappTikTok/QappTikTokUserChargeRequest.php

@@ -15,6 +15,11 @@ class QappTikTokUserChargeRequest
     // 支付时间
     public $pay_time;
 
+    /**
+     * 订单号
+     */
+    public $order_no;
+
     // 上报类型
     public $type;
 
@@ -38,5 +43,4 @@ class QappTikTokUserChargeRequest
 
     // 分母
     public $denominator = 100;
-
-}
+}

+ 3 - 9
app/Modules/Trade/Pay/PaySuccessAbstract.php

@@ -2,6 +2,7 @@
 
 namespace App\Modules\Trade\Pay;
 
+use App\Jobs\QappTikTok\NewQappTikTokUserCharge;
 use App\Jobs\QappTikTok\QappTikTokUserChargeRequest;
 use App\Jobs\QappTikTok\QappTikTokUserCharge;
 use App\Modules\Book\Models\BookConfig;
@@ -99,22 +100,15 @@ abstract class PaySuccessAbstract
         $tikTokChargeRequest                = new QappTikTokUserChargeRequest();
         $tikTokChargeRequest->uid           = $this->order->uid;
         $tikTokChargeRequest->amount        = $this->order->price;
+        $tikTokChargeRequest->order_no        = $this->order->trade_no;
         $tikTokChargeRequest->pay_time      = $this->order->created_at;
-        $tikTokChargeRequest->type          = $reportType ?: $this->getReportType($this->order->distribution_channel_id);
         $tikTokChargeRequest->book_id       = $book_id;
         $tikTokChargeRequest->book_name     = $book_name;
         $tikTokChargeRequest->send_order_id = $sendOrderId;
-        $tikTokChargeRequest->molecule      = $reportRate;
-
-        // 求最大公约数、格式化比例值
-        $molecule    = $reportRate;
-        $denominator = $tikTokChargeRequest->denominator;
-        $gcd         = gcd($molecule, $denominator);
-        [$tikTokChargeRequest->molecule, $tikTokChargeRequest->denominator] = proportion($molecule, $denominator, $gcd);
 
         // 需要跟派单设置的回传类型一致才上报
         myLog('qapp_user_charge')->info('addQueue', compact('tikTokChargeRequest'));
-        $job = new QappTikTokUserCharge($tikTokChargeRequest);
+        $job = new NewQappTikTokUserCharge($tikTokChargeRequest);
         dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_charge_queue'));
     }
 }