Jelajahi Sumber

qapp pay return 快应用付费回传

onlinetest 4 tahun lalu
induk
melakukan
d091771f8a

+ 0 - 85
app/Jobs/NewTikTokUserCharge.php

@@ -1,85 +0,0 @@
-<?php
-
-namespace App\Jobs;
-
-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 NewTikTokUserCharge implements ShouldQueue
-{
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
-
-    private $uid;
-    private $amount;
-    private $pay_time;
-    private $type;
-    /**
-     * 分子
-     */
-    private $molecule;
-    /**
-     * 分母
-     */
-    private $denominator;
-
-    protected $url = 'https://newtrackapi.zhuishuyun.com/api/user/charge';
-
-    /**
-     * 一般情况都上传
-     */
-    const COMMON = 'common';
-    /**
-     * 只有当天注册当天充值用户才上传
-     */
-    const CURRENT_DAY_REGISTER = 'current_day_register';
-    /**
-     * Create a new job instance.
-     *
-     * @return void
-     */
-    public function __construct(int $uid, float $amount, string $pay_time, string $type = null, int $molecule = 1, int $denominator = 1)
-    {
-        $this->uid = $uid;
-        $this->amount = $amount;
-        $this->pay_time = $pay_time;
-        $this->type = $type ? $type : 'common';
-        $this->molecule = $molecule;
-        $this->denominator = $denominator;
-    }
-
-    /**
-     * Execute the job.
-     *
-     * @return void
-     */
-    public function handle()
-    {
-        $client = new Client();
-        $params = [
-            'uid' => $this->uid,
-            'amount' => $this->amount,
-            'pay_time' => $this->pay_time,
-            'type' => $this->type,
-            'molecule' => $this->molecule,
-            'denominator' => $this->denominator,
-            'source' => 'zsy'
-        ];
-        $params['sign'] = _sign($params,  SysConsts::TIKTOK_KEY);
-        $response =  $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
-        myLog('new_user_charge')->info($response);
-        $result =  json_decode($response);
-        if ($result) {
-            if ($result->code != 0) {
-                myLog('new_user_charge')->info($response);
-            }
-        }
-    }
-}

+ 81 - 1
app/Jobs/QappTikTokUserCharge.php

@@ -2,10 +2,90 @@
 
 namespace App\Jobs;
 
+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 QappTikTokUserCharge extends NewTikTokUserCharge
+class QappTikTokUserCharge implements ShouldQueue
 {
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    private $uid;
+    private $amount;
+    private $pay_time;
+    private $type;
+    private $book_id;
+    private $book_name;
+    /**
+     * 分子
+     */
+    private $molecule;
+    /**
+     * 分母
+     */
+    private $denominator;
+
     protected $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/charge';
+
+    /**
+     * 一般情况都上传
+     */
+    const COMMON = 'common';
+    /**
+     * 只有当天注册当天充值用户才上传
+     */
+    const CURRENT_DAY_REGISTER = 'current_day_register';
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct(int $uid, float $amount, string $pay_time, string $type, string $book_id, string $book_name, int $molecule = 1, int $denominator = 1)
+    {
+        $this->uid = $uid;
+        $this->amount = $amount;
+        $this->pay_time = $pay_time;
+        $this->type = $type;
+        $this->book_id = $book_id;
+        $this->book_name = $book_name;
+        $this->molecule = $molecule;
+        $this->denominator = $denominator;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $client = new Client();
+        $params = [
+            'uid' => $this->uid,
+            'amount' => $this->amount,
+            'pay_time' => $this->pay_time,
+            'type' => $this->type,
+            'book_id' => $this->book_id,
+            'book_name' => $this->book_name,
+            'molecule' => $this->molecule,
+            'denominator' => $this->denominator,
+            'source' => 'zsy'
+        ];
+        $params['sign'] = _sign($params,  SysConsts::TIKTOK_KEY);
+        $response =  $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
+        myLog('new_user_charge')->info($response);
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code != 0) {
+                myLog('new_user_charge')->info($response);
+            }
+        }
+    }
 }

+ 13 - 2
app/Modules/Trade/Pay/PaySuccessAbstract.php

@@ -3,7 +3,9 @@
 namespace App\Modules\Trade\Pay;
 
 use App\Jobs\QappTikTokUserCharge;
+use App\Modules\Book\Models\BookConfig;
 use App\Modules\Subscribe\Models\Order;
+use App\Modules\User\Services\ReadRecordService;
 use Exception;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
@@ -35,9 +37,8 @@ abstract class PaySuccessAbstract
          DB::beginTransaction();
          $this->setOrderSuccess();
          $this->handlePayProcess();
-         $job = new QappTikTokUserCharge($this->order->uid, $this->order->price, $this->order->created_at);
-         dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_charge_queue'));
          DB::commit();
+         $this->addQueue();
          return true;
       } catch (Exception $e) {
          DB::rollback();
@@ -66,4 +67,14 @@ abstract class PaySuccessAbstract
       $count = Order::where('uid', $this->order->uid)->where('status', 'PAID')->count('id');
       return $count + 1;
    }
+
+   protected function addQueue()
+   {
+      $bid = ReadRecordService::getSimpleFirstReadRecord($this->order->uid);
+      $book_id = book_hash_encode($bid);
+      $book = BookConfig::where('bid', $bid)->select('$book_name')->first();
+      $book_name = $book ? $book->book_name : '';
+      $job = new QappTikTokUserCharge($this->order->uid, $this->order->price, $this->order->created_at, QappTikTokUserCharge::CURRENT_DAY_REGISTER, $book_id, $book_name);
+      dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_charge_queue'));
+   }
 }