xieruidong 2 years ago
parent
commit
befb9c2c9d

+ 0 - 4
application/common/model/Orders.php

@@ -138,10 +138,6 @@ class Orders extends Model
 
 
 
-
-    public static function whenPaySuccess($params){
-
-    }
     protected static function init()
     {
         self::beforeInsert(function (self $orders){

+ 2 - 11
application/common/model/Payment.php

@@ -38,16 +38,7 @@ class Payment extends Model
     }
 
     public function payed(){
-        $user=$this->user;
-        return payment($user)->handlePaidNotify(function ($message, $fail){
-            Log::info("支付通知:".json_encode($message));
-            if($this['pay_time']){
-                return true;
-            }
-            $this['pay_time']=date('Y-m-d H:i:s');
-            $class=new $this['class'];
-            $class->{$this['func']}($this['params'],$this);
-            return true;
-        });
+        $this['pay_time']=time();
+        $this->save();
     }
 }

+ 2 - 2
application/common/service/OrderPayService.php

@@ -12,7 +12,7 @@ class OrderPayService{
     protected $payment;
     /** @var string */
     protected $body;
-    protected $methods=[
+    public static $methods=[
         Orders::PT_QYWY=>'companyBank',
         Orders::PT_WX=>'wechat',
         Orders::PT_ZFB=>'alipay',
@@ -95,7 +95,7 @@ class OrderPayService{
    public function otherUser(){}
    public function offline(){}
    public function pay(){
-        $method=Arr::get($this->methods,$this->payment->pay_type);
+        $method=Arr::get(self::$methods,$this->payment->pay_type);
         return App::invokeMethod([$this,$method]);
    }
 }

+ 5 - 16
application/common/service/OrderPaySuccService.php → application/common/service/PayReturnService.php

@@ -1,23 +1,13 @@
 <?php
 namespace app\common\service;
 
-use addons\epay\library\Service;
-use app\common\model\Orders;
 use app\common\model\Payment;
 use fast\Arr;
 use think\App;
 
-class OrderPaySuccService{
+class PayReturnService{
     /** @var Payment */
     protected $payment;
-    protected $methods=[
-        Orders::PT_QYWY=>'companyBank',
-        Orders::PT_WX=>'wechat',
-        Orders::PT_ZFB=>'alipay',
-        Orders::PT_YL=>'bankUnion',
-        Orders::PT_DF=>'otherUser',
-        Orders::PT_OFF=>'offline',
-    ];
 
     /**
      * @param Payment $payment
@@ -26,12 +16,11 @@ class OrderPaySuccService{
     {
         $this->payment = $payment;
     }
-   public function companyBank(){}
-   public function wechat(){
+   public function companyBank(){
 
    }
-   public function notifyUrl(){
-        return request()->root(true)."/index/payment/notify/order_no/".$this->payment->order_no;
+   public function wechat(){
+
    }
     public function returnUrl(){
         return request()->root(true);
@@ -43,7 +32,7 @@ class OrderPaySuccService{
    public function otherUser(){}
    public function offline(){}
    public function process(){
-        $method=Arr::get($this->methods,$this->payment->pay_type);
+        $method=Arr::get(OrderPayService::$methods,$this->payment->pay_type);
         return App::invokeMethod([$this,$method]);
    }
 }

+ 12 - 48
application/index/controller/Payment.php

@@ -2,11 +2,9 @@
 
 namespace app\index\controller;
 
-use addons\epay\library\Service;
 use app\common\controller\Frontend;
-use app\common\model\MobileOrder;
-use app\common\service\SmsSend;
-use app\service\byte_dance\OceanEngineService;
+use app\common\service\OrderPaySuccService;
+use app\common\service\PayReturnService;
 use think\Db;
 
 /**
@@ -21,55 +19,21 @@ class Payment extends Frontend
      */
     public function notify($order_no)
     {
-        $check=Service::checkNotify($type);
-        if (!$check) {
-            echo '签名错误';
-            return;
-        }
-        $data=$check->verify();
-
-        $name="payment/$type/{$order_no}";
-        user_log($name,compact('type','order_no','data'));
         Db::startTrans();
-        $payment=\app\common\model\Payment::where('order_no',$order_no)->lock(true)->find();
+        $payment=\app\common\model\Payment::where('order_no',$order_no)
+            ->lock(true)
+            ->find();
         if(!$payment){
-            user_log($name,"支付没找到");
-            Db::rollback();
-            return 'success';
-        }
-        if($payment['pay_time']){
-            user_log($name,"支付已支付");
             Db::rollback();
-            return 'success';
+            $this->result([],400);
         }
-        $payment['pay_time']=time();
-        if(!$payment->save()){
-            user_log($name,"支付保存失败");
-            Db::rollback();
-            return '支付保存失败';
+        $service=new PayReturnService();
+        $service->setPayment($payment);
+        list($isPay,$succ)=$service->process();
+        if(!$payment['pay_time'] && $isPay){
+            $payment->payed();
         }
         Db::commit();
-
-        Db::startTrans();
-        $mobileOrder=MobileOrder::where('id',$payment['mobile_order_id'])->find();
-        if(!$mobileOrder){
-            user_log($name,"手机订单不存在");
-            Db::rollback();
-            return 'success';
-        }
-        try {
-            $mobileOrder->paySuccessCallback($payment,$data,$type);
-            Db::commit();
-        }catch (\Exception $e){
-            user_log($name,$e->getMessage());
-            Db::rollback();
-            return $e->getMessage();
-        }
-        try {
-            OceanEngineService::setQuery($payment['params']?:[])->setAddon(['order_no'=>$order_no])->shopping();
-        }catch (\Exception $e){}
-
-        echo "success";
-        return;
+        return $succ;
     }
 }