laowu hai 1 semana
pai
achega
7b8c9378b8

+ 6 - 1
app/Http/Controllers/Api/PayPlusController.php

@@ -45,7 +45,10 @@ class PayPlusController implements PayMentInterFace
     public function notify(Request $request)
     {
         $post = $request->all();
+        $content = (string) $request->getContent();
+        $post = json_decode($content, true) ?: $post;
         Util::WriteLog('PayPlus', 'pay notify: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
+        Util::WriteLog('PayPlus', 'pay notify header: ' . json_encode($request->headers->all()));
 
         $orderSn = $post['data']['platform_order_id'] ?? '';
         if ($orderSn === '') {
@@ -81,8 +84,10 @@ class PayPlusController implements PayMentInterFace
     public function cash_notify(Request $request)
     {
         $post = $request->all();
+        $content = (string) $request->getContent();
+        $post = json_decode($content, true) ?: $post;
         Util::WriteLog('PayPlus', 'cash notify: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
-        Util::WriteLog('PayPlus', 'cash notify body: ' . (string) $request->getContent());
+        Util::WriteLog('PayPlus', 'cash notify header: ' . json_encode($request->headers->all()));
         $signature = $request->header('Authorization', '');
         $service = (new PayPlus())->getPayoutService();
         if (!$service->verifyPayoutSignature($post, $signature)) {

+ 18 - 1
app/Http/logic/api/PayPlusLogic.php

@@ -10,6 +10,7 @@ use App\Jobs\Order;
 use App\Notification\TelegramBot;
 use App\Services\CreateLog;
 use App\Services\OrderServices;
+use App\Services\PayConfig;
 use App\Services\PayPlus;
 use App\Util;
 use Illuminate\Support\Facades\DB;
@@ -171,12 +172,28 @@ class PayPlusLogic extends BaseApiLogic
         ];
 
         if ($this->isSuccessfulPayment($post)) {
+            $AdId = $order->AdId ?: '';
+            $eventType = $order->eventType ?: '';
+
             $payAmount = round((float) ($data['amount'] ?? 0), 2);
             $body['pay_status'] = 1;
             $body['pay_at'] = date('Y-m-d H:i:s');
             $body['finished_at'] = date('Y-m-d H:i:s');
             $body['amount'] = (int) round($payAmount * NumConfig::NUM_VALUE);
 
+            $config = (new PayConfig())->getConfig('PayPlus');
+            // 根据支付方式计算代收手续费: 费率% * 金额 + 固定$
+            // pay_rate 格式: [1=>[10,0.3], 2=>[13,0.3], 4=>[11,0.3], 8=>[12,0.3]]
+            $payRates = $config['pay_rate'] ?? null;
+            if (is_array($payRates)) {
+                $payMethod = $order->order_title ?? 1;
+                $payRate = $payRates[$payMethod] ?? ($payRates[1] ?? [10, 0.3]);
+                $feePercent = $payRate[0] ?? 10;
+                $feeFixed = $payRate[1] ?? 0.3;
+                $body['payment_fee'] = intval(($body['amount'] * $feePercent) / 100)
+                    + (int)($feeFixed * NumConfig::NUM_VALUE);
+            }
+
             $service = new OrderServices();
             list($give, $favorablePrice, $recharge, $czReason, $cjReason) = $service->getPayInfo(
                 $order->GiftsID ?: '',
@@ -195,7 +212,7 @@ class PayPlusLogic extends BaseApiLogic
                 $cjReason,
                 $order->AdId ?: '',
                 $order->eventType ?: '',
-                0
+                $body['payment_fee'] ?? 0
             );
 
             Order::dispatch([