shish 2 éve
szülő
commit
e7cfd5d042
1 módosított fájl, 76 hozzáadás és 68 törlés
  1. 76 68
      biz-ghs/cg/services/CgRefundService.php

+ 76 - 68
biz-ghs/cg/services/CgRefundService.php

@@ -122,77 +122,85 @@ class CgRefundService extends BaseService
 
                 $sendRefundData = $currentProduct['sendRefund'] ?? [];
                 if ($shop->bookSn == $bookSn && !empty($bookSn)) {
-                    if (empty($sendRefundData)) {
-                        util::fail('请填写货位要退的数量');
-                    }
-                    $sendIds = array_column($sendRefundData, 'id');
-                    $sendRes = CgOrderItemSendClass::getAllByCondition(['id' => ['in', $sendIds]], null, '*', 'id', true);
-                    $totalSendRefundNum = 0;
-                    foreach ($sendRefundData as $sendKey => $send) {
-                        $sendRefundNum = $send['refundNum'] ?? 0;
-                        $totalSendRefundNum = bcadd($totalSendRefundNum, $sendRefundNum);
-                        $sendId = $send['id'] ?? 0;
-                        $currentSend = $sendRes[$sendId] ?? null;
-                        if (empty($currentSend)) {
-                            util::fail('没有找到采购单花材的配送信息呢');
-                        }
-                        $totalOnNum = $currentSend->num ?? 0;
-                        $hasOutNum = $currentSend->outNum ?? 0;
-                        $remainNum = bcsub($totalOnNum, $hasOutNum);
-                        $customName = $currentSend->customName ?? '';
-                        if ($sendRefundNum > $remainNum) {
-                            util::fail($customName . '货位不够退了');
+                    if (!empty($sendRefundData)) {
+                        $sendIds = array_column($sendRefundData, 'id');
+                        $sendRes = CgOrderItemSendClass::getAllByCondition(['id' => ['in', $sendIds]], null, '*', 'id', true);
+                        $totalSendRefundNum = 0;
+                        foreach ($sendRefundData as $sendKey => $send) {
+                            $sendRefundNum = $send['refundNum'] ?? 0;
+                            $totalSendRefundNum = bcadd($totalSendRefundNum, $sendRefundNum);
+                            $sendId = $send['id'] ?? 0;
+                            $currentSend = $sendRes[$sendId] ?? null;
+                            if (empty($currentSend)) {
+                                util::fail('没有找到采购单花材的配送信息呢');
+                            }
+                            $totalOnNum = $currentSend->num ?? 0;
+                            $hasOutNum = $currentSend->outNum ?? 0;
+                            $remainNum = bcsub($totalOnNum, $hasOutNum);
+                            $customName = $currentSend->customName ?? '';
+                            if ($sendRefundNum > $remainNum) {
+                                util::fail($customName . '货位不够退了');
+                            }
+                            $currentSend->outNum = bcadd($currentSend->outNum, $sendRefundNum);
+                            $currentSend->save();
+
+                            $bookGhsGiveId = $currentSend->bookGhsGiveId ?? 0;
+                            $give = BookItemGhsClass::getById($bookGhsGiveId, true);
+                            if (empty($give)) {
+                                util::fail('售后时,货位配送相关信息缺失哦');
+                            }
+                            $give->outNum = bcadd($give->outNum, $sendRefundNum);
+                            $give->save();
+
+                            $bookItemCustomId = $currentSend->bookItemCustomId ?? 0;
+                            $bookItemCustomRes = BookItemCustomClass::getById($bookItemCustomId, true);
+                            if (empty($bookItemCustomRes)) {
+                                util::fail('售后时,bookItemCustom信息缺失');
+                            }
+                            $onNum = $bookItemCustomRes->onNum ?? 0;
+                            if ($sendRefundNum > $onNum) {
+                                util::fail('售后时,bookItemCustom上架数量不够扣');
+                            }
+
+                            $staffId = $post['shopAdminId'] ?? 0;
+                            $staffName = $post['shopAdminName'] ?? '';
+                            $params = ['staffId' => $staffId, 'staffName' => $staffName, 'currentChangeType' => 'ghsCgRefund'];
+                            $bookItemCustomRes = BookItemCustomClass::delOnNum($bookItemCustomRes, $sendRefundNum, $num, $order, $shop, $productInfo, $params);
+
+                            $customId = $bookItemCustomRes->customId ?? 0;
+                            $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
+                            if (empty($bookCustomRes)) {
+                                util::fail('售后时,bookCustom信息缺失');
+                            }
+                            $onNum2 = $bookCustomRes->onNum ?? 0;
+                            if ($sendRefundNum > $onNum2) {
+                                util::fail('售后时,bookCustom上架数量不够扣');
+                            }
+                            $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $sendRefundNum, $num, $order, $shop, $productInfo, $params);
+
+                            $itemId = $bookItemCustomRes->itemId ?? 0;
+                            $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
+                            if (empty($bookItemRes)) {
+                                util::fail('售后时,bookItem信息缺失');
+                            }
+                            $onNum3 = $bookItemRes->onNum ?? 0;
+                            if ($sendRefundNum > $onNum3) {
+                                util::fail('售后时,bookItem上架数量不够扣');
+                            }
+                            $bookItemRes = BookItemClass::delOnNum($bookItemRes, $sendRefundNum, $num, $order, $shop, $productInfo, $params);
                         }
-                        $currentSend->outNum = bcadd($currentSend->outNum, $sendRefundNum);
-                        $currentSend->save();
-
-                        $bookGhsGiveId = $currentSend->bookGhsGiveId ?? 0;
-                        $give = BookItemGhsClass::getById($bookGhsGiveId, true);
-                        if (empty($give)) {
-                            util::fail('售后时,货位配送相关信息缺失哦');
+                        if (floatval($num) != floatval($totalSendRefundNum)) {
+                            util::fail("{$name} 退货数量必须和货位退货数和一致");
                         }
-                        $give->outNum = bcadd($give->outNum, $sendRefundNum);
-                        $give->save();
-
-                        $bookItemCustomId = $currentSend->bookItemCustomId ?? 0;
-                        $bookItemCustomRes = BookItemCustomClass::getById($bookItemCustomId, true);
-                        if (empty($bookItemCustomRes)) {
-                            util::fail('售后时,bookItemCustom信息缺失');
+                    }else{
+                        $sendList = CgOrderItemSendClass::getAllByCondition(['parentId'=>$currentCgItem->id],null,'*',null,true);
+                        if(!empty($sendList)){
+                            foreach($sendList as $sendInfo){
+                                if($sendInfo->status != 2){
+                                    util::fail('请填写货位要退的数量');
+                                }
+                            }
                         }
-                        $onNum = $bookItemCustomRes->onNum ?? 0;
-                        if ($sendRefundNum > $onNum) {
-                            util::fail('售后时,bookItemCustom上架数量不够扣');
-                        }
-
-                        $staffId = $post['shopAdminId'] ?? 0;
-                        $staffName = $post['shopAdminName'] ?? '';
-                        $params = ['staffId' => $staffId, 'staffName' => $staffName, 'currentChangeType' => 'ghsCgRefund'];
-                        $bookItemCustomRes = BookItemCustomClass::delOnNum($bookItemCustomRes, $sendRefundNum, $num, $order, $shop, $productInfo, $params);
-
-                        $customId = $bookItemCustomRes->customId ?? 0;
-                        $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
-                        if (empty($bookCustomRes)) {
-                            util::fail('售后时,bookCustom信息缺失');
-                        }
-                        $onNum2 = $bookCustomRes->onNum ?? 0;
-                        if ($sendRefundNum > $onNum2) {
-                            util::fail('售后时,bookCustom上架数量不够扣');
-                        }
-                        $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $sendRefundNum, $num, $order, $shop, $productInfo, $params);
-
-                        $itemId = $bookItemCustomRes->itemId ?? 0;
-                        $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
-                        if (empty($bookItemRes)) {
-                            util::fail('售后时,bookItem信息缺失');
-                        }
-                        $onNum3 = $bookItemRes->onNum ?? 0;
-                        if ($sendRefundNum > $onNum3) {
-                            util::fail('售后时,bookItem上架数量不够扣');
-                        }
-                        $bookItemRes = BookItemClass::delOnNum($bookItemRes, $sendRefundNum, $num, $order, $shop, $productInfo, $params);
-                    }
-                    if (floatval($num) != floatval($totalSendRefundNum)) {
-                        util::fail("{$name} 退货数量必须和货位退货数和一致");
                     }
                 }
             }