shish hace 11 meses
padre
commit
477f9ec386

+ 1 - 1
app-hd/controllers/ItemController.php

@@ -111,7 +111,7 @@ class ItemController extends BaseController
                 util::fail('不是你的客户哦,编号55236');
             }
         }
-        $level = $custom->level ?? 1;
+        $level = 0;
         $field = '*';
 
         $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);

+ 13 - 12
app-hd/controllers/RefundController.php

@@ -84,6 +84,7 @@ class RefundController extends BaseController
         if ($version == 1) {
             util::fail('请升级小程序');
         }
+        $refundType = $post['refundType'] ?? 1;//1退货并退款2只退款
 
         //避免重复提交
         util::checkRepeatCommit($id, 10);
@@ -123,19 +124,20 @@ class RefundController extends BaseController
                 util::fail('负数订单不能发起售后');
             }
 
-            //商品花材结构 property 0花束 1花材
-            //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
-            $productJson = $post['product'] ?? '';
-            if (empty($productJson)) {
-                util::fail('请选择商品');
-            }
-            $productList = json_decode($productJson, true);
-            if (!is_array($productList)) {
-                util::fail('请选择商品哦');
+            if ($refundType == 1) {
+                //商品花材结构 property 0花束 1花材
+                //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
+                $productJson = $post['product'] ?? '';
+                if (empty($productJson)) {
+                    util::fail('请选择商品');
+                }
+                $productList = json_decode($productJson, true);
+                if (!is_array($productList)) {
+                    util::fail('请选择商品哦');
+                }
+                $post['product'] = $productList;
             }
 
-            $post['product'] = $productList;
-
             $post['price'] = $post['price'] ?? 0;
             if ($post['price'] <= 0) {
                 util::fail("退款金额不能小于0");
@@ -167,7 +169,6 @@ class RefundController extends BaseController
                 $shopId = $order->shopId;
                 $staffId = $this->shopAdminId;
                 $staffName = $this->shopAdminName;
-                $refundType = $post['refundType'] ?? 1;//1退货并退款2只退款
                 $forwardStock = $refundType == 1 ? 0 : 1;
                 $refundPrice = $post['price'] ?? 0;
 

+ 115 - 113
biz-hd/refund/services/HdRefundService.php

@@ -55,6 +55,7 @@ class HdRefundService extends BaseService
         $order->realPrice = $currentActPrice;
         $order->save();
 
+        $refundType = $post['refundType'] ?? 1;
         $post['orderId'] = $order->id ?? 0;
 
         $data = [];
@@ -76,123 +77,124 @@ class HdRefundService extends BaseService
 
         $postProduct = $post['product'] ?? '';
 
-        //商品花材结构 property 0商品 1花材
-        //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
-        if (empty($postProduct)) {
-            util::fail('没有退款商品');
-        }
-        $goodsInfoList = [];
-        $itemInfoList = [];
-        $calcAmount = 0;
-        foreach ($postProduct as $current) {
-            $property = $current['property'] ?? 0;
-            if ($property == 0) {
-                $goodsInfoList[] = $current;
-            } else {
-                $itemInfoList[] = $current;
-            }
-            $calcNum = $current['num'] ?? 0;
-            $calcUnitPrice = $current['unitPrice'] ?? 0;
-            $calcPrice = bcmul($calcNum, $calcUnitPrice, 2);
-            $calcAmount = bcadd($calcAmount, $calcPrice, 2);
-        }
-
-        if (floatval($refundPrice) != floatval($calcAmount)) {
-            util::fail('数量与单价的总乘积,与退款金额不一致');
-        }
-
-        if (!empty($itemInfoList)) {
-            $ids = array_column($itemInfoList, 'productId');
-            $productInfo = ProductClass::getByids($ids, null, 'id');
-            $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'itemId', true);
-            if (empty($orderItemData)) {
-                util::fail('没有找到商品');
+        if ($refundType == 1) {
+            //商品花材结构 property 0商品 1花材
+            //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
+            if (empty($postProduct)) {
+                util::fail('没有退款商品');
             }
-            foreach ($itemInfoList as $currentProduct) {
-                $id = $currentProduct['productId'] ?? 0;
-                $unitPrice = $currentProduct['unitPrice'] ?? 0;
-                $unitType = $currentProduct['unitType'] ?? 0;
-                $unitName = $currentProduct['unitName'] ?? '';
-                $currentRefundNum = $currentProduct['num'] ?? 0;
-                $price = bcmul($currentRefundNum, $unitPrice, 2);
-                $name = $productInfo[$id]['name'] ?? '';
-                $ptItemId = $productInfo[$id]['itemId'] ?? 0;
-                $cover = $productInfo[$id]['cover'] ?? '';
-                $ratio = $productInfo[$id]['ratio'] ?? '';
-                $bigUnit = $productInfo[$id]['bigUnit'] ?? '';
-                $smallUnit = $productInfo[$id]['smallUnit'] ?? '';
-                $currentOrderItem = $orderItemData[$id] ?? null;
-                if (empty($currentOrderItem)) {
-                    util::fail('没有找到退款的花材');
-                }
-                $orderItemNum = $currentOrderItem->num ?? 0;
-                //已退货数
-                $hasRefundNum = $currentOrderItem->refundNum ?? 0;
-                $remainNum = bcsub($orderItemNum, $hasRefundNum);
-                if ($currentRefundNum > $remainNum) {
-                    util::fail("{$name}超过可退数量");
+            $goodsInfoList = [];
+            $itemInfoList = [];
+            $calcAmount = 0;
+            foreach ($postProduct as $current) {
+                $property = $current['property'] ?? 0;
+                if ($property == 0) {
+                    $goodsInfoList[] = $current;
+                } else {
+                    $itemInfoList[] = $current;
                 }
-                $currentOrderItem->refundNum = bcadd($hasRefundNum, $currentRefundNum);
-                $currentOrderItem->save();
-                $thisItemData = [
-                    'refundSn' => $refundSn,
-                    'mainId' => $mainId,
-                    'sjId' => $sjId,
-                    'shopId' => $shopId,
-                    'name' => $name,
-                    'itemId' => $id,
-                    'ptItemId' => $ptItemId,
-                    'num' => $currentRefundNum,
-                    'unitName' => $unitName,
-                    'unitType' => $unitType,
-                    'cover' => $cover,
-                    'ratio' => $ratio,
-                    'bigUnit' => $bigUnit,
-                    'smallUnit' => $smallUnit,
-                    'unitPrice' => $unitPrice,
-                    'price' => $price,
-                ];
-                HdRefundItemClass::addData($thisItemData, $refundSn, $post);
+                $calcNum = $current['num'] ?? 0;
+                $calcUnitPrice = $current['unitPrice'] ?? 0;
+                $calcPrice = bcmul($calcNum, $calcUnitPrice, 2);
+                $calcAmount = bcadd($calcAmount, $calcPrice, 2);
             }
-        }
-        if (!empty($goodsInfoList)) {
-            $ids = array_column($goodsInfoList, 'productId');
-            $goodsData = GoodsClass::getByIds($ids, null, 'id');
-            $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'goodsId', true);
-            foreach ($goodsInfoList as $currentGoods) {
-                $goodsId = $currentGoods['productId'] ?? 0;
-                $unitPrice = $currentGoods['unitPrice'] ?? 0;
-                $name = $goodsData[$goodsId]['name'] ?? '';
-                $currentRefundNum = $currentGoods['num'] ?? 0;
-                $price = bcmul($currentRefundNum, $unitPrice, 2);
-                $currentOrderGoods = $orderGoodsData[$goodsId] ?? [];
-                if (empty($currentOrderGoods)) {
-                    util::fail('没有找到商品呢');
+            if (floatval($refundPrice) < floatval($calcAmount)) {
+                util::fail('退款金额要大于商品金额总和');
+            }
+
+            if (!empty($itemInfoList)) {
+                $ids = array_column($itemInfoList, 'productId');
+                $productInfo = ProductClass::getByids($ids, null, 'id');
+                $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'itemId', true);
+                if (empty($orderItemData)) {
+                    util::fail('没有找到商品');
                 }
-                $totalNum = $currentOrderGoods->num ?? 0;
-                $hasRefundNum = $currentOrderGoods->refundNum ?? 0;
-                $remainNum = bcsub($totalNum, $hasRefundNum);
-                if ($currentRefundNum > $remainNum) {
-                    util::fail("{$name}超过可退数量");
+                foreach ($itemInfoList as $currentProduct) {
+                    $id = $currentProduct['productId'] ?? 0;
+                    $unitPrice = $currentProduct['unitPrice'] ?? 0;
+                    $unitType = $currentProduct['unitType'] ?? 0;
+                    $unitName = $currentProduct['unitName'] ?? '';
+                    $currentRefundNum = $currentProduct['num'] ?? 0;
+                    $price = bcmul($currentRefundNum, $unitPrice, 2);
+                    $name = $productInfo[$id]['name'] ?? '';
+                    $ptItemId = $productInfo[$id]['itemId'] ?? 0;
+                    $cover = $productInfo[$id]['cover'] ?? '';
+                    $ratio = $productInfo[$id]['ratio'] ?? '';
+                    $bigUnit = $productInfo[$id]['bigUnit'] ?? '';
+                    $smallUnit = $productInfo[$id]['smallUnit'] ?? '';
+                    $currentOrderItem = $orderItemData[$id] ?? null;
+                    if (empty($currentOrderItem)) {
+                        util::fail('没有找到退款的花材');
+                    }
+                    $orderItemNum = $currentOrderItem->num ?? 0;
+                    //已退货数
+                    $hasRefundNum = $currentOrderItem->refundNum ?? 0;
+                    $remainNum = bcsub($orderItemNum, $hasRefundNum);
+                    if ($currentRefundNum > $remainNum) {
+                        util::fail("{$name}超过可退数量");
+                    }
+                    $currentOrderItem->refundNum = bcadd($hasRefundNum, $currentRefundNum);
+                    $currentOrderItem->save();
+                    $thisItemData = [
+                        'refundSn' => $refundSn,
+                        'mainId' => $mainId,
+                        'sjId' => $sjId,
+                        'shopId' => $shopId,
+                        'name' => $name,
+                        'itemId' => $id,
+                        'ptItemId' => $ptItemId,
+                        'num' => $currentRefundNum,
+                        'unitName' => $unitName,
+                        'unitType' => $unitType,
+                        'cover' => $cover,
+                        'ratio' => $ratio,
+                        'bigUnit' => $bigUnit,
+                        'smallUnit' => $smallUnit,
+                        'unitPrice' => $unitPrice,
+                        'price' => $price,
+                    ];
+                    HdRefundItemClass::addData($thisItemData, $refundSn, $post);
                 }
-                $currentOrderGoods->refundNum = bcadd($hasRefundNum, $currentRefundNum);
-                $currentOrderGoods->save();
+            }
+            if (!empty($goodsInfoList)) {
+                $ids = array_column($goodsInfoList, 'productId');
+                $goodsData = GoodsClass::getByIds($ids, null, 'id');
+                $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $myOrderSn], null, '*', 'goodsId', true);
+                foreach ($goodsInfoList as $currentGoods) {
+                    $goodsId = $currentGoods['productId'] ?? 0;
+                    $unitPrice = $currentGoods['unitPrice'] ?? 0;
+                    $name = $goodsData[$goodsId]['name'] ?? '';
+                    $currentRefundNum = $currentGoods['num'] ?? 0;
+                    $price = bcmul($currentRefundNum, $unitPrice, 2);
+                    $currentOrderGoods = $orderGoodsData[$goodsId] ?? [];
+                    if (empty($currentOrderGoods)) {
+                        util::fail('没有找到商品呢');
+                    }
+                    $totalNum = $currentOrderGoods->num ?? 0;
+                    $hasRefundNum = $currentOrderGoods->refundNum ?? 0;
+                    $remainNum = bcsub($totalNum, $hasRefundNum);
+                    if ($currentRefundNum > $remainNum) {
+                        util::fail("{$name}超过可退数量");
+                    }
+                    $currentOrderGoods->refundNum = bcadd($hasRefundNum, $currentRefundNum);
+                    $currentOrderGoods->save();
 
-                $cover = $goodsData[$goodsId]['cover'] ?? '';
-                $num = $currentGoods['num'] ?? 0;
-                $saveGoods = [
-                    'refundSn' => $refundSn,
-                    'mainId' => $mainId,
-                    'sjId' => $sjId,
-                    'shopId' => $shopId,
-                    'name' => $name,
-                    'cover' => $cover,
-                    'goodsId' => $goodsId,
-                    'num' => $num,
-                    'unitPrice' => $unitPrice,
-                    'price' => $price,
-                ];
-                HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
+                    $cover = $goodsData[$goodsId]['cover'] ?? '';
+                    $num = $currentGoods['num'] ?? 0;
+                    $saveGoods = [
+                        'refundSn' => $refundSn,
+                        'mainId' => $mainId,
+                        'sjId' => $sjId,
+                        'shopId' => $shopId,
+                        'name' => $name,
+                        'cover' => $cover,
+                        'goodsId' => $goodsId,
+                        'num' => $num,
+                        'unitPrice' => $unitPrice,
+                        'price' => $price,
+                    ];
+                    HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
+                }
             }
         }
 
@@ -296,7 +298,7 @@ class HdRefundService extends BaseService
                     $order->debt = 0;
                 }
                 $order->save();
-                CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund,$payWay);
+                CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund, $payWay);
             }
             if ($payWay == dict::getDict('payWay', 'cash')) {
                 //如果现金支付
@@ -310,7 +312,7 @@ class HdRefundService extends BaseService
             }
             if ($payWay == dict::getDict('payWay', 'balancePay')) {
                 //如果是余额支付,客户的余额要增加
-                CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund,$payWay);
+                CustomClass::skRefundDebtAmountReduce($custom, $refundPrice, $refund, $payWay);
             }
         }
         return $refund;