shish 3 лет назад
Родитель
Сommit
987fd5adaa

+ 0 - 52
biz-ghs/order/classes/RefundOrderItemClass.php

@@ -16,59 +16,7 @@ class RefundOrderItemClass extends BaseClass
 
     public static function addData($data, $order)
     {
-        $productId = $data['productId'] ?? 0;
-        $mainId = $data['mainId'] ?? 0;
-        $unitType = $data['xhUnitType'] ?? 0;
-        $num = $data['xhNum'] ?? 0;
-        $xhUnitPrice = $data['xhUnitPrice'] ?? 0;
-        $xhNum = $data['xhNum'] ?? 0;
-        $totalNum = $data['itemNum'] ?? 0;
-        $orderSn = $data['orderSn'] ?? '';
-
-        if ($unitType == dict::getDict('unitType', 'small')) {
-            $smallNum = $num;
-            $bigNum = 0;
-        } else {
-            $smallNum = 0;
-            $bigNum = $num;
-        }
-
-        $oldStock = 0;
-        $newStock = 0;
-        if ($bigNum > 0) {
-            //退货加库存
-            $stockInfo = ProductClass::addStock($productId, $bigNum, $smallNum);
-            $oldStock = $stockInfo['oldStock'] ?? 0;
-            $newStock = $stockInfo['newStock'] ?? 0;
-            //库存变动记录
-            $recordData = [];
-            $recordData['shopId'] = $data['shopId'];
-            $recordData['relateName'] = $order->customName ?? '';
-            $recordData['itemNum'] = $totalNum;
-            $recordData['sjId'] = $data['sjId'] ?? 0;
-            $recordData['shopId'] = $data['shopId'] ?? 0;
-            $recordData['mainId'] = $data['mainId'] ?? 0;
-            $recordData['orderSn'] = $orderSn;
-            $recordData['itemId'] = $data['itemId'] ?? 0;
-            $recordData['oldStock'] = $oldStock; //当时库存
-            $recordData['productId'] = $productId;
-            $recordData['newStock'] = $newStock;// 最新库存
-            StockRecordClass::ghsRefundAddRecord($recordData);
-        }
-
-
-        $data['itemStock'] = $oldStock;
-        $data['newStock'] = $newStock;
         self::add($data);
-
-        //花材销量统计变动
-        $refundStat = [
-            'mainId' => $mainId,
-            'productId' => $productId,
-            'itemNum' => $xhNum,
-            'itemPrice' => $xhUnitPrice,
-        ];
-        StatItemClass::refundReplace($refundStat);
     }
 
     public static function batchAddOrderItem($data)

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

@@ -37,8 +37,6 @@ class RefundOrderService extends BaseService
         $order->refund = OrderClass::REFUND_YES;
         $order->save();
 
