From bc6855fc7c3cfa5856e4fa77412d08b669ee8b8d Mon Sep 17 00:00:00 2001
From: liu <1873441552@qq.com>
Date: Thu, 27 Jun 2024 18:23:00 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=A0=E5=85=A5=E5=86=BB?=
 =?UTF-8?q?=E7=BB=93=E5=85=91=E6=8D=A2=E5=88=B8=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/common/logic/PayNotifyLogic.php | 117 +++++++++++++---------------
 1 file changed, 52 insertions(+), 65 deletions(-)

diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php
index 0d00a6857..311be253b 100644
--- a/app/common/logic/PayNotifyLogic.php
+++ b/app/common/logic/PayNotifyLogic.php
@@ -206,6 +206,7 @@ class PayNotifyLogic extends BaseLogic
             OrderLogic::writeOff($params);
         }
         self::dealProductLog($order);
+        self::addFlowLog($order);
         //        if($order['shipping_type'] == 3){
         //            self::descStock($order['id']);
         //        }
@@ -220,9 +221,9 @@ class PayNotifyLogic extends BaseLogic
     {
         //查询当前用户有无对应的充值的冻结金额
         if($order['uid'] >0 ){
-            $query = VipFlow::where([
+            $query = UserSign::where([
                 'user_id'=>$order['uid'],
-                'type'=>2,
+                'type'=>1,
                 'status'=>0
             ]);
             $query1 = clone $query;
@@ -234,30 +235,27 @@ class PayNotifyLogic extends BaseLogic
                 if($count == 1){
                     //存在拆单子否
                     //少了就冻结减去这个对应的金额
-                    $one = VipFlow::where([
+                    $one = UserSign::where([
                         'user_id'=>$order['uid'],
-                        'type'=>2,
+                        'type'=>1,
                         'status'=>0
                     ])->find();
                     $data = [
-                        'vip_flow_id'=>$one['id'],
-                        'order_id' => $order['id'],
-                        'order_sn' => $order['order_id'],
-                        'user_id' => $order['uid'],
-                        'pay_type' => $pay_type ?? 1,
-                        'status' => 1,
-                        'type' => 1,
+                        'uid' => $order['uid'],
+                        'order_id' => $order['order_id'],
+                        'title' => '充值获得冻结兑换券',
+                        'financial_pm' => 1,
                         'store_id' => $order['store_id'],
-                        'staff_id' => $order['staff_id'],
-                        'create_time' => time()
+                        'type' => 1,
                     ];
+
                     if($one['back_num'] >= $backPurchase){
                         $data['number'] =$backPurchase;
-                        Db::name('la_vip_flow_log')->insert($data);
+                        Db::name('user_sign_log')->insert($data);
                         //总的减去采购款百分之十剩余的
                         $wait = bcsub($one['back_num'],$backPurchase,2);
                         if(empty($wait)){
-                            VipFlow::where('id',$one['id'])->update(
+                            UserSign::where('id',$one['id'])->update(
                                 [
                                     'back_num'=>0,
                                     'status'=>1
@@ -265,7 +263,7 @@ class PayNotifyLogic extends BaseLogic
                             );
                         }else{
                             //add
-                            VipFlow::where('id',$one['id'])->update([
+                            UserSign::where('id',$one['id'])->update([
                                 [
                                     'back_num'=>$wait
                                 ]
@@ -273,12 +271,13 @@ class PayNotifyLogic extends BaseLogic
                         }
                         //并且加到对应的用户的采购款中
                         User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
-                    }else{
+                    }
+                    else{
                         //对比采购款支付的多少  多了就拿冻结金额即可
                         $data['number'] =$one['number'];
                         //都存到对应的log日志
-                        Db::name('la_vip_flow_log')->insert($data);
-                        VipFlow::where('id',$one['id'])->update(
+                        Db::name('user_sign_log')->insert($data);
+                        UserSign::where('id',$one['id'])->update(
                             [
                                 'back_num'=>0,
                                 'status'=>1
@@ -292,56 +291,46 @@ class PayNotifyLogic extends BaseLogic
                     //大于0的时候
                     //先处理金额大的再处理剩余的
                     /**** 把所有的金额改为正的再加一条后再加***/
-                    VipFlow::where([
+                    UserSign::where([
                         'user_id'=>$order['uid'],
-                        'type'=>2,
+                        'type'=>1,
                         'status'=>0
                     ])->update([
                         'status'=>1,
-                        'remark'=>json_encode($ids)
+                        'title'=>json_encode($ids)
                     ]);
                     if ($check >= $backPurchase) {
                         //补一条待解冻的
-//                        $data = [
-//                            'order_id' => $order['id'],
-//                            'transaction_id' => $transaction_id ?? 0,
-//                            'order_sn' => $order['order_id'],
-//                            'user_id' => $order['uid'],
-//                            'number' => $total_vip,
-//                            'back_num' => $total_vip,
-//                            'pay_type' => $pay_type ?? 1,
-//                            'status' => 0,
-//                            'type' => 1,
-//                            'store_id' => $order['store_id'],
-//                            'staff_id' => $order['staff_id'],
-//                            'create_time' => time()
-//                        ];
-//                        Db::name('vip_flow')->insert($data);
+                        $left = bcsub($check,$backPurchase,2);
+                        if($left > 0){
+                            $data = [
+                                'uid' => $order['uid'],
+                                'order_id' => $order['order_id'],
+                                'title' => '补冻结兑换券',
+                                'financial_pm' => 0,
+                                'store_id' => $order['store_id'],
+                                'type' => 1,
+                            ];
+                            $data['number'] =$check;
+                            Db::name('user_sign')->insert($data);
+                        }
+                        User::where('id',$order['uid'])->inc('purchase_funds',$backPurchase)->update();//add
 
                     }else{
                         //log
                         $data = [
-                            'vip_flow_id'=>0,
-                            'remark'=>$ids,
-                            'order_id' => $order['id'],
-                            'order_sn' => $order['order_id'],
-                            'user_id' => $order['uid'],
-                            'pay_type' => $pay_type ?? 1,
-                            'status' => 1,
-                            'type' => 1,
+                            'uid' => $order['uid'],
+                            'order_id' => $order['order_id'],
+                            'title' => '充值获得冻结兑换券',
+                            'financial_pm' => 1,
                             'store_id' => $order['store_id'],
-                            'staff_id' => $order['staff_id'],
-                            'create_time' => time()
+                            'type' => 1,
                         ];
                         $data['number'] =$check;
-                        Db::name('la_vip_flow_log')->insert($data);
+                        Db::name('user_sign_log')->insert($data);
                         User::where('id',$order['uid'])->inc('purchase_funds',$check)->update();//add
                     }
 
-
-
-
-
                 }
 
             }
@@ -349,7 +338,7 @@ class PayNotifyLogic extends BaseLogic
 
         }
 
-        
+        return true;
     }
 
     /**
@@ -594,21 +583,19 @@ class PayNotifyLogic extends BaseLogic
     public static function dealRechargeFrozen($order)
     {
         $total_vip = bcmul($order['price'],0.1,2);
-        $data = [
-            'order_id' => $order['id'],
-            'transaction_id' => $transaction_id ?? 0,
-            'order_sn' => $order['order_id'],
-            'user_id' => $order['uid'],
+        $user_sing = new UserSign();
+        $sing = [
+            'uid' => $order['uid'],
+            'order_id' => $order['order_id'],
+            'title' => '充值获得冻结兑换券',
+            'financial_pm' => 1,
+            'store_id' => $order['store_id'],
+            'type' => 1,
             'number' => $total_vip,
             'back_num' => $total_vip,
-            'pay_type' => $pay_type ?? 1,
-            'status' => 0,
-            'type' => 1,
-            'store_id' => $order['store_id'],
-            'staff_id' => $order['staff_id'],
-            'create_time' => time()
         ];
-        Db::name('vip_flow')->insert($data);
+            $user_sing->save($sing);
+
         return true;
     }