xieruidong 2 年之前
父节点
当前提交
c47edfcd70

+ 18 - 2
application/common/model/Orders.php

@@ -105,10 +105,26 @@ class Orders extends Model
             $this['amount_pay'],
             self::class,
             'whenPaySuccess',
-            ['id'=>$this['id']],
-            "订单【{$this['order_no']}】付款"
+            $this['id'],
+            "订单【{$this['order_no']}】付款",
         );
     }
+    public static function makePayed(Payment $payment){
+        $order=Orders::find($payment['payment_id']);
+        if(!$order){
+            return false;
+        }
+        if(!$order->isNotPay()){
+            return false;
+        }
+        $order['status']=self::S_WAIT_REC;
+        $order['pay_time']=$payment['pay_time'];
+        $order->save();
+        return true;
+    }
+    public function isNotPay(){
+        return $this['status']===self::S_WAIT_PAY;
+    }
 
 
 

+ 6 - 1
application/common/model/Payment.php

@@ -16,7 +16,7 @@ class Payment extends Model
         'params'=>'json',
     ];
 
-    public static function pay(User $user,$pay_type,$amount,$class,$func,$payment_id,$body="订单付款",$payment_type='order'){
+    public static function pay(User $user,$pay_type,$amount,$class,$func,$payment_id,$body="订单付款",$payment_type=''){
         $payment=self::create([
             'pay_type'=>$pay_type,
             'class'=>$class,
@@ -40,5 +40,10 @@ class Payment extends Model
     public function payed(){
         $this['pay_time']=time();
         $this->save();
+        switch ($this['payment_type']){
+            case 'orders':
+                Orders::makePayed($this['payment_id']);
+                break;
+        }
     }
 }

+ 11 - 2
application/common/service/PayReturnService.php

@@ -1,6 +1,7 @@
 <?php
 namespace app\common\service;
 
+use addons\epay\library\Service;
 use app\common\model\Payment;
 use fast\Arr;
 use think\App;
@@ -20,13 +21,21 @@ class PayReturnService{
 
    }
    public function wechat(){
-
+        $payed=Service::checkNotify('wechat');
+        return [
+            $payed!==false,
+            'success'
+        ];
    }
     public function returnUrl(){
         return request()->root(true);
     }
    public function alipay(){
-
+       $payed=Service::checkNotify('alipay');
+       return [
+           $payed!==false,
+           'success'
+       ];
    }
    public function bankUnion(){}
    public function otherUser(){}