-        $onlinePay = $order->onlinePay ?? 1;
-
         $refundPrice = $post['price'] ?? 0;
         if ($refundPrice <= 0) {
             util::fail('请填写退款金额');
@@ -134,186 +132,9 @@ class RefundOrderService extends BaseService
         $data['remark'] = $post['remark'] ?? '';
         $data['refundPrice'] = $refundPrice;
         $data['refundType'] = $post['refundType'] ?? 0;
-        $data['status'] = 1;
+        $data['status'] = 0;
         $refund = RefundOrderClass::add($data, true);
 
-        $payWay = $order->payWay;
-        $shopId = $order->shopId;
-        $shop = ShopClass::getLockById($shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有main信息');
-        }
-        //总支出增加
-        $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
-        $main->totalExpend = $currentTotalExpend;
-        $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
-        $main->totalRefund = $totalRefund;
-        $main->save();
-
-        //支出流水
-        $thisType = dict::getDict('capitalType', 'saleRefund', 'id');
-        $sjId = $order->sjId ?? 0;
-        $event = '销售退款';
-        $capitalData = [
-            'capitalType' => $thisType,
-            'io' => 0,
-            'totalExpend' => $currentTotalExpend,
-            'payWay' => 0,
-            'amount' => $refundPrice,
-            'sjId' => $sjId,
-            'shopId' => $shopId,
-            'event' => $event,
-            'mainId' => $mainId,
-        ];
-        ShopCapitalClass::addCapital($capitalData);
-        //当天和当月支出统计
-        StatOutClass::updateOrInsert($main, $shop, $refundPrice);
-        //退款统计
-        StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
-        StatKhCgClass::refundReplace($refund);
-
-        //记录总的退款金额
-        $currentTkPrice = bcadd($order->tkPrice, $refundPrice, 2);
-        $order->tkPrice = $currentTkPrice;
-        $order->refund = OrderClass::REFUND_YES;
-        $order->save();
-
-
-        if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-            //退款流程
-            if ($payWay == dict::getDict('payWay', 'wxPay')) {
-
-                $order->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额不足');
-                }
-                $order->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足哦');
-                }
-                $order->realPrice = $currentRealPrice;
-                $order->save();
-
-                //门店余额减少
-                ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
-            } else {
-                util::fail('此支付方式暂不支持退款');
-            }
-        } else {
-            if ($payWay == dict::getDict('payWay', 'debtPay')) {
-
-                $clearId = $order->clearId;
-                if (!empty($clearId)) {
-                    util::fail('订单已结账,无法发起退款');
-                }
-
-                //门店应收款减少
-                $currentMayGathering = bcsub($main->mayGathering, $refundPrice, 2);
-                if ($currentMayGathering < 0) {
-                    noticeUtil::push("应付款有问题 {$main->mayGathering} {$refundPrice}", '15280215347');
-                    util::fail('应付款有问题哦');
-                }
-                $main->mayGathering = $currentMayGathering;
-                $main->save();
-
-                $order->refundPrice = $refundPrice;
-
-                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额不足');
-                }
-                $order->actPrice = $currentActPrice;
-
-                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足哈');
-                }
-                $order->realPrice = $currentRealPrice;
-
-                $currentRemainDebt = bcsub($order->remainDebtPrice, $refundPrice, 2);
-                if ($currentRemainDebt < 0) {
-                    util::fail('退款金额有问题');
-                }
-                if ($currentRemainDebt == 0) {
-                    $order->debt = OrderClass::DEBT_NO;
-                }
-                $order->remainDebtPrice = $currentRemainDebt;
-                $order->save();
-
-                //门店客户欠款减少
-                $customId = $order->customId;
-                $custom = CustomClass::getLockById($customId);
-                if (empty($custom)) {
-                    util::fail('没有找到客户');
-                }
-
-                //客户欠款金额减少
-                CustomClass::refundDebtAmountReduce($custom, $refund, $order);
-
-            } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
-
-                util::fail('余额支付暂不支持退款');
-
-                $order->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额已不足了');
-                }
-                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额已不足');
-                }
-                $order->actPrice = $currentActPrice;
-                $order->realPrice = $currentRealPrice;
-                $order->save();
-
-                //门店余额减少
-                ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
-
-            } elseif ($payWay == dict::getDict('payWay', 'cash')) {
-                $moneyData = [
-                    'shopId' => $shopId,
-                    'amount' => $refundPrice,
-                    'orderSn' => $order->orderSn,
-                    'mainId' => $mainId,
-                ];
-                ShopMoneyClass::ghsRefundHdOutAmount($moneyData, $main);
-
-                $order->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额已不足。');
-                }
-                $order->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足那');
-                }
-                $order->realPrice = $currentRealPrice;
-                $order->save();
-
-            } else {
-                //其它线下退款直接完成
-                $order->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额已不足。');
-                }
-                $order->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足那');
-                }
-                $order->realPrice = $currentRealPrice;
-                $order->save();
-            }
-        }
         return $refund;
     }
 }

+ 0 - 46
biz-hd/cg/classes/CgRefundItemClass.php

