shish hace 1 año
padre
commit
021216cff9
Se han modificado 2 ficheros con 126 adiciones y 188 borrados
  1. 23 83
      app-hd/controllers/RefundController.php
  2. 103 105
      biz-hd/refund/services/HdRefundService.php

+ 23 - 83
app-hd/controllers/RefundController.php

@@ -31,7 +31,7 @@ class RefundController extends BaseController
         }
 
         $staff = $this->shopAdmin;
-        if($staff->mobile != '15280215347'){
+        if ($staff->mobile != '15280215347') {
             util::fail('请联系管理员操作');
         }
 
@@ -72,20 +72,19 @@ class RefundController extends BaseController
     public function actionCreateOrder()
     {
         $shopAdmin = $this->shopAdmin;
-        if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) {
+        if (!isset($shopAdmin['super']) || $shopAdmin['super'] != 1) {
             util::fail('超管才能操作退款');
         }
 
         $post = Yii::$app->request->post();
         $id = isset($post['id']) ? $post['id'] : 0;
-
-        //避免网络延迟,暂时重复申请
-        $cacheKey = 'hd_order_refund_' . $id;
-        $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
-        if (!empty($has)) {
-            util::fail('请10秒之后再提交');
+        $version = $post['version'] ?? 1;
+        if ($version == 1) {
+            util::fail('请升级小程序');
         }
-        Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 10, 'has']);
+
+        //避免重复提交
+        util::checkRepeatCommit($id, 10);
 
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
@@ -106,7 +105,7 @@ class RefundController extends BaseController
                 util::fail('10月17日前订单无法申请退款');
             }
 
