Browse Source

支付回调

moonsflyer 8 months ago
parent
commit
78b1fa1b73
2 changed files with 34 additions and 0 deletions
  1. 27 0
      app/common/logic/PayNotifyLogic.php
  2. 7 0
      app/common/service/pay/WeChatPayService.php

+ 27 - 0
app/common/logic/PayNotifyLogic.php

@@ -17,6 +17,7 @@ namespace app\common\logic;
 use app\common\enum\PayEnum;
 use app\common\enum\user\AccountLogEnum;
 use app\common\model\recharge\RechargeOrder;
+use app\common\model\agricultural_machinery\UserService;
 use app\common\model\user\User;
 use think\facade\Db;
 use think\facade\Log;
@@ -84,5 +85,31 @@ class PayNotifyLogic extends BaseLogic
         $order->save();
     }
 
+    /**
+     * @notes 充值回调
+     * @param $orderSn
+     * @param array $extra
+     * @author 段誉
+     * @date 2023/2/27 15:28
+     */
+    public static function service($orderSn, array $extra = [])
+    {
+        $order = RechargeOrder::where('sn', $orderSn)->findOrEmpty();
 
+
+        // 更新充值订单状态
+        $order->transaction_id = $extra['transaction_id'] ?? '';
+        $order->pay_status = PayEnum::ISPAID;
+        $order->pay_time = time();
+        $order->save();
+
+        //更新服务数据
+        $s_where['order_id'] = $order['id'];
+        $user_service_info = UserService::where($s_where)->findOrEmpty();
+        if(!$user_service_info->isEmpty()){
+            $user_service_info->status = 1;
+            $user_service_info->expiration_time = time() + 365*24*60*60;
+            $user_service_info->save();
+        }
+    }
 }

+ 7 - 0
app/common/service/pay/WeChatPayService.php

@@ -383,6 +383,13 @@ class WeChatPayService extends BasePayService
                         }
                         PayNotifyLogic::handle('recharge', $message['out_trade_no'], $extra);
                         break;
+                    case 'service':
+                        $order = RechargeOrder::where(['sn' => $message['out_trade_no']])->findOrEmpty();
+                        if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) {
+                            return true;
+                        }
+                        PayNotifyLogic::handle('service', $message['out_trade_no'], $extra);
+                        break;
                 }
             }
             return true;