shish před 5 roky
rodič
revize
72f8c9a0f7

+ 1 - 1
app-ghs/controllers/OrderController.php

@@ -546,7 +546,7 @@ class OrderController extends BaseController
             util::fail("退款金额不能小于0");
         }
         if (bccomp($post['price'], $order['realPrice'], 2) == 1) {
-            util::fail("退款金额不能大于实际支付金额");
+            util::fail("退款金额不能大于订单金额");
         }
 
         $connection = Yii::$app->db;

+ 1 - 4
biz-ghs/order/services/RefundOrderService.php

@@ -68,12 +68,10 @@ class RefundOrderService extends BaseService
             $payWay = 0;
 
             if ($payWay == dict::getDict('payWay', 'wxPay')) {
-
+                //无操作
             } elseif ($payWay == dict::getDict('payWay', 'debtPay')) {
-                //客户应付款减少
                 //供应商应收款减少
             } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
-                //客户余额增加
                 //供应商余额减少
             } else {
 
@@ -81,7 +79,6 @@ class RefundOrderService extends BaseService
 
             //引起供应商支出增加
 
-
             return $order;
         } catch (\Exception $exception) {
             util::fail("操作失败" . $exception->getMessage());

+ 88 - 5
biz-hd/cg/services/CgRefundService.php

@@ -2,8 +2,11 @@
 
 namespace bizHd\cg\services;
 
+use biz\pt\classes\PtAssetClass;
+use biz\pt\classes\PtYeChangeClass;
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
+use biz\shop\classes\ShopYeChangeClass;
 use bizHd\base\services\BaseService;
 use bizHd\cg\classes\CgRefundClass;
 use bizHd\purchase\classes\PurchaseClass;
@@ -34,8 +37,12 @@ class CgRefundService extends BaseService
         $refundOrderSn = orderSn::getCgRefundSn();
         $post['orderSn'] = $refundOrderSn;
         $post['cgId'] = $cg->id;
-        $refundPrice = $post['refundPrice'] ?? 0.01;
+        $refundPrice = $post['price'] ?? 0;
+        if (is_numeric($refundPrice) == false || $refundPrice < 0) {
+            util::fail('退款金额有问题');
+        }
         $post['refundPrice'] = $refundPrice;
+        //创建退款单
         $cgRefund = CgRefundClass::add($post, true);
 
         $shopId = $cg->shopId ?? 0;
@@ -48,7 +55,11 @@ class CgRefundService extends BaseService
         $shop->totalIncome = $currentTotalIncome;
         $shop->save();
 
+        $ptStyle = $shop->ptStyle;
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
         $payWay = $cg->payWay;
+        $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
 
         if ($payWay == dict::getDict('payWay', 'wxPay')) {
 
@@ -93,19 +104,91 @@ class CgRefundService extends BaseService
             $cgRefund->save();
 
         } elseif ($payWay == dict::getDict('payWay', 'debtPay')) {
+
             //客户应付款减少
-            //供应商应收款减少
+            $clearId = $cg->clearId ?? 0;
+            if (!empty($clearId)) {
+                util::fail('订单已经结帐,无法再发起退款');
+            }
+            $currentMayPay = bcsub($shop->mayPay, $refundPrice, 2);
+            if ($currentMayPay < 0) {
+                util::fail('应付款有问题');
+            }
+            $shop->mayPay = $currentMayPay;
+            $shop->save();
+
         } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
+
             //客户余额增加
-            //供应商余额减少
-        } else {
+            $currentBalance = bcadd($shop->balance, $refundPrice, 2);
+            $shop->balance = $currentBalance;
+            $shop->save();
+            $currentTxBalance = $shop->txBalance;
+
+            $id = $cgRefund->id;
+            $change = [
+                'relateId' => $id,
+                'capitalType' => $currentType,
+                'amount' => $refundPrice,
+                'balance' => $currentBalance,
+                'txBalance' => $currentTxBalance,
+                'io' => 1,
+                'payWay' => 0,
+                'event' => "采购退款",
+                'sjId' => $sjId,
+                'shopId' => $shopId,
+                'tx' => dict::getDict('yeTx', 'canNot'),
+                'ptStyle' => $ptStyle,
+            ];
+            ShopYeChangeClass::addChange($change, true);
+
+            $asset = null;
+            if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+                $asset = PtAssetClass::getHdBalance();
+            } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+                $asset = PtAssetClass::getGhsBalance();
+            } else {
+                util::fail('没有找到平台');
+            }
+            $currentPtBalance = bcadd($asset->amount, $refundPrice, 2);
+            $asset->amount = $currentPtBalance;
+            $asset->save();
+
+            $txAsset = null;
+            if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+                $txAsset = PtAssetClass::getHdTxBalance();
+            } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+                $txAsset = PtAssetClass::getGhsTxBalance();
+            } else {
+                util::fail('没有找到平台');
+            }
+            $currentPtTxBalance = $txAsset->amount;
+
+            $change = [
+                'relateId' => $id,
+                'capitalType' => $currentType,
+                'amount' => $refundPrice,
+                'balance' => $currentPtBalance,
+                'txBalance' => $currentPtTxBalance,
+                'io' => 1,
+                'payWay' => 0,
+                'event' => "【{$shop->merchantName} {$shop->shopName}】的采购被退款",
+                'sjId' => $sjId,
+                'shopId' => $shopId,
+                'tx' => dict::getDict('yeTx', 'canNot'),
+                'ptStyle' => $ptStyle,
+                'shopName' => $shop->shopName,
+                'sjName' => $shop->merchantName,
+            ];
+            PtYeChangeClass::addChange($change, true);
 
+        } else {
+            util::fail('支付方式没有找到哦!');
         }
 
         $sjId = $cg->sjId ?? 0;
         $shopId = $cg->shopId ?? 0;
         $event = '采购退款';
-        $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
         $capitalData = [
             'capitalType' => $currentType,
             'io' => 1,

+ 1 - 4
biz/sj/classes/CashClass.php

@@ -208,7 +208,7 @@ class CashClass extends BaseClass
         if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
             $txAsset = PtAssetClass::getHdTxBalance();
         } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
-            $txAsset = self::getGhsTxBalance();
+            $txAsset = PtAssetClass::getGhsTxBalance();
         } else {
             CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
             util::fail('没有找到平台');
@@ -226,9 +226,6 @@ class CashClass extends BaseClass
         } else {
             util::fail('没有找到平台');
         }
-        if (bccomp($cashAmount, $asset->amount, 2) == 1) {
-            util::fail('平台余额不足');
-        }
         $currentPtBalance = bcadd($asset->amount, $cashAmount, 2);
         $asset->amount = $currentPtBalance;
         $asset->save();