-            if($order->payWay == 2){
+            if ($order->payWay == 2) {
                 util::fail('余额支付订单暂不支持售后');
             }
 
@@ -118,26 +117,20 @@ class RefundController extends BaseController
             if (strtotime($addTime) <= strtotime('2022-03-30 00:00:00')) {
                 util::fail('历史订单,不能发起退款哦');
             }
-            //退款类型 1退货并退款 2 仅退款
-            $refundType = $post['refundType'] ?? 1;
-
-            if ($refundType == HdRefundClass::REFUND_TYPE_MONEY_GOOD) {
-                //商品花材结构 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;
-            } else {
-                //仅退款商品花材直接设置为空
-                $post['product'] = [];
+
+            //商品花材结构 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['price'] = $post['price'] ?? 0;
             if ($post['price'] <= 0) {
                 util::fail("退款金额不能小于0");
@@ -172,60 +165,7 @@ class RefundController extends BaseController
 
     public function actionAllRefund()
     {
-        $get = Yii::$app->request->get();
-
-        $connection = Yii::$app->db;
-        $transaction = $connection->beginTransaction();
-        try {
-            $id = $get['id'] ?? 0;
-            $order = OrderClass::getById($id, true);
-            OrderClass::valid($order, $this->mainId);
-
-            $shopId = $this->shopId ?? 0;
-            $sjId = $this->sjId ?? 0;
-            $mainId = $this->mainId ?? 0;
-            $post = [];
-            $post['price'] = $order->actPrice ?? 0;
-            $post['refundType'] = HdRefundClass::REFUND_TYPE_MONEY_GOOD;
-            $post['id'] = $order->id ?? 0;
-            $post['shopId'] = $shopId;
-            $post['sjId'] = $sjId;
-            $post['shopAdminId'] = 0;
-            $post['mainId'] = $mainId;
-            $staff = $this->shopAdmin;
-            $post['shopAdminName'] = $staff->name ?? '';
-            $orderSn = $order->orderSn ?? '';
-            $orderGoods = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
-            $productData = [];
-            if (!empty($orderGoods)) {
-                foreach ($orderGoods as $goodsItem) {
-                    $productData[] = ['productId' => $goodsItem->goodsId, 'num' => $goodsItem->num, 'unitPrice' => $goodsItem->unitPrice, 'property' => 0,];
-                }
-            }
-            $orderItem = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
-            if (!empty($orderItem)) {
-                foreach ($orderItem as $singe) {
-                    $unitType = $singe->unitType;
-                    $productData[] = ['productId' => $singe->itemId, 'num' => $singe->num, 'unitPrice' => $singe->unitPrice, 'property' => 1, 'unitType' => $unitType];
-                }
-            }
-            $post['product'] = $productData;
-            HdRefundService::addRefund($post, $order);
-
-            $transaction->commit();
-
-            //制作单取消通知
-            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
-            ShopExtClass::orderCancelRemind($shopExt, $order);
-
-            util::complete();
-
-        } catch (\Exception $e) {
-            $transaction->rollBack();
-            $msg = $e->getMessage();
-            noticeUtil::push("取消报错了,错误信息:{$msg}", '15280215347');
-            util::fail('退款失败');
-        }
+        util::fail('功能开发中');
     }
 
 }

+ 103 - 105
biz-hd/refund/services/HdRefundService.php

@@ -55,8 +55,6 @@ class HdRefundService extends BaseService
         $order->realPrice = $currentActPrice;
         $order->save();
 
-        $transaction_id = $order->thirdNo ?? '';
-
         $post['orderId'] = $order->id ?? 0;
 
         $data = [];
@@ -77,118 +75,118 @@ class HdRefundService extends BaseService
         $data['shopAdminName'] = $post['shopAdminName'] ?? '';
 
         $postProduct = $post['product'] ?? '';
-        if ($refundType == HdRefundClass::REFUND_TYPE_MONEY_GOOD) {
-            //商品花材结构 property 0商品 1花材
-            //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
-            if (empty($postProduct)) {
-                util::fail('没有退款商品');
+
+        //商品花材结构 property 0商品 1花材
+        //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
+        if (empty($postProduct)) {
+            util::fail('没有退款商品');
+        }
+        $goodsInfoList = [];
+        $itemInfoList = [];
+        foreach ($postProduct as $current) {
+            $property = $current['property'] ?? 0;
+            if ($property == 0) {
+                $goodsInfoList[] = $current;
+            } else {
+                $itemInfoList[] = $current;
             }
-            $goodsInfoList = [];
-            $itemInfoList = [];
-            foreach ($postProduct as $current) {
-                $property = $current['property'] ?? 0;
-                if ($property == 0) {
-                    $goodsInfoList[] = $current;
-                } else {
-                    $itemInfoList[] = $current;
-                }
+        }
+        if (!empty($itemInfoList)) {
+            $ids = array_column($itemInfoList, 'productId');
+            $productInfo = ProductClass::getByids($ids, null, 'id');
+            $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $xsOrderSn], null, '*', 'itemId', true);
+            if (empty($orderItemData)) {
+                util::fail('没有找到商品');
             }
-            if (!empty($itemInfoList)) {
-                $ids = array_column($itemInfoList, 'productId');
-                $productInfo = ProductClass::getByids($ids, null, 'id');
-                $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $xsOrderSn], null, '*', 'itemId', true);
-                if (empty($orderItemData)) {
-                    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('没有找到退款的花材');
                 }
-                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);
+                $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);
             }
-            if (!empty($goodsInfoList)) {
-                $ids = array_column($goodsInfoList, 'productId');
-                $goodsData = GoodsClass::getByIds($ids, null, 'id');
-                $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $xsOrderSn], 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);
+        }
+        if (!empty($goodsInfoList)) {
+            $ids = array_column($goodsInfoList, 'productId');
+            $goodsData = GoodsClass::getByIds($ids, null, 'id');
+            $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $xsOrderSn], 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);
             }
         }
 
+
         $data['customId'] = $order->customId ?? 0;
         $data['remark'] = $post['remark'] ?? '';
         $data['refundPrice'] = $refundPrice;