@@ -16,52 +16,6 @@ class CgRefundItemClass extends BaseClass
 
     public static function addData($data, $cg)
     {
-        //退货减库存
-        $productId = $data['productId'] ?? 0;
-        $unitType = $data['xhUnitType'] ?? 0;
-        $mainId = $data['mainId'] ?? 0;
-        $ptItemId = $data['itemId'] ?? 0;
-        $orderSn = $data['orderSn'] ?? '';
-        $sjId = $data['sjId'] ?? 0;
-        $shopId = $data['shopId'] ?? 0;
-        $ratio = $data['ratio'] ?? 20;
-        $ghsName = $cg->ghsName ?? '';
-
-        $bigNum = 0;
-        $smallNum = 0;
-        $num = $data['xhNum'] ?? 0;
-        if ($unitType == dict::getDict('unitType', 'big')) {
-            $bigNum = $num;
-            $totalNum = $num;
-        } else {
-            $smallNum = $num;
-            $totalNum = bcdiv($num, $ratio, 2);
-        }
-
-        $newStock = 0;
-        $oldStock = 0;
-        if ($bigNum > 0) {
-            $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum);
-            $oldStock = $stockInfo['oldStock'] ?? 0;
-            $newStock = $stockInfo['newStock'] ?? 0;
-
-            $recordData = [];
-            $recordData['shopId'] = $data['shopId'];
-            $recordData['itemNum'] = $totalNum;
-            $recordData['sjId'] = $sjId;
-            $recordData['shopId'] = $shopId;
-            $recordData['mainId'] = $mainId;
-            $recordData['orderSn'] = $orderSn;
-            $recordData['itemId'] = $ptItemId;
-            $recordData['oldStock'] = $oldStock; //当时库存
-            $recordData['productId'] = $productId;
-            $recordData['newStock'] = $newStock;// 最新库存
-            $recordData['relateName'] = $ghsName;
-            StockRecordClass::hdCgApplyRefundAddRecord($recordData);
-        }
-
-        $data['itemStock'] = $oldStock;
-        $data['newStock'] = $newStock;
         self::add($data);
     }
 

+ 1 - 210
biz-hd/cg/services/CgRefundService.php

@@ -28,15 +28,9 @@ class CgRefundService extends BaseService
 
     public static $baseFile = '\bizHd\cg\classes\CgRefundClass';
 
-    public static function createRefund()
-    {
-
-    }
-
     //新增退款
     public static function addRefund($post, $cg)
     {
-
         $cgId = $cg->id ?? 0;
         $mainId = $cg->mainId ?? 0;
         $shopId = $cg->shopId ?? 0;
@@ -74,7 +68,7 @@ class CgRefundService extends BaseService
         $data['refundType'] = $refundType;
         $data['refundPrice'] = $refundPrice;
         $data['remark'] = $post['remark'];
-        $data['status'] = CgRefundClass::STATUS_COMPLETE;
+        $data['status'] = CgRefundClass::STATUS_UN_COMPLETE;
 
         //花材列表结构
         // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
@@ -133,209 +127,6 @@ class CgRefundService extends BaseService
             }
         }
 
