xxxrrrdddd пре 3 година
родитељ
комит
36d1ea3179
1 измењених фајлова са 32 додато и 1 уклоњено
  1. 32 1
      application/index/controller/Payment.php

+ 32 - 1
application/index/controller/Payment.php

@@ -4,6 +4,8 @@ namespace app\index\controller;
 
 use addons\epay\library\Service;
 use app\common\controller\Frontend;
+use app\common\model\MobileOrder;
+use think\Db;
 
 /**
  * 第三方登录控制器
@@ -17,11 +19,40 @@ class Payment extends Frontend
      */
     public function notify($type,$order_no)
     {
-        if (!Service::checkNotify($type)) {
+        $data=Service::checkNotify($type);
+        if (!$data) {
             echo '签名错误';
             return;
         }
 
+        $name="pay/$type/{$order_no}";
+        user_log($name,compact('type','order_no','data'));
+        Db::startTrans();
+        $order=MobileOrder::where('order_no',$order_no)->lock(true)->find();
+        if(!$order){
+            user_log($name,"订单没找到");
+            Db::rollback();
+            return '订单没找到';
+        }
+        if($order['pay_time']){
+            user_log($name,"订单已支付");
+            Db::rollback();
+            return '订单已支付';
+        }
+        $order['pay_time']=time();
+        if($type=='wechat'){
+            $order['pay_type']=1;
+            $order['pay_no']=$data['transaction_id'];
+        }else{
+            $order['pay_type']=2;
+        }
+        if(!$order->save()){
+            user_log($name,"保存失败");
+            Db::rollback();
+            return '保存失败';
+        }
+        Db::commit();
+
         //你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
         //下面这句必须要执行,且在此之前不能有任何输出
         echo "success";