From b65ce4717a878fb562614707d4384f97a955e6ac Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Thu, 26 Sep 2024 10:56:02 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E4=BA=86=E9=80=80?=
 =?UTF-8?q?=E6=AC=BE=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BA=86?=
 =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../logic/store_order/StoreOrderLogic.php     | 38 +++----------------
 app/common/logic/PayNotifyLogic.php           |  2 +-
 2 files changed, 6 insertions(+), 34 deletions(-)

diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php
index 94910e3b0..57a1a28d2 100644
--- a/app/admin/logic/store_order/StoreOrderLogic.php
+++ b/app/admin/logic/store_order/StoreOrderLogic.php
@@ -132,49 +132,21 @@ class StoreOrderLogic extends BaseLogic
                 $refund = (new \app\common\logic\store_order\StoreOrderLogic())
                     ->refund($params['order_id'], $money, $pay_price);
                 if ($refund) {
-                    $refund_price = $params['refund_price'];
-                    $refund_num = 0;
-                    foreach ($params['product_arr'] as $k => $v) {
-                        $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find();
-                        if ($find) {
-                            $refund_num += $v['cart_num'];
-                            $cart_num = bcsub($find['cart_num'], $v['cart_num']);
-                            $total_price = bcmul($find['price'], $cart_num);
-                            $data = ['cart_num' => $cart_num, 'total_price' => $total_price];
-                            StoreOrderCartInfo::where('id', $find['id'])->update($data);
-                            $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray();
-                            foreach ($arr as $key => $value) {
-                                $value['cart_num'] = $cart_num;
-                                $value['total_price'] = bcmul($cart_num, $value['price'], 2);
-                                $value['number'] = bcmul($value['total_price'], $value['rate'], 2);
-                                StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]);
-                                unset($value['id']);
-                                $value['create_time'] = strtotime($value['create_time']);
-                                $value['update_time'] = strtotime($value['update_time']);
-                                StoreFinanceFlowProduct::create($value);
-                            }
-                        }
-                    }
-                    $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid');
-                    $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
-                    $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
-                    StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
-                    $detail['refund_price']=$refund_price;
-                    CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
-            
-                    StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
+                    self::refundProduct($detail, $params);
                     return '退款成功';
                 }
             }
             //余额支付   采购款支付
             if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
                 PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']);
+                self::refundProduct($detail, $params);
                 return '退款成功';
 
             }
             //现金支付
             if ($detail['pay_type'] = PayEnum::CASH_PAY) {
                 PayNotifyLogic::cash_refund($params['order_id']);
+                self::refundProduct($detail, $params);
                 return '退款成功';
 
             }
@@ -208,7 +180,7 @@ class StoreOrderLogic extends BaseLogic
         }
     }
 
-    public function refundProduct($detail, $params)
+    public static function refundProduct($detail, $params)
     {
         $refund_price = $params['refund_price'];
         $refund_num = 0;
@@ -237,9 +209,9 @@ class StoreOrderLogic extends BaseLogic
         $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
         $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
         StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
+        $detail['refund_price']=$refund_price;
         CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
 
         StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
-        StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
     }
 }
diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php
index 7ec32a306..ae5f8b2c2 100644
--- a/app/common/logic/PayNotifyLogic.php
+++ b/app/common/logic/PayNotifyLogic.php
@@ -855,7 +855,7 @@ class PayNotifyLogic extends BaseLogic
                 $updateData[] = [
                     'id' => $StoreBranchProduct['id'],
                     'stock' => $StoreBranchProduct['stock'] + $v['cart_num'],
-                    //                    'sales' => ['inc', $v['cart_num']]
+                     'sales' => ['dec', $v['cart_num']]
                     //                    'sales' => ['inc', $v['cart_num']]
                 ];
             }