-        //门店总收入增加
-        $currentTotalIncome = bcadd($main->totalIncome, $refundPrice, 2);
-        $main->totalIncome = $currentTotalIncome;
-        $main->save();
-
-        $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
-
-        //记录总的退款金额
-        $currentTkPrice = bcadd($cg->tkPrice, $refundPrice, 2);
-        $cg->tkPrice = $currentTkPrice;
-        $cg->refund = PurchaseClass::REFUND_YES;
-        $cg->save();
-
-        $ghsId = $cg->ghsId;
-        $ghs = GhsClass::getLockById($ghsId);
-        if (empty($ghs)) {
-            util::fail('没有找到供货商');
-        }
-        $ghsName = $ghs->name ?? '';
-
-        if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
-            if ($payWay == dict::getDict('payWay', 'wxPay')) {
-
-                //微信收款的原路退回
-                ini_set('date.timezone', 'Asia/Shanghai');
-                $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
-                require_once($wx . '/lib/WxPay.Api.php');
-                require_once($wx . '/example/WxPay.Config.php');
-
-                $totalFee = $cg->book == 1 ? $cg->bookPrice * 100 : $cg->orderPrice * 100;
-                $refundFee = $refundPrice * 100;
-
-                $merchantExt = WxOpenClass::getWxInfo();
-                $mid = $merchantExt['wxPayMerchantId'] ?? '';
-                $appId = $merchantExt['miniAppId'] ?? '';
-                $key = $merchantExt['wxPayKey'] ?? '';
-
-                $input = new \WxPayRefund();
-                $input->SetTransaction_id($transaction_id);
-                $input->SetTotal_fee($totalFee);
-                $input->SetRefund_fee($refundFee);
-                $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-refund-callback/');
-
-                $config = new \WxPayConfig();
-                $config->SetAppId($appId);
-                $config->SetMerchantId($mid);
-                $config->SetKey($key);
-
-                $input->SetOut_refund_no($refundOrderSn);
-                $input->SetOp_user_id($mid);
-                $return = \WxPayApi::refund($config, $input);
-                if (isset($return['return_code']) == false || $return['return_code'] != 'SUCCESS' || isset($return['result_code']) == false || $return['result_code'] != 'SUCCESS') {
-                    $msg = $return['return_msg'] ?? '';
-                    $err_code_des = $return['err_code_des'] ?? '';
-                    Yii::info("退款失败 cgId:{$cgId} msg:{$msg}");
-                    Yii::info($err_code_des);
-                    Yii::info('微信退款返回信息:' . json_encode($return));
-                    util::fail('退款操作失败');
-                }
-                $wxRefundId = $return['refund_id'] ?? '';
-                $cgRefund->thirdRefundNo = $wxRefundId;
-                $cgRefund->save();
-
-                $cg->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额不足!!');
-                }
-                $cg->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足,请排查。');
-                }
-                $cg->realPrice = $currentRealPrice;
-                $cg->save();
-
-                //发起退款通知
-                //$customName = $order->customName ?? '';
-                //noticeUtil::push("商家正在给{$customName}退款{$refundPrice}元", '15280215347');
-
-            } else {
-                util::fail('此支付方式暂不支持退款');
-            }
-        } else {
-            if ($payWay == dict::getDict('payWay', 'debtPay')) {
-
-                $clearId = $cg->clearId ?? 0;
-                if (!empty($clearId)) {
-                    util::fail('订单已经结帐,无法再发起退款');
-                }
-
-                $cg->refundPrice = $refundPrice;
-
-                $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额不足');
-                }
-                $cg->actPrice = $currentActPrice;
-
-                $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足,请排查');
-                }
-                $cg->realPrice = $currentRealPrice;
-
-                $currentRemainDebt = bcsub($cg->remainDebtPrice, $refundPrice, 2);
-                if ($currentRemainDebt < 0) {
-                    util::fail('可退款金额不足哦');
-                }
-                if ($currentRemainDebt == 0) {
-                    $cg->debt = PurchaseClass::DEBT_NO;
-                }
-                $cg->remainDebtPrice = $currentRemainDebt;
-                $cg->save();
-
-                //门店应付总款减少
-                $currentMayPay = bcsub($main->mayPay, $refundPrice, 2);
-                if ($currentMayPay < 0) {
-                    //noticeUtil::push("应付款有问题! {$main->mayPay} {$refundPrice}", '15280215347');
-                    //util::fail('应付款有问题!');
-                }
-                $main->mayPay = $currentMayPay;
-                $main->save();
-
-                //应付供货商款减少
-                \bizHd\ghs\classes\GhsClass::refundDebtAmountReduce($ghs, $cgRefund, $cg);
-
-            } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
-
-                util::fail('余额支付暂不支持退款');
-
-                //采购单总金额还要减去退款
-                $cg->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('退款金额有问题!');
-                }
-                $cg->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('退款金额有问题,请排查');
-                }
-                $cg->realPrice = $currentRealPrice;
-                $cg->save();
-
-                //门店余额增加
-                ShopClass::cgRefundAddBalance($main, $shop, $refundPrice, $cgRefund, $ghs);
-
-            } elseif ($payWay == dict::getDict('payWay', 'cash')) {
-                $cg->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额不足...');
-                }
-                $cg->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足,请确认');
-                }
-                $cg->realPrice = $currentRealPrice;
-                $cg->save();
-            } else {
-                //其它线下退款直接完成
-                $cg->refundPrice = $refundPrice;
-                $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
-                if ($currentActPrice < 0) {
-                    util::fail('可退款金额不足...');
-                }
-                $cg->actPrice = $currentActPrice;
-                $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
-                if ($currentRealPrice < 0) {
-                    util::fail('可退款金额不足,请确认');
-                }
-                $cg->realPrice = $currentRealPrice;
-                $cg->save();
-            }
-        }
-
-        $sjId = $cg->sjId ?? 0;
-        $shopId = $cg->shopId ?? 0;
-        $event = "采购退款({$ghsName})";
-        $capitalData = [
-            'capitalType' => $currentType,
-            'io' => 1,
-            'totalIncome' => $currentTotalIncome,
-            'payWay' => 0,
-            'amount' => $refundPrice,
-            'sjId' => $sjId,
-            'shopId' => $shopId,
-            'event' => $event,
-            'mainId' => $mainId,
-        ];
-        ShopCapitalClass::addCapital($capitalData);
-
-        //每天每月收入
-        StatIncomeClass::updateOrInsert($main, $shop, $refundPrice);
-
-        //微信付款的不需要通知,微信官方会通知
-        if ($payWay != dict::getDict('payWay', 'wxPay')) {
-            //微信通知退款成功
-            WxMessageClass::cgRefundInform($shop, $cg, $refundPrice);
-        }
-
         return $cgRefund;
 
     }